def run_test_createdbNX(self): database = 'test001' conn_str = "DATABASE=%s;HOSTNAME=%s;PORT=%d;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % (database, config.hostname, config.port, config.user, config.password) conn_str_attach = "attach=true;HOSTNAME=%s;PORT=%d;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % (config.hostname, config.port, config.user, config.password) #for create db or drop db API it is nessesory that connection only attach to the DB server not to any existing database of DB server conn_attach = ibm_db.connect(conn_str_attach, '', '') if conn_attach: conn = False try: conn = ibm_db.connect(conn_str, '', '') except: pass if conn: ibm_db.close(conn) conn = False try: ibm_db.dropdb(conn_attach, database) except: print('Errors occurred during drop database') try: # call createdbNX without codeset argument when specified database not exeist rc = ibm_db.createdbNX(conn_attach, database) if rc: conn = ibm_db.connect(conn_str, '', '') if conn: print('database created sucessfully') ibm_db.close(conn) conn = False else: print('database is not created') else: print('Error occurred during create db if not exist') conn = ibm_db.connect(conn_str, '', '') if conn: ibm_db.close(conn) conn = False # call recreate db with codeset argument when specified database exist rc = ibm_db.createdbNX(conn_attach, database, 'iso88591') if rc: conn = ibm_db.connect(conn_str, '', '') server_info = ibm_db.server_info( conn ) if conn and (server_info.DB_CODEPAGE != 819): print('database with codeset created sucessfully') ibm_db.close(conn) conn = False else: print('Database not created') else: print('Error occurred during create db if not exist with codeset') #drop database rc = ibm_db.dropdb(conn_attach, database) if rc: try: conn = ibm_db.connect(conn_str, '', '') except: print('datbase droped sucessfully') if conn: print('Errors occurred during drop database') ibm_db.close(conn) conn = False else: print('Errors occurred during drop database') except: print(ibm_db.conn_errormsg()) pass ibm_db.close(conn_attach) else: print(ibm_db.conn_errormsg())
def run_test_createdbNX(self): database = 'test001' conn_str = "DATABASE=%s;HOSTNAME=%s;PORT=%d;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % (database, config.hostname, config.port, config.user, config.password) conn_str_attach = "attach=true;HOSTNAME=%s;PORT=%d;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % (config.hostname, config.port, config.user, config.password) #for create db or drop db API it is nessesory that connection only attach to the DB server not to any existing database of DB server conn_attach = ibm_db.connect(conn_str_attach, '', '') if conn_attach: conn = False try: conn = ibm_db.connect(conn_str, '', '') except: pass if conn: ibm_db.close(conn) conn = False try: ibm_db.dropdb(conn_attach, database) except: print 'Errors occurred during drop database' try: # call createdbNX without codeset argument when specified database not exeist rc = ibm_db.createdbNX(conn_attach, database) if rc: conn = ibm_db.connect(conn_str, '', '') if conn: print 'database created sucessfully' ibm_db.close(conn) conn = False else: print 'database is not created' else: print 'Error occurred during create db if not exist' conn = ibm_db.connect(conn_str, '', '') if conn: ibm_db.close(conn) conn = False # call recreate db with codeset argument when specified database exist rc = ibm_db.createdbNX(conn_attach, database, 'iso88591') if rc: conn = ibm_db.connect(conn_str, '', '') server_info = ibm_db.server_info( conn ) if conn and (server_info.DB_CODEPAGE != 819): print 'database with codeset created sucessfully' ibm_db.close(conn) conn = False else: print 'Database not created' else: print 'Error occurred during create db if not exist with codeset' #drop database rc = ibm_db.dropdb(conn_attach, database) if rc: try: conn = ibm_db.connect(conn_str, '', '') except: print 'datbase droped sucessfully' if conn: print 'Errors occurred during drop database' ibm_db.close(conn) conn = False else: print 'Errors occurred during drop database' except: print ibm_db.conn_errormsg() pass ibm_db.close(conn_attach) else: print ibm_db.conn_errormsg()
continue # Otherwise, Display A "Connection Ready" Status Message else: print(" Connection {:>2} ready!".format(loopCounter + 1)) # Add A Blank Line To The End Of The List Of Connections Created print() # Attempt To Create A New Database At The Remote Server Using Connection Number Five if not svrConnection[5] is None: print("Creating a database named " + dbName + " using Connection 5. Please wait.") currentConnection = svrConnection[5] try: returnCode = ibm_db.createdbNX(currentConnection, dbName) except Exception: pass # If The Database Could Not Be Created, Display An Error Message And Exit if returnCode is None: print("ERROR: Unable to create the " + dbName + " database.\n") errorMsg = ibm_db.conn_errormsg(svrConnection) print(errorMsg + "\n") # Otherwise, Display A Status Message Indicating The Database Was Created else: print("\nThe database \"" + dbName + "\" has been created!\n") # Attempt To Close The Db2 Server Connection (Connection 5) print("Closing Db2 server Connection 5 ... ", end="")
returnCode = False # Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To The Local Db2 Server conn = Db2ConnectionMgr('LOCAL_SVR', '', '', '', userID, passWord) conn.openConnection() if conn.returnCode is True: svrConnection = conn.connectionID else: conn.closeConnection() exit(-1) # Attempt To Create A New Database At The Local Server print("Creating a database named " + dbName + " at the local server. Please wait.") try: returnCode = ibm_db.createdbNX(svrConnection, dbName) except Exception: pass # If The Database Could Not Be Created, Display An Error Message And Exit if returnCode is False: print("ERROR: Unable to create the " + dbName + " database.\n") errorMsg = ibm_db.conn_errormsg(svrConnection) print(errorMsg + "\n") conn.closeConnection() exit(-1) # Otherwise, Display A Status Message else: print("\nThe database \"" + dbName + "\" has been created!\n") query_sdb_dir(dbName)