Beispiel #1
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 #2
0
def insert_1():
    return Data(
        sql='insert into table_name values ("value!", value2,3)',
        tokens=[
            Token(Token.INSERT, 'insert into'),
            Token(Token.IDENTIFIER, 'table_name'),
            Token(Token.VALUES, 'values'),
            Token(Token.PARENTHESIS_OPEN, '('),
            Token(Token.STR, '"value!"'),
            Token(Token.COMMA, ','),
            Token(Token.IDENTIFIER, 'value2'),
            Token(Token.COMMA, ','),
            Token(Token.NUMBER, '3'),
            Token(Token.PARENTHESIS_CLOSE, ')'),
        ],
        statements=[
            Insert('insert into',
                   table='table_name',
                   values=Values(
                       'values',
                       [[Str('"value!"'),
                         Identifier('value2'),
                         Number('3')]]))
        ],
        style=[
            'INSERT INTO', '    table_name', 'VALUES',
            '    ("value!", value2, 3)'
        ])
Beispiel #3
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 #4
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 #5
0
def func_1():
    return Data(sql='CONCAT(last_name,", ",first_name)',
                tokens=[
                    Token(Token.FUNC, 'CONCAT'),
                    Token(Token.PARENTHESIS_OPEN, '('),
                    Token(Token.IDENTIFIER, 'last_name'),
                    Token(Token.COMMA, ','),
                    Token(Token.STR, '", "'),
                    Token(Token.COMMA, ','),
                    Token(Token.IDENTIFIER, 'first_name'),
                    Token(Token.PARENTHESIS_CLOSE, ')'),
                ],
                statements=[
                    Func('CONCAT',
                         args=[
                             Identifier('last_name'),
                             Str('", "'),
                             Identifier('first_name')
                         ]),
                ],
                style=['CONCAT(last_name, ", ", first_name)'])
Beispiel #6
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")'])