Started query queue with like method

This commit is contained in:
Timothy Warren 2012-03-13 20:04:18 -04:00
parent 521c0d32da
commit 3f7236c706
4 changed files with 25 additions and 26 deletions

View File

@ -24,7 +24,6 @@ class Query_Builder {
private $select_string, private $select_string,
$from_string, $from_string,
$where_string, $where_string,
$like_string,
$insert_string, $insert_string,
$update_string, $update_string,
$set_string, $set_string,
@ -45,6 +44,9 @@ class Query_Builder {
// Alias to $this->db->sql // Alias to $this->db->sql
private $sql; private $sql;
// Query component order mapping
private $query_map;
/** /**
* Constructor * Constructor
@ -165,8 +167,6 @@ class Query_Builder {
*/ */
public function like($field, $val, $pos='both') public function like($field, $val, $pos='both')
{ {
// @todo Add to where string in the appropriate location
$field = $this->db->quote_ident($field); $field = $this->db->quote_ident($field);
$this->like_array[$field] = array( $this->like_array[$field] = array(
@ -174,29 +174,28 @@ class Query_Builder {
'pos' => $post 'pos' => $post
); );
$likes = array(); // Add the like string into the order map
$l = $field. ' LIKE ';
foreach($this->like_array as $field => $array)
if ($pos == 'before')
{ {
$l = $field. ' LIKE '; $l .= '%?';
}
if ($pos == 'before') elseif ($pos == 'after')
{ {
$l .= '%?'; $l .= '?%';
} }
elseif ($pos == 'after') else
{ {
$l .= '?%'; $l .= '%?%';
}
else
{
$l .= '%?%';
}
$likes[] = $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; return $this;
} }
@ -712,7 +711,7 @@ class Query_Builder {
break; break;
} }
echo $sql.'<br />'; //echo $sql.'<br />';
return $sql; return $sql;
} }

View File

@ -32,7 +32,7 @@ class FirebirdQBTest extends UnitTestCase {
$params->pass = 'masterkey'; $params->pass = 'masterkey';
$this->qb = new Query_Builder($params); $this->qb = new Query_Builder($params);
echo '<hr /> Firebird Queries <hr />'; //echo '<hr /> Firebird Queries <hr />';
} }
function TestGet() function TestGet()

View File

@ -28,7 +28,7 @@
$params->host = 'localhost'; $params->host = 'localhost';
$this->qb = new Query_Builder($params); $this->qb = new Query_Builder($params);
echo '<hr /> SQLite Queries <hr />'; //echo '<hr /> SQLite Queries <hr />';
} }
function TestGet() function TestGet()

Binary file not shown.