Deduplicate error methods in Firebird_Result class

This commit is contained in:
Timothy Warren 2014-04-09 13:20:30 -04:00
parent 9f93d1ce35
commit 3cc260b779
3 changed files with 15 additions and 10 deletions

View File

@ -207,7 +207,7 @@ class Firebird extends Abstract_Driver {
$err_string = \fbird_errmsg() . "Last query:" . $this->last_query; $err_string = \fbird_errmsg() . "Last query:" . $this->last_query;
if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL); if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL);
$this->statement = new FireBird_Result($this->statement_link); $this->statement = new FireBird_Result($this->statement_link, $this);
return $this->statement; return $this->statement;
} }
@ -229,7 +229,7 @@ class Firebird extends Abstract_Driver {
// Throw the error as an exception // Throw the error as an exception
if ($this->statement_link === FALSE) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL); if ($this->statement_link === FALSE) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
$this->statement = new FireBird_Result($this->statement_link); $this->statement = new FireBird_Result($this->statement_link, $this);
return $this->statement; return $this->statement;
} }

View File

@ -45,14 +45,23 @@ class Firebird_Result extends \PDOStatement {
*/ */
private $result = array(); private $result = array();
/**
* Reference to the db drive to de-duplicate error functions
*
* @var \Query\Driver\Firebird
*/
private $db;
/** /**
* Create the object by passing the resource for * Create the object by passing the resource for
* the query * the query
* *
* @param resource $link * @param resource $link
* @param [\Query\Driver\Firebird] $db
*/ */
public function __construct($link) public function __construct($link, Driver_Interface $db = NULL)
{ {
if ( ! is_null($db)) $this->db = $db;
$this->statement = $link; $this->statement = $link;
$this->setFetchMode(\PDO::FETCH_ASSOC); $this->setFetchMode(\PDO::FETCH_ASSOC);
$this->row = -1; $this->row = -1;
@ -271,7 +280,7 @@ class Firebird_Result extends \PDOStatement {
*/ */
public function errorCode() public function errorCode()
{ {
return \fbird_errcode(); return $this->db->errorCode();
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -283,10 +292,7 @@ class Firebird_Result extends \PDOStatement {
*/ */
public function errorInfo() public function errorInfo()
{ {
$code = \fbird_errcode(); return $this->db->errorInfo();
$msg = \fbird_errmsg();
return array(0, $code, $msg);
} }
} }
// End of firebird_result.php // End of firebird_result.php

View File

@ -34,10 +34,9 @@ class Firebird_Util extends Abstract_Util {
* @param string $name * @param string $name
* @param array $fields * @param array $fields
* @param array $constraints * @param array $constraints
* @param array $indexes
* @return string * @return string
*/ */
public function create_table($name, $fields, array $constraints=array(), array $indexes=array()) public function create_table($name, $fields, array $constraints=array())
{ {
$column_array = array(); $column_array = array();