diff --git a/Query/Connection_Manager.php b/Query/Connection_Manager.php
index f1f280d..ebf1fa6 100644
--- a/Query/Connection_Manager.php
+++ b/Query/Connection_Manager.php
@@ -186,7 +186,7 @@ final class Connection_Manager {
{
$dsn = "{$params->host}:{$params->file}";
}
- else if(strtolower($dbtype === 'sqlite'))
+ else if(strtolower($dbtype) === 'sqlite')
{
$dsn = $params->file;
}
@@ -212,18 +212,17 @@ final class Connection_Manager {
{
if (strtolower($dbtype) === 'pdo_firebird') $dbtype = 'firebird';
- $dsn = strtolower($dbtype) . ':';
+ $pairs = [];
if ( ! empty($params->database))
{
- $dsn .= "dbname={$params->database}";
+ $pairs[] = implode('=', ['dbname', $params->database]);
}
$skip = array(
'name' => 'name',
'pass' => 'pass',
'user' => 'user',
- 'file' => 'file',
'type' => 'type',
'prefix' => 'prefix',
'options' => 'options',
@@ -233,13 +232,13 @@ final class Connection_Manager {
foreach($params as $key => $val)
{
- if (( ! array_key_exists($key, $skip)) && ! empty($val))
+ if (( ! array_key_exists($key, $skip)) && ( ! empty($val)))
{
- $dsn .= ";{$key}={$val}";
+ $pairs[] = implode('=', [$key, $val]);
}
}
- return $dsn;
+ return strtolower($dbtype) . ':' . implode(';', $pairs);
}
}
// End of connection_manager.php
\ No newline at end of file
diff --git a/Query/Drivers/Pdo_firebird/Driver.php b/Query/Drivers/Pdo_firebird/Driver.php
new file mode 100644
index 0000000..d8e2d14
--- /dev/null
+++ b/Query/Drivers/Pdo_firebird/Driver.php
@@ -0,0 +1,88 @@
+quote_table($table);
+ $fields = \array_keys(\current($data));
+
+ $insert_template = "INSERT INTO {$table} ("
+ . implode(',', $this->quote_ident($fields))
+ . ") VALUES (";
+
+ foreach($data as $item)
+ {
+ // Quote string values
+ $vals = array_map(array($this, 'quote'), $item);
+
+ // Add the values in the sql
+ $sql .= $insert_template . implode(', ', $vals) . ");\n";
+ }
+
+ // End the block of SQL statements
+ $sql .= "END";
+
+ // Return a null array value so the query is run as it is,
+ // not as a prepared statement, because a prepared statement
+ // doesn't work for this type of query in Firebird.
+ return array($sql, NULL);
+ }
+}
+//End of firebird_driver.php
\ No newline at end of file
diff --git a/Query/Drivers/Pdo_firebird/SQL.php b/Query/Drivers/Pdo_firebird/SQL.php
new file mode 100644
index 0000000..7521ed1
--- /dev/null
+++ b/Query/Drivers/Pdo_firebird/SQL.php
@@ -0,0 +1,25 @@
+ $v)
- {
- $params_object->$k = $v;
- }
+ $params_object = (object) $params;
// Otherwise, return a new connection
return $cmanager->connect($params_object);
diff --git a/phpunit.xml b/phpunit.xml
index 182d28f..f53be02 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -32,9 +32,9 @@
tests/databases/firebird/FirebirdTest.php
tests/databases/firebird/FirebirdQBTest.php
-
+
\ No newline at end of file
diff --git a/tests/databases/pdo_firebird/PDOFirebirdQBTest.php b/tests/databases/pdo_firebird/PDOFirebirdQBTest.php
new file mode 100644
index 0000000..c0fa588
--- /dev/null
+++ b/tests/databases/pdo_firebird/PDOFirebirdQBTest.php
@@ -0,0 +1,119 @@
+markTestSkipped('PDO Firebird extension does not exist');
+ }
+
+ $dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
+
+ // test the query builder
+ $params = new Stdclass();
+ $params->alias = 'fire';
+ $params->type = 'pdo_firebird';
+ $params->database = $dbpath;
+ $params->host = 'localhost';
+ $params->user = 'SYSDBA';
+ $params->pass = 'masterkey';
+ $params->prefix = 'create_';
+
+ $this->db = Query($params);
+ }
+
+ public function testQueryFunctionAlias()
+ {
+$this->markTestSkipped();
+ $db = Query();
+
+ $this->assertTrue($this->db === $db);
+ }
+
+ public function testGetNamedConnectionException()
+ {
+ try
+ {
+ $db = Query('water');
+ }
+ catch(InvalidArgumentException $e)
+ {
+ $this->assertIsA($e, 'InvalidArgumentException');
+ }
+ }
+
+ public function testGetNamedConnection()
+ {
+ $dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
+
+ // test the query builder
+ $params = new Stdclass();
+ $params->alias = 'wood';
+ $params->type = 'pdo_firebird';
+ $params->database = $dbpath;
+ $params->host = 'localhost';
+ $params->user = 'sysdba';
+ $params->pass = 'masterkey';
+ $params->prefix = '';
+ $f_conn = Query($params);
+ $q_conn = Query('wood');
+
+ $this->assertReference($f_conn, $q_conn);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testTypeList()
+ {
+$this->markTestSkipped();
+ $this->doSetUp();
+ $sql = $this->db->get_sql()->type_list();
+ $query = $this->db->query($sql);
+
+ $this->assertIsA('PDOStatement', $query);
+
+ $res = $query->fetchAll(PDO::FETCH_ASSOC);
+
+ $this->assertTrue(is_array($res));
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testQueryExplain()
+ {
+ $res = $this->db->select('id, key as k, val')
+ ->explain()
+ ->where('id >', 1)
+ ->where('id <', 900)
+ ->limit(2, 1)
+ ->get_compiled_select();
+
+ $res2 = $this->db->select('id, key as k, val')
+ ->where('id >', 1)
+ ->where('id <', 900)
+ ->limit(2, 1)
+ ->get_compiled_select();
+
+ // Queries are equal because explain is not a keyword in Firebird
+ $this->assertEqual($res, $res2);
+ }
+}
\ No newline at end of file
diff --git a/tests/databases/pdo_firebird/PDOFirebirdTest.php b/tests/databases/pdo_firebird/PDOFirebirdTest.php
new file mode 100644
index 0000000..d45ec95
--- /dev/null
+++ b/tests/databases/pdo_firebird/PDOFirebirdTest.php
@@ -0,0 +1,283 @@
+table_prefix = 'create_';
+ }
+
+ public function setUp()
+ {
+ if ( ! in_array('firebird', PDO::getAvailableDrivers()))
+ {
+ $this->markTestSkipped('PDO Firebird extension does not exist');
+ }
+
+ $this->tables = self::$db->get_tables();
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function tearDown()
+ {
+ unset($this->tables);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testExists()
+ {
+ $this->assertTrue(in_array('firebird', PDO::getAvailableDrivers()));;
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testConnection()
+ {
+ $this->assertIsA(self::$db, '\\Query\\Drivers\\Pdo_firebird\\Driver');
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testGetSystemTables()
+ {
+ $only_system = TRUE;
+
+ $tables = self::$db->get_system_tables();
+
+ foreach($tables as $t)
+ {
+ if(stripos($t, 'rdb$') !== 0 && stripos($t, 'mon$') !== 0)
+ {
+ $only_system = FALSE;
+ break;
+ }
+ }
+
+ $this->assertTrue($only_system);
+ }
+
+ // --------------------------------------------------------------------------
+ // ! Create / Delete Tables
+ // --------------------------------------------------------------------------
+
+ public function testCreateTable()
+ {
+$this->markTestSkipped();
+ //Attempt to create the table
+ $sql = self::$db->util->create_table('create_delete', array(
+ 'id' => 'SMALLINT',
+ 'key' => 'VARCHAR(64)',
+ 'val' => 'BLOB SUB_TYPE TEXT'
+ ));
+ self::$db->query($sql);
+
+ //Check
+ $this->assertTrue(in_array('create_delete', self::$db->get_tables()));
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testDeleteTable()
+ {
+$this->markTestSkipped();
+ //Attempt to delete the table
+ $sql = self::$db->util->delete_table('create_delete');
+ self::$db->query($sql);
+
+ //Check
+ $table_exists = in_array('create_delete', self::$db->get_tables());
+ $this->assertFalse($table_exists);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testTruncate()
+ {
+$this->markTestSkipped();
+ self::$db->truncate('create_test');
+
+ $this->assertTrue(self::$db->affected_rows() > 0);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testCommitTransaction()
+ {
+$this->markTestSkipped();
+ $res = self::$db->beginTransaction();
+
+ $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
+ self::$db->query($sql);
+
+ $res = self::$db->commit();
+ $this->assertTrue($res);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testRollbackTransaction()
+ {
+$this->markTestSkipped();
+ $res = self::$db->beginTransaction();
+
+ $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
+ self::$db->query($sql);
+
+ $res = self::$db->rollback();
+ $this->assertTrue($res);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testPreparedStatements()
+ {
+$this->markTestSkipped();
+ $sql = <<prepare($sql);
+ $query->execute(array(1,"booger's", "Gross"));
+
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testPrepareExecute()
+ {
+ $sql = <<prepare_execute($sql, array(
+ 2, "works", 'also?'
+ ));
+
+ }
+
+ // --------------------------------------------------------------------------
+
+ /*public function testFetch()
+ {
+ $res = self::$db->query('SELECT "key","val" FROM "create_test"');
+
+ // Object
+ $fetchObj = $res->fetchObject();
+ $this->assertIsA($fetchObj, 'stdClass');
+
+ // Associative array
+ $fetchAssoc = $res->fetch(PDO::FETCH_ASSOC);
+ $this->assertTrue(is_array($fetchAssoc));
+ $this->assertTrue(array_key_exists('key', $fetchAssoc));
+
+ // Numeric array
+ $res2 = self::$db->query('SELECT "id","key","val" FROM "create_test"');
+ $fetch = $res2->fetch(PDO::FETCH_NUM);
+ $this->assertTrue(is_array($fetch));
+ }*/
+
+ // --------------------------------------------------------------------------
+
+ /*public function testPrepareQuery()
+ {
+ $this->assertNull(self::$db->prepare_query('', array()));
+ }*/
+
+ // --------------------------------------------------------------------------
+
+ public function testErrorInfo()
+ {
+ $result = self::$db->errorInfo();
+
+ $expected = array (
+ 0 => 0,
+ 1 => false,
+ 2 => false,
+ );
+
+ $this->assertEqual($expected, $result);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testErrorCode()
+ {
+ $result = self::$db->errorCode();
+ $this->assertEquals(00000, $result);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testDBList()
+ {
+ $res = self::$db->get_sql()->db_list();
+ $this->assertNULL($res);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /*public function testExec()
+ {
+ $res = self::$db->exec('SELECT * FROM "create_test"');
+ $this->assertEquals(NULL, $res);
+ }*/
+
+ // --------------------------------------------------------------------------
+
+ public function testInTransaction()
+ {
+$this->markTestSkipped();
+ self::$db->beginTransaction();
+ $this->assertTrue(self::$db->inTransaction());
+ self::$db->rollBack();
+ $this->assertFalse(self::$db->inTransaction());
+ }
+
+ // --------------------------------------------------------------------------
+
+ /*public function testGetAttribute()
+ {
+ $res = self::$db->getAttribute("foo");
+ $this->assertEquals(NULL, $res);
+ }
+
+ // --------------------------------------------------------------------------
+
+ public function testSetAttribute()
+ {
+ $this->assertFalse(self::$db->setAttribute(47, 'foo'));
+ }*/
+
+ public function testLastInsertId()
+ {
+$this->markTestSkipped();
+ $this->assertEqual(0, self::$db->lastInsertId('NEWTABLE_SEQ'));
+ }
+}
\ No newline at end of file
diff --git a/tests/databases/sqlite/SQLiteTest.php b/tests/databases/sqlite/SQLiteTest.php
index 391c797..52f66ff 100644
--- a/tests/databases/sqlite/SQLiteTest.php
+++ b/tests/databases/sqlite/SQLiteTest.php
@@ -33,9 +33,7 @@ class SQLiteTest extends DBTest {
)
);
- Query($params);
-
- self::$db = Query('test_sqlite');
+ self::$db = Query($params);
self::$db->table_prefix = 'create_';
}