def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('autocommit', 'use_mars', 'as_dict'): if param in keys: connect_args[param] = asbool(keys.pop(param)) for param in ('port', 'timeout', 'login_timeout'): if param in keys: connect_args[param] = int(keys.pop(param)) for param in ('host', 'user', 'password', 'database', 'auth_method'): if param in keys: connect_args[param] = keys.pop(param) connect_args['server'] = connect_args['host'] del connect_args['host'] if "auth_method" in connect_args: if connect_args["auth_method"] == "mssql": del connect_args["auth_method"] elif connect_args["auth_method"] == "ntlm": connect_args["auth"] = pytds.login.NtlmAuth( connect_args["user"], connect_args["password"]) del connect_args["auth_method"] del connect_args["user"] del connect_args["password"] else: raise Exception("Unknown auth_method " + connect_args["auth_method"]) return [[], connect_args]
def _get_options_with_defaults(url): user_options = url.translate_connect_args(username='******', password='******', database='exaschema', host='destination') user_options.update(url.query) options = {key.lower(): value for (key, value) in DEFAULT_CONNECTION_PARAMS.items()} options.update({key.lower(): value for (key, value) in DEFAULT_TURBODBC_PARAMS.items()}) for key in user_options.keys(): options[key.lower()] = user_options[key] real_turbodbc = __import__('turbodbc') turbodbc_options = {} for param in TURBODBC_TRANSLATED_PARAMS: if param in options: raw = options.pop(param) if param in {'use_async_io', 'prefer_unicode', 'large_decimals_as_64_bit_types', 'limit_varchar_results_to_max', 'autocommit'}: value = util.asbool(raw) elif param == 'read_buffer_size': value = real_turbodbc.Megabytes(util.asint(raw)) else: value = util.asint(raw) turbodbc_options[param] = value options['turbodbc_options'] = real_turbodbc.make_options(**turbodbc_options) return options
def connect( self, disable_cockroachdb_telemetry=False, **kwargs, ): self.disable_cockroachdb_telemetry = asbool(disable_cockroachdb_telemetry) return super().connect(**kwargs)
def create_connect_args(self, url): opts = url.translate_connect_args(username="******") opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ("autocommit", "use_mars", "as_dict"): if param in keys: connect_args[param] = asbool(keys.pop(param)) for param in ("port", "timeout", "login_timeout"): if param in keys: connect_args[param] = int(keys.pop(param)) for param in ("host", "user", "password", "database", "auth_method"): if param in keys: connect_args[param] = keys.pop(param) connect_args["dsn"] = connect_args["host"] del connect_args["host"] if "auth_method" in connect_args: if connect_args["auth_method"] == "mssql": del connect_args["auth_method"] elif connect_args["auth_method"] == "ntlm": connect_args["auth"] = pytds.login.NtlmAuth( connect_args["user"], connect_args["password"] ) del connect_args["auth_method"] del connect_args["user"] del connect_args["password"] else: raise Exception("Unknown auth_method " + connect_args["auth_method"]) return [[], connect_args]
def _get_options_with_defaults(url): user_options = url.translate_connect_args(username='******', password='******', database='exaschema', host='destination') user_options.update(url.query) options = {key.lower(): value for (key, value) in DEFAULT_CONNECTION_PARAMS.items()} options.update({key.lower(): value for (key, value) in DEFAULT_TURBODBC_PARAMS.items()}) for key in user_options.keys(): options[key.lower()] = user_options[key] real_turbodbc = __import__('turbodbc') turbodbc_options = {} for param in ('read_buffer_size', 'parameter_sets_to_buffer', 'use_async_io'): if param in options: raw = options.pop(param) if param == 'use_async_io': value = util.asbool(raw) elif param == 'read_buffer_size': value = real_turbodbc.Megabytes(util.asint(raw)) else: value = util.asint(raw) turbodbc_options[param] = value options['turbodbc_options'] = real_turbodbc.make_options(**turbodbc_options) return options
def create_connect_args(self, url): kwargs = {} port = url.port or 9000 db_name = url.database or 'default' secure = url.query.get('secure') if secure is not None: url.query['secure'] = asbool(secure) verify = url.query.get('verify') if verify is not None: url.query['verify'] = asbool(verify) kwargs.update(url.query) return (url.host, port, db_name, url.username, url.password), kwargs
def __init__(self, db_url, db_name, username, password, timeout=None, ch_settings=None, verify=None, **kwargs): self.db_url = db_url self.db_name = db_name self.auth = (username, password) self.timeout = float(timeout) if timeout is not None else None self.verify = asbool(verify) self.headers = { key[8:]: value for key, value in kwargs.items() if key.startswith('header__') } self.unicode_errors = kwargs.pop('unicode_errors', 'escape') ch_settings = dict(ch_settings or {}) self.ch_settings = ch_settings ddl_timeout = kwargs.pop('ddl_timeout', DEFAULT_DDL_TIMEOUT) if ddl_timeout is not None: self.ch_settings['distributed_ddl_task_timeout'] = int(ddl_timeout) # By default, keep connection open between queries. self.http = kwargs.pop('http_session', requests.Session()) super(RequestsTransport, self).__init__()
def create_connect_args(self, url): url = url.set(drivername='clickhouse') self.engine_reflection = asbool( url.query.get('engine_reflection', 'true') ) return (str(url), ), {}
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param] = util.asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) if dsn_connection: connectors = ['dsn=%s' % (keys.pop('host', '') or \ keys.pop('dsn', ''))] else: port = '' if 'port' in keys and not 'port' in query: port = ',%d' % int(keys.pop('port')) database = keys.pop('database', '') db_alias = database if 'alias' in keys and not 'alias' in query: db_alias = keys.pop('alias') connectors = ["driver={%s}" % keys.pop('driver', self.pyodbc_driver_name), 'server=%s%s' % (keys.pop('host', ''), port), 'database=%s' % database, 'dbalias=%s' % db_alias] user = keys.pop("user", None) if user: connectors.append("uid=%s" % user) connectors.append("pwd=%s" % keys.pop('password', '')) else: connectors.append("trusted_connection=yes") # if set to 'yes', the odbc layer will try to automagically # convert textual data from your database encoding to your # client encoding. this should obviously be set to 'no' if # you query a cp1253 encoded database from a latin1 client... if 'odbc_autotranslate' in keys: connectors.append("autotranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend(['%s=%s' % (k, v) for k, v in keys.iteritems()]) return [[";".join(connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param] = util.asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) if dsn_connection: connectors = ['dsn=%s' % (keys.pop('host', '') or \ keys.pop('dsn', ''))] else: port = '' if 'port' in keys and not 'port' in query: port = '%d' % int(keys.pop('port')) database = keys.pop('database', '') connectors = [ "DRIVER={%s}" % keys.pop('driver', self.pyodbc_driver_name), 'hostname=%s;port=%s' % (keys.pop('host', ''), port), 'database=%s' % database ] user = keys.pop("user", None) if user: connectors.append("uid=%s" % user) connectors.append("pwd=%s" % keys.pop('password', '')) else: connectors.append("trusted_connection=yes") # if set to 'yes', the odbc layer will try to automagically # convert textual data from your database encoding to your # client encoding. this should obviously be set to 'no' if # you query a cp1253 encoded database from a latin1 client... if 'odbc_autotranslate' in keys: connectors.append("autotranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend( ['%s=%s' % (k, v) for k, v in keys.iteritems()]) return [[";".join(connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username="******") opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ("ansi", "unicode_results", "autocommit"): if param in keys: connect_args[param] = util.asbool(keys.pop(param)) if "odbc_connect" in keys: connectors = [urllib.parse.unquote_plus(keys.pop("odbc_connect"))] else: dsn_connection = "dsn" in keys or ("host" in keys and "database" not in keys) if dsn_connection: connectors = [ "dsn=%s" % (keys.pop("host", "") or keys.pop("dsn", "")) ] else: port = "" if "port" in keys and not "port" in query: port = "%d" % int(keys.pop("port")) database = keys.pop("database", "") connectors = [ "DRIVER={%s}" % keys.pop("driver", self.pyodbc_driver_name), "hostname=%s;port=%s" % (keys.pop("host", ""), port), "database=%s" % database, ] user = keys.pop("user", None) if user: connectors.append("uid=%s" % user) connectors.append("pwd=%s" % keys.pop("password", "")) else: connectors.append("trusted_connection=yes") # if set to 'yes', the odbc layer will try to automagically # convert textual data from your database encoding to your # client encoding. this should obviously be set to 'no' if # you query a cp1253 encoded database from a latin1 client... if "odbc_autotranslate" in keys: connectors.append("autotranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend(["%s=%s" % (k, v) for k, v in keys.items()]) return [[";".join(connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param] = util.asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [urllib.parse.unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) if dsn_connection: connectors = ['dsn=%s' % (keys.pop('host', '') or \ keys.pop('dsn', ''))] else: connectors = [ "DRIVER={%s}" % keys.pop('driver', self.pyodbc_driver_name), 'System=%s' % keys.pop('host', ''), 'DBQ=QGPL' ] connectors.append("PKG=QGPL/DEFAULT(IBM),2,0,1,0,512") db_name = keys.pop('database', '') if db_name: connectors.append("DATABASE=%s" % db_name) user = keys.pop("user", None) if user: connectors.append("UID=%s" % user) connectors.append("PWD=%s" % keys.pop('password', '')) else: connectors.append("trusted_connection=yes") # if set to 'Yes', the ODBC layer will try to automagically convert # textual data from your database encoding to your client encoding # This should obviously be set to 'No' if you query a cp1253 encoded # database from a latin1 client... if 'odbc_autotranslate' in keys: connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) return [[";".join(connectors)], connect_args]
def create_connect_args(self, url): kwargs = {} protocol = url.query.get('protocol', 'http') port = url.port or 8123 db_name = url.database or 'default' endpoint = url.query.get('endpoint', '') self.engine_reflection = asbool( url.query.get('engine_reflection', 'true')) kwargs.update(url.query) if kwargs.get('verify') and kwargs['verify'] in ('False', 'false'): kwargs['verify'] = False db_url = '%s://%s:%d/%s' % (protocol, url.host, port, endpoint) return (db_url, db_name, url.username, url.password), kwargs
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param] = util.asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) if dsn_connection: connectors = ['dsn=%s' % (keys.pop('host', '') or \ keys.pop('dsn', ''))] else: connectors = ["DRIVER={%s}" % keys.pop('driver', self.pyodbc_driver_name), 'System=%s' % keys.pop('host', ''), 'DBQ=QGPL'] connectors.append("PKG=QGPL/DEFAULT(IBM),2,0,1,0,512") connectors.append("CMT=0") db_name = keys.pop('database', '') if db_name: connectors.append("DATABASE=%s" % db_name) user = keys.pop("user", None) if user: connectors.append("UID=%s" % user) connectors.append("PWD=%s" % keys.pop('password', '')) else: connectors.append("trusted_connection=yes") # if set to 'Yes', the ODBC layer will try to automagically convert # textual data from your database encoding to your client encoding # This should obviously be set to 'No' if you query a cp1253 encoded # database from a latin1 client... if 'odbc_autotranslate' in keys: connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend(['%s=%s' % (k,v) for k,v in keys.items()]) return [[";".join (connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username="******") opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ("ansi", "unicode_results", "autocommit"): if param in keys: connect_args[param] = asbool(keys.pop(param)) if "odbc_connect" in keys: connectors = [urllib.unquote_plus(keys.pop("odbc_connect"))] else: dsn_connection = "dsn" in keys or ("host" in keys and "database" not in keys) if dsn_connection: connectors = ["dsn=%s" % (keys.pop("host", "") or keys.pop("dsn", ""))] else: port = "" if "port" in keys and not "port" in query: port = ",%d" % int(keys.pop("port")) connectors = [ "DRIVER={%s}" % keys.pop("driver", self.pyodbc_driver_name), "Server=%s%s" % (keys.pop("host", ""), port), "Database=%s" % keys.pop("database", ""), ] user = keys.pop("user", None) if user: connectors.append("UID=%s" % user) connectors.append("PWD=%s" % keys.pop("password", "")) else: connectors.append("Trusted_Connection=Yes") # if set to 'Yes', the ODBC layer will try to automagically # convert textual data from your database encoding to your # client encoding. This should obviously be set to 'No' if # you query a cp1253 encoded database from a latin1 client... if "odbc_autotranslate" in keys: connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend(["%s=%s" % (k, v) for k, v in keys.iteritems()]) return [[";".join(connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param] = asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] else: # Default Webtrends port: port = '80' if 'port' in keys and not 'port' in query: port = '%d' % int(keys.pop('port')) database = keys.pop('database', None) profile_guid = query.pop('profile_guid', '') connectors = [ 'SERVER=%s' % keys.pop('host', ''), 'SSL=0', 'PORT=%s' % (port,), 'DATABASE=%s' % database, 'AccountID=1', ] if database != 'WTSystem' and profile_guid: connectors.append('ProfileGuid=%s' % profile_guid) if 'dsn' in query: connectors.append( "Extended Properties=DSN=%s" % query.pop('dsn', 'Webtrends') ) user = keys.pop("user", None) if user: connectors.append("User ID=%s" % user) connectors.append("UID=%s" % user) connectors.append("PASSWORD=%s" % keys.pop('password', '')) connectors.extend(['%s=%s' % (k, v) for k, v in keys.iteritems()]) return [[";".join (connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param] = asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or ('host' in keys and 'database' not in keys) if dsn_connection: connectors= ['dsn=%s' % (keys.pop('host', '') or keys.pop('dsn', ''))] else: port = '' if 'port' in keys and not 'port' in query: port = ',%d' % int(keys.pop('port')) connectors = ["DRIVER={%s}" % keys.pop('driver', self.pyodbc_driver_name), 'Server=%s%s' % (keys.pop('host', ''), port), 'Database=%s' % keys.pop('database', '') ] user = keys.pop("user", None) if user: connectors.append("UID=%s" % user) connectors.append("PWD=%s" % keys.pop('password', '')) else: connectors.append("Trusted_Connection=Yes") # if set to 'Yes', the ODBC layer will try to automagically convert # textual data from your database encoding to your client encoding # This should obviously be set to 'No' if you query a cp1253 encoded # database from a latin1 client... if 'odbc_autotranslate' in keys: connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) connectors.extend(['%s=%s' % (k,v) for k,v in keys.iteritems()]) return [[";".join (connectors)], connect_args]
def create_connect_args(self, url): opts = url.translate_connect_args(username='******') opts.update(url.query) keys = opts query = url.query connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: connect_args[param.upper()] = util.asbool(keys.pop(param)) if 'odbc_connect' in keys: connectors = [util.unquote_plus(keys.pop('odbc_connect'))] else: def check_quote(token): if ";" in str(token): token = "'%s'" % token return token keys = dict((k.lower(), check_quote(v)) for k, v in keys.items()) dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) if dsn_connection: connectors = [ 'DSN=%s' % (keys.pop('host', '') or keys.pop('dsn', '')) ] connectors.extend(['HOST=', 'PORT=', 'Schema=']) else: port = '' if 'port' in keys and 'port' not in query: port = '%d' % int(keys.pop('port')) connectors = [] driver = keys.pop('driver', self.pyodbc_driver_name) if driver is None: util.warn("No driver name specified; " "this is expected by PyODBC when using " "DSN-less connections") else: connectors.append("DRIVER={%s}" % driver) connectors.extend([ 'HOST=%s' % keys.pop('host', ''), 'PORT=%s' % port, 'Schema=%s' % keys.pop('database', '') ]) user = keys.pop("user", None) if user and 'password' in keys: connectors.append("UID=%s" % user) connectors.append("PWD=%s" % keys.pop('password', '')) elif user and 'password' not in keys: pass else: connectors.append("Trusted_Connection=Yes") # if set to 'Yes', the ODBC layer will try to automagically # convert textual data from your database encoding to your # client encoding. This should obviously be set to 'No' if # you query a cp1253 encoded database from a latin1 client... if 'odbc_autotranslate' in keys: connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) connectors.append('INTTYPESINRESULTSIFPOSSIBLE=y') connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) return [[";".join(connectors)], connect_args]
def create_connect_args(self, url): """Create the connect args for Turbodbc. Some code adapted from the Pyodbc connector in the SQLAlchemy codebase. """ options = url.translate_connect_args(username='******') query = url.query options.update(query) connect_args = {} # first get the Turbodbc specific options turbodbc_options = {} for param in ('read_buffer_size', 'parameter_sets_to_buffer', 'use_async_io', 'autocommit', 'large_decimals_as_64_bit_types'): if param in options: raw = options.pop(param) if param in ('use_async_io', 'autocommit', 'large_decimals_as_64_bit_types'): value = util.asbool(raw) else: value = util.asint(raw) turbodbc_options[param] = value # we always need to set prefer_unicode=True for MSSQL + Turbodbc connect_args['turbodbc_options'] = make_options(prefer_unicode=True, **turbodbc_options) for param in ('ansi', 'unicode_results'): if param in options: connect_args[param] = util.asbool(options.pop(param)) dsn_connection = 'dsn' in options or \ ('host' in options and 'database' not in options) if dsn_connection: dsn = [options.pop('host', '') or options.pop('dsn', '')] else: dsn = [] port = '' if 'port' in options and 'port' not in query: port = int(options.pop('port')) driver = options.pop('driver', None) if driver is None: util.warn( "No driver name specified; " "this is expected by ODBC when using " "DSN-less connections") else: connect_args['driver'] = driver connect_args.update( server=(options.pop('host', '')), port=port, database=options.pop('database', '') ) user = options.pop('user', None) if user: connect_args.update( uid=user, pwd=options.pop('password', '') ) else: connect_args['trusted_connection'] = 'Yes' return [dsn, connect_args]