blob: 9ceac0b76f9bd0392d7ef35e3d6338951a39bc0a [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Active Record Class
20 *
21 * This is the platform-independent base Active Record implementation class.
22 *
23 * @package CodeIgniter
24 * @subpackage Drivers
25 * @category Database
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/database/
28 */
29class CI_DB_active_record extends CI_DB_driver {
30
31 var $ar_select = array();
32 var $ar_distinct = FALSE;
33 var $ar_from = array();
34 var $ar_join = array();
35 var $ar_where = array();
36 var $ar_like = array();
37 var $ar_groupby = array();
38 var $ar_having = array();
Robin Sowell43753fd2010-09-16 12:52:07 -040039 var $ar_keys = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000040 var $ar_limit = FALSE;
41 var $ar_offset = FALSE;
42 var $ar_order = FALSE;
43 var $ar_orderby = array();
Barry Mienydd671972010-10-04 16:33:58 +020044 var $ar_set = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000045 var $ar_wherein = array();
46 var $ar_aliased_tables = array();
47 var $ar_store_array = array();
Barry Mienydd671972010-10-04 16:33:58 +020048
Derek Allard2067d1a2008-11-13 22:59:24 +000049 // Active Record Caching variables
Barry Mienydd671972010-10-04 16:33:58 +020050 var $ar_caching = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000051 var $ar_cache_exists = array();
52 var $ar_cache_select = array();
53 var $ar_cache_from = array();
54 var $ar_cache_join = array();
55 var $ar_cache_where = array();
56 var $ar_cache_like = array();
57 var $ar_cache_groupby = array();
58 var $ar_cache_having = array();
59 var $ar_cache_orderby = array();
Barry Mienydd671972010-10-04 16:33:58 +020060 var $ar_cache_set = array();
Greg Akere156c6e2011-04-20 16:03:04 -050061
62 var $ar_no_escape = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000063
64
65 // --------------------------------------------------------------------
66
67 /**
68 * Select
69 *
70 * Generates the SELECT portion of the query
71 *
72 * @access public
73 * @param string
74 * @return object
75 */
76 function select($select = '*', $escape = NULL)
77 {
Derek Allard2067d1a2008-11-13 22:59:24 +000078 if (is_string($select))
79 {
80 $select = explode(',', $select);
81 }
82
83 foreach ($select as $val)
84 {
85 $val = trim($val);
86
87 if ($val != '')
88 {
89 $this->ar_select[] = $val;
Greg Akere156c6e2011-04-20 16:03:04 -050090 $this->ar_no_escape[] = $escape;
Derek Allard2067d1a2008-11-13 22:59:24 +000091
92 if ($this->ar_caching === TRUE)
93 {
94 $this->ar_cache_select[] = $val;
95 $this->ar_cache_exists[] = 'select';
96 }
97 }
98 }
99 return $this;
100 }
101
102 // --------------------------------------------------------------------
103
104 /**
105 * Select Max
106 *
107 * Generates a SELECT MAX(field) portion of a query
108 *
109 * @access public
110 * @param string the field
111 * @param string an alias
112 * @return object
113 */
114 function select_max($select = '', $alias = '')
115 {
116 return $this->_max_min_avg_sum($select, $alias, 'MAX');
117 }
Barry Mienydd671972010-10-04 16:33:58 +0200118
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 // --------------------------------------------------------------------
120
121 /**
122 * Select Min
123 *
124 * Generates a SELECT MIN(field) portion of a query
125 *
126 * @access public
127 * @param string the field
128 * @param string an alias
129 * @return object
130 */
131 function select_min($select = '', $alias = '')
132 {
133 return $this->_max_min_avg_sum($select, $alias, 'MIN');
134 }
135
136 // --------------------------------------------------------------------
137
138 /**
139 * Select Average
140 *
141 * Generates a SELECT AVG(field) portion of a query
142 *
143 * @access public
144 * @param string the field
145 * @param string an alias
146 * @return object
147 */
148 function select_avg($select = '', $alias = '')
149 {
150 return $this->_max_min_avg_sum($select, $alias, 'AVG');
151 }
152
153 // --------------------------------------------------------------------
154
155 /**
156 * Select Sum
157 *
158 * Generates a SELECT SUM(field) portion of a query
159 *
160 * @access public
161 * @param string the field
162 * @param string an alias
163 * @return object
164 */
165 function select_sum($select = '', $alias = '')
166 {
167 return $this->_max_min_avg_sum($select, $alias, 'SUM');
168 }
169
170 // --------------------------------------------------------------------
171
172 /**
173 * Processing Function for the four functions above:
174 *
175 * select_max()
176 * select_min()
177 * select_avg()
178 * select_sum()
Barry Mienydd671972010-10-04 16:33:58 +0200179 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 * @access public
181 * @param string the field
182 * @param string an alias
183 * @return object
184 */
185 function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
186 {
187 if ( ! is_string($select) OR $select == '')
188 {
189 $this->display_error('db_invalid_query');
190 }
Barry Mienydd671972010-10-04 16:33:58 +0200191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 $type = strtoupper($type);
Barry Mienydd671972010-10-04 16:33:58 +0200193
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM')))
195 {
196 show_error('Invalid function type: '.$type);
197 }
Barry Mienydd671972010-10-04 16:33:58 +0200198
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 if ($alias == '')
200 {
201 $alias = $this->_create_alias_from_table(trim($select));
202 }
Barry Mienydd671972010-10-04 16:33:58 +0200203
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias;
205
206 $this->ar_select[] = $sql;
Barry Mienydd671972010-10-04 16:33:58 +0200207
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 if ($this->ar_caching === TRUE)
209 {
210 $this->ar_cache_select[] = $sql;
211 $this->ar_cache_exists[] = 'select';
212 }
Barry Mienydd671972010-10-04 16:33:58 +0200213
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 return $this;
215 }
216
217 // --------------------------------------------------------------------
218
219 /**
220 * Determines the alias name based on the table
221 *
222 * @access private
223 * @param string
224 * @return string
225 */
226 function _create_alias_from_table($item)
227 {
228 if (strpos($item, '.') !== FALSE)
229 {
230 return end(explode('.', $item));
231 }
Barry Mienydd671972010-10-04 16:33:58 +0200232
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 return $item;
234 }
235
236 // --------------------------------------------------------------------
237
238 /**
239 * DISTINCT
240 *
241 * Sets a flag which tells the query string compiler to add DISTINCT
242 *
243 * @access public
244 * @param bool
245 * @return object
246 */
247 function distinct($val = TRUE)
248 {
249 $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
250 return $this;
251 }
Barry Mienydd671972010-10-04 16:33:58 +0200252
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 // --------------------------------------------------------------------
254
255 /**
256 * From
257 *
258 * Generates the FROM portion of the query
259 *
260 * @access public
261 * @param mixed can be a string or array
262 * @return object
263 */
264 function from($from)
265 {
266 foreach ((array)$from as $val)
267 {
268 if (strpos($val, ',') !== FALSE)
269 {
270 foreach (explode(',', $val) as $v)
271 {
272 $v = trim($v);
273 $this->_track_aliases($v);
274
275 $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
Barry Mienydd671972010-10-04 16:33:58 +0200276
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 if ($this->ar_caching === TRUE)
278 {
279 $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
280 $this->ar_cache_exists[] = 'from';
Barry Mienydd671972010-10-04 16:33:58 +0200281 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 }
283
284 }
285 else
286 {
287 $val = trim($val);
288
289 // Extract any aliases that might exist. We use this information
Barry Mienydd671972010-10-04 16:33:58 +0200290 // in the _protect_identifiers to know whether to add a table prefix
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 $this->_track_aliases($val);
Barry Mienydd671972010-10-04 16:33:58 +0200292
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
Barry Mienydd671972010-10-04 16:33:58 +0200294
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 if ($this->ar_caching === TRUE)
296 {
297 $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
298 $this->ar_cache_exists[] = 'from';
299 }
300 }
301 }
302
303 return $this;
304 }
305
306 // --------------------------------------------------------------------
307
308 /**
309 * Join
310 *
311 * Generates the JOIN portion of the query
312 *
313 * @access public
314 * @param string
315 * @param string the join condition
316 * @param string the type of join
317 * @return object
318 */
319 function join($table, $cond, $type = '')
Barry Mienydd671972010-10-04 16:33:58 +0200320 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 if ($type != '')
322 {
323 $type = strtoupper(trim($type));
324
325 if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
326 {
327 $type = '';
328 }
329 else
330 {
331 $type .= ' ';
332 }
333 }
334
335 // Extract any aliases that might exist. We use this information
Barry Mienydd671972010-10-04 16:33:58 +0200336 // in the _protect_identifiers to know whether to add a table prefix
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 $this->_track_aliases($table);
338
339 // Strip apart the condition and protect the identifiers
340 if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
341 {
342 $match[1] = $this->_protect_identifiers($match[1]);
343 $match[3] = $this->_protect_identifiers($match[3]);
Barry Mienydd671972010-10-04 16:33:58 +0200344
345 $cond = $match[1].$match[2].$match[3];
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 }
Barry Mienydd671972010-10-04 16:33:58 +0200347
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 // Assemble the JOIN statement
349 $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
350
351 $this->ar_join[] = $join;
352 if ($this->ar_caching === TRUE)
353 {
354 $this->ar_cache_join[] = $join;
355 $this->ar_cache_exists[] = 'join';
356 }
357
358 return $this;
359 }
360
361 // --------------------------------------------------------------------
362
363 /**
364 * Where
365 *
366 * Generates the WHERE portion of the query. Separates
367 * multiple calls with AND
368 *
369 * @access public
370 * @param mixed
371 * @param mixed
372 * @return object
373 */
374 function where($key, $value = NULL, $escape = TRUE)
375 {
376 return $this->_where($key, $value, 'AND ', $escape);
377 }
Barry Mienydd671972010-10-04 16:33:58 +0200378
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 // --------------------------------------------------------------------
380
381 /**
382 * OR Where
383 *
384 * Generates the WHERE portion of the query. Separates
385 * multiple calls with OR
386 *
387 * @access public
388 * @param mixed
389 * @param mixed
390 * @return object
391 */
392 function or_where($key, $value = NULL, $escape = TRUE)
393 {
394 return $this->_where($key, $value, 'OR ', $escape);
395 }
396
397 // --------------------------------------------------------------------
398
399 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 * Where
401 *
402 * Called by where() or orwhere()
403 *
404 * @access private
405 * @param mixed
406 * @param mixed
407 * @param string
408 * @return object
409 */
410 function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
411 {
412 if ( ! is_array($key))
413 {
414 $key = array($key => $value);
415 }
Barry Mienydd671972010-10-04 16:33:58 +0200416
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 // If the escape value was not set will will base it on the global setting
418 if ( ! is_bool($escape))
419 {
420 $escape = $this->_protect_identifiers;
421 }
422
423 foreach ($key as $k => $v)
424 {
425 $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
426
427 if (is_null($v) && ! $this->_has_operator($k))
428 {
429 // value appears not to have been set, assign the test to IS NULL
430 $k .= ' IS NULL';
431 }
Barry Mienydd671972010-10-04 16:33:58 +0200432
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 if ( ! is_null($v))
434 {
435 if ($escape === TRUE)
436 {
437 $k = $this->_protect_identifiers($k, FALSE, $escape);
Barry Mienydd671972010-10-04 16:33:58 +0200438
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 $v = ' '.$this->escape($v);
440 }
Greg Akere156c6e2011-04-20 16:03:04 -0500441
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 if ( ! $this->_has_operator($k))
443 {
Greg Akere156c6e2011-04-20 16:03:04 -0500444 $k .= ' = ';
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 }
446 }
447 else
448 {
Barry Mienydd671972010-10-04 16:33:58 +0200449 $k = $this->_protect_identifiers($k, FALSE, $escape);
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 }
451
452 $this->ar_where[] = $prefix.$k.$v;
Barry Mienydd671972010-10-04 16:33:58 +0200453
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 if ($this->ar_caching === TRUE)
455 {
456 $this->ar_cache_where[] = $prefix.$k.$v;
457 $this->ar_cache_exists[] = 'where';
458 }
Barry Mienydd671972010-10-04 16:33:58 +0200459
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 }
Barry Mienydd671972010-10-04 16:33:58 +0200461
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 return $this;
463 }
464
465 // --------------------------------------------------------------------
466
467 /**
468 * Where_in
469 *
470 * Generates a WHERE field IN ('item', 'item') SQL query joined with
471 * AND if appropriate
472 *
473 * @access public
474 * @param string The field to search
475 * @param array The values searched on
476 * @return object
477 */
478 function where_in($key = NULL, $values = NULL)
479 {
480 return $this->_where_in($key, $values);
481 }
Barry Mienydd671972010-10-04 16:33:58 +0200482
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 // --------------------------------------------------------------------
484
485 /**
486 * Where_in_or
487 *
488 * Generates a WHERE field IN ('item', 'item') SQL query joined with
489 * OR if appropriate
490 *
491 * @access public
492 * @param string The field to search
493 * @param array The values searched on
494 * @return object
495 */
496 function or_where_in($key = NULL, $values = NULL)
497 {
498 return $this->_where_in($key, $values, FALSE, 'OR ');
499 }
500
501 // --------------------------------------------------------------------
502
503 /**
504 * Where_not_in
505 *
506 * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
507 * with AND if appropriate
508 *
509 * @access public
510 * @param string The field to search
511 * @param array The values searched on
512 * @return object
513 */
514 function where_not_in($key = NULL, $values = NULL)
515 {
516 return $this->_where_in($key, $values, TRUE);
517 }
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 // --------------------------------------------------------------------
520
521 /**
522 * Where_not_in_or
523 *
524 * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
525 * with OR if appropriate
526 *
527 * @access public
528 * @param string The field to search
529 * @param array The values searched on
530 * @return object
531 */
532 function or_where_not_in($key = NULL, $values = NULL)
533 {
534 return $this->_where_in($key, $values, TRUE, 'OR ');
535 }
536
537 // --------------------------------------------------------------------
538
539 /**
540 * Where_in
541 *
542 * Called by where_in, where_in_or, where_not_in, where_not_in_or
543 *
544 * @access public
545 * @param string The field to search
546 * @param array The values searched on
547 * @param boolean If the statement would be IN or NOT IN
Barry Mienydd671972010-10-04 16:33:58 +0200548 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 * @return object
550 */
551 function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
552 {
553 if ($key === NULL OR $values === NULL)
554 {
555 return;
556 }
Barry Mienydd671972010-10-04 16:33:58 +0200557
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 if ( ! is_array($values))
559 {
560 $values = array($values);
561 }
Barry Mienydd671972010-10-04 16:33:58 +0200562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 $not = ($not) ? ' NOT' : '';
564
565 foreach ($values as $value)
566 {
567 $this->ar_wherein[] = $this->escape($value);
568 }
569
570 $prefix = (count($this->ar_where) == 0) ? '' : $type;
Barry Mienydd671972010-10-04 16:33:58 +0200571
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
573
574 $this->ar_where[] = $where_in;
575 if ($this->ar_caching === TRUE)
576 {
577 $this->ar_cache_where[] = $where_in;
578 $this->ar_cache_exists[] = 'where';
579 }
580
581 // reset the array for multiple calls
582 $this->ar_wherein = array();
583 return $this;
584 }
Barry Mienydd671972010-10-04 16:33:58 +0200585
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 // --------------------------------------------------------------------
587
588 /**
589 * Like
590 *
591 * Generates a %LIKE% portion of the query. Separates
592 * multiple calls with AND
593 *
594 * @access public
595 * @param mixed
596 * @param mixed
597 * @return object
598 */
599 function like($field, $match = '', $side = 'both')
600 {
601 return $this->_like($field, $match, 'AND ', $side);
602 }
603
604 // --------------------------------------------------------------------
605
606 /**
607 * Not Like
608 *
609 * Generates a NOT LIKE portion of the query. Separates
610 * multiple calls with AND
611 *
612 * @access public
613 * @param mixed
614 * @param mixed
615 * @return object
616 */
617 function not_like($field, $match = '', $side = 'both')
618 {
619 return $this->_like($field, $match, 'AND ', $side, 'NOT');
620 }
Barry Mienydd671972010-10-04 16:33:58 +0200621
Derek Allard2067d1a2008-11-13 22:59:24 +0000622 // --------------------------------------------------------------------
623
624 /**
625 * OR Like
626 *
627 * Generates a %LIKE% portion of the query. Separates
628 * multiple calls with OR
629 *
630 * @access public
631 * @param mixed
632 * @param mixed
633 * @return object
634 */
635 function or_like($field, $match = '', $side = 'both')
636 {
637 return $this->_like($field, $match, 'OR ', $side);
638 }
639
640 // --------------------------------------------------------------------
641
642 /**
643 * OR Not Like
644 *
645 * Generates a NOT LIKE portion of the query. Separates
646 * multiple calls with OR
647 *
648 * @access public
649 * @param mixed
650 * @param mixed
651 * @return object
652 */
653 function or_not_like($field, $match = '', $side = 'both')
654 {
655 return $this->_like($field, $match, 'OR ', $side, 'NOT');
656 }
Barry Mienydd671972010-10-04 16:33:58 +0200657
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 // --------------------------------------------------------------------
659
660 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000661 * Like
662 *
663 * Called by like() or orlike()
664 *
665 * @access private
666 * @param mixed
667 * @param mixed
668 * @param string
669 * @return object
670 */
671 function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
672 {
673 if ( ! is_array($field))
674 {
675 $field = array($field => $match);
676 }
Barry Mienydd671972010-10-04 16:33:58 +0200677
Derek Allard2067d1a2008-11-13 22:59:24 +0000678 foreach ($field as $k => $v)
679 {
680 $k = $this->_protect_identifiers($k);
681
682 $prefix = (count($this->ar_like) == 0) ? '' : $type;
683
Derek Jonese4ed5832009-02-20 21:44:59 +0000684 $v = $this->escape_like_str($v);
Derek Allard2067d1a2008-11-13 22:59:24 +0000685
686 if ($side == 'before')
687 {
688 $like_statement = $prefix." $k $not LIKE '%{$v}'";
689 }
690 elseif ($side == 'after')
691 {
692 $like_statement = $prefix." $k $not LIKE '{$v}%'";
693 }
694 else
695 {
696 $like_statement = $prefix." $k $not LIKE '%{$v}%'";
697 }
Derek Jonesd10e8962010-03-02 17:10:36 -0600698
Derek Jonese4ed5832009-02-20 21:44:59 +0000699 // some platforms require an escape sequence definition for LIKE wildcards
700 if ($this->_like_escape_str != '')
701 {
Greg Aker0d424892010-01-26 02:14:44 +0000702 $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Jonese4ed5832009-02-20 21:44:59 +0000703 }
Derek Jonesd10e8962010-03-02 17:10:36 -0600704
Derek Allard2067d1a2008-11-13 22:59:24 +0000705 $this->ar_like[] = $like_statement;
706 if ($this->ar_caching === TRUE)
707 {
708 $this->ar_cache_like[] = $like_statement;
709 $this->ar_cache_exists[] = 'like';
710 }
Barry Mienydd671972010-10-04 16:33:58 +0200711
Derek Allard2067d1a2008-11-13 22:59:24 +0000712 }
713 return $this;
714 }
Barry Mienydd671972010-10-04 16:33:58 +0200715
Derek Allard2067d1a2008-11-13 22:59:24 +0000716 // --------------------------------------------------------------------
717
718 /**
719 * GROUP BY
720 *
721 * @access public
722 * @param string
723 * @return object
724 */
725 function group_by($by)
726 {
727 if (is_string($by))
728 {
729 $by = explode(',', $by);
730 }
Barry Mienydd671972010-10-04 16:33:58 +0200731
Derek Allard2067d1a2008-11-13 22:59:24 +0000732 foreach ($by as $val)
733 {
734 $val = trim($val);
Barry Mienydd671972010-10-04 16:33:58 +0200735
Derek Allard2067d1a2008-11-13 22:59:24 +0000736 if ($val != '')
737 {
738 $this->ar_groupby[] = $this->_protect_identifiers($val);
Barry Mienydd671972010-10-04 16:33:58 +0200739
Derek Allard2067d1a2008-11-13 22:59:24 +0000740 if ($this->ar_caching === TRUE)
741 {
742 $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
743 $this->ar_cache_exists[] = 'groupby';
744 }
745 }
746 }
747 return $this;
748 }
749
750 // --------------------------------------------------------------------
751
752 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000753 * Sets the HAVING value
754 *
755 * Separates multiple calls with AND
756 *
757 * @access public
758 * @param string
759 * @param string
760 * @return object
761 */
762 function having($key, $value = '', $escape = TRUE)
763 {
764 return $this->_having($key, $value, 'AND ', $escape);
765 }
Barry Mienydd671972010-10-04 16:33:58 +0200766
Derek Allard2067d1a2008-11-13 22:59:24 +0000767 // --------------------------------------------------------------------
768
769 /**
770 * Sets the OR HAVING value
771 *
772 * Separates multiple calls with OR
773 *
774 * @access public
775 * @param string
776 * @param string
777 * @return object
778 */
779 function or_having($key, $value = '', $escape = TRUE)
780 {
781 return $this->_having($key, $value, 'OR ', $escape);
782 }
Barry Mienydd671972010-10-04 16:33:58 +0200783
Derek Allard2067d1a2008-11-13 22:59:24 +0000784 // --------------------------------------------------------------------
785
786 /**
787 * Sets the HAVING values
788 *
789 * Called by having() or or_having()
790 *
791 * @access private
792 * @param string
793 * @param string
794 * @return object
795 */
796 function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
797 {
798 if ( ! is_array($key))
799 {
800 $key = array($key => $value);
801 }
Barry Mienydd671972010-10-04 16:33:58 +0200802
Derek Allard2067d1a2008-11-13 22:59:24 +0000803 foreach ($key as $k => $v)
804 {
805 $prefix = (count($this->ar_having) == 0) ? '' : $type;
806
807 if ($escape === TRUE)
808 {
809 $k = $this->_protect_identifiers($k);
810 }
811
812 if ( ! $this->_has_operator($k))
813 {
814 $k .= ' = ';
815 }
816
817 if ($v != '')
818 {
819 $v = ' '.$this->escape_str($v);
820 }
Barry Mienydd671972010-10-04 16:33:58 +0200821
Derek Allard2067d1a2008-11-13 22:59:24 +0000822 $this->ar_having[] = $prefix.$k.$v;
823 if ($this->ar_caching === TRUE)
824 {
825 $this->ar_cache_having[] = $prefix.$k.$v;
826 $this->ar_cache_exists[] = 'having';
827 }
828 }
Barry Mienydd671972010-10-04 16:33:58 +0200829
Derek Allard2067d1a2008-11-13 22:59:24 +0000830 return $this;
831 }
Barry Mienydd671972010-10-04 16:33:58 +0200832
Derek Allard2067d1a2008-11-13 22:59:24 +0000833 // --------------------------------------------------------------------
834
835 /**
836 * Sets the ORDER BY value
837 *
838 * @access public
839 * @param string
840 * @param string direction: asc or desc
841 * @return object
842 */
843 function order_by($orderby, $direction = '')
844 {
845 if (strtolower($direction) == 'random')
846 {
847 $orderby = ''; // Random results want or don't need a field name
848 $direction = $this->_random_keyword;
849 }
850 elseif (trim($direction) != '')
851 {
852 $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
853 }
Barry Mienydd671972010-10-04 16:33:58 +0200854
855
Derek Allard2067d1a2008-11-13 22:59:24 +0000856 if (strpos($orderby, ',') !== FALSE)
857 {
858 $temp = array();
859 foreach (explode(',', $orderby) as $part)
860 {
861 $part = trim($part);
862 if ( ! in_array($part, $this->ar_aliased_tables))
863 {
864 $part = $this->_protect_identifiers(trim($part));
865 }
Barry Mienydd671972010-10-04 16:33:58 +0200866
Derek Allard2067d1a2008-11-13 22:59:24 +0000867 $temp[] = $part;
868 }
Barry Mienydd671972010-10-04 16:33:58 +0200869
870 $orderby = implode(', ', $temp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000871 }
Derek Allarde37ab382009-02-03 16:13:57 +0000872 else if ($direction != $this->_random_keyword)
Derek Allard2067d1a2008-11-13 22:59:24 +0000873 {
874 $orderby = $this->_protect_identifiers($orderby);
875 }
Barry Mienydd671972010-10-04 16:33:58 +0200876
Derek Allard2067d1a2008-11-13 22:59:24 +0000877 $orderby_statement = $orderby.$direction;
Barry Mienydd671972010-10-04 16:33:58 +0200878
Derek Allard2067d1a2008-11-13 22:59:24 +0000879 $this->ar_orderby[] = $orderby_statement;
880 if ($this->ar_caching === TRUE)
881 {
882 $this->ar_cache_orderby[] = $orderby_statement;
883 $this->ar_cache_exists[] = 'orderby';
884 }
885
886 return $this;
887 }
Barry Mienydd671972010-10-04 16:33:58 +0200888
Derek Allard2067d1a2008-11-13 22:59:24 +0000889 // --------------------------------------------------------------------
890
891 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 * Sets the LIMIT value
893 *
894 * @access public
895 * @param integer the limit value
896 * @param integer the offset value
897 * @return object
898 */
899 function limit($value, $offset = '')
900 {
901 $this->ar_limit = $value;
902
903 if ($offset != '')
904 {
905 $this->ar_offset = $offset;
906 }
Barry Mienydd671972010-10-04 16:33:58 +0200907
Derek Allard2067d1a2008-11-13 22:59:24 +0000908 return $this;
909 }
Barry Mienydd671972010-10-04 16:33:58 +0200910
Derek Allard2067d1a2008-11-13 22:59:24 +0000911 // --------------------------------------------------------------------
912
913 /**
914 * Sets the OFFSET value
915 *
916 * @access public
917 * @param integer the offset value
918 * @return object
919 */
920 function offset($offset)
921 {
922 $this->ar_offset = $offset;
923 return $this;
924 }
Barry Mienydd671972010-10-04 16:33:58 +0200925
Derek Allard2067d1a2008-11-13 22:59:24 +0000926 // --------------------------------------------------------------------
927
928 /**
929 * The "set" function. Allows key/value pairs to be set for inserting or updating
930 *
931 * @access public
932 * @param mixed
933 * @param string
934 * @param boolean
935 * @return object
936 */
937 function set($key, $value = '', $escape = TRUE)
938 {
939 $key = $this->_object_to_array($key);
Barry Mienydd671972010-10-04 16:33:58 +0200940
Derek Allard2067d1a2008-11-13 22:59:24 +0000941 if ( ! is_array($key))
942 {
943 $key = array($key => $value);
Barry Mienydd671972010-10-04 16:33:58 +0200944 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000945
946 foreach ($key as $k => $v)
947 {
948 if ($escape === FALSE)
949 {
950 $this->ar_set[$this->_protect_identifiers($k)] = $v;
951 }
952 else
953 {
Phil Sturgeond0ac1a22011-02-15 22:54:08 +0000954 $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 }
956 }
Barry Mienydd671972010-10-04 16:33:58 +0200957
Derek Allard2067d1a2008-11-13 22:59:24 +0000958 return $this;
959 }
Barry Mienydd671972010-10-04 16:33:58 +0200960
Derek Allard2067d1a2008-11-13 22:59:24 +0000961 // --------------------------------------------------------------------
962
963 /**
964 * Get
965 *
966 * Compiles the select statement based on the other functions called
967 * and runs the query
968 *
969 * @access public
970 * @param string the table
971 * @param string the limit clause
972 * @param string the offset clause
973 * @return object
974 */
975 function get($table = '', $limit = null, $offset = null)
976 {
977 if ($table != '')
978 {
979 $this->_track_aliases($table);
980 $this->from($table);
981 }
Barry Mienydd671972010-10-04 16:33:58 +0200982
Derek Allard2067d1a2008-11-13 22:59:24 +0000983 if ( ! is_null($limit))
984 {
985 $this->limit($limit, $offset);
986 }
Barry Mienydd671972010-10-04 16:33:58 +0200987
Derek Allard2067d1a2008-11-13 22:59:24 +0000988 $sql = $this->_compile_select();
989
990 $result = $this->query($sql);
991 $this->_reset_select();
992 return $result;
993 }
994
995 /**
996 * "Count All Results" query
997 *
Barry Mienydd671972010-10-04 16:33:58 +0200998 * Generates a platform-specific query string that counts all records
Derek Allard2067d1a2008-11-13 22:59:24 +0000999 * returned by an Active Record query.
1000 *
1001 * @access public
1002 * @param string
1003 * @return string
1004 */
1005 function count_all_results($table = '')
1006 {
1007 if ($table != '')
1008 {
1009 $this->_track_aliases($table);
1010 $this->from($table);
1011 }
Barry Mienydd671972010-10-04 16:33:58 +02001012
Derek Allard2067d1a2008-11-13 22:59:24 +00001013 $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
1014
1015 $query = $this->query($sql);
1016 $this->_reset_select();
Barry Mienydd671972010-10-04 16:33:58 +02001017
Derek Allard2067d1a2008-11-13 22:59:24 +00001018 if ($query->num_rows() == 0)
1019 {
Phil Sturgeonaf6f3442011-03-22 19:12:23 +00001020 return 0;
Derek Allard2067d1a2008-11-13 22:59:24 +00001021 }
1022
1023 $row = $query->row();
Phil Sturgeonaf6f3442011-03-22 19:12:23 +00001024 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +00001025 }
1026
1027 // --------------------------------------------------------------------
1028
1029 /**
1030 * Get_Where
1031 *
1032 * Allows the where clause, limit and offset to be added directly
1033 *
1034 * @access public
1035 * @param string the where clause
1036 * @param string the limit clause
1037 * @param string the offset clause
1038 * @return object
1039 */
1040 function get_where($table = '', $where = null, $limit = null, $offset = null)
1041 {
1042 if ($table != '')
1043 {
1044 $this->from($table);
1045 }
1046
1047 if ( ! is_null($where))
1048 {
1049 $this->where($where);
1050 }
Barry Mienydd671972010-10-04 16:33:58 +02001051
Derek Allard2067d1a2008-11-13 22:59:24 +00001052 if ( ! is_null($limit))
1053 {
1054 $this->limit($limit, $offset);
1055 }
Barry Mienydd671972010-10-04 16:33:58 +02001056
Derek Allard2067d1a2008-11-13 22:59:24 +00001057 $sql = $this->_compile_select();
1058
1059 $result = $this->query($sql);
1060 $this->_reset_select();
1061 return $result;
1062 }
1063
1064 // --------------------------------------------------------------------
1065
1066 /**
Derek Jonesd10e8962010-03-02 17:10:36 -06001067 * Insert_Batch
1068 *
1069 * Compiles batch insert strings and runs the queries
1070 *
1071 * @access public
1072 * @param string the table to retrieve the results from
1073 * @param array an associative array of insert values
1074 * @return object
1075 */
1076 function insert_batch($table = '', $set = NULL)
Barry Mienydd671972010-10-04 16:33:58 +02001077 {
Derek Jonesd10e8962010-03-02 17:10:36 -06001078 if ( ! is_null($set))
1079 {
1080 $this->set_insert_batch($set);
1081 }
Barry Mienydd671972010-10-04 16:33:58 +02001082
Derek Jonesd10e8962010-03-02 17:10:36 -06001083 if (count($this->ar_set) == 0)
1084 {
1085 if ($this->db_debug)
1086 {
Barry Mienydd671972010-10-04 16:33:58 +02001087 //No valid data array. Folds in cases where keys and values did not match up
Derek Jonesd10e8962010-03-02 17:10:36 -06001088 return $this->display_error('db_must_use_set');
1089 }
1090 return FALSE;
1091 }
1092
1093 if ($table == '')
1094 {
1095 if ( ! isset($this->ar_from[0]))
1096 {
1097 if ($this->db_debug)
1098 {
1099 return $this->display_error('db_must_set_table');
1100 }
1101 return FALSE;
1102 }
Barry Mienydd671972010-10-04 16:33:58 +02001103
Derek Jonesd10e8962010-03-02 17:10:36 -06001104 $table = $this->ar_from[0];
1105 }
1106
1107 // Batch this baby
1108 for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
1109 {
Barry Mienydd671972010-10-04 16:33:58 +02001110
Derek Jonesd10e8962010-03-02 17:10:36 -06001111 $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
1112
1113 //echo $sql;
1114
1115 $this->query($sql);
1116 }
Barry Mienydd671972010-10-04 16:33:58 +02001117
Derek Jonesd10e8962010-03-02 17:10:36 -06001118 $this->_reset_write();
1119
1120
Barry Mienydd671972010-10-04 16:33:58 +02001121 return TRUE;
Derek Jonesd10e8962010-03-02 17:10:36 -06001122 }
1123
1124 // --------------------------------------------------------------------
1125
1126 /**
1127 * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
1128 *
1129 * @access public
1130 * @param mixed
1131 * @param string
1132 * @param boolean
1133 * @return object
1134 */
1135
1136 function set_insert_batch($key, $value = '', $escape = TRUE)
1137 {
1138 $key = $this->_object_to_array_batch($key);
Barry Mienydd671972010-10-04 16:33:58 +02001139
Derek Jonesd10e8962010-03-02 17:10:36 -06001140 if ( ! is_array($key))
1141 {
1142 $key = array($key => $value);
Barry Mienydd671972010-10-04 16:33:58 +02001143 }
Derek Jonesd10e8962010-03-02 17:10:36 -06001144
1145 $keys = array_keys(current($key));
1146 sort($keys);
1147
1148 foreach ($key as $row)
1149 {
Barry Mienydd671972010-10-04 16:33:58 +02001150 if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0)
1151 {
1152 // batch function above returns an error on an empty array
1153 $this->ar_set[] = array();
1154 return;
1155 }
Phil Sturgeond0ac1a22011-02-15 22:54:08 +00001156
Barry Mienydd671972010-10-04 16:33:58 +02001157 ksort($row); // puts $row in the same order as our keys
1158
Derek Jonesd10e8962010-03-02 17:10:36 -06001159 if ($escape === FALSE)
1160 {
1161 $this->ar_set[] = '('.implode(',', $row).')';
1162 }
1163 else
1164 {
1165 $clean = array();
1166
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001167 foreach ($row as $value)
Derek Jonesd10e8962010-03-02 17:10:36 -06001168 {
Barry Mienydd671972010-10-04 16:33:58 +02001169 $clean[] = $this->escape($value);
Derek Jonesd10e8962010-03-02 17:10:36 -06001170 }
1171
Barry Mienydd671972010-10-04 16:33:58 +02001172 $this->ar_set[] = '('.implode(',', $clean).')';
1173 }
Derek Jonesd10e8962010-03-02 17:10:36 -06001174 }
1175
1176 foreach ($keys as $k)
1177 {
1178 $this->ar_keys[] = $this->_protect_identifiers($k);
1179 }
Barry Mienydd671972010-10-04 16:33:58 +02001180
Derek Jonesd10e8962010-03-02 17:10:36 -06001181 return $this;
1182 }
1183
Derek Allard2067d1a2008-11-13 22:59:24 +00001184 // --------------------------------------------------------------------
1185
1186 /**
1187 * Insert
1188 *
1189 * Compiles an insert string and runs the query
1190 *
1191 * @access public
1192 * @param string the table to retrieve the results from
1193 * @param array an associative array of insert values
1194 * @return object
1195 */
1196 function insert($table = '', $set = NULL)
Barry Mienydd671972010-10-04 16:33:58 +02001197 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001198 if ( ! is_null($set))
1199 {
1200 $this->set($set);
1201 }
Barry Mienydd671972010-10-04 16:33:58 +02001202
Derek Allard2067d1a2008-11-13 22:59:24 +00001203 if (count($this->ar_set) == 0)
1204 {
1205 if ($this->db_debug)
1206 {
1207 return $this->display_error('db_must_use_set');
1208 }
1209 return FALSE;
1210 }
1211
1212 if ($table == '')
1213 {
1214 if ( ! isset($this->ar_from[0]))
1215 {
1216 if ($this->db_debug)
1217 {
1218 return $this->display_error('db_must_set_table');
1219 }
1220 return FALSE;
1221 }
Barry Mienydd671972010-10-04 16:33:58 +02001222
Derek Allard2067d1a2008-11-13 22:59:24 +00001223 $table = $this->ar_from[0];
1224 }
1225
1226 $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
Barry Mienydd671972010-10-04 16:33:58 +02001227
Derek Allard2067d1a2008-11-13 22:59:24 +00001228 $this->_reset_write();
Barry Mienydd671972010-10-04 16:33:58 +02001229 return $this->query($sql);
Derek Allard2067d1a2008-11-13 22:59:24 +00001230 }
Barry Mienydd671972010-10-04 16:33:58 +02001231
Derek Jonesd10e8962010-03-02 17:10:36 -06001232 function replace($table = '', $set = NULL)
1233 {
1234 if ( ! is_null($set))
1235 {
1236 $this->set($set);
1237 }
Barry Mienydd671972010-10-04 16:33:58 +02001238
Derek Jonesd10e8962010-03-02 17:10:36 -06001239 if (count($this->ar_set) == 0)
1240 {
1241 if ($this->db_debug)
1242 {
1243 return $this->display_error('db_must_use_set');
1244 }
1245 return FALSE;
1246 }
1247
1248 if ($table == '')
1249 {
1250 if ( ! isset($this->ar_from[0]))
1251 {
1252 if ($this->db_debug)
1253 {
1254 return $this->display_error('db_must_set_table');
1255 }
1256 return FALSE;
1257 }
Barry Mienydd671972010-10-04 16:33:58 +02001258
Derek Jonesd10e8962010-03-02 17:10:36 -06001259 $table = $this->ar_from[0];
1260 }
1261
1262 $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
Barry Mienydd671972010-10-04 16:33:58 +02001263
Derek Jonesd10e8962010-03-02 17:10:36 -06001264 $this->_reset_write();
Barry Mienydd671972010-10-04 16:33:58 +02001265 return $this->query($sql);
Derek Jonesd10e8962010-03-02 17:10:36 -06001266 }
1267
Derek Allard2067d1a2008-11-13 22:59:24 +00001268 // --------------------------------------------------------------------
1269
1270 /**
1271 * Update
1272 *
1273 * Compiles an update string and runs the query
1274 *
1275 * @access public
1276 * @param string the table to retrieve the results from
1277 * @param array an associative array of update values
1278 * @param mixed the where clause
1279 * @return object
1280 */
1281 function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
1282 {
1283 // Combine any cached components with the current statements
1284 $this->_merge_cache();
1285
1286 if ( ! is_null($set))
1287 {
1288 $this->set($set);
1289 }
Barry Mienydd671972010-10-04 16:33:58 +02001290
Derek Allard2067d1a2008-11-13 22:59:24 +00001291 if (count($this->ar_set) == 0)
1292 {
1293 if ($this->db_debug)
1294 {
1295 return $this->display_error('db_must_use_set');
1296 }
1297 return FALSE;
1298 }
1299
1300 if ($table == '')
1301 {
1302 if ( ! isset($this->ar_from[0]))
1303 {
1304 if ($this->db_debug)
1305 {
1306 return $this->display_error('db_must_set_table');
1307 }
1308 return FALSE;
1309 }
Barry Mienydd671972010-10-04 16:33:58 +02001310
Derek Allard2067d1a2008-11-13 22:59:24 +00001311 $table = $this->ar_from[0];
1312 }
Barry Mienydd671972010-10-04 16:33:58 +02001313
Derek Allard2067d1a2008-11-13 22:59:24 +00001314 if ($where != NULL)
1315 {
1316 $this->where($where);
1317 }
1318
1319 if ($limit != NULL)
1320 {
1321 $this->limit($limit);
1322 }
Barry Mienydd671972010-10-04 16:33:58 +02001323
Derek Allard2067d1a2008-11-13 22:59:24 +00001324 $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
Barry Mienydd671972010-10-04 16:33:58 +02001325
Derek Allard2067d1a2008-11-13 22:59:24 +00001326 $this->_reset_write();
1327 return $this->query($sql);
1328 }
1329
Derek Jonesd10e8962010-03-02 17:10:36 -06001330
1331 // --------------------------------------------------------------------
1332
1333 /**
1334 * Update_Batch
1335 *
1336 * Compiles an update string and runs the query
1337 *
1338 * @access public
1339 * @param string the table to retrieve the results from
1340 * @param array an associative array of update values
1341 * @param string the where key
1342 * @return object
1343 */
1344 function update_batch($table = '', $set = NULL, $index = NULL)
1345 {
1346 // Combine any cached components with the current statements
1347 $this->_merge_cache();
Barry Mienydd671972010-10-04 16:33:58 +02001348
Derek Jonesd10e8962010-03-02 17:10:36 -06001349 if (is_null($index))
1350 {
1351 if ($this->db_debug)
1352 {
1353 return $this->display_error('db_myst_use_index');
1354 }
1355
1356 return FALSE;
1357 }
1358
1359 if ( ! is_null($set))
1360 {
1361 $this->set_update_batch($set, $index);
1362 }
1363
1364 if (count($this->ar_set) == 0)
1365 {
1366 if ($this->db_debug)
1367 {
1368 return $this->display_error('db_must_use_set');
1369 }
1370
1371 return FALSE;
1372 }
1373
1374 if ($table == '')
1375 {
1376 if ( ! isset($this->ar_from[0]))
1377 {
1378 if ($this->db_debug)
1379 {
1380 return $this->display_error('db_must_set_table');
1381 }
1382 return FALSE;
1383 }
Barry Mienydd671972010-10-04 16:33:58 +02001384
Derek Jonesd10e8962010-03-02 17:10:36 -06001385 $table = $this->ar_from[0];
1386 }
Barry Mienydd671972010-10-04 16:33:58 +02001387
Derek Jonesd10e8962010-03-02 17:10:36 -06001388 // Batch this baby
1389 for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
1390 {
1391 $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
1392
1393 $this->query($sql);
1394 }
Barry Mienydd671972010-10-04 16:33:58 +02001395
Derek Jonesd10e8962010-03-02 17:10:36 -06001396 $this->_reset_write();
1397 }
1398
1399 // --------------------------------------------------------------------
1400
1401 /**
1402 * The "set_update_batch" function. Allows key/value pairs to be set for batch updating
1403 *
1404 * @access public
1405 * @param array
1406 * @param string
1407 * @param boolean
1408 * @return object
1409 */
1410
1411 function set_update_batch($key, $index = '', $escape = TRUE)
1412 {
1413 $key = $this->_object_to_array_batch($key);
Barry Mienydd671972010-10-04 16:33:58 +02001414
Derek Jonesd10e8962010-03-02 17:10:36 -06001415 if ( ! is_array($key))
1416 {
1417 // @todo error
Barry Mienydd671972010-10-04 16:33:58 +02001418 }
Derek Jonesd10e8962010-03-02 17:10:36 -06001419
1420 foreach ($key as $k => $v)
1421 {
1422 $index_set = FALSE;
1423 $clean = array();
1424
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001425 foreach ($v as $k2 => $v2)
Derek Jonesd10e8962010-03-02 17:10:36 -06001426 {
1427 if ($k2 == $index)
1428 {
1429 $index_set = TRUE;
1430 }
1431 else
1432 {
1433 $not[] = $k.'-'.$v;
1434 }
1435
1436 if ($escape === FALSE)
1437 {
1438 $clean[$this->_protect_identifiers($k2)] = $v2;
1439 }
1440 else
1441 {
Barry Mienydd671972010-10-04 16:33:58 +02001442 $clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
Derek Jonesd10e8962010-03-02 17:10:36 -06001443 }
1444 }
1445
1446 if ($index_set == FALSE)
1447 {
1448 return $this->display_error('db_batch_missing_index');
1449 }
1450
1451 $this->ar_set[] = $clean;
1452 }
Barry Mienydd671972010-10-04 16:33:58 +02001453
Derek Jonesd10e8962010-03-02 17:10:36 -06001454 return $this;
1455 }
1456
Derek Allard2067d1a2008-11-13 22:59:24 +00001457 // --------------------------------------------------------------------
1458
1459 /**
1460 * Empty Table
1461 *
1462 * Compiles a delete string and runs "DELETE FROM table"
1463 *
1464 * @access public
1465 * @param string the table to empty
1466 * @return object
1467 */
1468 function empty_table($table = '')
1469 {
1470 if ($table == '')
1471 {
1472 if ( ! isset($this->ar_from[0]))
1473 {
1474 if ($this->db_debug)
1475 {
1476 return $this->display_error('db_must_set_table');
1477 }
1478 return FALSE;
1479 }
1480
1481 $table = $this->ar_from[0];
1482 }
1483 else
1484 {
1485 $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
1486 }
1487
1488 $sql = $this->_delete($table);
1489
1490 $this->_reset_write();
Barry Mienydd671972010-10-04 16:33:58 +02001491
Derek Allard2067d1a2008-11-13 22:59:24 +00001492 return $this->query($sql);
1493 }
1494
1495 // --------------------------------------------------------------------
1496
1497 /**
1498 * Truncate
1499 *
1500 * Compiles a truncate string and runs the query
1501 * If the database does not support the truncate() command
1502 * This function maps to "DELETE FROM table"
1503 *
1504 * @access public
1505 * @param string the table to truncate
1506 * @return object
1507 */
1508 function truncate($table = '')
1509 {
1510 if ($table == '')
1511 {
1512 if ( ! isset($this->ar_from[0]))
1513 {
1514 if ($this->db_debug)
1515 {
1516 return $this->display_error('db_must_set_table');
1517 }
1518 return FALSE;
1519 }
1520
1521 $table = $this->ar_from[0];
1522 }
1523 else
1524 {
1525 $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
1526 }
1527
1528 $sql = $this->_truncate($table);
1529
1530 $this->_reset_write();
Barry Mienydd671972010-10-04 16:33:58 +02001531
Derek Allard2067d1a2008-11-13 22:59:24 +00001532 return $this->query($sql);
1533 }
Barry Mienydd671972010-10-04 16:33:58 +02001534
Derek Allard2067d1a2008-11-13 22:59:24 +00001535 // --------------------------------------------------------------------
1536
1537 /**
1538 * Delete
1539 *
1540 * Compiles a delete string and runs the query
1541 *
1542 * @access public
1543 * @param mixed the table(s) to delete from. String or array
1544 * @param mixed the where clause
1545 * @param mixed the limit clause
1546 * @param boolean
1547 * @return object
1548 */
1549 function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
1550 {
1551 // Combine any cached components with the current statements
1552 $this->_merge_cache();
1553
1554 if ($table == '')
1555 {
1556 if ( ! isset($this->ar_from[0]))
1557 {
1558 if ($this->db_debug)
1559 {
1560 return $this->display_error('db_must_set_table');
1561 }
1562 return FALSE;
1563 }
1564
1565 $table = $this->ar_from[0];
1566 }
1567 elseif (is_array($table))
1568 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001569 foreach ($table as $single_table)
Derek Allard2067d1a2008-11-13 22:59:24 +00001570 {
1571 $this->delete($single_table, $where, $limit, FALSE);
1572 }
1573
1574 $this->_reset_write();
1575 return;
1576 }
1577 else
1578 {
1579 $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
1580 }
1581
1582 if ($where != '')
1583 {
1584 $this->where($where);
1585 }
1586
1587 if ($limit != NULL)
1588 {
1589 $this->limit($limit);
1590 }
1591
Derek Allard03d783b2009-05-03 19:45:45 +00001592 if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001593 {
1594 if ($this->db_debug)
1595 {
1596 return $this->display_error('db_del_must_use_where');
1597 }
1598
1599 return FALSE;
Barry Mienydd671972010-10-04 16:33:58 +02001600 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001601
1602 $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
1603
1604 if ($reset_data)
1605 {
1606 $this->_reset_write();
1607 }
Barry Mienydd671972010-10-04 16:33:58 +02001608
Derek Allard2067d1a2008-11-13 22:59:24 +00001609 return $this->query($sql);
1610 }
1611
1612 // --------------------------------------------------------------------
1613
1614 /**
1615 * DB Prefix
1616 *
1617 * Prepends a database prefix if one exists in configuration
1618 *
1619 * @access public
1620 * @param string the table
1621 * @return string
1622 */
1623 function dbprefix($table = '')
1624 {
1625 if ($table == '')
1626 {
1627 $this->display_error('db_table_name_required');
1628 }
1629
1630 return $this->dbprefix.$table;
1631 }
1632
1633 // --------------------------------------------------------------------
1634
1635 /**
1636 * Track Aliases
1637 *
1638 * Used to track SQL statements written with aliased tables.
1639 *
1640 * @access private
1641 * @param string The table to inspect
1642 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001643 */
Derek Allard2067d1a2008-11-13 22:59:24 +00001644 function _track_aliases($table)
1645 {
1646 if (is_array($table))
1647 {
1648 foreach ($table as $t)
1649 {
1650 $this->_track_aliases($t);
1651 }
1652 return;
1653 }
Barry Mienydd671972010-10-04 16:33:58 +02001654
Derek Allard2067d1a2008-11-13 22:59:24 +00001655 // Does the string contain a comma? If so, we need to separate
1656 // the string into discreet statements
1657 if (strpos($table, ',') !== FALSE)
1658 {
1659 return $this->_track_aliases(explode(',', $table));
1660 }
Barry Mienydd671972010-10-04 16:33:58 +02001661
Derek Allard2067d1a2008-11-13 22:59:24 +00001662 // if a table alias is used we can recognize it by a space
1663 if (strpos($table, " ") !== FALSE)
1664 {
1665 // if the alias is written with the AS keyword, remove it
1666 $table = preg_replace('/ AS /i', ' ', $table);
Barry Mienydd671972010-10-04 16:33:58 +02001667
Derek Allard2067d1a2008-11-13 22:59:24 +00001668 // Grab the alias
1669 $table = trim(strrchr($table, " "));
Barry Mienydd671972010-10-04 16:33:58 +02001670
Derek Allard2067d1a2008-11-13 22:59:24 +00001671 // Store the alias, if it doesn't already exist
1672 if ( ! in_array($table, $this->ar_aliased_tables))
1673 {
1674 $this->ar_aliased_tables[] = $table;
1675 }
1676 }
1677 }
1678
1679 // --------------------------------------------------------------------
1680
1681 /**
1682 * Compile the SELECT statement
1683 *
1684 * Generates a query string based on which functions were used.
1685 * Should not be called directly. The get() function calls it.
1686 *
1687 * @access private
1688 * @return string
1689 */
1690 function _compile_select($select_override = FALSE)
1691 {
1692 // Combine any cached components with the current statements
1693 $this->_merge_cache();
1694
1695 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001696
Derek Allard2067d1a2008-11-13 22:59:24 +00001697 // Write the "select" portion of the query
1698
1699 if ($select_override !== FALSE)
1700 {
1701 $sql = $select_override;
1702 }
1703 else
1704 {
1705 $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
Barry Mienydd671972010-10-04 16:33:58 +02001706
Derek Allard2067d1a2008-11-13 22:59:24 +00001707 if (count($this->ar_select) == 0)
1708 {
Barry Mienydd671972010-10-04 16:33:58 +02001709 $sql .= '*';
Derek Allard2067d1a2008-11-13 22:59:24 +00001710 }
1711 else
Barry Mienydd671972010-10-04 16:33:58 +02001712 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001713 // Cycle through the "select" portion of the query and prep each column name.
1714 // The reason we protect identifiers here rather then in the select() function
1715 // is because until the user calls the from() function we don't know if there are aliases
1716 foreach ($this->ar_select as $key => $val)
1717 {
Greg Akere156c6e2011-04-20 16:03:04 -05001718 $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $this->ar_no_escape[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001719 }
Barry Mienydd671972010-10-04 16:33:58 +02001720
Derek Allard2067d1a2008-11-13 22:59:24 +00001721 $sql .= implode(', ', $this->ar_select);
1722 }
1723 }
1724
1725 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001726
Derek Allard2067d1a2008-11-13 22:59:24 +00001727 // Write the "FROM" portion of the query
1728
1729 if (count($this->ar_from) > 0)
1730 {
1731 $sql .= "\nFROM ";
1732
1733 $sql .= $this->_from_tables($this->ar_from);
1734 }
1735
1736 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001737
Derek Allard2067d1a2008-11-13 22:59:24 +00001738 // Write the "JOIN" portion of the query
1739
1740 if (count($this->ar_join) > 0)
1741 {
1742 $sql .= "\n";
1743
1744 $sql .= implode("\n", $this->ar_join);
1745 }
1746
1747 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001748
Derek Allard2067d1a2008-11-13 22:59:24 +00001749 // Write the "WHERE" portion of the query
1750
1751 if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
1752 {
Greg Akere156c6e2011-04-20 16:03:04 -05001753 $sql .= "\nWHERE ";
Derek Allard2067d1a2008-11-13 22:59:24 +00001754 }
1755
1756 $sql .= implode("\n", $this->ar_where);
1757
1758 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001759
Derek Allard2067d1a2008-11-13 22:59:24 +00001760 // Write the "LIKE" portion of the query
Barry Mienydd671972010-10-04 16:33:58 +02001761
Derek Allard2067d1a2008-11-13 22:59:24 +00001762 if (count($this->ar_like) > 0)
1763 {
1764 if (count($this->ar_where) > 0)
1765 {
1766 $sql .= "\nAND ";
1767 }
1768
1769 $sql .= implode("\n", $this->ar_like);
1770 }
1771
1772 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001773
Derek Allard2067d1a2008-11-13 22:59:24 +00001774 // Write the "GROUP BY" portion of the query
Barry Mienydd671972010-10-04 16:33:58 +02001775
Derek Allard2067d1a2008-11-13 22:59:24 +00001776 if (count($this->ar_groupby) > 0)
1777 {
1778 $sql .= "\nGROUP BY ";
Barry Mienydd671972010-10-04 16:33:58 +02001779
Derek Allard2067d1a2008-11-13 22:59:24 +00001780 $sql .= implode(', ', $this->ar_groupby);
1781 }
1782
1783 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001784
Derek Allard2067d1a2008-11-13 22:59:24 +00001785 // Write the "HAVING" portion of the query
Barry Mienydd671972010-10-04 16:33:58 +02001786
Derek Allard2067d1a2008-11-13 22:59:24 +00001787 if (count($this->ar_having) > 0)
1788 {
1789 $sql .= "\nHAVING ";
1790 $sql .= implode("\n", $this->ar_having);
1791 }
1792
1793 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001794
Derek Allard2067d1a2008-11-13 22:59:24 +00001795 // Write the "ORDER BY" portion of the query
1796
1797 if (count($this->ar_orderby) > 0)
1798 {
1799 $sql .= "\nORDER BY ";
1800 $sql .= implode(', ', $this->ar_orderby);
Barry Mienydd671972010-10-04 16:33:58 +02001801
Derek Allard2067d1a2008-11-13 22:59:24 +00001802 if ($this->ar_order !== FALSE)
1803 {
1804 $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
Barry Mienydd671972010-10-04 16:33:58 +02001805 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001806 }
1807
1808 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001809
Derek Allard2067d1a2008-11-13 22:59:24 +00001810 // Write the "LIMIT" portion of the query
Barry Mienydd671972010-10-04 16:33:58 +02001811
Derek Allard2067d1a2008-11-13 22:59:24 +00001812 if (is_numeric($this->ar_limit))
1813 {
1814 $sql .= "\n";
1815 $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
1816 }
1817
1818 return $sql;
1819 }
1820
1821 // --------------------------------------------------------------------
1822
1823 /**
1824 * Object to Array
1825 *
1826 * Takes an object as input and converts the class variables to array key/vals
1827 *
1828 * @access public
1829 * @param object
1830 * @return array
1831 */
1832 function _object_to_array($object)
1833 {
1834 if ( ! is_object($object))
1835 {
1836 return $object;
1837 }
Barry Mienydd671972010-10-04 16:33:58 +02001838
Derek Allard2067d1a2008-11-13 22:59:24 +00001839 $array = array();
1840 foreach (get_object_vars($object) as $key => $val)
1841 {
1842 // There are some built in keys we need to ignore for this conversion
Derek Jonescf579552010-03-11 09:13:34 -06001843 if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name')
Derek Allard2067d1a2008-11-13 22:59:24 +00001844 {
1845 $array[$key] = $val;
1846 }
1847 }
Derek Jonesd10e8962010-03-02 17:10:36 -06001848
1849 return $array;
1850 }
Barry Mienydd671972010-10-04 16:33:58 +02001851
Derek Jonesd10e8962010-03-02 17:10:36 -06001852 // --------------------------------------------------------------------
1853
1854 /**
1855 * Object to Array
1856 *
1857 * Takes an object as input and converts the class variables to array key/vals
1858 *
1859 * @access public
1860 * @param object
1861 * @return array
1862 */
1863 function _object_to_array_batch($object)
1864 {
1865 if ( ! is_object($object))
1866 {
1867 return $object;
1868 }
Barry Mienydd671972010-10-04 16:33:58 +02001869
Derek Jonesd10e8962010-03-02 17:10:36 -06001870 $array = array();
1871 $out = get_object_vars($object);
1872 $fields = array_keys($out);
1873
1874 foreach ($fields as $val)
1875 {
1876 // There are some built in keys we need to ignore for this conversion
Derek Jonescf579552010-03-11 09:13:34 -06001877 if ($val != '_parent_name')
Derek Jonesd10e8962010-03-02 17:10:36 -06001878 {
1879
1880 $i = 0;
1881 foreach ($out[$val] as $data)
1882 {
1883 $array[$i][$val] = $data;
1884 $i++;
1885 }
1886 }
1887 }
1888
Derek Allard2067d1a2008-11-13 22:59:24 +00001889 return $array;
1890 }
Barry Mienydd671972010-10-04 16:33:58 +02001891
Derek Allard2067d1a2008-11-13 22:59:24 +00001892 // --------------------------------------------------------------------
1893
1894 /**
1895 * Start Cache
1896 *
1897 * Starts AR caching
1898 *
1899 * @access public
1900 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001901 */
Derek Allard2067d1a2008-11-13 22:59:24 +00001902 function start_cache()
1903 {
1904 $this->ar_caching = TRUE;
1905 }
1906
1907 // --------------------------------------------------------------------
1908
1909 /**
1910 * Stop Cache
1911 *
1912 * Stops AR caching
1913 *
1914 * @access public
1915 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001916 */
Derek Allard2067d1a2008-11-13 22:59:24 +00001917 function stop_cache()
1918 {
1919 $this->ar_caching = FALSE;
1920 }
1921
1922 // --------------------------------------------------------------------
1923
1924 /**
1925 * Flush Cache
1926 *
1927 * Empties the AR cache
1928 *
1929 * @access public
1930 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001931 */
Derek Allard2067d1a2008-11-13 22:59:24 +00001932 function flush_cache()
Barry Mienydd671972010-10-04 16:33:58 +02001933 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001934 $this->_reset_run(
1935 array(
Barry Mienydd671972010-10-04 16:33:58 +02001936 'ar_cache_select' => array(),
1937 'ar_cache_from' => array(),
Derek Allard2067d1a2008-11-13 22:59:24 +00001938 'ar_cache_join' => array(),
Barry Mienydd671972010-10-04 16:33:58 +02001939 'ar_cache_where' => array(),
1940 'ar_cache_like' => array(),
1941 'ar_cache_groupby' => array(),
1942 'ar_cache_having' => array(),
1943 'ar_cache_orderby' => array(),
Derek Allard2067d1a2008-11-13 22:59:24 +00001944 'ar_cache_set' => array(),
1945 'ar_cache_exists' => array()
1946 )
Barry Mienydd671972010-10-04 16:33:58 +02001947 );
Derek Allard2067d1a2008-11-13 22:59:24 +00001948 }
1949
1950 // --------------------------------------------------------------------
1951
1952 /**
1953 * Merge Cache
1954 *
Barry Mienydd671972010-10-04 16:33:58 +02001955 * When called, this function merges any cached AR arrays with
Derek Allard2067d1a2008-11-13 22:59:24 +00001956 * locally called ones.
1957 *
1958 * @access private
1959 * @return void
1960 */
1961 function _merge_cache()
1962 {
1963 if (count($this->ar_cache_exists) == 0)
1964 {
1965 return;
1966 }
1967
1968 foreach ($this->ar_cache_exists as $val)
1969 {
1970 $ar_variable = 'ar_'.$val;
1971 $ar_cache_var = 'ar_cache_'.$val;
1972
1973 if (count($this->$ar_cache_var) == 0)
1974 {
1975 continue;
1976 }
1977
1978 $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable));
1979 }
1980
1981 // If we are "protecting identifiers" we need to examine the "from"
1982 // portion of the query to determine if there are any aliases
1983 if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0)
1984 {
1985 $this->_track_aliases($this->ar_from);
1986 }
1987 }
1988
1989 // --------------------------------------------------------------------
1990
1991 /**
1992 * Resets the active record values. Called by the get() function
1993 *
1994 * @access private
1995 * @param array An array of fields to reset
1996 * @return void
1997 */
1998 function _reset_run($ar_reset_items)
1999 {
2000 foreach ($ar_reset_items as $item => $default_value)
2001 {
2002 if ( ! in_array($item, $this->ar_store_array))
2003 {
2004 $this->$item = $default_value;
2005 }
2006 }
2007 }
2008
2009 // --------------------------------------------------------------------
2010
2011 /**
2012 * Resets the active record values. Called by the get() function
2013 *
2014 * @access private
2015 * @return void
2016 */
2017 function _reset_select()
2018 {
2019 $ar_reset_items = array(
Barry Mienydd671972010-10-04 16:33:58 +02002020 'ar_select' => array(),
2021 'ar_from' => array(),
2022 'ar_join' => array(),
2023 'ar_where' => array(),
2024 'ar_like' => array(),
2025 'ar_groupby' => array(),
2026 'ar_having' => array(),
2027 'ar_orderby' => array(),
2028 'ar_wherein' => array(),
Derek Allard2067d1a2008-11-13 22:59:24 +00002029 'ar_aliased_tables' => array(),
Greg Akere156c6e2011-04-20 16:03:04 -05002030 'ar_no_escape' => array(),
Barry Mienydd671972010-10-04 16:33:58 +02002031 'ar_distinct' => FALSE,
2032 'ar_limit' => FALSE,
2033 'ar_offset' => FALSE,
Derek Allard2067d1a2008-11-13 22:59:24 +00002034 'ar_order' => FALSE,
2035 );
Barry Mienydd671972010-10-04 16:33:58 +02002036
Derek Allard2067d1a2008-11-13 22:59:24 +00002037 $this->_reset_run($ar_reset_items);
2038 }
Barry Mienydd671972010-10-04 16:33:58 +02002039
Derek Allard2067d1a2008-11-13 22:59:24 +00002040 // --------------------------------------------------------------------
2041
2042 /**
2043 * Resets the active record "write" values.
2044 *
Robin Sowell43753fd2010-09-16 12:52:07 -04002045 * Called by the insert() update() insert_batch() update_batch() and delete() functions
Derek Allard2067d1a2008-11-13 22:59:24 +00002046 *
2047 * @access private
2048 * @return void
2049 */
2050 function _reset_write()
Barry Mienydd671972010-10-04 16:33:58 +02002051 {
Derek Allard2067d1a2008-11-13 22:59:24 +00002052 $ar_reset_items = array(
Barry Mienydd671972010-10-04 16:33:58 +02002053 'ar_set' => array(),
2054 'ar_from' => array(),
2055 'ar_where' => array(),
Derek Allard2067d1a2008-11-13 22:59:24 +00002056 'ar_like' => array(),
Robin Sowell43753fd2010-09-16 12:52:07 -04002057 'ar_orderby' => array(),
Barry Mienydd671972010-10-04 16:33:58 +02002058 'ar_keys' => array(),
2059 'ar_limit' => FALSE,
Derek Allard2067d1a2008-11-13 22:59:24 +00002060 'ar_order' => FALSE
2061 );
2062
2063 $this->_reset_run($ar_reset_items);
2064 }
Barry Mienydd671972010-10-04 16:33:58 +02002065
Derek Allard2067d1a2008-11-13 22:59:24 +00002066}
2067
2068/* End of file DB_active_rec.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +00002069/* Location: ./system/database/DB_active_rec.php */