Added *_PRIORITY and IGNORE syntax

Expanded Model class to support queries with priorities as well as the ignore syntax. Priority can be set to LOW or HIGH and will be added to the appropriate queries with the appended _PRIORITY syntax. Ignore is boolean like the Delayed variable.
This commit is contained in:
Josh Sherman 2011-11-20 13:32:35 -05:00
parent 7f52efdbde
commit dc916622bb
2 changed files with 122 additions and 6 deletions

View file

@ -74,6 +74,16 @@ class Model extends Object
*/
protected $datasource;
/**
* Insert Priority
*
* Defaults to false (normal priority) but can be set to "low" or "high"
*
* @access protected
* @var string
*/
protected $priority = false;
/**
* Delayed Insert
*
@ -82,6 +92,14 @@ class Model extends Object
*/
protected $delayed = false;
/**
* Ignore Unique Index
*
* @access protected
* @var boolean
*/
protected $ignore = false;
/**
* Replace instead of Insert/Update?
*
@ -947,15 +965,53 @@ class Model extends Object
// Determines if it's an UPDATE or INSERT
$update = (isset($this->record[$this->id]) && trim($this->record[$this->id]) != '');
// Establishes the query, optionally uses DELAYED INSERTS
// Starts to build the query, optionally sets PRIORITY, DELAYED and IGNORE syntax
if ($this->replace === true)
{
$sql = 'REPLACE' . ($this->delayed == true ? ' DELAYED' : '') . ' INTO ' . $this->table . ' SET ';
$sql = 'REPLACE';
if (strtoupper($this->priority) == 'LOW')
{
$sql .= ' LOW_PRIORITY';
}
elseif ($this->delayed == true)
{
$sql .= ' DELAYED';
}
$sql .= ' INTO ' . $this->table . ' SET ';
}
else
{
$sql = ($update === true ? 'UPDATE' : 'INSERT' . ($this->delayed == true ? ' DELAYED' : '') . ' INTO') . ' ' . $this->table . ' SET ';
if ($update === true)
{
$sql = 'UPDATE';
}
else
{
$sql = 'INSERT';
// PRIORITY syntax takes priority over DELAYED
if ($this->priority !== false && in_array(strtoupper($this->priority), array('LOW', 'HIGH')))
{
$sql .= ' ' . strtoupper($this->priority) . '_PRIORITY';
}
elseif ($this->delayed == true)
{
$sql .= ' DELAYED';
}
if ($this->ignore == true)
{
$sql .= ' IGNORE';
}
$sql .= ' INTO';
}
$sql .= ' ' . $this->table . ' SET ';
}
$input_parameters = null;
// Limits the columns being updated
@ -996,6 +1052,8 @@ class Model extends Object
}
}
echo $sql;
return false;
}

64
jar.php Normal file → Executable file
View file

@ -3986,6 +3986,16 @@ class Model extends Object
*/
protected $datasource;
/**
* Insert Priority
*
* Defaults to false (normal priority) but can be set to "low" or "high"
*
* @access protected
* @var string
*/
protected $priority = false;
/**
* Delayed Insert
*
@ -3994,6 +4004,14 @@ class Model extends Object
*/
protected $delayed = false;
/**
* Ignore Unique Index
*
* @access protected
* @var boolean
*/
protected $ignore = false;
/**
* Replace instead of Insert/Update?
*
@ -4859,15 +4877,53 @@ class Model extends Object
// Determines if it's an UPDATE or INSERT
$update = (isset($this->record[$this->id]) && trim($this->record[$this->id]) != '');
// Establishes the query, optionally uses DELAYED INSERTS
// Starts to build the query, optionally sets PRIORITY, DELAYED and IGNORE syntax
if ($this->replace === true)
{
$sql = 'REPLACE' . ($this->delayed == true ? ' DELAYED' : '') . ' INTO ' . $this->table . ' SET ';
$sql = 'REPLACE';
if (strtoupper($this->priority) == 'LOW')
{
$sql .= ' LOW_PRIORITY';
}
elseif ($this->delayed == true)
{
$sql .= ' DELAYED';
}
$sql .= ' INTO ' . $this->table . ' SET ';
}
else
{
$sql = ($update === true ? 'UPDATE' : 'INSERT' . ($this->delayed == true ? ' DELAYED' : '') . ' INTO') . ' ' . $this->table . ' SET ';
if ($update === true)
{
$sql = 'UPDATE';
}
else
{
$sql = 'INSERT';
// PRIORITY syntax takes priority over DELAYED
if ($this->priority !== false && in_array(strtoupper($this->priority), array('LOW', 'HIGH')))
{
$sql .= ' ' . strtoupper($this->priority) . '_PRIORITY';
}
elseif ($this->delayed == true)
{
$sql .= ' DELAYED';
}
if ($this->ignore == true)
{
$sql .= ' IGNORE';
}
$sql .= ' INTO';
}
$sql .= ' ' . $this->table . ' SET ';
}
$input_parameters = null;
// Limits the columns being updated
@ -4908,6 +4964,8 @@ class Model extends Object
}
}
echo $sql;
return false;
}