mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-06-03 06:19:59 -04:00
MSSQL refactoring of BINARY type and addition of MSVarBinary and MSImage.
- Added in new types: MSVarBinary and MSImage - Modified MSBinary to now return BINARY instead of IMAGE. This is a backwards incompatible change. Closes #1249.
This commit is contained in:
@@ -39,6 +39,7 @@ CHANGES
|
||||
built from it.
|
||||
|
||||
- mssql
|
||||
- Added in new types: MSVarBinary and MSImage. [ticket:1249]
|
||||
- Added in the MSReal and MSNText types.
|
||||
|
||||
- bugfixes, behavioral changes
|
||||
@@ -233,6 +234,11 @@ CHANGES
|
||||
new doc section "Custom Comparators".
|
||||
|
||||
- mssql
|
||||
- ``MSBinary`` now returns a ``BINARY`` instead of an
|
||||
``IMAGE``. This is a backwards incompatible change in that
|
||||
``BINARY`` is a fixed length data type whereas ``IMAGE`` is
|
||||
a variable length data type. [ticket:1249]
|
||||
|
||||
- ``get_default_schema_name`` is now reflected from the
|
||||
database based on the user's default schema. This only works
|
||||
with MSSQL 2005 and later. [ticket:1258]
|
||||
|
||||
@@ -677,9 +677,26 @@ class MSNChar(_StringType, sqltypes.NCHAR):
|
||||
|
||||
|
||||
class MSBinary(sqltypes.Binary):
|
||||
def get_col_spec(self):
|
||||
if self.length:
|
||||
return "BINARY(%s)" % self.length
|
||||
else:
|
||||
return "BINARY"
|
||||
|
||||
|
||||
class MSVarBinary(MSBinary):
|
||||
def get_col_spec(self):
|
||||
if self.length:
|
||||
return "VARBINARY(%s)" % self.length
|
||||
else:
|
||||
return "VARBINARY"
|
||||
|
||||
|
||||
class MSImage(MSBinary):
|
||||
def get_col_spec(self):
|
||||
return "IMAGE"
|
||||
|
||||
|
||||
class MSBoolean(sqltypes.Boolean):
|
||||
def get_col_spec(self):
|
||||
return "BIT"
|
||||
@@ -861,10 +878,10 @@ class MSSQLDialect(default.DefaultDialect):
|
||||
'date': MSDate,
|
||||
'smalldatetime' : MSSmallDate,
|
||||
'binary' : MSBinary,
|
||||
'varbinary' : MSBinary,
|
||||
'varbinary' : MSVarBinary,
|
||||
'bit': MSBoolean,
|
||||
'real' : MSFloat,
|
||||
'image' : MSBinary,
|
||||
'image' : MSImage,
|
||||
'timestamp': MSTimeStamp,
|
||||
'money': MSMoney,
|
||||
'smallmoney': MSSmallMoney,
|
||||
|
||||
+16
-4
@@ -548,6 +548,16 @@ class TypesTest2(TestBase, AssertsExecutionResults):
|
||||
columns = [
|
||||
# column type, args, kwargs, expected ddl
|
||||
(mssql.MSBinary, [], {},
|
||||
'BINARY'),
|
||||
(mssql.MSBinary, [10], {},
|
||||
'BINARY(10)'),
|
||||
|
||||
(mssql.MSVarBinary, [], {},
|
||||
'VARBINARY'),
|
||||
(mssql.MSVarBinary, [10], {},
|
||||
'VARBINARY(10)'),
|
||||
|
||||
(mssql.MSImage, [], {},
|
||||
'IMAGE')
|
||||
]
|
||||
|
||||
@@ -570,6 +580,12 @@ class TypesTest2(TestBase, AssertsExecutionResults):
|
||||
assert True
|
||||
except:
|
||||
raise
|
||||
|
||||
reflected_binary = Table('test_mssql_binary', MetaData(testing.db), autoload=True)
|
||||
for col in reflected_binary.c:
|
||||
testing.eq_(col.type.__class__, binary_table.c[col.name].type.__class__)
|
||||
if binary_table.c[col.name].type.length:
|
||||
testing.eq_(col.type.length, binary_table.c[col.name].type.length)
|
||||
binary_table.drop()
|
||||
|
||||
def test_boolean(self):
|
||||
@@ -678,8 +694,6 @@ class TypesTest2(TestBase, AssertsExecutionResults):
|
||||
'VARCHAR'),
|
||||
(mssql.MSString, [1], {},
|
||||
'VARCHAR(1)'),
|
||||
(mssql.MSString, ['max'], {},
|
||||
'VARCHAR(max)'),
|
||||
(mssql.MSString, [1], {'collation': 'Latin1_General_CI_AS'},
|
||||
'VARCHAR(1) COLLATE Latin1_General_CI_AS'),
|
||||
|
||||
@@ -687,8 +701,6 @@ class TypesTest2(TestBase, AssertsExecutionResults):
|
||||
'NVARCHAR'),
|
||||
(mssql.MSNVarchar, [1], {},
|
||||
'NVARCHAR(1)'),
|
||||
(mssql.MSNVarchar, ['max'], {},
|
||||
'NVARCHAR(max)'),
|
||||
(mssql.MSNVarchar, [1], {'collation': 'Latin1_General_CI_AS'},
|
||||
'NVARCHAR(1) COLLATE Latin1_General_CI_AS'),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user