Fix some test issues and allow persistent database connections
This commit is contained in:
parent
deb9237532
commit
f6d50c678b
@ -194,7 +194,7 @@ function Query($params = '')
|
|||||||
// Create the database connection
|
// Create the database connection
|
||||||
$db = ( ! empty($params->user))
|
$db = ( ! empty($params->user))
|
||||||
? new $dbtype($dsn, $params->user, $params->pass, $options)
|
? new $dbtype($dsn, $params->user, $params->pass, $options)
|
||||||
: new $dbtype($dsn);
|
: new $dbtype($dsn, '', '', $options);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -58,10 +58,18 @@ class Firebird extends DB_PDO {
|
|||||||
* @param string $dbpath
|
* @param string $dbpath
|
||||||
* @param string $user
|
* @param string $user
|
||||||
* @param string $pass
|
* @param string $pass
|
||||||
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function __construct($dbpath, $user='SYSDBA', $pass='masterkey')
|
public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', $options = array())
|
||||||
{
|
{
|
||||||
$this->conn = fbird_connect($dbpath, $user, $pass, 'utf-8', 0);
|
if (isset($options[PDO::ATTR_PERSISTENT]) && $options[PDO::ATTR_PERSISTENT] == TRUE)
|
||||||
|
{
|
||||||
|
$this->conn = fbird_pconnect($dbpath, $user, $pass, 'utf-8', 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->conn = fbird_connect($dbpath, $user, $pass, 'utf-8', 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Throw an exception to make this match other pdo classes
|
// Throw an exception to make this match other pdo classes
|
||||||
if ( ! is_resource($this->conn)) throw new PDOException(fbird_errmsg());
|
if ( ! is_resource($this->conn)) throw new PDOException(fbird_errmsg());
|
||||||
|
@ -607,9 +607,9 @@ abstract class QBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$query = $this->db->where('id', 4)
|
$query = $this->db->where('id', 7)
|
||||||
->update('create_test', array(
|
->update('create_test', array(
|
||||||
'id' => 4,
|
'id' => 7,
|
||||||
'key' => 'gogle',
|
'key' => 'gogle',
|
||||||
'val' => 'non-word'
|
'val' => 'non-word'
|
||||||
));
|
));
|
||||||
@ -622,13 +622,13 @@ abstract class QBTest extends Query_TestCase {
|
|||||||
public function testSetArrayUpdate()
|
public function testSetArrayUpdate()
|
||||||
{
|
{
|
||||||
$array = array(
|
$array = array(
|
||||||
'id' => 4,
|
'id' => 22,
|
||||||
'key' => 'gogle',
|
'key' => 'gogle',
|
||||||
'val' => 'non-word'
|
'val' => 'non-word'
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = $this->db->set($array)
|
$query = $this->db->set($array)
|
||||||
->where('id', 4)
|
->where('id', 22)
|
||||||
->update('create_test');
|
->update('create_test');
|
||||||
|
|
||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
@ -638,8 +638,8 @@ abstract class QBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testWhereSetUpdate()
|
public function testWhereSetUpdate()
|
||||||
{
|
{
|
||||||
$query = $this->db->where('id', 4)
|
$query = $this->db->where('id', 36)
|
||||||
->set('id', 4)
|
->set('id', 36)
|
||||||
->set('key', 'gogle')
|
->set('key', 'gogle')
|
||||||
->set('val', 'non-word')
|
->set('val', 'non-word')
|
||||||
->update('test');
|
->update('test');
|
||||||
@ -651,7 +651,7 @@ abstract class QBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
$query = $this->db->delete('create_test', array('id' => 4));
|
$query = $this->db->delete('create_test', array('id' => 5));
|
||||||
|
|
||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,11 @@ class FirebirdQBTest extends QBTest {
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
||||||
|
|
||||||
|
if ( ! function_exists('fbird_connect'))
|
||||||
|
{
|
||||||
|
$this->markTestSkipped('Firebird extension does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
// test the query builder
|
// test the query builder
|
||||||
$params = new Stdclass();
|
$params = new Stdclass();
|
||||||
@ -32,6 +37,8 @@ class FirebirdQBTest extends QBTest {
|
|||||||
$params->user = 'sysdba';
|
$params->user = 'sysdba';
|
||||||
$params->pass = 'masterkey';
|
$params->pass = 'masterkey';
|
||||||
$params->prefix = 'create_';
|
$params->prefix = 'create_';
|
||||||
|
$params->options = array();
|
||||||
|
$params->options[PDO::ATTR_PERSISTENT] = TRUE;
|
||||||
$this->db = Query($params);
|
$this->db = Query($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +70,7 @@ class FirebirdQBTest extends QBTest {
|
|||||||
$params->host = 'localhost';
|
$params->host = 'localhost';
|
||||||
$params->user = 'sysdba';
|
$params->user = 'sysdba';
|
||||||
$params->pass = 'masterkey';
|
$params->pass = 'masterkey';
|
||||||
$params->prefix = 'create_';
|
$params->prefix = '';
|
||||||
$f_conn = Query($params);
|
$f_conn = Query($params);
|
||||||
|
|
||||||
$this->assertReference($f_conn, Query('fire'));
|
$this->assertReference($f_conn, Query('fire'));
|
||||||
@ -142,5 +149,4 @@ class FirebirdQBTest extends QBTest {
|
|||||||
// Queries are equal because explain is not a keyword in Firebird
|
// Queries are equal because explain is not a keyword in Firebird
|
||||||
$this->assertEqual($res, $res2);
|
$this->assertEqual($res, $res2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -26,7 +26,9 @@ class MySQLQBTest extends QBTest {
|
|||||||
$params = json_decode(file_get_contents(QBASE_DIR . "test_config.json"));
|
$params = json_decode(file_get_contents(QBASE_DIR . "test_config.json"));
|
||||||
$params = $params->mysql;
|
$params = $params->mysql;
|
||||||
$params->type = "MySQL";
|
$params->type = "MySQL";
|
||||||
$params->prefix = "create_";;
|
$params->prefix = "create_";
|
||||||
|
$params->options = array();
|
||||||
|
$params->options[PDO::ATTR_PERSISTENT] = TRUE;
|
||||||
}
|
}
|
||||||
elseif (($var = getenv('CI'))) // Travis CI Connection Info
|
elseif (($var = getenv('CI'))) // Travis CI Connection Info
|
||||||
{
|
{
|
||||||
@ -43,11 +45,6 @@ class MySQLQBTest extends QBTest {
|
|||||||
|
|
||||||
$this->db = Query($params);
|
$this->db = Query($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhereSetUpdate() {}
|
|
||||||
public function testDelete() {}
|
|
||||||
public function testSetArrayUpdate() {}
|
|
||||||
public function testUpdate() {}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class PgSQLQBTest extends QBTest {
|
|||||||
// If the database isn't installed, skip the tests
|
// If the database isn't installed, skip the tests
|
||||||
if ( ! class_exists("PgSQL"))
|
if ( ! class_exists("PgSQL"))
|
||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
$this->markTestSkipped("Postgres extension for PDO not loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to connect, if there is a test config file
|
// Attempt to connect, if there is a test config file
|
||||||
@ -32,6 +32,8 @@ class PgSQLQBTest extends QBTest {
|
|||||||
$params = $params->pgsql;
|
$params = $params->pgsql;
|
||||||
$params->type = "pgsql";
|
$params->type = "pgsql";
|
||||||
$params->prefix = 'create_';
|
$params->prefix = 'create_';
|
||||||
|
$params->options = array();
|
||||||
|
$params->options[PDO::ATTR_PERSISTENT] = TRUE;
|
||||||
}
|
}
|
||||||
elseif (($var = getenv('CI'))) // Travis CI Connection Info
|
elseif (($var = getenv('CI'))) // Travis CI Connection Info
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ class PgTest extends DBTest {
|
|||||||
// If the database isn't installed, skip the tests
|
// If the database isn't installed, skip the tests
|
||||||
if ( ! class_exists("PgSQL"))
|
if ( ! class_exists("PgSQL"))
|
||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
$this->markTestSkipped("Postgres extension for PDO not loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to connect, if there is a test config file
|
// Attempt to connect, if there is a test config file
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
$params->file = $path;
|
$params->file = $path;
|
||||||
$params->host = 'localhost';
|
$params->host = 'localhost';
|
||||||
$params->prefix = 'create_';
|
$params->prefix = 'create_';
|
||||||
|
$params->options = array();
|
||||||
|
$params->options[PDO::ATTR_PERSISTENT] = TRUE;
|
||||||
$this->db = Query($params);
|
$this->db = Query($params);
|
||||||
|
|
||||||
// echo '<hr /> SQLite Queries <hr />';
|
// echo '<hr /> SQLite Queries <hr />';
|
||||||
|
Loading…
Reference in New Issue
Block a user