diff --git a/sys/databases/firebird-ibase.php b/sys/databases/firebird-ibase.php index ce4671b..c433fcd 100644 --- a/sys/databases/firebird-ibase.php +++ b/sys/databases/firebird-ibase.php @@ -19,7 +19,7 @@ */ class firebird extends DB_PDO { - protected $conn, $statement, $trans, $count, $result; + protected $statement, $trans, $count, $result; /** * Open the link to the database @@ -30,7 +30,11 @@ class firebird extends DB_PDO { */ public function __construct($dbpath, $user='sysdba', $pass='masterkey') { - $this->conn = ibase_connect($dbpath, $user, $pass, 'utf-8'); + // 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. + ibase_connect($dbpath, $user, $pass, 'utf-8'); $class = __CLASS__."_sql"; $this->sql = new $class; @@ -43,7 +47,7 @@ class firebird extends DB_PDO { */ public function __destruct() { - @ibase_close($this->conn); + @ibase_close(); @ibase_free_result($this->statement); } @@ -73,7 +77,16 @@ class firebird extends DB_PDO { public function query($sql) { $this->count = 0; - $this->statement = ibase_query($this->conn, $sql); + + if (isset($this->trans)) + { + $this->statement = ibase_query($this->trans, $sql); + } + else + { + $this->statement = ibase_query($sql); + } + return $this->statement; } @@ -135,7 +148,7 @@ class firebird extends DB_PDO { */ public function prepare($query, $options=NULL) { - $this->statement = ibase_prepare($this->conn, $query); + $this->statement = ibase_prepare($query); return $this->statement; } @@ -202,7 +215,7 @@ SQL; */ public function affected_rows($statement="") { - return ibase_affected_rows($this->conn); + return ibase_affected_rows(); } // -------------------------------------------------------------------------- @@ -235,7 +248,7 @@ SQL; */ public function beginTransaction() { - if(($this->trans =& ibase_trans($this->conn)) !== NULL) + if(($this->trans = ibase_trans()) !== NULL) { return TRUE; } diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php index 507a6eb..ad0c2ec 100644 --- a/tests/databases/firebird.php +++ b/tests/databases/firebird.php @@ -68,6 +68,12 @@ class FirebirdTest extends UnitTestCase { $this->assertTrue($only_system); } + + function TestCreateTransaction() + { + $res = $this->db->beginTransaction(); + $this->assertTrue($res); + } function TestCreateTable() { @@ -92,6 +98,28 @@ class FirebirdTest extends UnitTestCase { $this->assertTrue($table_exists);*/ } + function TestCommitTransaction() + { + $this->TestCreateTransaction(); + + $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; + $this->db->query($sql); + + $res = $this->db->commit(); + $this->assertTrue($res); + } + + function TestRollbackTransaction() + { + $this->TestCreateTransaction(); + + $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; + $this->db->query($sql); + + $res = $this->db->rollback(); + $this->assertTrue($res); + } + function TestPreparedStatements() { $sql = <<