2016-10-12 22:12:25 -04:00
|
|
|
<?php declare(strict_types=1);
|
2012-03-15 09:25:18 -04:00
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
2016-10-12 22:12:25 -04:00
|
|
|
* SQL Query Builder / Database Abstraction Layer
|
2012-03-15 09:25:18 -04:00
|
|
|
*
|
2016-10-12 22:12:25 -04:00
|
|
|
* PHP version 7
|
|
|
|
*
|
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2012 - 2016 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @link https://git.timshomepage.net/aviat4ion/Query
|
2012-03-15 09:25:18 -04:00
|
|
|
*/
|
|
|
|
|
2018-01-22 12:03:37 -05:00
|
|
|
namespace Query\Tests\Drivers;
|
|
|
|
|
|
|
|
use PDO;
|
|
|
|
use Query\Tests\BaseQueryBuilderTest;
|
|
|
|
use InvalidArgumentException;
|
2016-10-12 22:12:25 -04:00
|
|
|
|
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
|
|
|
*/
|
2018-01-22 12:03:37 -05:00
|
|
|
class FirebirdQueryBuilderTest extends BaseQueryBuilderTest {
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
public static function setUpBeforeClass()
|
2014-02-25 13:47:35 -05:00
|
|
|
{
|
2015-07-17 15:38:06 -04:00
|
|
|
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
// test the query builder
|
2018-01-22 12:03:37 -05: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_';
|
2015-07-30 16:40:30 -04:00
|
|
|
self::$db = Query($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2018-01-22 12:03:37 -05:00
|
|
|
if ( ! \function_exists('\\fbird_connect'))
|
2015-07-30 16:40:30 -04:00
|
|
|
{
|
|
|
|
$this->markTestSkipped('Firebird extension does not exist');
|
|
|
|
}
|
2014-02-07 16:53:01 -05:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2015-07-30 16:40:30 -04: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
|
|
|
{
|
2015-07-17 15:38:06 -04:00
|
|
|
$db = Query('water');
|
2014-02-07 16:53:01 -05:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2015-07-17 15:38:06 -04:00
|
|
|
public function testQueryFunctionAlias()
|
|
|
|
{
|
|
|
|
$db = Query();
|
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
$this->assertTrue(self::$db === $db);
|
2015-07-17 15:38:06 -04:00
|
|
|
}
|
|
|
|
|
2015-07-30 16:40:30 -04: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
|
2018-01-22 12:03:37 -05:00
|
|
|
$params = new \Stdclass();
|
2015-07-17 15:38:06 -04:00
|
|
|
$params->alias = 'wood';
|
2014-02-07 16:53:01 -05:00
|
|
|
$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 = '';
|
2016-10-13 21:55:23 -04:00
|
|
|
$fConn = Query($params);
|
|
|
|
$qConn = Query('wood');
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->assertReference($fConn, $qConn);
|
2012-04-20 16:33:40 -04:00
|
|
|
}
|
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
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$sql = self::$db->sql->typeList();
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$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()
|
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$res = self::$db->select('id, key as k, val')
|
2014-02-06 17:07:29 -05:00
|
|
|
->explain()
|
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
|
|
|
->limit(2, 1)
|
2016-10-13 21:55:23 -04:00
|
|
|
->getCompiledSelect();
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
$res2 = self::$db->select('id, key as k, val')
|
2014-02-14 10:38:25 -05:00
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
|
|
|
->limit(2, 1)
|
2016-10-13 21:55:23 -04:00
|
|
|
->getCompiledSelect();
|
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()
|
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$obj = self::$db->query('SELECT * FROM "create_test"');
|
2014-02-25 13:47:35 -05:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2014-04-02 10:31:59 -04:00
|
|
|
public function testBackupStructure()
|
|
|
|
{
|
2014-04-08 14:26:28 -04:00
|
|
|
$existing = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
|
|
|
$backup = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_BKP.FDB';
|
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->assertTrue(self::$db->getUtil()->backupStructure($existing, $backup));
|
2014-04-02 10:31:59 -04:00
|
|
|
}
|
2012-03-15 09:25:18 -04:00
|
|
|
}
|