當前位置: 首頁>>代碼示例>>Python>>正文


Python sql.Function方法代碼示例

本文整理匯總了Python中sqlparse.sql.Function方法的典型用法代碼示例。如果您正苦於以下問題:Python sql.Function方法的具體用法?Python sql.Function怎麽用?Python sql.Function使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlparse.sql的用法示例。


在下文中一共展示了sql.Function方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _extract_table_identifiers

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def _extract_table_identifiers(token_stream):
    for item in token_stream:
        if isinstance(item, IdentifierList):
            for ident in item.get_identifiers():
                try:
                    alias = ident.get_alias()
                    schema_name = ident.get_parent_name()
                    real_name = ident.get_real_name()
                except AttributeError:
                    continue
                if real_name:
                    yield Reference(schema_name, real_name,
                                    alias, _identifier_is_function(ident))
        elif isinstance(item, Identifier):
            yield Reference(item.get_parent_name(), item.get_real_name(),
                            item.get_alias(), _identifier_is_function(item))
        elif isinstance(item, Function):
            yield Reference(item.get_parent_name(), item.get_real_name(),
                            item.get_alias(), _identifier_is_function(item)) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:21,代碼來源:ParseUtils.py

示例2: group_period

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [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) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:25,代碼來源:grouping.py

示例3: group_comparison

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def group_comparison(tlist):
    sqlcls = (sql.Parenthesis, sql.Function, sql.Identifier,
              sql.Operation)
    ttypes = T_NUMERICAL + T_STRING + T_NAME

    def match(token):
        return token.ttype == T.Operator.Comparison

    def valid(token):
        if imt(token, t=ttypes, i=sqlcls):
            return True
        elif token and token.is_keyword and token.normalized == 'NULL':
            return True
        else:
            return False

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

    valid_prev = valid_next = valid
    _group(tlist, sql.Comparison, match,
           valid_prev, valid_next, post, extend=False) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:24,代碼來源:grouping.py

示例4: group_arrays

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [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) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:20,代碼來源:grouping.py

