From a03935ac97f71888f023c518aacd3494cb25b756 Mon Sep 17 00:00:00 2001 From: Brad Allen Date: Thu, 18 Mar 2010 14:09:04 -0600 Subject: [PATCH] Added MSSQLStrictCompiler support for rendering datetime types --- lib/sqlalchemy/dialects/mssql/base.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 6a35cbc876..5a5cda7a9b 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -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): -- 2.47.3