Exemplo n.º 1
0
def test_2_statements_1st_current():
    suggestions = suggest_type("select * from ; select * from b",
                               "select * from ")
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])

    suggestions = suggest_type("select  from a; select * from b", "select ")
    assert set(suggestions) == cols_etc("a", last_keyword="SELECT")
Exemplo n.º 2
0
def test_suggest_after_join_with_one_table(expression):
    suggestions = suggest_type(expression, expression)
    tables = ((None, "foo", None, False), )
    assert set(suggestions) == set([
        FromClauseItem(schema=None, table_refs=tables),
        Join(((None, "foo", None, False), ), None),
        Schema(),
    ])
Exemplo n.º 3
0
def test_2_statements_2nd_current():
    suggestions = suggest_type("select * from a; select * from ",
                               "select * from a; select * from ")
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])

    suggestions = suggest_type("select * from a; select  from b",
                               "select * from a; select ")
    assert set(suggestions) == set([
        Column(table_refs=((None, "b", None, False), ), qualifiable=True),
        Function(schema=None),
        Keyword("SELECT"),
    ])

    # Should work even if first statement is invalid
    suggestions = suggest_type("select * from; select * from ",
                               "select * from; select * from ")
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])
Exemplo n.º 4
0
def test_suggest_after_join_with_two_tables(expression):
    suggestions = suggest_type(expression, expression)
    tables = tuple([(None, "foo", None, False), (None, "bar", None, False)])
    assert set(suggestions) == set([
        FromClauseItem(schema=None, table_refs=tables),
        Join(tables, None),
        Schema()
    ])
Exemplo n.º 5
0
def test_left_join_with_comma():
    text = "select * from foo f left join bar b,"
    suggestions = suggest_type(text, text)
    # tbls should also include (None, 'bar', 'b', False)
    # but there's a bug with commas
    tbls = tuple([(None, "foo", "f", False)])
    assert set(suggestions) == set(
        [FromClauseItem(schema=None, table_refs=tbls),
         Schema()])
Exemplo n.º 6
0
def test_join_suggests_tables_and_schemas(tbl_alias, join_type):
    text = "SELECT * FROM abc {0} {1} JOIN ".format(tbl_alias, join_type)
    suggestion = suggest_type(text, text)
    tbls = tuple([(None, "abc", tbl_alias or None, False)])
    assert set(suggestion) == set([
        FromClauseItem(schema=None, table_refs=tbls),
        Schema(),
        Join(tbls, None)
    ])
Exemplo n.º 7
0
def test_ignore_leading_double_quotes(sql):
    suggestions = suggest_type(sql, sql)
    assert FromClauseItem(schema=None) in set(suggestions)
Exemplo n.º 8
0
def test_sub_select_table_name_completion_with_outer_table(expression):
    suggestion = suggest_type(expression, expression)
    tbls = tuple([(None, "foo", None, False)])
    assert set(suggestion) == set(
        [FromClauseItem(schema=None, table_refs=tbls),
         Schema()])
Exemplo n.º 9
0
def test_sub_select_table_name_completion(expression):
    suggestion = suggest_type(expression, expression)
    assert set(suggestion) == set([FromClauseItem(schema=None), Schema()])
Exemplo n.º 10
0
def test_table_comma_suggests_tables_and_schemas():
    suggestions = suggest_type("SELECT a, b FROM tbl1, ",
                               "SELECT a, b FROM tbl1, ")
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])
Exemplo n.º 11
0
def test_suggest_qualified_tables_views_functions_and_joins(expression):
    suggestions = suggest_type(expression, expression)
    tbls = tuple([(None, "foo", None, False)])
    assert set(suggestions) == set(
        [FromClauseItem(schema="sch", table_refs=tbls),
         Join(tbls, "sch")])
Exemplo n.º 12
0
def test_suggest_qualified_tables_views_and_functions(expression):
    suggestions = suggest_type(expression, expression)
    assert set(suggestions) == set([FromClauseItem(schema="sch")])
Exemplo n.º 13
0
def test_suggest_tables_views_schemas_and_functions(expression):
    suggestions = suggest_type(expression, expression)
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])