开发者

MySQL error code categories

开发者 https://www.devze.com 2023-04-10 01:25 出处:网络
I know that the MySQL errors are split into client and server types. Has anyone discerned any further structure in the numbering?

I know that the MySQL errors are split into client and server types. Has anyone discerned any further structure in the numbering?

I love applications that hide errors from the user and try to recover and continue execution, so am trying to switch from printing a string like "Doh! Connection failed." to a custom class of database exceptions and a single handler to catch all database connection errors that aren't caught within the function that threw them or get rethrown. I figure I can try to recover right there and re-throw if that fails. I thought I might try using a different catch block for dif开发者_开发技巧ferent types of errors like connection failures, memory errors, prepared procedure errors, etc., When I tried to figure out a test for connection errors to start with, there seem to be several clusters that may relate, 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 would this occur?!?)

Some of the errors listed at briandunning.com/error-codes/?source=MySQL have a SQLSTATE code. what are these?

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

If they aren't following a logical pattern would I be better off rolling my own custom codes? Is there a better approach I don't see? This is my first time with exceptions, so I may be going about this all wrong. Thanks!


Some of the errors listed have a SQLSTATE code. what are these?

From the MySQL manual:

const char *mysql_sqlstate(MYSQL *mysql)
Returns a null-terminated string containing the SQLSTATE error code for the most recently executed SQL statement. The error code consists of five characters. '00000' means “no error.” The values are specified by ANSI SQL and ODBC

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

And here's a list of SQLSTATE errors from IBM 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

A quote:

The following table is a quick reference 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

精彩评论

暂无评论...
验证码 换一张
取 消