Ejemplo n.º 1
0
  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()
Ejemplo n.º 2
0
    def run_test_064(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)
        server = ifx_db.server_info(conn)

        create = 'CREATE SCHEMA AUTHORIZATION t'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t1( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t2( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t3( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t4( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        if (server.DBMS_NAME[0:3] == 'IDS'):
            result = ifx_db.tables(conn, None, 't')
        else:
            result = ifx_db.tables(conn, None, 'T')

        for i in range(0, ifx_db.num_fields(result)):
            print "%s, " % ifx_db.field_name(result, i)
        print
        print

        i = 0
        row = ifx_db.fetch_tuple(result)
        while (row):
            ifx_db.num_fields(result)
            if (i < 4):
                print ", " + row[1] + ", " + row[2] + ", " + row[3] + ", , \n"
            i = i + 1
            row = ifx_db.fetch_tuple(result)

        ifx_db.free_result(result)

        ifx_db.exec_immediate(conn, 'DROP TABLE t.t1')
        ifx_db.exec_immediate(conn, 'DROP TABLE t.t2')
        ifx_db.exec_immediate(conn, 'DROP TABLE t.t3')
        ifx_db.exec_immediate(conn, 'DROP TABLE t.t4')
Ejemplo n.º 3
0
    def run_test_063(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)

        result = ifx_db.tables(conn, None, "SYSIBM", "", "VIEW")

        if (type(result) == ifx_db.IBM_DBStatement):
            print "Resource is a DB2 Statement"

        ifx_db.free_result(result)
Ejemplo n.º 4
0
    def run_test_065(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)
        server = ifx_db.server_info(conn)

        create = 'CREATE SCHEMA AUTHORIZATION t'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t1( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t2( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t3( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        create = 'CREATE TABLE t.t4( c1 integer, c2 varchar(40))'
        try:
            result = ifx_db.exec_immediate(conn, create)
        except:
            pass

        result = ifx_db.tables(conn, None, '%', "t3")
        columns = ifx_db.num_fields(result)

        for i in range(0, columns):
            print "%s, " % ifx_db.field_name(result, i)
        print "\n\n"

        row = ifx_db.fetch_tuple(result)
        while (row):
            final = ", " + row[1] + ", " + row[2] + ", " + row[3] + ", , "
            row = ifx_db.fetch_tuple(result)

        print final

        ifx_db.free_result(result)

        ifx_db.exec_immediate(conn, 'DROP TABLE t.t1')
        ifx_db.exec_immediate(conn, 'DROP TABLE t.t2')
        ifx_db.exec_immediate(conn, 'DROP TABLE t.t3')
        ifx_db.exec_immediate(conn, 'DROP TABLE t.t4')
Ejemplo n.º 5
0
    def run_test_250(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")

        r1 = ifx_db.free_result(result)
        r2 = ifx_db.free_result(result2)
        r3 = ifx_db.free_result(result3)

        print r1
        print r2
        print r3
Ejemplo n.º 6
0
    def run_test_251(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)

        result = ifx_db.exec_immediate(conn, "select * from sales")

        r1 = ifx_db.free_result(result)
        r2 = ifx_db.free_result(result)
        r3 = ''
        try:
            r3 = ifx_db.free_result(result99)
        except:
            r3 = None

        print r1
        print r2
        print r3
Ejemplo n.º 7
0
    def run_test_066(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)
        server = ifx_db.server_info(conn)

        if (server.DBMS_NAME[0:3] == 'IDS'):
            result = ifx_db.tables(conn, None, config.user.lower(), 'animals')
        else:
            result = ifx_db.tables(conn, None, config.user.upper(), 'ANIMALS')

#    NOTE: This is a workaround
#    function fetch_object() to be implemented...
#    row = ifx_db.fetch_object(result)

        class Row:
            pass

        data = ifx_db.fetch_assoc(result)
        while (data):
            row = Row()
            if (server.DBMS_NAME[0:3] == 'IDS'):
                row.table_schem = data['table_schem']
                row.table_name = data['table_name']
                row.table_type = data['table_type']
                row.remarks = data['remarks']

                print "Schema:  %s" % row.table_schem
                print "Name:    %s" % row.table_name
                print "Type:    %s" % row.table_type
                print "Remarks: %s\n" % row.remarks
            else:
                row.TABLE_SCHEM = data['TABLE_SCHEM']
                row.TABLE_NAME = data['TABLE_NAME']
                row.TABLE_TYPE = data['TABLE_TYPE']
                row.REMARKS = data['REMARKS']

                print "Schema:  %s" % row.TABLE_SCHEM
                print "Name:    %s" % row.TABLE_NAME
                print "Type:    %s" % row.TABLE_TYPE
                print "Remarks: %s\n" % row.REMARKS
#      row = ifx_db.fetch_object(result)
            data = ifx_db.fetch_assoc(result)

        if (server.DBMS_NAME[0:3] == 'IDS'):
            result = ifx_db.tables(conn, None, config.user.lower(),
                                   'animal_pics')
        else:
            result = ifx_db.tables(conn, None, config.user.upper(),
                                   'ANIMAL_PICS')

#    row = ifx_db.fetch_object(result)
        data = ifx_db.fetch_assoc(result)
        while (data):
            row = Row()
            if (server.DBMS_NAME[0:3] == 'IDS'):
                row.table_schem = data['table_schem']
                row.table_name = data['table_name']
                row.table_type = data['table_type']
                row.remarks = data['remarks']

                print "Schema:  %s" % row.table_schem
                print "Name:    %s" % row.table_name
                print "Type:    %s" % row.table_type
                print "Remarks: %s\n" % row.remarks
            else:
                row.TABLE_SCHEM = data['TABLE_SCHEM']
                row.TABLE_NAME = data['TABLE_NAME']
                row.TABLE_TYPE = data['TABLE_TYPE']
                row.REMARKS = data['REMARKS']

                print "Schema:  %s" % row.TABLE_SCHEM
                print "Name:    %s" % row.TABLE_NAME
                print "Type:    %s" % row.TABLE_TYPE
                print "Remarks: %s\n" % row.REMARKS
#      row = ifx_db.fetch_object(result)
            data = ifx_db.fetch_assoc(result)

        if (server.DBMS_NAME[0:3] == 'IDS'):
            result = ifx_db.tables(conn, None, config.user.lower(),
                                   'anime_cat')
        else:
            result = ifx_db.tables(conn, None, config.user.upper(),
                                   'ANIME_CAT')

#    row = ifx_db.fetch_object(result)
        data = ifx_db.fetch_assoc(result)
        while (data):
            row = Row()
            if (server.DBMS_NAME[0:3] == 'IDS'):
                row.table_schem = data['table_schem']
                row.table_name = data['table_name']
                row.table_type = data['table_type']
                row.remarks = data['remarks']

                print "Schema:  %s" % row.table_schem
                print "Name:    %s" % row.table_name
                print "Type:    %s" % row.table_type
                print "Remarks: %s\n" % row.remarks
            else:
                row.TABLE_SCHEM = data['TABLE_SCHEM']
                row.TABLE_NAME = data['TABLE_NAME']
                row.TABLE_TYPE = data['TABLE_TYPE']
                row.REMARKS = data['REMARKS']

                print "Schema:  %s" % row.TABLE_SCHEM
                print "Name:    %s" % row.TABLE_NAME
                print "Type:    %s" % row.TABLE_TYPE
                print "Remarks: %s\n" % row.REMARKS
#      row = ifx_db.fetch_object(result)
            data = ifx_db.fetch_assoc(result)

        ifx_db.free_result(result)
        ifx_db.close(conn)