Implement set method

This commit is contained in:
Timothy Warren 2012-03-12 15:28:52 -04:00
parent e3ba364dd6
commit 0eb9de2ba6
2 changed files with 59 additions and 3 deletions

View File

@ -24,6 +24,8 @@ class Query_Builder {
$from_string,
$where_array,
$where_string,
$set_array,
$set_string,
$limit,
$offset;
@ -90,8 +92,6 @@ class Query_Builder {
}
$sql = $this->_compile('select');
//echo $sql."<br />";
// Do prepared statements for anything involving a "where" clause
if ( ! empty($this->where_string))
@ -121,7 +121,31 @@ class Query_Builder {
*/
public function set($key, $val)
{
// @todo Implement set method
// Plain key, value pair
if (is_scalar($key) && is_scalar($val))
{
$this->set_array[$key] = $val;
}
// Object or array
elseif ( ! is_scalar($key))
{
foreach($key as $k => $v)
{
$this->set_array[$k] = $v;
}
}
// Use the keys of the array to make the insert/update string
$fields = array_keys($this->set_array);
// Escape the field names
$fields = array_map(array($this, 'quote_ident'), $fields);
// Generate the "set" string
$this->set_string = implode('=?, ', $fields);
$this->set_string .= '=?';
return $this;
}
// --------------------------------------------------------------------------
@ -345,6 +369,22 @@ class Query_Builder {
// --------------------------------------------------------------------------
/**
* Creates a Like clause in the sql statement
*
* @param string $field
* @param mixed $val
* @param string $pos
* @return $this
*/
public function like($field, $val, $pos='both')
{
// @todo implement like method
return $this;
}
// --------------------------------------------------------------------------
/**
* Set a limit on the current sql statement
*
@ -374,6 +414,22 @@ class Query_Builder {
// @todo implement order_by method
return $this;
}
// --------------------------------------------------------------------------
/**
* Join a table
*
* @param string $table
* @param string $statement
* @param string $type
* @return $this
*/
public function join($table, $statement, $type='INNER')
{
// @todo implement join method
return $this;
}
// --------------------------------------------------------------------------

Binary file not shown.