MySQL Error Codes

I know that MySQL errors are broken down into types of clients and servers. Has anyone noticed any additional structure in the numbering?

I like applications that hide errors from the user and try to repair and continue execution, so I'm trying to switch from printing a line, for example, "Doh! Connection failed". to a special database exception class and one handler to catch all database connection errors that do not fall into the function that threw them or returned them. I believe that I can try to rebuild there and resign if it fails. I thought that I could try using a different catch block for various types of errors, such as connection failures, memory errors, prepared procedure errors, etc. When I tried to find out what the connection errors were for, it seems that there are several clusters that can be connected, however, I'm not sure if some of them are connection errors or not! For example: Error 2048: (CR_INVALID_CONN_HANDLE) Invalid connection handle. (When will this happen?!?)

Some errors listed at briandunning.com/error-codes/?source=MySQL have SQLSTATE code. what it is?

I hope I can check the range or ranges using existing codes. Has anyone else tried to do this? is there a PEAR package? How about a good book?

If they don’t follow the logical pattern, would I rather not collapse my own custom codes? Is there a better approach that I don't see? This is my first time with exceptions, so I could be wrong about that. Thanks!

+4
source share
1 answer

Some of these errors have SQLSTATE code. what it is?

In the MySQL manual:

const char *mysql_sqlstate(MYSQL *mysql)
Returns a null-terminated string containing the SQLSTATE error code for the last SQL statement executed. The error code consists of five characters. "00000" means "no error." Values ​​specified in ANSI SQL and ODBC

This page and its subpages should tell you everything you need to know:
http://dev.mysql.com/doc/refman/5.0/en/error-handling.html

And here is the list of IBM SQLSTATE errors that goes into the structure behind the 5-character error code: http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc /sqls520.htm

Quote:

The following table is a short link for interpreting class code values.

  SQLSTATE 
 Class_Code_Value Outcome
  00 Success 
  01 Success with warning 
  02 No data found 
  >= 03 Error or warning 
0
source

All Articles