本文整理汇总了Python中sqlparse.tokens.String方法的典型用法代码示例。如果您正苦于以下问题:Python tokens.String方法的具体用法?Python tokens.String怎么用?Python tokens.String使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlparse.tokens
的用法示例。
在下文中一共展示了tokens.String方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sql_literal_to_model
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import String [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: group_period
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import String [as 别名]
def group_period(tlist):
def match(token):
return token.match(T.Punctuation, '.')
def valid_prev(token):
sqlcls = sql.SquareBrackets, sql.Identifier
ttypes = T.Name, T.String.Symbol
return imt(token, i=sqlcls, t=ttypes)
def valid_next(token):
# issue261, allow invalid next token
return True
def post(tlist, pidx, tidx, nidx):
# next_ validation is being performed here. issue261
sqlcls = sql.SquareBrackets, sql.Function
ttypes = T.Name, T.String.Symbol, T.Wildcard
next_ = tlist[nidx] if nidx is not None else None
valid_next = imt(next_, i=sqlcls, t=ttypes)
return (pidx, nidx) if valid_next else (pidx, tidx)
_group(tlist, sql.Identifier, match, valid_prev, valid_next, post)
示例3: group_arrays
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import String [as 别名]
def group_arrays(tlist):
sqlcls = sql.SquareBrackets, sql.Identifier, sql.Function
ttypes = T.Name, T.String.Symbol
def match(token):
return isinstance(token, sql.SquareBrackets)
def valid_prev(token):
return imt(token, i=sqlcls, t=ttypes)
def valid_next(token):
return True
def post(tlist, pidx, tidx, nidx):
return pidx, tidx
_group(tlist, sql.Identifier, match,
valid_prev, valid_next, post, extend=True, recurse=False)
示例4: group_identifier
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import String [as 别名]
def group_identifier(tlist):
ttypes = (T.String.Symbol, T.Name)
tidx, token = tlist.token_next_by(t=ttypes)
while token:
tlist.group_tokens(sql.Identifier, tidx, tidx)
tidx, token = tlist.token_next_by(t=ttypes, idx=tidx)
示例5: _get_table
# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import String [as 别名]
def _get_table(tlist: TokenList) -> Optional[Table]:
"""
Return the table if valid, i.e., conforms to the [[catalog.]schema.]table
construct.
:param tlist: The SQL tokens
:returns: The table if the name conforms
"""
# Strip the alias if present.
idx = len(tlist.tokens)
if tlist.has_alias():
ws_idx, _ = tlist.token_next_by(t=Whitespace)
if ws_idx != -1:
idx = ws_idx
tokens = tlist.tokens[:idx]
if (
len(tokens) in (1, 3, 5)
and all(imt(token, t=[Name, String]) for token in tokens[::2])
and all(imt(token, m=(Punctuation, ".")) for token in tokens[1::2])
):
return Table(*[remove_quotes(token.value) for token in tokens[::-2]])
return None