Query/tests/databases/firebird/FirebirdTest.php

292 lines
6.9 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
* @copyright Copyright (c) 2012 - 2014
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
*/
// --------------------------------------------------------------------------
/**
2014-02-14 22:08:19 -05:00
* Firebirdtest class.
2014-02-25 13:47:35 -05:00
*
2014-02-14 22:08:19 -05:00
* @extends DBtest
* @requires extension interbase
2012-03-15 09:25:18 -04:00
*/
2014-02-14 22:08:19 -05:00
class FirebirdTest extends DBtest {
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
public function setUp()
2014-02-25 13:47:35 -05:00
{
2012-04-30 16:06:06 -04:00
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
2014-02-25 13:47:35 -05:00
2014-02-14 22:52:56 -05:00
if ( ! function_exists('fbird_connect'))
{
$this->markTestSkipped('Firebird extension does not exist');
}
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
// test the db driver directly
2012-03-15 09:25:18 -04:00
$this->db = new Firebird('localhost:'.$dbpath);
$this->tables = $this->db->get_tables();
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
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);
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
/**
* coverage for methods in result class that aren't implemented
*/
2014-02-14 22:08:19 -05:00
public function testNullResultMethods()
2014-02-07 15:43:25 -05:00
{
$obj = $this->db->query('SELECT "id" FROM "create_test"');
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
$val = "bar";
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
$this->assertNull($obj->bindColumn('foo', $val));
$this->assertNull($obj->bindParam('foo', $val));
$this->assertNull($obj->bindValue('foo', $val));
2014-02-20 11:00:18 -05:00
}
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testExists()
{
$this->assertTrue(function_exists('ibase_connect'));
$this->assertTrue(function_exists('fbird_connect'));
2014-02-25 13:47:35 -05:00
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2014-02-14 22:08:19 -05:00
public function testConnection()
2012-03-15 09:25:18 -04:00
{
$this->assertIsA($this->db, 'Firebird');
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetTables()
2012-03-15 09:25:18 -04:00
{
$tables = $this->tables;
$this->assertTrue(is_array($tables));
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetSystemTables()
2014-02-25 13:47:35 -05:00
{
2012-03-15 09:25:18 -04:00
$only_system = TRUE;
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$tables = $this->db->get_system_tables();
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
foreach($tables as $t)
{
if(stripos($t, 'rdb$') !== 0 && stripos($t, 'mon$') !== 0)
{
$only_system = FALSE;
break;
}
}
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$this->assertTrue($only_system);
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testCreateTransaction()
2012-03-15 09:25:18 -04:00
{
$res = $this->db->beginTransaction();
$this->assertTrue($res);
}
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
// --------------------------------------------------------------------------
// ! Create / Delete Tables
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2012-03-15 09:25:18 -04:00
2014-02-14 22:08:19 -05:00
public function testCreateTable()
2012-03-15 09:25:18 -04:00
{
//Attempt to create the table
2014-02-07 15:43:25 -05:00
$sql = $this->db->util->create_table('create_delete', array(
2014-02-25 13:47:35 -05:00
'id' => 'SMALLINT',
'key' => 'VARCHAR(64)',
2012-03-15 09:25:18 -04:00
'val' => 'BLOB SUB_TYPE TEXT'
));
$this->db->query($sql);
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
//Check
2014-02-07 15:43:25 -05:00
$this->assertTrue(in_array('create_delete', $this->db->get_tables()));
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05:00
public function testDeleteTable()
2014-02-07 15:43:25 -05:00
{
//Attempt to delete the table
$sql = $this->db->util->delete_table('create_delete');
$this->db->query($sql);
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
//Check
$table_exists = in_array('create_delete', $this->db->get_tables());
$this->assertFalse($table_exists);
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testTruncate()
2012-03-15 09:25:18 -04:00
{
$this->db->truncate('create_test');
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$this->assertTrue($this->db->affected_rows() > 0);
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testCommitTransaction()
2012-03-15 09:25:18 -04:00
{
$res = $this->db->beginTransaction();
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
$this->db->query($sql);
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$res = $this->db->commit();
$this->assertTrue($res);
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testRollbackTransaction()
2012-03-15 09:25:18 -04:00
{
$res = $this->db->beginTransaction();
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
$this->db->query($sql);
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
$res = $this->db->rollback();
$this->assertTrue($res);
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testPreparedStatements()
2012-03-15 09:25:18 -04:00
{
$sql = <<<SQL
2014-02-25 13:47:35 -05:00
INSERT INTO "create_test" ("id", "key", "val")
2012-03-15 09:25:18 -04:00
VALUES (?,?,?)
SQL;
$query = $this->db->prepare($sql);
$query->execute(array(1,"booger's", "Gross"));
2012-03-15 09:25:18 -04:00
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testPrepareExecute()
2012-03-15 09:25:18 -04:00
{
$sql = <<<SQL
2014-02-25 13:47:35 -05:00
INSERT INTO "create_test" ("id", "key", "val")
2012-03-15 09:25:18 -04:00
VALUES (?,?,?)
SQL;
$this->db->prepare_execute($sql, array(
2, "works", 'also?'
));
2014-02-25 13:47:35 -05:00
2012-03-15 09:25:18 -04:00
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testFetch()
2012-03-15 09:25:18 -04:00
{
2014-02-07 15:43:25 -05:00
$res = $this->db->query('SELECT "key","val" FROM "create_test"');
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
// Object
$fetchObj = $res->fetchObject();
$this->assertIsA($fetchObj, 'stdClass');
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
// Associative array
$fetchAssoc = $res->fetch(PDO::FETCH_ASSOC);
$this->assertTrue(array_key_exists('key', $fetchAssoc));
2014-02-25 13:47:35 -05:00
2014-02-07 15:43:25 -05:00
// Numeric array
$res2 = $this->db->query('SELECT "id","key","val" FROM "create_test"');
$fetch = $res2->fetch(PDO::FETCH_NUM);
$this->assertTrue(is_array($fetch));
2012-03-15 09:25:18 -04:00
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testPrepareQuery()
2012-03-15 09:25:18 -04:00
{
2014-02-25 13:47:35 -05:00
$this->assertNull($this->db->prepare_query('', array()));
2014-02-07 15:43:25 -05:00
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetSequences()
2012-04-10 14:06:34 -04:00
{
$this->assertTrue(is_array($this->db->get_sequences()));
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetProcedures()
2012-04-10 14:06:34 -04:00
{
$this->assertTrue(is_array($this->db->get_procedures()));
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05: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
}
2014-02-25 13:47:35 -05:00
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetTriggers()
2012-04-10 14:06:34 -04:00
{
$this->assertTrue(is_array($this->db->get_triggers()));
}
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
public function testErrorInfo()
{
$result = $this->db->errorInfo();
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
$expected = array (
0 => 0,
1 => false,
2 => false,
);
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
$this->assertEqual($expected, $result);
}
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
public function testErrorCode()
2014-02-20 11:00:18 -05:00
{
$result = $this->db->errorCode();
$this->assertFalse($result);
}
2014-02-25 13:47:35 -05:00
2014-02-20 11:00:18 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
public function testDBList()
2014-02-20 11:00:18 -05:00
{
$res = $this->db->sql->db_list();
$this->assertNULL($res);
}
2012-03-15 09:25:18 -04:00
}