Query/tests/databases/firebird/firebird.php

228 lines
5.3 KiB
PHP
Raw Normal View History

2012-03-15 09:25:18 -04:00
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
2012-04-20 13:17:39 -04:00
* @package Query
* @author Timothy J. Warren
2013-01-02 14:26:42 -05:00
* @copyright Copyright (c) 2012 - 2013
2012-03-15 09:25:18 -04:00
* @link https://github.com/aviat4ion/Query
2012-04-20 13:17:39 -04:00
* @license http://philsturgeon.co.uk/code/dbad-license
2012-03-15 09:25:18 -04:00
*/
// --------------------------------------------------------------------------
/**
* FirebirdTest class.
*
* @extends UnitTestCase
*/
2012-03-19 13:38:49 -04:00
class FirebirdTest extends DBTest {
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
public function setUp()
2012-03-15 09:25:18 -04:00
{
2012-04-30 16:06:06 -04:00
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
2012-03-15 09:25:18 -04:00
// Test the db driver directly
$this->db = new Firebird('localhost:'.$dbpath);
$this->tables = $this->db->get_tables();
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function tearDown()
2012-03-15 09:25:18 -04:00
{
unset($this->db);
unset($this->tables);
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestExists()
{
$this->assertTrue(function_exists('ibase_connect'));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
public function TestConnection()
2012-03-15 09:25:18 -04:00
{
$this->assertIsA($this->db, 'Firebird');
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestGetTables()
2012-03-15 09:25:18 -04:00
{
$tables = $this->tables;
$this->assertTrue(is_array($tables));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestGetSystemTables()
2012-03-15 09:25:18 -04:00
{
$only_system = TRUE;
$tables = $this->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);
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestCreateTransaction()
2012-03-15 09:25:18 -04:00
{
$res = $this->db->beginTransaction();
$this->assertTrue($res);
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
/*public function TestCreateTable()
2012-03-15 09:25:18 -04:00
{
//Attempt to create the table
$sql = $this->db->util->create_table('create_test', array(
2012-03-15 09:25:18 -04:00
'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
//Reset
$this->tearDown();
$this->setUp();
//Check
$table_exists = (bool)in_array('create_test', $this->tables);
//echo "create_test exists :".(int)$table_exists.'<br />';
2012-03-15 09:25:18 -04:00
$this->assertTrue($table_exists);
}*/
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
public function TestTruncate()
2012-03-15 09:25:18 -04:00
{
$this->db->truncate('create_test');
$this->assertTrue($this->db->affected_rows() > 0);
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestCommitTransaction()
2012-03-15 09:25:18 -04:00
{
$res = $this->db->beginTransaction();
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
$this->db->query($sql);
$res = $this->db->commit();
$this->assertTrue($res);
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestRollbackTransaction()
2012-03-15 09:25:18 -04:00
{
$res = $this->db->beginTransaction();
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
$this->db->query($sql);
$res = $this->db->rollback();
$this->assertTrue($res);
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
public function TestPreparedStatements()
2012-03-15 09:25:18 -04:00
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$query = $this->db->prepare($sql);
$query->execute(array(1,"booger's", "Gross"));
2012-03-15 09:25:18 -04:00
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestPrepareExecute()
2012-03-15 09:25:18 -04:00
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->db->prepare_execute($sql, array(
2, "works", 'also?'
));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestPrepareQuery()
2012-03-15 09:25:18 -04:00
{
$this->assertFalse($this->db->prepare_query('', array()));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
/*public function TestDeleteTable()
2012-03-15 09:25:18 -04:00
{
//Attempt to delete the table
$sql = $this->db->util->delete_table('create_test');
2012-03-15 09:25:18 -04:00
$this->db->query($sql);
//Reset
$this->tearDown();
$this->setUp();
//Check
$table_exists = in_array('create_test', $this->tables);
$this->assertFalse($table_exists);
}*/
2012-04-10 14:06:34 -04:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestGetSequences()
2012-04-10 14:06:34 -04:00
{
$this->assertTrue(is_array($this->db->get_sequences()));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestGetProcedures()
2012-04-10 14:06:34 -04:00
{
$this->assertTrue(is_array($this->db->get_procedures()));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-04-24 14:03:54 -04:00
public function TestGetFunctions()
2012-04-10 14:06:34 -04:00
{
2012-04-24 14:03:54 -04:00
$this->assertTrue(is_array($this->db->get_functions()));
2012-04-10 14:06:34 -04:00
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
public function TestGetTriggers()
2012-04-10 14:06:34 -04:00
{
$this->assertTrue(is_array($this->db->get_triggers()));
}
2012-03-15 09:25:18 -04:00
}