本文整理汇总了Python中sqlalchemy.types.VARBINARY属性的典型用法代码示例。如果您正苦于以下问题:Python types.VARBINARY属性的具体用法?Python types.VARBINARY怎么用?Python types.VARBINARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.types
的用法示例。
在下文中一共展示了types.VARBINARY属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_typedec_to_nonstandard
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_typedec_to_nonstandard(self, impl_fixture):
class PasswordType(TypeDecorator):
impl = VARBINARY
def copy(self, **kw):
return PasswordType(self.impl.length)
def load_dialect_impl(self, dialect):
if dialect.name == "default":
impl = sqlite.NUMERIC(self.length)
else:
impl = VARBINARY(self.length)
return dialect.type_descriptor(impl)
impl_fixture.compare_type(
Column("x", sqlite.NUMERIC(50)), Column("x", PasswordType(50))
)
示例2: test_large_type_deprecation
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_large_type_deprecation(self):
d1 = mssql.dialect(deprecate_large_types=True)
d2 = mssql.dialect(deprecate_large_types=False)
d3 = mssql.dialect()
d3.server_version_info = (11, 0)
d3._setup_version_attributes()
d4 = mssql.dialect()
d4.server_version_info = (10, 0)
d4._setup_version_attributes()
for dialect in (d1, d3):
eq_(str(Text().compile(dialect=dialect)), "VARCHAR(max)")
eq_(str(UnicodeText().compile(dialect=dialect)), "NVARCHAR(max)")
eq_(str(LargeBinary().compile(dialect=dialect)), "VARBINARY(max)")
for dialect in (d2, d4):
eq_(str(Text().compile(dialect=dialect)), "TEXT")
eq_(str(UnicodeText().compile(dialect=dialect)), "NTEXT")
eq_(str(LargeBinary().compile(dialect=dialect)), "IMAGE")
示例3: test_max_ident_in_varchar_not_present
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_max_ident_in_varchar_not_present(self):
"""test [ticket:3504].
Here we are testing not just that the "max" token comes back
as None, but also that these types accept "max" as the value
of "length" on construction, which isn't a directly documented
pattern however is likely in common use.
"""
metadata = self.metadata
Table(
"t",
metadata,
Column("t1", types.String),
Column("t2", types.Text("max")),
Column("t3", types.Text("max")),
Column("t4", types.LargeBinary("max")),
Column("t5", types.VARBINARY("max")),
)
metadata.create_all()
for col in inspect(testing.db).get_columns("t"):
is_(col["type"].length, None)
in_("max", str(col["type"].compile(dialect=testing.db.dialect)))
示例4: test_binary
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_binary(self):
"Exercise type specification for binary types."
columns = [
# column type, args, kwargs, expected ddl
(mssql.MSBinary, [], {}, "BINARY"),
(mssql.MSBinary, [10], {}, "BINARY(10)"),
(types.BINARY, [], {}, "BINARY"),
(types.BINARY, [10], {}, "BINARY(10)"),
(mssql.MSVarBinary, [], {}, "VARBINARY(max)"),
(mssql.MSVarBinary, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [], {}, "VARBINARY(max)"),
(mssql.MSImage, [], {}, "IMAGE"),
(mssql.IMAGE, [], {}, "IMAGE"),
(types.LargeBinary, [], {}, "IMAGE"),
]
metadata = MetaData()
table_args = ["test_mssql_binary", metadata]
for index, spec in enumerate(columns):
type_, args, kw, res = spec
table_args.append(
Column("c%s" % index, type_(*args, **kw), nullable=None)
)
binary_table = Table(*table_args)
dialect = mssql.dialect()
gen = dialect.ddl_compiler(dialect, schema.CreateTable(binary_table))
for col in binary_table.c:
index = int(col.name[1:])
testing.eq_(
gen.get_column_specification(col),
"%s %s" % (col.name, columns[index][3]),
)
self.assert_(repr(col))
示例5: test_mssql_varbinary_max
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_mssql_varbinary_max(self):
stream1 = self._load_stream("binary_data_one.dat")
self._test_round_trip(mssql.VARBINARY("max"), stream1)
示例6: test_mssql_legacy_varbinary_max
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_mssql_legacy_varbinary_max(self):
stream1 = self._load_stream("binary_data_one.dat")
self._test_round_trip(
mssql.VARBINARY("max"), stream1, deprecate_large_types=False
)
示例7: test_varbinary_slice_zeropadding
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_varbinary_slice_zeropadding(self):
self._test_var_slice_zeropadding(types.VARBINARY, False)
示例8: test_mssql_varbinary_slice
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_mssql_varbinary_slice(self):
self._test_var_slice(mssql.VARBINARY)
示例9: test_mssql_varbinary_slice_zeropadding
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def test_mssql_varbinary_slice_zeropadding(self):
self._test_var_slice_zeropadding(mssql.VARBINARY, False)
示例10: _test_binary_reflection
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import VARBINARY [as 别名]
def _test_binary_reflection(self, deprecate_large_types):
"Exercise type specification for binary types."
columns = [
# column type, args, kwargs, expected ddl from reflected
(mssql.MSBinary, [], {}, "BINARY(1)"),
(mssql.MSBinary, [10], {}, "BINARY(10)"),
(types.BINARY, [], {}, "BINARY(1)"),
(types.BINARY, [10], {}, "BINARY(10)"),
(mssql.MSVarBinary, [], {}, "VARBINARY(max)"),
(mssql.MSVarBinary, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [], {}, "VARBINARY(max)"),
(mssql.MSImage, [], {}, "IMAGE"),
(mssql.IMAGE, [], {}, "IMAGE"),
(
types.LargeBinary,
[],
{},
"IMAGE" if not deprecate_large_types else "VARBINARY(max)",
),
]
metadata = self.metadata
metadata.bind = engines.testing_engine(
options={"deprecate_large_types": deprecate_large_types}
)
table_args = ["test_mssql_binary", metadata]
for index, spec in enumerate(columns):
type_, args, kw, res = spec
table_args.append(
Column("c%s" % index, type_(*args, **kw), nullable=None)
)
binary_table = Table(*table_args)
metadata.create_all()
reflected_binary = Table(
"test_mssql_binary", MetaData(testing.db), autoload=True
)
for col, spec in zip(reflected_binary.c, columns):
eq_(
str(col.type),
spec[3],
"column %s %s != %s" % (col.key, str(col.type), spec[3]),
)
c1 = testing.db.dialect.type_descriptor(col.type).__class__
c2 = testing.db.dialect.type_descriptor(
binary_table.c[col.name].type
).__class__
assert issubclass(
c1, c2
), "column %s: %r is not a subclass of %r" % (col.key, c1, c2)
if binary_table.c[col.name].type.length:
testing.eq_(
col.type.length, binary_table.c[col.name].type.length
)