Update of /cvsroot/phpmp/phpMP/core/dba
In directory sc8-pr-cvs1:/tmp/cvs-serv12737/core/dba
Modified Files:
postgresql.php
Log Message:
I remember being called an idiot and non developer but I think this might work slightly better than @mysql_errno() ... IMHO of course!
Index: postgresql.php
===================================================================
RCS file: /cvsroot/phpmp/phpMP/core/dba/postgresql.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** postgresql.php 25 Sep 2003 03:43:55 -0000 1.3
--- postgresql.php 27 Sep 2003 03:42:22 -0000 1.4
***************
*** 52,55 ****
--- 52,120 ----
}
}
+
+ // Attempt to get PostgreSQL Error code
+ // Blame me (R45) if this fails
+ function sql_errno($connection = NULL)
+ {
+ if( is_null($connection) )
+ {
+ $connection = $this->db_connection_id;
+ }
+
+ // With postgres, there is no unified error number system. We will need
+ // to get the number based on the message
+ // We'll get the last message here, feel free to adjust this Booster
+ // if you want it as an object variable created elsewhere
+ $last_error = @pg_errormessage($connection);
+
+ // So we don't have to set the error messages again
+ static $pgsql_errors;
+
+ // If we didn't do this before
+ if( empty($pgsql_errors) )
+ {
+ // This is an array of error messages that PostgreSQL has error numbers for
+ $pgsql_errors = Array(
+ '/Out of memory in line [0-9]+/' => -12,
+ '/Data not found line [0-9]+/' => -100,
+ '/Unsupported type .* on line ([0-9])+/' => -200,
+ '/Too many arguments line [0-9]+/' => -201,
+ '/Too few arguments line [0-9]+/' => -202,
+ '/Too many matches line [0-9]+/' => -203,
+ '/Not correctly formatted int type: .* line [0-9]+/' => -204,
+ '/Not correctly formatted unsigned type: .* line [0-9]+/' => -205,
+ '/Not correctly formatted floating-point type: .* line [0-9]+/' => -206,
+ '/Unable to convert .* to bool on line [0-9]+/' => -207,
+ '/Empty query line [0-9]+/' => -208,
+ '/NULL value without indicator in line [0-9]+/' => -209,
+ '/Variable is not an array in line [0-9]+/' => -210,
+ '/Data read from backend is not an array in line [0-9]+/' => -211,
+ '/No such connection .* in line [0-9]+/' => -220,
+ '/Not connected in line [0-9]+/' => -221,
+ '/Invalid statement name .* in line [0-9]+/' => -230,
+ '/Descriptor .* not found in line [0-9]+/' => -240,
+ '/Descriptor index out of range in line [0-9]+/' => -241,
+ '/Descriptor .* not found in line [0-9]+/' => -242,
+ '/Variable is not a numeric type in line [0-9]+/' => -243,
+ '/Variable is not a character type in line [0-9]+/' => -244,
+ '/Postgres error: .* line [0-9]+/' => -400,
+ '/Error in transaction processing line [0-9]+/' => -401,
+ '/Could not connect to database .* in line [0-9]+/' => -402,
+ );
+ }
+
+ // Lets juggle the error messages
+ foreach ($pgsql_errors as $error => $number)
+ {
+ if( preg_match($error, $last_error))
+ {
+ // return appropriate number for this error
+ return $number;
+ }
+ }
+
+ // No error number exists, so 0 will do
+ return 0;
+ }
}
?>
|