示例5: group_identifier_list

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [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

示例6: group_functions

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def group_functions(tlist):
    has_create = False
    has_table = False
    for tmp_token in tlist.tokens:
        if tmp_token.value == 'CREATE':
            has_create = True
        if tmp_token.value == 'TABLE':
            has_table = True
    if has_create and has_table:
        return

    tidx, token = tlist.token_next_by(t=T.Name)
    while token:
        nidx, next_ = tlist.token_next(tidx)
        if isinstance(next_, sql.Parenthesis):
            tlist.group_tokens(sql.Function, tidx, nidx)
        tidx, token = tlist.token_next_by(t=T.Name, idx=tidx) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:19,代碼來源:grouping.py

示例7: group_aliased

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def group_aliased(tlist):
    clss = (sql.Identifier, sql.Function, sql.Case)
    [group_aliased(sgroup) for sgroup in tlist.get_sublists()
     if not isinstance(sgroup, clss)]
    idx = 0
    token = tlist.token_next_by_instance(idx, clss)
    while token:
        next_ = tlist.token_next(tlist.token_index(token))
        if next_ is not None and isinstance(next_, clss):
            if not next_.value.upper().startswith('VARCHAR'):
                grp = tlist.tokens_between(token, next_)[1:]
                token.tokens.extend(grp)
                for t in grp:
                    tlist.tokens.remove(t)
        idx = tlist.token_index(token) + 1
        token = tlist.token_next_by_instance(idx, clss) 
開發者ID:sriniiyer,項目名稱:codenn,代碼行數:18,代碼來源:grouping.py

示例8: group_aliased

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def group_aliased(tlist):
    clss = (sql.Identifier, sql.Function, sql.Case)
    [group_aliased(sgroup) for sgroup in tlist.get_sublists()
     if not isinstance(sgroup, clss)]
    idx = 0
    token = tlist.token_next_by_instance(idx, clss)
    while token:
        next_ = tlist.token_next(tlist.token_index(token))
        if next_ is not None and isinstance(next_, clss):
            # for jython str.upper()
            # if not next_.value.upper().startswith('VARCHAR'):
            text = next_.value
            if sys.version_info[0] < 3 and isinstance(text, str):
                text = text.decode('utf-8').upper().encode('utf-8')
            if not text.startswith('VARCHAR'):
                grp = tlist.tokens_between(token, next_)[1:]
                token.tokens.extend(grp)
                for t in grp:
                    tlist.tokens.remove(t)
        idx = tlist.token_index(token) + 1
        token = tlist.token_next_by_instance(idx, clss) 
開發者ID:future-architect,項目名稱:uroboroSQL-formatter,代碼行數:23,代碼來源:grouping.py

示例9: _identifier_is_function

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def _identifier_is_function(identifier):
    return any(isinstance(t, Function) for t in identifier.tokens) 
開發者ID:dbcli,項目名稱:pgcli,代碼行數:4,代碼來源:tables.py

示例10: extract_table_identifiers

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def extract_table_identifiers(token_stream):
    """yields tuples of (schema_name, table_name, table_alias)"""

    for item in token_stream:
        if isinstance(item, IdentifierList):
            for identifier in item.get_identifiers():
                # Sometimes Keywords (such as FROM ) are classified as
                # identifiers which don't have the get_real_name() method.
                try:
                    schema_name = identifier.get_parent_name()
                    real_name = identifier.get_real_name()
                except AttributeError:
                    continue
                if real_name:
                    yield (schema_name, real_name, identifier.get_alias())
        elif isinstance(item, Identifier):
            real_name = item.get_real_name()
            schema_name = item.get_parent_name()

            if real_name:
                yield (schema_name, real_name, item.get_alias())
            else:
                name = item.get_name()
                yield (None, name, item.get_alias() or name)
        elif isinstance(item, Function):
            yield (None, item.get_name(), item.get_name())


# extract_tables is inspired from examples in the sqlparse lib. 
開發者ID:dbcli,項目名稱:litecli,代碼行數:31,代碼來源:parseutils.py

示例11: group_aliased

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def group_aliased(tlist):
    I_ALIAS = (sql.Parenthesis, sql.Function, sql.Case, sql.Identifier,
               sql.Operation)

    tidx, token = tlist.token_next_by(i=I_ALIAS, t=T.Number)
    while token:
        nidx, next_ = tlist.token_next(tidx)
        if isinstance(next_, sql.Identifier):
            tlist.group_tokens(sql.Identifier, tidx, nidx, extend=True)
        tidx, token = tlist.token_next_by(i=I_ALIAS, t=T.Number, idx=tidx) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:12,代碼來源:grouping.py

示例12: _process_identifierlist

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def _process_identifierlist(self, tlist):
        identifiers = list(tlist.get_identifiers())
        first = next(identifiers.pop(0).flatten())
        num_offset = 1 if self.char == '\t' else self._get_offset(first)
        if not tlist.within(sql.Function):
            with offset(self, num_offset):
                position = 0
                for token in identifiers:
                    # Add 1 for the "," separator
                    position += len(token.value) + 1
                    if position > (self.wrap_after - self.offset):
                        adjust = 0
                        if self.comma_first:
                            adjust = -2
                            _, comma = tlist.token_prev(
                                tlist.token_index(token))
                            if comma is None:
                                continue
                            token = comma
                        tlist.insert_before(token, self.nl(offset=adjust))
                        if self.comma_first:
                            _, ws = tlist.token_next(
                                tlist.token_index(token), skip_ws=False)
                            if (ws is not None
                                    and ws.ttype is not T.Text.Whitespace):
                                tlist.insert_after(
                                    token, sql.Token(T.Whitespace, ' '))
                        position = 0
        self._process_default(tlist) 
開發者ID:mtxr,項目名稱:SublimeText-SQLTools,代碼行數:31,代碼來源:reindent.py

示例13: _process_identifierlist

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def _process_identifierlist(self, tlist):
        identifiers = list(tlist.get_identifiers())
        if len(identifiers) > 1 and not tlist.within(sql.Function):
            first = list(identifiers[0].flatten())[0]
            if self.char == '\t':
                # when using tabs we don't count the actual word length
                # in spaces.
                num_offset = 1
            else:
                num_offset = self._get_offset(first) - len(first.value)
            self.offset += num_offset
            for token in identifiers[1:]:
                tlist.insert_before(token, self.nl())
            self.offset -= num_offset
        self._process_default(tlist) 
開發者ID:sriniiyer,項目名稱:codenn,代碼行數:17,代碼來源:filters.py

示例14: compact

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def compact(stream):
    """Function that return a compacted version of the stream"""
    pipe = Pipeline()

    pipe.append(StripComments())
    pipe.append(StripWhitespace)

    return pipe(stream) 
開發者ID:sriniiyer,項目名稱:codenn,代碼行數:10,代碼來源:filters.py

示例15: group_functions

# 需要導入模塊: from sqlparse import sql [as 別名]
# 或者: from sqlparse.sql import Function [as 別名]
def group_functions(tlist):
    [group_functions(sgroup) for sgroup in tlist.get_sublists()
     if not isinstance(sgroup, sql.Function)]
    idx = 0
    token = tlist.token_next_by_type(idx, T.Name)
    while token:
        next_ = tlist.token_next(token)
        if not isinstance(next_, sql.Parenthesis):
            idx = tlist.token_index(token) + 1
        else:
            func = tlist.group_tokens(sql.Function,
                                      tlist.tokens_between(token, next_))
            idx = tlist.token_index(func) + 1
        token = tlist.token_next_by_type(idx, T.Name) 
開發者ID:sriniiyer,項目名稱:codenn,代碼行數:16,代碼來源:grouping.py


注:本文中的sqlparse.sql.Function方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。