当前位置: 首页>>代码示例>>Python>>正文


Python tokens.Keyword方法代码示例

本文整理汇总了Python中sqlparse.tokens.Keyword方法的典型用法代码示例。如果您正苦于以下问题:Python tokens.Keyword方法的具体用法?Python tokens.Keyword怎么用?Python tokens.Keyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlparse.tokens的用法示例。


在下文中一共展示了tokens.Keyword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_primary_key

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def _get_primary_key(self, def_tokens):
        EXPECT_PRIMARY = 0
        EXPECT_KEY = 1
        EXPECT_COLUMN = 2
        state = EXPECT_PRIMARY
        for token in def_tokens:
            if state == EXPECT_PRIMARY and token.match(T.Keyword, 'PRIMARY'):
                state = EXPECT_KEY
            elif state == EXPECT_KEY and token.value.upper() == 'KEY':
                state = EXPECT_COLUMN
            elif state == EXPECT_COLUMN and isinstance(token, sql.Parenthesis):
                return [
                    self._clean_identifier_quotes(t.value)
                    for t in token.tokens[1:-1]
                    if t.ttype in (T.Name, T.Literal.String.Symbol)
                ]
        return [] 
开发者ID:Yelp,项目名称:schematizer,代码行数:19,代码来源:mysql_handler.py

示例2: group_identifier_list

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def group_identifier_list(tlist):
    m_role = T.Keyword, ('null', 'role')
    sqlcls = (sql.Function, sql.Case, sql.Identifier, sql.Comparison,
              sql.IdentifierList, sql.Operation)
    ttypes = (T_NUMERICAL + T_STRING + T_NAME +
              (T.Keyword, T.Comment, T.Wildcard))

    def match(token):
        return token.match(T.Punctuation, ',')

    def valid(token):
        return imt(token, i=sqlcls, m=m_role, t=ttypes)

    def post(tlist, pidx, tidx, nidx):
        return pidx, nidx

    valid_prev = valid_next = valid
    _group(tlist, sql.IdentifierList, match,
           valid_prev, valid_next, post, extend=True) 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:21,代码来源:grouping.py

示例3: _process_case

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def _process_case(self, tlist):
        offset_ = len('case ') + len('when ')
        cases = tlist.get_cases(skip_ws=True)
        # align the end as well
        end_token = tlist.token_next_by(m=(T.Keyword, 'END'))[1]
        cases.append((None, [end_token]))

        condition_width = [len(' '.join(map(text_type, cond))) if cond else 0
                           for cond, _ in cases]
        max_cond_width = max(condition_width)

        for i, (cond, value) in enumerate(cases):
            # cond is None when 'else or end'
            stmt = cond[0] if cond else value[0]

            if i > 0:
                tlist.insert_before(stmt, self.nl(
                    offset_ - len(text_type(stmt))))
            if cond:
                ws = sql.Token(T.Whitespace, self.char * (
                    max_cond_width - condition_width[i]))
                tlist.insert_after(cond[-1], ws) 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:24,代码来源:aligned_indent.py

示例4: group_where

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def group_where(tlist):
    [group_where(sgroup) for sgroup in tlist.get_sublists()
     if not isinstance(sgroup, sql.Where)]
    idx = 0
    token = tlist.token_next_match(idx, T.Keyword, 'WHERE')
    stopwords = ('ORDER', 'GROUP', 'LIMIT', 'UNION', 'EXCEPT', 'HAVING')
    while token:
        tidx = tlist.token_index(token)
        end = tlist.token_next_match(tidx + 1, T.Keyword, stopwords)
        if end is None:
            end = tlist._groupable_tokens[-1]
        else:
            end = tlist.tokens[tlist.token_index(end) - 1]
        group = tlist.group_tokens(sql.Where,
                                   tlist.tokens_between(token, end),
                                   ignore_ws=True)
        idx = tlist.token_index(group)
        token = tlist.token_next_match(idx, T.Keyword, 'WHERE') 
开发者ID:sriniiyer,项目名称:codenn,代码行数:20,代码来源:grouping.py

示例5: _get_first_name

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def _get_first_name(self, idx=None, reverse=False, keywords=False):
        """Returns the name of the first token with a name"""

        if idx and not isinstance(idx, int):
            idx = self.token_index(idx) + 1

        tokens = self.tokens[idx:] if idx else self.tokens
        tokens = reversed(tokens) if reverse else tokens
        types = [T.Name, T.Wildcard, T.String.Symbol]

        if keywords:
            types.append(T.Keyword)

        for tok in tokens:
            if tok.ttype in types:
                return self._remove_quotes(tok.value)
            elif isinstance(tok, Identifier) or isinstance(tok, Function):
                return tok.get_name()
        return None 
开发者ID:sriniiyer,项目名称:codenn,代码行数:21,代码来源:sql.py

示例6: get_type

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def get_type(self):
        """Returns the type of a statement.

        The returned value is a string holding an upper-cased reprint of
        the first DML or DDL keyword. If the first token in this group
        isn't a DML or DDL keyword "UNKNOWN" is returned.
        """
        first_token = self.token_first()
        if first_token is None:
            # An "empty" statement that either has not tokens at all
            # or only whitespace tokens.
            return 'UNKNOWN'

        elif first_token.ttype in (T.Keyword.DML, T.Keyword.DDL):
            return first_token.normalized

        return 'UNKNOWN' 
开发者ID:sriniiyer,项目名称:codenn,代码行数:19,代码来源:sql.py

