PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/adodb5/adodb-error.inc.php

https://gitlab.com/mrktinh/bookonline
PHP | 265 lines | 218 code | 28 blank | 19 comment | 14 complexity | 7c5362ae2836da139215e30f44409180 MD5 | raw file
  1. <?php
  2. /**
  3. * @version v5.20.4 30-Mar-2016
  4. * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. * Released under both BSD license and Lesser GPL library license.
  7. * Whenever there is any discrepancy between the two licenses,
  8. * the BSD license will take precedence.
  9. *
  10. * Set tabs to 4 for best viewing.
  11. *
  12. * The following code is adapted from the PEAR DB error handling code.
  13. * Portions (c)1997-2002 The PHP Group.
  14. */
  15. 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);
  43. define("DB_ERROR_DEADLOCK", -27);
  44. define("DB_ERROR_STATEMENT_TIMEOUT", -28);
  45. define("DB_ERROR_SERIALIZATION_FAILURE", -29);
  46. }
  47. function adodb_errormsg($value)
  48. {
  49. global $ADODB_LANG,$ADODB_LANG_ARRAY;
  50. if (empty($ADODB_LANG)) $ADODB_LANG = 'en';
  51. if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ;
  52. else {
  53. include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php");
  54. }
  55. return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR];
  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': $map = adodb_error_mysql(); break;
  63. case 'oracle':
  64. case 'oci8': $map = adodb_error_oci8(); break;
  65. case 'ibase': $map = adodb_error_ibase(); break;
  66. case 'odbc': $map = adodb_error_odbc(); break;
  67. case 'mssql':
  68. case 'sybase': $map = adodb_error_mssql(); break;
  69. case 'informix': $map = adodb_error_ifx(); break;
  70. case 'postgres': return adodb_error_pg($errno); break;
  71. case 'sqlite': return $map = adodb_error_sqlite(); break;
  72. default:
  73. return DB_ERROR;
  74. }
  75. //print_r($map);
  76. //var_dump($errno);
  77. if (isset($map[$errno])) return $map[$errno];
  78. return DB_ERROR;
  79. }
  80. //**************************************************************************************
  81. function adodb_error_pg($errormsg)
  82. {
  83. if (is_numeric($errormsg)) return (integer) $errormsg;
  84. // Postgres has no lock-wait timeout. The best we could do would be to set a statement timeout.
  85. static $error_regexps = array(
  86. '(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$' => DB_ERROR_NOSUCHTABLE,
  87. 'Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint' => DB_ERROR_ALREADY_EXISTS,
  88. 'database ".+" does not exist$' => DB_ERROR_NOSUCHDB,
  89. '(divide|division) by zero$' => DB_ERROR_DIVZERO,
  90. 'pg_atoi: error in .*: can\'t parse ' => DB_ERROR_INVALID_NUMBER,
  91. 'ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']' => DB_ERROR_NOSUCHFIELD,
  92. '(parser: parse|syntax) error at or near \"' => DB_ERROR_SYNTAX,
  93. 'referential integrity violation' => DB_ERROR_CONSTRAINT,
  94. 'deadlock detected$' => DB_ERROR_DEADLOCK,
  95. 'canceling statement due to statement timeout$' => DB_ERROR_STATEMENT_TIMEOUT,
  96. 'could not serialize access due to' => DB_ERROR_SERIALIZATION_FAILURE
  97. );
  98. reset($error_regexps);
  99. while (list($regexp,$code) = each($error_regexps)) {
  100. if (preg_match("/$regexp/mi", $errormsg)) {
  101. return $code;
  102. }
  103. }
  104. // Fall back to DB_ERROR if there was no mapping.
  105. return DB_ERROR;
  106. }
  107. function adodb_error_odbc()
  108. {
  109. static $MAP = array(
  110. '01004' => DB_ERROR_TRUNCATED,
  111. '07001' => DB_ERROR_MISMATCH,
  112. '21S01' => DB_ERROR_MISMATCH,
  113. '21S02' => DB_ERROR_MISMATCH,
  114. '22003' => DB_ERROR_INVALID_NUMBER,
  115. '22008' => DB_ERROR_INVALID_DATE,
  116. '22012' => DB_ERROR_DIVZERO,
  117. '23000' => DB_ERROR_CONSTRAINT,
  118. '24000' => DB_ERROR_INVALID,
  119. '34000' => DB_ERROR_INVALID,
  120. '37000' => DB_ERROR_SYNTAX,
  121. '42000' => DB_ERROR_SYNTAX,
  122. 'IM001' => DB_ERROR_UNSUPPORTED,
  123. 'S0000' => DB_ERROR_NOSUCHTABLE,
  124. 'S0001' => DB_ERROR_NOT_FOUND,
  125. 'S0002' => DB_ERROR_NOSUCHTABLE,
  126. 'S0011' => DB_ERROR_ALREADY_EXISTS,
  127. 'S0012' => DB_ERROR_NOT_FOUND,
  128. 'S0021' => DB_ERROR_ALREADY_EXISTS,
  129. 'S0022' => DB_ERROR_NOT_FOUND,
  130. 'S1000' => DB_ERROR_NOSUCHTABLE,
  131. 'S1009' => DB_ERROR_INVALID,
  132. 'S1090' => DB_ERROR_INVALID,
  133. 'S1C00' => DB_ERROR_NOT_CAPABLE
  134. );
  135. return $MAP;
  136. }
  137. function adodb_error_ibase()
  138. {
  139. static $MAP = array(
  140. -104 => DB_ERROR_SYNTAX,
  141. -150 => DB_ERROR_ACCESS_VIOLATION,
  142. -151 => DB_ERROR_ACCESS_VIOLATION,
  143. -155 => DB_ERROR_NOSUCHTABLE,
  144. -157 => DB_ERROR_NOSUCHFIELD,
  145. -158 => DB_ERROR_VALUE_COUNT_ON_ROW,
  146. -170 => DB_ERROR_MISMATCH,
  147. -171 => DB_ERROR_MISMATCH,
  148. -172 => DB_ERROR_INVALID,
  149. -204 => DB_ERROR_INVALID,
  150. -205 => DB_ERROR_NOSUCHFIELD,
  151. -206 => DB_ERROR_NOSUCHFIELD,
  152. -208 => DB_ERROR_INVALID,
  153. -219 => DB_ERROR_NOSUCHTABLE,
  154. -297 => DB_ERROR_CONSTRAINT,
  155. -530 => DB_ERROR_CONSTRAINT,
  156. -803 => DB_ERROR_CONSTRAINT,
  157. -551 => DB_ERROR_ACCESS_VIOLATION,
  158. -552 => DB_ERROR_ACCESS_VIOLATION,
  159. -922 => DB_ERROR_NOSUCHDB,
  160. -923 => DB_ERROR_CONNECT_FAILED,
  161. -924 => DB_ERROR_CONNECT_FAILED
  162. );
  163. return $MAP;
  164. }
  165. function adodb_error_ifx()
  166. {
  167. static $MAP = array(
  168. '-201' => DB_ERROR_SYNTAX,
  169. '-206' => DB_ERROR_NOSUCHTABLE,
  170. '-217' => DB_ERROR_NOSUCHFIELD,
  171. '-329' => DB_ERROR_NODBSELECTED,
  172. '-1204' => DB_ERROR_INVALID_DATE,
  173. '-1205' => DB_ERROR_INVALID_DATE,
  174. '-1206' => DB_ERROR_INVALID_DATE,
  175. '-1209' => DB_ERROR_INVALID_DATE,
  176. '-1210' => DB_ERROR_INVALID_DATE,
  177. '-1212' => DB_ERROR_INVALID_DATE
  178. );
  179. return $MAP;
  180. }
  181. function adodb_error_oci8()
  182. {
  183. static $MAP = array(
  184. 1 => DB_ERROR_ALREADY_EXISTS,
  185. 900 => DB_ERROR_SYNTAX,
  186. 904 => DB_ERROR_NOSUCHFIELD,
  187. 923 => DB_ERROR_SYNTAX,
  188. 942 => DB_ERROR_NOSUCHTABLE,
  189. 955 => DB_ERROR_ALREADY_EXISTS,
  190. 1476 => DB_ERROR_DIVZERO,
  191. 1722 => DB_ERROR_INVALID_NUMBER,
  192. 2289 => DB_ERROR_NOSUCHTABLE,
  193. 2291 => DB_ERROR_CONSTRAINT,
  194. 2449 => DB_ERROR_CONSTRAINT
  195. );
  196. return $MAP;
  197. }
  198. function adodb_error_mssql()
  199. {
  200. static $MAP = array(
  201. 208 => DB_ERROR_NOSUCHTABLE,
  202. 2601 => DB_ERROR_ALREADY_EXISTS
  203. );
  204. return $MAP;
  205. }
  206. function adodb_error_sqlite()
  207. {
  208. static $MAP = array(
  209. 1 => DB_ERROR_SYNTAX
  210. );
  211. return $MAP;
  212. }
  213. function adodb_error_mysql()
  214. {
  215. static $MAP = array(
  216. 1004 => DB_ERROR_CANNOT_CREATE,
  217. 1005 => DB_ERROR_CANNOT_CREATE,
  218. 1006 => DB_ERROR_CANNOT_CREATE,
  219. 1007 => DB_ERROR_ALREADY_EXISTS,
  220. 1008 => DB_ERROR_CANNOT_DROP,
  221. 1045 => DB_ERROR_ACCESS_VIOLATION,
  222. 1046 => DB_ERROR_NODBSELECTED,
  223. 1049 => DB_ERROR_NOSUCHDB,
  224. 1050 => DB_ERROR_ALREADY_EXISTS,
  225. 1051 => DB_ERROR_NOSUCHTABLE,
  226. 1054 => DB_ERROR_NOSUCHFIELD,
  227. 1062 => DB_ERROR_ALREADY_EXISTS,
  228. 1064 => DB_ERROR_SYNTAX,
  229. 1100 => DB_ERROR_NOT_LOCKED,
  230. 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
  231. 1146 => DB_ERROR_NOSUCHTABLE,
  232. 1048 => DB_ERROR_CONSTRAINT,
  233. 2002 => DB_ERROR_CONNECT_FAILED,
  234. 2005 => DB_ERROR_CONNECT_FAILED
  235. );
  236. return $MAP;
  237. }