ssb Thu Mar 22 17:15:10 2001 EDT
Modified files:
/php4/pear DB.php PEAR.php.in
/php4/pear/DB STATUS common.php oci8.php
/php4/pear/DB/tests errors.inc fetchrow.inc numrows.inc
sequences.inc
/php4/pear/DB/tests/ibase mktable.inc
/php4/pear/DB/tests/mysql mktable.inc
/php4/pear/DB/tests/oci8 002.phpt 007.phpt 009.phpt 010.phpt
connect.inc mktable.inc skipif.inc
/php4/pear/DB/tests/odbc mktable.inc
/php4/pear/DB/tests/pgsql mktable.inc
Log:
* fixed Oracle tests, fixed some bugs in DB_oci8, all tests but
errorNative() pass now (but that may be a bug in the test :-)
* implemented numRows() emulation in DB_oci8 that is available
in "optimize portability" mode only
Index: php4/pear/DB.php
diff -u php4/pear/DB.php:1.51 php4/pear/DB.php:1.52
--- php4/pear/DB.php:1.51 Tue Mar 20 20:15:40 2001
+++ php4/pear/DB.php Thu Mar 22 17:15:05 2001
@@ -17,7 +17,7 @@
// | Tomas V.V.Cox <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.51 2001/03/21 04:15:40 jon Exp $
+// $Id: DB.php,v 1.52 2001/03/23 01:15:05 ssb Exp $
//
// Database independent query interface.
//
@@ -56,6 +56,7 @@
define("DB_ERROR_NOT_LOCKED", -21);
define("DB_ERROR_VALUE_COUNT_ON_ROW", -22);
define("DB_ERROR_INVALID_DSN", -23);
+define("DB_ERROR_CONNECT_FAILED", -24);
/*
* Warnings are not detected as errors by DB::isError(), and are not
@@ -326,6 +327,8 @@
DB_ERROR_SYNTAX => 'syntax error',
DB_ERROR_UNSUPPORTED => 'not supported',
DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
+ DB_ERROR_INVALID_DSN => "invalid DSN",
+ DB_ERROR_CONNECT_FAILED => "connect failed",
DB_OK => 'no error',
DB_WARNING => 'unknown warning',
DB_WARNING_READ_ONLY => 'read only'
Index: php4/pear/PEAR.php.in
diff -u php4/pear/PEAR.php.in:1.15 php4/pear/PEAR.php.in:1.16
--- php4/pear/PEAR.php.in:1.15 Sat Mar 10 01:59:15 2001
+++ php4/pear/PEAR.php.in Thu Mar 22 17:15:05 2001
@@ -17,7 +17,7 @@
// | Stig Bakken <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: PEAR.php.in,v 1.15 2001/03/10 09:59:15 ssb Exp $
+// $Id: PEAR.php.in,v 1.16 2001/03/23 01:15:05 ssb Exp $
//
define('PEAR_ERROR_RETURN', 1);
@@ -513,12 +513,12 @@
$modes[] = "return";
}
return sprintf('[%s: message="%s" code=%d mode=%s level=%s prefix="%s" '.
- 'prepend="%s" append="%s" debug="%s"]',
+ 'prepend="%s" append="%s" info="%s"]',
get_class($this), $this->message, $this->code,
implode("|", $modes), $levels[$this->level],
$this->error_message_prefix,
$this->error_prepend, $this->error_append,
- $this->debuginfo);
+ $this->userinfo);
}
// }}}
Index: php4/pear/DB/STATUS
diff -u php4/pear/DB/STATUS:1.14 php4/pear/DB/STATUS:1.15
--- php4/pear/DB/STATUS:1.14 Sun Jan 14 17:19:28 2001
+++ php4/pear/DB/STATUS Thu Mar 22 17:15:06 2001
@@ -10,14 +10,14 @@
"-" - no implementation of this feature
FEATURE ibase msql mssql mysql oci8 odbc pgsql sybase
-simpleQuery x x x T x x T x
-numCols x x x T x x T x
-numRows n x x T n n T n
+simpleQuery x x x T T x T x
+numCols x x x T T x T x
+numRows n x x T E n T n
errorNative n n n T x x T n
-prepare/execute x e e E x e E e
-sequences n n n E n n T n
-affectedRows n n n T x n T n
-fetch modes x x x T x x T x
+prepare/execute x e e E T e E e
+sequences n n n E T n T n
+affectedRows n n n T T n T n
+fetch modes x x x T T x T x
transactions x n n n x x x n
auto-commit x n n n x x x n
-error mapping - - - T - x E -
+error mapping - - - T T x E -
Index: php4/pear/DB/common.php
diff -u php4/pear/DB/common.php:1.39 php4/pear/DB/common.php:1.40
--- php4/pear/DB/common.php:1.39 Mon Mar 12 01:33:21 2001
+++ php4/pear/DB/common.php Thu Mar 22 17:15:06 2001
@@ -161,10 +161,10 @@
*
*/
- function &raiseError($code = DB_ERROR, $mode = false, $level = false,
- $debuginfo = false, $nativecode = false)
+ function &raiseError($code = DB_ERROR, $mode = null, $level = null,
+ $debuginfo = null, $nativecode = null)
{
- if (!$mode) {
+ if ($mode === null) {
$mode = $this->error_mode;
}
@@ -175,12 +175,12 @@
$level = $this->error_callback;
}
} else {
- if (!$level) {
+ if ($level === null) {
$level = $this->error_level;
}
}
- if (!$debuginfo) {
+ if ($debuginfo === null) {
$debuginfo = $this->last_query;
}
Index: php4/pear/DB/oci8.php
diff -u php4/pear/DB/oci8.php:1.20 php4/pear/DB/oci8.php:1.21
--- php4/pear/DB/oci8.php:1.20 Mon Mar 12 04:50:44 2001
+++ php4/pear/DB/oci8.php Thu Mar 22 17:15:06 2001
@@ -34,122 +34,132 @@
{
// {{{ properties
- var $connection;
- var $phptype, $dbsyntax;
- var $manip_query = array();
- var $prepare_types = array();
- var $autoCommit = 1;
- var $last_stmt = false;
+ var $connection;
+ var $phptype, $dbsyntax;
+ var $manip_query = array();
+ var $prepare_types = array();
+ var $autoCommit = 1;
+ var $last_stmt = false;
// }}}
// {{{ constructor
- function DB_oci8()
+ function DB_oci8()
{
$this->DB_common();
- $this->phptype = 'oci8';
- $this->dbsyntax = 'oci8';
- $this->features = array(
- 'prepare' => false,
- 'pconnect' => true,
- 'transactions' => true
- );
- $this->errorcode_map = array();
- }
+ $this->phptype = 'oci8';
+ $this->dbsyntax = 'oci8';
+ $this->features = array(
+ 'prepare' => false,
+ 'pconnect' => true,
+ 'transactions' => true
+ );
+ $this->errorcode_map = array(
+ 900 => DB_ERROR_SYNTAX,
+ 904 => DB_ERROR_NOSUCHFIELD,
+ 923 => DB_ERROR_SYNTAX,
+ 942 => DB_ERROR_NOSUCHTABLE,
+ 955 => DB_ERROR_ALREADY_EXISTS,
+ 1476 => DB_ERROR_DIVZERO,
+ 1722 => DB_ERROR_INVALID_NUMBER,
+ 2289 => DB_ERROR_NOSUCHTABLE,
+ 2291 => DB_ERROR_CONSTRAINT,
+ 2449 => DB_ERROR_CONSTRAINT,
+ );
+ }
// }}}
// {{{ connect()
- /**
- * Connect to a database and log in as the specified user.
- *
- * @param $dsn the data source name (see DB::parseDSN for syntax)
- * @param $persistent (optional) whether the connection should
- * be persistent
- *
- * @return int DB_OK on success, a DB error code on failure
- */
- function connect($dsn, $persistent = false)
- {
- if (is_array($dsn)) {
- $dsninfo = &$dsn;
- } else {
- $dsninfo = DB::parseDSN($dsn);
- }
- if (!$dsninfo || !$dsninfo['phptype']) {
- return $this->raiseError();
- }
+ /**
+ * Connect to a database and log in as the specified user.
+ *
+ * @param $dsn the data source name (see DB::parseDSN for syntax)
+ * @param $persistent (optional) whether the connection should
+ * be persistent
+ *
+ * @return int DB_OK on success, a DB error code on failure
+ */
+ function connect($dsn, $persistent = false)
+ {
+ if (is_array($dsn)) {
+ $dsninfo = &$dsn;
+ } else {
+ $dsninfo = DB::parseDSN($dsn);
+ }
+ if (!$dsninfo || !$dsninfo['phptype']) {
+ return $this->raiseError(DB_ERROR_INVALID_DSN);
+ }
$this->dsn = $dsninfo;
- $user = $dsninfo['username'];
- $pw = $dsninfo['password'];
- $hostspec = $dsninfo['hostspec'];
+ $user = $dsninfo['username'];
+ $pw = $dsninfo['password'];
+ $hostspec = $dsninfo['hostspec'];
DB::assertExtension("oci8");
- $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
- if ($hostspec) {
- $conn = @$connect_function($user,$pw,$hostspec);
- } elseif ($user || $pw) {
- $conn = @$connect_function($user,$pw);
- } else {
- $conn = false;
- }
- if ($conn == false) {
- return $this->raiseError();
- }
- $this->connection = $conn;
- return DB_OK;
- }
+ $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
+ if ($hostspec) {
+ $conn = @$connect_function($user,$pw,$hostspec);
+ } elseif ($user || $pw) {
+ $conn = @$connect_function($user,$pw);
+ } else {
+ $conn = false;
+ }
+ if ($conn == false) {
+ return $this->raiseError(DB_ERROR_CONNECT_FAILED);
+ }
+ $this->connection = $conn;
+ return DB_OK;
+ }
// }}}
// {{{ disconnect()
- /**
- * Log out and disconnect from the database.
- *
- * @return bool TRUE on success, FALSE if not connected.
- */
- function disconnect()
+ /**
+ * Log out and disconnect from the database.
+ *
+ * @return bool TRUE on success, FALSE if not connected.
+ */
+ function disconnect()
{
- return @OCILogOff($this->connection);
- }
+ return @OCILogOff($this->connection);
+ }
// }}}
// {{{ simpleQuery()
- /**
- * Send a query to oracle and return the results as an oci8 resource
- * identifier.
- *
- * @param $query the SQL query
- *
- * @return int returns a valid oci8 result for successful SELECT
- * queries, DB_OK for other successful queries. A DB error code
- * is returned on failure.
- */
- function simpleQuery($query)
+ /**
+ * Send a query to oracle and return the results as an oci8 resource
+ * identifier.
+ *
+ * @param $query the SQL query
+ *
+ * @return int returns a valid oci8 result for successful SELECT
+ * queries, DB_OK for other successful queries. A DB error code
+ * is returned on failure.
+ */
+ function simpleQuery($query)
{
- $this->last_query = $query;
+ $this->last_query = $query;
$query = $this->modifyQuery($query);
- $result = @OCIParse($this->connection, $query);
- if (!$result) {
- return $this->raiseError();
- }
- if ($this->autoCommit) {
- $success = @OCIExecute($result,OCI_COMMIT_ON_SUCCESS);
- }
- else {
- $success = @OCIExecute($result,OCI_DEFAULT);
- }
- if (!$success) {
- return $this->raiseError();
- }
- $this->last_stmt=$result;
- // Determine which queries that should return data, and which
- // should return an error code only.
+ $result = @OCIParse($this->connection, $query);
+ if (!$result) {
+ return $this->oci8RaiseError();
+ }
+ if ($this->autoCommit) {
+ $success = @OCIExecute($result,OCI_COMMIT_ON_SUCCESS);
+ } else {
+ $success = @OCIExecute($result,OCI_DEFAULT);
+ }
+ if (!$success) {
+ return $this->oci8RaiseError($result);
+ }
+ $this->last_stmt=$result;
+ // Determine which queries that should return data, and which
+ // should return an error code only.
return DB::isManip($query) ? DB_OK : $result;
- }
+ }
- // }}}
+ // }}}
// {{{ fetchRow()
/**
@@ -163,280 +173,303 @@
*/
function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT)
{
- if ($fetchmode == DB_FETCHMODE_DEFAULT) {
- $fetchmode = $this->fetchmode;
- }
- if ($fetchmode & DB_FETCHMODE_ASSOC) {
- $moredata = @OCIFetchInto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS +
OCI_RETURN_LOBS);
- } else {
- $moredata = @OCIFetchInto($result, $row, OCI_RETURN_NULLS +
OCI_RETURN_LOBS);
- }
- if (!$row) {
- return $this->raiseError();
- }
- if ($moredata == NULL) {
- return NULL;
- }
- return $row;
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
+ $moredata = @OCIFetchInto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS +
+OCI_RETURN_LOBS);
+ } else {
+ $moredata = @OCIFetchInto($result, $row, OCI_RETURN_NULLS +
+OCI_RETURN_LOBS);
+ }
+ if (!$moredata) {
+ return NULL;
+ }
+ return $row;
}
// }}}
// {{{ fetchInto()
- /**
- * Fetch a row and insert the data into an existing array.
- *
- * @param $result oci8 result identifier
- * @param $arr (reference) array where data from the row is stored
- * @param $fetchmode how the array data should be indexed
- *
- * @return int DB_OK on success, a DB error code on failure
- */
- function fetchInto($result, &$arr, $fetchmode = DB_FETCHMODE_DEFAULT)
- {
- if ($fetchmode == DB_FETCHMODE_DEFAULT) {
- $fetchmode = $this->fetchmode;
- }
- if ($fetchmode & DB_FETCHMODE_ASSOC) {
- $moredata =
@OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
- } else {
- $moredata =
@OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
- }
- if (!($arr && $moredata)) {
- return $this->raiseError();
- }
- return DB_OK;
- }
+ /**
+ * Fetch a row and insert the data into an existing array.
+ *
+ * @param $result oci8 result identifier
+ * @param $arr (reference) array where data from the row is stored
+ * @param $fetchmode how the array data should be indexed
+ *
+ * @return int DB_OK on success, a DB error code on failure
+ */
+ function fetchInto($result, &$arr, $fetchmode = DB_FETCHMODE_DEFAULT)
+ {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
+ $moredata =
+@OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
+ } else {
+ $moredata = @OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
+ }
+ if (!($arr && $moredata)) {
+ return $this->oci8RaiseError($result);
+ }
+ return DB_OK;
+ }
- // }}}
+ // }}}
// {{{ freeResult()
- /**
- * Free the internal resources associated with $result.
- *
- * @param $result oci8 result identifier or DB statement identifier
- *
- * @return bool TRUE on success, FALSE if $result is invalid
- */
- function freeResult($result)
- {
- if (is_resource($result)) {
- return @OCIFreeStatement($result);
- }
- if (!isset($this->prepare_tokens[$result])) {
- return false;
- }
- unset($this->prepare_tokens[$result]);
- unset($this->prepare_types[$result]);
- return true;
- }
+ /**
+ * Free the internal resources associated with $result.
+ *
+ * @param $result oci8 result identifier or DB statement identifier
+ *
+ * @return bool TRUE on success, FALSE if $result is invalid
+ */
+ function freeResult($result)
+ {
+ if (is_resource($result)) {
+ return @OCIFreeStatement($result);
+ }
+ if (!isset($this->prepare_tokens[$result])) {
+ return false;
+ }
+ unset($this->prepare_tokens[$result]);
+ unset($this->prepare_types[$result]);
+ unset($this->manip_query[$result]);
+ return true;
+ }
+
+ // }}}
+ // {{{ numRows()
+
+ function numRows($result)
+ {
+ // emulate numRows for Oracle. yuck.
+ if ($this->options['optimize'] == 'portability' &&
+ $result === $this->last_stmt) {
+ $countquery = preg_replace('/^\s*SELECT\s+(.*)\s+FROM\s+/i',
+ 'SELECT COUNT(\1) FROM ',
+ $this->last_query);
+ $save_query = $this->last_query;
+ $save_stmt = $this->last_stmt;
+ $count = $this->query($countquery);
+ if (DB::isError($count) ||
+ DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED)))
+ {
+ $this->last_query = $save_query;
+ $this->last_stmt = $save_stmt;
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+ }
+ return $row[0];
+ }
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+ }
- // }}}
+ // }}}
// {{{ numCols()
- /**
- * Get the number of columns in a result set.
- *
- * @param $result oci8 result identifier
- *
- * @return int the number of columns per row in $result
- */
- function numCols($result)
- {
- $cols = @OCINumCols($result);
- if (!$cols) {
- return $this->raiseError();
- }
- return $cols;
- }
+ /**
+ * Get the number of columns in a result set.
+ *
+ * @param $result oci8 result identifier
+ *
+ * @return int the number of columns per row in $result
+ */
+ function numCols($result)
+ {
+ $cols = @OCINumCols($result);
+ if (!$cols) {
+ return $this->oci8RaiseError($result);
+ }
+ return $cols;
+ }
// }}}
// {{{ errorNative()
- /**
- * Get the native error code of the last error (if any) that occured
- * on the current connection. This does not work, as OCIError does
- * not work unless given a statement. If OCIError does return
- * something, so will this.
- *
- * @return int native oci8 error code
- */
- function errorNative()
- {
- $error = @OCIError($this->connection);
- if (is_array($error)) {
- return $error['code'];
- }
- return false;
- }
+ /**
+ * Get the native error code of the last error (if any) that occured
+ * on the current connection. This does not work, as OCIError does
+ * not work unless given a statement. If OCIError does return
+ * something, so will this.
+ *
+ * @return int native oci8 error code
+ */
+ function errorNative()
+ {
+ if (is_resource($this->last_stmt)) {
+ $error = @OCIError($this->last_stmt);
+ } else {
+ $error = @OCIError($this->connection);
+ }
+ if (is_array($error)) {
+ return $error['code'];
+ }
+ return false;
+ }
// }}}
// {{{ prepare()
- /**
- * Prepares a query for multiple execution with execute(). With
- * oci8, this is emulated.
- * @param $query query to be prepared
- *
- * @return DB statement resource
- */
- function prepare($query)
- {
- $tokens = split('[\&\?]', $query);
- $token = 0;
- $types = array();
- for ($i = 0; $i < strlen($query); $i++) {
- switch ($query[$i]) {
- case '?':
- $types[$token++] = DB_PARAM_SCALAR;
- break;
- case '&':
- $types[$token++] = DB_PARAM_OPAQUE;
- break;
- }
- }
- $binds = sizeof($tokens) - 1;
- for ($i = 0; $i < $binds; $i++) {
- $newquery .= $tokens[$i] . ":bind" . $i;
- }
- $newquery .= $tokens[$i];
- $this->last_query = $query;
+ /**
+ * Prepares a query for multiple execution with execute(). With
+ * oci8, this is emulated.
+ * @param $query query to be prepared
+ *
+ * @return DB statement resource
+ */
+ function prepare($query)
+ {
+ $tokens = split('[\&\?]', $query);
+ $token = 0;
+ $types = array();
+ for ($i = 0; $i < strlen($query); $i++) {
+ switch ($query[$i]) {
+ case '?':
+ $types[$token++] = DB_PARAM_SCALAR;
+ break;
+ case '&':
+ $types[$token++] = DB_PARAM_OPAQUE;
+ break;
+ }
+ }
+ $binds = sizeof($tokens) - 1;
+ for ($i = 0; $i < $binds; $i++) {
+ $newquery .= $tokens[$i] . ":bind" . $i;
+ }
+ $newquery .= $tokens[$i];
+ $this->last_query = $query;
$newquery = $this->modifyQuery($newquery);
- $stmt = @OCIParse($this->connection, $newquery);
- $this->prepare_types[$stmt] = $types;
- $this->manip_query[$stmt] = DB::isManip($query);
- return $stmt;
- }
+ $stmt = @OCIParse($this->connection, $newquery);
+ $this->prepare_types[$stmt] = $types;
+ $this->manip_query[$stmt] = DB::isManip($query);
+ return $stmt;
+ }
// }}}
// {{{ execute()
- /**
- * Executes a DB statement prepared with prepare().
- *
- * @param $stmt a DB statement resource (returned from prepare())
- * @param $data data to be used in execution of the statement
- *
- * @return int returns an oci8 result resource for successful
- * SELECT queries, DB_OK for other successful queries. A DB error
- * code is returned on failure.
- */
- function execute($stmt, $data = false)
- {
- $types=&$this->prepare_types[$stmt];
- if (($size=sizeof($types))!=sizeof($data)) {
- return $this->raiseError();
- }
- for ($i=0;$i<$size;$i++) {
- if (is_array($data)) {
- $pdata[$i]=$data[$i];
- }
- else {
- $pdata[$i]=$data;
- }
- if ($types[$i]==DB_PARAM_OPAQUE) {
- $fp = fopen($pdata[$i], "r");
- $pdata = '';
- if ($fp) {
- while (($buf = fread($fp, 4096)) != false) {
- $pdata[$i] .= $buf;
- }
- }
- }
- if (!@OCIBindByName($stmt,":bind".$i,$pdata[$i],-1)) {
- return $this->raiseError();
- }
- }
- if ($this->autoCommit) {
- $success = @OCIExecute($stmt,OCI_COMMIT_ON_SUCCESS);
- }
- else {
- $success = @OCIExecute($stmt,OCI_DEFAULT);
- }
- if (!$success) {
- return $this->raiseError();
- }
- $this->last_stmt=$stmt;
- if ($this->manip_query[$stmt]) {
- return $DB_OK;
- } else {
- return $stmt;
- }
- }
+ /**
+ * Executes a DB statement prepared with prepare().
+ *
+ * @param $stmt a DB statement resource (returned from prepare())
+ * @param $data data to be used in execution of the statement
+ *
+ * @return int returns an oci8 result resource for successful
+ * SELECT queries, DB_OK for other successful queries. A DB error
+ * code is returned on failure.
+ */
+ function execute($stmt, $data = false)
+ {
+ $types=&$this->prepare_types[$stmt];
+ if (($size = sizeof($types)) != sizeof($data)) {
+ return $this->raiseError(DB_ERROR_MISMATCH);
+ }
+ for ($i = 0; $i < $size; $i++) {
+ if (is_array($data)) {
+ $pdata[$i] = $data[$i];
+ }
+ else {
+ $pdata[$i] = $data;
+ }
+ if ($types[$i] == DB_PARAM_OPAQUE) {
+ $fp = fopen($pdata[$i], "r");
+ $pdata = '';
+ if ($fp) {
+ while (($buf = fread($fp, 4096)) != false) {
+ $pdata[$i] .= $buf;
+ }
+ }
+ }
+ if (!@OCIBindByName($stmt, ":bind" . $i, $pdata[$i], -1)) {
+ return $this->oci8RaiseError($stmt);
+ }
+ }
+ if ($this->autoCommit) {
+ $success = @OCIExecute($stmt, OCI_COMMIT_ON_SUCCESS);
+ }
+ else {
+ $success = @OCIExecute($stmt, OCI_DEFAULT);
+ }
+ if (!$success) {
+ return $this->oci8RaiseError($stmt);
+ }
+ $this->last_stmt = $stmt;
+ if ($this->manip_query[$stmt]) {
+ return $DB_OK;
+ } else {
+ return $stmt;
+ }
+ }
// }}}
// {{{ autoCommit()
- /**
- * Enable/disable automatic commits
- *
- * @param $onoff true/false whether to autocommit
- */
- function autoCommit($onoff = false)
- {
- if (!$onoff) {
- $this->autoCommit = 0;
- }
- else {
- $this->autoCommit = 1;
- }
- return DB_OK;
- }
+ /**
+ * Enable/disable automatic commits
+ *
+ * @param $onoff true/false whether to autocommit
+ */
+ function autoCommit($onoff = false)
+ {
+ $this->autoCommit = (bool)$onoff;;
+ return DB_OK;
+ }
// }}}
// {{{ commit()
- /**
- * Commit transactions on the current connection
- *
- * @return DB_ERROR or DB_OK
- */
- function commit()
- {
- $result = @OCICommit($this->connection);
- if (!$result) {
- return $this->raiseError();
- }
- return DB_OK;
- }
+ /**
+ * Commit transactions on the current connection
+ *
+ * @return DB_ERROR or DB_OK
+ */
+ function commit()
+ {
+ $result = @OCICommit($this->connection);
+ if (!$result) {
+ return $this->oci8RaiseError();
+ }
+ return DB_OK;
+ }
// }}}
// {{{ rollback()
- /**
- * Roll back all uncommitted transactions on the current connection.
- *
- * @return DB_ERROR or DB_OK
- */
- function rollback()
- {
- $result = @OCIRollback($this->connection);
- if (!$result) {
- return $this->raiseError();
- }
- return DB_OK;
- }
+ /**
+ * Roll back all uncommitted transactions on the current connection.
+ *
+ * @return DB_ERROR or DB_OK
+ */
+ function rollback()
+ {
+ $result = @OCIRollback($this->connection);
+ if (!$result) {
+ return $this->oci8RaiseError();
+ }
+ return DB_OK;
+ }
// }}}
// {{{ affectedRows()
- /**
- * Gets the number of rows affected by the last query.
- * if the last query was a select, returns 0.
- *
- * @return number of rows affected by the last query or DB_ERROR
- */
- function affectedRows()
- {
- if ($this->last_stmt === false) {
- return $this->raiseError();
- }
- $result = @OCIRowCount($this->last_stmt);
- if ($result === false) {
- return $this->raiseError();
- }
- return $result;
- }
+ /**
+ * Gets the number of rows affected by the last query.
+ * if the last query was a select, returns 0.
+ *
+ * @return number of rows affected by the last query or DB_ERROR
+ */
+ function affectedRows()
+ {
+ if ($this->last_stmt === false) {
+ return $this->oci8RaiseError();
+ }
+ $result = @OCIRowCount($this->last_stmt);
+ if ($result === false) {
+ return $this->oci8RaiseError($this->last_stmt);
+ }
+ return $result;
+ }
// }}}
// {{{ modifyQuery()
@@ -453,13 +486,88 @@
// }}}
// {{{ quoteString()
+
+ function quoteString($string)
+ {
+ return str_replace("'", "''", $string);
+ }
+
+ // }}}
+ // {{{ nextId()
+
+ /**
+ * Get the next value in a sequence. We emulate sequences
+ * for MySQL. Will create the sequence if it does not exist.
+ *
+ * @access public
+ *
+ * @param $seq_name the name of the sequence
+ *
+ * @param $ondemand whether to create the sequence table on demand
+ * (default is true)
+ *
+ * @return a sequence integer, or a DB error
+ */
+ function nextId($seq_name, $ondemand = true)
+ {
+ $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name);
+ $repeat = 0;
+ do {
+ $result = $this->query("SELECT ${sqn}_seq.nextval FROM dual");
+ if ($ondemand && DB::isError($result) &&
+ $result->getCode() == DB_ERROR_NOSUCHTABLE) {
+ $repeat = 1;
+ $result = $this->createSequence($seq_name);
+ if (DB::isError($result)) {
+ return $result;
+ }
+ } else {
+ $repeat = 0;
+ }
+ } while ($repeat);
+ if (DB::isError($result)) {
+ return $result;
+ }
+ $arr = $result->fetchRow(DB_FETCHMODE_ORDERED);
+ return $arr[0];
+ }
+
+ // }}}
+ // {{{ createSequence()
- function quoteString($string)
+ function createSequence($seq_name)
{
- return str_replace("'", "''", $string);
- }
+ $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name);
+ return $this->query("CREATE SEQUENCE ${sqn}_seq");
+ }
- // }}}
+ // }}}
+ // {{{ dropSequence()
+
+ function dropSequence($seq_name)
+ {
+ $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name);
+ return $this->query("DROP SEQUENCE ${sqn}_seq");
+ }
+
+ // }}}
+ // {{{ oci8RaiseError()
+
+ function oci8RaiseError($errno = null)
+ {
+ if ($errno === null) {
+ $error = @OCIError($this->connection);
+ return $this->raiseError($this->errorCode($error['code']),
+ null, null, null, $error['message']);
+ } elseif (is_resource($errno)) {
+ $error = @OCIError($errno);
+ return $this->raiseError($this->errorCode($error['code']),
+ null, null, null, $error['message']);
+ }
+ return $this->raiseError($this->errorCode($errno));
+ }
+
+ // }}}
}
// Local variables:
Index: php4/pear/DB/tests/errors.inc
diff -u php4/pear/DB/tests/errors.inc:1.1 php4/pear/DB/tests/errors.inc:1.2
--- php4/pear/DB/tests/errors.inc:1.1 Thu Dec 14 18:36:18 2000
+++ php4/pear/DB/tests/errors.inc Thu Mar 22 17:15:06 2001
@@ -2,10 +2,14 @@
function errhandler($obj)
{
- $msg = $obj->getMessage();
- print " $msg";
- if (substr($msg, -1) != "\n") {
- print "\n";
+ if ($obj->getCode() == DB_ERROR) {
+ print " unknown: ".$obj->getUserInfo()."\n";
+ } else {
+ $msg = $obj->getMessage();
+ print " $msg";
+ if (substr($msg, -1) != "\n") {
+ print "\n";
+ }
}
}
@@ -15,7 +19,7 @@
$dbh->query("SELECT * FROM tableThatDoesNotExist");
print "Trying to provoke DB_ERROR_ALREADY_EXISTS\n";
-$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
+$dbh->query($test_mktable_query);
print "Trying to provoke DB_ERROR_NOSUCHTABLE\n";
$dbh->query("DROP TABLE tableThatDoesNotExist");
Index: php4/pear/DB/tests/fetchrow.inc
diff -u php4/pear/DB/tests/fetchrow.inc:1.1 php4/pear/DB/tests/fetchrow.inc:1.2
--- php4/pear/DB/tests/fetchrow.inc:1.1 Sun Feb 18 16:50:30 2001
+++ php4/pear/DB/tests/fetchrow.inc Thu Mar 22 17:15:06 2001
@@ -10,6 +10,10 @@
for ($i = 1; $i <= 5; $i++) {
print "row $i: ";
$row = $sth->fetchRow();
+ if (DB::isError($row)) {
+ print $row->toString() . "\n";
+ continue;
+ }
if (is_array($row)) {
print implode(", ", $row) . "\n";
} else {
Index: php4/pear/DB/tests/numrows.inc
diff -u php4/pear/DB/tests/numrows.inc:1.4 php4/pear/DB/tests/numrows.inc:1.5
--- php4/pear/DB/tests/numrows.inc:1.4 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/numrows.inc Thu Mar 22 17:15:06 2001
@@ -1,11 +1,10 @@
<?php
-function errhandler($obj)
+if (!function_exists("errhandler"))
{
- $msg = $obj->getMessage();
- print "$msg";
- if (substr($msg, -1) != "\n") {
- print "\n";
+ function errhandler($obj)
+ {
+ printf("%s\n", $obj->getMessage());
}
}
@@ -15,17 +14,33 @@
$dbh->setErrorHandling(PEAR_ERROR_DIE);
}
$sth = $dbh->query("SELECT a FROM phptest");
-printf("%d\n", $sth->numRows());
+if (!DB::isError($rows = $sth->numRows())) {
+ print "$rows\n";
+} else {
+ print "\n";
+}
for ($i = 0; $i < 5; $i++) {
$sth = $dbh->query("INSERT INTO phptest (a) VALUES($i)");
$sth = $dbh->query("SELECT a FROM phptest");
- printf("%d\n", $sth->numRows());
+ if (!DB::isError($rows = $sth->numRows())) {
+ print "$rows\n";
+ } else {
+ print "\n";
+ }
}
$dbh->query("DELETE FROM phptest WHERE a < 4");
$sth = $dbh->query("SELECT a FROM phptest");
-printf("%d\n", $sth->numRows());
+if (!DB::isError($rows = $sth->numRows())) {
+ print "$rows\n";
+} else {
+ print "\n";
+}
$sth = $dbh->query("SELECT a FROM phptest where a < 0");
-printf("%d\n", $sth->numRows());
+if (!DB::isError($rows = $sth->numRows())) {
+ print "$rows\n";
+} else {
+ print "\n";
+}
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "errhandler");
$test = $dbh->numRows(false);
Index: php4/pear/DB/tests/sequences.inc
diff -u php4/pear/DB/tests/sequences.inc:1.1 php4/pear/DB/tests/sequences.inc:1.2
--- php4/pear/DB/tests/sequences.inc:1.1 Wed Dec 13 06:41:04 2000
+++ php4/pear/DB/tests/sequences.inc Thu Mar 22 17:15:06 2001
@@ -7,12 +7,12 @@
$a = $dbh->nextId("test");
$b = $dbh->nextId("test");
if (DB::isError($a)) {
- print "a: ".$a->getMessage()."\n";
+ print "a: ".$a->toString()."\n";
} else {
print "a=$a\n";
}
if (DB::isError($b)) {
- print "b: ".$b->getMessage()."\n";
+ print "b: ".$b->toString()."\n";
} else {
print "b=$b\n";
}
Index: php4/pear/DB/tests/ibase/mktable.inc
diff -u php4/pear/DB/tests/ibase/mktable.inc:1.2
php4/pear/DB/tests/ibase/mktable.inc:1.3
--- php4/pear/DB/tests/ibase/mktable.inc:1.2 Sun Feb 18 16:50:30 2001
+++ php4/pear/DB/tests/ibase/mktable.inc Thu Mar 22 17:15:07 2001
@@ -6,7 +6,8 @@
$dbh->query("DROP TABLE phptest");
$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
-$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
+$test_mktable_query = "CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d
+DATE)"
+$dbh->query($test_mktable_query);
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
Index: php4/pear/DB/tests/mysql/mktable.inc
diff -u php4/pear/DB/tests/mysql/mktable.inc:1.3
php4/pear/DB/tests/mysql/mktable.inc:1.4
--- php4/pear/DB/tests/mysql/mktable.inc:1.3 Sun Feb 18 16:50:30 2001
+++ php4/pear/DB/tests/mysql/mktable.inc Thu Mar 22 17:15:07 2001
@@ -6,7 +6,8 @@
$dbh->query("DROP TABLE phptest");
$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
-$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
+$test_mktable_query = "CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d
+DATE)";
+$dbh->query($test_mktable_query);
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
Index: php4/pear/DB/tests/oci8/002.phpt
diff -u php4/pear/DB/tests/oci8/002.phpt:1.1 php4/pear/DB/tests/oci8/002.phpt:1.2
--- php4/pear/DB/tests/oci8/002.phpt:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/002.phpt Thu Mar 22 17:15:07 2001
@@ -11,10 +11,10 @@
?>
--EXPECT--
testing fetchrow:
-row 1: 42, bing, This is a test, 11-21-1999
-row 2: 1, one, One, 02-16-2001
-row 3: 2, two, Two, 02-15-2001
-row 4: 3, three, Three, 02-14-2001
+row 1: 42, bing, This is a test, 1999-11-21
+row 2: 1, one, One, 2001-02-16
+row 3: 2, two, Two, 2001-02-15
+row 4: 3, three, Three, 2001-02-14
row 5: NULL
testing fetchmodes: fetchrow default default
0 1 2 3
@@ -23,16 +23,16 @@
testing fetchmodes: fetchrow ordered default
0 1 2 3
testing fetchmodes: fetchrow assoc default
-a b c d
+A B C D
testing fetchmodes: fetchrow ordered default with assoc specified
-a b c d
+A B C D
testing fetchmodes: fetchrow assoc default with ordered specified
0 1 2 3
testing fetchmodes: fetchinto ordered default
0 1 2 3
testing fetchmodes: fetchinto assoc default
-a b c d
+A B C D
testing fetchmodes: fetchinto ordered default with assoc specified
-a b c d
+A B C D
testing fetchmodes: fetchinto assoc default with ordered specified
0 1 2 3
Index: php4/pear/DB/tests/oci8/007.phpt
diff -u php4/pear/DB/tests/oci8/007.phpt:1.1 php4/pear/DB/tests/oci8/007.phpt:1.2
--- php4/pear/DB/tests/oci8/007.phpt:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/007.phpt Thu Mar 22 17:15:07 2001
@@ -1,13 +1,12 @@
--TEST--
DB_oci8::errorNative test
--SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php /*include("skipif.inc");*/ print "skip\n"; ?>
--FILE--
<?php
require_once "DB.php";
include("mktable.inc");
-$dbh->query("syntax error please");
+$err = $dbh->query("SELECT foo FROM tablethatdoesnotexist");
print $dbh->errorNative() . "\n";
?>
--EXPECT--
-XXX fill me in
Index: php4/pear/DB/tests/oci8/009.phpt
diff -u php4/pear/DB/tests/oci8/009.phpt:1.1 php4/pear/DB/tests/oci8/009.phpt:1.2
--- php4/pear/DB/tests/oci8/009.phpt:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/009.phpt Thu Mar 22 17:15:07 2001
@@ -6,10 +6,26 @@
<?php
require "connect.inc";
require "mktable.inc";
+$dbh->autoCommit(false);
+$dbh->setOption("optimize", "portability");
$test_error_mode = PEAR_ERROR_PRINT;
include "../numrows.inc";
+$dbh->rollback();
+$dbh->setOption("optimize", "performance");
+include "../numrows.inc";
+$dbh->rollback();
?>
--EXPECT--
+1
+2
+3
+4
+5
+6
+2
+0
+DB Error: DB backend not capable
+DB Error: DB backend not capable
DB Error: DB backend not capable
DB Error: DB backend not capable
DB Error: DB backend not capable
@@ -18,4 +34,3 @@
DB Error: DB backend not capable
DB Error: DB backend not capable
DB Error: DB backend not capable
-DB Error: unknown error
Index: php4/pear/DB/tests/oci8/010.phpt
diff -u php4/pear/DB/tests/oci8/010.phpt:1.1 php4/pear/DB/tests/oci8/010.phpt:1.2
--- php4/pear/DB/tests/oci8/010.phpt:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/010.phpt Thu Mar 22 17:15:07 2001
@@ -16,6 +16,8 @@
Trying to provoke DB_ERROR_NOSUCHTABLE
DB Error: no such table
Trying to provoke DB_ERROR_CONSTRAINT
+ DB Error: constraint violation
+ DB Error: constraint violation
Trying to provoke DB_ERROR_DIVZERO
DB Error: division by zero
Trying to provoke DB_ERROR_INVALID_NUMBER
Index: php4/pear/DB/tests/oci8/connect.inc
diff -u php4/pear/DB/tests/oci8/connect.inc:1.1 php4/pear/DB/tests/oci8/connect.inc:1.2
--- php4/pear/DB/tests/oci8/connect.inc:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/connect.inc Thu Mar 22 17:15:07 2001
@@ -1,4 +1,4 @@
<?php
require_once "DB.php";
-$dbh = DB::connect("oci8://test:test@test");
+$dbh = DB::connect("oci8://system:manager@test");
?>
Index: php4/pear/DB/tests/oci8/mktable.inc
diff -u php4/pear/DB/tests/oci8/mktable.inc:1.1 php4/pear/DB/tests/oci8/mktable.inc:1.2
--- php4/pear/DB/tests/oci8/mktable.inc:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/mktable.inc Thu Mar 22 17:15:07 2001
@@ -2,11 +2,18 @@
require_once "connect.inc";
+function mktable_error_handler($errobj) {
+ print "mktable error: ".$errobj->getMessage().": ".$errobj->getUserInfo();
+ print "\n";
+ exit;
+}
+
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
$dbh->query("DROP TABLE phptest");
-$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
-$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR2(40), c TEXT, d DATE)");
+$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "mktable_error_handler");
+$test_mktable_query = "CREATE TABLE phptest (a INTEGER, b VARCHAR2(40), c LONG
+VARCHAR, d VARCHAR2(20))";
+$dbh->query($test_mktable_query);
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
Index: php4/pear/DB/tests/oci8/skipif.inc
diff -u php4/pear/DB/tests/oci8/skipif.inc:1.1 php4/pear/DB/tests/oci8/skipif.inc:1.2
--- php4/pear/DB/tests/oci8/skipif.inc:1.1 Sun Feb 18 16:49:07 2001
+++ php4/pear/DB/tests/oci8/skipif.inc Thu Mar 22 17:15:07 2001
@@ -10,7 +10,7 @@
if (!extension_loaded("oci8")) {
die("skip\n");
}
-$conn = @OCILogon("test", "test", "test");
+$conn = @OCILogon("system", "manager", "test");
if (!is_resource($conn)) {
die("skip\n");
}
Index: php4/pear/DB/tests/odbc/mktable.inc
diff -u php4/pear/DB/tests/odbc/mktable.inc:1.2 php4/pear/DB/tests/odbc/mktable.inc:1.3
--- php4/pear/DB/tests/odbc/mktable.inc:1.2 Sun Feb 18 16:50:30 2001
+++ php4/pear/DB/tests/odbc/mktable.inc Thu Mar 22 17:15:07 2001
@@ -6,7 +6,8 @@
$dbh->query("DROP TABLE phptest");
$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
-$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
+$test_mktable_query = "CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d
+DATE)";
+$dbh->query($test_mktable_query);
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
Index: php4/pear/DB/tests/pgsql/mktable.inc
diff -u php4/pear/DB/tests/pgsql/mktable.inc:1.3
php4/pear/DB/tests/pgsql/mktable.inc:1.4
--- php4/pear/DB/tests/pgsql/mktable.inc:1.3 Sun Feb 18 16:50:31 2001
+++ php4/pear/DB/tests/pgsql/mktable.inc Thu Mar 22 17:15:08 2001
@@ -6,7 +6,8 @@
$dbh->query("DROP TABLE phptest");
$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
-$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
+$test_mktable_query = "CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d
+DATE)";
+$dbh->query($test_mktable_query);
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]