From: Rick Morrison Date: Mon, 31 Mar 2008 17:19:32 +0000 (+0000) Subject: Add a new 'driver' keyword to the MSSQL pyodbc Dialect. X-Git-Tag: rel_0_4_5~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=128ee627e1ac6b73f87195cf51d2ce00fb144cb9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add a new 'driver' keyword to the MSSQL pyodbc Dialect. Refresh items that were recently reverted by another checkin --- diff --git a/CHANGES b/CHANGES index 41ddd52b75..6773d9333e 100644 --- a/CHANGES +++ b/CHANGES @@ -212,6 +212,10 @@ CHANGES - Added stubs for small date type, [ticket:884] + - Added a new 'driver' keyword parameter for the pyodbc dialect. + Will substitute into the ODBC connection string if given, + defaults to 'SQL Server'. + - Improvements to pyodbc + Unix. If you couldn't get that combination to work before, please try again. diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index da42ea1055..c8551407b8 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: