示例#1
0
 def test_query_sql_specified_cols(self):
     expected_sql = "SELECT id, integer_field FROM basic_table WHERE 1 " \
                    "AND date_field = '2010-01-01';"
     actual_sql = sqlgen.query_sql(self.basic_table,
                                   {'date_field': '2010-01-01'},
                                   ['id', 'integer_field'])
     self.assertEqual(expected_sql, actual_sql)
示例#2
0
 def test_query_sql_multiple_parameters(self):
     expected_sql = "SELECT * FROM basic_table WHERE 1 " \
                    "AND date_field = '2010-01-01' " \
                    "AND text_field = 'foo';"
     actual_sql = sqlgen.query_sql(self.basic_table,
                                   {'date_field': '2010-01-01',
                                    'text_field': 'foo'})
     self.assertEqual(expected_sql, actual_sql)
示例#3
0
def query(c, table, query_data):
    sql = sqlgen.query_sql(table, query_data)
    rows = c.execute(sql).fetchall()
    schema = get_table_schema(c, table)
    row_dicts = [dict(zip(schema, row)) for row in rows]
    return row_dicts
示例#4
0
 def test_query_sql(self):
     expected_sql = "SELECT * FROM basic_table WHERE 1 " \
                    "AND date_field = '2010-01-01';"
     actual_sql = sqlgen.query_sql(self.basic_table,
                                   {'date_field': '2010-01-01'})
     self.assertEqual(expected_sql, actual_sql)