You are here

function DB_pgsql::errorCode in Flickr API 5

Determines PEAR::DB error code from the database's text error message.

Parameters

string $errormsg error message returned from the database:

Return value

integer an error number from a DB error constant

Overrides DB_common::errorCode

1 call to DB_pgsql::errorCode()
DB_pgsql::pgsqlRaiseError in phpFlickr/PEAR/DB/pgsql.php
Produces a DB_Error object regarding the current problem

File

phpFlickr/PEAR/DB/pgsql.php, line 812

Class

DB_pgsql
The methods PEAR DB uses to interact with PHP's pgsql extension for interacting with PostgreSQL databases

Code

function errorCode($errormsg) {
  static $error_regexps;
  if (!isset($error_regexps)) {
    $error_regexps = array(
      '/(relation|sequence|table).*does not exist|class .* not found/i' => DB_ERROR_NOSUCHTABLE,
      '/index .* does not exist/' => DB_ERROR_NOT_FOUND,
      '/column .* does not exist/i' => DB_ERROR_NOSUCHFIELD,
      '/relation .* already exists/i' => DB_ERROR_ALREADY_EXISTS,
      '/(divide|division) by zero$/i' => DB_ERROR_DIVZERO,
      '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
      '/invalid input syntax for( type)? (integer|numeric)/i' => DB_ERROR_INVALID_NUMBER,
      '/value .* is out of range for type \\w*int/i' => DB_ERROR_INVALID_NUMBER,
      '/integer out of range/i' => DB_ERROR_INVALID_NUMBER,
      '/value too long for type character/i' => DB_ERROR_INVALID,
      '/attribute .* not found|relation .* does not have attribute/i' => DB_ERROR_NOSUCHFIELD,
      '/column .* specified in USING clause does not exist in (left|right) table/i' => DB_ERROR_NOSUCHFIELD,
      '/parser: parse error at or near/i' => DB_ERROR_SYNTAX,
      '/syntax error at/' => DB_ERROR_SYNTAX,
      '/column reference .* is ambiguous/i' => DB_ERROR_SYNTAX,
      '/permission denied/' => DB_ERROR_ACCESS_VIOLATION,
      '/violates not-null constraint/' => DB_ERROR_CONSTRAINT_NOT_NULL,
      '/violates [\\w ]+ constraint/' => DB_ERROR_CONSTRAINT,
      '/referential integrity violation/' => DB_ERROR_CONSTRAINT,
      '/more expressions than target columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
    );
  }
  foreach ($error_regexps as $regexp => $code) {
    if (preg_match($regexp, $errormsg)) {
      return $code;
    }
  }

  // Fall back to DB_ERROR if there was no mapping.
  return DB_ERROR;
}