cvs: php4 /pear/DB odbc.php
| From: | Thomas V.V.Cox | Date: | Tue, 07 Aug 2001 18:14:37 +0000 |
| Subject: | cvs: php4 /pear/DB odbc.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-434@lists.php.net to get a copy of this message | ||
cox Tue Aug 7 14:14:37 2001 EDT
Modified files:
/php4/pear/DB odbc.php
Log:
better error reporting, E_ALL conformance and other bugfixes/style
Index: php4/pear/DB/odbc.php
diff -u php4/pear/DB/odbc.php:1.34 php4/pear/DB/odbc.php:1.35
--- php4/pear/DB/odbc.php:1.34 Thu Aug 2 14:13:59 2001
+++ php4/pear/DB/odbc.php Tue Aug 7 14:14:37 2001
@@ -17,17 +17,20 @@
// | |
// +----------------------------------------------------------------------+
//
+// $Id: odbc.php,v 1.35 2001/08/07 18:14:37 cox Exp $
+//
// Database independent query interface definition for PHP's ODBC
// extension.
//
//
// XXX legend:
+// More info on ODBC errors could be found here:
+// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/trblsql/tr_err_odbc_5stz.asp
//
// XXX ERRORMSG: The error message from the odbc function should
// be registered here.
//
-//
require_once 'DB/common.php';
@@ -37,6 +40,7 @@
var $connection;
var $phptype, $dbsyntax;
+ var $row = array();
// }}}
// {{{ constructor
@@ -52,28 +56,28 @@
'transactions' => false
);
$this->errorcode_map = array(
- "01004" => DB_ERROR_TRUNCATED,
- "07001" => DB_ERROR_MISMATCH,
- "21S01" => DB_ERROR_MISMATCH,
- "21S02" => DB_ERROR_MISMATCH,
- "22003" => DB_ERROR_INVALID_NUMBER,
- "22008" => DB_ERROR_INVALID_DATE,
- "22012" => DB_ERROR_DIVZERO,
- "23000" => DB_ERROR_CONSTRAINT,
- "24000" => DB_ERROR_INVALID,
- "34000" => DB_ERROR_INVALID,
- "37000" => DB_ERROR_SYNTAX,
- "42000" => DB_ERROR_SYNTAX,
- "IM001" => DB_ERROR_UNSUPPORTED,
- "S0001" => DB_ERROR_NOT_FOUND,
- "S0002" => DB_ERROR_NOT_FOUND,
- "S0011" => DB_ERROR_ALREADY_EXISTS,
- "S0012" => DB_ERROR_NOT_FOUND,
- "S0021" => DB_ERROR_ALREADY_EXISTS,
- "S0022" => DB_ERROR_NOT_FOUND,
- "S1009" => DB_ERROR_INVALID,
- "S1090" => DB_ERROR_INVALID,
- "S1C00" => DB_ERROR_NOT_CAPABLE
+ '01004' => DB_ERROR_TRUNCATED,
+ '07001' => DB_ERROR_MISMATCH,
+ '21S01' => DB_ERROR_MISMATCH,
+ '21S02' => DB_ERROR_MISMATCH,
+ '22003' => DB_ERROR_INVALID_NUMBER,
+ '22008' => DB_ERROR_INVALID_DATE,
+ '22012' => DB_ERROR_DIVZERO,
+ '23000' => DB_ERROR_CONSTRAINT,
+ '24000' => DB_ERROR_INVALID,
+ '34000' => DB_ERROR_INVALID,
+ '37000' => DB_ERROR_SYNTAX,
+ '42000' => DB_ERROR_SYNTAX,
+ 'IM001' => DB_ERROR_UNSUPPORTED,
+ 'S0001' => DB_ERROR_NOT_FOUND,
+ 'S0002' => DB_ERROR_NOT_FOUND,
+ 'S0011' => DB_ERROR_ALREADY_EXISTS,
+ 'S0012' => DB_ERROR_NOT_FOUND,
+ 'S0021' => DB_ERROR_ALREADY_EXISTS,
+ 'S0022' => DB_ERROR_NOT_FOUND,
+ 'S1009' => DB_ERROR_INVALID,
+ 'S1090' => DB_ERROR_INVALID,
+ 'S1C00' => DB_ERROR_NOT_CAPABLE
);
}
@@ -110,7 +114,7 @@
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
$user = $dsninfo['username'];
$pw = $dsninfo['password'];
- DB::assertExtension("odbc");
+ DB::assertExtension('odbc');
if ($this->provides('pconnect')) {
$connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
} else {
@@ -118,7 +122,8 @@
}
$conn = @$connect_function($dbhost, $user, $pw);
if (!is_resource($conn)) {
- return $this->raiseError(DB_ERROR_CONNECT_FAILED);
+ return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+ null, $this->errorNative());
}
$this->connection = $conn;
return DB_OK;
@@ -153,11 +158,15 @@
$query = $this->modifyQuery($query);
$result = odbc_exec($this->connection, $query);
if (!$result) {
- return $this->raiseError(); // XXX ERRORMSG
+ return $this->odbcRaiseError(); // XXX ERRORMSG
}
// Determine which queries that should return data, and which
// should return an error code only.
- return DB::isManip($query) ? DB_OK : $result;
+ if (DB::isManip($query)) {
+ return DB_OK;
+ }
+ $this->row[$result] = 0;
+ return $result;
}
// }}}
@@ -183,9 +192,11 @@
$rownum = ($rownum !== null) ? $rownum : $this->row[$result];
$cols = odbc_fetch_into($result, $rownum, &$row);
if (!$cols) {
+ /* XXX FIXME: doesn't work with unixODBC and easysoft
+ (get corrupted $errno values)
if ($errno = odbc_error($this->connection)) {
- return $this->raiseError($errno);
- }
+ return $this->RaiseError($errno);
+ }*/
return null;
}
if ($fetchmode !== DB_FETCHMODE_ORDERED) {
@@ -215,7 +226,7 @@
{
$cols = @odbc_num_fields($result);
if (!$cols) {
- return $this->raiseError($php_errormsg);
+ return $this->odbcRaiseError();
}
return $cols;
}
@@ -249,11 +260,10 @@
function errorNative()
{
- if (is_resource($this->connection)) {
- return odbc_error($this->connection);
- } else {
- return odbc_error();
+ if (!isset($this->connection) || !is_resource($this->connection)) {
+ return odbc_error() . ' ' . odbc_errormsg();
}
+ return odbc_error($this->connection) . ' ' .
odbc_errormsg($this->connection);
}
// }}}
@@ -262,7 +272,7 @@
function autoCommit($onoff = false)
{
if (!@odbc_autocommit($this->connection, $onoff)) {
- return $this->raiseError($php_errormsg);
+ return $this->odbcRaiseError();
}
return DB_OK;
}
@@ -273,7 +283,7 @@
function commit()
{
if (!@odbc_commit($this->connection)) {
- return $this->raiseError($php_errormsg);
+ return $this->odbcRaiseError();
}
return DB_OK;
}
@@ -283,8 +293,8 @@
function rollback()
{
- if (!@odbc_commit($this->connection)) {
- return $this->raiseError($php_errormsg);
+ if (!@odbc_rollback($this->connection)) {
+ return $this->odbcRaiseError();
}
return DB_OK;
}
@@ -294,17 +304,11 @@
function odbcRaiseError($errno = null)
{
- if (is_resource($this->connection)) {
- $message = odbc_errormsg($this->connection);
- $code = odbc_error($this->connection);
- } else {
- $message = odbc_errormsg();
- $code = odbc_error();
- }
if ($errno === null) {
- return $this->raiseError($this->errorCode($code));
+ $errno = $this->errorCode(odbc_error($this->connection));
}
- return $this->raiseError($this->errorCode($errno));
+ return $this->raiseError($errno, null, null, null,
+ $this->errorNative());
}
// }}}
@@ -314,4 +318,4 @@
// tab-width: 4
// c-basic-offset: 4
// End:
-?>
+?>
\ No newline at end of file