From: Brad Allen Date: Thu, 18 Mar 2010 20:09:04 +0000 (-0600) Subject: Added MSSQLStrictCompiler support for rendering datetime types X-Git-Tag: rel_0_6beta2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a03935ac97f71888f023c518aacd3494cb25b756;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Added MSSQLStrictCompiler support for rendering datetime types --- 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):