1

If I run the following query:

DELETE FROM `table` where `id` = '123%7D';

Notice the gibberish at the end of the where clause

I get the following error

ERROR 1292 (22007): Truncated incorrect DOUBLE value: '123%7D'

Which is the expected behavior since I'm running a MySQL (5.7.33-log) database on strict mode.

BUT

If I run the same query on a prepared statement:

PREPARE stmt FROM "delete from `table` where `id` = ?;";
SET @id = '1234%7D';
EXECUTE stmt USING @id;

The query runs fine without any error, which in my view is not expected behavior

My question is, how can I make prepared queries throw the same errors that they would throw as if they where not prepared?

Thanks in advance.

My @@sql_mode value is:

ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
5
  • What is the data type of id?
    – mustaccio
    May 26, 2022 at 18:49
  • @mustaccio The ìd column is a int(10) unsigned May 26, 2022 at 21:19
  • Where did the string come from? It looks like a "url-encoded" string. That would turn } into %7D to avoid difficulties when used in a URL string.
    – Rick James
    May 27, 2022 at 18:14
  • @RickJames, yes, it did come from a URL. But for the scope of my question, any form of gibberish in the string reproduces the same results. May 27, 2022 at 18:53
  • Dig back further and find out where the } comes from.
    – Rick James
    May 27, 2022 at 20:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.