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