当前位置: 首页>>代码示例>>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;未经允许,请勿转载。