]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/adodb-error.inc.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / adodb-error.inc.php
1 <?php
2 /**
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.
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 if (!defined("DB_ERROR")) define("DB_ERROR", -1);
15
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);
43 }
44
45 function adodb_errormsg($value)
46 {
47     global $ADODB_LANG, $ADODB_LANG_ARRAY;
48
49     if (empty($ADODB_LANG)) $ADODB_LANG = 'en';
50     if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ;
51     else {
52         include_once(ADODB_DIR . "/lang/adodb-$ADODB_LANG.inc.php");
53     }
54     return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR];
55 }
56
57 function adodb_error($provider, $dbType, $errno)
58 {
59     //var_dump($errno);
60     if (is_numeric($errno) && $errno == 0) return 0;
61     switch ($provider) {
62         case 'mysql':
63             $map = adodb_error_mysql();
64             break;
65
66         case 'oracle':
67         case 'oci8':
68             $map = adodb_error_oci8();
69             break;
70
71         case 'ibase':
72             $map = adodb_error_ibase();
73             break;
74
75         case 'odbc':
76             $map = adodb_error_odbc();
77             break;
78
79         case 'mssql':
80         case 'sybase':
81             $map = adodb_error_mssql();
82             break;
83
84         case 'informix':
85             $map = adodb_error_ifx();
86             break;
87
88         case 'postgres':
89             return adodb_error_pg($errno);
90             break;
91
92         case 'sqlite':
93             return $map = adodb_error_sqlite();
94             break;
95         default:
96             return DB_ERROR;
97     }
98     //print_r($map);
99     //var_dump($errno);
100     if (isset($map[$errno])) return $map[$errno];
101     return DB_ERROR;
102 }
103
104 //**************************************************************************************
105
106 function adodb_error_pg($errormsg)
107 {
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
116     );
117     reset($error_regexps);
118     while (list($regexp, $code) = each($error_regexps)) {
119         if (preg_match($regexp, $errormsg)) {
120             return $code;
121         }
122     }
123     // Fall back to DB_ERROR if there was no mapping.
124     return DB_ERROR;
125 }
126
127 function adodb_error_odbc()
128 {
129     static $MAP = array(
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
154     );
155     return $MAP;
156 }
157
158 function adodb_error_ibase()
159 {
160     static $MAP = array(
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
183     );
184
185     return $MAP;
186 }
187
188 function adodb_error_ifx()
189 {
190     static $MAP = array(
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
201     );
202
203     return $MAP;
204 }
205
206 function adodb_error_oci8()
207 {
208     static $MAP = array(
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
220     );
221
222     return $MAP;
223 }
224
225 function adodb_error_mssql()
226 {
227     static $MAP = array(
228         208 => DB_ERROR_NOSUCHTABLE,
229         2601 => DB_ERROR_ALREADY_EXISTS
230     );
231
232     return $MAP;
233 }
234
235 function adodb_error_sqlite()
236 {
237     static $MAP = array(
238         1 => DB_ERROR_SYNTAX
239     );
240
241     return $MAP;
242 }
243
244 function adodb_error_mysql()
245 {
246     static $MAP = array(
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
265     );
266
267     return $MAP;
268 }