Fixed prepared statements in Firebird driver
This commit is contained in:
parent
c4ff05074f
commit
89a014685d
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ settings.json
|
||||
errors.txt
|
||||
*/simpletest/*
|
||||
tests/test_dbs/*
|
||||
*.db
|
||||
*.FDB
|
@ -42,7 +42,7 @@ abstract class DB_PDO extends PDO {
|
||||
// Prepare the sql
|
||||
$query = $this->prepare($sql);
|
||||
|
||||
if( ! is_like_array($query))
|
||||
if( ! (is_object($query) || is_resource($query)))
|
||||
{
|
||||
$this->get_last_error();
|
||||
return FALSE;
|
||||
@ -52,7 +52,7 @@ abstract class DB_PDO extends PDO {
|
||||
$this->statement =& $query;
|
||||
|
||||
|
||||
if( ! is_like_array($data))
|
||||
if( ! (is_array($data) || is_object($data)))
|
||||
{
|
||||
trigger_error("Invalid data argument");
|
||||
return FALSE;
|
||||
|
@ -118,9 +118,10 @@ class firebird extends DB_PDO {
|
||||
/**
|
||||
* Emulate PDO prepare
|
||||
*
|
||||
* @param string $query
|
||||
* @return resource
|
||||
*/
|
||||
public function prepare()
|
||||
public function prepare($query)
|
||||
{
|
||||
$this->statement = ibase_prepare($this->conn, $query);
|
||||
return $this->statement;
|
||||
@ -248,8 +249,43 @@ SQL;
|
||||
*/
|
||||
public function execute($args)
|
||||
{
|
||||
// Is there a better way to do this?
|
||||
return eval('ibase_execute('.$this->statement.','.explode(',', $args).")");
|
||||
//Add the prepared statement as the first parameter
|
||||
array_unshift($args, $this->statement);
|
||||
|
||||
// Let php do all the hard stuff in converting
|
||||
// the array of arguments into a list of arguments
|
||||
return call_user_func_array('ibase_execute', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare and execute a query
|
||||
*
|
||||
* @param string $sql
|
||||
* @param array $args
|
||||
* @return resource
|
||||
*/
|
||||
public function prepare_execute($sql, $args)
|
||||
{
|
||||
$query = $this->prepare($sql);
|
||||
|
||||
// Set the statement in the class variable for easy later access
|
||||
$this->statement =& $query;
|
||||
|
||||
return $this->execute($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a prepared query with arguments for executing
|
||||
*
|
||||
* @param string $sql
|
||||
* @param mixed $args
|
||||
* @return FALSE
|
||||
*/
|
||||
public function prepare_query($sql, $args)
|
||||
{
|
||||
// You can't bind query statements before execution with
|
||||
// the firebird database
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
// End of firebird.php
|
@ -62,7 +62,7 @@ class firebird_manip extends db_manip {
|
||||
$columns = array();
|
||||
foreach($column_array as $n => $props)
|
||||
{
|
||||
$str = "{$n} ";
|
||||
$str = '"'.$n.'" ';
|
||||
$str .= (isset($props['type'])) ? "{$props['type']} " : "";
|
||||
$str .= (isset($props['constraint'])) ? "{$props['constraint']} " : "";
|
||||
|
||||
@ -70,9 +70,9 @@ class firebird_manip extends db_manip {
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = "CREATE TABLE \"{$name}\" (";
|
||||
$sql .= implode(",", $columns);
|
||||
$sql .= ")";
|
||||
$sql = 'CREATE TABLE "'.$name.'" (';
|
||||
$sql .= implode(',', $columns);
|
||||
$sql .= ')';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class FirebirdTest extends UnitTestCase {
|
||||
function TestCreateTable()
|
||||
{
|
||||
//Attempt to create the table
|
||||
$sql = $this->db->manip->create_table('create_test', array('id' => 'SMALLINT'));
|
||||
$sql = $this->db->manip->create_table('create_test', array('id' => 'SMALLINT', 'key' => 'VARCHAR(64)', 'val' => 'BLOB SUB_TYPE TEXT'));
|
||||
$this->db->query($sql);
|
||||
|
||||
//This test fails for an unknown reason, when clearly the table exists
|
||||
@ -88,6 +88,34 @@ class FirebirdTest extends UnitTestCase {
|
||||
$this->assertTrue($table_exists);*/
|
||||
}
|
||||
|
||||
function TestPreparedStatements()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
INSERT INTO "create_test" ("id", "key", "val")
|
||||
VALUES (?,?,?)
|
||||
SQL;
|
||||
$this->db->prepare($sql);
|
||||
$this->db->execute(array(1,"boogers", "Gross"));
|
||||
|
||||
}
|
||||
|
||||
function TestPrepareExecute()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
INSERT INTO "create_test" ("id", "key", "val")
|
||||
VALUES (?,?,?)
|
||||
SQL;
|
||||
$this->db->prepare_execute($sql, array(
|
||||
2, "works", 'also?'
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
function TestPrepareQuery()
|
||||
{
|
||||
$this->assertFalse($this->db->prepare_query('', array()));
|
||||
}
|
||||
|
||||
function TestDeleteTable()
|
||||
{
|
||||
//Attempt to delete the table
|
||||
@ -103,12 +131,5 @@ class FirebirdTest extends UnitTestCase {
|
||||
$this->assertFalse($table_exists);
|
||||
}
|
||||
|
||||
function TestPreparedStatements()
|
||||
{
|
||||
$sql = 'INSERT INTO "create_test" ("id") VALUES (?),(?),(?)';
|
||||
$this->db->prepare($sql);
|
||||
|
||||
$this->db->execute(array(1,2,3));
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user