當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。