You can, for example, check the warning_count
variable:
MySQL [test]> SELECT CAST(0 AS UNSIGNED INTEGER) AS 'CAST1', @@warning_count; +-------+-----------------+ | CAST1 | @@warning_count | +-------+-----------------+ | 0 | 0 | +-------+-----------------+ 1 row in set (0.01 sec) MySQL [test]> SELECT CAST('Banana' AS UNSIGNED INTEGER) AS 'CAST1', @@warning_count; +-------+-----------------+ | CAST1 | @@warning_count | +-------+-----------------+ | 0 | 1 | +-------+-----------------+ 1 row in set, 1 warning (0.00 sec)
However, there is a caveat: the number of warnings is only reset per statement, not per result line, so if CAST () is executed several times, for example. for each line of the result, the counter will grow with every failed call.
Also the warnings do not seem to get reset on successful queries that do not concern any tables, therefore in the above example the 2nd
SELECT CAST(0 AS UNSIGNED INTEGER) AS 'CAST1', @@warning_count;
still show 1 warning, while, for example,
SELECT CAST(0 AS UNSIGNED INTEGER) AS 'CAST1', @@warning_count FROM mysql.user LIMIT 1;
will correctly reset to 0 ...
source share