composer update
This commit is contained in:
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Driver\IBMDB2;
|
||||
|
||||
@@ -43,29 +26,27 @@ use function func_get_args;
|
||||
|
||||
class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
{
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $_conn = null;
|
||||
/** @var resource */
|
||||
private $conn = null;
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param array $driverOptions
|
||||
* @param mixed[] $params
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param mixed[] $driverOptions
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Driver\IBMDB2\DB2Exception
|
||||
* @throws DB2Exception
|
||||
*/
|
||||
public function __construct(array $params, $username, $password, $driverOptions = [])
|
||||
{
|
||||
$isPersistent = (isset($params['persistent']) && $params['persistent'] == true);
|
||||
$isPersistent = (isset($params['persistent']) && $params['persistent'] === true);
|
||||
|
||||
if ($isPersistent) {
|
||||
$this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
|
||||
$this->conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
|
||||
} else {
|
||||
$this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
|
||||
$this->conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
|
||||
}
|
||||
if ( ! $this->_conn) {
|
||||
if (! $this->conn) {
|
||||
throw new DB2Exception(db2_conn_errormsg());
|
||||
}
|
||||
}
|
||||
@@ -76,7 +57,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
public function getServerVersion()
|
||||
{
|
||||
/** @var stdClass $serverInfo */
|
||||
$serverInfo = db2_server_info($this->_conn);
|
||||
$serverInfo = db2_server_info($this->conn);
|
||||
|
||||
return $serverInfo->DBMS_VER;
|
||||
}
|
||||
@@ -94,8 +75,8 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function prepare($sql)
|
||||
{
|
||||
$stmt = @db2_prepare($this->_conn, $sql);
|
||||
if ( ! $stmt) {
|
||||
$stmt = @db2_prepare($this->conn, $sql);
|
||||
if (! $stmt) {
|
||||
throw new DB2Exception(db2_stmt_errormsg());
|
||||
}
|
||||
|
||||
@@ -108,7 +89,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
public function query()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$sql = $args[0];
|
||||
$sql = $args[0];
|
||||
$stmt = $this->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
@@ -126,7 +107,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
return $input;
|
||||
}
|
||||
|
||||
return "'".$input."'";
|
||||
return "'" . $input . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,9 +115,9 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function exec($statement)
|
||||
{
|
||||
$stmt = @db2_exec($this->_conn, $statement);
|
||||
$stmt = @db2_exec($this->conn, $statement);
|
||||
|
||||
if (false === $stmt) {
|
||||
if ($stmt === false) {
|
||||
throw new DB2Exception(db2_stmt_errormsg());
|
||||
}
|
||||
|
||||
@@ -148,7 +129,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function lastInsertId($name = null)
|
||||
{
|
||||
return db2_last_insert_id($this->_conn);
|
||||
return db2_last_insert_id($this->conn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +137,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function beginTransaction()
|
||||
{
|
||||
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_OFF);
|
||||
db2_autocommit($this->conn, DB2_AUTOCOMMIT_OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,10 +145,10 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
if (!db2_commit($this->_conn)) {
|
||||
throw new DB2Exception(db2_conn_errormsg($this->_conn));
|
||||
if (! db2_commit($this->conn)) {
|
||||
throw new DB2Exception(db2_conn_errormsg($this->conn));
|
||||
}
|
||||
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
|
||||
db2_autocommit($this->conn, DB2_AUTOCOMMIT_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,10 +156,10 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function rollBack()
|
||||
{
|
||||
if (!db2_rollback($this->_conn)) {
|
||||
throw new DB2Exception(db2_conn_errormsg($this->_conn));
|
||||
if (! db2_rollback($this->conn)) {
|
||||
throw new DB2Exception(db2_conn_errormsg($this->conn));
|
||||
}
|
||||
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
|
||||
db2_autocommit($this->conn, DB2_AUTOCOMMIT_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +167,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
return db2_conn_error($this->_conn);
|
||||
return db2_conn_error($this->conn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +176,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
|
||||
public function errorInfo()
|
||||
{
|
||||
return [
|
||||
0 => db2_conn_errormsg($this->_conn),
|
||||
0 => db2_conn_errormsg($this->conn),
|
||||
1 => $this->errorCode(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Driver\IBMDB2;
|
||||
|
||||
@@ -23,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDB2Driver;
|
||||
|
||||
/**
|
||||
* IBM DB2 Driver.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class DB2Driver extends AbstractDB2Driver
|
||||
{
|
||||
@@ -34,18 +14,18 @@ class DB2Driver extends AbstractDB2Driver
|
||||
*/
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
|
||||
{
|
||||
if ( ! isset($params['protocol'])) {
|
||||
if (! isset($params['protocol'])) {
|
||||
$params['protocol'] = 'TCPIP';
|
||||
}
|
||||
|
||||
if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') {
|
||||
if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') {
|
||||
// if the host isn't localhost, use extended connection params
|
||||
$params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
|
||||
';DATABASE=' . $params['dbname'] .
|
||||
';HOSTNAME=' . $params['host'] .
|
||||
';PROTOCOL=' . $params['protocol'] .
|
||||
';UID=' . $username .
|
||||
';PWD=' . $password .';';
|
||||
';UID=' . $username .
|
||||
';PWD=' . $password . ';';
|
||||
if (isset($params['port'])) {
|
||||
$params['dbname'] .= 'PORT=' . $params['port'];
|
||||
}
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Driver\IBMDB2;
|
||||
|
||||
class DB2Exception extends \Exception
|
||||
use Exception;
|
||||
|
||||
class DB2Exception extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Driver\IBMDB2;
|
||||
|
||||
@@ -23,11 +6,19 @@ use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Driver\StatementIterator;
|
||||
use Doctrine\DBAL\FetchMode;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use IteratorAggregate;
|
||||
use PDO;
|
||||
use ReflectionClass;
|
||||
use ReflectionObject;
|
||||
use ReflectionProperty;
|
||||
use stdClass;
|
||||
use const CASE_LOWER;
|
||||
use const DB2_BINARY;
|
||||
use const DB2_CHAR;
|
||||
use const DB2_LONG;
|
||||
use const DB2_PARAM_FILE;
|
||||
use const DB2_PARAM_IN;
|
||||
use function array_change_key_case;
|
||||
use function call_user_func_array;
|
||||
use function db2_bind_param;
|
||||
use function db2_execute;
|
||||
use function db2_fetch_array;
|
||||
@@ -39,41 +30,46 @@ use function db2_num_fields;
|
||||
use function db2_num_rows;
|
||||
use function db2_stmt_error;
|
||||
use function db2_stmt_errormsg;
|
||||
use function error_get_last;
|
||||
use function fclose;
|
||||
use function func_get_args;
|
||||
use function func_num_args;
|
||||
use function fwrite;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function ksort;
|
||||
use function sprintf;
|
||||
use function stream_copy_to_stream;
|
||||
use function stream_get_meta_data;
|
||||
use function strtolower;
|
||||
use function tmpfile;
|
||||
|
||||
class DB2Statement implements \IteratorAggregate, Statement
|
||||
class DB2Statement implements IteratorAggregate, Statement
|
||||
{
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $_stmt;
|
||||
/** @var resource */
|
||||
private $stmt;
|
||||
|
||||
/** @var mixed[] */
|
||||
private $bindParam = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* Map of LOB parameter positions to the tuples containing reference to the variable bound to the driver statement
|
||||
* and the temporary file handle bound to the underlying statement
|
||||
*
|
||||
* @var mixed[][]
|
||||
*/
|
||||
private $_bindParam = [];
|
||||
private $lobs = [];
|
||||
|
||||
/**
|
||||
* @var string Name of the default class to instantiate when fetching class instances.
|
||||
*/
|
||||
/** @var string Name of the default class to instantiate when fetching class instances. */
|
||||
private $defaultFetchClass = '\stdClass';
|
||||
|
||||
/**
|
||||
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
|
||||
*/
|
||||
/** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */
|
||||
private $defaultFetchClassCtorArgs = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $_defaultFetchMode = FetchMode::MIXED;
|
||||
/** @var int */
|
||||
private $defaultFetchMode = FetchMode::MIXED;
|
||||
|
||||
/**
|
||||
* Indicates whether the statement is in the state when fetching results is possible
|
||||
@@ -82,22 +78,12 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
*/
|
||||
private $result = false;
|
||||
|
||||
/**
|
||||
* DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static private $_typeMap = [
|
||||
ParameterType::INTEGER => DB2_LONG,
|
||||
ParameterType::STRING => DB2_CHAR,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param resource $stmt
|
||||
*/
|
||||
public function __construct($stmt)
|
||||
{
|
||||
$this->_stmt = $stmt;
|
||||
$this->stmt = $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,33 +99,60 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
*/
|
||||
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
{
|
||||
$this->_bindParam[$column] =& $variable;
|
||||
switch ($type) {
|
||||
case ParameterType::INTEGER:
|
||||
$this->bind($column, $variable, DB2_PARAM_IN, DB2_LONG);
|
||||
break;
|
||||
|
||||
if ($type && isset(self::$_typeMap[$type])) {
|
||||
$type = self::$_typeMap[$type];
|
||||
} else {
|
||||
$type = DB2_CHAR;
|
||||
}
|
||||
case ParameterType::LARGE_OBJECT:
|
||||
if (isset($this->lobs[$column])) {
|
||||
[, $handle] = $this->lobs[$column];
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) {
|
||||
throw new DB2Exception(db2_stmt_errormsg());
|
||||
$handle = $this->createTemporaryFile();
|
||||
$path = stream_get_meta_data($handle)['uri'];
|
||||
|
||||
$this->bind($column, $path, DB2_PARAM_FILE, DB2_BINARY);
|
||||
|
||||
$this->lobs[$column] = [&$variable, $handle];
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->bind($column, $variable, DB2_PARAM_IN, DB2_CHAR);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $parameter Parameter position or name
|
||||
* @param mixed $variable
|
||||
*
|
||||
* @throws DB2Exception
|
||||
*/
|
||||
private function bind($parameter, &$variable, int $parameterType, int $dataType) : void
|
||||
{
|
||||
$this->bindParam[$parameter] =& $variable;
|
||||
|
||||
if (! db2_bind_param($this->stmt, $parameter, 'variable', $parameterType, $dataType)) {
|
||||
throw new DB2Exception(db2_stmt_errormsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function closeCursor()
|
||||
{
|
||||
if ( ! $this->_stmt) {
|
||||
if (! $this->stmt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_bindParam = [];
|
||||
$this->bindParam = [];
|
||||
|
||||
if (!db2_free_result($this->_stmt)) {
|
||||
if (! db2_free_result($this->stmt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -153,11 +166,11 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
*/
|
||||
public function columnCount()
|
||||
{
|
||||
if ( ! $this->_stmt) {
|
||||
if (! $this->stmt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return db2_num_fields($this->_stmt);
|
||||
return db2_num_fields($this->stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,21 +197,37 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
*/
|
||||
public function execute($params = null)
|
||||
{
|
||||
if ( ! $this->_stmt) {
|
||||
if (! $this->stmt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($params === null) {
|
||||
ksort($this->_bindParam);
|
||||
ksort($this->bindParam);
|
||||
|
||||
$params = [];
|
||||
|
||||
foreach ($this->_bindParam as $column => $value) {
|
||||
foreach ($this->bindParam as $column => $value) {
|
||||
$params[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$retval = db2_execute($this->_stmt, $params);
|
||||
foreach ($this->lobs as [$source, $target]) {
|
||||
if (is_resource($source)) {
|
||||
$this->copyStreamToStream($source, $target);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->writeStringToStream($source, $target);
|
||||
}
|
||||
|
||||
$retval = db2_execute($this->stmt, $params);
|
||||
|
||||
foreach ($this->lobs as [, $handle]) {
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
$this->lobs = [];
|
||||
|
||||
if ($retval === false) {
|
||||
throw new DB2Exception(db2_stmt_errormsg());
|
||||
@@ -214,7 +243,7 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
*/
|
||||
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
|
||||
{
|
||||
$this->_defaultFetchMode = $fetchMode;
|
||||
$this->defaultFetchMode = $fetchMode;
|
||||
$this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass;
|
||||
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
|
||||
|
||||
@@ -232,24 +261,24 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
|
||||
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
|
||||
{
|
||||
// do not try fetching from the statement if it's not expected to contain result
|
||||
// in order to prevent exceptional situation
|
||||
if (!$this->result) {
|
||||
if (! $this->result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
|
||||
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
|
||||
switch ($fetchMode) {
|
||||
case FetchMode::COLUMN:
|
||||
return $this->fetchColumn();
|
||||
|
||||
case FetchMode::MIXED:
|
||||
return db2_fetch_both($this->_stmt);
|
||||
return db2_fetch_both($this->stmt);
|
||||
|
||||
case FetchMode::ASSOCIATIVE:
|
||||
return db2_fetch_assoc($this->_stmt);
|
||||
return db2_fetch_assoc($this->stmt);
|
||||
|
||||
case FetchMode::CUSTOM_OBJECT:
|
||||
$className = $this->defaultFetchClass;
|
||||
@@ -261,19 +290,19 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
$ctorArgs = $args[2] ?? [];
|
||||
}
|
||||
|
||||
$result = db2_fetch_object($this->_stmt);
|
||||
$result = db2_fetch_object($this->stmt);
|
||||
|
||||
if ($result instanceof \stdClass) {
|
||||
if ($result instanceof stdClass) {
|
||||
$result = $this->castObject($result, $className, $ctorArgs);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
case FetchMode::NUMERIC:
|
||||
return db2_fetch_array($this->_stmt);
|
||||
return db2_fetch_array($this->stmt);
|
||||
|
||||
case FetchMode::STANDARD_OBJECT:
|
||||
return db2_fetch_object($this->_stmt);
|
||||
return db2_fetch_object($this->stmt);
|
||||
|
||||
default:
|
||||
throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.');
|
||||
@@ -314,7 +343,7 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
{
|
||||
$row = $this->fetch(FetchMode::NUMERIC);
|
||||
|
||||
if (false === $row) {
|
||||
if ($row === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -326,37 +355,38 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
*/
|
||||
public function rowCount()
|
||||
{
|
||||
return (@db2_num_rows($this->_stmt)) ? : 0;
|
||||
return @db2_num_rows($this->stmt) ? : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a stdClass object to the given class name mapping its' properties.
|
||||
*
|
||||
* @param \stdClass $sourceObject Object to cast from.
|
||||
* @param stdClass $sourceObject Object to cast from.
|
||||
* @param string|object $destinationClass Name of the class or class instance to cast to.
|
||||
* @param array $ctorArgs Arguments to use for constructing the destination class instance.
|
||||
* @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @throws DB2Exception
|
||||
*/
|
||||
private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
|
||||
private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
|
||||
{
|
||||
if ( ! is_string($destinationClass)) {
|
||||
if ( ! is_object($destinationClass)) {
|
||||
if (! is_string($destinationClass)) {
|
||||
if (! is_object($destinationClass)) {
|
||||
throw new DB2Exception(sprintf(
|
||||
'Destination class has to be of type string or object, %s given.', gettype($destinationClass)
|
||||
'Destination class has to be of type string or object, %s given.',
|
||||
gettype($destinationClass)
|
||||
));
|
||||
}
|
||||
} else {
|
||||
$destinationClass = new \ReflectionClass($destinationClass);
|
||||
$destinationClass = new ReflectionClass($destinationClass);
|
||||
$destinationClass = $destinationClass->newInstanceArgs($ctorArgs);
|
||||
}
|
||||
|
||||
$sourceReflection = new \ReflectionObject($sourceObject);
|
||||
$destinationClassReflection = new \ReflectionObject($destinationClass);
|
||||
/** @var \ReflectionProperty[] $destinationProperties */
|
||||
$destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), \CASE_LOWER);
|
||||
$sourceReflection = new ReflectionObject($sourceObject);
|
||||
$destinationClassReflection = new ReflectionObject($destinationClass);
|
||||
/** @var ReflectionProperty[] $destinationProperties */
|
||||
$destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), CASE_LOWER);
|
||||
|
||||
foreach ($sourceReflection->getProperties() as $sourceProperty) {
|
||||
$sourceProperty->setAccessible(true);
|
||||
@@ -392,4 +422,45 @@ class DB2Statement implements \IteratorAggregate, Statement
|
||||
|
||||
return $destinationClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*
|
||||
* @throws DB2Exception
|
||||
*/
|
||||
private function createTemporaryFile()
|
||||
{
|
||||
$handle = @tmpfile();
|
||||
|
||||
if ($handle === false) {
|
||||
throw new DB2Exception('Could not create temporary file: ' . error_get_last()['message']);
|
||||
}
|
||||
|
||||
return $handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $source
|
||||
* @param resource $target
|
||||
*
|
||||
* @throws DB2Exception
|
||||
*/
|
||||
private function copyStreamToStream($source, $target) : void
|
||||
{
|
||||
if (@stream_copy_to_stream($source, $target) === false) {
|
||||
throw new DB2Exception('Could not copy source stream to temporary file: ' . error_get_last()['message']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $target
|
||||
*
|
||||
* @throws DB2Exception
|
||||
*/
|
||||
private function writeStringToStream(string $string, $target) : void
|
||||
{
|
||||
if (@fwrite($target, $string) === false) {
|
||||
throw new DB2Exception('Could not write string to temporary file: ' . error_get_last()['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user