summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2007-04-19 23:44:26 +0000
committerJason Kirtland <jek@discorporate.us>2007-04-19 23:44:26 +0000
commit0fe6b80c7024e6f9430071f162274fbbd0e3ca44 (patch)
treeb1da6761a496585cbcd68819d3104e0b1df012c3 /lib/sqlalchemy/databases
parent42df71d2159e60042d0931b9dd6b878ecfac9dd4 (diff)
downloadsqlalchemy-0fe6b80c7024e6f9430071f162274fbbd0e3ca44.tar.gz
- Promoted mysql's dburl query string helper to util + fixed
- Coercing sqlite connect args provided in query string to their expected type (e.g. 'timeout' as float, fixes #544) - Coerce mysql's client_flag to int too
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r--lib/sqlalchemy/databases/mysql.py18
-rw-r--r--lib/sqlalchemy/databases/sqlite.py11
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 21f8bb398..52aa03003 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -10,6 +10,7 @@ from sqlalchemy import sql,engine,schema,ansisql
from sqlalchemy.engine import default
import sqlalchemy.types as sqltypes
import sqlalchemy.exceptions as exceptions
+import sqlalchemy.util as util
from array import array
@@ -285,16 +286,13 @@ 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
+
+ util.coerce_kw_type(opts, 'compress', bool)
+ util.coerce_kw_type(opts, 'connect_timeout', int)
+ util.coerce_kw_type(opts, 'client_flag', int)
+ # note: these two could break SA Unicode type
+ util.coerce_kw_type(opts, 'use_unicode', bool)
+ util.coerce_kw_type(opts, 'charset', str)
# TODO: what about options like "ssl", "cursorclass" and "conv" ?
client_flag = opts.get('client_flag', 0)
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py
index 0222496f8..6c1234542 100644
--- a/lib/sqlalchemy/databases/sqlite.py
+++ b/lib/sqlalchemy/databases/sqlite.py
@@ -10,6 +10,7 @@ import sys, StringIO, string, types, re
from sqlalchemy import sql, engine, schema, ansisql, exceptions, pool, PassiveDefault
import sqlalchemy.engine.default as default
import sqlalchemy.types as sqltypes
+import sqlalchemy.util as util
import datetime,time
@@ -179,7 +180,15 @@ class SQLiteDialect(ansisql.ANSIDialect):
def create_connect_args(self, url):
filename = url.database or ':memory:'
- return ([filename], url.query)
+
+ opts = url.query.copy()
+ util.coerce_kw_type(opts, 'timeout', float)
+ util.coerce_kw_type(opts, 'isolation_level', str)
+ util.coerce_kw_type(opts, 'detect_types', int)
+ util.coerce_kw_type(opts, 'check_same_thread', bool)
+ util.coerce_kw_type(opts, 'cached_statements', int)
+
+ return ([filename], opts)
def type_descriptor(self, typeobj):
return sqltypes.adapt_type(typeobj, colspecs)