Remove quote on first DATEPART paramater

(cherry picked from commit c4f415d979)
- changelog for pr bitbucket:70, fixes #3624

(cherry picked from commit 215167d8d3)
This commit is contained in:
Guillaume DOUMENC
2016-01-12 04:46:32 +00:00
committed by Mike Bayer
parent 4c1f1c130f
commit dc733bcea6
3 changed files with 22 additions and 1 deletions
+9
View File
@@ -19,6 +19,15 @@
:version: 1.0.12
:released:
.. change::
:tags: bug, mssql
:tickets: 3624
:pullreq: bitbucket:70
Fixed the syntax of the :func:`.extract` function when used on
MSSQL against a datetime value; the quotes around the keyword
are removed. Pull request courtesy Guillaume Doumenc.
.. change::
:tags: bug, orm
:tickets: 3623
+1 -1
View File
@@ -1181,7 +1181,7 @@ class MSSQLCompiler(compiler.SQLCompiler):
def visit_extract(self, extract, **kw):
field = self.extract_map.get(extract.field, extract.field)
return 'DATEPART("%s", %s)' % \
return 'DATEPART(%s, %s)' % \
(field, self.process(extract.expr, **kw))
def visit_savepoint(self, savepoint_stmt):
+12
View File
@@ -64,6 +64,18 @@ class MSDateTypeTest(fixtures.TestBase):
result_processor, 'abc'
)
def test_extract(self):
from sqlalchemy import extract
fivedaysago = datetime.datetime.now() \
- datetime.timedelta(days=5)
for field, exp in ('year', fivedaysago.year), \
('month', fivedaysago.month), ('day', fivedaysago.day):
r = testing.db.execute(
select([
extract(field, fivedaysago)])
).scalar()
eq_(r, exp)
class TypeDDLTest(fixtures.TestBase):