00001 <?php
00015 if (!defined("DB_ERROR")) define("DB_ERROR",-1);
00016
00017 if (!defined("DB_ERROR_SYNTAX")) {
00018 define("DB_ERROR_SYNTAX", -2);
00019 define("DB_ERROR_CONSTRAINT", -3);
00020 define("DB_ERROR_NOT_FOUND", -4);
00021 define("DB_ERROR_ALREADY_EXISTS", -5);
00022 define("DB_ERROR_UNSUPPORTED", -6);
00023 define("DB_ERROR_MISMATCH", -7);
00024 define("DB_ERROR_INVALID", -8);
00025 define("DB_ERROR_NOT_CAPABLE", -9);
00026 define("DB_ERROR_TRUNCATED", -10);
00027 define("DB_ERROR_INVALID_NUMBER", -11);
00028 define("DB_ERROR_INVALID_DATE", -12);
00029 define("DB_ERROR_DIVZERO", -13);
00030 define("DB_ERROR_NODBSELECTED", -14);
00031 define("DB_ERROR_CANNOT_CREATE", -15);
00032 define("DB_ERROR_CANNOT_DELETE", -16);
00033 define("DB_ERROR_CANNOT_DROP", -17);
00034 define("DB_ERROR_NOSUCHTABLE", -18);
00035 define("DB_ERROR_NOSUCHFIELD", -19);
00036 define("DB_ERROR_NEED_MORE_DATA", -20);
00037 define("DB_ERROR_NOT_LOCKED", -21);
00038 define("DB_ERROR_VALUE_COUNT_ON_ROW", -22);
00039 define("DB_ERROR_INVALID_DSN", -23);
00040 define("DB_ERROR_CONNECT_FAILED", -24);
00041 define("DB_ERROR_EXTENSION_NOT_FOUND",-25);
00042 define("DB_ERROR_NOSUCHDB", -25);
00043 define("DB_ERROR_ACCESS_VIOLATION", -26);
00044 }
00045
00046 function adodb_errormsg($value)
00047 {
00048 global $ADODB_LANG,$ADODB_LANG_ARRAY;
00049
00050 if (empty($ADODB_LANG)) $ADODB_LANG = 'en';
00051 if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ;
00052 else {
00053 include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php");
00054 }
00055 return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR];
00056 }
00057
00058 function adodb_error($provider,$dbType,$errno)
00059 {
00060
00061 if (is_numeric($errno) && $errno == 0) return 0;
00062 switch($provider) {
00063 case 'mysql': $map = adodb_error_mysql(); break;
00064
00065 case 'oracle':
00066 case 'oci8': $map = adodb_error_oci8(); break;
00067
00068 case 'ibase': $map = adodb_error_ibase(); break;
00069
00070 case 'odbc': $map = adodb_error_odbc(); break;
00071
00072 case 'mssql':
00073 case 'sybase': $map = adodb_error_mssql(); break;
00074
00075 case 'informix': $map = adodb_error_ifx(); break;
00076
00077 case 'postgres': return adodb_error_pg($errno); break;
00078
00079 case 'sqlite': return $map = adodb_error_sqlite(); break;
00080 default:
00081 return DB_ERROR;
00082 }
00083
00084
00085 if (isset($map[$errno])) return $map[$errno];
00086 return DB_ERROR;
00087 }
00088
00089
00090
00091 function adodb_error_pg($errormsg)
00092 {
00093 if (is_numeric($errormsg)) return (integer) $errormsg;
00094 static $error_regexps = array(
00095 '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
00096 '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
00097 '/divide by zero$/' => DB_ERROR_DIVZERO,
00098 '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
00099 '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
00100 '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
00101 '/referential integrity violation/' => DB_ERROR_CONSTRAINT,
00102 '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
00103 => DB_ERROR_ALREADY_EXISTS
00104 );
00105 reset($error_regexps);
00106 while (list($regexp,$code) = each($error_regexps)) {
00107 if (preg_match($regexp, $errormsg)) {
00108 return $code;
00109 }
00110 }
00111 // Fall back to DB_ERROR if there was no mapping.
00112 return DB_ERROR;
00113 }
00114
00115 function adodb_error_odbc()
00116 {
00117 static $MAP = array(
00118 '01004' => DB_ERROR_TRUNCATED,
00119 '07001' => DB_ERROR_MISMATCH,
00120 '21S01' => DB_ERROR_MISMATCH,
00121 '21S02' => DB_ERROR_MISMATCH,
00122 '22003' => DB_ERROR_INVALID_NUMBER,
00123 '22008' => DB_ERROR_INVALID_DATE,
00124 '22012' => DB_ERROR_DIVZERO,
00125 '23000' => DB_ERROR_CONSTRAINT,
00126 '24000' => DB_ERROR_INVALID,
00127 '34000' => DB_ERROR_INVALID,
00128 '37000' => DB_ERROR_SYNTAX,
00129 '42000' => DB_ERROR_SYNTAX,
00130 'IM001' => DB_ERROR_UNSUPPORTED,
00131 'S0000' => DB_ERROR_NOSUCHTABLE,
00132 'S0001' => DB_ERROR_NOT_FOUND,
00133 'S0002' => DB_ERROR_NOSUCHTABLE,
00134 'S0011' => DB_ERROR_ALREADY_EXISTS,
00135 'S0012' => DB_ERROR_NOT_FOUND,
00136 'S0021' => DB_ERROR_ALREADY_EXISTS,
00137 'S0022' => DB_ERROR_NOT_FOUND,
00138 'S1000' => DB_ERROR_NOSUCHTABLE,
00139 'S1009' => DB_ERROR_INVALID,
00140 'S1090' => DB_ERROR_INVALID,
00141 'S1C00' => DB_ERROR_NOT_CAPABLE
00142 );
00143 return $MAP;
00144 }
00145
00146 function adodb_error_ibase()
00147 {
00148 static $MAP = array(
00149 -104 => DB_ERROR_SYNTAX,
00150 -150 => DB_ERROR_ACCESS_VIOLATION,
00151 -151 => DB_ERROR_ACCESS_VIOLATION,
00152 -155 => DB_ERROR_NOSUCHTABLE,
00153 -157 => DB_ERROR_NOSUCHFIELD,
00154 -158 => DB_ERROR_VALUE_COUNT_ON_ROW,
00155 -170 => DB_ERROR_MISMATCH,
00156 -171 => DB_ERROR_MISMATCH,
00157 -172 => DB_ERROR_INVALID,
00158 -204 => DB_ERROR_INVALID,
00159 -205 => DB_ERROR_NOSUCHFIELD,
00160 -206 => DB_ERROR_NOSUCHFIELD,
00161 -208 => DB_ERROR_INVALID,
00162 -219 => DB_ERROR_NOSUCHTABLE,
00163 -297 => DB_ERROR_CONSTRAINT,
00164 -530 => DB_ERROR_CONSTRAINT,
00165 -803 => DB_ERROR_CONSTRAINT,
00166 -551 => DB_ERROR_ACCESS_VIOLATION,
00167 -552 => DB_ERROR_ACCESS_VIOLATION,
00168 -922 => DB_ERROR_NOSUCHDB,
00169 -923 => DB_ERROR_CONNECT_FAILED,
00170 -924 => DB_ERROR_CONNECT_FAILED
00171 );
00172
00173 return $MAP;
00174 }
00175
00176 function adodb_error_ifx()
00177 {
00178 static $MAP = array(
00179 '-201' => DB_ERROR_SYNTAX,
00180 '-206' => DB_ERROR_NOSUCHTABLE,
00181 '-217' => DB_ERROR_NOSUCHFIELD,
00182 '-329' => DB_ERROR_NODBSELECTED,
00183 '-1204' => DB_ERROR_INVALID_DATE,
00184 '-1205' => DB_ERROR_INVALID_DATE,
00185 '-1206' => DB_ERROR_INVALID_DATE,
00186 '-1209' => DB_ERROR_INVALID_DATE,
00187 '-1210' => DB_ERROR_INVALID_DATE,
00188 '-1212' => DB_ERROR_INVALID_DATE
00189 );
00190
00191 return $MAP;
00192 }
00193
00194 function adodb_error_oci8()
00195 {
00196 static $MAP = array(
00197 1 => DB_ERROR_ALREADY_EXISTS,
00198 900 => DB_ERROR_SYNTAX,
00199 904 => DB_ERROR_NOSUCHFIELD,
00200 923 => DB_ERROR_SYNTAX,
00201 942 => DB_ERROR_NOSUCHTABLE,
00202 955 => DB_ERROR_ALREADY_EXISTS,
00203 1476 => DB_ERROR_DIVZERO,
00204 1722 => DB_ERROR_INVALID_NUMBER,
00205 2289 => DB_ERROR_NOSUCHTABLE,
00206 2291 => DB_ERROR_CONSTRAINT,
00207 2449 => DB_ERROR_CONSTRAINT
00208 );
00209
00210 return $MAP;
00211 }
00212
00213 function adodb_error_mssql()
00214 {
00215 static $MAP = array(
00216 208 => DB_ERROR_NOSUCHTABLE,
00217 2601 => DB_ERROR_ALREADY_EXISTS
00218 );
00219
00220 return $MAP;
00221 }
00222
00223 function adodb_error_sqlite()
00224 {
00225 static $MAP = array(
00226 1 => DB_ERROR_SYNTAX
00227 );
00228
00229 return $MAP;
00230 }
00231
00232 function adodb_error_mysql()
00233 {
00234 static $MAP = array(
00235 1004 => DB_ERROR_CANNOT_CREATE,
00236 1005 => DB_ERROR_CANNOT_CREATE,
00237 1006 => DB_ERROR_CANNOT_CREATE,
00238 1007 => DB_ERROR_ALREADY_EXISTS,
00239 1008 => DB_ERROR_CANNOT_DROP,
00240 1045 => DB_ERROR_ACCESS_VIOLATION,
00241 1046 => DB_ERROR_NODBSELECTED,
00242 1049 => DB_ERROR_NOSUCHDB,
00243 1050 => DB_ERROR_ALREADY_EXISTS,
00244 1051 => DB_ERROR_NOSUCHTABLE,
00245 1054 => DB_ERROR_NOSUCHFIELD,
00246 1062 => DB_ERROR_ALREADY_EXISTS,
00247 1064 => DB_ERROR_SYNTAX,
00248 1100 => DB_ERROR_NOT_LOCKED,
00249 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
00250 1146 => DB_ERROR_NOSUCHTABLE,
00251 1048 => DB_ERROR_CONSTRAINT,
00252 2002 => DB_ERROR_CONNECT_FAILED,
00253 2005 => DB_ERROR_CONNECT_FAILED
00254 );
00255
00256 return $MAP;
00257 }
00258 ?>