Michael Manfre avatar Michael Manfre committed 055ab8a

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

Comments (0)

Files changed (3)


+            # Provide DatabaseOperations with SQL Version
+            setattr(self.ops, 'is_sql2005', self.connection.is_sql2005)
+            setattr(self.ops, 'is_sql2008', self.connection.is_sql2008)
         return Database.Cursor(self.connection)


     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:


             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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.