示例7: get_type

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def get_type(self):
        """Returns the type of a statement.

        The returned value is a string holding an upper-cased reprint of
        the first DML or DDL keyword. If the first token in this group
        isn't a DML or DDL keyword "UNKNOWN" is returned.

        Whitespaces and comments at the beginning of the statement
        are ignored.
        """
        first_token = self.token_first(ignore_comments=True)
        if first_token is None:
            # An "empty" statement that either has not tokens at all
            # or only whitespace tokens.
            return 'UNKNOWN'

        elif first_token.ttype in (T.Keyword.DML, T.Keyword.DDL):
            return first_token.normalized

        return 'UNKNOWN' 
开发者ID:future-architect,项目名称:uroboroSQL-formatter,代码行数:22,代码来源:sql.py

示例8: is_dmlddl_parenthesis

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def is_dmlddl_parenthesis(token):
    """
        DMLかDDLの括弧判定
    """
    if not is_parenthesis(token):
        return False


    open_punc = token.token_next_match(0, T.Punctuation, '(')
    first = token_next_enable(token, open_punc)
    if first and first.ttype in (T.Keyword.DML, T.Keyword.DDL):
        return True

    if is_with(first):
        return True

    if is_parenthesis(first):
        return is_dmlddl_parenthesis(first)

    return False 
开发者ID:future-architect,项目名称:uroboroSQL-formatter,代码行数:22,代码来源:tokenutils.py

示例9: extract_column_names

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def extract_column_names(parsed):
    # Find the first DML token to check if it's a SELECT or INSERT/UPDATE/DELETE
    idx, tok = parsed.token_next_by(t=DML)
    tok_val = tok and tok.value.lower()

    if tok_val in ("insert", "update", "delete"):
        # Jump ahead to the RETURNING clause where the list of column names is
        idx, tok = parsed.token_next_by(idx, (Keyword, "returning"))
    elif not tok_val == "select":
        # Must be invalid CTE
        return ()

    # The next token should be either a column name, or a list of column names
    idx, tok = parsed.token_next(idx, skip_ws=True, skip_cm=True)
    return tuple(t.get_name() for t in _identifiers(tok)) 
开发者ID:dbcli,项目名称:pgcli,代码行数:17,代码来源:ctes.py

示例10: is_create_table_sql

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def is_create_table_sql(self, parsed_sql):
        if parsed_sql.get_type() != 'CREATE':
            return False

        token = parsed_sql.token_next_by_type(1, T.Keyword)
        if token.normalized not in ('TABLE', 'TEMPORARY'):
            return False

        if token.normalized == 'TABLE':
            return True

        index = parsed_sql.token_index(token)
        token = parsed_sql.token_next_by_type(index + 1, T.Keyword)
        return token.normalized == 'TABLE' 
开发者ID:Yelp,项目名称:schematizer,代码行数:16,代码来源:mysql_handler.py

示例11: group_order

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def group_order(tlist):
    """Group together Identifier and Asc/Desc token"""
    tidx, token = tlist.token_next_by(t=T.Keyword.Order)
    while token:
        pidx, prev_ = tlist.token_prev(tidx)
        if imt(prev_, i=sql.Identifier, t=T.Number):
            tlist.group_tokens(sql.Identifier, pidx, tidx)
            tidx = pidx
        tidx, token = tlist.token_next_by(t=T.Keyword.Order, idx=tidx) 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:11,代码来源:grouping.py

示例12: __init__

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def __init__(self, ttype, value):
        value = text_type(value)
        self.value = value
        self.ttype = ttype
        self.parent = None
        self.is_group = False
        self.is_keyword = ttype in T.Keyword
        self.is_whitespace = self.ttype in T.Whitespace
        self.normalized = value.upper() if self.is_keyword else value 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:11,代码来源:sql.py

示例13: get_alias

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def get_alias(self):
        """Returns the alias for this identifier or ``None``."""

        # "name AS alias"
        kw_idx, kw = self.token_next_by(m=(T.Keyword, 'AS'))
        if kw is not None:
            return self._get_first_name(kw_idx + 1, keywords=True)

        # "name alias" or "complicated column expression alias"
        _, ws = self.token_next_by(t=T.Whitespace)
        if len(self.tokens) > 2 and ws is not None:
            return self._get_first_name(reverse=True) 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:14,代码来源:sql.py

示例14: get_type

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def get_type(self):
        """Returns the type of a statement.

        The returned value is a string holding an upper-cased reprint of
        the first DML or DDL keyword. If the first token in this group
        isn't a DML or DDL keyword "UNKNOWN" is returned.

        Whitespaces and comments at the beginning of the statement
        are ignored.
        """
        first_token = self.token_first(skip_cm=True)
        if first_token is None:
            # An "empty" statement that either has not tokens at all
            # or only whitespace tokens.
            return 'UNKNOWN'

        elif first_token.ttype in (T.Keyword.DML, T.Keyword.DDL):
            return first_token.normalized

        elif first_token.ttype == T.Keyword.CTE:
            # The WITH keyword should be followed by either an Identifier or
            # an IdentifierList containing the CTE definitions;  the actual
            # DML keyword (e.g. SELECT, INSERT) will follow next.
            fidx = self.token_index(first_token)
            tidx, token = self.token_next(fidx, skip_ws=True)
            if isinstance(token, (Identifier, IdentifierList)):
                _, dml_keyword = self.token_next(tidx, skip_ws=True)

                if dml_keyword.ttype == T.Keyword.DML:
                    return dml_keyword.normalized

        # Hmm, probably invalid syntax, so return unknown.
        return 'UNKNOWN' 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:35,代码来源:sql.py

示例15: get_ordering

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Keyword [as 别名]
def get_ordering(self):
        """Returns the ordering or ``None`` as uppercase string."""
        _, ordering = self.token_next_by(t=T.Keyword.Order)
        return ordering.normalized if ordering else None 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:6,代码来源:sql.py


注:本文中的sqlparse.tokens.Keyword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。