Skip to content

Instantly share code, notes, and snippets.

@clasen
Created December 29, 2010 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clasen/758093 to your computer and use it in GitHub Desktop.
Save clasen/758093 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
class Database_Query_Builder_Update extends Kohana_Database_Query_Builder_Update {
/**
* Compile the SQL query and return it.
*
* @param object Database instance
* @return string
*/
public function compile(Database $db)
{
// Start an update query
$query = 'UPDATE '.$db->quote_table($this->_table);
// Add the columns to update
$query .= ' SET '.$this->_compile_set($db, $this->_set);
if ( ! empty($this->_where))
{
// Add selection conditions
$query .= ' WHERE '.$this->_compile_conditions($db, $this->_where);
}
if ( ! empty($this->_order_by))
{
// Add sorting
$query .= ' '.$this->_compile_order_by($db, $this->_order_by);
}
if ($this->_limit !== NULL)
{
// Add limiting
$query .= ' LIMIT '.$this->_limit;
}
return $query;
}
public function reset()
{
$this->_order_by = array();
$this->_limit = NULL;
return parent::reset();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment