Exemplo n.º 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%'"
Exemplo n.º 2
0
 def test_invalid(self, value):
     with pytest.raises(TypeError):
         substitute_parameters("SELECT %s", value)
Exemplo n.º 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%'"
Exemplo n.º 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%'"
Exemplo n.º 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