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