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


Python sql.Parenthesis方法代码示例

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


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

示例1: get_cte_from_token

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def get_cte_from_token(tok, pos0):
    cte_name = tok.get_real_name()
    if not cte_name:
        return None

    # Find the start position of the opening parens enclosing the cte body
    idx, parens = tok.token_next_by(Parenthesis)
    if not parens:
        return None

    start_pos = pos0 + token_start_pos(tok.tokens, idx)
    cte_len = len(str(parens))  # includes parens
    stop_pos = start_pos + cte_len

    column_names = extract_column_names(parens)

    return TableExpression(cte_name, column_names, start_pos, stop_pos) 
开发者ID:dbcli,项目名称:pgcli,代码行数:19,代码来源:ctes.py

示例2: build_comparison

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def build_comparison(token):
    assert type(token) is S.Comparison

    m = M.Comparison()
    for tok in remove_whitespace(token.tokens):
        LOG.debug("  %s %s", tok, type(tok))
        if type(tok) is S.Parenthesis:
            subtokens = remove_whitespace(tok.tokens)
            subquery = tokens_to_sqla(subtokens[1:-1])
            if not m.left:
                m.left = subquery
            else:
                m.right = subquery
        else:
            m = sql_literal_to_model(tok, m)
            if not m:
                raise Exception("[BUG] Failed to convert %s to model" % tok)

    return m 
开发者ID:pglass,项目名称:sqlitis,代码行数:21,代码来源:convert.py

示例3: _get_primary_key

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [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

示例4: group_comparison

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [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

示例5: group_operator

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def group_operator(tlist):
    ttypes = T_NUMERICAL + T_STRING + T_NAME
    sqlcls = (sql.SquareBrackets, sql.Parenthesis, sql.Function,
              sql.Identifier, sql.Operation)

    def match(token):
        return imt(token, t=(T.Operator, T.Wildcard))

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

    def post(tlist, pidx, tidx, nidx):
        tlist[tidx].ttype = T.Operator
        return pidx, nidx

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

示例6: group_functions

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [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: parse

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def parse(self):
        tok = self.statement.next()
        sql = SQLToken.token2sql(tok, self.query)
        right_table = self.right_table = sql.table

        tok = self.statement.next()
        if not tok.match(tokens.Keyword, 'ON'):
            raise SQLDecodeError

        tok = self.statement.next()
        if isinstance(tok, Parenthesis):
            tok = tok[1]

        sql = SQLToken.token2sql(tok, self.query)
        if right_table == sql.right_table:
            self.left_table = sql.left_table
            self.left_column = sql.left_column
            self.right_column = sql.right_column
        else:
            self.left_table = sql.right_table
            self.left_column = sql.right_column
            self.right_column = sql.left_column 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:converters.py

示例8: group_parenthesis

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def group_parenthesis(tlist):
    _group_matching(tlist, sql.Parenthesis) 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:4,代码来源:grouping.py

示例9: group_aliased

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [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

示例10: group_comparison

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def group_comparison(tlist):

    def _parts_valid(token):
        return (token.ttype in (T.String.Symbol, T.String.Single,
                                T.Name, T.Number, T.Number.Float,
                                T.Number.Integer, T.Literal,
                                T.Literal.Number.Integer, T.Name.Placeholder)
                or isinstance(token, (sql.Identifier, sql.Parenthesis))
                or (token.ttype is T.Keyword
                    and token.value.upper() in ['NULL', ]))
    _group_left_right(tlist, T.Operator.Comparison, None, sql.Comparison,
                      check_left=_parts_valid, check_right=_parts_valid) 
开发者ID:sriniiyer,项目名称:codenn,代码行数:14,代码来源:grouping.py

示例11: group_functions

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [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

示例12: test_issue9

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def test_issue9(self):
        # make sure where doesn't consume parenthesis
        p = sqlparse.parse('(where 1)')[0]
        self.assert_(isinstance(p, sql.Statement))
        self.assertEqual(len(p.tokens), 1)
        self.assert_(isinstance(p.tokens[0], sql.Parenthesis))
        prt = p.tokens[0]
        self.assertEqual(len(prt.tokens), 3)
        self.assertEqual(prt.tokens[0].ttype, T.Punctuation)
        self.assertEqual(prt.tokens[-1].ttype, T.Punctuation) 
开发者ID:sriniiyer,项目名称:codenn,代码行数:12,代码来源:test_regressions.py

示例13: test_parenthesis

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def test_parenthesis(self):
        s = 'select (select (x3) x2) and (y2) bar'
        parsed = sqlparse.parse(s)[0]
        self.ndiffAssertEqual(s, str(parsed))
        self.assertEqual(len(parsed.tokens), 7)
        self.assert_(isinstance(parsed.tokens[2], sql.Parenthesis))
        self.assert_(isinstance(parsed.tokens[-1], sql.Identifier))
        self.assertEqual(len(parsed.tokens[2].tokens), 5)
        self.assert_(isinstance(parsed.tokens[2].tokens[3], sql.Identifier))
        self.assert_(isinstance(parsed.tokens[2].tokens[3].tokens[0], sql.Parenthesis))
        self.assertEqual(len(parsed.tokens[2].tokens[3].tokens), 3) 
开发者ID:sriniiyer,项目名称:codenn,代码行数:13,代码来源:test_grouping.py

示例14: test_function_not_in

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def test_function_not_in(self):  # issue183
        p = sqlparse.parse('in(1, 2)')[0]
        self.assertEqual(len(p.tokens), 2)
        self.assertEqual(p.tokens[0].ttype, T.Keyword)
        self.assert_(isinstance(p.tokens[1], sql.Parenthesis)) 
开发者ID:sriniiyer,项目名称:codenn,代码行数:7,代码来源:test_grouping.py

示例15: test_comparison_with_parenthesis

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Parenthesis [as 别名]
def test_comparison_with_parenthesis():  # issue23
    p = sqlparse.parse('(3 + 4) = 7')[0]
    assert len(p.tokens) == 1
    assert isinstance(p.tokens[0], sql.Comparison)
    comp = p.tokens[0]
    assert isinstance(comp.left, sql.Parenthesis)
    assert comp.right.ttype is T.Number.Integer 
开发者ID:sriniiyer,项目名称:codenn,代码行数:9,代码来源:test_grouping.py


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