def run_test_116(self): conn = None is_alive = IfxPy.active(conn) if is_alive: print("Is active") else: print("Is not active") conn = IfxPy.connect(config.ConnStr, config.user, config.password) is_alive = IfxPy.active(conn) if is_alive: print("Is active") else: print("Is not active") IfxPy.close(conn) is_alive = IfxPy.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(IfxPy.active(conn)) print(IfxPy.active(conn)) print(IfxPy.active(conn)) conn = IfxPy.connect(config.ConnStr, config.user, config.password) print(IfxPy.active(conn)) print(IfxPy.active(conn)) print(IfxPy.active(conn))
def run_test_114(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: drop = "drop table numericliteral" try: IfxPy.exec_immediate( conn, drop ) except: pass create = "create table numericliteral ( id INTEGER, num INTEGER )" IfxPy.exec_immediate(conn, create) insert = "INSERT INTO numericliteral (id, num) values (1,5)" IfxPy.exec_immediate(conn, insert) insert = "UPDATE numericliteral SET num = '10' WHERE num = '5'" IfxPy.exec_immediate(conn, insert) stmt = IfxPy.prepare(conn, "SELECT * FROM numericliteral") IfxPy.execute(stmt) result = IfxPy.fetch_row( stmt ) while ( result ): row0 = IfxPy.result(stmt, 0) row1 = IfxPy.result(stmt, 1) print row0 print row1 result = IfxPy.fetch_row( stmt ) else: print "Connection failed."
def run_test_038(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) serverinfo = IfxPy.server_info(conn) if (serverinfo.DBMS_NAME[0:3] != 'Inf'): result = IfxPy.exec_immediate( conn, "SELECT * FROM staff WHERE id < 101", {IfxPy.SQL_ATTR_CURSOR_TYPE: IfxPy.SQL_CURSOR_KEYSET_DRIVEN}) else: result = IfxPy.exec_immediate( conn, "SELECT * FROM staff WHERE id < 101") row = IfxPy.fetch_row(result) while (row): if (serverinfo.DBMS_NAME[0:3] != 'Inf'): result2 = IfxPy.prepare(conn, "SELECT * FROM staff WHERE id < 101", { IfxPy.SQL_ATTR_CURSOR_TYPE: IfxPy.SQL_CURSOR_KEYSET_DRIVEN }) else: result2 = IfxPy.prepare(conn, "SELECT * FROM staff WHERE id < 101") IfxPy.execute(result2) row2 = IfxPy.fetch_row(result2) while (row2): print "%s : %s : %s : %s : %s\n" % (IfxPy.result(result2, 0), \ IfxPy.result(result2, 1), \ IfxPy.result(result2, 2), \ IfxPy.result(result2, 3), \ IfxPy.result(result2, 5)) row2 = IfxPy.fetch_row(result2) row = IfxPy.fetch_row(result)
def run_test_022(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: stmt = IfxPy.exec_immediate(conn, "SELECT count(*) FROM animals") res = IfxPy.fetch_tuple(stmt) rows = res[0] print rows IfxPy.autocommit(conn, 0) ac = IfxPy.autocommit(conn) if ac != 0: print "Cannot set IfxPy.AUTOCOMMIT_OFF\nCannot run test" #continue IfxPy.exec_immediate( conn, "INSERT INTO animals values (7,'bug','Brain Bug',10000.1)") stmt = IfxPy.exec_immediate(conn, "SELECT count(*) FROM animals") res = IfxPy.fetch_tuple(stmt) rows = res[0] print rows IfxPy.rollback(conn) stmt = IfxPy.exec_immediate(conn, "SELECT count(*) FROM animals") res = IfxPy.fetch_tuple(stmt) rows = res[0] print rows IfxPy.close(conn) else: print "Connection failed."
def run_test_147(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: IfxPy.autocommit(conn, IfxPy.SQL_AUTOCOMMIT_OFF) stmt = IfxPy.prepare( conn, "INSERT INTO animals (id, breed, name) VALUES (?, ?, ?)") id = "\"999\"" breed = None name = 'PythonDS' try: IfxPy.bind_param(stmt, 1, id) IfxPy.bind_param(stmt, 2, breed) IfxPy.bind_param(stmt, 3, name) error = IfxPy.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_092(self): try: conn = IfxPy.connect(config.ConnStr, config.user, "z") print("??? No way.") except: err = IfxPy.conn_errormsg() print(err[0:68])
def run_test_150(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) server = IfxPy.server_info( conn ) if (server.DBMS_NAME[0:3] == 'Inf'): op = {IfxPy.ATTR_CASE: IfxPy.CASE_UPPER} IfxPy.set_option(conn, op, 1) result = IfxPy.exec_immediate(conn, "select * from staff") row = IfxPy.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 = IfxPy.fetch_assoc(result)
def run_test_004(self): try: conn = IfxPy.connect("sample", "not_a_user", "inv_pass") except: print("connect failed, test succeeded") return -1 print("connect succeeded? Test failed")
def run_test_006(self): options1 = {IfxPy.SQL_ATTR_CURSOR_TYPE: IfxPy.SQL_CURSOR_KEYSET_DRIVEN} options2 = {IfxPy.SQL_ATTR_CURSOR_TYPE: IfxPy.SQL_CURSOR_FORWARD_ONLY} conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: serverinfo = IfxPy.server_info(conn) if (serverinfo.DBMS_NAME[0:3] == 'Inf'): options1 = options2 stmt = IfxPy.prepare( conn, "SELECT name FROM animals WHERE weight < 10.0", options2) IfxPy.execute(stmt) data = IfxPy.fetch_both(stmt) while (data): print(data[0]) data = IfxPy.fetch_both(stmt) print("") stmt = IfxPy.prepare( conn, "SELECT name FROM animals WHERE weight < 10.0", options1) IfxPy.execute(stmt) data = IfxPy.fetch_both(stmt) while (data): print(data[0]) data = IfxPy.fetch_both(stmt) IfxPy.close(conn) else: print("Connection failed.")
def run_test_warn(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: drop = "DROP TABLE TEST1" try: result = IfxPy.exec_immediate(conn, drop) except: pass # Create the table test1 create = "CREATE TABLE TEST1 (COL1 CHAR(5))" result = IfxPy.exec_immediate(conn, create) # Insert a string longer than 5 characters to force an error # IfxPy.stmt_warn() API query = 'INSERT INTO TEST1 VALUES (?)' stmt = IfxPy.prepare(conn, query) try: IfxPy.execute(stmt, ('ABCDEF', )) except: pass print((IfxPy.stmt_warn(stmt))) IfxPy.close(conn) else: print("Connection failed.")
def run_test_110(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) server = IfxPy.server_info(conn) if conn: stmt = IfxPy.exec_immediate( conn, "SELECT * FROM animals ORDER BY breed") num1 = IfxPy.field_num(stmt, "id") num2 = IfxPy.field_num(stmt, "breed") num3 = IfxPy.field_num(stmt, "name") num4 = IfxPy.field_num(stmt, "weight") num5 = IfxPy.field_num(stmt, "test") num6 = IfxPy.field_num(stmt, 8) num7 = IfxPy.field_num(stmt, 1) num8 = IfxPy.field_num(stmt, "WEIGHT") print("int(%d)" % num1) print("int(%d)" % num2) print("int(%d)" % num3) print("int(%d)" % num4) print("%s" % num5) print("%s" % num6) print("int(%d)" % num7) print("%s" % num8) else: print("Connection failed.")
def run_test_091(self): try: conn = IfxPy.connect(config.ConnStr, "y", config.password) print("??? No way.") except: err = IfxPy.conn_errormsg() print(err[0:68])
def run_test_018(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) IfxPy.autocommit(conn, IfxPy.SQL_AUTOCOMMIT_ON) if conn: stmt = IfxPy.prepare(conn, "SELECT * from animals WHERE weight < 10.0" ) IfxPy.set_option(stmt, {IfxPy.SQL_ATTR_ROWCOUNT_PREFETCH : IfxPy.SQL_ROWCOUNT_PREFETCH_ON}, 2) result = IfxPy.execute(stmt) if result: rows = IfxPy.num_rows(stmt) print("affected row:", rows) IfxPy.free_result(stmt) else: print(IfxPy.stmt_errormsg()) IfxPy.set_option(stmt, {IfxPy.SQL_ATTR_ROWCOUNT_PREFETCH : IfxPy.SQL_ROWCOUNT_PREFETCH_OFF}, 2) result = IfxPy.execute(stmt) if result: rows = IfxPy.num_rows(stmt) print("affected row:", rows) IfxPy.free_result(stmt) else: print(IfxPy.stmt_errormsg()) IfxPy.set_option(stmt, {IfxPy.SQL_ATTR_ROWCOUNT_PREFETCH : IfxPy.SQL_ROWCOUNT_PREFETCH_ON}, 2) result = IfxPy.execute(stmt) if result: rows = IfxPy.num_rows(stmt) print("affected row:", rows) else: print(IfxPy.stmt_errormsg()) IfxPy.close(conn) else: print("no connection:", IfxPy.conn_errormsg())
def run_test_161(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) server = IfxPy.server_info(conn) if (server.DBMS_NAME[0:3] == 'Inf'): op = {IfxPy.ATTR_CASE: IfxPy.CASE_UPPER} IfxPy.set_option(conn, op, 1) result = IfxPy.exec_immediate( conn, "select * from emp_act order by projno desc") row = IfxPy.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 = IfxPy.exec_immediate( conn, "select * from employee where employee.empno='" + row['EMPNO'] + "'") row2 = IfxPy.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 = IfxPy.fetch_both(result)
def run_test_312(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) IfxPy.autocommit(conn, IfxPy.SQL_AUTOCOMMIT_OFF) query = "INSERT INTO department (deptno, deptname, mgrno, admrdept, location) VALUES (?, ?, ?, ?, ?)" if conn: stmt = IfxPy.prepare(conn, query) params = ['STG', 'Systems & Technology', '123456', 'RSF', 'Fiji'] print("Binding parameters") for i, p in enumerate(params, 1): IfxPy.bind_param(stmt, i, Wrapper(p)) if IfxPy.execute(stmt): print("Executing statement") IfxPy.execute(stmt) # force the cache to be unbound for i, p in enumerate(params, 1): IfxPy.bind_param(stmt, i, p) IfxPy.rollback(conn) else: print("Connection failed.")
def run_test_112(self): os.environ['DELIMIDENT'] = 'y' conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: drop = "DROP TABLE ftest" try: IfxPy.exec_immediate(conn, drop) except: pass create = "CREATE TABLE ftest ( \"TEST\" INTEGER, \"test\" INTEGER, \"Test\" INTEGER )" IfxPy.exec_immediate(conn, create) insert = "INSERT INTO ftest VALUES (1,2,3)" IfxPy.exec_immediate(conn, insert) stmt = IfxPy.exec_immediate(conn, "SELECT * FROM ftest") num1 = IfxPy.field_num(stmt, "TEST") num2 = IfxPy.field_num(stmt, 'test') num3 = IfxPy.field_num(stmt, 'Test') print("int(%d)" % num1) print("int(%d)" % num2) print("int(%d)" % num3) else: print("Connection failed.")
def run_test_124(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: result = IfxPy.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 = IfxPy.num_fields(result) j = 0 row = IfxPy.fetch_both(result) while (row): for i in range(0, cols): field = IfxPy.field_name(result, i) value = row[IfxPy.field_name(result, i)] if (value == None): value = '' print("%s:%s" % (field, value)) print("---------") j += 1 if (j == 10): break row = IfxPy.fetch_both(result) IfxPy.close(conn) print("done") else: print(IfxPy.conn_errormsg())
def run_test_015(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: result = IfxPy.exec_immediate( conn, "insert into t_string values(123,1.222333,'one to one')") if result: cols = IfxPy.num_fields(result) # NOTE: Removed '\n' from the following and a few more prints here (refer to ruby test_015.rb) print "col:", cols rows = IfxPy.num_rows(result) print "affected row:", rows else: print IfxPy.stmt_errormsg() result = IfxPy.exec_immediate(conn, "delete from t_string where a=123") if result: cols = IfxPy.num_fields(result) print "col:", cols rows = IfxPy.num_rows(result) print "affected row:", rows else: print IfxPy.stmt_errormsg() IfxPy.close(conn) else: print "no connection:", IfxPy.conn_errormsg()
def run_test_020(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: stmt = IfxPy.exec_immediate(conn, "SELECT count(*) FROM animals") res = IfxPy.fetch_tuple(stmt) rows = res[0] print(rows) IfxPy.autocommit(conn, IfxPy.SQL_AUTOCOMMIT_OFF) ac = IfxPy.autocommit(conn) if ac != 0: print("Cannot set IfxPy.SQL_AUTOCOMMIT_OFF\nCannot run test") #continue IfxPy.exec_immediate(conn, "DELETE FROM animals") stmt = IfxPy.exec_immediate(conn, "SELECT count(*) FROM animals") res = IfxPy.fetch_tuple(stmt) rows = res[0] print(rows) IfxPy.rollback(conn) stmt = IfxPy.exec_immediate(conn, "SELECT count(*) FROM animals") res = IfxPy.fetch_tuple(stmt) rows = res[0] print(rows) IfxPy.close(conn) else: print("Connection failed.")
def run_test_142(self): sql = "SELECT id, breed, name, weight FROM animals WHERE weight < ? AND weight > ?" conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: stmt = IfxPy.prepare(conn, sql) weight = 200.05 mass = 2.0 IfxPy.bind_param(stmt, 1, weight, IfxPy.SQL_PARAM_INPUT) IfxPy.bind_param(stmt, 2, mass, IfxPy.SQL_PARAM_INPUT) result = IfxPy.execute(stmt) if (result): row = IfxPy.fetch_tuple(stmt) while (row): #row.each { |child| print child } for i in row: print i row = IfxPy.fetch_tuple(stmt) IfxPy.close(conn) else: print "Connection failed."
def run_test_180(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: result = '' result2 = '' try: result = IfxPy.exec_immediate( conn, "insert int0 t_string values(123,1.222333,'one to one')") except: pass if result: cols = IfxPy.num_fields(result) print("col:", cols, ", ") rows = IfxPy.num_rows(result) print("affected row:", rows) else: print(IfxPy.stmt_errormsg()) try: result = IfxPy.exec_immediate( conn, "delete from t_string where a=123") except: pass if result: cols = IfxPy.num_fields(result) print("col:", cols, ", ") rows = IfxPy.num_rows(result) print("affected row:", rows) else: print(IfxPy.stmt_errormsg()) else: print("no connection")
def run_test_113(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) if conn: drop = "DROP TABLE datetest" try: IfxPy.exec_immediate(conn, drop) except: pass create = "CREATE TABLE datetest ( id INTEGER, mydate DATE )" IfxPy.exec_immediate(conn, create) insert = "INSERT INTO datetest (id, mydate) VALUES (1,'03-27-1982')" IfxPy.exec_immediate(conn, insert) insert = "INSERT INTO datetest (id, mydate) VALUES (2,'07-08-1981')" IfxPy.exec_immediate(conn, insert) stmt = IfxPy.prepare(conn, "SELECT * FROM datetest") IfxPy.execute(stmt) result = IfxPy.fetch_row(stmt) while (result): row0 = IfxPy.result(stmt, 0) row1 = IfxPy.result(stmt, 1) print row0 print row1 result = IfxPy.fetch_row(stmt) else: print "Connection failed."
def run_test_313(self): # Make a connection conn = IfxPy.connect(config.ConnStr, config.user, config.password) # Get the server type server = IfxPy.server_info(conn) try: sql = "drop table collection_tab;" stmt = IfxPy.exec_immediate(conn, sql) except: pass SetupSqlSet = [ "create table collection_tab ( col1 int, s1 SET(float not null), m1 MULTISET(char(20) not null), l1 LIST(bigint not null)) ;", "insert into collection_tab values( 1, SET{11.10, 12.11}, MULTISET{'Hey', 'Hell'}, LIST{120, -120});", "insert into collection_tab values( 2, SET{13.11, 14.20}, MULTISET{'Jhon', 'Nick'}, LIST{130, -130});", "insert into collection_tab values( 3, SET{14.21, 14.00}, MULTISET{'Dave', 'Mill'}, LIST{140, -141});", "insert into collection_tab values( 4, SET{15.0, 16}, MULTISET{'Mon', 'Phebee'}, LIST{150, -150});" ] i = 0 for sql in SetupSqlSet: i += 1 stmt = IfxPy.exec_immediate(conn, sql) sql = "select * from collection_tab;" stmt = IfxPy.exec_immediate(conn, sql) tu = IfxPy.fetch_tuple(stmt) rc = 0 while tu != False: rc += 1 tu = IfxPy.fetch_tuple(stmt) print("Collection Data Access complete")
def run_test_143(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) IfxPy.autocommit(conn, IfxPy.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 = IfxPy.prepare(conn, insert1) animal = None IfxPy.bind_param(stmt, 1, animal) if IfxPy.execute(stmt): stmt = IfxPy.exec_immediate(conn, select) row = IfxPy.fetch_tuple(stmt) while ( row ): #row.each { |child| print child } for i in row: print(i) row = IfxPy.fetch_tuple(stmt) IfxPy.rollback(conn) else: print("Connection failed.")
def run_test_152(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) server = IfxPy.server_info(conn) if (server.DBMS_NAME[0:3] == 'Inf'): op = {IfxPy.ATTR_CASE: IfxPy.CASE_UPPER} IfxPy.set_option(conn, op, 1) result = IfxPy.exec_immediate(conn, "select * from project") row = IfxPy.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 = IfxPy.fetch_assoc(result)
def run_test_300(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) server = IfxPy.server_info(conn) if server: print("DBMS_NAME: string(%d) \"%s\"" % (len(server.DBMS_NAME), server.DBMS_NAME)) print("DBMS_VER: string(%d) \"%s\"" % (len(server.DBMS_VER), server.DBMS_VER)) print("DB_NAME: string(%d) \"%s\"" % (len(server.DB_NAME), server.DB_NAME)) print("INST_NAME: string(%d) \"%s\"" % (len(server.INST_NAME), server.INST_NAME)) print("SPECIAL_CHARS: string(%d) \"%s\"" % (len(server.SPECIAL_CHARS), server.SPECIAL_CHARS)) print("KEYWORDS: int(%d)" % len(server.KEYWORDS)) print("DFT_ISOLATION: string(%d) \"%s\"" % (len(server.DFT_ISOLATION), server.DFT_ISOLATION)) il = '' for opt in server.ISOLATION_OPTION: il += opt + " " print("ISOLATION_OPTION: string(%d) \"%s\"" % (len(il), il)) print("SQL_CONFORMANCE: string(%d) \"%s\"" % (len(server.SQL_CONFORMANCE), server.SQL_CONFORMANCE)) print("PROCEDURES:", server.PROCEDURES) print("IDENTIFIER_QUOTE_CHAR: string(%d) \"%s\"" % (len(server.IDENTIFIER_QUOTE_CHAR), server.IDENTIFIER_QUOTE_CHAR)) print("LIKE_ESCAPE_CLAUSE:", server.LIKE_ESCAPE_CLAUSE) print("MAX_COL_NAME_LEN: int(%d)" % server.MAX_COL_NAME_LEN) print("MAX_ROW_SIZE: int(%d)" % server.MAX_ROW_SIZE) print("MAX_IDENTIFIER_LEN: int(%d)" % server.MAX_IDENTIFIER_LEN) print("MAX_INDEX_SIZE: int(%d)" % server.MAX_INDEX_SIZE) print("MAX_PROC_NAME_LEN: int(%d)" % server.MAX_PROC_NAME_LEN) print("MAX_SCHEMA_NAME_LEN: int(%d)" % server.MAX_SCHEMA_NAME_LEN) print("MAX_STATEMENT_LEN: int(%d)" % server.MAX_STATEMENT_LEN) print("MAX_TABLE_NAME_LEN: int(%d)" % server.MAX_TABLE_NAME_LEN) print("NON_NULLABLE_COLUMNS:", server.NON_NULLABLE_COLUMNS) IfxPy.close(conn) else: print("Error.")
def run_test_231(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) result = IfxPy.exec_immediate(conn, "select * from sales") result2 = IfxPy.exec_immediate(conn, "select * from staff") result3 = IfxPy.exec_immediate(conn, "select * from emp_photo") for i in range(0, IfxPy.num_fields(result) + 1): print str(i) + ":" + str( IfxPy.field_type(result, IfxPy.field_name(result, i))) print "\n-----" for i in range(0, IfxPy.num_fields(result2)): print str(i) + ":" + IfxPy.field_type(result2, IfxPy.field_name(result2, i)) print "\n-----" for i in range(0, 3): print str(i) + ":" + IfxPy.field_type(result3, IfxPy.field_name(result3, i)) print "\n-----" print "region:%s" % IfxPy.field_type(result, 'region') print "5:%s" % IfxPy.field_type(result2, 5)
def run_test_040(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) IfxPy.autocommit(conn, IfxPy.SQL_AUTOCOMMIT_OFF) # Drop the test table, in case it exists drop = 'DROP TABLE animals' try: result = IfxPy.exec_immediate(conn, drop) except: pass # Create the test table create = 'CREATE TABLE animals (id INTEGER, breed VARCHAR(32), name CHAR(16), weight DECIMAL(7,2))' result = IfxPy.exec_immediate(conn, create) insert = "INSERT INTO animals values (0, 'cat', 'Pook', 3.2)" IfxPy.exec_immediate(conn, insert) stmt = IfxPy.exec_immediate(conn, "select * from animals") onerow = IfxPy.fetch_tuple(stmt) for element in onerow: print(element) IfxPy.rollback(conn)
def run_test_spinout_timestamp(self): conn = IfxPy.connect(config.ConnStr, config.user, config.password) # Get the server type serverinfo = IfxPy.server_info(conn) if conn: drop = "DROP PROCEDURE PROC_TIMESTAMP" try: result = IfxPy.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 = IfxPy.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 = IfxPy.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) IfxPy.close(conn) else: print("Connection failed.")
def run_test_157(self): conn = IfxPy.connect(config.ConnStr + 'ENABLESCROLLABLECURSORS=1', config.user, config.password) server = IfxPy.server_info(conn) if conn: sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed" if (server.DBMS_NAME[0:3] != 'Inf'): result = IfxPy.exec_immediate(conn, sql, { IfxPy.SQL_ATTR_CURSOR_TYPE: IfxPy.SQL_CURSOR_KEYSET_DRIVEN }) else: result = IfxPy.exec_immediate( conn, sql, {IfxPy.SQL_ATTR_CURSOR_TYPE: IfxPy.SQL_CURSOR_STATIC}) i = 2 row = IfxPy.fetch_assoc(result, i) while (row): if (server.DBMS_NAME[0:3] == 'Inf'): 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 = IfxPy.fetch_assoc(result, i)