]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Added MSSQLStrictCompiler support for rendering datetime types
authorBrad Allen <bradallen137@gmail.com>
Thu, 18 Mar 2010 20:09:04 +0000 (14:09 -0600)
committerBrad Allen <bradallen137@gmail.com>
Thu, 18 Mar 2010 20:09:04 +0000 (14:09 -0600)
lib/sqlalchemy/dialects/mssql/base.py

index 6a35cbc87671caad6e47c7ce31987ffddfa4245c..5a5cda7a9b5d37a4ed62bb19ca9c0a1de61a1c90 100644 (file)
@@ -1065,9 +1065,23 @@ class MSSQLStrictCompiler(MSSQLCompiler):
         kw['literal_binds'] = True
         return super(MSSQLStrictCompiler, self).visit_function(func, **kw)
 
-    #def render_literal_value(self, value):
-        # TODO! use mxODBC's literal quoting services here
-
+    def render_literal_value(self, value, type_):
+        """
+        For date and datetime values, convert to a string
+        format acceptable to MSSQL. That seems to be the
+        so-called ODBC canonical date format which looks
+        like this:
+        
+            yyyy-mm-dd hh:mi:ss.mmm(24h)
+        
+        For other data types, call the base class implementation.
+        """
+        # datetime and date are both subclasses of datetime.date
+        if issubclass(type(value), datetime.date):
+            # SQL Server wants single quotes around the date string.
+            return "'" + str(value) + "'"
+        else:
+            MSSQLCompiler.render_literal_value(self, value, type_)
 
 class MSDDLCompiler(compiler.DDLCompiler):
     def get_column_specification(self, column, **kwargs):