Beispiel #1
0
def where_3():
    return Data(sql='where not x= 1 and x != 3',
                tokens=[
                    Token(Token.WHERE, 'where'),
                    Token(Token.NOT, 'not'),
                    Token(Token.IDENTIFIER, 'x'),
                    Token(Token.COMPARE, '='),
                    Token(Token.NUMBER, '1'),
                    Token(Token.LINK, 'and'),
                    Token(Token.IDENTIFIER, 'x'),
                    Token(Token.COMPARE, '!='),
                    Token(Token.NUMBER, '3'),
                ],
                statements=[
                    Where('where', [
                        Condition([
                            Not('not'),
                            Identifier('x'),
                            Operator('='),
                            Number('1'),
                        ]),
                        Link('and'),
                        Condition([
                            Identifier('x'),
                            Operator('!='),
                            Number('3'),
                        ]),
                    ])
                ],
                style=['WHERE', '    NOT x = 1', '    AND x != 3'])
Beispiel #2
0
def composition_3():
    return Data(
        sql=
        "select p.* from p1 as p left join p2 as r on r.sk = CONCAT(p.x, '-!') where 1 = 1",
        tokens=[
            Token(Token.SELECT, 'select'),
            Token(Token.IDENTIFIER, 'p.*'),
            Token(Token.FROM, 'from'),
            Token(Token.IDENTIFIER, 'p1'),
            Token(Token.AS, 'as'),
            Token(Token.IDENTIFIER, 'p'),
            Token(Token.JOIN, 'left join'),
            Token(Token.IDENTIFIER, 'p2'),
            Token(Token.AS, 'as'),
            Token(Token.IDENTIFIER, 'r'),
            Token(Token.ON, 'on'),
            Token(Token.IDENTIFIER, 'r.sk'),
            Token(Token.COMPARE, '='),
            Token(Token.FUNC, 'CONCAT'),
            Token(Token.PARENTHESIS_OPEN, '('),
            Token(Token.IDENTIFIER, 'p.x'),
            Token(Token.COMMA, ','),
            Token(Token.STR, "'-!'"),
            Token(Token.PARENTHESIS_CLOSE, ')'),
            Token(Token.WHERE, 'where'),
            Token(Token.NUMBER, '1'),
            Token(Token.COMPARE, '='),
            Token(Token.NUMBER, '1')
        ],
        statements=[
            Select('select', [Identifier('p.*')]),
            From('from', [
                Identifier('p1', as_='as', alias='p'),
                Join('left join'),
                Identifier('p2', as_='as', alias='r'),
                On('on',
                   values=[
                       Condition([
                           Identifier('r.sk'),
                           Operator('='),
                           Func('CONCAT',
                                args=[Identifier('p.x'),
                                      Str("'-!'")])
                       ])
                   ])
            ]),
            Where('where',
                  [Condition([Number('1'),
                              Operator('='),
                              Number('1')])])
        ],
        style=[
            'SELECT', '    p.*', 'FROM', '    p1 AS p',
            '    LEFT JOIN p2 AS r ON', "        r.sk = CONCAT(p.x, '-!')",
            'WHERE', '    1 = 1'
        ])
Beispiel #3
0
def from_5():
    return Data(sql='From x t join r As z on t.id1=z.id2 And t.id2=z.id3',
                tokens=[
                    Token(Token.FROM, 'From'),
                    Token(Token.IDENTIFIER, 'x'),
                    Token(Token.IDENTIFIER, 't'),
                    Token(Token.JOIN, 'join'),
                    Token(Token.IDENTIFIER, 'r'),
                    Token(Token.AS, 'As'),
                    Token(Token.IDENTIFIER, 'z'),
                    Token(Token.ON, 'on'),
                    Token(Token.IDENTIFIER, 't.id1'),
                    Token(Token.COMPARE, '='),
                    Token(Token.IDENTIFIER, 'z.id2'),
                    Token(Token.LINK, 'And'),
                    Token(Token.IDENTIFIER, 't.id2'),
                    Token(Token.COMPARE, '='),
                    Token(Token.IDENTIFIER, 'z.id3'),
                ],
                statements=[
                    From('From',
                         values=[
                             Identifier('x', alias='t'),
                             Join('join'),
                             Identifier('r', as_='As', alias='z'),
                             On('on',
                                values=[
                                    Condition([
                                        Identifier('t.id1'),
                                        Operator('='),
                                        Identifier('z.id2')
                                    ]),
                                    Link('And'),
                                    Condition([
                                        Identifier('t.id2'),
                                        Operator('='),
                                        Identifier('z.id3')
                                    ])
                                ])
                         ])
                ],
                style=[
                    'FROM',
                    '    x t',
                    '    JOIN r AS z ON',
                    '        t.id1 = z.id2',
                    '        AND t.id2 = z.id3',
                ])
