diff --git a/sys/db/drivers/firebird-ibase.php b/sys/db/drivers/firebird-ibase.php
index eec03b6..a54789b 100644
--- a/sys/db/drivers/firebird-ibase.php
+++ b/sys/db/drivers/firebird-ibase.php
@@ -19,7 +19,7 @@
*/
class firebird extends DB_PDO {
- protected $statement, $trans, $count, $result;
+ protected $statement, $trans, $count, $result, $conn;
/**
* Open the link to the database
@@ -30,14 +30,10 @@ class firebird extends DB_PDO {
*/
public function __construct($dbpath, $user='sysdba', $pass='masterkey')
{
- // More a pain than it is worth to actually
- // pass around the resource that this provides.
- // Since the resource is not required by the
- // functions that would use it, I'm dumping it.
- $conn = @ibase_connect($dbpath, $user, $pass, 'utf-8');
+ $this->conn = @ibase_connect($dbpath, $user, $pass, 'utf-8');
// Throw an exception to make this match other pdo classes
- if ( ! is_resource($conn))
+ if ( ! is_resource($this->conn))
{
throw new PDOException(ibase_errmsg());
die();
@@ -87,18 +83,18 @@ class firebird extends DB_PDO {
if (isset($this->trans))
{
- $this->statement = @ibase_query($this->trans, $sql);
+ $this->statement = ibase_query($this->trans, $sql);
}
else
{
- $this->statement = @ibase_query($sql);
+ $this->statement = ibase_query($this->conn, $sql);
}
// Throw the error as a exception
- if ($this->statement === FALSE)
+ /*if ($this->statement === FALSE)
{
throw new PDOException(ibase_errmsg());
- }
+ }*/
return $this->statement;
}
@@ -161,13 +157,13 @@ class firebird extends DB_PDO {
*/
public function prepare($query, $options=NULL)
{
- $this->statement = @ibase_prepare($query);
+ $this->statement = ibase_prepare($this->conn, $query);
// Throw the error as an exception
- if ($this->statement === FALSE)
+ /*if ($this->statement === FALSE)
{
throw new PDOException(ibase_errmsg());
- }
+ }*/
return $this->statement;
}
@@ -268,7 +264,7 @@ SQL;
*/
public function beginTransaction()
{
- if(($this->trans = ibase_trans()) !== NULL)
+ if(($this->trans = ibase_trans($this->conn)) !== NULL)
{
return TRUE;
}
diff --git a/sys/db/drivers/firebird_sql.php b/sys/db/drivers/firebird_sql.php
index e1a1be1..6fd1a5d 100644
--- a/sys/db/drivers/firebird_sql.php
+++ b/sys/db/drivers/firebird_sql.php
@@ -103,7 +103,7 @@ class Firebird_SQL extends DB_SQL {
if ($offset > 0)
{
- $sql .= ' SKIP'. (int) $offset;
+ $sql .= ' SKIP '. (int) $offset;
}
$sql = preg_replace("`SELECT`i", "SELECT {$sql}", $orig_sql);
diff --git a/sys/db/query_builder.php b/sys/db/query_builder.php
index 1745ce0..f2eac8d 100644
--- a/sys/db/query_builder.php
+++ b/sys/db/query_builder.php
@@ -18,7 +18,7 @@
*/
class Query_Builder {
- private $table, $where_array;
+ private $table, $where_array, $sql;
/**
* Constructor
@@ -52,24 +52,9 @@ class Query_Builder {
$this->db = new $dbtype("{$params->host}:{$params->file}", $params->user, $params->pass);
break;
}
- }
-
- // --------------------------------------------------------------------------
-
- /**
- * Shortcut to directly access database class properties
- *
- * @param string $key
- * @return mixed
- */
- public function __get($key)
- {
- if (isset($this->db->$key))
- {
- return $this->db->$key;
- }
-
- return NULL;
+
+ // Make things just slightly shorter
+ $this->sql =& $this->db->sql;
}
// --------------------------------------------------------------------------
@@ -83,7 +68,7 @@ class Query_Builder {
*/
public function __call($name, $params)
{
- if (isset($this->db->$name))
+ if (method_exists($this->db, $name))
{
if (is_callable($this->db->$name))
{
@@ -107,19 +92,24 @@ class Query_Builder {
*/
public function get($table='', $limit=FALSE, $offset=FALSE)
{
- $sql = 'SELECT * FROM ' . $this->quote_ident($table);
+ // @todo Only add in the table name when using the select method
+ // @tood Only execute combined query when using other query methods and empty parameters
+
+ $sql = 'SELECT * FROM ' . $this->db->quote_ident($table);
if ( ! empty($table) && $limit === FALSE && $offset === FALSE)
{
- $result = $this->query($sql);
+ $result = $this->db->query($sql);
}
else
{
- $result = $this->query($this->sql->limit($sql, $limit, $offset));
+ $sql = $this->sql->limit($sql, $limit, $offset);
+ $result = $this->db->query($sql);
}
+
+ //echo $sql."
";
- // For the firebird class, return $this so you can act on the result
- return (is_resource($result)) ? $this : $result;
+ return $result;
}
// --------------------------------------------------------------------------
diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php
index 08cde46..9c4272f 100644
--- a/tests/databases/firebird.php
+++ b/tests/databases/firebird.php
@@ -100,11 +100,11 @@ class FirebirdTest extends UnitTestCase {
//This test fails for an unknown reason, when clearly the table exists
//Reset
- /*$this->tearDown();
+ $this->tearDown();
$this->setUp();
//Check
- $table_exists = (bool)in_array('create_test', $this->tables);
+ /*$table_exists = (bool)in_array('create_test', $this->tables);
echo "create_test exists :".(int)$table_exists.'
';
@@ -133,6 +133,27 @@ class FirebirdTest extends UnitTestCase {
$this->assertTrue($res);
}
+ function TestQBGet()
+ {
+ $query = $this->qb->get('create_test');
+
+ $this->assertTrue(is_resource($query));
+ }
+
+ function TestQBGetLimit()
+ {
+ $query = $this->qb->get('create_test', 2);
+
+ $this->assertTrue(is_resource($query));
+ }
+
+ function TestQBGetLimitSkip()
+ {
+ $query = $this->qb->get('create_test', 2, 1);
+
+ $this->assertTrue(is_resource($query));
+ }
+
function TestPreparedStatements()
{
$sql = <<db = new SQLite($path);
+
+ $params = new Stdclass();
+ $params->type = 'sqlite';
+ $params->file = $path;
+ $params->host = 'localhost';
+ $this->qb = new Query_Builder($params);
}
function tearDown()
@@ -125,6 +131,27 @@ SQL;
$this->assertTrue($res);
}
+ function TestQBGet()
+ {
+ $query = $this->qb->get('create_test');
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestQBGetLimit()
+ {
+ $query = $this->qb->get('create_test', 2);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestQBGetLimitSkip()
+ {
+ $query = $this->qb->get('create_test', 2, 1);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
function TestDeleteTable()
{
//Make sure the table exists to delete
diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB
index 90a4ba4..24b583a 100755
Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