summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnts Aasma <ants.aasma@gmail.com>2007-08-08 22:35:05 +0000
committerAnts Aasma <ants.aasma@gmail.com>2007-08-08 22:35:05 +0000
commit2f090b483d259048160682b88e3c21167523f61a (patch)
tree484463626cd18a2cebf0230f0487dc04d445d2f3
parent06bebbb41c6ec0ba98467de575835dea0ade6e51 (diff)
downloadsqlalchemy-2f090b483d259048160682b88e3c21167523f61a.tar.gz
- fix mssql compiling explicitly added alias twice
- add is_select to mssql dialect. currently adds only sp_columns, someone familiar with mssql should update this - update mssql get_default_schema_name api - remove commented code from Query.filter_by
-rw-r--r--lib/sqlalchemy/databases/mssql.py15
-rw-r--r--lib/sqlalchemy/orm/query.py6
2 files changed, 12 insertions, 9 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index 5faaf31bf..77819cc92 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -39,7 +39,7 @@ Known issues / TODO:
"""
-import datetime, random, warnings
+import datetime, random, warnings, re
from sqlalchemy import sql, schema, ansisql, exceptions
import sqlalchemy.types as sqltypes
@@ -294,6 +294,12 @@ class MSSQLExecutionContext(default.DefaultExecutionContext):
# print "LAST ROW ID", self._last_inserted_ids
self.HASIDENT = False
super(MSSQLExecutionContext, self).post_exec()
+
+ _ms_is_select = re.compile(r'\s*(?:SELECT|sp_columns)',
+ re.I | re.UNICODE)
+
+ def is_select(self):
+ return self._ms_is_select.match(self.statement) is not None
class MSSQLExecutionContext_pyodbc (MSSQLExecutionContext):
@@ -438,7 +444,7 @@ class MSSQLDialect(ansisql.ANSIDialect):
def preparer(self):
return MSSQLIdentifierPreparer(self)
- def get_default_schema_name(self):
+ def get_default_schema_name(self, connection):
return self.schema_name
def set_default_schema_name(self, schema_name):
@@ -487,7 +493,7 @@ class MSSQLDialect(ansisql.ANSIDialect):
def has_table(self, connection, tablename, schema=None):
import sqlalchemy.databases.information_schema as ischema
- current_schema = schema or self.get_default_schema_name()
+ current_schema = schema or self.get_default_schema_name(connection)
columns = self.uppercase_table(ischema.columns)
s = sql.select([columns],
current_schema
@@ -506,7 +512,7 @@ class MSSQLDialect(ansisql.ANSIDialect):
if table.schema is not None:
current_schema = table.schema
else:
- current_schema = self.get_default_schema_name()
+ current_schema = self.get_default_schema_name(connection)
columns = self.uppercase_table(ischema.columns)
s = sql.select([columns],
@@ -861,6 +867,7 @@ class MSSQLCompiler(ansisql.ANSICompiler):
def visit_alias(self, alias, **kwargs):
# translate for schema-qualified table aliases
self.tablealiases[alias.original] = alias
+ kwargs['mssql_aliased'] = True
return super(MSSQLCompiler, self).visit_alias(alias, **kwargs)
def visit_column(self, column):
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 08ae760fc..44329468f 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -300,11 +300,7 @@ class Query(object):
def filter_by(self, **kwargs):
"""apply the given filtering criterion to the query and return the newly resulting ``Query``."""
- #import properties
-
- joinpoint = self._joinpoint
-
- clauses = [joinpoint.get_property(key, resolve_synonyms=True).compare(operator.eq, value)
+ clauses = [self._joinpoint.get_property(key, resolve_synonyms=True).compare(operator.eq, value)
for key, value in kwargs.iteritems()]
return self.filter(sql.and_(*clauses))