Example #1
0
    def run_test_6755(self):
        conn = IfxPy.connect(config.ConnStr, config.user, config.password)
        server = IfxPy.server_info(conn)

        if conn:
            drop = 'DROP TABLE table_6755'
            result = ''
            try:
                result = IfxPy.exec_immediate(conn, drop)
            except:
                pass

            if (server.DBMS_NAME[0:3] == 'Inf'):
                create = 'CREATE TABLE table_6755 (col1 VARCHAR(20), col2 CLOB)'
                insert = "INSERT INTO table_6755 VALUES ('database', 'database')"
            else:
                create = 'CREATE TABLE table_6755 (col1 VARCHAR(20), col2 CLOB(20))'
                insert = "INSERT INTO table_6755 VALUES ('database', 'database')"
            result = IfxPy.exec_immediate(conn, create)
            result = IfxPy.exec_immediate(conn, insert)
            statement = "SELECT col1, col2 FROM table_6755"

            result = IfxPy.prepare(conn, statement)
            IfxPy.execute(result)

            row = IfxPy.fetch_tuple(result)
            while (row):
                #printf("\"%s\" from VARCHAR is %d bytes long, \"%s\" from CLOB is %d bytes long.\n",
                #    row[0], row[0].length,
                #    row[1], row[1].length)
                print "\"%s\" from VARCHAR is %d bytes long, \"%s\" from CLOB is %d bytes long." % (
                    row[0], len(row[0]), row[1], len(row[1]))
                row = IfxPy.fetch_tuple(result)

            IfxPy.close(conn)
        else:
            print "Connection failed."
Example #2
0
def my_Sample():
    ConStr = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxxx;"

    try:
        # netstat -a | findstr  9088
        conn = IfxPy.connect(ConStr, "", "")
    except Exception as e:
        print('ERROR: Connect failed')
        print(e)
        quit()

    try:
        sql = "drop table t1;"
        print(sql)
        stmt = IfxPy.exec_immediate(conn, sql)
    except:
        print('FYI: drop table failed')

    sql = "create table t1 ( c1 int, c2 char(20), c3 int, c4 int ) ;"
    stmt = IfxPy.exec_immediate(conn, sql)

    sql = "INSERT INTO t1 (c1, c2, c3, c4) VALUES ( ?, ?, ?, ? )"
    stmt = IfxPy.prepare(conn, sql)

    c1 = None
    c2 = None
    c3 = None
    c4 = None
    # Create bindings for the parameter
    IfxPy.bind_param(stmt, 1, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)
    IfxPy.bind_param(stmt, 2, c2, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_CHAR)
    IfxPy.bind_param(stmt, 3, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)
    IfxPy.bind_param(stmt, 4, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)

    print("Inserting Recors ......")
    i = 0
    while i < 10:
        i += 1
        c1 = 100 + i
        c2 = "Testing {0}".format(i)
        c3 = 20000 + i
        c4 = 50000 + i
        # supply new values as a tuple
        IfxPy.execute(stmt, (c1, c2, c3, c4))

    # Try select those rows we have just inserted
    print("Selecting Recors ......")
    sql = "SELECT * FROM t1"
    stmt = IfxPy.exec_immediate(conn, sql)
    tu = IfxPy.fetch_tuple(stmt)
    rc = 0
    while tu != False:
        rc += 1
        print(tu)
        tu = IfxPy.fetch_tuple(stmt)

    print()
    print("Total Record Inserted {}".format(i))
    print("Total Record Selected {}".format(rc))

    # Free up memory used by result and then stmt too
    IfxPy.free_result(stmt)
    IfxPy.free_stmt(stmt)

    # close the connection
    IfxPy.close(conn)

    print("Done")
Example #3
0
    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.")
Example #4
0
def task2():
    print("Task 2 assigned to thread: {}".format(threading.current_thread().name))
    print("ID of process running task 2: {}".format(os.getpid()))
    #temp5 = IfxPy.register_smart_trigger_loop(conn, printme2, temp, "t2", "informix", "sheshdb", "select * from t2;", "label2", False, False)
    temp5 = IfxPy.register_smart_trigger_loop(conn, printme2, temp, "t2", "informix", "sheshdb_utf8", "select * from t2;", "label2", False, False)
Example #5
0
def task1():
    print("Task 1 assigned to thread: {}".format(threading.current_thread().name))
    print("ID of process running task 1: {}".format(os.getpid()))
    temp4 = IfxPy.register_smart_trigger_loop(conn, printme1, temp, "t1", "informix", "sheshdb", "select * from t1;", "label1", False, False)
Example #6
0
    print("ID of process running task 1: {}".format(os.getpid()))
    temp4 = IfxPy.register_smart_trigger_loop(conn, printme1, temp, "t1", "informix", "sheshdb", "select * from t1;", "label1", False, False)
    #temp4 = IfxPy.register_smart_trigger_loop(conn, printme1, temp, "बस", "informix", "sheshdb_utf8", "select * from बस;", "label1", False, False)
 
def task2():
    print("Task 2 assigned to thread: {}".format(threading.current_thread().name))
    print("ID of process running task 2: {}".format(os.getpid()))
    #temp5 = IfxPy.register_smart_trigger_loop(conn, printme2, temp, "t2", "informix", "sheshdb", "select * from t2;", "label2", False, False)
    temp5 = IfxPy.register_smart_trigger_loop(conn, printme2, temp, "t2", "informix", "sheshdb_utf8", "select * from t2;", "label2", False, False)
 
# if __name__ == "__main__":
             
# ConStr = "SERVER=ol_informix1410;DATABASE=sheshdb_utf8;HOST=127.0.0.1;SERVICE=1067;UID=informix;PWD=xxxx;DB_LOCALE=en_us.utf8;CLIENT_LOCALE=en_us.UTF8;"
ConStr = "SERVER=ol_informix1410;DATABASE=sheshdb;HOST=127.0.0.1;SERVICE=1067;UID=informix;PWD=xxx;"

conn = IfxPy.connect( ConStr, "", "")

temp = IfxPy.open_smart_trigger(conn, "Unique1", False, 5, 1, 0)
print ("\nFile descriptor = ", temp)
 
# creating threads
t1 = threading.Thread(target=task1, name='t1')
t2 = threading.Thread(target=task2, name='t2')  
 
# starting threads
t1.start()
t2.start()
 
# wait until all threads finish
t1.join()
t2.join()