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


Python sql.Comparison方法代码示例

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


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

示例1: sql_literal_to_model

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [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 
开发者ID:pglass,项目名称:sqlitis,代码行数:25,代码来源:convert.py

示例2: build_comparison

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

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

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

示例5: _validate_comparison

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def _validate_comparison(cls, tokens):
        base_error_string = "Invalid comparison clause"
        if len(tokens) != 3:
            raise MlflowException("{}. Expected 3 tokens found {}".format(base_error_string,
                                                                          len(tokens)),
                                  error_code=INVALID_PARAMETER_VALUE)
        if not isinstance(tokens[0], Identifier):
            raise MlflowException("{}. Expected 'Identifier' found '{}'".format(base_error_string,
                                                                                str(tokens[0])),
                                  error_code=INVALID_PARAMETER_VALUE)
        if not isinstance(tokens[1], Token) and tokens[1].ttype != TokenType.Operator.Comparison:
            raise MlflowException("{}. Expected comparison found '{}'".format(base_error_string,
                                                                              str(tokens[1])),
                                  error_code=INVALID_PARAMETER_VALUE)
        if not isinstance(tokens[2], Token) and \
                (tokens[2].ttype not in cls.STRING_VALUE_TYPES.union(cls.NUMERIC_VALUE_TYPES) or
                 isinstance(tokens[2], Identifier)):
            raise MlflowException("{}. Expected value token found '{}'".format(base_error_string,
                                                                               str(tokens[2])),
                                  error_code=INVALID_PARAMETER_VALUE) 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:search_utils.py

示例6: group_comparison

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

示例7: test_comparison_exclude

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def test_comparison_exclude(self):
        # make sure operators are not handled too lazy
        p = sqlparse.parse('(=)')[0]
        self.assert_(isinstance(p.tokens[0], sql.Parenthesis))
        self.assert_(not isinstance(p.tokens[0].tokens[1], sql.Comparison))
        p = sqlparse.parse('(a=1)')[0]
        self.assert_(isinstance(p.tokens[0].tokens[1], sql.Comparison))
        p = sqlparse.parse('(a>=1)')[0]
        self.assert_(isinstance(p.tokens[0].tokens[1], sql.Comparison)) 
开发者ID:sriniiyer,项目名称:codenn,代码行数:11,代码来源:test_grouping.py

示例8: test_comparison_with_keywords

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def test_comparison_with_keywords():  # issue90
    # in fact these are assignments, but for now we don't distinguish them
    p = sqlparse.parse('foo = NULL')[0]
    assert len(p.tokens) == 1
    assert isinstance(p.tokens[0], sql.Comparison)
    assert len(p.tokens[0].tokens) == 5
    assert p.tokens[0].left.value == 'foo'
    assert p.tokens[0].right.value == 'NULL'
    # make sure it's case-insensitive
    p = sqlparse.parse('foo = null')[0]
    assert len(p.tokens) == 1
    assert isinstance(p.tokens[0], sql.Comparison) 
开发者ID:sriniiyer,项目名称:codenn,代码行数:14,代码来源:test_grouping.py

示例9: test_comparison_with_floats

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def test_comparison_with_floats():  # issue145
    p = sqlparse.parse('foo = 25.5')[0]
    assert len(p.tokens) == 1
    assert isinstance(p.tokens[0], sql.Comparison)
    assert len(p.tokens[0].tokens) == 5
    assert p.tokens[0].left.value == 'foo'
    assert p.tokens[0].right.value == '25.5' 
开发者ID:sriniiyer,项目名称:codenn,代码行数:9,代码来源:test_grouping.py

示例10: test_comparison_with_strings

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def test_comparison_with_strings():  # issue148
    p = sqlparse.parse('foo = \'bar\'')[0]
    assert len(p.tokens) == 1
    assert isinstance(p.tokens[0], sql.Comparison)
    assert p.tokens[0].right.value == '\'bar\''
    assert p.tokens[0].right.ttype == T.String.Single 
开发者ID:sriniiyer,项目名称:codenn,代码行数:8,代码来源:test_grouping.py

示例11: is_comparison

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def is_comparison(token):
    """
        比較演算判定
    """
    return isinstance(token, sql.Comparison) 
开发者ID:future-architect,项目名称:uroboroSQL-formatter,代码行数:7,代码来源:tokenutils.py

示例12: _invalid_statement_token

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def _invalid_statement_token(cls, token):
        if isinstance(token, Comparison):
            return False
        elif token.is_whitespace:
            return False
        elif token.match(ttype=TokenType.Keyword, values=["AND"]):
            return False
        else:
            return True 
开发者ID:mlflow,项目名称:mlflow,代码行数:11,代码来源:search_utils.py

示例13: _process_statement

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def _process_statement(cls, statement):
        # check validity
        invalids = list(filter(cls._invalid_statement_token, statement.tokens))
        if len(invalids) > 0:
            invalid_clauses = ", ".join("'%s'" % token for token in invalids)
            raise MlflowException("Invalid clause(s) in filter string: %s" % invalid_clauses,
                                  error_code=INVALID_PARAMETER_VALUE)
        return [cls._get_comparison(si) for si in statement.tokens if isinstance(si, Comparison)] 
开发者ID:mlflow,项目名称:mlflow,代码行数:10,代码来源:search_utils.py

示例14: _parse_filter_for_model_registry

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def _parse_filter_for_model_registry(cls, filter_string, valid_search_keys):
        if not filter_string or filter_string == "":
            return []
        expected = "Expected search filter with single comparison operator. e.g. name='myModelName'"
        try:
            parsed = sqlparse.parse(filter_string)
        except Exception:
            raise MlflowException("Error while parsing filter '%s'. %s" % (filter_string, expected),
                                  error_code=INVALID_PARAMETER_VALUE)
        if len(parsed) == 0 or not isinstance(parsed[0], Statement):
            raise MlflowException("Invalid filter '%s'. Could not be parsed. %s" %
                                  (filter_string, expected), error_code=INVALID_PARAMETER_VALUE)
        elif len(parsed) > 1:
            raise MlflowException("Search filter '%s' contains multiple expressions. "
                                  "%s " % (filter_string, expected),
                                  error_code=INVALID_PARAMETER_VALUE)
        statement = parsed[0]
        invalids = list(filter(cls._invalid_statement_token, statement.tokens))
        if len(invalids) > 0:
            invalid_clauses = ", ".join("'%s'" % token for token in invalids)
            raise MlflowException("Invalid clause(s) in filter string: %s. "
                                  "%s" % (invalid_clauses, expected),
                                  error_code=INVALID_PARAMETER_VALUE)
        return [cls._get_comparison_for_model_registry(
            si,
            valid_search_keys)
            for si in statement.tokens if isinstance(si, Comparison)] 
开发者ID:mlflow,项目名称:mlflow,代码行数:29,代码来源:search_utils.py

示例15: tokens2sql

# 需要导入模块: from sqlparse import sql [as 别名]
# 或者: from sqlparse.sql import Comparison [as 别名]
def tokens2sql(token: Token,
                   query: 'query_module.BaseQuery'
                   ) -> Iterator[all_token_types]:
        from .functions import SQLFunc
        if isinstance(token, Identifier):
            # Bug fix for sql parse
            if isinstance(token[0], Parenthesis):
                try:
                    int(token[0][1].value)
                except ValueError:
                    raise
                else:
                    yield SQLConstIdentifier(token, query)
            elif isinstance(token[0], Function):
                yield SQLFunc.token2sql(token, query)
            else:
                yield SQLIdentifier(token, query)
        elif isinstance(token, Function):
            yield SQLFunc.token2sql(token, query)
        elif isinstance(token, Comparison):
            yield SQLComparison(token, query)
        elif isinstance(token, IdentifierList):
            for tok in token.get_identifiers():
                yield from SQLToken.tokens2sql(tok, query)
        elif isinstance(token, Parenthesis):
            yield SQLPlaceholder(token, query)
        else:
            raise SQLDecodeError(f'Unsupported: {token.value}') 
开发者ID:nesdis,项目名称:djongo,代码行数:30,代码来源:sql_tokens.py


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