Ejemplo n.º 1
0
def test_create_table():
    stmt = sqlparse.parse(
        'create table foo (x integer not null, y text, primary key (x, y),)'
    )[0]
    assert str(
        remove_trailing_commas(stmt)
    ) == 'create table foo (x integer not null, y text, primary key (x, y))'
Ejemplo n.º 2
0
def test_nested_func():
    stmt = sqlparse.parse('SELECT foo(bar(x, y, z,),)')[0]
    assert str(remove_trailing_commas(stmt)) == 'SELECT foo(bar(x, y, z))'
Ejemplo n.º 3
0
def test_cte():
    s = 'WITH x AS (SELECT foo FROM bar), y AS (SELECT baz FROM quux), SELECT garply FROM waldo'
    stmt = sqlparse.parse(s)[0]
    assert str(remove_trailing_commas(stmt)) == replace_right(s, ',', '', 1)
Ejemplo n.º 4
0
def test_multiple_select():
    stmt = sqlparse.parse(
        'SELECT 0 AS a, b, c, FROM tab1 UNION ALL SELECT 1 AS a, b, c, FROM tab2'
    )[0]
    assert str(remove_trailing_commas(stmt)) == \
     'SELECT 0 AS a, b, c FROM tab1 UNION ALL SELECT 1 AS a, b, c FROM tab2'
Ejemplo n.º 5
0
def test_only_illegal_commas_removed(s):
    stmt = sqlparse.parse(s)[0]
    assert str(remove_trailing_commas(stmt)) == s
Ejemplo n.º 6
0
def test_select():
    stmt = sqlparse.parse('select x, y, z, from tab')[0]
    assert str(remove_trailing_commas(stmt)) == 'select x, y, z from tab'