def run_test_116(self): conn = None is_alive = ifx_db.active(conn) if is_alive: print "Is active" else: print "Is not active" conn = ifx_db.connect(config.ConnStr, config.user, config.password) is_alive = ifx_db.active(conn) if is_alive: print "Is active" else: print "Is not active" ifx_db.close(conn) is_alive = ifx_db.active(conn) if is_alive: print "Is active" else: print "Is not active" # Executing active method multiple times to reproduce a customer reported defect print ifx_db.active(conn) print ifx_db.active(conn) print ifx_db.active(conn) conn = ifx_db.connect(config.ConnStr, config.user, config.password) print ifx_db.active(conn) print ifx_db.active(conn) print ifx_db.active(conn)
def run_test_054(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) serverinfo = ifx_db.server_info(conn) stmt = ifx_db.exec_immediate(conn, "SELECT * FROM animals") val = ifx_db.get_option(stmt, ifx_db.SQL_ATTR_CURSOR_TYPE, 0) print val op = {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_FORWARD_ONLY} stmt = ifx_db.exec_immediate(conn, "SELECT * FROM animals", op) val = ifx_db.get_option(stmt, ifx_db.SQL_ATTR_CURSOR_TYPE, 0) print val if (serverinfo.DBMS_NAME[0:3] != 'IDS'): op = {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN} else: op = {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_STATIC} stmt = ifx_db.exec_immediate(conn, "SELECT * FROM animals", op) val = ifx_db.get_option(stmt, ifx_db.SQL_ATTR_CURSOR_TYPE, 0) print val op = {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_STATIC} stmt = ifx_db.exec_immediate(conn, "SELECT * FROM animals", op) val = ifx_db.get_option(stmt, ifx_db.SQL_ATTR_CURSOR_TYPE, 0) print val
def run_test_113(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: drop = "DROP TABLE datetest" try: ifx_db.exec_immediate( conn, drop ) except: pass create = "CREATE TABLE datetest ( id INTEGER, mydate DATE )" ifx_db.exec_immediate(conn, create) insert = "INSERT INTO datetest (id, mydate) VALUES (1,'03-27-1982')" ifx_db.exec_immediate(conn, insert) insert = "INSERT INTO datetest (id, mydate) VALUES (2,'07-08-1981')" ifx_db.exec_immediate(conn, insert) stmt = ifx_db.prepare(conn, "SELECT * FROM datetest") ifx_db.execute(stmt) result = ifx_db.fetch_row( stmt ) while ( result ): row0 = ifx_db.result(stmt, 0) row1 = ifx_db.result(stmt, 1) print row0 print row1 result = ifx_db.fetch_row( stmt ) else: print "Connection failed."
def run_test_142(self): sql = "SELECT id, breed, name, weight FROM animals WHERE weight < ? AND weight > ?" conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: stmt = ifx_db.prepare(conn, sql) weight = 200.05 mass = 2.0 ifx_db.bind_param(stmt, 1, weight, ifx_db.SQL_PARAM_INPUT) ifx_db.bind_param(stmt, 2, mass, ifx_db.SQL_PARAM_INPUT) result = ifx_db.execute(stmt) if ( result ): row = ifx_db.fetch_tuple(stmt) while ( row ): #row.each { |child| print child } for i in row: print i row = ifx_db.fetch_tuple(stmt) ifx_db.close(conn) else: print "Connection failed."
def run_test_112(self): os.environ['DELIMIDENT'] = 'y' conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: drop = "DROP TABLE ftest" try: ifx_db.exec_immediate(conn, drop) except: pass create = "CREATE TABLE ftest ( \"TEST\" INTEGER, \"test\" INTEGER, \"Test\" INTEGER )" ifx_db.exec_immediate(conn, create) insert = "INSERT INTO ftest VALUES (1,2,3)" ifx_db.exec_immediate(conn, insert) stmt = ifx_db.exec_immediate(conn, "SELECT * FROM ftest") num1 = ifx_db.field_num(stmt, "TEST") num2 = ifx_db.field_num(stmt, 'test') num3 = ifx_db.field_num(stmt, 'Test') print "int(%d)" % num1 print "int(%d)" % num2 print "int(%d)" % num3 else: print "Connection failed."
def run_test_022(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: stmt = ifx_db.exec_immediate(conn, "SELECT count(*) FROM animals") res = ifx_db.fetch_tuple(stmt) rows = res[0] print rows ifx_db.autocommit(conn, 0) ac = ifx_db.autocommit(conn) if ac != 0: print "Cannot set ifx_db.AUTOCOMMIT_OFF\nCannot run test" #continue ifx_db.exec_immediate( conn, "INSERT INTO animals values (7,'bug','Brain Bug',10000.1)") stmt = ifx_db.exec_immediate(conn, "SELECT count(*) FROM animals") res = ifx_db.fetch_tuple(stmt) rows = res[0] print rows ifx_db.rollback(conn) stmt = ifx_db.exec_immediate(conn, "SELECT count(*) FROM animals") res = ifx_db.fetch_tuple(stmt) rows = res[0] print rows ifx_db.close(conn) else: print "Connection failed."
def run_test_037(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) serverinfo = ifx_db.server_info(conn) result = ifx_db.exec_immediate(conn, "SELECT * FROM staff WHERE id < 101") row = ifx_db.fetch_row(result) while (row): if (serverinfo.DBMS_NAME[0:3] != 'IDS'): result2 = ifx_db.prepare(conn, "SELECT * FROM staff WHERE id < 101", { ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN }) else: result2 = ifx_db.prepare(conn, "SELECT * FROM staff WHERE id < 101") ifx_db.execute(result2) row2 = ifx_db.fetch_row(result2) while (row2): print "%s : %s : %s : %s : %s" % (ifx_db.result(result2, 0), \ ifx_db.result(result2, 1), \ ifx_db.result(result2, 2), \ ifx_db.result(result2, 3), \ ifx_db.result(result2, 5)) row2 = ifx_db.fetch_row(result2) row = ifx_db.fetch_row(result)
def run_test_152(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info(conn) if (server.DBMS_NAME[0:3] == 'Inf'): op = {ifx_db.ATTR_CASE: ifx_db.CASE_UPPER} ifx_db.set_option(conn, op, 1) result = ifx_db.exec_immediate(conn, "select * from project") row = ifx_db.fetch_assoc(result) while (row): #printf("%6s ",row['PROJNO']) #printf("%-24s ",row['PROJNAME']) #printf("%3s ",row['DEPTNO']) #printf("%6s",row['RESPEMP']) #printf("%7s ",row['PRSTAFF']) #printf("%10s ",row['PRSTDATE']) #printf("%10s ",row['PRENDATE']) #printf("%6s",row['MAJPROJ']) #puts "" if (row['MAJPROJ'] == None): row['MAJPROJ'] = '' print "%6s %-24s %3s %6s%7s %10s %10s %6s" % ( row['PROJNO'], row['PROJNAME'], row['DEPTNO'], row['RESPEMP'], row['PRSTAFF'], row['PRSTDATE'], row['PRENDATE'], row['MAJPROJ']) row = ifx_db.fetch_assoc(result)
def run_test_spinout_timestamp(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) # Get the server type serverinfo = ifx_db.server_info(conn) if conn: drop = "DROP PROCEDURE PROC_TIMESTAMP" try: result = ifx_db.exec_immediate(conn, drop) except: pass # Create the SP with timestamp parameters create = "CREATE PROCEDURE PROC_TIMESTAMP ( INOUT PAR1 DATETIME YEAR TO FRACTION(5), OUT PAR2 DATETIME YEAR TO FRACTION(5)) LET PAR2 = PAR1; END PROCEDURE" result = ifx_db.exec_immediate(conn, create) # call the SP. Expect PAR2 to contain value passed to PAR1 par1 = "2017-05-13 22:47:29.82688" par2 = "" print "Values of bound parameters _before_ CALL:" print " 1: %s 2: %s\n" % (par1, par2) stmt, par1, par2 = ifx_db.callproc(conn, 'proc_timestamp', (par1, par2)) if stmt is not None: print "Values of bound parameters _after_ CALL:" print " 1: %s 2: %s\n" % (par1, par2) ifx_db.close(conn) else: print("Connection failed.")
def run_test_120(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info( conn ) if conn: stmt = ifx_db.exec_immediate(conn, "SELECT * FROM animals") name1 = ifx_db.field_name(stmt, 1) name2 = ifx_db.field_name(stmt, 2) name3 = ifx_db.field_name(stmt, 3) name4 = ifx_db.field_name(stmt, 4) name6 = ifx_db.field_name(stmt, 8) name7 = ifx_db.field_name(stmt, 0) if (server.DBMS_NAME[0:3] == 'IDS'): name5 = ifx_db.field_name(stmt, "id") name8 = ifx_db.field_name(stmt, "WEIGHT") else: name5 = ifx_db.field_name(stmt, "ID") name8 = ifx_db.field_name(stmt, "weight") print "string(%d) \"%s\"" % (len(name1), name1) print "string(%d) \"%s\"" % (len(name2), name2) print "string(%d) \"%s\"" % (len(name3), name3) print "%s" % name4 print "string(%d) \"%s\"" % (len(name5), name5) print "%s" % name6 print "string(%d) \"%s\"" % (len(name7), name7) print "%s" % name8 else: print "Connection failed."
def run_test_312(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF) query = "INSERT INTO department (deptno, deptname, mgrno, admrdept, location) VALUES (?, ?, ?, ?, ?)" if conn: stmt = ifx_db.prepare(conn, query) params = ['STG', 'Systems & Technology', '123456', 'RSF', 'Fiji'] print("Binding parameters") for i, p in enumerate(params, 1): ifx_db.bind_param(stmt, i, Wrapper(p)) if ifx_db.execute(stmt): print("Executing statement") ifx_db.execute(stmt) # force the cache to be unbound for i, p in enumerate(params, 1): ifx_db.bind_param(stmt, i, p) ifx_db.rollback(conn) else: print("Connection failed.")
def run_test_157(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info(conn) if conn: sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed" if (server.DBMS_NAME[0:3] != 'IDS'): result = ifx_db.exec_immediate(conn, sql, { ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN }) else: result = ifx_db.exec_immediate( conn, sql, {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_STATIC}) i = 2 row = ifx_db.fetch_assoc(result, i) while (row): if (server.DBMS_NAME[0:3] == 'IDS'): print "%-5d %-16s %-32s %10s\n" % ( row['id'], row['name'], row['breed'], row['weight']) else: print "%-5d %-16s %-32s %10s\n" % ( row['ID'], row['NAME'], row['BREED'], row['WEIGHT']) i = i + 2 row = ifx_db.fetch_assoc(result, i)
def run_test_091(self): try: conn = ifx_db.connect(config.ConnStr, "y", config.password) print "??? No way." except: err = ifx_db.conn_errormsg() print err[0:68]
def run_test_004(self): try: conn = ifx_db.connect("sample", "not_a_user", "inv_pass") except: print "connect failed, test succeeded" return -1 print "connect succeeded? Test failed"
def run_test_240(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) result = ifx_db.exec_immediate(conn, "select * from sales") result2 = ifx_db.exec_immediate(conn, "select * from staff") result3 = ifx_db.exec_immediate(conn, "select * from emp_photo") for i in range(0, ifx_db.num_fields(result)): print str(i) + ":" + str(ifx_db.field_width(result, i)) print "\n-----" for i in range(0, ifx_db.num_fields(result2)): print str(i) + ":" + str( ifx_db.field_width(result2, ifx_db.field_name(result2, i))) print "\n-----" for i in range(0, 3): print str(i) + ":" + str(ifx_db.field_width( result3, i)) + "," + str(ifx_db.field_display_size(result3, i)) print "\n-----" print "region:%s" % ifx_db.field_type(result, 'region') print "5:%s" % ifx_db.field_type(result2, 5)
def run_test_6561(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF) stmt = ifx_db.exec_immediate( conn, "INSERT INTO animals (id, breed, name, weight) VALUES (null, null, null, null)" ) statement = "SELECT count(id) FROM animals" result = ifx_db.exec_immediate(conn, statement) if ((not result) and ifx_db.stmt_error()): print "ERROR: %s" % (ifx_db.stmt_errormsg(), ) row = ifx_db.fetch_tuple(result) while (row): for i in row: print i row = ifx_db.fetch_tuple(result) ifx_db.rollback(conn) ifx_db.close(conn) else: print "Connection failed."
def run_test_161(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info(conn) if (server.DBMS_NAME[0:3] == 'IDS'): op = {ifx_db.ATTR_CASE: ifx_db.CASE_UPPER} ifx_db.set_option(conn, op, 1) result = ifx_db.exec_immediate( conn, "select * from emp_act order by projno desc") row = ifx_db.fetch_both(result) count = 1 while (row): print "Record", count, ": %6s %-6s %3d %9s %10s %10s %6s " % ( row[0], row[1], row[2], row['EMPTIME'], row['EMSTDATE'], row['EMENDATE'], row[0]) result2 = ifx_db.exec_immediate( conn, "select * from employee where employee.empno='" + row['EMPNO'] + "'") row2 = ifx_db.fetch_both(result2) if row2: print ">>%s,%s,%s,%s,%s,%s,%s" % ( row2['EMPNO'], row2['FIRSTNME'], row2['MIDINIT'], row2[3], row2[3], row2[5], row2[6]) count = count + 1 if (count > 10): break row = ifx_db.fetch_both(result)
def run_test_157a(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info(conn) print "Starting..." if conn: sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed" result = ifx_db.exec_immediate(conn, sql) try: i = 2 row = ifx_db.fetch_assoc(result, i) while (row): if (server.DBMS_NAME[0:3] == 'IDS'): print "%-5d %-16s %-32s %10s" % ( row['id'], row['name'], row['breed'], row['weight']) else: print "%-5d %-16s %-32s %10s" % ( row['ID'], row['NAME'], row['BREED'], row['WEIGHT']) i = i + 2 row = ifx_db.fetch_assoc(result, i) except: print "SQLSTATE: %s" % ifx_db.stmt_error(result) print "Message: %s" % ifx_db.stmt_errormsg(result) print "DONE"
def run_test_018(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_ON) if conn: stmt = ifx_db.prepare(conn, "SELECT * from animals WHERE weight < 10.0" ) ifx_db.set_option(stmt, {ifx_db.SQL_ATTR_ROWCOUNT_PREFETCH : ifx_db.SQL_ROWCOUNT_PREFETCH_ON}, 2) result = ifx_db.execute(stmt) if result: rows = ifx_db.num_rows(stmt) print "affected row:", rows ifx_db.free_result(stmt) else: print ifx_db.stmt_errormsg() ifx_db.set_option(stmt, {ifx_db.SQL_ATTR_ROWCOUNT_PREFETCH : ifx_db.SQL_ROWCOUNT_PREFETCH_OFF}, 2) result = ifx_db.execute(stmt) if result: rows = ifx_db.num_rows(stmt) print "affected row:", rows ifx_db.free_result(stmt) else: print ifx_db.stmt_errormsg() ifx_db.set_option(stmt, {ifx_db.SQL_ATTR_ROWCOUNT_PREFETCH : ifx_db.SQL_ROWCOUNT_PREFETCH_ON}, 2) result = ifx_db.execute(stmt) if result: rows = ifx_db.num_rows(stmt) print "affected row:", rows else: print ifx_db.stmt_errormsg() ifx_db.close(conn) else: print "no connection:", ifx_db.conn_errormsg()
def run_test_144(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: # Drop the test table, in case it exists drop = 'DROP TABLE pictures' try: result = ifx_db.exec_immediate(conn, drop) except: pass # Create the test table create = 'CREATE TABLE pictures (id INTEGER, picture BLOB)' result = ifx_db.exec_immediate(conn, create) stmt = ifx_db.prepare(conn, "INSERT INTO pictures VALUES (0, ?)") picture = os.path.dirname(os.path.abspath(__file__)) + "/pic1.jpg" rc = ifx_db.bind_param(stmt, 1, picture, ifx_db.SQL_PARAM_INPUT, ifx_db.SQL_BINARY) rc = ifx_db.execute(stmt) num = ifx_db.num_rows(stmt) print num else: print "Connection failed."
def run_test_124(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: result = ifx_db.exec_immediate( conn, "select * from staff, employee, org where employee.lastname in ('HAAS','THOMPSON', 'KWAN', 'GEYER', 'STERN', 'PULASKI', 'HENDERSON', 'SPENSER', 'LUCCHESSI', 'OCONNELL', 'QUINTANA', 'NICHOLLS', 'ADAMSON', 'PIANKA', 'YOSHIMURA', 'SCOUTTEN', 'WALKER', 'BROWN', 'JONES', 'LUTZ', 'JEFFERSON', 'MARINO', 'SMITH', 'JOHNSON', 'PEREZ', 'SCHNEIDER', 'PARKER', 'SMITH', 'SETRIGHT', 'MEHTA', 'LEE', 'GOUNOT') order by org.location,employee.lastname,staff.id" ) cols = ifx_db.num_fields(result) j = 0 row = ifx_db.fetch_both(result) while (row): for i in range(0, cols): field = ifx_db.field_name(result, i) value = row[ifx_db.field_name(result, i)] if (value == None): value = '' print "%s:%s" % (field, value) print "---------" j += 1 if (j == 10): break row = ifx_db.fetch_both(result) ifx_db.close(conn) print "done" else: print ifx_db.conn_errormsg()
def run_test_143(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF) insert1 = "INSERT INTO animals (id, breed, name, weight) VALUES (NULL, 'ghost', NULL, ?)" select = 'SELECT id, breed, name, weight FROM animals WHERE weight IS NULL' if conn: stmt = ifx_db.prepare(conn, insert1) animal = None ifx_db.bind_param(stmt, 1, animal) if ifx_db.execute(stmt): stmt = ifx_db.exec_immediate(conn, select) row = ifx_db.fetch_tuple(stmt) while ( row ): #row.each { |child| print child } for i in row: print i row = ifx_db.fetch_tuple(stmt) ifx_db.rollback(conn) else: print "Connection failed."
def run_test_014(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) serverinfo = ifx_db.server_info(conn) query = 'SELECT * FROM animals ORDER BY name' if (serverinfo.DBMS_NAME[0:3] != 'Inf'): stmt = ifx_db.prepare( conn, query, {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN}) else: stmt = ifx_db.prepare(conn, query) ifx_db.execute(stmt) data = ifx_db.fetch_both(stmt) while (data): print "%s : %s : %s : %s\n" % (data[0], data[1], data[2], data[3]) data = ifx_db.fetch_both(stmt) try: stmt = ifx_db.prepare( conn, query, {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN}) ifx_db.execute(stmt) rc = ifx_db.fetch_row(stmt, -1) print "Fetch row -1: %s" % str(rc) except: print "Requested row number must be a positive value" ifx_db.close(conn)
def run_test_147(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF) stmt = ifx_db.prepare( conn, "INSERT INTO animals (id, breed, name) VALUES (?, ?, ?)") id = "\"999\"" breed = None name = 'PythonDS' try: ifx_db.bind_param(stmt, 1, id) ifx_db.bind_param(stmt, 2, breed) ifx_db.bind_param(stmt, 3, name) error = ifx_db.execute(stmt) print "Should not make it this far" except: excp = sys.exc_info() # slot 1 contains error message print excp[1] else: print "Connection failed."
def run_test_039(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) serverinfo = ifx_db.server_info(conn) if (serverinfo.DBMS_NAME[0:3] != 'Inf'): result = ifx_db.prepare( conn, "SELECT * FROM animals", {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN}) else: result = ifx_db.prepare(conn, "SELECT * FROM animals") ifx_db.execute(result) row = ifx_db.fetch_row(result) while (row): if (serverinfo.DBMS_NAME[0:3] != 'Inf'): result2 = ifx_db.prepare(conn, "SELECT * FROM animals", { ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN }) else: result2 = ifx_db.prepare(conn, "SELECT * FROM animals") ifx_db.execute(result2) while (ifx_db.fetch_row(result2)): print "%s : %s : %s : %s" % (ifx_db.result(result2, 0), \ ifx_db.result(result2, 1), \ ifx_db.result(result2, 2), \ ifx_db.result(result2, 3)) row = ifx_db.fetch_row(result)
def run_test_03a(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info( conn ) if conn: stmt = ifx_db.exec_immediate(conn, "SELECT id, breed, name, weight FROM animals WHERE id = 0") while ( ifx_db.fetch_row(stmt) ): breed = ifx_db.result(stmt, 1) print "string(%d) \"%s\"" % (len(breed), breed) if (server.DBMS_NAME[0:3] == 'IDS'): name = ifx_db.result(stmt, "name") else: name = ifx_db.result(stmt, "NAME") print "string(%d) \"%s\"" % (len(name), name) # following field does not exist in result set if (server.DBMS_NAME[0:3] == 'IDS'): name = ifx_db.result(stmt, "passport") else: name = ifx_db.result(stmt, "PASSPORT") print name ifx_db.close(conn) else: print "Connection failed."
def run_test_180(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: result = '' result2 = '' try: result = ifx_db.exec_immediate( conn, "insert int0 t_string values(123,1.222333,'one to one')") except: pass if result: cols = ifx_db.num_fields(result) print "col:", cols, ", " rows = ifx_db.num_rows(result) print "affected row:", rows else: print ifx_db.stmt_errormsg() try: result = ifx_db.exec_immediate( conn, "delete from t_string where a=123") except: pass if result: cols = ifx_db.num_fields(result) print "col:", cols, ", " rows = ifx_db.num_rows(result) print "affected row:", rows else: print ifx_db.stmt_errormsg() else: print "no connection"
def run_test_082(self): try: conn = ifx_db.connect(config.ConnStr, config.user, "z") print "??? No way." except: err = ifx_db.conn_error() print err
def run_test_150(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) server = ifx_db.server_info(conn) if (server.DBMS_NAME[0:3] == 'IDS'): op = {ifx_db.ATTR_CASE: ifx_db.CASE_UPPER} ifx_db.set_option(conn, op, 1) result = ifx_db.exec_immediate(conn, "select * from staff") row = ifx_db.fetch_assoc(result) while (row): #print "%5d " % row['ID'] #print "%-10s " % row['NAME'] #print "%5d " % row['DEPT'] #print "%-7s " % row['JOB'] #print "%5d " % row['YEARS'] #print "%15s " % row['SALARY'] #print "%10s " % row['COMM'] if (row['YEARS'] == None): row['YEARS'] = 0 if (row['COMM'] == None): row['COMM'] = '' print "%5d %-10s %5d %-7s %5s %15s %10s " % ( row['ID'], row['NAME'], row['DEPT'], row['JOB'], row['YEARS'], row['SALARY'], row['COMM']) row = ifx_db.fetch_assoc(result)
def run_test_020(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: stmt = ifx_db.exec_immediate(conn, "SELECT count(*) FROM animals") res = ifx_db.fetch_tuple(stmt) rows = res[0] print rows ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF) ac = ifx_db.autocommit(conn) if ac != 0: print "Cannot set ifx_db.SQL_AUTOCOMMIT_OFF\nCannot run test" #continue ifx_db.exec_immediate(conn, "DELETE FROM animals") stmt = ifx_db.exec_immediate(conn, "SELECT count(*) FROM animals") res = ifx_db.fetch_tuple(stmt) rows = res[0] print rows ifx_db.rollback(conn) stmt = ifx_db.exec_immediate(conn, "SELECT count(*) FROM animals") res = ifx_db.fetch_tuple(stmt) rows = res[0] print rows ifx_db.close(conn) else: print "Connection failed."