class SQLiteReverseEngineering(GenericReverseEngineering): @classmethod def getTargetDBMSName(cls): return 'SQLite' @classmethod def serverVersion(cls, connection): return cls._connections[connection.__id__]["version"] ######### Connection related functions ######### @classmethod def connect(cls, connection, password): '''Establishes a connection to the server and stores the connection object in the connections pool. It first looks for a connection with the given connection parameters in the connections pool to reuse existent connections. If such connection is found it queries the server to ensure that the connection is alive and reestablishes it if is dead. If no suitable connection is found in the connections pool, a new one is created and stored in the pool. Parameters: =========== connection: an object of the class db_mgmt_Connection storing the parameters for the connection. password: a string with the password to use for the connection (ignored for SQLite). ''' con = None try: con = cls.get_connection(connection) try: if not con.cursor().execute('SELECT 1'): raise Exception('connection error') except Exception, exc: grt.send_info( 'Connection to %s apparently lost, reconnecting...' % connection.hostIdentifier) raise NotConnectedError('Connection error') except NotConnectedError, exc: grt.send_info('Connecting to %s...' % connection.hostIdentifier) con = sqlite3.connect(connection.parameterValues['dbfile']) if not con: grt.send_error('Connection failed', str(exc)) raise connection.parameterValues[ 'wbcopytables_connection_string'] = "'" + connection.parameterValues[ 'dbfile'] + "'" grt.send_info('Connected') cls._connections[connection.__id__] = {'connection': con} if con: ver = cls.execute_query(connection, "SELECT sqlite_version()").fetchone()[0] grt.log_info('SQLite RE', 'Connected to %s, %s' % (connection.name, ver)) ver_parts = server_version_str2tuple(ver) + (0, 0, 0, 0) version = grt.classes.GrtVersion() version.majorNumber, version.minorNumber, version.releaseNumber, version.buildNumber = ver_parts[: 4] cls._connections[connection.__id__]['version'] = version return 1
def start(self): try: import pyodbc except ImportError: mforms.Utilities.show_message_and_remember('Dependency Warning', 'Could not import the pyodbc python module. You need pyodbc 2.1.8 or newer for migrations from RDBMSes other than MySQL.', 'OK', '', '', 'wb.migration.nopyodbc', "Don't show this message again") else: pyodbc_version = server_version_str2tuple(pyodbc.version) if pyodbc_version < (2, 1, 8): mforms.Utilities.show_message_and_remember('Dependency Warning', '''We have detected that you have pyodbc %s installed but the migration tool requires pyodbc 2.1.8 or newer for migrations from RDBMSes other than MySQL. Please install a supported pyodbc version. You may proceed with the currently installed version, but the migration may not succeed. To install the latest version of pyodbc, execute "sudo easy_install pyodbc" from a command line shell.''' % pyodbc.version, 'OK', '', '', 'wb.migration.oldpyodbc', "Don't show this message again") self.main.start()
def start(self): try: import pyodbc except ImportError: mforms.Utilities.show_message_and_remember( 'Dependency Warning', 'Could not import the pyodbc python module. You need pyodbc 2.1.8 or newer for migrations from RDBMSes other than MySQL.', 'OK', '', '', 'wb.migration.nopyodbc', "Don't show this message again") else: pyodbc_version = server_version_str2tuple(pyodbc.version) if pyodbc_version < (2, 1, 8): mforms.Utilities.show_message_and_remember( 'Dependency Warning', '''We have detected that you have pyodbc %s installed but the migration tool requires pyodbc 2.1.8 or newer for migrations from RDBMSes other than MySQL. Please install a supported pyodbc version. You may proceed with the currently installed version, but the migration may not succeed. To install the latest version of pyodbc, execute "sudo easy_install pyodbc" from a command line shell.''' % pyodbc.version, 'OK', '', '', 'wb.migration.oldpyodbc', "Don't show this message again") self.main.start()
conn_params = dict(params) conn_params['password'] = '******' connection.parameterValues['wbcopytables_connection_string'] = repr(conn_params) con = sqlanydb.connect(**params) else: con = db_driver.connect(connection, password) if not con: grt.send_error('Connection failed', str(exc)) raise grt.send_info('Connected') cls._connections[connection.__id__] = {'connection': con} if con: ver = cls.execute_query(connection, "SELECT @@version").fetchone()[0] grt.log_info("SQLAnywhere RE", "Connected to %s, %s\n" % (connection.name, ver)) ver_parts = server_version_str2tuple(ver) + (0, 0, 0, 0) version = grt.classes.GrtVersion() version.majorNumber, version.minorNumber, version.releaseNumber, version.buildNumber = ver_parts[:4] cls._connections[connection.__id__]["version"] = version return 1 @classmethod @release_cursors def getCatalogNames(cls, connection): """Returns a list of the available catalogs. [NOTE] This will in fact return the name of the database we are connected to. """ return [cls.execute_query(connection, "SELECT DB_PROPERTY('Name')").fetchone()[0]]
def connect(cls, connection, password): '''Establishes a connection to the server and stores the connection object in the connections pool. It first looks for a connection with the given connection parameters in the connections pool to reuse existent connections. If such connection is found it queries the server to ensure that the connection is alive and reestablishes it if is dead. If no suitable connection is found in the connections pool, a new one is created and stored in the pool. Parameters: =========== connection: an object of the class db_mgmt_Connection storing the parameters for the connection. password: a string with the password to use for the connection (ignored for SQLite). ''' con = None try: con = cls.get_connection(connection) try: if not con.cursor().execute('SELECT 1'): raise Exception('connection error') except Exception as exc: grt.send_info( 'Connection to %s apparently lost, reconnecting...' % connection.hostIdentifier) raise NotConnectedError('Connection error') except NotConnectedError as exc: grt.send_info('Connecting to %s...' % connection.hostIdentifier) if connection.driver.driverLibraryName == 'sqlanydb': import sqlanydbwrapper as sqlanydb # Replace this to a direct sqlanydb import when it complies with PEP 249 connstr = replace_string_parameters( connection.driver.connectionStringTemplate, dict(connection.parameterValues)) import ast try: all_params_dict = ast.literal_eval(connstr) except Exception as exc: grt.send_error( 'The given connection string is not a valid python dict: %s' % connstr) raise # Remove unreplaced parameters: params = dict( (key, value) for key, value in list(all_params_dict.items()) if not (value.startswith('%') and value.endswith('%'))) params['password'] = password conn_params = dict(params) conn_params['password'] = '******' connection.parameterValues[ 'wbcopytables_connection_string'] = repr(conn_params) con = sqlanydb.connect(**params) else: con = db_driver.connect(connection, password) if not con: grt.send_error('Connection failed', str(exc)) raise grt.send_info('Connected') cls._connections[connection.__id__] = {'connection': con} if con: ver = cls.execute_query(connection, "SELECT @@version").fetchone()[0] grt.log_info("SQLAnywhere RE", "Connected to %s, %s\n" % (connection.name, ver)) ver_parts = server_version_str2tuple(ver) + (0, 0, 0, 0) version = grt.classes.GrtVersion() version.majorNumber, version.minorNumber, version.releaseNumber, version.buildNumber = ver_parts[: 4] cls._connections[connection.__id__]["version"] = version return 1