diff options
author | Michael Trier <mtrier@gmail.com> | 2008-10-11 16:14:20 +0000 |
---|---|---|
committer | Michael Trier <mtrier@gmail.com> | 2008-10-11 16:14:20 +0000 |
commit | 41e1f5526cf24131f6365de2c48f39748504daf2 (patch) | |
tree | fc87f0132b7fee1cca7870929286070dcb8e7bd2 | |
parent | b3c39decc1b992bcb7c1bb7cad452dcea5991f20 (diff) | |
download | sqlalchemy-41e1f5526cf24131f6365de2c48f39748504daf2.tar.gz |
Removed the visit_function stuff in mssql dialect. Added some tests for the function overrides. Fixed up the test_select in the sql/defaults.py tests which was a mess.
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 14 | ||||
-rwxr-xr-x | test/dialect/mssql.py | 4 | ||||
-rw-r--r-- | test/sql/defaults.py | 7 |
3 files changed, 12 insertions, 13 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 8bf8144cf..4c5ad1fd1 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -882,10 +882,12 @@ class MSSQLCompiler(compiler.DefaultCompiler): functions = compiler.DefaultCompiler.functions.copy() functions.update ( { - sql_functions.now: 'CURRENT_TIMESTAMP' + sql_functions.now: 'CURRENT_TIMESTAMP', + sql_functions.current_date: 'GETDATE()', + 'length': lambda x: "LEN(%s)" % x } ) - + def __init__(self, *args, **kwargs): super(MSSQLCompiler, self).__init__(*args, **kwargs) self.tablealiases = {} @@ -984,14 +986,6 @@ class MSSQLCompiler(compiler.DefaultCompiler): else: return super(MSSQLCompiler, self).label_select_column(select, column, asfrom) - # TODO: update this to use generic functions - function_rewrites = {'current_date': 'getdate', - 'length': 'len', - } - def visit_function(self, func, **kwargs): - func.name = self.function_rewrites.get(func.name, func.name) - return super(MSSQLCompiler, self).visit_function(func, **kwargs) - def for_update_clause(self, select): # "FOR UPDATE" is only allowed on "DECLARE CURSOR" which SQLAlchemy doesn't use return '' diff --git a/test/dialect/mssql.py b/test/dialect/mssql.py index 26f8892bd..02c583d5d 100755 --- a/test/dialect/mssql.py +++ b/test/dialect/mssql.py @@ -105,6 +105,10 @@ class CompileTest(TestBase, AssertsCompiledSQL): t = Table('sometable', m, Column('col1', Integer), Column('col2', Integer)) self.assert_compile(select([func.max(t.c.col1)]), "SELECT max(sometable.col1) AS max_1 FROM sometable") + def test_function_overrides(self): + self.assert_compile(func.current_date(), "GETDATE()") + self.assert_compile(func.length(3), "LEN(:length_1)") + class ReflectionTest(TestBase): __only_on__ = 'mssql' diff --git a/test/sql/defaults.py b/test/sql/defaults.py index dfd626b72..d69174248 100644 --- a/test/sql/defaults.py +++ b/test/sql/defaults.py @@ -33,14 +33,13 @@ class DefaultTest(testing.TestBase): # since its a "branched" connection conn.close() - use_function_defaults = testing.against('postgres', 'oracle') + use_function_defaults = testing.against('postgres', 'mssql', 'maxdb') is_oracle = testing.against('oracle') # select "count(1)" returns different results on different DBs also # correct for "current_date" compatible as column default, value # differences currenttime = func.current_date(type_=sa.Date, bind=db) - if is_oracle: ts = db.scalar(sa.select([func.trunc(func.sysdate(), sa.literal_column("'DAY'"), type_=sa.Date).label('today')])) assert isinstance(ts, datetime.date) and not isinstance(ts, datetime.datetime) @@ -56,11 +55,13 @@ class DefaultTest(testing.TestBase): f = sa.select([func.length('abcdef')], bind=db).scalar() f2 = sa.select([func.length('abcdefghijk')], bind=db).scalar() def1 = currenttime + deftype = sa.Date if testing.against('maxdb'): def2 = sa.text("curdate") + elif testing.against('mssql'): + def2 = sa.text("getdate()") else: def2 = sa.text("current_date") - deftype = sa.Date ts = db.func.current_date().scalar() else: f = len('abcdef') |