import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -59,7 +59,9 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
{
|
||||
$connection = $this->_adapter->getConnection();
|
||||
|
||||
$this->_stmt = db2_prepare($connection, $sql);
|
||||
// db2_prepare on i5 emits errors, these need to be
|
||||
// suppressed so that proper exceptions can be thrown
|
||||
$this->_stmt = @db2_prepare($connection, $sql);
|
||||
|
||||
if (!$this->_stmt) {
|
||||
/**
|
||||
@ -102,8 +104,8 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Db2/Exception.php';
|
||||
throw new Zend_Db_Statement_Db2_Exception(
|
||||
db2_stmt_errormsg($this->_stmt),
|
||||
db2_stmt_error($this->_stmt)
|
||||
db2_stmt_errormsg(),
|
||||
db2_stmt_error()
|
||||
);
|
||||
}
|
||||
|
||||
@ -149,10 +151,15 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
public function errorCode()
|
||||
{
|
||||
if (!$this->_stmt) {
|
||||
return '0000';
|
||||
return false;
|
||||
}
|
||||
|
||||
return db2_stmt_error($this->_stmt);
|
||||
$error = db2_stmt_error();
|
||||
if ($error === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,18 +170,19 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
if (!$this->_stmt) {
|
||||
return array(false, 0, '');
|
||||
}
|
||||
$error = $this->errorCode();
|
||||
if ($error === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return three-valued array like PDO. But DB2 does not distinguish
|
||||
* between SQLCODE and native RDBMS error code, so repeat the SQLCODE.
|
||||
*/
|
||||
return array(
|
||||
db2_stmt_error($this->_stmt),
|
||||
db2_stmt_error($this->_stmt),
|
||||
db2_stmt_errormsg($this->_stmt)
|
||||
$error,
|
||||
$error,
|
||||
db2_stmt_errormsg()
|
||||
);
|
||||
}
|
||||
|
||||
@ -204,8 +212,8 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Db2/Exception.php';
|
||||
throw new Zend_Db_Statement_Db2_Exception(
|
||||
db2_stmt_errormsg($this->_stmt),
|
||||
db2_stmt_error($this->_stmt));
|
||||
db2_stmt_errormsg(),
|
||||
db2_stmt_error());
|
||||
}
|
||||
|
||||
$this->_keys = array();
|
||||
|
@ -51,6 +51,36 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
*/
|
||||
protected $_values;
|
||||
|
||||
/**
|
||||
* Check if LOB field are returned as string
|
||||
* instead of OCI-Lob object
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_lobAsString = false;
|
||||
|
||||
/**
|
||||
* Activate/deactivate return of LOB as string
|
||||
*
|
||||
* @param string $lob_as_string
|
||||
* @return Zend_Db_Statement_Oracle
|
||||
*/
|
||||
public function setLobAsString($lob_as_string)
|
||||
{
|
||||
$this->_lobAsString = (bool) $lob_as_string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not LOB are returned as string
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLobAsString()
|
||||
{
|
||||
return $this->_lobAsString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares statement handle
|
||||
*
|
||||
@ -279,21 +309,23 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
$style = $this->_fetchMode;
|
||||
}
|
||||
|
||||
$lob_as_string = $this->getLobAsString() ? OCI_RETURN_LOBS : 0;
|
||||
|
||||
switch ($style) {
|
||||
case Zend_Db::FETCH_NUM:
|
||||
$row = oci_fetch_row($this->_stmt);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_NUM | OCI_RETURN_NULLS | $lob_as_string);
|
||||
break;
|
||||
case Zend_Db::FETCH_ASSOC:
|
||||
$row = oci_fetch_assoc($this->_stmt);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_ASSOC | OCI_RETURN_NULLS | $lob_as_string);
|
||||
break;
|
||||
case Zend_Db::FETCH_BOTH:
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
|
||||
break;
|
||||
case Zend_Db::FETCH_OBJ:
|
||||
$row = oci_fetch_object($this->_stmt);
|
||||
break;
|
||||
case Zend_Db::FETCH_BOUND:
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
|
||||
if ($row !== false) {
|
||||
return $this->_fetchBound($row);
|
||||
}
|
||||
@ -320,6 +352,10 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
throw new Zend_Db_Statement_Oracle_Exception($error);
|
||||
}
|
||||
|
||||
if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
|
||||
unset($row['zend_db_rownum']);
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
@ -404,6 +440,11 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
if ($style == Zend_Db::FETCH_COLUMN) {
|
||||
$result = $result[$col];
|
||||
}
|
||||
foreach ($result as &$row) {
|
||||
if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
|
||||
unset($row['zend_db_rownum']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (($row = oci_fetch_object($this->_stmt)) !== false) {
|
||||
$result [] = $row;
|
||||
@ -435,7 +476,15 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
}
|
||||
|
||||
if (!oci_fetch($this->_stmt)) {
|
||||
/* TODO ERROR */
|
||||
// if no error, there is simply no record
|
||||
if (!$error = oci_error($this->_stmt)) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Oracle_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Oracle/Exception.php';
|
||||
throw new Zend_Db_Statement_Oracle_Exception($error);
|
||||
}
|
||||
|
||||
$data = oci_result($this->_stmt, $col+1); //1-based
|
||||
@ -446,10 +495,18 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
require_once 'Zend/Db/Statement/Oracle/Exception.php';
|
||||
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
|
||||
}
|
||||
|
||||
if ($this->getLobAsString()) {
|
||||
// instanceof doesn't allow '-', we must use a temporary string
|
||||
$type = 'OCI-Lob';
|
||||
if ($data instanceof $type) {
|
||||
$data = $data->read($data->size());
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the next row and returns it as an object.
|
||||
*
|
||||
@ -466,12 +523,12 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
|
||||
$obj = oci_fetch_object($this->_stmt);
|
||||
|
||||
if ($obj === false) {
|
||||
if ($error = oci_error($this->_stmt)) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Oracle_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Oracle/Exception.php';
|
||||
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
|
||||
throw new Zend_Db_Statement_Oracle_Exception($error);
|
||||
}
|
||||
|
||||
/* @todo XXX handle parameters */
|
||||
|
@ -37,11 +37,11 @@ require_once 'Zend/Db/Statement.php';
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate
|
||||
{
|
||||
|
||||
/**
|
||||
* The mysqli_stmt object.
|
||||
* The statement object.
|
||||
*
|
||||
* @var PDOStatement
|
||||
*/
|
||||
@ -82,7 +82,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
public function bindColumn($column, &$param, $type = null)
|
||||
{
|
||||
try {
|
||||
if (is_null($type)) {
|
||||
if ($type === null) {
|
||||
return $this->_stmt->bindColumn($column, $param);
|
||||
} else {
|
||||
return $this->_stmt->bindColumn($column, $param, $type);
|
||||
@ -110,7 +110,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
if ($type === null) {
|
||||
if (is_bool($variable)) {
|
||||
$type = PDO::PARAM_BOOL;
|
||||
} elseif (is_null($variable)) {
|
||||
} elseif ($variable === null) {
|
||||
$type = PDO::PARAM_NULL;
|
||||
} elseif (is_integer($variable)) {
|
||||
$type = PDO::PARAM_INT;
|
||||
@ -140,7 +140,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
$parameter = ":$parameter";
|
||||
}
|
||||
try {
|
||||
if (is_null($type)) {
|
||||
if ($type === null) {
|
||||
return $this->_stmt->bindValue($parameter, $value);
|
||||
} else {
|
||||
return $this->_stmt->bindValue($parameter, $value, $type);
|
||||
@ -261,6 +261,16 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by IteratorAggregate interface
|
||||
*
|
||||
* @return IteratorIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new IteratorIterator($this->_stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the result set rows.
|
||||
*
|
||||
|
@ -80,7 +80,7 @@ class Zend_Db_Statement_Pdo_Ibm extends Zend_Db_Statement_Pdo
|
||||
public function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
|
||||
{
|
||||
try {
|
||||
if ( is_null($type) && is_null($length) && is_null($options) ) {
|
||||
if (($type === null) && ($length === null) && ($options === null)) {
|
||||
return $this->_stmt->bindParam($parameter, $variable);
|
||||
} else {
|
||||
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
|
||||
|
69
libs/Zend/Db/Statement/Pdo/Oci.php
Normal file
69
libs/Zend/Db/Statement/Pdo/Oci.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Statement
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Mysqli.php 4874 2007-05-19 01:26:32Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Statement_Pdo
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Pdo.php';
|
||||
|
||||
/**
|
||||
* Proxy class to wrap a PDOStatement object for IBM Databases.
|
||||
* Matches the interface of PDOStatement. All methods simply proxy to the
|
||||
* matching method in PDOStatement. PDOExceptions thrown by PDOStatement
|
||||
* are re-thrown as Zend_Db_Statement_Exception.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Statement
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Statement_Pdo_Oci extends Zend_Db_Statement_Pdo
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the result set rows.
|
||||
*
|
||||
* Behaves like parent, but if limit()
|
||||
* is used, the final result removes the extra column
|
||||
* 'zend_db_rownum'
|
||||
*
|
||||
* @param int $style OPTIONAL Fetch mode.
|
||||
* @param int $col OPTIONAL Column number, if fetch mode is by column.
|
||||
* @return array Collection of rows, each in a format by the fetch mode.
|
||||
* @throws Zend_Db_Statement_Exception
|
||||
*/
|
||||
public function fetchAll($style = null, $col = null)
|
||||
{
|
||||
$data = parent::fetchAll($style, $col);
|
||||
$results = array();
|
||||
$remove = $this->_adapter->foldCase('zend_db_rownum');
|
||||
|
||||
foreach ($data as $row) {
|
||||
if (is_array($row) && array_key_exists($remove, $row)) {
|
||||
unset($row[$remove]);
|
||||
}
|
||||
$results[] = $row;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user