diff --git a/sys/db/query_builder.php b/sys/db/query_builder.php index 470a856..1d78881 100644 --- a/sys/db/query_builder.php +++ b/sys/db/query_builder.php @@ -578,16 +578,15 @@ class Query_Builder { * @return $this */ 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.'
'; + echo $sql.'
'; return $sql; } diff --git a/tests/databases/firebird-qb.php b/tests/databases/firebird-qb.php index 28aa318..bce231a 100644 --- a/tests/databases/firebird-qb.php +++ b/tests/databases/firebird-qb.php @@ -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) diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php index b715ac0..80aa806 100644 --- a/tests/databases/firebird.php +++ b/tests/databases/firebird.php @@ -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'); diff --git a/tests/databases/sqlite-qb.php b/tests/databases/sqlite-qb.php index 4f148c6..5798244 100644 --- a/tests/databases/sqlite-qb.php +++ b/tests/databases/sqlite-qb.php @@ -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) diff --git a/tests/databases/sqlite.php b/tests/databases/sqlite.php index 6ce21ad..6f090d6 100644 --- a/tests/databases/sqlite.php +++ b/tests/databases/sqlite.php @@ -73,6 +73,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(); diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index 58ec9fa..3b0c4d0 100755 Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