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
|
2014-02-18 15:18:01 -05:00
|
|
|
* @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
|
|
|
*/
|
2012-03-19 13:24:36 -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
|
|
|
|
2014-02-18 14:50:20 -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;
|
2014-03-26 20:49:33 -04:00
|
|
|
$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_';
|
2012-11-08 14:28:49 -05:00
|
|
|
$this->db = Query($params);
|
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-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';
|
2012-11-08 14:28:49 -05:00
|
|
|
|
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';
|
2014-02-18 14:50:20 -05:00
|
|
|
$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'));
|
2012-04-20 16:33:40 -04: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');
|
|
|
|
}
|
2013-05-01 15:59:23 -04:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
public function testInsertBatch()
|
2013-05-01 15:59:23 -04:00
|
|
|
{
|
|
|
|
if (empty($this->db)) return;
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2013-05-01 15:59:23 -04: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
|
|
|
|
2013-05-03 13:07:34 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-11-08 14:28:49 -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-11-08 14:28:49 -05:00
|
|
|
|
2012-05-08 15:37:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
2012-11-08 14:28:49 -05:00
|
|
|
|
2012-05-08 15:37:36 -04:00
|
|
|
$res = $query->fetchAll(PDO::FETCH_ASSOC);
|
2012-11-08 14:28:49 -05:00
|
|
|
|
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);
|
|
|
|
}
|
2014-04-02 10:31:59 -04:00
|
|
|
|
|
|
|
public function testBackupStructure()
|
|
|
|
{
|
|
|
|
$this->assertEquals('', $this->db->util->backup_structure());
|
|
|
|
}
|
2012-03-15 09:25:18 -04:00
|
|
|
}
|