Beispiel #4
0
def where_10():
    return Data(sql='where x = (select max(*) from k)',
                tokens=[
                    Token(Token.WHERE, 'where'),
                    Token(Token.IDENTIFIER, 'x'),
                    Token(Token.COMPARE, '='),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.SELECT, 'select'),
                    Token(Token.FUNC, 'max'),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.IDENTIFIER, '*'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                    Token(Token.FROM, 'from'),
                    Token(Token.IDENTIFIER, 'k'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                ],
                statements=[
                    Where('where', [
                        Condition([
                            Identifier('x'),
                            Operator('='),
                            SubSelect([
                                Select('select',
                                       [Func('max', args=[Identifier('*')])]),
                                From('from', [Identifier('k')])
                            ])
                        ])
                    ])
                ],
                style=[
                    'WHERE', '    x = (', '        SELECT',
                    '            MAX(*)', '        FROM', '            k)'
                ])
Beispiel #5
0
def where_5():
    return Data(sql='where x in (select * from k)',
                tokens=[
                    Token(Token.WHERE, 'where'),
                    Token(Token.IDENTIFIER, 'x'),
                    Token(Token.IN, 'in'),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.SELECT, 'select'),
                    Token(Token.IDENTIFIER, '*'),
                    Token(Token.FROM, 'from'),
                    Token(Token.IDENTIFIER, 'k'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                ],
                statements=[
                    Where('where', [
                        Condition([
                            Identifier('x'),
                            Operator('in'),
                            SubSelect([
                                Select('select', [Identifier('*')]),
                                From('from', [Identifier('k')])
                            ])
                        ])
                    ])
                ],
                style=[
                    'WHERE', '    x IN (', '        SELECT', '            *',
                    '        FROM', '            k)'
                ])
Beispiel #6
0
def like_1():
    return Data(
        sql="Select * From xs Where x Like 'A%Z'",
        tokens=[
            Token(Token.SELECT, 'Select'),
            Token(Token.IDENTIFIER, '*'),
            Token(Token.FROM, 'From'),
            Token(Token.IDENTIFIER, 'xs'),
            Token(Token.WHERE, 'Where'),
            Token(Token.IDENTIFIER, 'x'),
            Token(Token.COMPARE, 'Like'),
            Token(Token.STR, "'A%Z'"),
        ],
        statements=[
            Select('Select', [Identifier('*')]),
            From('From', [Identifier('xs')]),
            Where(
                'Where',
                [Condition([Identifier('x'),
                            Operator('Like'),
                            Str("'A%Z'")])])
        ],
        style=[
            'SELECT', '    *', 'FROM', '    xs', 'WHERE', "    x LIKE 'A%Z'"
        ])
Beispiel #7
0
def between_1():
    return Data(sql='SELECT * FROM ys WHERE ys.id BETWEEN 91 AND 92',
                tokens=[
                    Token(Token.SELECT, 'SELECT'),
                    Token(Token.IDENTIFIER, '*'),
                    Token(Token.FROM, 'FROM'),
                    Token(Token.IDENTIFIER, 'ys'),
                    Token(Token.WHERE, 'WHERE'),
                    Token(Token.IDENTIFIER, 'ys.id'),
                    Token(Token.BETWEEN, 'BETWEEN'),
                    Token(Token.NUMBER, '91'),
                    Token(Token.LINK, 'AND'),
                    Token(Token.NUMBER, '92'),
                ],
                statements=[
                    Select('SELECT', [Identifier('*')]),
                    From('FROM', [Identifier('ys')]),
                    Where('WHERE', [
                        Condition([
                            Identifier('ys.id'),
                            Between('BETWEEN'),
                            Number('91'),
                            Link('AND'),
                            Number('92')
                        ])
                    ])
                ],
                style=[
                    'SELECT', '    *', 'FROM', '    ys', 'WHERE',
                    '    ys.id BETWEEN 91 AND 92'
                ])
Beispiel #8
0
def where_7():
    return Data(
        sql='where x in (select * from k) Or c = 3',
        tokens=[
            Token(Token.WHERE, 'where'),
            Token(Token.IDENTIFIER, 'x'),
            Token(Token.IN, 'in'),
            Token(Token.PARENTHESIS_OPEN, '('),
            Token(Token.SELECT, 'select'),
            Token(Token.IDENTIFIER, '*'),
            Token(Token.FROM, 'from'),
            Token(Token.IDENTIFIER, 'k'),
            Token(Token.PARENTHESIS_CLOSE, ')'),
            Token(Token.LINK, 'Or'),
            Token(Token.IDENTIFIER, 'c'),
            Token(Token.COMPARE, '='),
            Token(Token.NUMBER, '3'),
        ],
        statements=[
            Where('where', [
                Condition([
                    Identifier('x'),
                    Operator('in'),
                    SubSelect([
                        Select('select', [Identifier('*')]),
                        From('from', [Identifier('k')])
                    ])
                ]),
                Link('Or'),
                Condition([Identifier('c'),
                           Operator('='),
                           Number('3')])
            ])
        ],
        style=[
            'WHERE', '    x IN (', '        SELECT', '            *',
            '        FROM', '            k)', '    OR c = 3'
        ])
