2012-02-02 19:04:10 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OpenSQLManager
|
|
|
|
*
|
|
|
|
* Free Database manager for Open Source Databases
|
|
|
|
*
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FirebirdTest class.
|
|
|
|
*
|
|
|
|
* @extends UnitTestCase
|
|
|
|
*/
|
|
|
|
class FirebirdTest extends UnitTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __construct function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2012-02-10 17:57:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUp()
|
|
|
|
{
|
2012-03-06 21:32:49 -05:00
|
|
|
$dbpath = TEST_DIR.DS.'test_dbs'.DS.'FB_TEST_DB.FDB';
|
2012-03-08 09:15:42 -05:00
|
|
|
|
|
|
|
// Test the db driver directly
|
2012-03-07 21:01:48 -05:00
|
|
|
$this->db = new Firebird('localhost:'.$dbpath);
|
2012-03-08 09:15:42 -05:00
|
|
|
|
|
|
|
// Test the query builder
|
|
|
|
$params = new Stdclass();
|
|
|
|
$params->type = 'firebird';
|
|
|
|
$params->file = $dbpath;
|
|
|
|
$params->host = 'localhost';
|
|
|
|
$params->user = 'sysdba';
|
|
|
|
$params->pass = 'masterkey';
|
|
|
|
$this->qb = new Query_Builder($params);
|
|
|
|
|
2012-02-10 17:57:10 -05:00
|
|
|
$this->tables = $this->db->get_tables();
|
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown()
|
|
|
|
{
|
2012-03-07 15:21:44 -05:00
|
|
|
unset($this->db);
|
2012-02-10 17:57:10 -05:00
|
|
|
unset($this->tables);
|
2012-02-02 19:04:10 -05:00
|
|
|
}
|
2012-02-07 08:18:38 -05:00
|
|
|
|
|
|
|
function TestConnection()
|
|
|
|
{
|
2012-02-07 08:45:56 -05:00
|
|
|
$this->assertIsA($this->db, 'Firebird');
|
2012-02-07 08:18:38 -05:00
|
|
|
}
|
2012-02-08 15:05:28 -05:00
|
|
|
|
2012-02-09 12:00:39 -05:00
|
|
|
function TestGetTables()
|
2012-02-08 15:05:28 -05:00
|
|
|
{
|
2012-02-10 17:57:10 -05:00
|
|
|
$tables = $this->tables;
|
|
|
|
$this->assertTrue(is_array($tables));
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestGetSystemTables()
|
|
|
|
{
|
|
|
|
$only_system = TRUE;
|
|
|
|
|
|
|
|
foreach($this->tables as $t)
|
|
|
|
{
|
|
|
|
if(stripos($t, 'rdb$') !== 0 && stripos($t, 'mon$') !== 0)
|
|
|
|
{
|
|
|
|
$only_system = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($only_system);
|
2012-02-08 15:05:28 -05:00
|
|
|
}
|
2012-03-06 16:53:40 -05:00
|
|
|
|
|
|
|
function TestCreateTransaction()
|
|
|
|
{
|
|
|
|
$res = $this->db->beginTransaction();
|
|
|
|
$this->assertTrue($res);
|
|
|
|
}
|
2012-02-08 13:42:49 -05:00
|
|
|
|
2012-02-22 09:37:14 -05:00
|
|
|
function TestCreateTable()
|
2012-02-08 13:42:49 -05:00
|
|
|
{
|
2012-02-08 15:05:28 -05:00
|
|
|
//Attempt to create the table
|
2012-02-29 14:36:42 -05:00
|
|
|
$sql = $this->db->sql->create_table('create_test', array(
|
2012-02-28 22:07:13 -05:00
|
|
|
'id' => 'SMALLINT',
|
|
|
|
'key' => 'VARCHAR(64)',
|
|
|
|
'val' => 'BLOB SUB_TYPE TEXT'
|
|
|
|
));
|
2012-02-08 15:05:28 -05:00
|
|
|
$this->db->query($sql);
|
2012-02-09 12:00:39 -05:00
|
|
|
|
2012-02-22 09:37:14 -05:00
|
|
|
//This test fails for an unknown reason, when clearly the table exists
|
2012-02-10 17:57:10 -05:00
|
|
|
//Reset
|
2012-03-08 12:37:33 -05:00
|
|
|
$this->tearDown();
|
2012-02-10 17:57:10 -05:00
|
|
|
$this->setUp();
|
|
|
|
|
2012-02-09 12:00:39 -05:00
|
|
|
//Check
|
2012-03-08 12:37:33 -05:00
|
|
|
/*$table_exists = (bool)in_array('create_test', $this->tables);
|
2012-02-10 17:57:10 -05:00
|
|
|
|
|
|
|
echo "create_test exists :".(int)$table_exists.'<br />';
|
|
|
|
|
2012-02-13 13:46:53 -05:00
|
|
|
$this->assertTrue($table_exists);*/
|
2012-02-08 13:42:49 -05:00
|
|
|
}
|
2012-02-23 11:26:08 -05:00
|
|
|
|
2012-03-06 16:53:40 -05:00
|
|
|
function TestCommitTransaction()
|
|
|
|
{
|
|
|
|
$this->TestCreateTransaction();
|
|
|
|
|
|
|
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
|
|
|
$this->db->query($sql);
|
|
|
|
|
|
|
|
$res = $this->db->commit();
|
|
|
|
$this->assertTrue($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestRollbackTransaction()
|
|
|
|
{
|
|
|
|
$this->TestCreateTransaction();
|
|
|
|
|
|
|
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
|
|
|
$this->db->query($sql);
|
|
|
|
|
|
|
|
$res = $this->db->rollback();
|
|
|
|
$this->assertTrue($res);
|
|
|
|
}
|
|
|
|
|
2012-03-08 12:37:33 -05:00
|
|
|
function TestQBGet()
|
|
|
|
{
|
|
|
|
$query = $this->qb->get('create_test');
|
|
|
|
|
|
|
|
$this->assertTrue(is_resource($query));
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestQBGetLimit()
|
|
|
|
{
|
|
|
|
$query = $this->qb->get('create_test', 2);
|
|
|
|
|
|
|
|
$this->assertTrue(is_resource($query));
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestQBGetLimitSkip()
|
|
|
|
{
|
|
|
|
$query = $this->qb->get('create_test', 2, 1);
|
|
|
|
|
|
|
|
$this->assertTrue(is_resource($query));
|
|
|
|
}
|
|
|
|
|
2012-03-09 08:26:16 -05:00
|
|
|
function TestQBSelectGet()
|
|
|
|
{
|
|
|
|
$query = $this->qb->select('id, key as k, val')->get('create_test', 2, 1);
|
|
|
|
|
|
|
|
$this->assertTrue(is_resource($query));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-23 11:26:08 -05:00
|
|
|
function TestPreparedStatements()
|
|
|
|
{
|
|
|
|
$sql = <<<SQL
|
|
|
|
INSERT INTO "create_test" ("id", "key", "val")
|
|
|
|
VALUES (?,?,?)
|
|
|
|
SQL;
|
2012-03-06 16:20:59 -05:00
|
|
|
$this->db->prepare($sql);
|
|
|
|
$this->db->execute(array(1,"booger's", "Gross"));
|
2012-02-23 11:26:08 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
|
|
|
}
|
2012-02-08 13:42:49 -05:00
|
|
|
|
2012-02-22 09:37:14 -05:00
|
|
|
function TestDeleteTable()
|
2012-02-08 13:42:49 -05:00
|
|
|
{
|
2012-02-09 12:00:39 -05:00
|
|
|
//Attempt to delete the table
|
2012-02-29 14:36:42 -05:00
|
|
|
$sql = $this->db->sql->delete_table('create_test');
|
2012-02-08 15:05:28 -05:00
|
|
|
$this->db->query($sql);
|
2012-02-09 12:00:39 -05:00
|
|
|
|
2012-02-10 17:57:10 -05:00
|
|
|
//Reset
|
|
|
|
$this->tearDown();
|
|
|
|
$this->setUp();
|
|
|
|
|
2012-02-09 12:00:39 -05:00
|
|
|
//Check
|
2012-02-10 17:57:10 -05:00
|
|
|
$table_exists = in_array('create_test', $this->tables);
|
2012-02-09 12:00:39 -05:00
|
|
|
$this->assertFalse($table_exists);
|
|
|
|
}
|
2012-02-02 19:04:10 -05:00
|
|
|
}
|