Query/tests/databases/firebird/FirebirdTest.php

260 lines
6.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
*/
// --------------------------------------------------------------------------
/**
2014-02-14 22:08:19 -05:00
* Firebirdtest class.
2012-03-15 09:25:18 -04: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 {
2012-03-15 09:25:18 -04:00
2012-04-24 14:00:44 -04:00
public function setUp()
2014-02-14 22:08:19 -05: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
2014-02-14 22:52:56 -05:00
if ( ! function_exists('fbird_connect'))
{
$this->markTestSkipped('Firebird extension does not exist');
}
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();
}
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
// --------------------------------------------------------------------------
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"');
$val = "bar";
$this->assertNull($obj->bindColumn('foo', $val));
$this->assertNull($obj->bindParam('foo', $val));
$this->assertNull($obj->bindValue('foo', $val));
}
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05:00
public function testExists()
{
$this->assertTrue(function_exists('ibase_connect'));
$this->assertTrue(function_exists('fbird_connect'));
}
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');
}
2012-04-24 14:00:44 -04: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));
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05: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
// --------------------------------------------------------------------------
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);
}
2012-04-24 14:00:44 -04: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(
2012-03-15 09:25:18 -04:00
'id' => 'SMALLINT',
'key' => 'VARCHAR(64)',
'val' => 'BLOB SUB_TYPE TEXT'
));
$this->db->query($sql);
//Check
2014-02-07 15:43:25 -05:00
$this->assertTrue(in_array('create_delete', $this->db->get_tables()));
}
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);
2012-03-15 09:25:18 -04:00
2014-02-07 15:43:25 -05:00
//Check
$table_exists = in_array('create_delete', $this->db->get_tables());
$this->assertFalse($table_exists);
}
2012-03-15 09:25:18 -04: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 testTruncate()
2012-03-15 09:25:18 -04:00
{
2014-02-14 22:08:19 -05:00
$this->markTestSkipped();
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
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05: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
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05: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
2014-02-14 22:08:19 -05: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
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05: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
// --------------------------------------------------------------------------
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"');
// Object
$fetchObj = $res->fetchObject();
$this->assertIsA($fetchObj, 'stdClass');
// Associative array
$fetchAssoc = $res->fetch(PDO::FETCH_ASSOC);
$this->assertTrue(array_key_exists('key', $fetchAssoc));
// 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
}
2012-04-24 14:00:44 -04:00
// --------------------------------------------------------------------------
2014-02-07 15:43:25 -05:00
2014-02-14 22:08:19 -05:00
public function testPrepareQuery()
2012-03-15 09:25:18 -04:00
{
2014-02-14 22:08:19 -05:00
$this->assertNull($this->db->prepare_query('', array()));
2014-02-07 15:43:25 -05:00
}
2012-04-10 14:06:34 -04:00
2012-04-24 14:00:44 -04: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()));
}
2012-04-24 14:00:44 -04: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()));
}
2012-04-24 14:00:44 -04: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
}
2012-04-24 14:00:44 -04: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()));
}
2012-03-15 09:25:18 -04:00
}