Skip to content

Not detecting multiple where clauses #238

@acscott

Description

@acscott

While testing this, sqlparse doesn't seem to detect the second where clause in the sql statement below.

#!/usr/bin/env python2.7

import sqlparse
from sqlparse.tokens import Keyword, DML

sql = ("select * from names inner join addresses on nameid=nameid_fk where"
     " a like test% and 1 in (select * from testtables where a='d');")
stmts = sqlparse.parse(sql)

for item in stmts[0].tokens:

    print "result:",item
    if item.is_group():
        print "the result above is_group"

    if isinstance(item, sqlparse.sql.Where):
        print "Where clause found:",item
        for item2 in item.tokens:
            if not isinstance(item2, sqlparse.sql.Token):
                print "     item2", item2, "tokens", len(item2.tokens)
            if isinstance(item2, sqlparse.sql.Statement):
                print "     another statement", item2
            if isinstance(item2, sqlparse.sql.Where):
                print "     another where clause", item2


    if isinstance(item, sqlparse.sql.Comparison):
        print "result above is a comparison"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions