From: Jacobo de Vera Date: Fri, 13 Nov 2015 15:57:41 +0000 (+0100) Subject: Pass precision value to mssql.DATETIME2 when it is 0 X-Git-Tag: rel_1_0_10~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f34deb456e9d2a82fa8f2f1accc20a896760bd17;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Pass precision value to mssql.DATETIME2 when it is 0 The simple check on the precision results in DATETIME2(0) generating a DATETIME2 column, with default precision, which is 7. (cherry picked from commit 80ce23f6fd0f14ab656d3ec82773bd0cffbd4791) --- diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index da8bbbd5f6..3a81861bb3 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -788,7 +788,7 @@ class MSTypeCompiler(compiler.GenericTypeCompiler): def visit_DATETIME2(self, type_, **kw): precision = getattr(type_, 'precision', None) - if precision: + if precision is not None: return "DATETIME2(%s)" % precision else: return "DATETIME2" diff --git a/test/dialect/mssql/test_types.py b/test/dialect/mssql/test_types.py index 17ceb6b61a..e5462eb79a 100644 --- a/test/dialect/mssql/test_types.py +++ b/test/dialect/mssql/test_types.py @@ -466,6 +466,8 @@ class TypeRoundTripTest( (mssql.MSDateTime2, [], {}, 'DATETIME2', ['>=', (10,)]), + (mssql.MSDateTime2, [0], {}, + 'DATETIME2(0)', ['>=', (10,)]), (mssql.MSDateTime2, [1], {}, 'DATETIME2(1)', ['>=', (10,)]),