]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add a new 'driver' keyword to the MSSQL pyodbc Dialect.
authorRick Morrison <rickmorrison@gmail.com>
Mon, 31 Mar 2008 17:19:32 +0000 (17:19 +0000)
committerRick Morrison <rickmorrison@gmail.com>
Mon, 31 Mar 2008 17:19:32 +0000 (17:19 +0000)
Refresh items that were recently reverted by another checkin

CHANGES
lib/sqlalchemy/databases/mssql.py

diff --git a/CHANGES b/CHANGES
index 41ddd52b75ad12e0b7eea17c46df73351f97767f..6773d9333e758ccde279753c5556cab35ac4adfb 100644 (file)
--- 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.
 
index da42ea1055167233105ed392f4ad2fda939e4874..c8551407b8764692569ac7a3166519f90274a8f1 100644 (file)
@@ -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: