summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mssql/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py104
1 files changed, 52 insertions, 52 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index dda63080d..290cd1019 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -18,7 +18,7 @@ Auto Increment Behavior
``schema.Sequence()`` objects. In other words::
from sqlalchemy import Table, Integer, Sequence, Column
-
+
Table('test', metadata,
Column('id', Integer,
Sequence('blah',100,10), primary_key=True),
@@ -261,7 +261,7 @@ class SMALLDATETIME(_DateTimeBase, sqltypes.DateTime):
class DATETIME2(_DateTimeBase, sqltypes.DateTime):
__visit_name__ = 'DATETIME2'
-
+
def __init__(self, precision=None, **kw):
super(DATETIME2, self).__init__(**kw)
self.precision = precision
@@ -270,7 +270,7 @@ class DATETIME2(_DateTimeBase, sqltypes.DateTime):
# TODO: is this not an Interval ?
class DATETIMEOFFSET(sqltypes.TypeEngine):
__visit_name__ = 'DATETIMEOFFSET'
-
+
def __init__(self, precision=None, **kwargs):
self.precision = precision
@@ -298,7 +298,7 @@ class NTEXT(_StringType, sqltypes.UnicodeText):
characters."""
__visit_name__ = 'NTEXT'
-
+
def __init__(self, length=None, collation=None, **kw):
"""Construct a NTEXT.
@@ -405,7 +405,7 @@ class IMAGE(sqltypes.LargeBinary):
class BIT(sqltypes.TypeEngine):
__visit_name__ = 'BIT'
-
+
class MONEY(sqltypes.TypeEngine):
__visit_name__ = 'MONEY'
@@ -487,13 +487,13 @@ class MSTypeCompiler(compiler.GenericTypeCompiler):
collation = 'COLLATE %s' % type_.collation
else:
collation = None
-
+
if not length:
length = type_.length
-
+
if length:
spec = spec + "(%s)" % length
-
+
return ' '.join([c for c in (spec, collation)
if c is not None])
@@ -535,10 +535,10 @@ class MSTypeCompiler(compiler.GenericTypeCompiler):
def visit_unicode(self, type_):
return self.visit_NVARCHAR(type_)
-
+
def visit_unicode_text(self, type_):
return self.visit_NTEXT(type_)
-
+
def visit_NTEXT(self, type_):
return self._extend("NTEXT", type_)
@@ -570,7 +570,7 @@ class MSTypeCompiler(compiler.GenericTypeCompiler):
return self.visit_DATETIME(type_)
else:
return self.visit_TIME(type_)
-
+
def visit_large_binary(self, type_):
return self.visit_IMAGE(type_)
@@ -600,7 +600,7 @@ class MSExecutionContext(default.DefaultExecutionContext):
_select_lastrowid = False
_result_proxy = None
_lastrowid = None
-
+
def pre_exec(self):
"""Activate IDENTITY_INSERT if needed."""
@@ -608,25 +608,25 @@ class MSExecutionContext(default.DefaultExecutionContext):
tbl = self.compiled.statement.table
seq_column = tbl._autoincrement_column
insert_has_sequence = seq_column is not None
-
+
if insert_has_sequence:
self._enable_identity_insert = \
seq_column.key in self.compiled_parameters[0]
else:
self._enable_identity_insert = False
-
+
self._select_lastrowid = insert_has_sequence and \
not self.compiled.returning and \
not self._enable_identity_insert and \
not self.executemany
-
+
if self._enable_identity_insert:
self.cursor.execute("SET IDENTITY_INSERT %s ON" %
self.dialect.identifier_preparer.format_table(tbl))
def post_exec(self):
"""Disable IDENTITY_INSERT if enabled."""
-
+
if self._select_lastrowid:
if self.dialect.use_scope_identity:
self.cursor.execute(
@@ -640,17 +640,17 @@ class MSExecutionContext(default.DefaultExecutionContext):
if (self.isinsert or self.isupdate or self.isdelete) and \
self.compiled.returning:
self._result_proxy = base.FullyBufferedResultProxy(self)
-
+
if self._enable_identity_insert:
self.cursor.execute(
- "SET IDENTITY_INSERT %s OFF" %
+ "SET IDENTITY_INSERT %s OFF" %
self.dialect.identifier_preparer.
format_table(self.compiled.statement.table)
)
-
+
def get_lastrowid(self):
return self._lastrowid
-
+
def handle_dbapi_exception(self, e):
if self._enable_identity_insert:
try:
@@ -670,7 +670,7 @@ class MSExecutionContext(default.DefaultExecutionContext):
class MSSQLCompiler(compiler.SQLCompiler):
returning_precedes_values = True
-
+
extract_map = util.update_copy(
compiler.SQLCompiler.extract_map,
{
@@ -686,31 +686,31 @@ class MSSQLCompiler(compiler.SQLCompiler):
def visit_now_func(self, fn, **kw):
return "CURRENT_TIMESTAMP"
-
+
def visit_current_date_func(self, fn, **kw):
return "GETDATE()"
-
+
def visit_length_func(self, fn, **kw):
return "LEN%s" % self.function_argspec(fn, **kw)
-
+
def visit_char_length_func(self, fn, **kw):
return "LEN%s" % self.function_argspec(fn, **kw)
-
+
def visit_concat_op(self, binary, **kw):
return "%s + %s" % \
(self.process(binary.left, **kw),
self.process(binary.right, **kw))
-
+
def visit_match_op(self, binary, **kw):
return "CONTAINS (%s, %s)" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw))
-
+
def get_select_precolumns(self, select):
""" MS-SQL puts TOP, it's version of LIMIT here """
if select._distinct or select._limit:
s = select._distinct and "DISTINCT " or ""
-
+
# ODBC drivers and possibly others
# don't support bind params in the SELECT clause on SQL Server.
# so have to use literal here.
@@ -743,7 +743,7 @@ class MSSQLCompiler(compiler.SQLCompiler):
sql.literal_column("ROW_NUMBER() OVER (ORDER BY %s)" \
% orderby).label("mssql_rn")
).order_by(None).alias()
-
+
mssql_rn = sql.column('mssql_rn')
limitselect = sql.select([c for c in select.c if
c.key!='mssql_rn'])
@@ -853,7 +853,7 @@ class MSSQLCompiler(compiler.SQLCompiler):
target = stmt.table.alias("inserted")
else:
target = stmt.table.alias("deleted")
-
+
adapter = sql_util.ClauseAdapter(target)
def col_label(col):
adapted = adapter.traverse(col)
@@ -861,7 +861,7 @@ class MSSQLCompiler(compiler.SQLCompiler):
return adapted.label(c.key)
else:
return self.label_select_column(None, adapted, asfrom=False)
-
+
columns = [
self.process(
col_label(c),
@@ -896,10 +896,10 @@ class MSSQLCompiler(compiler.SQLCompiler):
class MSSQLStrictCompiler(MSSQLCompiler):
"""A subclass of MSSQLCompiler which disables the usage of bind
parameters where not allowed natively by MS-SQL.
-
+
A dialect may use this compiler on a platform where native
binds are used.
-
+
"""
ansi_bind_rules = True
@@ -927,9 +927,9 @@ class MSSQLStrictCompiler(MSSQLCompiler):
format acceptable to MSSQL. That seems to be the
so-called ODBC canonical date format which looks
like this:
-
+
yyyy-mm-dd hh:mi:ss.mmm(24h)
-
+
For other data types, call the base class implementation.
"""
# datetime and date are both subclasses of datetime.date
@@ -950,12 +950,12 @@ class MSDDLCompiler(compiler.DDLCompiler):
colspec += " NOT NULL"
else:
colspec += " NULL"
-
+
if column.table is None:
raise exc.InvalidRequestError(
"mssql requires Table-bound columns "
"in order to generate DDL")
-
+
seq_col = column.table._autoincrement_column
# install a IDENTITY Sequence if we have an implicit IDENTITY column
@@ -1015,13 +1015,13 @@ class MSDialect(default.DefaultDialect):
}
ischema_names = ischema_names
-
+
supports_native_boolean = False
supports_unicode_binds = True
postfetch_lastrowid = True
-
+
server_version_info = ()
-
+
statement_compiler = MSSQLCompiler
ddl_compiler = MSDDLCompiler
type_compiler = MSTypeCompiler
@@ -1039,7 +1039,7 @@ class MSDialect(default.DefaultDialect):
self.max_identifier_length = int(max_identifier_length or 0) or \
self.max_identifier_length
super(MSDialect, self).__init__(**opts)
-
+
def do_savepoint(self, connection, name):
util.warn("Savepoint support in mssql is experimental and "
"may lead to data loss.")
@@ -1048,7 +1048,7 @@ class MSDialect(default.DefaultDialect):
def do_release_savepoint(self, connection, name):
pass
-
+
def initialize(self, connection):
super(MSDialect, self).initialize(connection)
if self.server_version_info[0] not in range(8, 17):
@@ -1064,7 +1064,7 @@ class MSDialect(default.DefaultDialect):
if self.server_version_info >= MS_2005_VERSION and \
'implicit_returning' not in self.__dict__:
self.implicit_returning = True
-
+
def _get_default_schema_name(self, connection):
user_name = connection.scalar("SELECT user_name() as user_name;")
if user_name is not None:
@@ -1138,7 +1138,7 @@ class MSDialect(default.DefaultDialect):
# below MS 2005
if self.server_version_info < MS_2005_VERSION:
return []
-
+
current_schema = schema or self.default_schema_name
full_tname = "%s.%s" % (current_schema, tablename)
@@ -1186,7 +1186,7 @@ class MSDialect(default.DefaultDialect):
for row in rp:
if row['index_id'] in indexes:
indexes[row['index_id']]['column_names'].append(row['name'])
-
+
return indexes.values()
@reflection.cache
@@ -1315,7 +1315,7 @@ class MSDialect(default.DefaultDialect):
# the constrained column
C = ischema.key_constraints.alias('C')
# information_schema.constraint_column_usage:
- # the referenced column
+ # the referenced column
R = ischema.key_constraints.alias('R')
# Primary key constraints
@@ -1337,7 +1337,7 @@ class MSDialect(default.DefaultDialect):
#information_schema.referential_constraints
RR = ischema.ref_constraints
# information_schema.table_constraints
- TC = ischema.constraints
+ TC = ischema.constraints
# information_schema.constraint_column_usage:
# the constrained column
C = ischema.key_constraints.alias('C')
@@ -1361,12 +1361,12 @@ class MSDialect(default.DefaultDialect):
order_by = [
RR.c.constraint_name,
R.c.ordinal_position])
-
+
# group rows by constraint ID, to handle multi-column FKs
fkeys = []
fknm, scols, rcols = (None, [], [])
-
+
def fkey_rec():
return {
'name' : None,
@@ -1377,7 +1377,7 @@ class MSDialect(default.DefaultDialect):
}
fkeys = util.defaultdict(fkey_rec)
-
+
for r in connection.execute(s).fetchall():
scol, rschema, rtbl, rcol, rfknm, fkmatch, fkuprule, fkdelrule = r
@@ -1388,11 +1388,11 @@ class MSDialect(default.DefaultDialect):
if schema is not None or current_schema != rschema:
rec['referred_schema'] = rschema
-
+
local_cols, remote_cols = \
rec['constrained_columns'],\
rec['referred_columns']
-
+
local_cols.append(scol)
remote_cols.append(rcol)