diff --git a/sys/db/query_builder.php b/sys/db/query_builder.php index f5d8290..2eac8d4 100644 --- a/sys/db/query_builder.php +++ b/sys/db/query_builder.php @@ -24,7 +24,6 @@ class Query_Builder { private $select_string, $from_string, $where_string, - $like_string, $insert_string, $update_string, $set_string, @@ -45,6 +44,9 @@ class Query_Builder { // Alias to $this->db->sql private $sql; + + // Query component order mapping + private $query_map; /** * Constructor @@ -165,8 +167,6 @@ class Query_Builder { */ public function like($field, $val, $pos='both') { - // @todo Add to where string in the appropriate location - $field = $this->db->quote_ident($field); $this->like_array[$field] = array( @@ -174,29 +174,28 @@ class Query_Builder { 'pos' => $post ); - $likes = array(); - - foreach($this->like_array as $field => $array) + // Add the like string into the order map + $l = $field. ' LIKE '; + + if ($pos == 'before') { - $l = $field. ' LIKE '; - - if ($pos == 'before') - { - $l .= '%?'; - } - elseif ($pos == 'after') - { - $l .= '?%'; - } - else - { - $l .= '%?%'; - } - - $likes[] = $l; + $l .= '%?'; + } + elseif ($pos == 'after') + { + $l .= '?%'; + } + else + { + $l .= '%?%'; } - $this->like_string = implode(' AND ', $likes); + $this->query_map[] = array( + 'type' => 'like', + 'conjunction' => (empty($this->query_map)) ? 'WHERE ' : ' AND ', + 'string' => $l, + 'value' => $val + ); return $this; } @@ -712,7 +711,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 8b6474b..3c26165 100644 --- a/tests/databases/firebird-qb.php +++ b/tests/databases/firebird-qb.php @@ -32,7 +32,7 @@ class FirebirdQBTest extends UnitTestCase { $params->pass = 'masterkey'; $this->qb = new Query_Builder($params); - echo '
Firebird Queries
'; + //echo '
Firebird Queries
'; } function TestGet() diff --git a/tests/databases/sqlite-qb.php b/tests/databases/sqlite-qb.php index 7f8fab5..e1a92a5 100644 --- a/tests/databases/sqlite-qb.php +++ b/tests/databases/sqlite-qb.php @@ -28,7 +28,7 @@ $params->host = 'localhost'; $this->qb = new Query_Builder($params); - echo '
SQLite Queries
'; + //echo '
SQLite Queries
'; } function TestGet() diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index fbb39cb..c324e62 100755 Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