pdo_sqlstate.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Wez Furlong <wez@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "php.h"
  20. #include "php_ini.h"
  21. #include "ext/standard/info.h"
  22. #include "php_pdo.h"
  23. #include "php_pdo_driver.h"
  24. struct pdo_sqlstate_info {
  25. const char state[5];
  26. const char *desc;
  27. };
  28. static HashTable err_hash;
  29. static const struct pdo_sqlstate_info err_initializer[] = {
  30. { "00000", "No error" },
  31. { "01000", "Warning" },
  32. { "01001", "Cursor operation conflict" },
  33. { "01002", "Disconnect error" },
  34. { "01003", "NULL value eliminated in set function" },
  35. { "01004", "String data, right truncated" },
  36. { "01006", "Privilege not revoked" },
  37. { "01007", "Privilege not granted" },
  38. { "01008", "Implicit zero bit padding" },
  39. { "0100C", "Dynamic result sets returned" },
  40. { "01P01", "Deprecated feature" },
  41. { "01S00", "Invalid connection string attribute" },
  42. { "01S01", "Error in row" },
  43. { "01S02", "Option value changed" },
  44. { "01S06", "Attempt to fetch before the result set returned the first rowset" },
  45. { "01S07", "Fractional truncation" },
  46. { "01S08", "Error saving File DSN" },
  47. { "01S09", "Invalid keyword" },
  48. { "02000", "No data" },
  49. { "02001", "No additional dynamic result sets returned" },
  50. { "03000", "Sql statement not yet complete" },
  51. { "07002", "COUNT field incorrect" },
  52. { "07005", "Prepared statement not a cursor-specification" },
  53. { "07006", "Restricted data type attribute violation" },
  54. { "07009", "Invalid descriptor index" },
  55. { "07S01", "Invalid use of default parameter" },
  56. { "08000", "Connection exception" },
  57. { "08001", "Client unable to establish connection" },
  58. { "08002", "Connection name in use" },
  59. { "08003", "Connection does not exist" },
  60. { "08004", "Server rejected the connection" },
  61. { "08006", "Connection failure" },
  62. { "08007", "Connection failure during transaction" },
  63. { "08S01", "Communication link failure" },
  64. { "09000", "Triggered action exception" },
  65. { "0A000", "Feature not supported" },
  66. { "0B000", "Invalid transaction initiation" },
  67. { "0F000", "Locator exception" },
  68. { "0F001", "Invalid locator specification" },
  69. { "0L000", "Invalid grantor" },
  70. { "0LP01", "Invalid grant operation" },
  71. { "0P000", "Invalid role specification" },
  72. { "21000", "Cardinality violation" },
  73. { "21S01", "Insert value list does not match column list" },
  74. { "21S02", "Degree of derived table does not match column list" },
  75. { "22000", "Data exception" },
  76. { "22001", "String data, right truncated" },
  77. { "22002", "Indicator variable required but not supplied" },
  78. { "22003", "Numeric value out of range" },
  79. { "22004", "Null value not allowed" },
  80. { "22005", "Error in assignment" },
  81. { "22007", "Invalid datetime format" },
  82. { "22008", "Datetime field overflow" },
  83. { "22009", "Invalid time zone displacement value" },
  84. { "2200B", "Escape character conflict" },
  85. { "2200C", "Invalid use of escape character" },
  86. { "2200D", "Invalid escape octet" },
  87. { "2200F", "Zero length character string" },
  88. { "2200G", "Most specific type mismatch" },
  89. { "22010", "Invalid indicator parameter value" },
  90. { "22011", "Substring error" },
  91. { "22012", "Division by zero" },
  92. { "22015", "Interval field overflow" },
  93. { "22018", "Invalid character value for cast specification" },
  94. { "22019", "Invalid escape character" },
  95. { "2201B", "Invalid regular expression" },
  96. { "2201E", "Invalid argument for logarithm" },
  97. { "2201F", "Invalid argument for power function" },
  98. { "2201G", "Invalid argument for width bucket function" },
  99. { "22020", "Invalid limit value" },
  100. { "22021", "Character not in repertoire" },
  101. { "22022", "Indicator overflow" },
  102. { "22023", "Invalid parameter value" },
  103. { "22024", "Unterminated c string" },
  104. { "22025", "Invalid escape sequence" },
  105. { "22026", "String data, length mismatch" },
  106. { "22027", "Trim error" },
  107. { "2202E", "Array subscript error" },
  108. { "22P01", "Floating point exception" },
  109. { "22P02", "Invalid text representation" },
  110. { "22P03", "Invalid binary representation" },
  111. { "22P04", "Bad copy file format" },
  112. { "22P05", "Untranslatable character" },
  113. { "23000", "Integrity constraint violation" },
  114. { "23001", "Restrict violation" },
  115. { "23502", "Not null violation" },
  116. { "23503", "Foreign key violation" },
  117. { "23505", "Unique violation" },
  118. { "23514", "Check violation" },
  119. { "24000", "Invalid cursor state" },
  120. { "25000", "Invalid transaction state" },
  121. { "25001", "Active sql transaction" },
  122. { "25002", "Branch transaction already active" },
  123. { "25003", "Inappropriate access mode for branch transaction" },
  124. { "25004", "Inappropriate isolation level for branch transaction" },
  125. { "25005", "No active sql transaction for branch transaction" },
  126. { "25006", "Read only sql transaction" },
  127. { "25007", "Schema and data statement mixing not supported" },
  128. { "25008", "Held cursor requires same isolation level" },
  129. { "25P01", "No active sql transaction" },
  130. { "25P02", "In failed sql transaction" },
  131. { "25S01", "Transaction state" },
  132. { "25S02", "Transaction is still active" },
  133. { "25S03", "Transaction is rolled back" },
  134. { "26000", "Invalid sql statement name" },
  135. { "27000", "Triggered data change violation" },
  136. { "28000", "Invalid authorization specification" },
  137. { "2B000", "Dependent privilege descriptors still exist" },
  138. { "2BP01", "Dependent objects still exist" },
  139. { "2D000", "Invalid transaction termination" },
  140. { "2F000", "Sql routine exception" },
  141. { "2F002", "Modifying sql data not permitted" },
  142. { "2F003", "Prohibited sql statement attempted" },
  143. { "2F004", "Reading sql data not permitted" },
  144. { "2F005", "Function executed no return statement" },
  145. { "34000", "Invalid cursor name" },
  146. { "38000", "External routine exception" },
  147. { "38001", "Containing sql not permitted" },
  148. { "38002", "Modifying sql data not permitted" },
  149. { "38003", "Prohibited sql statement attempted" },
  150. { "38004", "Reading sql data not permitted" },
  151. { "39000", "External routine invocation exception" },
  152. { "39001", "Invalid sqlstate returned" },
  153. { "39004", "Null value not allowed" },
  154. { "39P01", "Trigger protocol violated" },
  155. { "39P02", "Srf protocol violated" },
  156. { "3B000", "Savepoint exception" },
  157. { "3B001", "Invalid savepoint specification" },
  158. { "3C000", "Duplicate cursor name" },
  159. { "3D000", "Invalid catalog name" },
  160. { "3F000", "Invalid schema name" },
  161. { "40000", "Transaction rollback" },
  162. { "40001", "Serialization failure" },
  163. { "40002", "Transaction integrity constraint violation" },
  164. { "40003", "Statement completion unknown" },
  165. { "40P01", "Deadlock detected" },
  166. { "42000", "Syntax error or access violation" },
  167. { "42501", "Insufficient privilege" },
  168. { "42601", "Syntax error" },
  169. { "42602", "Invalid name" },
  170. { "42611", "Invalid column definition" },
  171. { "42622", "Name too long" },
  172. { "42701", "Duplicate column" },
  173. { "42702", "Ambiguous column" },
  174. { "42703", "Undefined column" },
  175. { "42704", "Undefined object" },
  176. { "42710", "Duplicate object" },
  177. { "42712", "Duplicate alias" },
  178. { "42723", "Duplicate function" },
  179. { "42725", "Ambiguous function" },
  180. { "42803", "Grouping error" },
  181. { "42804", "Datatype mismatch" },
  182. { "42809", "Wrong object type" },
  183. { "42830", "Invalid foreign key" },
  184. { "42846", "Cannot coerce" },
  185. { "42883", "Undefined function" },
  186. { "42939", "Reserved name" },
  187. { "42P01", "Undefined table" },
  188. { "42P02", "Undefined parameter" },
  189. { "42P03", "Duplicate cursor" },
  190. { "42P04", "Duplicate database" },
  191. { "42P05", "Duplicate prepared statement" },
  192. { "42P06", "Duplicate schema" },
  193. { "42P07", "Duplicate table" },
  194. { "42P08", "Ambiguous parameter" },
  195. { "42P09", "Ambiguous alias" },
  196. { "42P10", "Invalid column reference" },
  197. { "42P11", "Invalid cursor definition" },
  198. { "42P12", "Invalid database definition" },
  199. { "42P13", "Invalid function definition" },
  200. { "42P14", "Invalid prepared statement definition" },
  201. { "42P15", "Invalid schema definition" },
  202. { "42P16", "Invalid table definition" },
  203. { "42P17", "Invalid object definition" },
  204. { "42P18", "Indeterminate datatype" },
  205. { "42S01", "Base table or view already exists" },
  206. { "42S02", "Base table or view not found" },
  207. { "42S11", "Index already exists" },
  208. { "42S12", "Index not found" },
  209. { "42S21", "Column already exists" },
  210. { "42S22", "Column not found" },
  211. { "44000", "WITH CHECK OPTION violation" },
  212. { "53000", "Insufficient resources" },
  213. { "53100", "Disk full" },
  214. { "53200", "Out of memory" },
  215. { "53300", "Too many connections" },
  216. { "54000", "Program limit exceeded" },
  217. { "54001", "Statement too complex" },
  218. { "54011", "Too many columns" },
  219. { "54023", "Too many arguments" },
  220. { "55000", "Object not in prerequisite state" },
  221. { "55006", "Object in use" },
  222. { "55P02", "Cant change runtime param" },
  223. { "55P03", "Lock not available" },
  224. { "57000", "Operator intervention" },
  225. { "57014", "Query canceled" },
  226. { "57P01", "Admin shutdown" },
  227. { "57P02", "Crash shutdown" },
  228. { "57P03", "Cannot connect now" },
  229. { "58030", "Io error" },
  230. { "58P01", "Undefined file" },
  231. { "58P02", "Duplicate file" },
  232. { "F0000", "Config file error" },
  233. { "F0001", "Lock file exists" },
  234. { "HY000", "General error" },
  235. { "HY001", "Memory allocation error" },
  236. { "HY003", "Invalid application buffer type" },
  237. { "HY004", "Invalid SQL data type" },
  238. { "HY007", "Associated statement is not prepared" },
  239. { "HY008", "Operation canceled" },
  240. { "HY009", "Invalid use of null pointer" },
  241. { "HY010", "Function sequence error" },
  242. { "HY011", "Attribute cannot be set now" },
  243. { "HY012", "Invalid transaction operation code" },
  244. { "HY013", "Memory management error" },
  245. { "HY014", "Limit on the number of handles exceeded" },
  246. { "HY015", "No cursor name available" },
  247. { "HY016", "Cannot modify an implementation row descriptor" },
  248. { "HY017", "Invalid use of an automatically allocated descriptor handle" },
  249. { "HY018", "Server declined cancel request" },
  250. { "HY019", "Non-character and non-binary data sent in pieces" },
  251. { "HY020", "Attempt to concatenate a null value" },
  252. { "HY021", "Inconsistent descriptor information" },
  253. { "HY024", "Invalid attribute value" },
  254. { "HY090", "Invalid string or buffer length" },
  255. { "HY091", "Invalid descriptor field identifier" },
  256. { "HY092", "Invalid attribute/option identifier" },
  257. { "HY093", "Invalid parameter number" },
  258. { "HY095", "Function type out of range" },
  259. { "HY096", "Invalid information type" },
  260. { "HY097", "Column type out of range" },
  261. { "HY098", "Scope type out of range" },
  262. { "HY099", "Nullable type out of range" },
  263. { "HY100", "Uniqueness option type out of range" },
  264. { "HY101", "Accuracy option type out of range" },
  265. { "HY103", "Invalid retrieval code" },
  266. { "HY104", "Invalid precision or scale value" },
  267. { "HY105", "Invalid parameter type" },
  268. { "HY106", "Fetch type out of range" },
  269. { "HY107", "Row value out of range" },
  270. { "HY109", "Invalid cursor position" },
  271. { "HY110", "Invalid driver completion" },
  272. { "HY111", "Invalid bookmark value" },
  273. { "HYC00", "Optional feature not implemented" },
  274. { "HYT00", "Timeout expired" },
  275. { "HYT01", "Connection timeout expired" },
  276. { "IM001", "Driver does not support this function" },
  277. { "IM002", "Data source name not found and no default driver specified" },
  278. { "IM003", "Specified driver could not be loaded" },
  279. { "IM004", "Driver's SQLAllocHandle on SQL_HANDLE_ENV failed" },
  280. { "IM005", "Driver's SQLAllocHandle on SQL_HANDLE_DBC failed" },
  281. { "IM006", "Driver's SQLSetConnectAttr failed" },
  282. { "IM007", "No data source or driver specified; dialog prohibited" },
  283. { "IM008", "Dialog failed" },
  284. { "IM009", "Unable to load translation DLL" },
  285. { "IM010", "Data source name too long" },
  286. { "IM011", "Driver name too long" },
  287. { "IM012", "DRIVER keyword syntax error" },
  288. { "IM013", "Trace file error" },
  289. { "IM014", "Invalid name of File DSN" },
  290. { "IM015", "Corrupt file data source" },
  291. { "P0000", "Plpgsql error" },
  292. { "P0001", "Raise exception" },
  293. { "XX000", "Internal error" },
  294. { "XX001", "Data corrupted" },
  295. { "XX002", "Index corrupted" }
  296. };
  297. void pdo_sqlstate_fini_error_table(void)
  298. {
  299. zend_hash_destroy(&err_hash);
  300. }
  301. void pdo_sqlstate_init_error_table(void)
  302. {
  303. size_t i;
  304. const struct pdo_sqlstate_info *info;
  305. zend_hash_init(&err_hash, sizeof(err_initializer)/sizeof(err_initializer[0]), NULL, NULL, 1);
  306. for (i = 0; i < sizeof(err_initializer)/sizeof(err_initializer[0]); i++) {
  307. info = &err_initializer[i];
  308. zend_hash_str_add_ptr(&err_hash, info->state, sizeof(info->state), (void *)info);
  309. }
  310. }
  311. const char *pdo_sqlstate_state_to_description(char *state)
  312. {
  313. const struct pdo_sqlstate_info *info;
  314. if ((info = zend_hash_str_find_ptr(&err_hash, state, sizeof(err_initializer[0].state))) != NULL) {
  315. return info->desc;
  316. }
  317. return NULL;
  318. }