Showing entries 1 to 3
Displaying posts with tag: mysql_errno (reset)
Improve your Stored Procedure Error Handling with GET DIAGNOSTICS

In a previous post, I discussed debugging stored procedures with RESIGNAL, which is of great value when troubleshooting errors raised by your stored procedures, functions, triggers, and events as of MySQL/MariaDB 5.5.

However, as of MySQL 5.6 and MariaDB 10.0, there is GET DIAGNOSTICS, which can be used to get the exact error details as well.

RESIGNAL just outputs the error, as it comes from the server, for instance:

ERROR 1146 (42S02): Table 'db1.t1' doesn't exist

read more

Improve your Stored Procedure Error Handling with GET DIAGNOSTICS

In a previous post, I discussed debugging stored procedures with RESIGNAL, which is of great value when troubleshooting errors raised by your stored procedures, functions, triggers, and events as of MySQL/MariaDB 5.5.

However, as of MySQL 5.6 and MariaDB 10.0, there is GET DIAGNOSTICS, which can be used to get the exact error details as well.

RESIGNAL just outputs the error, as it comes from the server, for instance:

ERROR 1146 (42S02): Table 'db1.t1' doesn't exist

You may not want the error just written to the console, or perhaps you want to at least control how it is written.

It’s common to see exit handler code in the following form:

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
SELECT ...;
END;

Where the SELECT outputs something not very useful in many cases.

With GET DIAGNOSTICS, you can get all of the …

[Read more]
Error handling for MySQL applications

When connecting to MySQL, or executing a query, proper error handling is required. Many take this very seriously, and do a construct like mysql_connect() or die() or the equivalent with mysql_query(). For web apps this generally makes error codes end up on the user page, you can easily see this by doing a Google search for some of the common error texts. Slightly improved apps are nicer to the user and log the error separately.

But both approaches fail, fundamentally, as they don't take into account that not all errors are the same and, most importantly, many error are not fatal but require other forms of action. So let's look at that, look at what causes the errors so you truly understand that it's not fatal stuff, and how you can handle them.

When you get a "not successful" response back from a MySQL API function, you first need find out what the error is with mysql_errno() (and …

[Read more]
Showing entries 1 to 3