Python sqlalchemy.sql.compiler.SQLCompiler() Examples
The following are 20
code examples of sqlalchemy.sql.compiler.SQLCompiler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql.compiler
, or try the search function
.
Example #1
Source File: utils.py From jqdatasdk with MIT License | 6 votes |
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))
Example #2
Source File: base.py From android_universal with MIT License | 5 votes |
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)
Example #3
Source File: base.py From jbox with MIT License | 5 votes |
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 ""
Example #4
Source File: base.py From android_universal with MIT License | 5 votes |
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 ""
Example #5
Source File: base.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: base.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
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 ""
Example #7
Source File: base.py From jarvis with GNU General Public License v2.0 | 5 votes |
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)
Example #8
Source File: base.py From jarvis with GNU General Public License v2.0 | 5 votes |
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 ""
Example #9
Source File: test_compiler.py From sqlalchemy with MIT License | 5 votes |
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, )
Example #10
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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_slice(self, element, **kw): return "%s:%s" % ( self.process(element.start, **kw), self.process(element.stop, **kw), ) def visit_getitem_binary(self, binary, operator, **kw): return "%s[%s]" % ( self.process(binary.left, **kw), self.process(binary.right, **kw), ) class MyDialect(default.DefaultDialect): statement_compiler = MyCompiler type_compiler = MyTypeCompiler class MyType(ARRAY): __visit_name__ = "mytype" def __init__(self, zero_indexes=False, dimensions=1): if zero_indexes: self.zero_indexes = zero_indexes self.dimensions = dimensions self.item_type = Integer() self.MyType = MyType self.__dialect__ = MyDialect()
Example #11
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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()
Example #12
Source File: base.py From stdm with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: base.py From stdm with GNU General Public License v2.0 | 5 votes |
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 ""
Example #14
Source File: base.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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)
Example #15
Source File: base.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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 ""
Example #16
Source File: base.py From planespotter with MIT License | 5 votes |
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)
Example #17
Source File: base.py From planespotter with MIT License | 5 votes |
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 ""
Example #18
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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 ""
Example #20
Source File: base.py From jbox with MIT License | 5 votes |
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)