You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.4 KiB

  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2005 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.0 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_0.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Wez Furlong <wez@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #include "php_ini.h"
  24. #include "ext/standard/info.h"
  25. #include "php_pdo.h"
  26. #include "php_pdo_driver.h"
  27. struct pdo_sqlstate_info {
  28. char state[6];
  29. const char *desc;
  30. };
  31. static HashTable err_hash;
  32. static struct pdo_sqlstate_info err_initializer[] = {
  33. { "00000", "No error" },
  34. { "01001", "Cursor operation conflict" },
  35. { "01002", "Disconnect error" },
  36. { "01003", "NULL value eliminated in set function" },
  37. { "01004", "String data, right truncated" },
  38. { "01006", "Privilege not revoked" },
  39. { "01007", "Privilege not granted" },
  40. { "01S00", "Invalid connection string attribute" },
  41. { "01S01", "Error in row" },
  42. { "01S02", "Option value changed" },
  43. { "01S06", "Attempt to fetch before the result set returned the first rowset" },
  44. { "01S07", "Fractional truncation" },
  45. { "01S08", "Error saving File DSN" },
  46. { "01S09", "Invalid keyword" },
  47. { "07002", "COUNT field incorrect" },
  48. { "07005", "Prepared statement not a cursor-specification" },
  49. { "07006", "Restricted data type attribute violation" },
  50. { "07009", "Invalid descriptor index" },
  51. { "07S01", "Invalid use of default parameter" },
  52. { "08001", "Client unable to establish connection" },
  53. { "08002", "Connection name in use" },
  54. { "08003", "Connection does not exist" },
  55. { "08004", "Server rejected the connection" },
  56. { "08007", "Connection failure during transaction" },
  57. { "08S01", "Communication link failure" },
  58. { "21S01", "Insert value list does not match column list" },
  59. { "21S02", "Degree of derived table does not match column list" },
  60. { "22001", "String data, right truncated" },
  61. { "22002", "Indicator variable required but not supplied" },
  62. { "22003", "Numeric value out of range" },
  63. { "22007", "Invalid datetime format" },
  64. { "22008", "Datetime field overflow" },
  65. { "22012", "Division by zero" },
  66. { "22015", "Interval field overflow" },
  67. { "22018", "Invalid character value for cast specification" },
  68. { "22019", "Invalid escape character" },
  69. { "22025", "Invalid escape sequence" },
  70. { "22026", "String data, length mismatch" },
  71. { "23000", "Integrity constraint violation" },
  72. { "24000", "Invalid cursor state" },
  73. { "25000", "Invalid transaction state" },
  74. { "25S01", "Transaction state" },
  75. { "25S02", "Transaction is still active" },
  76. { "25S03", "Transaction is rolled back" },
  77. { "28000", "Invalid authorization specification" },
  78. { "34000", "Invalid cursor name" },
  79. { "3C000", "Duplicate cursor name" },
  80. { "3D000", "Invalid catalog name" },
  81. { "3F000", "Invalid schema name" },
  82. { "40001", "Serialization failure" },
  83. { "40003", "Statement completion unknown" },
  84. { "42000", "Syntax error or access violation" },
  85. { "42S01", "Base table or view already exists" },
  86. { "42S02", "Base table or view not found" },
  87. { "42S11", "Index already exists" },
  88. { "42S12", "Index not found" },
  89. { "42S21", "Column already exists" },
  90. { "42S22", "Column not found" },
  91. { "44000", "WITH CHECK OPTION violation" },
  92. { "HY000", "General error" },
  93. { "HY001", "Memory allocation error" },
  94. { "HY003", "Invalid application buffer type" },
  95. { "HY004", "Invalid SQL data type" },
  96. { "HY007", "Associated statement is not prepared" },
  97. { "HY008", "Operation canceled" },
  98. { "HY009", "Invalid use of null pointer" },
  99. { "HY010", "Function sequence error" },
  100. { "HY011", "Attribute cannot be set now" },
  101. { "HY012", "Invalid transaction operation code" },
  102. { "HY013", "Memory management error" },
  103. { "HY014", "Limit on the number of handles exceeded" },
  104. { "HY015", "No cursor name available" },
  105. { "HY016", "Cannot modify an implementation row descriptor" },
  106. { "HY017", "Invalid use of an automatically allocated descriptor handle" },
  107. { "HY018", "Server declined cancel request" },
  108. { "HY019", "Non-character and non-binary data sent in pieces" },
  109. { "HY020", "Attempt to concatenate a null value" },
  110. { "HY021", "Inconsistent descriptor information" },
  111. { "HY024", "Invalid attribute value" },
  112. { "HY090", "Invalid string or buffer length" },
  113. { "HY091", "Invalid descriptor field identifier" },
  114. { "HY092", "Invalid attribute/option identifier" },
  115. { "HY093", "Invalid parameter number" },
  116. { "HY095", "Function type out of range" },
  117. { "HY096", "Invalid information type" },
  118. { "HY097", "Column type out of range" },
  119. { "HY098", "Scope type out of range" },
  120. { "HY099", "Nullable type out of range" },
  121. { "HY100", "Uniqueness option type out of range" },
  122. { "HY101", "Accuracy option type out of range" },
  123. { "HY103", "Invalid retrieval code" },
  124. { "HY104", "Invalid precision or scale value" },
  125. { "HY105", "Invalid parameter type" },
  126. { "HY106", "Fetch type out of range" },
  127. { "HY107", "Row value out of range" },
  128. { "HY109", "Invalid cursor position" },
  129. { "HY110", "Invalid driver completion" },
  130. { "HY111", "Invalid bookmark value" },
  131. { "HYC00", "Optional feature not implemented" },
  132. { "HYT00", "Timeout expired" },
  133. { "HYT01", "Connection timeout expired" },
  134. { "IM001", "Driver does not support this function" },
  135. { "IM002", "Data source name not found and no default driver specified" },
  136. { "IM003", "Specified driver could not be loaded" },
  137. { "IM004", "Driver's SQLAllocHandle on SQL_HANDLE_ENV failed" },
  138. { "IM005", "Driver's SQLAllocHandle on SQL_HANDLE_DBC failed" },
  139. { "IM006", "Driver's SQLSetConnectAttr failed" },
  140. { "IM007", "No data source or driver specified; dialog prohibited" },
  141. { "IM008", "Dialog failed" },
  142. { "IM009", "Unable to load translation DLL" },
  143. { "IM010", "Data source name too long" },
  144. { "IM011", "Driver name too long" },
  145. { "IM012", "DRIVER keyword syntax error" },
  146. { "IM013", "Trace file error" },
  147. { "IM014", "Invalid name of File DSN" },
  148. { "IM015", "Corrupt file data source" }
  149. };
  150. void pdo_sqlstate_fini_error_table(void)
  151. {
  152. zend_hash_destroy(&err_hash);
  153. }
  154. int pdo_sqlstate_init_error_table(void)
  155. {
  156. int i;
  157. struct pdo_sqlstate_info *info;
  158. if (FAILURE == zend_hash_init(&err_hash,
  159. sizeof(err_initializer)/sizeof(err_initializer[0]), NULL, NULL, 1)) {
  160. return FAILURE;
  161. }
  162. for (i = 0; i < sizeof(err_initializer)/sizeof(err_initializer[0]); i++) {
  163. info = &err_initializer[i];
  164. zend_hash_add(&err_hash, info->state, sizeof(info->state), &info, sizeof(info), NULL);
  165. }
  166. return SUCCESS;
  167. }
  168. const char *pdo_sqlstate_state_to_description(char *state)
  169. {
  170. struct pdo_sqlstate_info **info;
  171. if (SUCCESS == zend_hash_find(&err_hash, state, sizeof(err_initializer[0].state),
  172. (void**)&info)) {
  173. return (*info)->desc;
  174. }
  175. return NULL;
  176. }