Query/tests/databases/firebird/FirebirdQBTest.php

173 lines
3.7 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
*/
// --------------------------------------------------------------------------
/**
* Firebird Query Builder Tests
2014-02-14 22:08:19 -05:00
* @requires extension interbase
2012-03-15 09:25:18 -04:00
*/
class FirebirdQBTest extends QBTest {
2014-02-25 13:47:35 -05:00
2014-02-07 16:53:01 -05: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
if ( ! function_exists('fbird_connect'))
{
$this->markTestSkipped('Firebird extension does not exist');
}
2012-03-15 09:25:18 -04:00
2014-02-14 22:08:19 -05:00
// test the query builder
2012-03-15 09:25:18 -04:00
$params = new Stdclass();
2014-02-07 16:53:01 -05:00
$params->alias = 'fire';
2012-03-15 09:25:18 -04:00
$params->type = 'firebird';
$params->file = $dbpath;
$params->host = '127.0.0.1';
$params->user = 'SYSDBA';
2012-03-15 09:25:18 -04:00
$params->pass = 'masterkey';
2012-11-07 08:42:34 -05:00
$params->prefix = 'create_';
$this->db = Query($params);
2014-02-07 16:53:01 -05:00
}
2014-02-25 13:47:35 -05:00
2014-02-07 16:53:01 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetNamedConnectionException()
2014-02-07 16:53:01 -05:00
{
2014-02-25 13:47:35 -05:00
try
2014-02-07 16:53:01 -05:00
{
$db = Query('fire');
}
catch(InvalidArgumentException $e)
{
2014-02-14 22:08:19 -05:00
$this->assertIsA($e, 'InvalidArgumentException');
2014-02-07 16:53:01 -05:00
}
}
2014-02-25 13:47:35 -05:00
2014-02-07 16:53:01 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetNamedConnection()
2014-02-07 16:53:01 -05:00
{
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
2014-02-14 22:08:19 -05:00
// test the query builder
2014-02-07 16:53:01 -05:00
$params = new Stdclass();
$params->alias = 'fire';
$params->type = 'firebird';
$params->file = $dbpath;
$params->host = 'localhost';
$params->user = 'sysdba';
$params->pass = 'masterkey';
$params->prefix = '';
2014-02-07 16:53:01 -05:00
$f_conn = Query($params);
2014-02-25 13:47:35 -05:00
2014-02-07 16:53:01 -05:00
$this->assertReference($f_conn, Query('fire'));
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetCompiledSelect()
2013-12-06 23:37:43 -05:00
{
$sql = $this->db->get_compiled_select('create_test');
$qb_res = $this->db->get('create_test');
$sql_res = $this->db->query($sql);
2014-02-25 13:47:35 -05:00
2013-12-06 23:37:43 -05:00
$this->assertIsA($qb_res, 'Firebird_Result');
$this->assertIsA($sql_res, 'Firebird_Result');
}
2014-02-14 22:08:19 -05:00
public function testInsertBatch()
{
if (empty($this->db)) return;
2014-02-25 13:47:35 -05:00
$insert_array = array(
array(
'id' => 6,
'key' => 2,
'val' => 3
),
array(
'id' => 5,
'key' => 6,
'val' => 7
),
array(
'id' => 8,
'key' => 1,
'val' => 2
)
);
$query = $this->db->insert_batch('test', $insert_array);
$this->assertNull($query);
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05:00
public function testTypeList()
2012-05-08 15:37:36 -04:00
{
$sql = $this->db->sql->type_list();
$query = $this->db->query($sql);
2012-05-08 15:37:36 -04:00
$this->assertIsA($query, 'PDOStatement');
2012-05-08 15:37:36 -04:00
$res = $query->fetchAll(PDO::FETCH_ASSOC);
2012-05-08 15:37:36 -04:00
$this->assertTrue(is_array($res));
}
2014-02-25 13:47:35 -05:00
2014-02-06 17:07:29 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-06 17:07:29 -05:00
public function testQueryExplain()
{
$res = $this->db->select('id, key as k, val')
->explain()
->where('id >', 1)
->where('id <', 900)
->limit(2, 1)
2014-02-14 10:38:25 -05:00
->get_compiled_select();
2014-02-25 13:47:35 -05:00
2014-02-14 10:38:25 -05:00
$res2 = $this->db->select('id, key as k, val')
->where('id >', 1)
->where('id <', 900)
->limit(2, 1)
->get_compiled_select();
2014-02-25 13:47:35 -05:00
2014-02-14 10:38:25 -05:00
// Queries are equal because explain is not a keyword in Firebird
$this->assertEqual($res, $res2);
2014-02-06 17:07:29 -05:00
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
public function testResultErrors()
{
$obj = $this->db->query('SELECT * FROM "create_test"');
// Test row count
$this->assertEqual(0, $obj->rowCount());
// Test error code
$this->assertFalse($obj->errorCode());
// Test error info
$error = $obj->errorInfo();
$expected = array (
0 => 0,
1 => false,
2 => false,
);
$this->assertEqual($expected, $error);
}
2012-03-15 09:25:18 -04:00
}