def run_test_025(self): conn = ibm_db.connect(config.database, config.user, config.password) server = ibm_db.server_info(conn) if (conn != 0): drop = 'DROP TABLE test_primary_keys' try: result = ibm_db.exec_immediate(conn, drop) except: pass drop = 'DROP TABLE test_foreign_keys' try: result = ibm_db.exec_immediate(conn, drop) except: pass statement = 'CREATE TABLE test_primary_keys (id INTEGER NOT NULL, PRIMARY KEY(id))' result = ibm_db.exec_immediate(conn, statement) statement = "INSERT INTO test_primary_keys VALUES (1)" result = ibm_db.exec_immediate(conn, statement) statement = 'CREATE TABLE test_foreign_keys (idf INTEGER NOT NULL, FOREIGN KEY(idf) REFERENCES test_primary_keys(id))' result = ibm_db.exec_immediate(conn, statement) statement = "INSERT INTO test_foreign_keys VALUES (1)" result = ibm_db.exec_immediate(conn, statement) if (server.DBMS_NAME[0:3] == 'IDS'): stmt = ibm_db.primary_keys(conn, None, config.user, 'test_primary_keys') elif ('zos' in sys.platform): stmt = ibm_db.primary_keys(conn, None, config.user, 'TEST_PRIMARY_KEYS') else: stmt = ibm_db.primary_keys(conn, None, None, 'TEST_PRIMARY_KEYS') row = ibm_db.fetch_tuple(stmt) print(row[2]) print(row[3]) print(row[4]) ibm_db.close(conn) else: print(ibm_db.conn_errormsg()) print("Connection failed\n")
def run_test_025(self): conn = ibm_db.connect(config.database, config.user, config.password) server = ibm_db.server_info( conn ) if (conn != 0): drop = 'DROP TABLE test_primary_keys' try: result = ibm_db.exec_immediate(conn, drop) except: pass drop = 'DROP TABLE test_foreign_keys' try: result = ibm_db.exec_immediate(conn, drop) except: pass statement = 'CREATE TABLE test_primary_keys (id INTEGER NOT NULL, PRIMARY KEY(id))' result = ibm_db.exec_immediate(conn, statement) statement = "INSERT INTO test_primary_keys VALUES (1)" result = ibm_db.exec_immediate(conn, statement) statement = 'CREATE TABLE test_foreign_keys (idf INTEGER NOT NULL, FOREIGN KEY(idf) REFERENCES test_primary_keys(id))' result = ibm_db.exec_immediate(conn, statement) statement = "INSERT INTO test_foreign_keys VALUES (1)" result = ibm_db.exec_immediate(conn, statement) if (server.DBMS_NAME[0:3] == 'IDS'): stmt = ibm_db.primary_keys(conn, None, config.user, 'test_primary_keys') else: stmt = ibm_db.primary_keys(conn, None, None, 'TEST_PRIMARY_KEYS') row = ibm_db.fetch_tuple(stmt) print(row[2]) print(row[3]) print(row[4]) ibm_db.close(conn) else: print(ibm_db.conn_errormsg()) print("Connection failed\n")
# Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To A Db2 Database conn = Db2ConnectionMgr('DB', dbName, '', '', userID, passWord) conn.openConnection() if conn.returnCode is True: dbConnection = conn.connectionID else: conn.closeConnection() exit(-1) # Attempt To Retrieve Information About All Primary Keys That Have Been Defined For The # Table Specified print("Obtaining information about primary keys created for ", end="") print("the " + schemaName + "." + tableName + " table ... ", end="") try: resultSet = ibm_db.primary_keys(dbConnection, None, schemaName, tableName) except Exception: pass # If The Information Desired Could Not Be Retrieved, Display An Error Message And Exit if resultSet is False: print("\nERROR: Unable to obtain the information desired\n.") conn.closeConnection() exit(-1) # Otherwise, Complete The Status Message else: print("Done!\n") # As Long As There Are Records (That Were Produced By The ibm_db.primary_keys API), ... noData = False