Firebird refactoring

This commit is contained in:
Timothy Warren 2012-03-06 15:54:59 -05:00
parent cee3bf8412
commit 46771a7725
7 changed files with 37 additions and 18 deletions

View File

@ -105,7 +105,7 @@ abstract class DB_PDO extends PDO {
*/ */
public function get_query_data($statement) public function get_query_data($statement)
{ {
$this->statement = $statement; $this->statement =& $statement;
// Execute the query // Execute the query
$this->statement->execute(); $this->statement->execute();

View File

@ -64,7 +64,14 @@ class Query_Builder {
break; break;
case "firebird": case "firebird":
$this->db = new $dbtype("{$params->host}:{$params->file}", $params->user, $params->pass); if(in_array('firebird', pdo_drivers()))
{
$this->db = new $dbtype("host={$params->host};dbname={$params->file}", $params->user, $params->pass);
}
else
{
$this->db = new $dbtype("{$params->host}:{$params->file}", $params->user, $params->pass);
}
break; break;
} }
} }

View File

@ -19,7 +19,8 @@
*/ */
class firebird extends DB_PDO { class firebird extends DB_PDO {
protected $conn, $statement, $trans, $count, $result; protected $statement, $trans, $count, $result;
public static $conn;
/** /**
* Open the link to the database * Open the link to the database
@ -30,7 +31,13 @@ class firebird extends DB_PDO {
*/ */
public function __construct($dbpath, $user='sysdba', $pass='masterkey') public function __construct($dbpath, $user='sysdba', $pass='masterkey')
{ {
$this->conn = ibase_connect($dbpath, $user, $pass, 'utf-8'); self::$conn = ibase_connect($dbpath, $user, $pass, 'utf-8');
if ( ! self::$conn)
{
throw new PDOException(ibase_errmsg());
}
$class = __CLASS__."_sql"; $class = __CLASS__."_sql";
$this->sql = new $class; $this->sql = new $class;
@ -43,7 +50,7 @@ class firebird extends DB_PDO {
*/ */
public function __destruct() public function __destruct()
{ {
@ibase_close($this->conn); @ibase_close(self::$conn);
@ibase_free_result($this->statement); @ibase_free_result($this->statement);
} }
@ -73,7 +80,7 @@ class firebird extends DB_PDO {
public function query($sql) public function query($sql)
{ {
$this->count = 0; $this->count = 0;
$this->statement = ibase_query($this->conn, $sql); $this->statement = ibase_query(self::$conn, $sql);
return $this->statement; return $this->statement;
} }
@ -135,7 +142,7 @@ class firebird extends DB_PDO {
*/ */
public function prepare($query, $options=NULL) public function prepare($query, $options=NULL)
{ {
$this->statement = ibase_prepare($this->conn, $query); $this->statement = ibase_prepare(self::$conn, $query);
return $this->statement; return $this->statement;
} }
@ -202,7 +209,7 @@ SQL;
*/ */
public function affected_rows($statement="") public function affected_rows($statement="")
{ {
return ibase_affected_rows($this->conn); return ibase_affected_rows(self::$conn);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -235,7 +242,7 @@ SQL;
*/ */
public function beginTransaction() public function beginTransaction()
{ {
if(($this->trans =& ibase_trans($this->conn)) !== NULL) if(($this->trans =& ibase_trans(self::$conn)) !== NULL)
{ {
return TRUE; return TRUE;
} }

View File

@ -21,7 +21,7 @@ class Firebird extends DB_PDO {
*/ */
public function __construct($dbpath, $user='sysdba', $pass='masterkey') public function __construct($dbpath, $user='sysdba', $pass='masterkey')
{ {
parent::__construct("firebird:{$dbpath}", $user, $pass); parent::__construct("firebird:dbname={$dbpath}", $user, $pass);
$class = __CLASS__."_sql"; $class = __CLASS__."_sql";
$this->sql = new $class; $this->sql = new $class;
@ -60,7 +60,7 @@ SQL;
$tables = array(); $tables = array();
while($row = $this->fetch(PDO::FETCH_ASSOC)) while($row = $this->statement->fetch(PDO::FETCH_ASSOC))
{ {
$tables[] = $row['RDB$RELATION_NAME']; $tables[] = $row['RDB$RELATION_NAME'];
} }
@ -87,7 +87,7 @@ SQL;
$tables = array(); $tables = array();
while($row = $this->fetch(PDO::FETCH_ASSOC)) while($row = $this->statement->fetch(PDO::FETCH_ASSOC))
{ {
$tables[] = $row['RDB$RELATION_NAME']; $tables[] = $row['RDB$RELATION_NAME'];
} }
@ -111,7 +111,7 @@ SQL;
} }
//Fetch all the rows for the result //Fetch all the rows for the result
$this->result = $this->fetchAll(); $this->result = $this->statement->fetchAll();
return count($this->result); return count($this->result);
} }
@ -163,7 +163,7 @@ SQL;
{ {
$sql = 'SELECT * FROM "'.trim($t).'"'; $sql = 'SELECT * FROM "'.trim($t).'"';
$res = $this->query($sql); $res = $this->query($sql);
$obj_res = $this->fetchAll(PDO::FETCH_ASSOC); $obj_res = $res->fetchAll(PDO::FETCH_ASSOC);
unset($res); unset($res);

View File

@ -38,7 +38,7 @@ class FirebirdTest extends UnitTestCase {
function tearDown() function tearDown()
{ {
unset($this->db); //unset($this->db);
unset($this->tables); unset($this->tables);
} }
@ -98,8 +98,8 @@ class FirebirdTest extends UnitTestCase {
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
$this->db->prepare($sql); $query = $this->db->prepare($sql);
$this->db->execute(array(1,"booger's", "Gross")); $query->execute(array(1,"booger's", "Gross"));
} }

View File

@ -41,6 +41,11 @@ $test_path = "./databases/";
foreach(pdo_drivers() as $d) foreach(pdo_drivers() as $d)
{ {
if($d === 'firebird')
{
continue;
}
$src_file = "{$src_path}{$d}.php"; $src_file = "{$src_path}{$d}.php";
if(is_file($src_file)) if(is_file($src_file))
@ -52,7 +57,7 @@ foreach(pdo_drivers() as $d)
} }
// Load Firebird if there is support // Load Firebird if there is support
if(function_exists('ibase_connect') && ! in_array('firebird', pdo_drivers())) if(function_exists('ibase_connect'))// && ! in_array('firebird', pdo_drivers()))
{ {
require_once("{$src_path}firebird-ibase.php"); require_once("{$src_path}firebird-ibase.php");
require_once("{$src_path}firebird_sql.php"); require_once("{$src_path}firebird_sql.php");

Binary file not shown.