1 | <?php |
---|
2 | /** |
---|
3 | * @version V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. |
---|
4 | * Released under both BSD license and Lesser GPL library license. |
---|
5 | * Whenever there is any discrepancy between the two licenses, |
---|
6 | * the BSD license will take precedence. |
---|
7 | * |
---|
8 | * Set tabs to 4 for best viewing. |
---|
9 | * |
---|
10 | * The following code is adapted from the PEAR DB error handling code. |
---|
11 | * Portions (c)1997-2002 The PHP Group. |
---|
12 | */ |
---|
13 | |
---|
14 | |
---|
15 | if (!defined("DB_ERROR")) define("DB_ERROR",-1); |
---|
16 | |
---|
17 | if (!defined("DB_ERROR_SYNTAX")) { |
---|
18 | define("DB_ERROR_SYNTAX", -2); |
---|
19 | define("DB_ERROR_CONSTRAINT", -3); |
---|
20 | define("DB_ERROR_NOT_FOUND", -4); |
---|
21 | define("DB_ERROR_ALREADY_EXISTS", -5); |
---|
22 | define("DB_ERROR_UNSUPPORTED", -6); |
---|
23 | define("DB_ERROR_MISMATCH", -7); |
---|
24 | define("DB_ERROR_INVALID", -8); |
---|
25 | define("DB_ERROR_NOT_CAPABLE", -9); |
---|
26 | define("DB_ERROR_TRUNCATED", -10); |
---|
27 | define("DB_ERROR_INVALID_NUMBER", -11); |
---|
28 | define("DB_ERROR_INVALID_DATE", -12); |
---|
29 | define("DB_ERROR_DIVZERO", -13); |
---|
30 | define("DB_ERROR_NODBSELECTED", -14); |
---|
31 | define("DB_ERROR_CANNOT_CREATE", -15); |
---|
32 | define("DB_ERROR_CANNOT_DELETE", -16); |
---|
33 | define("DB_ERROR_CANNOT_DROP", -17); |
---|
34 | define("DB_ERROR_NOSUCHTABLE", -18); |
---|
35 | define("DB_ERROR_NOSUCHFIELD", -19); |
---|
36 | define("DB_ERROR_NEED_MORE_DATA", -20); |
---|
37 | define("DB_ERROR_NOT_LOCKED", -21); |
---|
38 | define("DB_ERROR_VALUE_COUNT_ON_ROW", -22); |
---|
39 | define("DB_ERROR_INVALID_DSN", -23); |
---|
40 | define("DB_ERROR_CONNECT_FAILED", -24); |
---|
41 | define("DB_ERROR_EXTENSION_NOT_FOUND",-25); |
---|
42 | define("DB_ERROR_NOSUCHDB", -25); |
---|
43 | define("DB_ERROR_ACCESS_VIOLATION", -26); |
---|
44 | define("DB_ERROR_DEADLOCK", -27); |
---|
45 | define("DB_ERROR_STATEMENT_TIMEOUT", -28); |
---|
46 | define("DB_ERROR_SERIALIZATION_FAILURE", -29); |
---|
47 | } |
---|
48 | |
---|
49 | function adodb_errormsg($value) |
---|
50 | { |
---|
51 | global $ADODB_LANG,$ADODB_LANG_ARRAY; |
---|
52 | |
---|
53 | if (empty($ADODB_LANG)) $ADODB_LANG = 'en'; |
---|
54 | if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ; |
---|
55 | else { |
---|
56 | include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php"); |
---|
57 | } |
---|
58 | return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR]; |
---|
59 | } |
---|
60 | |
---|
61 | function adodb_error($provider,$dbType,$errno) |
---|
62 | { |
---|
63 | //var_dump($errno); |
---|
64 | if (is_numeric($errno) && $errno == 0) return 0; |
---|
65 | switch($provider) { |
---|
66 | case 'mysql': $map = adodb_error_mysql(); break; |
---|
67 | |
---|
68 | case 'oracle': |
---|
69 | case 'oci8': $map = adodb_error_oci8(); break; |
---|
70 | |
---|
71 | case 'ibase': $map = adodb_error_ibase(); break; |
---|
72 | |
---|
73 | case 'odbc': $map = adodb_error_odbc(); break; |
---|
74 | |
---|
75 | case 'mssql': |
---|
76 | case 'sybase': $map = adodb_error_mssql(); break; |
---|
77 | |
---|
78 | case 'informix': $map = adodb_error_ifx(); break; |
---|
79 | |
---|
80 | case 'postgres': return adodb_error_pg($errno); break; |
---|
81 | |
---|
82 | case 'sqlite': return $map = adodb_error_sqlite(); break; |
---|
83 | default: |
---|
84 | return DB_ERROR; |
---|
85 | } |
---|
86 | //print_r($map); |
---|
87 | //var_dump($errno); |
---|
88 | if (isset($map[$errno])) return $map[$errno]; |
---|
89 | return DB_ERROR; |
---|
90 | } |
---|
91 | |
---|
92 | //************************************************************************************** |
---|
93 | |
---|
94 | function adodb_error_pg($errormsg) |
---|
95 | { |
---|
96 | if (is_numeric($errormsg)) return (integer) $errormsg; |
---|
97 | // Postgres has no lock-wait timeout. The best we could do would be to set a statement timeout. |
---|
98 | static $error_regexps = array( |
---|
99 | '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE, |
---|
100 | '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint/i' => DB_ERROR_ALREADY_EXISTS, |
---|
101 | '/database ".+" does not exist$/i' => DB_ERROR_NOSUCHDB, |
---|
102 | '/(divide|division) by zero$/i' => DB_ERROR_DIVZERO, |
---|
103 | '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER, |
---|
104 | '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD, |
---|
105 | '/(parser: parse|syntax) error at or near \"/i' => DB_ERROR_SYNTAX, |
---|
106 | '/referential integrity violation/i' => DB_ERROR_CONSTRAINT, |
---|
107 | '/deadlock detected$/i' => DB_ERROR_DEADLOCK, |
---|
108 | '/canceling statement due to statement timeout$/i' => DB_ERROR_STATEMENT_TIMEOUT, |
---|
109 | '/could not serialize access due to/i' => DB_ERROR_SERIALIZATION_FAILURE |
---|
110 | ); |
---|
111 | reset($error_regexps); |
---|
112 | while (list($regexp,$code) = each($error_regexps)) { |
---|
113 | if (preg_match($regexp, $errormsg)) { |
---|
114 | return $code; |
---|
115 | } |
---|
116 | } |
---|
117 | // Fall back to DB_ERROR if there was no mapping. |
---|
118 | return DB_ERROR; |
---|
119 | } |
---|
120 | |
---|
121 | function adodb_error_odbc() |
---|
122 | { |
---|
123 | static $MAP = array( |
---|
124 | '01004' => DB_ERROR_TRUNCATED, |
---|
125 | '07001' => DB_ERROR_MISMATCH, |
---|
126 | '21S01' => DB_ERROR_MISMATCH, |
---|
127 | '21S02' => DB_ERROR_MISMATCH, |
---|
128 | '22003' => DB_ERROR_INVALID_NUMBER, |
---|
129 | '22008' => DB_ERROR_INVALID_DATE, |
---|
130 | '22012' => DB_ERROR_DIVZERO, |
---|
131 | '23000' => DB_ERROR_CONSTRAINT, |
---|
132 | '24000' => DB_ERROR_INVALID, |
---|
133 | '34000' => DB_ERROR_INVALID, |
---|
134 | '37000' => DB_ERROR_SYNTAX, |
---|
135 | '42000' => DB_ERROR_SYNTAX, |
---|
136 | 'IM001' => DB_ERROR_UNSUPPORTED, |
---|
137 | 'S0000' => DB_ERROR_NOSUCHTABLE, |
---|
138 | 'S0001' => DB_ERROR_NOT_FOUND, |
---|
139 | 'S0002' => DB_ERROR_NOSUCHTABLE, |
---|
140 | 'S0011' => DB_ERROR_ALREADY_EXISTS, |
---|
141 | 'S0012' => DB_ERROR_NOT_FOUND, |
---|
142 | 'S0021' => DB_ERROR_ALREADY_EXISTS, |
---|
143 | 'S0022' => DB_ERROR_NOT_FOUND, |
---|
144 | 'S1000' => DB_ERROR_NOSUCHTABLE, |
---|
145 | 'S1009' => DB_ERROR_INVALID, |
---|
146 | 'S1090' => DB_ERROR_INVALID, |
---|
147 | 'S1C00' => DB_ERROR_NOT_CAPABLE |
---|
148 | ); |
---|
149 | return $MAP; |
---|
150 | } |
---|
151 | |
---|
152 | function adodb_error_ibase() |
---|
153 | { |
---|
154 | static $MAP = array( |
---|
155 | -104 => DB_ERROR_SYNTAX, |
---|
156 | -150 => DB_ERROR_ACCESS_VIOLATION, |
---|
157 | -151 => DB_ERROR_ACCESS_VIOLATION, |
---|
158 | -155 => DB_ERROR_NOSUCHTABLE, |
---|
159 | -157 => DB_ERROR_NOSUCHFIELD, |
---|
160 | -158 => DB_ERROR_VALUE_COUNT_ON_ROW, |
---|
161 | -170 => DB_ERROR_MISMATCH, |
---|
162 | -171 => DB_ERROR_MISMATCH, |
---|
163 | -172 => DB_ERROR_INVALID, |
---|
164 | -204 => DB_ERROR_INVALID, |
---|
165 | -205 => DB_ERROR_NOSUCHFIELD, |
---|
166 | -206 => DB_ERROR_NOSUCHFIELD, |
---|
167 | -208 => DB_ERROR_INVALID, |
---|
168 | -219 => DB_ERROR_NOSUCHTABLE, |
---|
169 | -297 => DB_ERROR_CONSTRAINT, |
---|
170 | -530 => DB_ERROR_CONSTRAINT, |
---|
171 | -803 => DB_ERROR_CONSTRAINT, |
---|
172 | -551 => DB_ERROR_ACCESS_VIOLATION, |
---|
173 | -552 => DB_ERROR_ACCESS_VIOLATION, |
---|
174 | -922 => DB_ERROR_NOSUCHDB, |
---|
175 | -923 => DB_ERROR_CONNECT_FAILED, |
---|
176 | -924 => DB_ERROR_CONNECT_FAILED |
---|
177 | ); |
---|
178 | |
---|
179 | return $MAP; |
---|
180 | } |
---|
181 | |
---|
182 | function adodb_error_ifx() |
---|
183 | { |
---|
184 | static $MAP = array( |
---|
185 | '-201' => DB_ERROR_SYNTAX, |
---|
186 | '-206' => DB_ERROR_NOSUCHTABLE, |
---|
187 | '-217' => DB_ERROR_NOSUCHFIELD, |
---|
188 | '-329' => DB_ERROR_NODBSELECTED, |
---|
189 | '-1204' => DB_ERROR_INVALID_DATE, |
---|
190 | '-1205' => DB_ERROR_INVALID_DATE, |
---|
191 | '-1206' => DB_ERROR_INVALID_DATE, |
---|
192 | '-1209' => DB_ERROR_INVALID_DATE, |
---|
193 | '-1210' => DB_ERROR_INVALID_DATE, |
---|
194 | '-1212' => DB_ERROR_INVALID_DATE |
---|
195 | ); |
---|
196 | |
---|
197 | return $MAP; |
---|
198 | } |
---|
199 | |
---|
200 | function adodb_error_oci8() |
---|
201 | { |
---|
202 | static $MAP = array( |
---|
203 | 1 => DB_ERROR_ALREADY_EXISTS, |
---|
204 | 900 => DB_ERROR_SYNTAX, |
---|
205 | 904 => DB_ERROR_NOSUCHFIELD, |
---|
206 | 923 => DB_ERROR_SYNTAX, |
---|
207 | 942 => DB_ERROR_NOSUCHTABLE, |
---|
208 | 955 => DB_ERROR_ALREADY_EXISTS, |
---|
209 | 1476 => DB_ERROR_DIVZERO, |
---|
210 | 1722 => DB_ERROR_INVALID_NUMBER, |
---|
211 | 2289 => DB_ERROR_NOSUCHTABLE, |
---|
212 | 2291 => DB_ERROR_CONSTRAINT, |
---|
213 | 2449 => DB_ERROR_CONSTRAINT |
---|
214 | ); |
---|
215 | |
---|
216 | return $MAP; |
---|
217 | } |
---|
218 | |
---|
219 | function adodb_error_mssql() |
---|
220 | { |
---|
221 | static $MAP = array( |
---|
222 | 208 => DB_ERROR_NOSUCHTABLE, |
---|
223 | 2601 => DB_ERROR_ALREADY_EXISTS |
---|
224 | ); |
---|
225 | |
---|
226 | return $MAP; |
---|
227 | } |
---|
228 | |
---|
229 | function adodb_error_sqlite() |
---|
230 | { |
---|
231 | static $MAP = array( |
---|
232 | 1 => DB_ERROR_SYNTAX |
---|
233 | ); |
---|
234 | |
---|
235 | return $MAP; |
---|
236 | } |
---|
237 | |
---|
238 | function adodb_error_mysql() |
---|
239 | { |
---|
240 | static $MAP = array( |
---|
241 | 1004 => DB_ERROR_CANNOT_CREATE, |
---|
242 | 1005 => DB_ERROR_CANNOT_CREATE, |
---|
243 | 1006 => DB_ERROR_CANNOT_CREATE, |
---|
244 | 1007 => DB_ERROR_ALREADY_EXISTS, |
---|
245 | 1008 => DB_ERROR_CANNOT_DROP, |
---|
246 | 1045 => DB_ERROR_ACCESS_VIOLATION, |
---|
247 | 1046 => DB_ERROR_NODBSELECTED, |
---|
248 | 1049 => DB_ERROR_NOSUCHDB, |
---|
249 | 1050 => DB_ERROR_ALREADY_EXISTS, |
---|
250 | 1051 => DB_ERROR_NOSUCHTABLE, |
---|
251 | 1054 => DB_ERROR_NOSUCHFIELD, |
---|
252 | 1062 => DB_ERROR_ALREADY_EXISTS, |
---|
253 | 1064 => DB_ERROR_SYNTAX, |
---|
254 | 1100 => DB_ERROR_NOT_LOCKED, |
---|
255 | 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, |
---|
256 | 1146 => DB_ERROR_NOSUCHTABLE, |
---|
257 | 1048 => DB_ERROR_CONSTRAINT, |
---|
258 | 2002 => DB_ERROR_CONNECT_FAILED, |
---|
259 | 2005 => DB_ERROR_CONNECT_FAILED |
---|
260 | ); |
---|
261 | |
---|
262 | return $MAP; |
---|
263 | } |
---|
264 | ?> |
---|