本文整理汇总了Python中sqlalchemy.dialects.sqlite.base.dialect方法的典型用法代码示例。如果您正苦于以下问题:Python base.dialect方法的具体用法?Python base.dialect怎么用?Python base.dialect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.dialects.sqlite.base
的用法示例。
在下文中一共展示了base.dialect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_convert_unicode
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_no_convert_unicode(self):
"""test no utf-8 encoding occurs"""
dialect = sqlite.dialect()
for t in (
String(),
sqltypes.CHAR(),
sqltypes.Unicode(),
sqltypes.UnicodeText(),
String(),
sqltypes.CHAR(),
sqltypes.Unicode(),
sqltypes.UnicodeText(),
):
bindproc = t.dialect_impl(dialect).bind_processor(dialect)
assert not bindproc or isinstance(
bindproc(util.u("some string")), util.text_type
)
示例2: test_extra_reserved_words
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_extra_reserved_words(self):
"""Tests reserved words in identifiers.
'true', 'false', and 'column' are undocumented reserved words
when used as column identifiers (as of 3.5.1). Covering them
here to ensure they remain in place if the dialect's
reserved_words set is updated in the future. """
meta = MetaData(testing.db)
t = Table(
"reserved",
meta,
Column("safe", Integer),
Column("true", Integer),
Column("false", Integer),
Column("column", Integer),
Column("exists", Integer),
)
try:
meta.create_all()
t.insert().execute(safe=1)
list(t.select().execute())
finally:
meta.drop_all()
示例3: test_in_tuple
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_in_tuple(self):
compiled = (
tuple_(column("q"), column("p"))
.in_([(1, 2), (3, 4)])
.compile(dialect=sqlite.dialect())
)
eq_(str(compiled), "(q, p) IN ([POSTCOMPILE_param_1])")
eq_(
compiled._literal_execute_expanding_parameter(
"param_1",
compiled.binds["param_1"],
compiled.binds["param_1"].value,
),
(
[
("param_1_1_1", 1),
("param_1_1_2", 2),
("param_1_2_1", 3),
("param_1_2_2", 4),
],
"VALUES (?, ?), (?, ?)",
),
)
示例4: test_on_conflict_clause_column_many_clause
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_on_conflict_clause_column_many_clause(self):
meta = MetaData()
t = Table(
"n",
meta,
Column(
"test",
Integer,
nullable=False,
primary_key=True,
sqlite_on_conflict_not_null="FAIL",
sqlite_on_conflict_primary_key="IGNORE",
),
)
self.assert_compile(
CreateTable(t),
"CREATE TABLE n ("
"test INTEGER NOT NULL ON CONFLICT FAIL, "
"PRIMARY KEY (test) ON CONFLICT IGNORE)",
dialect=sqlite.dialect(),
)
示例5: test_on_conflict_clause_unique_constraint
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_on_conflict_clause_unique_constraint(self):
meta = MetaData()
t = Table(
"n",
meta,
Column("id", Integer),
Column("x", String(30)),
UniqueConstraint("id", "x", sqlite_on_conflict="FAIL"),
)
self.assert_compile(
CreateTable(t),
"CREATE TABLE n (id INTEGER, x VARCHAR(30), "
"UNIQUE (id, x) ON CONFLICT FAIL)",
dialect=sqlite.dialect(),
)
示例6: test_on_conflict_clause_primary_key
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_on_conflict_clause_primary_key(self):
meta = MetaData()
t = Table(
"n",
meta,
Column(
"id",
Integer,
primary_key=True,
sqlite_on_conflict_primary_key="FAIL",
),
sqlite_autoincrement=True,
)
self.assert_compile(
CreateTable(t),
"CREATE TABLE n (id INTEGER NOT NULL "
"PRIMARY KEY ON CONFLICT FAIL AUTOINCREMENT)",
dialect=sqlite.dialect(),
)
示例7: test_on_conflict_clause_primary_key_constraint_from_column
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_on_conflict_clause_primary_key_constraint_from_column(self):
meta = MetaData()
t = Table(
"n",
meta,
Column(
"x",
String(30),
sqlite_on_conflict_primary_key="FAIL",
primary_key=True,
),
)
self.assert_compile(
CreateTable(t),
"CREATE TABLE n (x VARCHAR(30) NOT NULL, "
"PRIMARY KEY (x) ON CONFLICT FAIL)",
dialect=sqlite.dialect(),
)
示例8: test_on_conflict_clause_check_constraint_from_column
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_on_conflict_clause_check_constraint_from_column(self):
meta = MetaData()
t = Table(
"n",
meta,
Column(
"x",
Integer,
CheckConstraint("x > 1", sqlite_on_conflict="FAIL"),
),
)
assert_raises_message(
exc.CompileError,
"SQLite does not support on conflict "
"clause for column check constraint",
CreateTable(t).compile,
dialect=sqlite.dialect(),
)
示例9: test_on_conflict_clause_primary_key_constraint
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_on_conflict_clause_primary_key_constraint(self):
meta = MetaData()
t = Table(
"n",
meta,
Column("id", Integer),
Column("x", String(30)),
PrimaryKeyConstraint("id", "x", sqlite_on_conflict="FAIL"),
)
self.assert_compile(
CreateTable(t),
"CREATE TABLE n ("
"id INTEGER NOT NULL, "
"x VARCHAR(30) NOT NULL, "
"PRIMARY KEY (id, x) ON CONFLICT FAIL)",
dialect=sqlite.dialect(),
)
示例10: test_sqlite_autoincrement_constraint
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_sqlite_autoincrement_constraint(self):
table = Table(
"autoinctable",
MetaData(),
Column("id", Integer, primary_key=True),
Column("x", Integer, default=None),
UniqueConstraint("x"),
sqlite_autoincrement=True,
)
self.assert_compile(
schema.CreateTable(table),
"CREATE TABLE autoinctable (id INTEGER NOT "
"NULL PRIMARY KEY AUTOINCREMENT, x "
"INTEGER, UNIQUE (x))",
dialect=sqlite.dialect(),
)
示例11: test_sqlite_autoincrement_int_affinity
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_sqlite_autoincrement_int_affinity(self):
class MyInteger(sqltypes.TypeDecorator):
impl = Integer
table = Table(
"autoinctable",
MetaData(),
Column("id", MyInteger, primary_key=True),
sqlite_autoincrement=True,
)
self.assert_compile(
schema.CreateTable(table),
"CREATE TABLE autoinctable (id INTEGER NOT "
"NULL PRIMARY KEY AUTOINCREMENT)",
dialect=sqlite.dialect(),
)
示例12: test_types
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_types(self):
class MyType(TypeEngine):
pass
@compiles(MyType, "sqlite")
def visit_sqlite_type(type_, compiler, **kw):
return "SQLITE_FOO"
@compiles(MyType, "postgresql")
def visit_pg_type(type_, compiler, **kw):
return "POSTGRES_FOO"
from sqlalchemy.dialects.sqlite import base as sqlite
from sqlalchemy.dialects.postgresql import base as postgresql
self.assert_compile(MyType(), "SQLITE_FOO", dialect=sqlite.dialect())
self.assert_compile(
MyType(), "POSTGRES_FOO", dialect=postgresql.dialect()
)
示例13: test_functions
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_functions(self):
from sqlalchemy.dialects import postgresql
class MyUtcFunction(FunctionElement):
pass
@compiles(MyUtcFunction)
def visit_myfunc(element, compiler, **kw):
return "utcnow()"
@compiles(MyUtcFunction, "postgresql")
def visit_myfunc_pg(element, compiler, **kw):
return "timezone('utc', current_timestamp)"
self.assert_compile(
MyUtcFunction(), "utcnow()", use_default_dialect=True
)
self.assert_compile(
MyUtcFunction(),
"timezone('utc', current_timestamp)",
dialect=postgresql.dialect(),
)
示例14: test_type_compile
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_type_compile(self):
from sqlalchemy.dialects.sqlite.base import dialect as SQLiteDialect
cast = sa.cast(column("x"), sa.Integer)
@profile_memory()
def go():
dialect = SQLiteDialect()
cast.compile(dialect=dialect)
go()
示例15: test_native_datetime
# 需要导入模块: from sqlalchemy.dialects.sqlite import base [as 别名]
# 或者: from sqlalchemy.dialects.sqlite.base import dialect [as 别名]
def test_native_datetime(self):
dbapi = testing.db.dialect.dbapi
connect_args = {
"detect_types": dbapi.PARSE_DECLTYPES | dbapi.PARSE_COLNAMES
}
engine = engines.testing_engine(
options={"connect_args": connect_args, "native_datetime": True}
)
t = Table(
"datetest",
MetaData(),
Column("id", Integer, primary_key=True),
Column("d1", Date),
Column("d2", sqltypes.TIMESTAMP),
)
t.create(engine)
try:
with engine.begin() as conn:
conn.execute(
t.insert(),
{
"d1": datetime.date(2010, 5, 10),
"d2": datetime.datetime(2010, 5, 10, 12, 15, 25),
},
)
row = conn.execute(t.select()).first()
eq_(
row,
(
1,
datetime.date(2010, 5, 10),
datetime.datetime(2010, 5, 10, 12, 15, 25),
),
)
r = conn.execute(func.current_date()).scalar()
assert isinstance(r, util.string_types)
finally:
t.drop(engine)
engine.dispose()