Various Query Builder improvements

This commit is contained in:
Timothy Warren 2012-04-30 14:49:30 -04:00
parent baad919dca
commit cd3255a8a2
37 changed files with 408 additions and 426 deletions

View File

@ -203,6 +203,9 @@ abstract class DB_PDO extends PDO {
return array_map(array($this, 'quote_ident'), $ident);
}
// Remove existing escape characters
$ident = str_replace($this->escape_char, '', $ident);
// Split each identifier by the period
$hiers = explode('.', $ident);

View File

@ -22,6 +22,10 @@
*/
class Query_Builder {
// --------------------------------------------------------------------------
// ! SQL Clause Strings
// --------------------------------------------------------------------------
/**
* Compiled 'select' clause
*
@ -58,13 +62,8 @@ class Query_Builder {
private $group_string;
// --------------------------------------------------------------------------
/**
* key/val pairs for insert/update statement
*
* @var array
*/
private $set_array;
// ! SQL Clause Arrays
// --------------------------------------------------------------------------
/**
* Keys for insert/update statement
@ -87,6 +86,8 @@ class Query_Builder {
*/
private $group_array;
// --------------------------------------------------------------------------
// ! Other Class vars
// --------------------------------------------------------------------------
/**
@ -856,12 +857,12 @@ class Query_Builder {
* @param mixed $val
* @return $this
*/
public function set($key, $val)
public function set($key, $val = NULL)
{
// Plain key, value pair
if (is_scalar($key) && is_scalar($val))
{
$this->set_array[$key] = $val;
$this->set_array_keys[] = $key;
$this->values[] = $val;
}
// Object or array
@ -869,18 +870,14 @@ class Query_Builder {
{
foreach($key as $k => $v)
{
$this->set_array[$k] = $v;
foreach($vals as $v)
{
$this->values[] = $v;
}
$this->set_array_keys[] = $k;
$this->values[] = $v;
}
}
// Use the keys of the array to make the insert/update string
// Escape the field names
$this->set_array_keys = array_map(array($this->db, 'quote_ident'), array_keys($this->set_array));
$this->set_array_keys = array_map(array($this->db, 'quote_ident'), $this->set_array_keys);
// Generate the "set" string
$this->set_string = implode('=?, ', $this->set_array_keys);
@ -1395,7 +1392,7 @@ class Query_Builder {
break;
case "insert":
$param_count = count($this->set_array);
$param_count = count($this->set_array_keys);
$params = array_fill(0, $param_count, '?');
$sql = 'INSERT INTO '. $this->quote_ident($table) .
' (' . implode(', ', $this->set_array_keys) .

View File

@ -662,7 +662,7 @@ the connection/database</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -151,7 +151,7 @@ and organizes database connections</p></p>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -268,7 +268,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -208,7 +208,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -812,7 +812,7 @@ the last query executed</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -503,7 +503,7 @@ the query</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -296,7 +296,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -211,7 +211,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -848,7 +848,7 @@ the connection/database</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -280,7 +280,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -207,7 +207,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -850,7 +850,7 @@ the connection/database</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -280,7 +280,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -202,7 +202,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -850,7 +850,7 @@ the connection/database</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -296,7 +296,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -207,7 +207,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -125,7 +125,6 @@ passed array with key / value pairs</span><pre>where()</pre></a></li>
for complex select queries"><span class="description">Query component order mapping
for complex select queries</span><pre>$query_map</pre></a></li>
<li class="property private "><a href="#%24select_string" title="$select_string :: Compiled 'select' clause"><span class="description">Compiled 'select' clause</span><pre>$select_string</pre></a></li>
<li class="property private "><a href="#%24set_array" title="$set_array :: key/val pairs for insert/update statement"><span class="description">key/val pairs for insert/update statement</span><pre>$set_array</pre></a></li>
<li class="property private "><a href="#%24set_array_keys" title="$set_array_keys :: Keys for insert/update statement"><span class="description">Keys for insert/update statement</span><pre>$set_array_keys</pre></a></li>
<li class="property private "><a href="#%24set_string" title="$set_string :: Compiled arguments for insert / update"><span class="description">Compiled arguments for insert / update</span><pre>$set_string</pre></a></li>
<li class="property private "><a href="#%24sql" title="$sql :: Alias to $this-&gt;db-&gt;sql"><span class="description">Alias to $this-&gt;db-&gt;sql</span><pre>$sql</pre></a></li>
@ -1049,12 +1048,6 @@ for complex select queries</h2>
<div class="labels"></div>
<div class="row collapse"><div class="span8"><p class="long_description"></p></div></div>
</div>
<a name="%24set_array" id="$set_array"> </a><div class="element clickable property private $set_array" data-toggle="collapse" data-target=".$set_array .collapse">
<h2>key/val pairs for insert/update statement</h2>
<pre>$set_array : array</pre>
<div class="labels"></div>
<div class="row collapse"><div class="span8"><p class="long_description"></p></div></div>
</div>
<a name="%24set_array_keys" id="$set_array_keys"> </a><div class="element clickable property private $set_array_keys" data-toggle="collapse" data-target=".$set_array_keys .collapse">
<h2>Keys for insert/update statement</h2>
<pre>$set_array_keys : array</pre>
@ -1086,7 +1079,7 @@ for complex select queries</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -865,7 +865,7 @@ method if the database does not support 'TRUNCATE';</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -280,7 +280,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -207,7 +207,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -243,7 +243,7 @@ directly - the settings should be safe!</h2>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -66,7 +66,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -92,7 +92,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -63,7 +63,7 @@
</script><div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -68,7 +68,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -282,7 +282,7 @@ instantiates the specific db driver</p>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -66,7 +66,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -93,7 +93,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -210,7 +210,7 @@ data-fetching methods</p>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -96,7 +96,7 @@
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -114,7 +114,7 @@ instantiates the specific db driver</p>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

View File

@ -315,7 +315,7 @@ instantiates the specific db driver</p>
<div class="row"><footer class="span12">
Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a2</a> and<br>
generated on 2012-04-30T14:28:37-04:00.<br></footer></div>
generated on 2012-04-30T14:49:04-04:00.<br></footer></div>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

Binary file not shown.