def __init__DB2(backend, host, port, username, password, database, sslmode, sslrootcert): """ Establish and check the connection so we can wrap it and handle exceptions. """ # __DB2 global object created here and pushed into the global namespace. global __DB2 try: my_db = __DB2 except NameError: # __DB2 has not been set up db_class = dbi.get_database_class(backend=backend) __DB2 = db_class(host, port, username, password, database, sslmode, sslrootcert) __DB2.connect() return else: del my_db if __DB2.is_connected_to(backend, host, port, username, password, database, sslmode, sslrootcert): __DB2.check_connection() return __DB2.commit() __DB2.close() # now we have to get a different connection __DB2 = dbi.get_database_class(backend=backend)( host, port, username, password, database, sslmode, sslrootcert) __DB2.connect() return 0
def __init__DB2(backend, host, port, username, password, database, sslmode, sslrootcert): """ Establish and check the connection so we can wrap it and handle exceptions. """ # __DB2 global object created here and pushed into the global namespace. global __DB2 try: my_db = __DB2 except NameError: # __DB2 has not been set up db_class = dbi.get_database_class(backend=backend) __DB2 = db_class(host, port, username, password, database, sslmode, sslrootcert) __DB2.connect() return else: del my_db if __DB2.is_connected_to(backend, host, port, username, password, database, sslmode, sslrootcert): __DB2.check_connection() return __DB2.commit() __DB2.close() # now we have to get a different connection __DB2 = dbi.get_database_class(backend=backend)(host, port, username, password, database, sslmode, sslrootcert) __DB2.connect() return 0