3 * @version V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). 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.
8 * Set tabs to 4 for best viewing.
10 * The following code is adapted from the PEAR DB error handling code.
11 * Portions (c)1997-2002 The PHP Group.
14 if (!defined("DB_ERROR")) define("DB_ERROR", -1);
16 if (!defined("DB_ERROR_SYNTAX")) {
17 define("DB_ERROR_SYNTAX", -2);
18 define("DB_ERROR_CONSTRAINT", -3);
19 define("DB_ERROR_NOT_FOUND", -4);
20 define("DB_ERROR_ALREADY_EXISTS", -5);
21 define("DB_ERROR_UNSUPPORTED", -6);
22 define("DB_ERROR_MISMATCH", -7);
23 define("DB_ERROR_INVALID", -8);
24 define("DB_ERROR_NOT_CAPABLE", -9);
25 define("DB_ERROR_TRUNCATED", -10);
26 define("DB_ERROR_INVALID_NUMBER", -11);
27 define("DB_ERROR_INVALID_DATE", -12);
28 define("DB_ERROR_DIVZERO", -13);
29 define("DB_ERROR_NODBSELECTED", -14);
30 define("DB_ERROR_CANNOT_CREATE", -15);
31 define("DB_ERROR_CANNOT_DELETE", -16);
32 define("DB_ERROR_CANNOT_DROP", -17);
33 define("DB_ERROR_NOSUCHTABLE", -18);
34 define("DB_ERROR_NOSUCHFIELD", -19);
35 define("DB_ERROR_NEED_MORE_DATA", -20);
36 define("DB_ERROR_NOT_LOCKED", -21);
37 define("DB_ERROR_VALUE_COUNT_ON_ROW", -22);
38 define("DB_ERROR_INVALID_DSN", -23);
39 define("DB_ERROR_CONNECT_FAILED", -24);
40 define("DB_ERROR_EXTENSION_NOT_FOUND", -25);
41 define("DB_ERROR_NOSUCHDB", -25);
42 define("DB_ERROR_ACCESS_VIOLATION", -26);
45 function adodb_errormsg($value)
47 global $ADODB_LANG, $ADODB_LANG_ARRAY;
49 if (empty($ADODB_LANG)) $ADODB_LANG = 'en';
50 if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ;
52 include_once(ADODB_DIR . "/lang/adodb-$ADODB_LANG.inc.php");
54 return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR];
57 function adodb_error($provider, $dbType, $errno)
60 if (is_numeric($errno) && $errno == 0) return 0;
63 $map = adodb_error_mysql();
68 $map = adodb_error_oci8();
72 $map = adodb_error_ibase();
76 $map = adodb_error_odbc();
81 $map = adodb_error_mssql();
85 $map = adodb_error_ifx();
89 return adodb_error_pg($errno);
93 return $map = adodb_error_sqlite();
100 if (isset($map[$errno])) return $map[$errno];
104 //**************************************************************************************
106 function adodb_error_pg($errormsg)
108 static $error_regexps = array(
109 '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
110 '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
111 '/divide by zero$/' => DB_ERROR_DIVZERO,
112 '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
113 '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
114 '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
115 '/referential integrity violation/' => DB_ERROR_CONSTRAINT
117 reset($error_regexps);
118 while (list($regexp, $code) = each($error_regexps)) {
119 if (preg_match($regexp, $errormsg)) {
123 // Fall back to DB_ERROR if there was no mapping.
127 function adodb_error_odbc()
130 '01004' => DB_ERROR_TRUNCATED,
131 '07001' => DB_ERROR_MISMATCH,
132 '21S01' => DB_ERROR_MISMATCH,
133 '21S02' => DB_ERROR_MISMATCH,
134 '22003' => DB_ERROR_INVALID_NUMBER,
135 '22008' => DB_ERROR_INVALID_DATE,
136 '22012' => DB_ERROR_DIVZERO,
137 '23000' => DB_ERROR_CONSTRAINT,
138 '24000' => DB_ERROR_INVALID,
139 '34000' => DB_ERROR_INVALID,
140 '37000' => DB_ERROR_SYNTAX,
141 '42000' => DB_ERROR_SYNTAX,
142 'IM001' => DB_ERROR_UNSUPPORTED,
143 'S0000' => DB_ERROR_NOSUCHTABLE,
144 'S0001' => DB_ERROR_NOT_FOUND,
145 'S0002' => DB_ERROR_NOSUCHTABLE,
146 'S0011' => DB_ERROR_ALREADY_EXISTS,
147 'S0012' => DB_ERROR_NOT_FOUND,
148 'S0021' => DB_ERROR_ALREADY_EXISTS,
149 'S0022' => DB_ERROR_NOT_FOUND,
150 'S1000' => DB_ERROR_NOSUCHTABLE,
151 'S1009' => DB_ERROR_INVALID,
152 'S1090' => DB_ERROR_INVALID,
153 'S1C00' => DB_ERROR_NOT_CAPABLE
158 function adodb_error_ibase()
161 -104 => DB_ERROR_SYNTAX,
162 -150 => DB_ERROR_ACCESS_VIOLATION,
163 -151 => DB_ERROR_ACCESS_VIOLATION,
164 -155 => DB_ERROR_NOSUCHTABLE,
165 -157 => DB_ERROR_NOSUCHFIELD,
166 -158 => DB_ERROR_VALUE_COUNT_ON_ROW,
167 -170 => DB_ERROR_MISMATCH,
168 -171 => DB_ERROR_MISMATCH,
169 -172 => DB_ERROR_INVALID,
170 -204 => DB_ERROR_INVALID,
171 -205 => DB_ERROR_NOSUCHFIELD,
172 -206 => DB_ERROR_NOSUCHFIELD,
173 -208 => DB_ERROR_INVALID,
174 -219 => DB_ERROR_NOSUCHTABLE,
175 -297 => DB_ERROR_CONSTRAINT,
176 -530 => DB_ERROR_CONSTRAINT,
177 -803 => DB_ERROR_CONSTRAINT,
178 -551 => DB_ERROR_ACCESS_VIOLATION,
179 -552 => DB_ERROR_ACCESS_VIOLATION,
180 -922 => DB_ERROR_NOSUCHDB,
181 -923 => DB_ERROR_CONNECT_FAILED,
182 -924 => DB_ERROR_CONNECT_FAILED
188 function adodb_error_ifx()
191 '-201' => DB_ERROR_SYNTAX,
192 '-206' => DB_ERROR_NOSUCHTABLE,
193 '-217' => DB_ERROR_NOSUCHFIELD,
194 '-329' => DB_ERROR_NODBSELECTED,
195 '-1204' => DB_ERROR_INVALID_DATE,
196 '-1205' => DB_ERROR_INVALID_DATE,
197 '-1206' => DB_ERROR_INVALID_DATE,
198 '-1209' => DB_ERROR_INVALID_DATE,
199 '-1210' => DB_ERROR_INVALID_DATE,
200 '-1212' => DB_ERROR_INVALID_DATE
206 function adodb_error_oci8()
209 1 => DB_ERROR_ALREADY_EXISTS,
210 900 => DB_ERROR_SYNTAX,
211 904 => DB_ERROR_NOSUCHFIELD,
212 923 => DB_ERROR_SYNTAX,
213 942 => DB_ERROR_NOSUCHTABLE,
214 955 => DB_ERROR_ALREADY_EXISTS,
215 1476 => DB_ERROR_DIVZERO,
216 1722 => DB_ERROR_INVALID_NUMBER,
217 2289 => DB_ERROR_NOSUCHTABLE,
218 2291 => DB_ERROR_CONSTRAINT,
219 2449 => DB_ERROR_CONSTRAINT
225 function adodb_error_mssql()
228 208 => DB_ERROR_NOSUCHTABLE,
229 2601 => DB_ERROR_ALREADY_EXISTS
235 function adodb_error_sqlite()
244 function adodb_error_mysql()
247 1004 => DB_ERROR_CANNOT_CREATE,
248 1005 => DB_ERROR_CANNOT_CREATE,
249 1006 => DB_ERROR_CANNOT_CREATE,
250 1007 => DB_ERROR_ALREADY_EXISTS,
251 1008 => DB_ERROR_CANNOT_DROP,
252 1045 => DB_ERROR_ACCESS_VIOLATION,
253 1046 => DB_ERROR_NODBSELECTED,
254 1049 => DB_ERROR_NOSUCHDB,
255 1050 => DB_ERROR_ALREADY_EXISTS,
256 1051 => DB_ERROR_NOSUCHTABLE,
257 1054 => DB_ERROR_NOSUCHFIELD,
258 1062 => DB_ERROR_ALREADY_EXISTS,
259 1064 => DB_ERROR_SYNTAX,
260 1100 => DB_ERROR_NOT_LOCKED,
261 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
262 1146 => DB_ERROR_NOSUCHTABLE,
263 1048 => DB_ERROR_CONSTRAINT,
264 2002 => DB_ERROR_CONNECT_FAILED