From 3c14b364ba31708aa8f6f43a62689c1fe6e9eac3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 25 Jul 2006 16:40:38 +0000 Subject: [PATCH] [ticket:256] propigating url.query arguments to connect() function for all db's --- CHANGES | 1 + lib/sqlalchemy/databases/firebird.py | 4 ++++ lib/sqlalchemy/databases/mssql.py | 1 + lib/sqlalchemy/databases/mysql.py | 12 ++++++++++++ lib/sqlalchemy/databases/oracle.py | 1 + lib/sqlalchemy/databases/postgres.py | 1 + lib/sqlalchemy/databases/sqlite.py | 2 +- 7 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a347df98da..6a90e74242 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ by not raising an error when redundant mappers were set up, fixed primary key columns are null (i.e. when mapping to outer joins etc) - fixed reflection of foreign keys to autoload the referenced table if it was not loaded already +- [ticket:256] - pass URL query string arguments to connect() function 0.2.6 - big overhaul to schema to allow truly composite primary and foreign diff --git a/lib/sqlalchemy/databases/firebird.py b/lib/sqlalchemy/databases/firebird.py index 085d8cf444..bef1855976 100644 --- a/lib/sqlalchemy/databases/firebird.py +++ b/lib/sqlalchemy/databases/firebird.py @@ -123,6 +123,10 @@ class FireBirdDialect(ansisql.ANSIDialect): if opts.get('port'): opts['host'] = "%s/%s" % (opts['host'], opts['port']) del opts['port'] + opts.update(url.query) + # pop arguments that we took at the module level + opts.pop('type_conv', None) + opts.pop('concurrency_level', None) self.opts = opts return ([], self.opts) diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 9d51d535da..6613009fc1 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -241,6 +241,7 @@ class MSSQLDialect(ansisql.ANSIDialect): def create_connect_args(self, url): self.opts = url.translate_connect_args(['host', 'database', 'user', 'password', 'port']) + self.opts.update(url.query) return ([], self.opts) def connect_args(self): diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 3f3e8d1484..c9ebd7ba63 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -265,6 +265,18 @@ class MySQLDialect(ansisql.ANSIDialect): def create_connect_args(self, url): opts = url.translate_connect_args(['host', 'db', 'user', 'passwd', 'port']) + opts.update(url.query) + def coercetype(param, type): + if param in opts and type(param) is not type: + if type is bool: + opts[param] = bool(int(opts[param])) + else: + opts[param] = type(opts[param]) + coercetype('compress', bool) + coercetype('connect_timeout', int) + coercetype('use_unicode', bool) # this could break SA Unicode type + coercetype('charset', str) # this could break SA Unicode type + # TODO: what about options like "ssl", "cursorclass" and "conv" ? return [[], opts] def create_execution_context(self): diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index c279da619f..897ed640ef 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -141,6 +141,7 @@ class OracleDialect(ansisql.ANSIDialect): dsn = dsn, threaded = self.threaded ) + opts.update(url.query) return ([], opts) def type_descriptor(self, typeobj): diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index decccba58d..8368c89315 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -225,6 +225,7 @@ class PGDialect(ansisql.ANSIDialect): opts['port'] = int(opts['port']) else: opts['port'] = str(opts['port']) + opts.update(url.query) return ([], opts) def create_execution_context(self): diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index c703cd81eb..c681f391ad 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -141,7 +141,7 @@ class SQLiteDialect(ansisql.ANSIDialect): return SQLiteSchemaGenerator(*args, **kwargs) def create_connect_args(self, url): filename = url.database or ':memory:' - return ([filename], {}) + return ([filename], url.query) def type_descriptor(self, typeobj): return sqltypes.adapt_type(typeobj, colspecs) def create_execution_context(self): -- 2.47.2