diff options
author | Rick Morrison <rickmorrison@gmail.com> | 2008-03-31 17:19:32 +0000 |
---|---|---|
committer | Rick Morrison <rickmorrison@gmail.com> | 2008-03-31 17:19:32 +0000 |
commit | 128ee627e1ac6b73f87195cf51d2ce00fb144cb9 (patch) | |
tree | a6f101125687e9dc729b4bb54f698f9fd6cd714d /lib/sqlalchemy/databases/mssql.py | |
parent | 0f8896e6fa692c0a91eb0980700bee069eddc8ef (diff) | |
download | sqlalchemy-128ee627e1ac6b73f87195cf51d2ce00fb144cb9.tar.gz |
Add a new 'driver' keyword to the MSSQL pyodbc Dialect.
Refresh items that were recently reverted by another checkin
Diffstat (limited to 'lib/sqlalchemy/databases/mssql.py')
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index da42ea105..c8551407b 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -133,7 +133,15 @@ class MSDate(sqltypes.Date): super(MSDate, self).__init__(False) def get_col_spec(self): - return "SMALLDATETIME" + return "DATETIME" + + def result_processor(self, dialect): + def process(value): + # If the DBAPI returns the value as datetime.datetime(), truncate it back to datetime.date() + if type(value) is datetime.datetime: + return value.date() + return value + return process class MSTime(sqltypes.Time): __zero_date = datetime.date(1900, 1, 1) @@ -188,23 +196,6 @@ class MSDate_pyodbc(MSDate): return value return process - def result_processor(self, dialect): - def process(value): - # pyodbc returns SMALLDATETIME values as datetime.datetime(). truncate it back to datetime.date() - if type(value) is datetime.datetime: - return value.date() - return value - return process - -class MSDate_pymssql(MSDate): - def result_processor(self, dialect): - def process(value): - # pymssql will return SMALLDATETIME values as datetime.datetime(), truncate it back to datetime.date() - if type(value) is datetime.datetime: - return value.date() - return value - return process - class MSText(sqltypes.Text): def get_col_spec(self): if self.dialect.text_as_varchar: @@ -413,7 +404,8 @@ class MSSQLDialect(default.DefaultDialect): 'numeric' : MSNumeric, 'float' : MSFloat, 'datetime' : MSDateTime, - 'smalldatetime' : MSDate, + 'date': MSDate, + 'smalldatetime' : MSSmallDate, 'binary' : MSBinary, 'varbinary' : MSBinary, 'bit': MSBoolean, @@ -714,11 +706,8 @@ class MSSQLDialect_pymssql(MSSQLDialect): return module import_dbapi = classmethod(import_dbapi) - colspecs = MSSQLDialect.colspecs.copy() - colspecs[sqltypes.Date] = MSDate_pymssql - ischema_names = MSSQLDialect.ischema_names.copy() - ischema_names['smalldatetime'] = MSDate_pymssql + def __init__(self, **params): super(MSSQLDialect_pymssql, self).__init__(**params) @@ -799,6 +788,7 @@ class MSSQLDialect_pyodbc(MSSQLDialect): self.use_scope_identity = hasattr(pyodbc.Cursor, 'nextset') except: pass + self.drivername = params.get('driver', 'SQL Server') def import_dbapi(cls): import pyodbc as module @@ -821,7 +811,7 @@ class MSSQLDialect_pyodbc(MSSQLDialect): if 'dsn' in keys: connectors = ['dsn=%s' % keys['dsn']] else: - connectors = ["DRIVER={SQL Server}"] + connectors = ["DRIVER={%s}" % self.drivername] if 'port' in keys: connectors.append('Server=%s,%d' % (keys.get('host'), keys.get('port'))) else: |