2012-03-15 09:25:18 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-10 14:06:34 -04:00
|
|
|
* OpenSQLManager
|
2012-03-15 09:25:18 -04:00
|
|
|
*
|
2012-04-10 14:06:34 -04:00
|
|
|
* Free Database manager for Open Source Databases
|
2012-03-15 09:25:18 -04:00
|
|
|
*
|
|
|
|
* @author Timothy J. Warren
|
2014-02-18 15:18:01 -05:00
|
|
|
* @copyright Copyright (c) 2012 - 2014
|
2012-04-10 14:06:34 -04:00
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
2012-11-08 14:28:49 -05:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-03-15 09:25:18 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2012-11-08 14:28:49 -05:00
|
|
|
* Class for testing Query Builder with SQLite
|
2014-02-21 15:02:41 -05:00
|
|
|
*
|
2014-02-14 22:08:19 -05:00
|
|
|
* @requires extension pdo_sqlite
|
2012-03-15 09:25:18 -04:00
|
|
|
*/
|
2012-03-19 13:24:36 -04:00
|
|
|
class SQLiteQBTest extends QBTest {
|
2012-11-08 14:28:49 -05:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
public function setUp()
|
2012-03-15 09:25:18 -04:00
|
|
|
{
|
2014-02-21 15:02:41 -05:00
|
|
|
// Set up in the bootstrap to mitigate
|
|
|
|
// connection locking issues
|
|
|
|
$this->db = Query('test_sqlite');
|
2012-03-15 09:25:18 -04:00
|
|
|
}
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2013-05-03 13:07:34 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2014-02-21 15:02:41 -05:00
|
|
|
|
|
|
|
public function testQueryFunctionAlias()
|
|
|
|
{
|
|
|
|
$db = Query('test_sqlite');
|
|
|
|
|
|
|
|
$this->assertTrue($this->db === $db);
|
|
|
|
}
|
|
|
|
|
2014-02-04 20:59:30 -05:00
|
|
|
// --------------------------------------------------------------------------
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-04 20:59:30 -05:00
|
|
|
public function testQueryExplain()
|
|
|
|
{
|
|
|
|
$query = $this->db->select('id, key as k, val')
|
|
|
|
->explain()
|
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
|
|
|
->get('create_test', 2, 1);
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-04 20:59:30 -05:00
|
|
|
$res = $query->fetchAll(PDO::FETCH_ASSOC);
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
$expected_possibilities = array();
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
$expected_possibilities[] = array(
|
|
|
|
array(
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'TABLE create_test USING PRIMARY KEY',
|
|
|
|
)
|
|
|
|
);
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
$expected_possibilities[] = array (
|
|
|
|
array (
|
|
|
|
'selectid' => '0',
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?) (~60000 rows)',
|
|
|
|
),
|
2014-02-04 20:59:30 -05:00
|
|
|
);
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
$expected_possibilities[] = array (
|
|
|
|
array (
|
|
|
|
'selectid' => '0',
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?)',
|
|
|
|
),
|
|
|
|
);
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-20 10:31:54 -05:00
|
|
|
$expected_possibilities[] = array (
|
|
|
|
array (
|
|
|
|
'selectid' => '0',
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?) (~62500 rows)',
|
|
|
|
),
|
|
|
|
);
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
$passed = FALSE;
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
// Check for a matching possibility
|
|
|
|
foreach($expected_possibilities as $ep)
|
|
|
|
{
|
|
|
|
if ($res == $ep)
|
|
|
|
{
|
|
|
|
$this->assertTrue(TRUE);
|
|
|
|
$passed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-06 16:48:52 -05:00
|
|
|
// Well, apparently not an expected possibility
|
|
|
|
if ( ! $passed)
|
|
|
|
{
|
|
|
|
var_export($res);
|
|
|
|
$this->assertTrue(FALSE);
|
|
|
|
}
|
2014-02-04 20:59:30 -05:00
|
|
|
}
|
2012-03-15 09:25:18 -04:00
|
|
|
}
|