Beispiel #1
0
 def test_select_with_field_alias(self):
     query = "SELECT tb.fa1 AS field1 FROM tbl1 tb"
     result = reverse_sql(query)
     self.assertEqual(result, [{
         'field_name': 'fa1',
         'field_alias': 'field1',
         'table_name': 'tbl1'
     }])
Beispiel #2
0
 def test_select_all(self):
     query = "SELECT * FROM tbl1"
     result = reverse_sql(query)
     self.assertEqual(result, [{
         'field_name': '*',
         'field_alias': '',
         'table_name': 'tbl1'
     }])
Beispiel #3
0
 def test_select_fields_joining_other_table(self):
     query = """
             SELECT tb1.fl1, tb2.fl2 AS field2 FROM tbl1 tb1
             INNER JOIN tbl2 tb2 ON tb1.pk = tb2.fk
             """
     result = reverse_sql(query)
     self.assertEqual(result, [{
         'field_name': 'fl1',
         'field_alias': '',
         'table_name': 'tbl1'
     }, {
         'field_name': 'fl2',
         'field_alias': 'field2',
         'table_name': 'tbl2'
     }])
Beispiel #4
0
 def test_select_from_subselect(self):
     query = """
             SELECT f1 FROM
                (SELECT colA as f1 FROM tableB)
             """
     result = reverse_sql(query)
     self.assertEqual(result, [{
         'field_name': 'colA',
         'field_alias': 'f1',
         'table_name': 'tableB'
     }, {
         'field_name': 'f1',
         'field_alias': '',
         'table_name': 'tableB'
     }])
Beispiel #5
0
 def test_select_with_multiple_joins(self):
     query = """
             SELECT tb1.fl1, tb2.fl2 AS field2, tb3.field3 FROM tbl1 tb1
             INNER JOIN tbl2 tb2 ON tb1.pk = tb2.fk
             LEFT JOIN tbl3 tb3 ON tb1.pk = tb3.fk
             """
     result = reverse_sql(query)
     self.assertEqual(result, [{
         'field_name': 'fl1',
         'field_alias': '',
         'table_name': 'tbl1'
     }, {
         'field_name': 'fl2',
         'field_alias': 'field2',
         'table_name': 'tbl2'
     }, {
         'field_name': 'field3',
         'field_alias': '',
         'table_name': 'tbl3'
     }])