Ejemplo n.º 1
0
def test_incomplete_join_clause():
    sql = '''select a.x, b.y
             from abc a join bcd b
             on a.id = '''
    tables = extract_tables(sql)
    assert tables == ((None, 'abc', 'a', False),
                      (None, 'bcd', 'b', False))
Ejemplo n.º 2
0
def test_incomplete_join_clause():
    sql = '''select a.x, b.y
             from abc a join bcd b
             on a.id = '''
    tables = extract_tables(sql)
    assert tables == ((None, 'abc', 'a', False),
                      (None, 'bcd', 'b', False))
Ejemplo n.º 3
0
def test_simple_insert_single_table():
    tables = extract_tables('insert into abc (id, name) values (1, "def")')

    # sqlparse mistakenly assigns an alias to the table
    # AND mistakenly identifies the field list as
    # assert tables == ((None, 'abc', 'abc', False),)

    assert tables == ((None, 'abc', 'abc', False),)
Ejemplo n.º 4
0
def test_simple_insert_single_table():
    tables = extract_tables('insert into abc (id, name) values (1, "def")')

    # sqlparse mistakenly assigns an alias to the table
    # AND mistakenly identifies the field list as
    # assert tables == ((None, 'abc', 'abc', False),)

    assert tables == ((None, 'abc', 'abc', False),)
Ejemplo n.º 5
0
def test_multiple_joins():
    sql = '''select * from t1
            inner join t2 ON
              t1.id = t2.t1_id
            inner join t3 ON
              t2.id = t3.'''
    tables = extract_tables(sql)
    assert tables == (
        (None, 't1', None, False),
        (None, 't2', None, False),
        (None, 't3', None, False))
Ejemplo n.º 6
0
def test_multiple_joins():
    sql = '''select * from t1
            inner join t2 ON
              t1.id = t2.t1_id
            inner join t3 ON
              t2.id = t3.'''
    tables = extract_tables(sql)
    assert tables == (
        (None, 't1', None, False),
        (None, 't2', None, False),
        (None, 't3', None, False))
Ejemplo n.º 7
0
def test_simple_update_table_no_schema():
    tables = extract_tables('update abc set id = 1')
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 8
0
def test_select_with_hanging_comma_single_table():
    tables = extract_tables('select a, from abc')
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 9
0
def test_select_with_hanging_comma_multiple_tables():
    tables = extract_tables('select a, from abc, def')
    assert set(tables) == set([(None, 'abc', None, False),
                               (None, 'def', None, False)])
Ejemplo n.º 10
0
def test_simple_select_with_cols_multiple_qualified_tables():
    tables = extract_tables('select a,b from abc.def, def.ghi')
    assert set(tables) == set([('abc', 'def', None, False),
                               ('def', 'ghi', None, False)])
Ejemplo n.º 11
0
def test_simple_select_with_cols_single_table_schema_qualified():
    tables = extract_tables('select a,b from abc.def')
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 12
0
def test_select_with_hanging_comma_multiple_tables():
    tables = extract_tables('select a, from abc, def')
    assert set(tables) == set([(None, 'abc', None, False),
                               (None, 'def', None, False)])
Ejemplo n.º 13
0
def test_simple_aliased_function_as_table(arg_list):
    tables = extract_tables('SELECT * FROM foo({0}) bar'.format(arg_list))
    assert tables == ((None, 'foo', 'bar', True),)
Ejemplo n.º 14
0
def test_join_table(join_type):
    sql = 'SELECT * FROM abc a {0} JOIN def d ON a.id = d.num'.format(join_type)
    tables = extract_tables(sql)
    assert set(tables) == set([(None, 'abc', 'a', False),
                               (None, 'def', 'd', False)])
Ejemplo n.º 15
0
def test_join_table_schema_qualified():
    tables = extract_tables('SELECT * FROM abc.def x JOIN ghi.jkl y ON x.id = y.num')
    assert set(tables) == set([('abc', 'def', 'x', False),
                               ('ghi', 'jkl', 'y', False)])
Ejemplo n.º 16
0
def test_simple_update_table_with_schema():
    tables = extract_tables('update abc.def set id = 1')
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 17
0
def test_simple_update_table_no_schema():
    tables = extract_tables('update abc set id = 1')
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 18
0
def test_simple_insert_single_table_schema_qualified():
    tables = extract_tables('insert into abc.def (id, name) values (1, "def")')
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 19
0
def test_join_table(join_type):
    sql = 'SELECT * FROM abc a {0} JOIN def d ON a.id = d.num'.format(join_type)
    tables = extract_tables(sql)
    assert set(tables) == set([(None, 'abc', 'a', False),
                               (None, 'def', 'd', False)])
