Fix some Firebird issues, and make util class available from the Query Builder class

This commit is contained in:
Timothy Warren 2014-02-10 13:35:57 -05:00
parent d4e99aa5cd
commit 56ea38ccad
4 changed files with 25 additions and 6 deletions

View File

@ -123,6 +123,7 @@ class Query_Builder implements iQuery_Builder {
// Make things just slightly shorter // Make things just slightly shorter
$this->sql = $this->db->sql; $this->sql = $this->db->sql;
$this->util = $this->db->util;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -61,7 +61,7 @@ class Firebird extends DB_PDO {
*/ */
public function __construct($dbpath, $user='SYSDBA', $pass='masterkey') public function __construct($dbpath, $user='SYSDBA', $pass='masterkey')
{ {
$this->conn = fbird_connect($dbpath, $user, $pass, 'utf-8'); $this->conn = fbird_connect($dbpath, $user, $pass, 'utf-8', 0);
// Throw an exception to make this match other pdo classes // Throw an exception to make this match other pdo classes
if ( ! is_resource($this->conn)) if ( ! is_resource($this->conn))
@ -83,6 +83,14 @@ class Firebird extends DB_PDO {
$this->util = new $class($this); $this->util = new $class($this);
} }
/**
* Clean up database connections
*/
public function __destruct()
{
fbird_close($this->conn);
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
@ -104,9 +112,15 @@ class Firebird extends DB_PDO {
* *
* @param string $sql * @param string $sql
* @return $this * @return $this
* @throws PDOException
*/ */
public function query($sql) public function query($sql)
{ {
if (empty($sql))
{
throw new PDOException("Query method requires an sql query!");
}
$this->statement_link = (isset($this->trans)) $this->statement_link = (isset($this->trans))
? fbird_query($this->trans, $sql) ? fbird_query($this->trans, $sql)
: fbird_query($this->conn, $sql); : fbird_query($this->conn, $sql);
@ -114,7 +128,7 @@ class Firebird extends DB_PDO {
// Throw the error as a exception // Throw the error as a exception
if ($this->statement_link === FALSE) if ($this->statement_link === FALSE)
{ {
throw new PDOException(fbird_errmsg()); throw new PDOException(fbird_errmsg() . "Last query:" . $this->last_query);
} }
$this->statement = new FireBird_Result($this->statement_link); $this->statement = new FireBird_Result($this->statement_link);
@ -130,6 +144,7 @@ class Firebird extends DB_PDO {
* @param string $query * @param string $query
* @param array $options * @param array $options
* @return $this * @return $this
* @throws PDOException
*/ */
public function prepare($query, $options=NULL) public function prepare($query, $options=NULL)
{ {

View File

@ -65,6 +65,9 @@ class Firebird_Result extends PDOStatement {
{ {
$this->result[] = $row; $this->result[] = $row;
} }
// Free the result resource
fbird_free_result($link);
} }
} }
@ -247,7 +250,7 @@ class Firebird_Result extends PDOStatement {
$rows = fbird_affected_rows(); $rows = fbird_affected_rows();
// Get the number of rows for the select query if you can // Get the number of rows for the select query if you can
if ($rows === FALSE && is_resource($link) && get_resource_type($link) === "interbase result") if ($rows === FALSE && is_resource($this->statement) && get_resource_type($this->statement) === "interbase result")
{ {
$rows = count($this->result); $rows = count($this->result);
} }