Exemplo n.º 1
0
def test_count_multitenant():
    p = Parser('SELECT COUNT(*) FROM "t1"')
    assert p.with_schemas("b",
                          "c") == 'SELECT COUNT(*) FROM ' \
                                  '(SELECT id, \'b\' AS __schema FROM "b"."t1" ' \
                                  'UNION ALL ' \
                                  'SELECT id, \'c\' AS __schema FROM "c"."t1") as __count'
Exemplo n.º 2
0
def test_select_with_order_multitenant():
    p = Parser('SELECT * FROM "t1" ORDER BY "f1"')
    assert p.with_schemas("b",
                          "c") == 'SELECT * FROM ' \
                                  '(SELECT *, \'b\' AS __schema FROM "b"."t1" ' \
                                  'UNION ALL ' \
                                  'SELECT *, \'c\' AS __schema FROM "c"."t1") as __query ORDER BY f1'
Exemplo n.º 3
0
def test_select_multitenant():
    p = Parser('SELECT * FROM "t1"')
    assert p.with_schemas(
        "b", "c"
    ) == 'SELECT * FROM (SELECT *, \'b\' AS __schema FROM "b"."t1" UNION ALL SELECT *, \'c\' AS __schema FROM "c"."t1") as __query'
Exemplo n.º 4
0
def test_add_schema1():
    sql = 'SELECT "f1" AS "f1" FROM "t1"'
    p = Parser(sql)
    assert p.set_schema(
        "bolivia"
    ) == 'SELECT "f1" AS "f1", \'bolivia\' AS __schema FROM "bolivia"."t1"'
Exemplo n.º 5
0
def test_where2():
    p = Parser('SELECT "f1" FROM t1 WHERE f1=%s')
    p.parse()
    assert p.where == "WHERE f1=%s"
Exemplo n.º 6
0
def test_split(sql):
    p = Parser(sql)
    assert p.join(p.split(sql)) == sql
Exemplo n.º 7
0
def test_where1():
    p = Parser('SELECT "f1" FROM t1 WHERE f1=1 AND f2=2')
    p.parse()
    assert p.where == "WHERE f1=1 AND f2=2"
Exemplo n.º 8
0
def test_order(sql):
    p = Parser(sql)
    p.parse()
    assert p.parts['from'] == ' FROM t1'
Exemplo n.º 9
0
def test_star():
    p = Parser('SELECT * FROM "s1"."t1" ORDER BY "t1"."f1"')
    assert p.tables == ['"t1"']
Exemplo n.º 10
0
def test_simple():
    p = Parser('SELECT id FROM "s1"."t1"')
    assert p.tables == ['"t1"']
Exemplo n.º 11
0
def test_single_table(sql):
    p = Parser(sql)
    # assert p.unknown == []
    # assert p.fields == ["f1"]
    assert p.tables == ['"t1"']