Reading rows from a table¶
Reading rows from a table¶
1# This script shows how to use the IDatabaseQuery object to read rows from a table using a simple SQL
2# select statement.
3
4ui = impact.gui
5ot = ui.output_toolbox
6
7db = impact.active_database
8
9ot.clear()
10
11# IDatabaseConnection for current impact database
12c = db.connection
13
14ot.add("Connection Name: " + str(c.connection_name))
15ot.add("Connection Type: " + str(c.connection_type))
16ot.add("DBMS Type: " + str(c.dbms_type))
17ot.add("DBMS version: " + str(c.dbms_version.as_string))
18
19q = c.create_query()
20
21# assign some SQL
22q.sql = "select T_KEY, T_TEST from TEST order by T_KEY"
23
24if q.open():
25 ot.add("Successfully opened query: '" + str(q.sql) + "'")
26
27 count = 0
28
29 # iterate all rows retreived by the IDatabaseQuery
30 while not q.is_eof:
31 count = count + 1
32
33 # output values from T_KEY and T_NAME columns
34 ot.add("Row " + str(count) + ": T_KEY=" + str(q.column(1)).value + ", T_TEST='" + q.column("T_TEST").value + "'")
35
36 # move to next row
37 if not q.move_next():
38 ot.add("Failed to move to next record")
39 break
40
41 ot.add("Successfully read " + str(count) + " rows")
42
43 if q.close():
44 ot.add("Successfully closed query")
45
46else:
47 ot.add("Unable to open query")
48
49
50