mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-28 11:35:19 -04:00
Remove quote on first DATEPART paramater
(cherry picked from commitc4f415d979) - changelog for pr bitbucket:70, fixes #3624 (cherry picked from commit215167d8d3)
This commit is contained in:
committed by
Mike Bayer
parent
4c1f1c130f
commit
dc733bcea6
Vendored
+9
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user