PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/include/adodb/adodb-error.inc.php

https://github.com/radicaldesigns/amp
PHP | 258 lines | 214 code | 28 blank | 16 comment | 14 complexity | c6c71d9d4a6a79202b1a1bf32d0ed51d MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. * @version V4.92a 29 Aug 2006 (c) 2000-2006 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. if (!defined("DB_ERROR")) define("DB_ERROR",-1);
  14. if (!defined("DB_ERROR_SYNTAX")) {
  15. define("DB_ERROR_SYNTAX", -2);
  16. define("DB_ERROR_CONSTRAINT", -3);
  17. define("DB_ERROR_NOT_FOUND", -4);
  18. define("DB_ERROR_ALREADY_EXISTS", -5);
  19. define("DB_ERROR_UNSUPPORTED", -6);
  20. define("DB_ERROR_MISMATCH", -7);
  21. define("DB_ERROR_INVALID", -8);
  22. define("DB_ERROR_NOT_CAPABLE", -9);
  23. define("DB_ERROR_TRUNCATED", -10);
  24. define("DB_ERROR_INVALID_NUMBER", -11);
  25. define("DB_ERROR_INVALID_DATE", -12);
  26. define("DB_ERROR_DIVZERO", -13);
  27. define("DB_ERROR_NODBSELECTED", -14);
  28. define("DB_ERROR_CANNOT_CREATE", -15);
  29. define("DB_ERROR_CANNOT_DELETE", -16);
  30. define("DB_ERROR_CANNOT_DROP", -17);
  31. define("DB_ERROR_NOSUCHTABLE", -18);
  32. define("DB_ERROR_NOSUCHFIELD", -19);
  33. define("DB_ERROR_NEED_MORE_DATA", -20);
  34. define("DB_ERROR_NOT_LOCKED", -21);
  35. define("DB_ERROR_VALUE_COUNT_ON_ROW", -22);
  36. define("DB_ERROR_INVALID_DSN", -23);
  37. define("DB_ERROR_CONNECT_FAILED", -24);
  38. define("DB_ERROR_EXTENSION_NOT_FOUND",-25);
  39. define("DB_ERROR_NOSUCHDB", -25);
  40. define("DB_ERROR_ACCESS_VIOLATION", -26);
  41. }
  42. function adodb_errormsg($value)
  43. {
  44. global $ADODB_LANG,$ADODB_LANG_ARRAY;
  45. if (empty($ADODB_LANG)) $ADODB_LANG = 'en';
  46. if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ;
  47. else {
  48. include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php");
  49. }
  50. return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR];
  51. }
  52. function adodb_error($provider,$dbType,$errno)
  53. {
  54. //var_dump($errno);
  55. if (is_numeric($errno) && $errno == 0) return 0;
  56. switch($provider) {
  57. case 'mysql': $map = adodb_error_mysql(); break;
  58. case 'oracle':
  59. case 'oci8': $map = adodb_error_oci8(); break;
  60. case 'ibase': $map = adodb_error_ibase(); break;
  61. case 'odbc': $map = adodb_error_odbc(); break;
  62. case 'mssql':
  63. case 'sybase': $map = adodb_error_mssql(); break;
  64. case 'informix': $map = adodb_error_ifx(); break;
  65. case 'postgres': return adodb_error_pg($errno); break;
  66. case 'sqlite': return $map = adodb_error_sqlite(); break;
  67. default:
  68. return DB_ERROR;
  69. }
  70. //print_r($map);
  71. //var_dump($errno);
  72. if (isset($map[$errno])) return $map[$errno];
  73. return DB_ERROR;
  74. }
  75. //**************************************************************************************
  76. function adodb_error_pg($errormsg)
  77. {
  78. if (is_numeric($errormsg)) return (integer) $errormsg;
  79. static $error_regexps = array(
  80. '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
  81. '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
  82. '/divide by zero$/' => DB_ERROR_DIVZERO,
  83. '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
  84. '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
  85. '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
  86. '/referential integrity violation/' => DB_ERROR_CONSTRAINT,
  87. '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
  88. => DB_ERROR_ALREADY_EXISTS
  89. );
  90. reset($error_regexps);
  91. while (list($regexp,$code) = each($error_regexps)) {
  92. if (preg_match($regexp, $errormsg)) {
  93. return $code;
  94. }
  95. }
  96. // Fall back to DB_ERROR if there was no mapping.
  97. return DB_ERROR;
  98. }
  99. function adodb_error_odbc()
  100. {
  101. static $MAP = array(
  102. '01004' => DB_ERROR_TRUNCATED,
  103. '07001' => DB_ERROR_MISMATCH,
  104. '21S01' => DB_ERROR_MISMATCH,
  105. '21S02' => DB_ERROR_MISMATCH,
  106. '22003' => DB_ERROR_INVALID_NUMBER,
  107. '22008' => DB_ERROR_INVALID_DATE,
  108. '22012' => DB_ERROR_DIVZERO,
  109. '23000' => DB_ERROR_CONSTRAINT,
  110. '24000' => DB_ERROR_INVALID,
  111. '34000' => DB_ERROR_INVALID,
  112. '37000' => DB_ERROR_SYNTAX,
  113. '42000' => DB_ERROR_SYNTAX,
  114. 'IM001' => DB_ERROR_UNSUPPORTED,
  115. 'S0000' => DB_ERROR_NOSUCHTABLE,
  116. 'S0001' => DB_ERROR_NOT_FOUND,
  117. 'S0002' => DB_ERROR_NOSUCHTABLE,
  118. 'S0011' => DB_ERROR_ALREADY_EXISTS,
  119. 'S0012' => DB_ERROR_NOT_FOUND,
  120. 'S0021' => DB_ERROR_ALREADY_EXISTS,
  121. 'S0022' => DB_ERROR_NOT_FOUND,
  122. 'S1000' => DB_ERROR_NOSUCHTABLE,
  123. 'S1009' => DB_ERROR_INVALID,
  124. 'S1090' => DB_ERROR_INVALID,
  125. 'S1C00' => DB_ERROR_NOT_CAPABLE
  126. );
  127. return $MAP;
  128. }
  129. function adodb_error_ibase()
  130. {
  131. static $MAP = array(
  132. -104 => DB_ERROR_SYNTAX,
  133. -150 => DB_ERROR_ACCESS_VIOLATION,
  134. -151 => DB_ERROR_ACCESS_VIOLATION,
  135. -155 => DB_ERROR_NOSUCHTABLE,
  136. -157 => DB_ERROR_NOSUCHFIELD,
  137. -158 => DB_ERROR_VALUE_COUNT_ON_ROW,
  138. -170 => DB_ERROR_MISMATCH,
  139. -171 => DB_ERROR_MISMATCH,
  140. -172 => DB_ERROR_INVALID,
  141. -204 => DB_ERROR_INVALID,
  142. -205 => DB_ERROR_NOSUCHFIELD,
  143. -206 => DB_ERROR_NOSUCHFIELD,
  144. -208 => DB_ERROR_INVALID,
  145. -219 => DB_ERROR_NOSUCHTABLE,
  146. -297 => DB_ERROR_CONSTRAINT,
  147. -530 => DB_ERROR_CONSTRAINT,
  148. -803 => DB_ERROR_CONSTRAINT,
  149. -551 => DB_ERROR_ACCESS_VIOLATION,
  150. -552 => DB_ERROR_ACCESS_VIOLATION,
  151. -922 => DB_ERROR_NOSUCHDB,
  152. -923 => DB_ERROR_CONNECT_FAILED,
  153. -924 => DB_ERROR_CONNECT_FAILED
  154. );
  155. return $MAP;
  156. }
  157. function adodb_error_ifx()
  158. {
  159. static $MAP = array(
  160. '-201' => DB_ERROR_SYNTAX,
  161. '-206' => DB_ERROR_NOSUCHTABLE,
  162. '-217' => DB_ERROR_NOSUCHFIELD,
  163. '-329' => DB_ERROR_NODBSELECTED,
  164. '-1204' => DB_ERROR_INVALID_DATE,
  165. '-1205' => DB_ERROR_INVALID_DATE,
  166. '-1206' => DB_ERROR_INVALID_DATE,
  167. '-1209' => DB_ERROR_INVALID_DATE,
  168. '-1210' => DB_ERROR_INVALID_DATE,
  169. '-1212' => DB_ERROR_INVALID_DATE
  170. );
  171. return $MAP;
  172. }
  173. function adodb_error_oci8()
  174. {
  175. static $MAP = array(
  176. 1 => DB_ERROR_ALREADY_EXISTS,
  177. 900 => DB_ERROR_SYNTAX,
  178. 904 => DB_ERROR_NOSUCHFIELD,
  179. 923 => DB_ERROR_SYNTAX,
  180. 942 => DB_ERROR_NOSUCHTABLE,
  181. 955 => DB_ERROR_ALREADY_EXISTS,
  182. 1476 => DB_ERROR_DIVZERO,
  183. 1722 => DB_ERROR_INVALID_NUMBER,
  184. 2289 => DB_ERROR_NOSUCHTABLE,
  185. 2291 => DB_ERROR_CONSTRAINT,
  186. 2449 => DB_ERROR_CONSTRAINT
  187. );
  188. return $MAP;
  189. }
  190. function adodb_error_mssql()
  191. {
  192. static $MAP = array(
  193. 208 => DB_ERROR_NOSUCHTABLE,
  194. 2601 => DB_ERROR_ALREADY_EXISTS
  195. );
  196. return $MAP;
  197. }
  198. function adodb_error_sqlite()
  199. {
  200. static $MAP = array(
  201. 1 => DB_ERROR_SYNTAX
  202. );
  203. return $MAP;
  204. }
  205. function adodb_error_mysql()
  206. {
  207. static $MAP = array(
  208. 1004 => DB_ERROR_CANNOT_CREATE,
  209. 1005 => DB_ERROR_CANNOT_CREATE,
  210. 1006 => DB_ERROR_CANNOT_CREATE,
  211. 1007 => DB_ERROR_ALREADY_EXISTS,
  212. 1008 => DB_ERROR_CANNOT_DROP,
  213. 1045 => DB_ERROR_ACCESS_VIOLATION,
  214. 1046 => DB_ERROR_NODBSELECTED,
  215. 1049 => DB_ERROR_NOSUCHDB,
  216. 1050 => DB_ERROR_ALREADY_EXISTS,
  217. 1051 => DB_ERROR_NOSUCHTABLE,
  218. 1054 => DB_ERROR_NOSUCHFIELD,
  219. 1062 => DB_ERROR_ALREADY_EXISTS,
  220. 1064 => DB_ERROR_SYNTAX,
  221. 1100 => DB_ERROR_NOT_LOCKED,
  222. 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
  223. 1146 => DB_ERROR_NOSUCHTABLE,
  224. 1048 => DB_ERROR_CONSTRAINT,
  225. 2002 => DB_ERROR_CONNECT_FAILED,
  226. 2005 => DB_ERROR_CONNECT_FAILED
  227. );
  228. return $MAP;
  229. }
  230. ?>