本文整理匯總了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