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


Python compiler.SQLCompiler方法代碼示例

本文整理匯總了Python中sqlalchemy.sql.compiler.SQLCompiler方法的典型用法代碼示例。如果您正苦於以下問題:Python compiler.SQLCompiler方法的具體用法?Python compiler.SQLCompiler怎麽用?Python compiler.SQLCompiler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.sql.compiler的用法示例。


在下文中一共展示了compiler.SQLCompiler方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: compile_query

# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def compile_query(query):
    """ 把一個 sqlalchemy query object 編譯成mysql風格的 sql 語句 """
    from sqlalchemy.sql import compiler
    from sqlalchemy.dialects import mysql as mysql_dialetct
    from pymysql.converters import conversions, escape_item, encoders

    dialect = mysql_dialetct.dialect()
    statement = query.statement
    comp = compiler.SQLCompiler(dialect, statement)
    comp.compile()
    enc = dialect.encoding
    comp_params = comp.params
    params = []
    for k in comp.positiontup:
        v = comp_params[k]
        if six.PY2 and isinstance(v, six.string_types) and not isinstance(v, six.text_type):
            v = v.decode("utf8")
        v = escape_item(v, conversions, encoders)
        params.append(v)
    return (comp.string % tuple(params)) 
開發者ID:JoinQuant,項目名稱:jqdatasdk,代碼行數:22,代碼來源:utils.py

示例2: function_argspec

# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def function_argspec(self, fn, **kw):
        if len(fn.clauses) > 0 or fn.name.upper() not in NO_ARG_FNS:
            return compiler.SQLCompiler.function_argspec(self, fn, **kw)
        else:
            return "" 
開發者ID:jpush,項目名稱:jbox,代碼行數:7,代碼來源:base.py

示例3: visit_join

# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def visit_join(self, join, **kwargs):
        if self.dialect.use_ansi:
            return compiler.SQLCompiler.visit_join(self, join, **kwargs)
        else:
            kwargs['asfrom'] = True
            if isinstance(join.right, expression.FromGrouping):
                right = join.right.element
            else:
                right = join.right
            return self.process(join.left, **kwargs) + \
                ", " + self.process(right, **kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:13,代碼來源:base.py

示例4: setUp

# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def setUp(self):
        class MyTypeCompiler(compiler.GenericTypeCompiler):
            def visit_mytype(self, type_, **kw):
                return "MYTYPE"

            def visit_myothertype(self, type_, **kw):
                return "MYOTHERTYPE"

        class MyCompiler(compiler.SQLCompiler):
            def visit_json_getitem_op_binary(self, binary, operator, **kw):
                return self._generate_generic_binary(
                    binary, " -> ", eager_grouping=True, **kw
                )

            def visit_json_path_getitem_op_binary(
                self, binary, operator, **kw
            ):
                return self._generate_generic_binary(
                    binary, " #> ", eager_grouping=True, **kw
                )

            def visit_getitem_binary(self, binary, operator, **kw):
                raise NotImplementedError()

        class MyDialect(default.DefaultDialect):
            statement_compiler = MyCompiler
            type_compiler = MyTypeCompiler

        class MyType(JSON):
            __visit_name__ = "mytype"

            pass

        self.MyType = MyType
        self.__dialect__ = MyDialect() 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:37,代碼來源:test_operators.py

示例5: test_select_precol_compile_ordering

# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def test_select_precol_compile_ordering(self):
        s1 = (
            select([column("x")])
            .select_from(text("a"))
            .limit(5)
            .scalar_subquery()
        )
        s2 = select([s1]).limit(10)

        class MyCompiler(compiler.SQLCompiler):
            def get_select_precolumns(self, select, **kw):
                result = ""
                if select._limit:
                    result += "FIRST %s " % self.process(
                        literal(select._limit), **kw
                    )
                if select._offset:
                    result += "SKIP %s " % self.process(
                        literal(select._offset), **kw
                    )
                return result

            def limit_clause(self, select, **kw):
                return ""

        dialect = default.DefaultDialect()
        dialect.statement_compiler = MyCompiler
        dialect.paramstyle = "qmark"
        dialect.positional = True
        self.assert_compile(
            s2,
            "SELECT FIRST ? (SELECT FIRST ? x FROM a) AS anon_1",
            checkpositional=(10, 5),
            dialect=dialect,
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:37,代碼來源:test_compiler.py

示例6: visit_join

# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def visit_join(self, join, **kwargs):
        if self.dialect.use_ansi:
            return compiler.SQLCompiler.visit_join(self, join, **kwargs)
        else:
            kwargs['asfrom'] = True
            if isinstance(join.right, expression.FromGrouping):
                right = join.right.element
            else:
                right = join.right
            return self.process(join.left, **kwargs) + \
                        ", " + self.process(right, **kwargs) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:13,代碼來源:base.py


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