general bind param escape unit tests added as a result of #8053. The final application of an escaped param name was moved out of compiler and into DefaultExecutionContext in related issue #8056. However in #8113 we made this conditional to suit usage recipes
(self)
| 4109 | ) |
| 4110 | |
| 4111 | def test_bind_param_escaping(self): |
| 4112 | """general bind param escape unit tests added as a result of |
| 4113 | #8053. |
| 4114 | |
| 4115 | The final application of an escaped param name |
| 4116 | was moved out of compiler and into DefaultExecutionContext in |
| 4117 | related issue #8056. |
| 4118 | |
| 4119 | However in #8113 we made this conditional to suit usage recipes |
| 4120 | posted in the FAQ. |
| 4121 | |
| 4122 | |
| 4123 | """ |
| 4124 | |
| 4125 | SomeEnum = pep435_enum("SomeEnum") |
| 4126 | one = SomeEnum("one", 1) |
| 4127 | SomeEnum("two", 2) |
| 4128 | |
| 4129 | t = Table( |
| 4130 | "t", |
| 4131 | MetaData(), |
| 4132 | Column("_id", Integer, primary_key=True), |
| 4133 | Column("_data", Enum(SomeEnum)), |
| 4134 | ) |
| 4135 | |
| 4136 | class MyCompiler(compiler.SQLCompiler): |
| 4137 | def bindparam_string(self, name, **kw): |
| 4138 | kw["escaped_from"] = name |
| 4139 | return super().bindparam_string('"%s"' % name, **kw) |
| 4140 | |
| 4141 | dialect = default.DefaultDialect() |
| 4142 | dialect.statement_compiler = MyCompiler |
| 4143 | |
| 4144 | self.assert_compile( |
| 4145 | t.insert(), |
| 4146 | 'INSERT INTO t (_id, _data) VALUES (:"_id", :"_data")', |
| 4147 | dialect=dialect, |
| 4148 | ) |
| 4149 | |
| 4150 | compiled = t.insert().compile( |
| 4151 | dialect=dialect, compile_kwargs=dict(compile_keys=("_id", "_data")) |
| 4152 | ) |
| 4153 | |
| 4154 | # not escaped |
| 4155 | params = compiled.construct_params( |
| 4156 | {"_id": 1, "_data": one}, escape_names=False |
| 4157 | ) |
| 4158 | eq_(params, {"_id": 1, "_data": one}) |
| 4159 | |
| 4160 | # escaped by default |
| 4161 | params = compiled.construct_params({"_id": 1, "_data": one}) |
| 4162 | eq_(params, {'"_id"': 1, '"_data"': one}) |
| 4163 | |
| 4164 | # escaped here as well |
| 4165 | eq_(compiled.params, {'"_data"': None, '"_id"': None}) |
| 4166 | |
| 4167 | # bind processors aren't part of this |
| 4168 | eq_(compiled._bind_processors, {"_data": mock.ANY}) |
nothing calls this directly
no test coverage detected