A new feature just got merged into mysql-trunk, the GET DIAGNOSTICS statement.
Many people have been asking for this for a very long time, so it is worth mentioning it.
mysql> select version(); +--------------+ | version() | +--------------+ | 5.6.4-m6-log | +--------------+ 1 row in set (0.00 sec) mysql> drop table test.no_such_table; ERROR 1051 (42S02): Unknown table 'test.no_such_table'
Why is it important ? In short, it allows to programmatically (i.e., in SQL) inspect what happened in a SQL exception.
mysql> get diagnostics condition 1 @p1 = MESSAGE_TEXT, @p2 = RETURNED_SQLSTATE, @p3 = MYSQL_ERRNO, @p4 = SCHEMA_NAME, @p5 = TABLE_NAME; Query OK, 0 rows[Read more...]

