Commits

Michael Manfre  committed 055ab8a

Connection will now detect if the database is SQL 2005. If 2005, date & time values will no longer strip microseconds.

  • Participants
  • Parent commits 07396e8

Comments (0)

Files changed (3)

File sqlserver_ado/base.py

                                 make_connection_string(self.settings_dict),
                                 self.command_timeout
                               )
+            # Provide DatabaseOperations with SQL Version
+            setattr(self.ops, 'is_sql2005', self.connection.is_sql2005)
+            setattr(self.ops, 'is_sql2008', self.connection.is_sql2008)
+            
             connection_created.send(sender=self.__class__)
 
         return Database.Cursor(self.connection)

File sqlserver_ado/dbapi.py

     if p.Size == 0:
         p.Size = -1
 
+VERSION_SQL2005 = 9
+VERSION_SQL2008 = 10
 
 class Connection(object):
     def __init__(self, adoConn, useTransactions=False):
         self.adoConn.CursorLocation = defaultCursorLocation
         self.supportsTransactions = useTransactions
 
+        self.adoConnProperties = dict([(x.Name, x.Value) for x in self.adoConn.Properties])
+
         if self.supportsTransactions:
             self.adoConn.IsolationLevel = defaultIsolationLevel
             self.adoConn.BeginTrans() # Disables autocommit per DBPAI
 
+    @property
+    def is_sql2005(self):
+        v = self.adoConnProperties.get('DBMS Version', '')
+        return v.startswith(unicode(VERSION_SQL2005))
+    
+    @property
+    def is_sql2008(self):
+        v = self.adoConnProperties.get('DBMS Version', '')
+        return v.startswith(unicode(VERSION_SQL2008))
+
     def _raiseConnectionError(self, errorclass, errorvalue):
         eh = self.errorhandler
         if eh is None:

File sqlserver_ado/operations.py

             raise ValueError("SQL Server 2005 does not support timezone-aware datetimes.")
 
         # SQL Server 2005 doesn't support microseconds
-        return value.replace(microsecond=0)
+        if self.is_sql2005:
+           value = value.replace(microseconds=0)
+
+        return value
     
     def value_to_db_time(self, value):
+        if not self.is_sql2005:
+            return value
+
         # MS SQL 2005 doesn't support microseconds
         #...but it also doesn't really suport bare times
         if value is None:
             return None
+        
         return value.replace(microsecond=0)
 	        
     def value_to_db_decimal(self, value, max_digits, decimal_places):