예제 #1
0
    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_133(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)

        if (not conn):
            print "Connection failed."
            return 0

        ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF)

        print "Starting test ..."
        res = ''
        sql = "INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)"
        try:
            stmt = ifx_db.prepare(conn, sql)
            res = ifx_db.execute(
                stmt, (128, 'hacker of human and technological nature',
                       'Wez the ruler of all things PECL', 88.3))

            stmt = ifx_db.prepare(
                conn, "SELECT breed, name FROM animals WHERE id = ?")
            res = ifx_db.execute(stmt, (128, ))
            row = ifx_db.fetch_assoc(stmt)

            for i in row:
                print i

            ifx_db.rollback(conn)
            print "Done"
        except:
            print "SQLSTATE: %s" % ifx_db.stmt_error(stmt)
            print "Message: %s" % ifx_db.stmt_errormsg(stmt)

        try:
            stmt = ifx_db.prepare(
                conn, "SELECT breed, name FROM animals WHERE id = ?")
            res = ifx_db.execute(stmt, (128, ))
            row = ifx_db.fetch_assoc(stmt)
            if (row):
                for i in row:
                    print i
            print res
            print "SQLSTATE: %s" % ifx_db.stmt_error(stmt)
            print "Message: %s" % ifx_db.stmt_errormsg(stmt)
        except:
            print "An Exception is not expected"
            print "SQLSTATE: %s" % ifx_db.stmt_error(stmt)
            print "Message: %s" % ifx_db.stmt_errormsg(stmt)

        ifx_db.rollback(conn)
        print "Done"
 def run_test_045(self):
     conn = ifx_db.connect(config.ConnStr, config.user, config.password)
     fp = open("tests/pic1_out.jpg", "wb")
     result = ifx_db.exec_immediate(
         conn, "SELECT picture FROM animal_pics WHERE name = 'Helmut'")
     row = ifx_db.fetch_tuple(result)
     if row:
         fp.write(row[0])
     else:
         print ifx_db.stmt_errormsg()
     fp.close()
     cmp = (open('tests/pic1_out.jpg',
                 'rb').read() == open('tests/pic1.jpg', 'rb').read())
     print 'Are the files the same:', cmp
    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."
예제 #5
0
    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_048(self):
   conn = ifx_db.connect(config.ConnStr, config.user, config.password)
   if (not conn):
     print "Could not make a connection." 
     return 0
   server = ifx_db.server_info( conn )
   
   fp = open("tests/spook_out.png", "wb")
   result = ifx_db.exec_immediate(conn, "SELECT picture FROM animal_pics WHERE name = 'Spook'")
   if (not result):
     print "Could not execute SELECT statement."
     return 0
   row = ifx_db.fetch_tuple(result)
   if row:
     fp.write(row[0])
   else:
     print ifx_db.stmt_errormsg()
   fp.close()
   cmp = (open('tests/spook_out.png', "rb").read() == open('tests/spook.png', "rb").read())
   print "Are the files the same:", cmp
    def run_test_019(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.SQL_ATTR_ROWCOUNT_PREFETCH:
                                      ifx_db.SQL_ROWCOUNT_PREFETCH_ON
                                  })
            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.close(conn)
        else:
            print "no connection:", ifx_db.conn_errormsg()
 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()
예제 #9
0
 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_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_133(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)

        if (not conn):
            print "Connection failed."
            return 0

        ifx_db.autocommit(conn, ifx_db.SQL_AUTOCOMMIT_OFF)

        print "Starting test ..."
        res = ''
        sql = "INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)"
        try:
            stmt = ifx_db.prepare(conn, sql)
            res = ifx_db.execute(
                stmt, (128, 'hacker of human and technological nature',
                       'Wez the ruler of all things PECL', 88.3))

            stmt = ifx_db.prepare(
                conn, "SELECT breed, name FROM animals WHERE id = ?")
            res = ifx_db.execute(stmt, (128, ))
            row = ifx_db.fetch_assoc(stmt)

            for i in row:
                print i

            ifx_db.rollback(conn)
            print "Done"
        except:
            print "SQLSTATE: %s" % ifx_db.stmt_error(stmt)
            print "Message: %s" % ifx_db.stmt_errormsg(stmt)

        try:
            stmt = ifx_db.prepare(
                conn, "SELECT breed, name FROM animals WHERE id = ?")
            res = ifx_db.execute(stmt, (128, ))
            row = ifx_db.fetch_assoc(stmt)
            if (row):
                for i in row:
                    print i
            print res
            print "SQLSTATE: %s" % ifx_db.stmt_error(stmt)
            print "Message: %s" % ifx_db.stmt_errormsg(stmt)
        except:
            print "An Exception is not expected"
            print "SQLSTATE: %s" % ifx_db.stmt_error(stmt)
            print "Message: %s" % ifx_db.stmt_errormsg(stmt)

        ifx_db.rollback(conn)
        print "Done"


#__END__
#__LUW_EXPECTED__
#Starting test ...
#
#SQLSTATE: 22001
#Message: [IBM][CLI Driver] CLI0109E  String data right truncation. SQLSTATE=22001 SQLCODE=-99999
#True
#SQLSTATE: 02000
#Message: [IBM][CLI Driver][DB2/%s] SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.  SQLSTATE=02000 SQLCODE=100
#Done
#__ZOS_EXPECTED__
#Starting test ...
#
#SQLSTATE: 22001
#Message: [IBM][CLI Driver] CLI0109E  String data right truncation. SQLSTATE=22001 SQLCODE=-99999
#True
#SQLSTATE: 02000
#Message: [IBM][CLI Driver][DB2] SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.  SQLSTATE=02000 SQLCODE=100
#Done
#__SYSTEMI_EXPECTED__
#Starting test ...
#
#SQLSTATE: 22001
#Message: [IBM][CLI Driver] CLI0109E  String data right truncation. SQLSTATE=22001 SQLCODE=-99999
#True
#SQLSTATE: 02000
#Message: [IBM][CLI Driver][AS] SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.  SQLSTATE=02000 SQLCODE=100
#Done
#__IDS_EXPECTED__
#Starting test ...
#
#SQLSTATE: 22001
#Message: [IBM][CLI Driver][IDS%s] Value exceeds string column length. SQLCODE=-1279
#True
#SQLSTATE: 02000
#Message: [IBM][CLI Driver][IDS%s] SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.  SQLSTATE=02000 SQLCODE=100
#Done
예제 #12
0
  def run_test_024(self):
    conn = ifx_db.connect(config.ConnStr, config.user, config.password)
    server = ifx_db.server_info( conn )
     
    if conn != 0:
      drop = 'DROP TABLE test_primary_keys'
      try:
        result = ifx_db.exec_immediate(conn, drop)
      except:
        pass
      drop = 'DROP TABLE test_keys'
      try:
        result = ifx_db.exec_immediate(conn, drop)
      except:
        pass
      drop = 'DROP TABLE test_foreign_keys'
      try:
        result = ifx_db.exec_immediate(conn, drop)
      except:
        pass

      statement = 'CREATE TABLE test_primary_keys (id INTEGER NOT NULL, PRIMARY KEY(id))'
      result = ifx_db.exec_immediate(conn, statement)
      statement = "INSERT INTO test_primary_keys VALUES (1)"
      result = ifx_db.exec_immediate(conn, statement)
      statement = 'CREATE TABLE test_keys (name VARCHAR(30) NOT NULL, idf INTEGER NOT NULL, FOREIGN KEY(idf) REFERENCES test_primary_keys(id), \
                   PRIMARY KEY(name))'
      result = ifx_db.exec_immediate(conn, statement)
      statement = "INSERT INTO test_keys VALUES ('vince', 1)"
      result = ifx_db.exec_immediate(conn, statement)
      statement = 'CREATE TABLE test_foreign_keys (namef VARCHAR(30) NOT NULL, id INTEGER NOT NULL, FOREIGN KEY(namef) REFERENCES test_keys(name))'
      result = ifx_db.exec_immediate(conn, statement)
      statement = "INSERT INTO test_foreign_keys VALUES ('vince', 1)"
      result = ifx_db.exec_immediate(conn, statement)

      if (server.DBMS_NAME[0:3] == 'IDS'):
        stmt = ifx_db.foreign_keys(conn, None, config.user, 'test_primary_keys')
      else:
        stmt = ifx_db.foreign_keys(conn, None, None, 'TEST_PRIMARY_KEYS')
      row = ifx_db.fetch_tuple(stmt)
      print row[2]
      print row[3]
      print row[6]
      print row[7]

      if (server.DBMS_NAME[0:3] == 'IDS'):
        stmt = ifx_db.foreign_keys(conn, None, None, None, None, config.user, 'test_keys')
      else:
        stmt = ifx_db.foreign_keys(conn, None, None, None, None, None, 'TEST_KEYS')
      row = ifx_db.fetch_tuple(stmt)
      print row[2]
      print row[3]
      print row[6]
      print row[7]

      if (server.DBMS_NAME[0:3] == 'IDS'):
        stmt = ifx_db.foreign_keys(conn, None, config.user, 'test_keys', None, None, None)
      else:
        stmt = ifx_db.foreign_keys(conn, None, None, 'TEST_KEYS', None, None, None)
      row = ifx_db.fetch_tuple(stmt)
      print row[2]
      print row[3]
      print row[6]
      print row[7]

      if (server.DBMS_NAME[0:3] == 'IDS'):
        stmt = ifx_db.foreign_keys(conn, None, config.user, 'test_keys', None, config.user, 'test_foreign_keys')
      else:
        stmt = ifx_db.foreign_keys(conn, None, None, 'TEST_KEYS', None, None, 'TEST_FOREIGN_KEYS')
      row = ifx_db.fetch_tuple(stmt)
      print row[2]
      print row[3]
      print row[6]
      print row[7]

      try:
        stmt = ifx_db.foreign_keys(conn, None, None, None, None, None, None)
        row = ifx_db.fetch_tuple(stmt)
      except:
        if (not stmt):
          print ifx_db.stmt_errormsg()

      if (server.DBMS_NAME[0:3] == 'IDS'):
        stmt = ifx_db.foreign_keys(conn, None, config.user, 'test_keys', None, 'dummy_schema')
      else:
        stmt = ifx_db.foreign_keys(conn, None, None, 'TEST_KEYS', None, 'dummy_schema')
      row = ifx_db.fetch_tuple(stmt)
      if(not row):
        print "No Data Found"
      else:
        print row
      ifx_db.close(conn)
    else:
      print ifx_db.conn_errormsg()
      print "Connection failed\n"