Beispiel #9
0
def where_8():
    return Data(
        sql='where x = "abc"',
        tokens=[
            Token(Token.WHERE, 'where'),
            Token(Token.IDENTIFIER, 'x'),
            Token(Token.COMPARE, '='),
            Token(Token.STR, '"abc"')
        ],
        statements=[
            Where('where',
                  [Condition([Identifier('x'),
                              Operator('='),
                              Str('"abc"')])])
        ],
        style=['WHERE', '    x = "abc"'])
Beispiel #10
0
def where_1():
    return Data(
        sql='where x= 1',
        tokens=[
            Token(Token.WHERE, 'where'),
            Token(Token.IDENTIFIER, 'x'),
            Token(Token.COMPARE, '='),
            Token(Token.NUMBER, '1')
        ],
        statements=[
            Where('where',
                  [Condition([Identifier('x'),
                              Operator('='),
                              Number('1')])])
        ],
        style=['WHERE', '    x = 1'])
Beispiel #11
0
def where_11():
    return Data(
        sql='where x is null',
        tokens=[
            Token(Token.WHERE, 'where'),
            Token(Token.IDENTIFIER, 'x'),
            Token(Token.IS, 'is'),
            Token(Token.NULL, 'null'),
        ],
        statements=[
            Where(
                'where',
                [Condition([Identifier('x'),
                            Is('is'), Null('null')])])
        ],
        style=['WHERE', '    x IS NULL'])
Beispiel #12
0
def having_1():
    return Data(
        sql='having col1 !=1',
        tokens=[
            Token(Token.HAVING, 'having'),
            Token(Token.IDENTIFIER, 'col1'),
            Token(Token.COMPARE, '!='),
            Token(Token.NUMBER, '1'),
        ],
        statements=[
            Having(
                'having',
                [Condition([Identifier('col1'),
                            Operator('!='),
                            Number('1')])])
        ],
        style=['HAVING', '    col1 != 1'])
Beispiel #13
0
def where_4():
    return Data(
        sql='where x in (1, "3")',
        tokens=[
            Token(Token.WHERE, 'where'),
            Token(Token.IDENTIFIER, 'x'),
            Token(Token.IN, 'in'),
            Token(Token.PARENTHESIS_OPEN, '('),
            Token(Token.NUMBER, '1'),
            Token(Token.COMMA, ','),
            Token(Token.STR, '"3"'),
            Token(Token.PARENTHESIS_CLOSE, ')'),
        ],
        statements=[
            Where('where', [
                Condition([
                    Identifier('x'),
                    Operator('in'), [Number('1'), Str('"3"')]
                ])
            ])
        ],
        style=['WHERE', '    x IN (', '        1,', '        "3")'])
Beispiel #14
0
def from_9():
    return Data(sql='From x join r on Xyz(r.id) = Abc(x.r)',
                tokens=[
                    Token(Token.FROM, 'From'),
                    Token(Token.IDENTIFIER, 'x'),
                    Token(Token.JOIN, 'join'),
                    Token(Token.IDENTIFIER, 'r'),
                    Token(Token.ON, 'on'),
                    Token(Token.FUNC, 'Xyz'),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.IDENTIFIER, 'r.id'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                    Token(Token.COMPARE, '='),
                    Token(Token.FUNC, 'Abc'),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.IDENTIFIER, 'x.r'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                ],
                statements=[
                    From('From',
                         values=[
                             Identifier('x'),
                             Join('join'),
                             Identifier('r'),
                             On('on',
                                values=[
                                    Condition([
                                        Func('Xyz', args=[Identifier('r.id')]),
                                        Operator('='),
                                        Func('Abc', args=[Identifier('x.r')]),
                                    ])
                                ])
                         ])
                ],
                style=[
                    'FROM', '    x', '    JOIN r ON',
                    '        XYZ(r.id) = ABC(x.r)'
                ])
Beispiel #15
0
def having_2():
    return Data(sql='having not count(1) !=1',
                tokens=[
                    Token(Token.HAVING, 'having'),
                    Token(Token.NOT, 'not'),
                    Token(Token.FUNC, 'count'),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.NUMBER, '1'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                    Token(Token.COMPARE, '!='),
                    Token(Token.NUMBER, '1'),
                ],
                statements=[
                    Having('having', [
                        Condition([
                            Not('not'),
                            Func('count', [Number('1')]),
                            Operator('!='),
                            Number('1')
                        ])
                    ])
                ],
                style=['HAVING', '    NOT COUNT(1) != 1'])