A few more query builder tests
This commit is contained in:
parent
09caf1d256
commit
5e73938733
@ -579,15 +579,14 @@ class Query_Builder {
|
||||
*/
|
||||
public function join($table, $condition, $type='')
|
||||
{
|
||||
$table = $this->db->quote_ident($table);
|
||||
// Paste it back together
|
||||
$table = implode(" ", array_map(array($this->db, 'quote_ident'), explode(' ', trim($table))));
|
||||
//$condition = preg_replace('`(\W)`', " $1 ", $condition);
|
||||
$cond_array = explode(' ', trim($condition));
|
||||
$cond_array = array_map('trim', $cond_array);
|
||||
|
||||
$matches = array();
|
||||
|
||||
if (preg_match('/([\[\w\.]+)([\W\s]+)(.+)/', $condition, $matches))
|
||||
{
|
||||
$condition = $this->db->quote_ident($matches[0]) . ' ' . $matches[1] .
|
||||
' ' . $this->db->quote_ident($matches[2]);
|
||||
}
|
||||
$condition = $table . ' ON ' . $this->db->quote_ident($cond_array[0]) . $cond_array[1] .
|
||||
' ' . $this->db->quote_ident($cond_array[2]);
|
||||
|
||||
$this->query_map[] = array(
|
||||
'type' => 'join',
|
||||
@ -947,6 +946,9 @@ class Query_Builder {
|
||||
{
|
||||
unset($this->$name);
|
||||
}
|
||||
|
||||
// Set values as an empty array
|
||||
$this->values = array();
|
||||
}
|
||||
}
|
||||
|
||||
@ -959,7 +961,7 @@ class Query_Builder {
|
||||
* @param string $table
|
||||
* @return $string
|
||||
*/
|
||||
private function _compile($type, $table="")
|
||||
private function _compile($type='', $table="")
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
@ -1039,7 +1041,7 @@ class Query_Builder {
|
||||
break;
|
||||
}
|
||||
|
||||
// echo $sql.'<br />';
|
||||
echo $sql.'<br />';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
@ -178,6 +178,15 @@ class FirebirdQBTest extends UnitTestCase {
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestJoin()
|
||||
{
|
||||
$query = $this->db->from('create_test')
|
||||
->join('create_join cj', 'cj.id = create_test.id')
|
||||
->get();
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestInsert()
|
||||
{
|
||||
$query = $this->db->set('id', 4)
|
||||
|
@ -83,7 +83,7 @@ class FirebirdTest extends UnitTestCase {
|
||||
/*function TestCreateTable()
|
||||
{
|
||||
//Attempt to create the table
|
||||
$sql = $this->db->sql->create_table('create_test', array(
|
||||
$sql = $this->db->sql->create_table('create_join', array(
|
||||
'id' => 'SMALLINT',
|
||||
'key' => 'VARCHAR(64)',
|
||||
'val' => 'BLOB SUB_TYPE TEXT'
|
||||
@ -103,6 +103,8 @@ class FirebirdTest extends UnitTestCase {
|
||||
$this->assertTrue($table_exists);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
function TestTruncate()
|
||||
{
|
||||
$this->db->truncate('create_test');
|
||||
|
@ -164,6 +164,15 @@
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestJoin()
|
||||
{
|
||||
$query = $this->db->from('create_test')
|
||||
->join('create_join cj', 'cj.id = create_test.id')
|
||||
->get();
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestInsert()
|
||||
{
|
||||
$query = $this->db->set('id', 4)
|
||||
|
@ -74,6 +74,19 @@ class SQLiteTest extends UnitTestCase {
|
||||
);
|
||||
$this->db->query($sql);
|
||||
|
||||
//Attempt to create the table
|
||||
$sql = $this->db->sql->create_table('create_join',
|
||||
array(
|
||||
'id' => 'INTEGER',
|
||||
'key' => 'TEXT',
|
||||
'val' => 'TEXT',
|
||||
),
|
||||
array(
|
||||
'id' => 'PRIMARY KEY'
|
||||
)
|
||||
);
|
||||
$this->db->query($sql);
|
||||
|
||||
//Check
|
||||
$dbs = $this->db->get_tables();
|
||||
$this->assertEqual($dbs['create_test'], 'CREATE TABLE "create_test" (id INTEGER PRIMARY KEY, key TEXT , val TEXT )');
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user