當前位置: 首頁>>代碼示例>>Python>>正文


Python base.dialect方法代碼示例

本文整理匯總了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
            ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:20,代碼來源:test_sqlite.py

示例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() 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:26,代碼來源:test_sqlite.py

示例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 (?, ?), (?, ?)",
            ),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:25,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:19,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:23,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:22,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:22,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:21,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_sqlite.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_sqlite.py

示例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()
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:22,代碼來源:test_compiler.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_compiler.py

示例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() 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:13,代碼來源:test_memusage.py

示例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() 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:41,代碼來源:test_sqlite.py


注:本文中的sqlalchemy.dialects.sqlite.base.dialect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。