Example #1
0
    def test_2_statements_2nd_current(self):
        suggestions = suggest_type('select * from a; select * from ',
                                   'select * from a; select * from ')
        self.assertSetEqual(set(suggestions),
                            set([
                                FromClauseItem(schema=None),
                                Schema(),
                            ]))

        suggestions = suggest_type('select * from a; select  from b',
                                   'select * from a; select ')
        self.assertSetEqual(
            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 ')
        self.assertSetEqual(set(suggestions),
                            set([
                                FromClauseItem(schema=None),
                                Schema(),
                            ]))
Example #2
0
 def test_sub_select_table_name_completion(self, expression):
     suggestions = suggest_type(expression, expression)
     self.assertSetEqual(set(suggestions),
                         set([
                             FromClauseItem(schema=None),
                             Schema(),
                         ]))
Example #3
0
 def test_table_comma_suggests_tables_and_schemas(self):
     suggestions = suggest_type('SELECT a, b FROM tbl1, ',
                                'SELECT a, b FROM tbl1, ')
     self.assertSetEqual(set(suggestions),
                         set([
                             FromClauseItem(schema=None),
                             Schema(),
                         ]))
Example #4
0
 def test_sub_select_table_name_completion_with_outer_table(
         self, expression):
     suggestions = suggest_type(expression, expression)
     tbls = tuple([(None, 'foo', None, False)])
     self.assertSetEqual(
         set(suggestions),
         set([
             FromClauseItem(schema=None, table_refs=tbls),
             Schema(),
         ]))
Example #5
0
 def test_suggest_qualified_tables_views_functions_and_joins(
         self, expression):
     suggestions = suggest_type(expression, expression)
     tbls = tuple([(None, 'foo', None, False)])
     self.assertSetEqual(
         set(suggestions),
         set([
             FromClauseItem(schema='sch', table_refs=tbls),
             Join(tbls, 'sch'),
         ]))
Example #6
0
 def test_suggest_after_join_with_one_table(self, expression):
     suggestions = suggest_type(expression, expression)
     tables = ((None, 'foo', None, False), )
     self.assertSetEqual(
         set(suggestions),
         set([
             FromClauseItem(schema=None, table_refs=tables),
             Join(((None, 'foo', None, False), ), None),
             Schema(),
         ]))
Example #7
0
 def test_suggest_after_join_with_two_tables(self, expression):
     suggestions = suggest_type(expression, expression)
     tables = tuple([(None, 'foo', None, False),
                     (None, 'bar', None, False)])
     self.assertSetEqual(
         set(suggestions),
         set([
             FromClauseItem(schema=None, table_refs=tables),
             Join(tables, None),
             Schema(),
         ]))
Example #8
0
 def test_left_join_with_comma(self):
     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)])
     self.assertSetEqual(
         set(suggestions),
         set([
             FromClauseItem(schema=None, table_refs=tbls),
             Schema(),
         ]))
Example #9
0
    def test_2_statements_1st_current(self):
        suggestions = suggest_type('select * from ; select * from b',
                                   'select * from ')
        self.assertSetEqual(set(suggestions),
                            set([
                                FromClauseItem(schema=None),
                                Schema(),
                            ]))

        suggestions = suggest_type('select  from a; select * from b',
                                   'select ')
        self.assertSetEqual(set(suggestions),
                            cols_etc('a', last_keyword='SELECT'))
Example #10
0
 def test_join_suggests_tables_and_schemas(self):
     tbl_aliases = (
         '',
         'foo',
     )
     join_types = (
         '',
         'INNER',
         'LEFT',
         'RIGHT OUTER',
     )
     for table in tbl_aliases:
         for join in join_types:
             text = 'SELECT * FROM abc {0} {1} JOIN '.format(table, join)
             suggestions = suggest_type(text, text)
             tbls = tuple([(None, 'abc', table or None, False)])
             self.assertSetEqual(
                 set(suggestions),
                 set([
                     FromClauseItem(schema=None, table_refs=tbls),
                     Schema(),
                     Join(tbls, None),
                 ]))
Example #11
0
 def test_ignore_leading_double_quotes(self, sql):
     suggestions = suggest_type(sql, sql)
     self.assertTrue(FromClauseItem(schema=None) in set(suggestions))
Example #12
0
 def test_suggest_qualified_tables_views_and_functions(self, expression):
     suggestions = suggest_type(expression, expression)
     self.assertSetEqual(set(suggestions),
                         set([FromClauseItem(schema='sch')]))
Example #13
0
 def test_suggest_tables_views_schemas_and_functions(self, expression):
     suggestions = suggest_type(expression, expression)
     self.assertSetEqual(set(suggestions),
                         set([FromClauseItem(schema=None),
                              Schema()]))