pdb
pdb copied to clipboard
[MySQL] Pdb incorrectly escapes queries with backslash
When performing a query to the database (using mysql backend):
Query q = select(all())
.from(table("table"))
.where(eq("id", k("my\id"));
engine.query(q);
pdb incorrectly escapes the query to
SELECT * FROM `table` WHERE `id` = 'my\id' ;
where it should be (notice the double \
)
SELECT * FROM `table` WHERE `id` = 'my\\id' ;
this is independent of the data in the table itself.
This behaviour does not appear in prepared statements because the escaping is delegated to the driver
Just to add some context: this is not a problem with PostgreSQL
I would say that is working as intended. \
in java in an escape character and it will interpret the next character in a different way ("\i"
is not event valid syntax). If you want to have a literal \
in your statement you need to escape the \
on your string. Ex: "my\\id"
It should work in the same way for other database engines, meaning that the same query should work regardless of the engine.
"my\id"
won't work anywhere because it won't even compile