Ejemplo n.º 20
0
def test_simple_select_single_table():
    tables = extract_tables('select * from abc')
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 21
0
def test_simple_select_with_cols_multiple_qualified_tables():
    tables = extract_tables('select a,b from abc.def, def.ghi')
    assert set(tables) == set([('abc', 'def', None, False),
                               ('def', 'ghi', None, False)])
Ejemplo n.º 22
0
def test_simple_select_multiple_tables():
    tables = extract_tables('select * from abc, def')
    assert set(tables) == set([(None, 'abc', None, False),
                               (None, 'def', None, False)])
Ejemplo n.º 23
0
def test_extract_no_tables(text):
    tables = extract_tables(text)
    assert tables == tuple()
Ejemplo n.º 24
0
def test_select_with_hanging_period_multiple_tables():
    tables = extract_tables('SELECT t1. FROM tabl1 t1, tabl2 t2')
    assert set(tables) == set([(None, 'tabl1', 't1', False),
                               (None, 'tabl2', 't2', False)])
Ejemplo n.º 25
0
def test_complex_table_and_function():
    tables = extract_tables('''SELECT * FROM foo.bar baz
                               JOIN bar.qux(x, y, z) quux''')
    assert set(tables) == set([('foo', 'bar', 'baz', False),
                               ('bar', 'qux', 'quux', True)])
Ejemplo n.º 26
0
def test_join_as_table():
    tables = extract_tables('SELECT * FROM my_table AS m WHERE m.a > 5')
    assert tables == ((None, 'my_table', 'm', False),)
Ejemplo n.º 27
0
def test_simple_select_single_table_schema_qualified(sql):
    tables = extract_tables(sql)
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 28
0
def test_subselect_tables():
    sql = 'SELECT * FROM (SELECT  FROM abc'
    tables = extract_tables(sql)
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 29
0
def test_simple_select_single_table_deouble_quoted_aliased():
    tables = extract_tables('select * from "Abc" a')
    assert tables == ((None, 'Abc', 'a', False),)
Ejemplo n.º 30
0
def test_extract_no_tables(text):
    tables = extract_tables(text)
    assert tables == tuple()
Ejemplo n.º 31
0
def test_simple_select_with_cols_single_table_schema_qualified():
    tables = extract_tables('select a,b from abc.def')
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 32
0
def test_simple_schema_qualified_function_as_table(arg_list):
    tables = extract_tables('SELECT * FROM foo.bar({0})'.format(arg_list))
    assert tables == (('foo', 'bar', None, True),)
Ejemplo n.º 33
0
def test_select_with_hanging_comma_single_table():
    tables = extract_tables('select a, from abc')
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 34
0
def test_simple_aliased_function_as_table(arg_list):
    tables = extract_tables('SELECT * FROM foo({0}) bar'.format(arg_list))
    assert tables == ((None, 'foo', 'bar', True),)
Ejemplo n.º 35
0
def test_select_with_hanging_period_multiple_tables():
    tables = extract_tables('SELECT t1. FROM tabl1 t1, tabl2 t2')
    assert set(tables) == set([(None, 'tabl1', 't1', False),
                               (None, 'tabl2', 't2', False)])
Ejemplo n.º 36
0
def test_simple_table_and_function():
    tables = extract_tables('SELECT * FROM foo JOIN bar()')
    assert set(tables) == set([(None, 'foo', None, False),
                               (None, 'bar', None, True)])
Ejemplo n.º 37
0
def test_simple_insert_single_table_schema_qualified():
    tables = extract_tables('insert into abc.def (id, name) values (1, "def")')
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 38
0
def test_complex_table_and_function():
    tables = extract_tables('''SELECT * FROM foo.bar baz
                               JOIN bar.qux(x, y, z) quux''')
    assert set(tables) == set([('foo', 'bar', 'baz', False),
                               ('bar', 'qux', 'quux', True)])
Ejemplo n.º 39
0
def test_simple_update_table_with_schema():
    tables = extract_tables('update abc.def set id = 1')
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 40
0
def test_empty_string():
    tables = extract_tables('')
    assert tables == ()
