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_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_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_101(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: result = ifx_db.exec_immediate( conn, "insert into t_string values(123,1.222333,'one to one')") if result: cols = ifx_db.num_fields(result) print "col: %d" % cols rows = ifx_db.num_rows(result) print "affected row: %d" % rows result = ifx_db.exec_immediate(conn, "delete from t_string where a=123") if result: cols = ifx_db.num_fields(result) print "col: %d" % cols rows = ifx_db.num_rows(result) print "affected row: %d" % rows else: print "no connection"
def run_test_017(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: result = ifx_db.exec_immediate( conn, "SELECT * from animals WHERE weight < 10.0", {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_KEYSET_DRIVEN}) if result: rows = ifx_db.num_rows(result) print "affected row:", rows else: print ifx_db.stmt_errormsg() result = ifx_db.exec_immediate( conn, "SELECT * from animals WHERE weight < 10.0", {ifx_db.SQL_ATTR_CURSOR_TYPE: ifx_db.SQL_CURSOR_FORWARD_ONLY}) if result: rows = ifx_db.num_rows(result) print "affected row:", rows else: print ifx_db.stmt_errormsg() result = ifx_db.exec_immediate( conn, "SELECT * from animals WHERE weight < 10.0", { ifx_db.SQL_ATTR_ROWCOUNT_PREFETCH: ifx_db.SQL_ROWCOUNT_PREFETCH_ON }) if result: rows = ifx_db.num_rows(result) print "affected row:", rows else: print ifx_db.stmt_errormsg() result = ifx_db.exec_immediate( conn, "SELECT * from animals WHERE weight < 10.0", { ifx_db.SQL_ATTR_ROWCOUNT_PREFETCH: ifx_db.SQL_ROWCOUNT_PREFETCH_OFF }) if result: rows = ifx_db.num_rows(result) 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_011(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, "DELETE FROM animals WHERE weight > 10.0") print "Number of affected rows: %d" % ifx_db.num_rows(stmt) ifx_db.rollback(conn) ifx_db.close(conn) else: print "Connection failed."
def run_test_003(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF) sql = 'UPDATE animals SET id = 9' res = ifx_db.exec_immediate(conn, sql) print "Number of affected rows: %d" % ifx_db.num_rows(res) ifx_db.rollback(conn) ifx_db.close(conn) else: print "Connection failed."
def run_test_264(self): # Make a connection conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: 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) # Drop the tab_bigint table, in case it exists drop = 'DROP TABLE tab_bigint' result = '' try: result = ifx_db.exec_immediate(conn, drop) except: pass # Create the tab_bigint table if (server.DBMS_NAME[0:3] == 'IDS'): create = "CREATE TABLE tab_bigint (col1 INT8, col2 INT8, col3 INT8, col4 INT8)" else: create = "CREATE TABLE tab_bigint (col1 BIGINT, col2 BIGINT, col3 BIGINT, col4 BIGINT)" result = ifx_db.exec_immediate(conn, create) insert = "INSERT INTO tab_bigint values (-9223372036854775807, 9223372036854775807, 0, NULL)" res = ifx_db.exec_immediate(conn, insert) print "Number of inserted rows:", ifx_db.num_rows(res) stmt = ifx_db.prepare(conn, "SELECT * FROM tab_bigint") ifx_db.execute(stmt) data = ifx_db.fetch_both(stmt) while ( data ): print data[0] print data[1] print data[2] print data[3] print type(data[0]) is long print type(data[1]) is long print type(data[2]) is long data = ifx_db.fetch_both(stmt) # test ifx_db.result for fetch of bigint stmt1 = ifx_db.prepare(conn, "SELECT col2 FROM tab_bigint") ifx_db.execute(stmt1) ifx_db.fetch_row(stmt1, 0) if (server.DBMS_NAME[0:3] != 'IDS'): row1 = ifx_db.result(stmt1, 'COL2') else: row1 = ifx_db.result(stmt1, 'col2') print row1 ifx_db.close(conn)
def run_test_015(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: result = ifx_db.exec_immediate(conn,"insert into t_string values(123,1.222333,'one to one')") if result: cols = ifx_db.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 = ifx_db.num_rows(result) print "affected row:", rows else: print ifx_db.stmt_errormsg() result = ifx_db.exec_immediate(conn,"delete from t_string where a=123") 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() ifx_db.close(conn) else: print "no connection:", ifx_db.conn_errormsg()
def run_test_016(self): conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: result = ifx_db.exec_immediate( conn, "insert into t_string values(123,1.222333,'one to one')") 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() result = ifx_db.exec_immediate(conn, "delete from t_string where a=123") 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() ifx_db.close(conn) else: print "no connection:", ifx_db.conn_errormsg()
def run_test_311(self): # Make a connection conn = ifx_db.connect(config.ConnStr, config.user, config.password) if conn: ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_ON) # Drop the tab_num_literals table, in case it exists drop = 'DROP TABLE tab_num_literals' result = '' try: result = ifx_db.exec_immediate(conn, drop) except: pass # Create the animal table create = "CREATE TABLE tab_num_literals (col1 INTEGER, col2 FLOAT, col3 DECIMAL(7,2))" result = ifx_db.exec_immediate(conn, create) insert = "INSERT INTO tab_num_literals values ('11.22', '33.44', '55.66')" res = ifx_db.exec_immediate(conn, insert) print "Number of inserted rows:", ifx_db.num_rows(res) stmt = ifx_db.prepare( conn, "SELECT col1, col2, col3 FROM tab_num_literals WHERE col1 = '11'" ) ifx_db.execute(stmt) data = ifx_db.fetch_both(stmt) while (data): print data[0] print data[1] print data[2] data = ifx_db.fetch_both(stmt) sql = "UPDATE tab_num_literals SET col1 = 77 WHERE col2 = 33.44" res = ifx_db.exec_immediate(conn, sql) print "Number of updated rows:", ifx_db.num_rows(res) stmt = ifx_db.prepare( conn, "SELECT col1, col2, col3 FROM tab_num_literals WHERE col2 > '33'" ) ifx_db.execute(stmt) data = ifx_db.fetch_both(stmt) while (data): print data[0] print data[1] print data[2] data = ifx_db.fetch_both(stmt) sql = "DELETE FROM tab_num_literals WHERE col1 > '10.0'" res = ifx_db.exec_immediate(conn, sql) print "Number of deleted rows:", ifx_db.num_rows(res) stmt = ifx_db.prepare( conn, "SELECT col1, col2, col3 FROM tab_num_literals WHERE col3 < '56'" ) ifx_db.execute(stmt) data = ifx_db.fetch_both(stmt) while (data): print data[0] print data[1] print data[2] data = ifx_db.fetch_both(stmt) ifx_db.rollback(conn) ifx_db.close(conn)