Skip to main content

Batch-Execution-of-SQL-Statements

Command Description

Batch execution of SQL statements, and return the number of results affected (select statement does not support this yet). Set SQL statement placeholders based on SQL attributes: MySQL, SQLServer, PostgreSQL: %s, Sqlite3: ?, Oracle: 1

Command Prototype

iRet = Database.ExecuteBatchSQL(objDatabase ,sql, optionArgs)

Parameter Description

ParameterRequiredTypeDefaultDescription
objDatabaseTrueexpressionobjDatabaseDatabase object, a database object created using the Create Database Object command (Database.CreateDB)
sqlTruestring""Add/remove/modify a SQL statement
argsNoneexpression[]The SQL statement parameter. Traverse the two-dimensional array of the parameter and execute SQL statements in loops. For placeholder, MySQL and SQLServer uses %s. Sqlite3 uses ? and Oracle uses :1

return

iRet,The variable used to save the output of the command.

Demo

sql = "INSERT IGNORE INTO `test` (`name`, `age`, `aa`, `bb`) VALUES (%s, %s, %s, %s);" 
iRet = Database.ExecuteBatchSQL(objDatabase ,sql, {"args": [["test3", 12, 2, 2], ["test4", 12, 2, 2]]})
TracePrint(iRet)

// 2