本文整理汇总了Python中sqlalchemy.engine.default.DefaultDialect方法的典型用法代码示例。如果您正苦于以下问题:Python default.DefaultDialect方法的具体用法?Python default.DefaultDialect怎么用?Python default.DefaultDialect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.engine.default
的用法示例。
在下文中一共展示了default.DefaultDialect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_dialect
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def _get_dialect(name):
if name is None or name == "default":
return default.DefaultDialect()
else:
try:
dialect_mod = _dialect_mods[name]
except KeyError:
dialect_mod = getattr(
__import__("sqlalchemy.dialects.%s" % name).dialects, name
)
_dialect_mods[name] = dialect_mod
d = dialect_mod.dialect()
if name == "postgresql":
d.implicit_returning = True
elif name == "mssql":
d.legacy_schema_aliasing = False
return d
示例2: test_unicode_warnings_dialectlevel
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_unicode_warnings_dialectlevel(self):
unicodedata = self.data
with testing.expect_deprecated(
"The create_engine.convert_unicode parameter and "
"corresponding dialect-level"
):
dialect = default.DefaultDialect(convert_unicode=True)
dialect.supports_unicode_binds = False
s = String()
uni = s.dialect_impl(dialect).bind_processor(dialect)
uni(util.b("x"))
assert isinstance(uni(unicodedata), util.binary_type)
eq_(uni(unicodedata), unicodedata.encode("utf-8"))
示例3: test_ignoring_unicode_error
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_ignoring_unicode_error(self):
"""checks String(unicode_error='ignore') is passed to
underlying codec."""
unicodedata = self.data
with testing.expect_deprecated(
"The String.convert_unicode parameter is deprecated and "
"will be removed in a future release.",
"The String.unicode_errors parameter is deprecated and "
"will be removed in a future release.",
):
type_ = String(
248, convert_unicode="force", unicode_error="ignore"
)
dialect = default.DefaultDialect(encoding="ascii")
proc = type_.result_processor(dialect, 10)
utfdata = unicodedata.encode("utf8")
eq_(proc(utfdata), unicodedata.encode("ascii", "ignore").decode())
示例4: test_positional
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_positional(self):
table1 = self.tables.mytable
values = [
{"myid": 1, "name": "a", "description": "b"},
{"myid": 2, "name": "c", "description": "d"},
{"myid": 3, "name": "e", "description": "f"},
]
checkpositional = (1, "a", "b", 2, "c", "d", 3, "e", "f")
dialect = default.DefaultDialect()
dialect.supports_multivalues_insert = True
dialect.paramstyle = "format"
dialect.positional = True
self.assert_compile(
table1.insert().values(values),
"INSERT INTO mytable (myid, name, description) VALUES "
"(%s, %s, %s), (%s, %s, %s), (%s, %s, %s)",
checkpositional=checkpositional,
dialect=dialect,
)
示例5: test_unformat
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_unformat(self):
prep = compiler.IdentifierPreparer(default.DefaultDialect())
unformat = prep.unformat_identifiers
def a_eq(have, want):
if have != want:
print("Wanted %s" % want)
print("Received %s" % have)
self.assert_(have == want)
a_eq(unformat("foo"), ["foo"])
a_eq(unformat('"foo"'), ["foo"])
a_eq(unformat("'foo'"), ["'foo'"])
a_eq(unformat("foo.bar"), ["foo", "bar"])
a_eq(unformat('"foo"."bar"'), ["foo", "bar"])
a_eq(unformat('foo."bar"'), ["foo", "bar"])
a_eq(unformat('"foo".bar'), ["foo", "bar"])
a_eq(unformat('"foo"."b""a""r"."baz"'), ["foo", 'b"a"r', "baz"])
示例6: test_bind_process
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_bind_process(self):
eq_(
self.variant._cached_bind_processor(dialects.mysql.dialect())(
"foo"
),
"fooUONE",
)
eq_(
self.variant._cached_bind_processor(default.DefaultDialect())(
"foo"
),
"fooUONE",
)
eq_(
self.variant._cached_bind_processor(dialects.postgresql.dialect())(
"foo"
),
"fooUTWO",
)
示例7: test_kwarg_legacy_typecompiler
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_kwarg_legacy_typecompiler(self):
from sqlalchemy.sql import compiler
class SomeTypeCompiler(compiler.GenericTypeCompiler):
# transparently decorated w/ kw decorator
def visit_VARCHAR(self, type_):
return "MYVARCHAR"
# not affected
def visit_INTEGER(self, type_, **kw):
return "MYINTEGER %s" % kw["type_expression"].name
dialect = default.DefaultDialect()
dialect.type_compiler = SomeTypeCompiler(dialect)
self.assert_compile(
ddl.CreateColumn(Column("bar", VARCHAR(50))),
"bar MYVARCHAR",
dialect=dialect,
)
self.assert_compile(
ddl.CreateColumn(Column("bar", INTEGER)),
"bar MYINTEGER bar",
dialect=dialect,
)
示例8: _test_colnames_longer_than_labels
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def _test_colnames_longer_than_labels(self, t1):
dialect = default.DefaultDialect(label_length=4)
a1 = t1.alias(name="asdf")
# 'abcde' is longer than 4, but rendered as itself
# needs to have all characters
s = select([a1])
self.assert_compile(
select([a1]), "SELECT asdf.abcde FROM a AS asdf", dialect=dialect
)
compiled = s.compile(dialect=dialect)
assert set(compiled._create_result_map()["abcde"][1]).issuperset(
["abcde", a1.c.abcde, "abcde"]
)
# column still there, but short label
s = select([a1]).apply_labels()
self.assert_compile(
s, "SELECT asdf.abcde AS _1 FROM a AS asdf", dialect=dialect
)
compiled = s.compile(dialect=dialect)
assert set(compiled._create_result_map()["_1"][1]).issuperset(
["asdf_abcde", a1.c.abcde, "_1"]
)
示例9: test_label_overlap_unlabeled
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_label_overlap_unlabeled(self):
"""test that an anon col can't overlap with a fixed name, #3396"""
table1 = table(
"tablename", column("columnname_one"), column("columnn_1")
)
stmt = select([table1]).apply_labels()
dialect = default.DefaultDialect(label_length=23)
self.assert_compile(
stmt,
"SELECT tablename.columnname_one AS tablename_columnn_1, "
"tablename.columnn_1 AS tablename_columnn_2 FROM tablename",
dialect=dialect,
)
compiled = stmt.compile(dialect=dialect)
eq_(
set(compiled._create_result_map()),
set(["tablename_columnn_1", "tablename_columnn_2"]),
)
示例10: test_order_by_labels_disabled
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_order_by_labels_disabled(self):
lab1 = (table1.c.myid + 12).label("foo")
lab2 = func.somefunc(table1.c.name).label("bar")
dialect = default.DefaultDialect()
dialect.supports_simple_order_by_label = False
self.assert_compile(
select([lab1, lab2]).order_by(lab1, desc(lab2)),
"SELECT mytable.myid + :myid_1 AS foo, "
"somefunc(mytable.name) AS bar FROM mytable "
"ORDER BY mytable.myid + :myid_1, somefunc(mytable.name) DESC",
dialect=dialect,
)
self.assert_compile(
select([lab1, lab2]).order_by(func.hoho(lab1), desc(lab2)),
"SELECT mytable.myid + :myid_1 AS foo, "
"somefunc(mytable.name) AS bar FROM mytable "
"ORDER BY hoho(mytable.myid + :myid_1), "
"somefunc(mytable.name) DESC",
dialect=dialect,
)
示例11: test_true_short_circuit
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_true_short_circuit(self):
t = table("t", column("x"))
self.assert_compile(
select([t]).where(true()),
"SELECT t.x FROM t WHERE 1 = 1",
dialect=default.DefaultDialect(supports_native_boolean=False),
)
self.assert_compile(
select([t]).where(true()),
"SELECT t.x FROM t WHERE true",
dialect=default.DefaultDialect(supports_native_boolean=True),
)
self.assert_compile(
select([t]),
"SELECT t.x FROM t",
dialect=default.DefaultDialect(supports_native_boolean=True),
)
示例12: test_expanding_parameter
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def test_expanding_parameter(self):
self.assert_compile(
tuple_(table1.c.myid, table1.c.name).in_(
bindparam("foo", expanding=True)
),
"(mytable.myid, mytable.name) IN ([POSTCOMPILE_foo])",
)
dialect = default.DefaultDialect()
dialect.tuple_in_values = True
self.assert_compile(
tuple_(table1.c.myid, table1.c.name).in_(
bindparam("foo", expanding=True)
),
"(mytable.myid, mytable.name) IN ([POSTCOMPILE_foo])",
dialect=dialect,
)
self.assert_compile(
table1.c.myid.in_(bindparam("foo", expanding=True)),
"mytable.myid IN ([POSTCOMPILE_foo])",
)
示例13: __init__
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def __init__(self,
use_ansi=True,
optimize_limits=False,
use_binds_for_limits=True,
**kwargs):
default.DefaultDialect.__init__(self, **kwargs)
self.use_ansi = use_ansi
self.optimize_limits = optimize_limits
self.use_binds_for_limits = use_binds_for_limits
示例14: _get_dialect
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def _get_dialect(name):
if name is None or name == 'default':
return default.DefaultDialect()
else:
try:
return _dialects[name]
except KeyError:
dialect_mod = getattr(
__import__('sqlalchemy.dialects.%s' % name).dialects, name)
_dialects[name] = d = dialect_mod.dialect()
if name == 'postgresql':
d.implicit_returning = True
elif name == 'mssql':
d.legacy_schema_aliasing = False
return d
示例15: render_python_code
# 需要导入模块: from sqlalchemy.engine import default [as 别名]
# 或者: from sqlalchemy.engine.default import DefaultDialect [as 别名]
def render_python_code(
up_or_down_op,
sqlalchemy_module_prefix="sa.",
alembic_module_prefix="op.",
render_as_batch=False,
imports=(),
render_item=None,
migration_context=None,
):
"""Render Python code given an :class:`.UpgradeOps` or
:class:`.DowngradeOps` object.
This is a convenience function that can be used to test the
autogenerate output of a user-defined :class:`.MigrationScript` structure.
"""
opts = {
"sqlalchemy_module_prefix": sqlalchemy_module_prefix,
"alembic_module_prefix": alembic_module_prefix,
"render_item": render_item,
"render_as_batch": render_as_batch,
}
if migration_context is None:
from ..runtime.migration import MigrationContext
from sqlalchemy.engine.default import DefaultDialect
migration_context = MigrationContext.configure(
dialect=DefaultDialect()
)
autogen_context = AutogenContext(migration_context, opts=opts)
autogen_context.imports = set(imports)
return render._indent(
render._render_cmd_body(up_or_down_op, autogen_context)
)