diff --git a/.gitignore b/.gitignore index d910a93..fb35caa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ settings.json errors.txt */simpletest/* -tests/test_dbs/* \ No newline at end of file +tests/test_dbs/* +*.db +*.FDB \ No newline at end of file diff --git a/src/common/db_pdo.php b/src/common/db_pdo.php index f994c36..3417b33 100644 --- a/src/common/db_pdo.php +++ b/src/common/db_pdo.php @@ -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; diff --git a/src/databases/firebird.php b/src/databases/firebird.php index adba703..0a46cae 100644 --- a/src/databases/firebird.php +++ b/src/databases/firebird.php @@ -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 \ No newline at end of file diff --git a/src/databases/firebird_manip.php b/src/databases/firebird_manip.php index e5a844f..5247305 100644 --- a/src/databases/firebird_manip.php +++ b/src/databases/firebird_manip.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; } diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php index eb05935..3ba8de8 100644 --- a/tests/databases/firebird.php +++ b/tests/databases/firebird.php @@ -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 @@ -87,6 +87,34 @@ class FirebirdTest extends UnitTestCase { $this->assertTrue($table_exists);*/ } + + function TestPreparedStatements() + { + $sql = <<db->prepare($sql); + $this->db->execute(array(1,"boogers", "Gross")); + + } + + function TestPrepareExecute() + { + $sql = <<db->prepare_execute($sql, array( + 2, "works", 'also?' + )); + + } + + function TestPrepareQuery() + { + $this->assertFalse($this->db->prepare_query('', array())); + } function TestDeleteTable() { @@ -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)); - - } + } \ No newline at end of file diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index bf379a6..8687efd 100755 Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index 64b32b8..1b2cd50 100755 Binary files a/tests/test_dbs/test_sqlite.db and b/tests/test_dbs/test_sqlite.db differ