Ejemplo n.º 41
0
def test_join_table_schema_qualified():
    tables = extract_tables('SELECT * FROM abc.def x JOIN ghi.jkl y ON x.id = y.num')
    assert set(tables) == set([('abc', 'def', 'x', False),
                               ('ghi', 'jkl', 'y', False)])
Ejemplo n.º 42
0
def test_simple_select_single_table():
    tables = extract_tables('select * from abc')
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 43
0
def test_join_as_table():
    tables = extract_tables('SELECT * FROM my_table AS m WHERE m.a > 5')
    assert tables == ((None, 'my_table', 'm', False),)
Ejemplo n.º 44
0
def test_simple_select_single_table_schema_qualified_quoted_table(sql):
    tables = extract_tables(sql)
    assert tables == (('abc', 'def', '"def"', False),)
Ejemplo n.º 45
0
def test_subselect_tables():
    sql = 'SELECT * FROM (SELECT  FROM abc'
    tables = extract_tables(sql)
    assert tables == ((None, 'abc', None, False),)
Ejemplo n.º 46
0
def test_simple_select_single_table_schema_qualified(sql):
    tables = extract_tables(sql)
    assert tables == (('abc', 'def', None, False),)
Ejemplo n.º 47
0
def test_simple_schema_qualified_function_as_table(arg_list):
    tables = extract_tables('SELECT * FROM foo.bar({0})'.format(arg_list))
    assert tables == (('foo', 'bar', None, True),)
Ejemplo n.º 48
0
def test_simple_select_single_table_double_quoted():
    tables = extract_tables('select * from "Abc"')
    assert tables == ((None, 'Abc', None, False),)
Ejemplo n.º 49
0
def test_simple_table_and_function():
    tables = extract_tables('SELECT * FROM foo JOIN bar()')
    assert set(tables) == set([(None, 'foo', None, False),
                               (None, 'bar', None, True)])
Ejemplo n.º 50
0
def test_simple_select_multiple_tables():
    tables = extract_tables('select * from abc, def')
    assert set(tables) == set([(None, 'abc', None, False),
                               (None, 'def', None, False)])
Ejemplo n.º 51
0
def test_empty_string():
    tables = extract_tables('')
    assert tables == ()
Ejemplo n.º 52
0
def test_simple_select_multiple_tables_double_quoted():
    tables = extract_tables('select * from "Abc", "Def"')
    assert set(tables) == set([(None, 'Abc', None, False),
                               (None, 'Def', None, False)])
Ejemplo n.º 53
0
def test_simple_select_single_table_schema_qualified_quoted_table(sql):
    tables = extract_tables(sql)
    assert tables == (('abc', 'def', '"def"', False),)
Ejemplo n.º 54
0
def test_simple_select_single_table_deouble_quoted_aliased():
    tables = extract_tables('select * from "Abc" a')
    assert tables == ((None, 'Abc', 'a', False),)
Ejemplo n.º 55
0
def test_simple_select_single_table_double_quoted():
    tables = extract_tables('select * from "Abc"')
    assert tables == ((None, 'Abc', None, False),)
Ejemplo n.º 56
0
def test_simple_select_multiple_tables_deouble_quoted_aliased():
    tables = extract_tables('select * from "Abc" a, "Def" d')
    assert set(tables) == set([(None, 'Abc', 'a', False),
                               (None, 'Def', 'd', False)])
Ejemplo n.º 57
0
def test_simple_select_multiple_tables_double_quoted():
    tables = extract_tables('select * from "Abc", "Def"')
    assert set(tables) == set([(None, 'Abc', None, False),
                               (None, 'Def', None, False)])
Ejemplo n.º 58
0
def test_simple_select_multiple_tables_schema_qualified():
    tables = extract_tables('select * from abc.def, ghi.jkl')
    assert set(tables) == set([('abc', 'def', None, False),
                               ('ghi', 'jkl', None, False)])
Ejemplo n.º 59
0
def test_simple_select_multiple_tables_deouble_quoted_aliased():
    tables = extract_tables('select * from "Abc" a, "Def" d')
    assert set(tables) == set([(None, 'Abc', 'a', False),
                               (None, 'Def', 'd', False)])
Ejemplo n.º 60
0
def test_simple_select_multiple_tables_schema_qualified():
    tables = extract_tables('select * from abc.def, ghi.jkl')
    assert set(tables) == set([('abc', 'def', None, False),
                               ('ghi', 'jkl', None, False)])