本文整理汇总了Python中sqlparse.tokens.Literal方法的典型用法代码示例。如果您正苦于以下问题:Python tokens.Literal方法的具体用法?Python tokens.Literal怎么用?Python tokens.Literal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlparse.tokens
的用法示例。
在下文中一共展示了tokens.Literal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sql_literal_to_model
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Literal [as 别名]
def sql_literal_to_model(tok, m=M):
"""
:param m: the source model to "append" the literal to.
defaults to M - the sqlitis models module (which means a fresh model
is created)
:return: the resulting model
"""
def is_string_literal(tok):
text = tok.normalized
return all([text.startswith('"'), text.endswith('"')])
# sqlparse treats string literals as identifiers
if type(tok) is S.Identifier and is_string_literal(tok):
return m.Field(tok.normalized, literal=True)
elif type(tok) is S.Identifier:
return m.Field(tok.normalized)
elif tok.ttype is T.Comparison:
return m.Op(tok.normalized)
elif tok.ttype in [T.Literal, T.String, T.Number, T.Number.Integer, T.Number.Float]:
return m.Field(tok.normalized, literal=True)
return None
示例2: get_parameters
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Literal [as 别名]
def get_parameters(self):
"""Return a list of parameters."""
parenthesis = self.tokens[-1]
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier), t=T.Literal):
return [token, ]
return []
示例3: group_comparison
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Literal [as 别名]
def group_comparison(tlist):
def _parts_valid(token):
return (token.ttype in (T.String.Symbol, T.String.Single,
T.Name, T.Number, T.Number.Float,
T.Number.Integer, T.Literal,
T.Literal.Number.Integer, T.Name.Placeholder)
or isinstance(token, (sql.Identifier, sql.Parenthesis))
or (token.ttype is T.Keyword
and token.value.upper() in ['NULL', ]))
_group_left_right(tlist, T.Operator.Comparison, None, sql.Comparison,
check_left=_parts_valid, check_right=_parts_valid)
示例4: get_parameters
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Literal [as 别名]
def get_parameters(self):
"""Return a list of parameters."""
parenthesis = self.tokens[-1]
for t in parenthesis.tokens:
if isinstance(t, IdentifierList):
return t.get_identifiers()
elif isinstance(t, Identifier) or \
isinstance(t, Function) or \
t.ttype in T.Literal:
return [t,]
return []
示例5: is_string_literal
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Literal [as 别名]
def is_string_literal(token):
"""
リテラル判定(文字列)
"""
return token.ttype in T.Literal.String
示例6: is_number_literal
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Literal [as 别名]
def is_number_literal(token):
"""
リテラル判定(数値)
"""
return token.ttype in T.Literal.Number