Executing multiple lines of SQL

Executing multiple lines of SQL
 1# This script shows how to use the IDatabaseConnection object to execute an SQL script.
 2
 3ui = impact.gui
 4ot = ui.output_toolbox
 5
 6db = impact.active_database
 7
 8ot.clear()
 9
10# IDatabaseConnection for current impact database
11c = db.connection
12
13ot.add("Connection Name: " + str(c.connection_name))
14ot.add("Connection Type: " + str(c.connection_type))
15ot.add("DBMS Type: " + str(c.dbms_type))
16ot.add("DBMS version: " + str(c.dbms_version.as_string))
17
18# generate or load some lines of SQL statements to execute
19
20sql = "update TEST set T_TEST = 'Test 11' where T_KEY = 26" + "\r\n" + "update TEST set T_TEST = 'Test 12' where T_KEY = 27" + "\r\n" + "update TEST set T_TEST = 'Test 13' where T_KEY = 28" + "\r\n" + "update TEST set T_TEST = 'Test 14' where T_KEY = 29"
21
22# execute all lines in a single transaction. If no transaction is running then
23# a transaction will be automatically created. If a transaction is running then
24# it is up to the caller to commit or rollback the transaction
25if c.execute_sql_lines(sql, False):
26    ot.add("Successfully executed SQL lines")
27
28else:
29    ot.add("Failed to execute SQL lines")
30
31# execute each line in its own transaction. An error will occur if a transaction
32# is already running
33if c.execute_sql_lines(sql, True):
34    ot.add("Successfully executed SQL lines with individual transactions")
35
36else:
37    ot.add("Failed to execute SQL lines")
38
39
40