예제 #1
0
 def test_substitute_mapping(self):
     sql = substitute_parameters(
         "SELECT %(id)s, %(name)s FROM t WHERE x LIKE 'A%%'",
         {
             "id": 1,
             "name": "foo"
         },
     )
     assert sql == "SELECT 1, 'foo' FROM t WHERE x LIKE 'A%'"
예제 #2
0
 def test_invalid(self, value):
     with pytest.raises(TypeError):
         substitute_parameters("SELECT %s", value)
예제 #3
0
 def test_substitute_none(self):
     sql = substitute_parameters("SELECT * FROM t WHERE x LIKE 'A%'")
     assert sql == "SELECT * FROM t WHERE x LIKE 'A%'"
예제 #4
0
 def test_substitute_sequence(self):
     sql = substitute_parameters("SELECT %s, %s FROM t WHERE x LIKE 'A%%'",
                                 [1, "foo"])
     assert sql == "SELECT 1, 'foo' FROM t WHERE x LIKE 'A%'"
예제 #5
0
 def _get_sql(self, operation: str, parameters: PARAMETERS) -> str:
     sql = substitute_parameters(operation, parameters)
     if self.normalize:
         sql = normalize_sql(sql)
     return sql