2012-04-10 14:06:34 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* Free Query Builder / Database Abstraction Layer
|
|
|
|
*
|
2012-04-20 13:17:39 -04:00
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren
|
2014-01-02 12:36:50 -05:00
|
|
|
* @copyright Copyright (c) 2012 - 2014
|
2012-04-10 14:06:34 -04:00
|
|
|
* @link https://github.com/aviat4ion/Query
|
2012-04-20 13:17:39 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-04-10 14:06:34 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2014-04-02 17:08:50 -04:00
|
|
|
namespace Query\Driver;
|
|
|
|
|
2012-04-10 14:06:34 -04:00
|
|
|
/**
|
|
|
|
* Firebird result class to emulate PDOStatement Class - only implements
|
|
|
|
* data-fetching methods
|
|
|
|
*
|
2012-04-20 13:17:39 -04:00
|
|
|
* @package Query
|
|
|
|
* @subpackage Drivers
|
2012-04-10 14:06:34 -04:00
|
|
|
*/
|
2014-04-02 17:08:50 -04:00
|
|
|
class Firebird_Result extends \PDOStatement {
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-04-19 11:42:50 -04:00
|
|
|
/**
|
|
|
|
* Reference to fbird resource
|
2012-04-20 16:33:40 -04:00
|
|
|
*
|
|
|
|
* @var resource
|
2012-04-19 11:42:50 -04:00
|
|
|
*/
|
2012-04-10 14:06:34 -04:00
|
|
|
private $statement;
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
/**
|
|
|
|
* Current row in result array
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $row;
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
/**
|
|
|
|
* Data pulled from query
|
|
|
|
*
|
|
|
|
* @param mixed
|
|
|
|
*/
|
|
|
|
private $result = array();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2014-04-09 13:20:30 -04:00
|
|
|
/**
|
|
|
|
* Reference to the db drive to de-duplicate error functions
|
|
|
|
*
|
|
|
|
* @var \Query\Driver\Firebird
|
|
|
|
*/
|
|
|
|
private $db;
|
|
|
|
|
2012-04-10 14:06:34 -04:00
|
|
|
/**
|
|
|
|
* Create the object by passing the resource for
|
|
|
|
* the query
|
|
|
|
*
|
|
|
|
* @param resource $link
|
2014-04-09 13:20:30 -04:00
|
|
|
* @param [\Query\Driver\Firebird] $db
|
2012-04-10 14:06:34 -04:00
|
|
|
*/
|
2014-04-09 13:20:30 -04:00
|
|
|
public function __construct($link, Driver_Interface $db = NULL)
|
2012-04-10 14:06:34 -04:00
|
|
|
{
|
2014-04-09 13:20:30 -04:00
|
|
|
if ( ! is_null($db)) $this->db = $db;
|
2012-04-10 14:06:34 -04:00
|
|
|
$this->statement = $link;
|
2014-04-02 17:08:50 -04:00
|
|
|
$this->setFetchMode(\PDO::FETCH_ASSOC);
|
2012-04-20 16:33:40 -04:00
|
|
|
$this->row = -1;
|
|
|
|
$this->result = array();
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
// Create the result array, so that we can get row counts
|
|
|
|
// Check the resource type, because prepared statements are "interbase query"
|
|
|
|
// but we only want "interbase result" types when attempting to fetch data
|
2014-04-02 17:08:50 -04:00
|
|
|
if (\is_resource($link) && \get_resource_type($link) === "interbase result")
|
2012-04-20 16:33:40 -04:00
|
|
|
{
|
2014-04-02 17:08:50 -04:00
|
|
|
while($row = \fbird_fetch_assoc($link, \IBASE_FETCH_BLOBS))
|
2012-04-20 16:33:40 -04:00
|
|
|
{
|
|
|
|
$this->result[] = $row;
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2014-02-10 13:35:57 -05:00
|
|
|
// Free the result resource
|
2014-04-02 17:08:50 -04:00
|
|
|
\fbird_free_result($link);
|
2012-04-20 16:33:40 -04:00
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
/**
|
|
|
|
* Invalidate method for data consistency
|
|
|
|
*
|
|
|
|
* @param mixed $column
|
2014-02-18 15:18:01 -05:00
|
|
|
* @param mixed $param
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param int $type
|
|
|
|
* @param mixed $maxlen
|
|
|
|
* @param array $driverdata
|
2013-05-01 15:59:23 -04:00
|
|
|
* @return NULL
|
2012-04-18 10:39:01 -04:00
|
|
|
*/
|
|
|
|
public function bindColumn($column, &$param, $type=NULL, $maxlen=NULL, $driverdata=NULL)
|
|
|
|
{
|
2013-05-01 15:59:23 -04:00
|
|
|
return NULL;
|
2012-04-18 10:39:01 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
/**
|
|
|
|
* Invalidate method for data consistency
|
|
|
|
*
|
|
|
|
* @param mixed $parameter
|
2014-02-18 15:18:01 -05:00
|
|
|
* @param mixed $variable
|
2012-04-18 10:39:01 -04:00
|
|
|
* @param int $data_type
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param mixed $maxlen
|
|
|
|
* @param array $driverdata
|
2013-05-01 15:59:23 -04:00
|
|
|
* @return NULL
|
2012-04-18 10:39:01 -04:00
|
|
|
*/
|
|
|
|
public function bindParam($parameter, &$variable, $data_type=NULL, $maxlen=NULL, $driverdata=NULL)
|
|
|
|
{
|
2013-05-01 15:59:23 -04:00
|
|
|
return NULL;
|
2012-04-18 10:39:01 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
/**
|
|
|
|
* Invalidate method for data consistency
|
|
|
|
*
|
|
|
|
* @param mixed $parameter
|
2014-02-18 15:18:01 -05:00
|
|
|
* @param mixed $variable
|
2012-04-18 10:39:01 -04:00
|
|
|
* @param int $data_type
|
2013-05-01 15:59:23 -04:00
|
|
|
* @return NULL
|
2012-04-18 10:39:01 -04:00
|
|
|
*/
|
|
|
|
public function bindValue($parameter, $variable, $data_type=NULL)
|
|
|
|
{
|
2013-05-01 15:59:23 -04:00
|
|
|
return NULL;
|
2012-04-18 10:39:01 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a prepared statement query
|
|
|
|
*
|
|
|
|
* @param array $args
|
2014-03-17 19:35:25 -04:00
|
|
|
* @return Firebird_Result
|
2012-04-18 10:39:01 -04:00
|
|
|
*/
|
|
|
|
public function execute($args = NULL)
|
|
|
|
{
|
|
|
|
//Add the prepared statement as the first parameter
|
2014-04-02 17:08:50 -04:00
|
|
|
\array_unshift($args, $this->statement);
|
2012-04-18 10:39:01 -04:00
|
|
|
|
|
|
|
// Let php do all the hard stuff in converting
|
|
|
|
// the array of arguments into a list of arguments
|
|
|
|
// Then pass the resource to the constructor
|
2014-04-02 17:08:50 -04:00
|
|
|
$this->__construct(\call_user_func_array('fbird_execute', $args));
|
2012-04-18 10:39:01 -04:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulate PDO fetch public function
|
|
|
|
*
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param int $fetch_style
|
2014-02-18 15:18:01 -05:00
|
|
|
* @param mixed $cursor_orientation
|
|
|
|
* @param mixed $cursor_offset
|
2012-04-10 14:06:34 -04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2014-04-02 17:08:50 -04:00
|
|
|
public function fetch($fetch_style=\PDO::FETCH_ASSOC, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset=NULL)
|
2014-02-25 13:47:35 -05:00
|
|
|
{
|
2012-04-20 16:33:40 -04:00
|
|
|
// If there is no result, continue
|
|
|
|
if (empty($this->result))
|
|
|
|
{
|
2013-05-01 15:59:23 -04:00
|
|
|
return NULL;
|
2012-04-20 16:33:40 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
// Keep track of the current row being fetched
|
|
|
|
++$this->row;
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2013-05-01 15:59:23 -04:00
|
|
|
// return NULL if the next row doesn't exist
|
2012-04-20 16:33:40 -04:00
|
|
|
if ( ! isset($this->result[$this->row]))
|
|
|
|
{
|
2013-05-01 15:59:23 -04:00
|
|
|
return NULL;
|
2012-04-20 16:33:40 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-10 14:06:34 -04:00
|
|
|
switch($fetch_style)
|
|
|
|
{
|
2014-04-02 17:08:50 -04:00
|
|
|
case \PDO::FETCH_OBJ:
|
2012-04-20 16:33:40 -04:00
|
|
|
$row = (object) $this->result[$this->row];
|
2012-04-10 14:06:34 -04:00
|
|
|
break;
|
|
|
|
|
2014-04-02 17:08:50 -04:00
|
|
|
case \PDO::FETCH_NUM:
|
|
|
|
$row = \array_values($this->result[$this->row]);
|
2012-04-10 14:06:34 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-04-20 16:33:40 -04:00
|
|
|
$row = $this->result[$this->row];
|
2012-04-10 14:06:34 -04:00
|
|
|
break;
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
return $row;
|
2012-04-10 14:06:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulate PDO fetchAll public function
|
|
|
|
*
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param int $fetch_style
|
|
|
|
* @param mixed $statement
|
|
|
|
* @param mixed $ctor_args
|
2012-04-10 14:06:34 -04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2014-04-02 17:08:50 -04:00
|
|
|
public function fetchAll($fetch_style=\PDO::FETCH_ASSOC, $statement=NULL, $ctor_args=NULL)
|
2012-04-10 14:06:34 -04:00
|
|
|
{
|
|
|
|
$all = array();
|
|
|
|
|
|
|
|
while($row = $this->fetch($fetch_style, $statement))
|
|
|
|
{
|
|
|
|
$all[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->result = $all;
|
|
|
|
|
|
|
|
return $all;
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-12 13:44:31 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulate PDOStatement::fetchColumn
|
2014-02-25 13:47:35 -05:00
|
|
|
*
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param int $column_num
|
2014-02-25 13:47:35 -05:00
|
|
|
* @return mixed
|
2012-04-12 13:44:31 -04:00
|
|
|
*/
|
|
|
|
public function fetchColumn($column_num=0)
|
|
|
|
{
|
2014-04-02 17:08:50 -04:00
|
|
|
$row = $this->fetch(\PDO::FETCH_NUM);
|
2012-04-12 13:44:31 -04:00
|
|
|
return $row[$column_num];
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 11:34:24 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulate PDOStatement::fetchObject, but only for the default use
|
2014-02-25 13:47:35 -05:00
|
|
|
*
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param string $class_name
|
|
|
|
* @param array $ctor_args
|
2014-02-25 13:47:35 -05:00
|
|
|
* @return stdClass
|
2012-04-18 11:34:24 -04:00
|
|
|
*/
|
|
|
|
public function fetchObject($class_name='stdClass', $ctor_args=array())
|
|
|
|
{
|
2014-04-02 17:08:50 -04:00
|
|
|
return $this->fetch(\PDO::FETCH_OBJ);
|
2012-04-18 11:34:24 -04:00
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of rows affected by the previous query
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function rowCount()
|
|
|
|
{
|
2014-04-02 17:08:50 -04:00
|
|
|
$rows = \fbird_affected_rows();
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
// Get the number of rows for the select query if you can
|
2014-04-02 17:08:50 -04:00
|
|
|
if ($rows === 0 && \is_resource($this->statement) && \get_resource_type($this->statement) === "interbase result")
|
2012-04-20 16:33:40 -04:00
|
|
|
{
|
2014-04-08 14:43:07 -04:00
|
|
|
// @codeCoverageIgnoreStart
|
2014-04-02 17:08:50 -04:00
|
|
|
$rows = \count($this->result);
|
2012-04-20 16:33:40 -04:00
|
|
|
}
|
2014-04-08 14:43:07 -04:00
|
|
|
// @codeCoverageIgnoreEnd
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-20 16:33:40 -04:00
|
|
|
return $rows;
|
2012-04-17 08:29:28 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2012-04-18 10:39:01 -04:00
|
|
|
/**
|
|
|
|
* Method to emulate PDOStatement->errorCode
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function errorCode()
|
|
|
|
{
|
2014-04-09 13:20:30 -04:00
|
|
|
return $this->db->errorCode();
|
2012-04-18 10:39:01 -04:00
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to emulate PDO->errorInfo / PDOStatement->errorInfo
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function errorInfo()
|
|
|
|
{
|
2014-04-09 13:20:30 -04:00
|
|
|
return $this->db->errorInfo();
|
2012-04-10 14:06:34 -04:00
|
|
|
}
|
|
|
|
}
|
2014-02-07 15:43:25 -05:00
|
|
|
// End of firebird_result.php
|