No more skipped tests, and minor update to query formatting

This commit is contained in:
Timothy Warren 2014-02-21 15:02:41 -05:00
parent 81692053ed
commit 4702ccb2b3
6 changed files with 109 additions and 99 deletions

View File

@ -1267,6 +1267,8 @@ class Query_Builder implements iQuery_Builder {
$vals = array_merge($this->values, (array) $this->where_values); $vals = array_merge($this->values, (array) $this->where_values);
} }
$evals = (is_array($vals)) ? $vals : array();
$start_time = microtime(TRUE); $start_time = microtime(TRUE);
if ($simple) if ($simple)
@ -1283,12 +1285,18 @@ class Query_Builder implements iQuery_Builder {
$total_time = number_format($end_time - $start_time, 5); $total_time = number_format($end_time - $start_time, 5);
// Add the interpreted query to the list of executed queries // Add the interpreted query to the list of executed queries
foreach($evals as $k => &$v)
{
$v = ( ! is_numeric($v)) ? htmlentities($this->db->quote($v), ENT_HTML401 | ENT_NOQUOTES, 'utf-8', FALSE) : $v;
}
$esql = str_replace('?', "%s", $sql); $esql = str_replace('?', "%s", $sql);
array_unshift($vals, $esql); array_unshift($vals, $esql);
array_unshift($evals, $esql);
$this->queries[] = array( $this->queries[] = array(
'time' => $total_time, 'time' => $total_time,
'sql' => call_user_func_array('sprintf', $vals), 'sql' => call_user_func_array('sprintf', $evals),
); );
$this->queries['total_time'] += $total_time; $this->queries['total_time'] += $total_time;
@ -1357,11 +1365,11 @@ class Query_Builder implements iQuery_Builder {
$params = array_fill(0, $param_count, '?'); $params = array_fill(0, $param_count, '?');
$sql = "INSERT INTO {$table} (" $sql = "INSERT INTO {$table} ("
. implode(',', $this->set_array_keys) . . implode(',', $this->set_array_keys) .
') VALUES ('.implode(',', $params).')'; ")\nVALUES (".implode(',', $params).')';
break; break;
case "update": case "update":
$sql = "UPDATE {$table} SET {$this->set_string}"; $sql = "UPDATE {$table}\nSET {$this->set_string}";
break; break;
case "delete": case "delete":

View File

@ -119,7 +119,7 @@ class SQLite_Util extends DB_Util {
if( ! empty($excluded)) if( ! empty($excluded))
{ {
$sql .= ' WHERE NOT IN("'.implode('","', $excluded).'")'; $sql .= " WHERE \"name\" NOT IN('".implode("','", $excluded)."')";
} }
$res = $this->query($sql); $res = $this->query($sql);

View File

@ -85,6 +85,24 @@ require_once(QTEST_DIR . '/core/db_test.php');
require_once(QTEST_DIR . '/core/db_qp_test.php'); require_once(QTEST_DIR . '/core/db_qp_test.php');
require_once(QTEST_DIR . '/core/db_qb_test.php'); require_once(QTEST_DIR . '/core/db_qb_test.php');
// Preset SQLite connection, so there aren't locking issues
if (extension_loaded('pdo_sqlite'))
{
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
$params = (object) array(
'type' => 'sqlite',
'file' => $path,
'host' => 'localhost',
'prefix' => 'create_',
'alias' => 'test_sqlite',
'options' => array(
PDO::ATTR_PERSISTENT => TRUE
)
);
Query($params);
}
// If Firebird (interbase) extension does not exist, // If Firebird (interbase) extension does not exist,
// create a fake class to suppress errors from skipped tests // create a fake class to suppress errors from skipped tests
if ( ! function_exists('fbird_connect')) if ( ! function_exists('fbird_connect'))

View File

@ -56,7 +56,7 @@ abstract class DBTest extends Query_TestCase {
public function testBackupData() public function testBackupData()
{ {
$this->assertTrue(is_string($this->db->util->backup_data())); $this->assertTrue(is_string($this->db->util->backup_data(array('create_delete'))));
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -21,28 +21,21 @@
public function setUp() public function setUp()
{ {
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; // Set up in the bootstrap to mitigate
$params = (object) array( // connection locking issues
'type' => 'sqlite', $this->db = Query('test_sqlite');
'file' => $path,
'host' => 'localhost',
'prefix' => 'create_',
'options' => array(
PDO::ATTR_PERSISTENT => TRUE
)
);
$this->db = Query($params);
// echo '<hr /> SQLite Queries <hr />'; // echo '<hr /> SQLite Queries <hr />';
} }
public function testInsert() { $this->markTestSkipped();} // --------------------------------------------------------------------------
public function testInsertArray() { $this->markTestSkipped();}
public function testUpdate() { $this->markTestSkipped();} public function testQueryFunctionAlias()
public function testSetArrayUpdate() { $this->markTestSkipped();} {
public function testWhereSetUpdate() { $this->markTestSkipped();} $db = Query('test_sqlite');
public function testDelete() { $this->markTestSkipped();}
public function testBadNumRows() { $this->markTestSkipped();} $this->assertTrue($this->db === $db);
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -22,15 +22,9 @@ class SQLiteTest extends DBTest {
public function setUp() public function setUp()
{ {
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; // Set up in the bootstrap to mitigate
$this->db = new SQLite($path); // connection locking issues
} $this->db = Query('test_sqlite');
// --------------------------------------------------------------------------
public function tearDown()
{
unset($this->db);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -88,7 +82,7 @@ class SQLiteTest extends DBTest {
public function testBackupData() public function testBackupData()
{ {
$sql = mb_trim($this->db->util->backup_data()); $sql = mb_trim($this->db->util->backup_data(array('create_join', 'create_test')));
$sql_array = explode("\n", $sql); $sql_array = explode("\n", $sql);
@ -140,7 +134,12 @@ SQL;
public function testConnection() public function testConnection()
{ {
$this->assertIsA($this->db, 'SQLite'); $db = new SQLite(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db');
$this->assertIsA($db, 'SQLite');
$this->assertIsA($this->db->db, 'SQLite');
unset($db);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -162,14 +161,6 @@ SQL;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
public function testCreateTransaction()
{
$res = $this->db->beginTransaction();
$this->assertTrue($res);
}
// --------------------------------------------------------------------------
public function testTruncate() public function testTruncate()
{ {
$this->db->truncate('create_test'); $this->db->truncate('create_test');