3 * @version V3.60 16 June 2003 (c) 2000-2003 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;
62 case 'mysql': $map = adodb_error_mysql(); break;
65 case 'oci8': $map = adodb_error_oci8(); break;
67 case 'ibase': $map = adodb_error_ibase(); break;
69 case 'odbc': $map = adodb_error_odbc(); break;
72 case 'sybase': $map = adodb_error_mssql(); break;
74 case 'informix': $map = adodb_error_ifx(); break;
76 case 'postgres': return adodb_error_pg($errno); break;
82 if (isset($map[$errno])) return $map[$errno];
86 //**************************************************************************************
88 function adodb_error_pg($errormsg)
90 static $error_regexps = array(
91 '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE
,
92 '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS
,
93 '/divide by zero$/' => DB_ERROR_DIVZERO
,
94 '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER
,
95 '/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD
,
96 '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX
,
97 '/referential integrity violation/' => DB_ERROR_CONSTRAINT
100 foreach ($error_regexps as $regexp => $code) {
101 if (preg_match($regexp, $errormsg)) {
105 // Fall back to DB_ERROR if there was no mapping.
109 function adodb_error_odbc()
112 '01004' => DB_ERROR_TRUNCATED
,
113 '07001' => DB_ERROR_MISMATCH
,
114 '21S01' => DB_ERROR_MISMATCH
,
115 '21S02' => DB_ERROR_MISMATCH
,
116 '22003' => DB_ERROR_INVALID_NUMBER
,
117 '22008' => DB_ERROR_INVALID_DATE
,
118 '22012' => DB_ERROR_DIVZERO
,
119 '23000' => DB_ERROR_CONSTRAINT
,
120 '24000' => DB_ERROR_INVALID
,
121 '34000' => DB_ERROR_INVALID
,
122 '37000' => DB_ERROR_SYNTAX
,
123 '42000' => DB_ERROR_SYNTAX
,
124 'IM001' => DB_ERROR_UNSUPPORTED
,
125 'S0000' => DB_ERROR_NOSUCHTABLE
,
126 'S0001' => DB_ERROR_NOT_FOUND
,
127 'S0002' => DB_ERROR_NOSUCHTABLE
,
128 'S0011' => DB_ERROR_ALREADY_EXISTS
,
129 'S0012' => DB_ERROR_NOT_FOUND
,
130 'S0021' => DB_ERROR_ALREADY_EXISTS
,
131 'S0022' => DB_ERROR_NOT_FOUND
,
132 'S1000' => DB_ERROR_NOSUCHTABLE
,
133 'S1009' => DB_ERROR_INVALID
,
134 'S1090' => DB_ERROR_INVALID
,
135 'S1C00' => DB_ERROR_NOT_CAPABLE
140 function adodb_error_ibase()
143 -104 => DB_ERROR_SYNTAX
,
144 -150 => DB_ERROR_ACCESS_VIOLATION
,
145 -151 => DB_ERROR_ACCESS_VIOLATION
,
146 -155 => DB_ERROR_NOSUCHTABLE
,
147 -157 => DB_ERROR_NOSUCHFIELD
,
148 -158 => DB_ERROR_VALUE_COUNT_ON_ROW
,
149 -170 => DB_ERROR_MISMATCH
,
150 -171 => DB_ERROR_MISMATCH
,
151 -172 => DB_ERROR_INVALID
,
152 -204 => DB_ERROR_INVALID
,
153 -205 => DB_ERROR_NOSUCHFIELD
,
154 -206 => DB_ERROR_NOSUCHFIELD
,
155 -208 => DB_ERROR_INVALID
,
156 -219 => DB_ERROR_NOSUCHTABLE
,
157 -297 => DB_ERROR_CONSTRAINT
,
158 -530 => DB_ERROR_CONSTRAINT
,
159 -803 => DB_ERROR_CONSTRAINT
,
160 -551 => DB_ERROR_ACCESS_VIOLATION
,
161 -552 => DB_ERROR_ACCESS_VIOLATION
,
162 -922 => DB_ERROR_NOSUCHDB
,
163 -923 => DB_ERROR_CONNECT_FAILED
,
164 -924 => DB_ERROR_CONNECT_FAILED
170 function adodb_error_ifx()
173 '-201' => DB_ERROR_SYNTAX
,
174 '-206' => DB_ERROR_NOSUCHTABLE
,
175 '-217' => DB_ERROR_NOSUCHFIELD
,
176 '-329' => DB_ERROR_NODBSELECTED
,
177 '-1204' => DB_ERROR_INVALID_DATE
,
178 '-1205' => DB_ERROR_INVALID_DATE
,
179 '-1206' => DB_ERROR_INVALID_DATE
,
180 '-1209' => DB_ERROR_INVALID_DATE
,
181 '-1210' => DB_ERROR_INVALID_DATE
,
182 '-1212' => DB_ERROR_INVALID_DATE
188 function adodb_error_oci8()
191 900 => DB_ERROR_SYNTAX
,
192 904 => DB_ERROR_NOSUCHFIELD
,
193 923 => DB_ERROR_SYNTAX
,
194 942 => DB_ERROR_NOSUCHTABLE
,
195 955 => DB_ERROR_ALREADY_EXISTS
,
196 1476 => DB_ERROR_DIVZERO
,
197 1722 => DB_ERROR_INVALID_NUMBER
,
198 2289 => DB_ERROR_NOSUCHTABLE
,
199 2291 => DB_ERROR_CONSTRAINT
,
200 2449 => DB_ERROR_CONSTRAINT
,
206 function adodb_error_mssql()
209 208 => DB_ERROR_NOSUCHTABLE
,
210 2601 => DB_ERROR_ALREADY_EXISTS
216 function adodb_error_mysql()
219 1004 => DB_ERROR_CANNOT_CREATE
,
220 1005 => DB_ERROR_CANNOT_CREATE
,
221 1006 => DB_ERROR_CANNOT_CREATE
,
222 1007 => DB_ERROR_ALREADY_EXISTS
,
223 1008 => DB_ERROR_CANNOT_DROP
,
224 1046 => DB_ERROR_NODBSELECTED
,
225 1050 => DB_ERROR_ALREADY_EXISTS
,
226 1051 => DB_ERROR_NOSUCHTABLE
,
227 1054 => DB_ERROR_NOSUCHFIELD
,
228 1062 => DB_ERROR_ALREADY_EXISTS
,
229 1064 => DB_ERROR_SYNTAX
,
230 1100 => DB_ERROR_NOT_LOCKED
,
231 1136 => DB_ERROR_VALUE_COUNT_ON_ROW
,
232 1146 => DB_ERROR_NOSUCHTABLE
,
233 1048 => DB_ERROR_CONSTRAINT
,