blob: c986ddec20dbfa28887f3b8d29d8542eb1d894ab [file] [log] [blame]
Derek Allard09de1852007-02-14 01:35:56 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
Derek Allardd2df9bc2007-04-15 17:41:17 +00003 * CodeIgniter
Derek Allard09de1852007-02-14 01:35:56 +00004 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Allard6838f002007-10-04 19:29:59 +000010 * @license http://www.codeigniter.com/user_guide/license.html
Derek Allard09de1852007-02-14 01:35:56 +000011 * @link http://www.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 Rick Ellis
27 * @link http://www.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();
39 var $ar_limit = FALSE;
40 var $ar_offset = FALSE;
41 var $ar_order = FALSE;
42 var $ar_orderby = array();
43 var $ar_set = array();
Derek Allard80dd7022007-12-18 23:55:06 +000044 var $ar_wherein = array();
Derek Allard5e128942007-12-28 21:33:03 +000045 var $ar_aliased_tables = array();
Derek Allard09de1852007-02-14 01:35:56 +000046
Derek Allard09de1852007-02-14 01:35:56 +000047 /**
48 * Select
49 *
50 * Generates the SELECT portion of the query
51 *
52 * @access public
53 * @param string
54 * @return object
55 */
Derek Allard39b622d2008-01-16 21:10:09 +000056 function select($select = '*', $protect_identifiers = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +000057 {
58 if (is_string($select))
59 {
60 $select = explode(',', $select);
61 }
62
63 foreach ($select as $val)
64 {
65 $val = trim($val);
Derek Allard39b622d2008-01-16 21:10:09 +000066
67 if ($val != '*' && $protect_identifiers !== FALSE)
68 {
69 $val = $this->_protect_identifiers($val);
70 }
Derek Allard09de1852007-02-14 01:35:56 +000071
72 if ($val != '')
Derek Allard39b622d2008-01-16 21:10:09 +000073 {
Derek Allard09de1852007-02-14 01:35:56 +000074 $this->ar_select[] = $val;
Derek Allard39b622d2008-01-16 21:10:09 +000075 }
Derek Allard09de1852007-02-14 01:35:56 +000076 }
77 return $this;
78 }
Derek Allard39b622d2008-01-16 21:10:09 +000079
80 // --------------------------------------------------------------------
81
82 /**
83 * Select Max
84 *
85 * Generates a SELECT MAX(field) portion of a query
86 *
87 * @access public
88 * @param string the field
89 * @param string an alias
90 * @return object
91 */
92 function select_max($select = '', $alias='')
93 {
94 if (!is_string($select) || $select == '')
95 {
96 $this->display_error('db_invalid_query');
97 }
Derek Allard09de1852007-02-14 01:35:56 +000098
Derek Allard39b622d2008-01-16 21:10:09 +000099 $alias = ($alias != '') ? $alias : $select;
100
101 $sql = 'MAX('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
102
103 $this->ar_select[] = $sql;
104
105 return $this;
106
107 return $this;
108 }
109
110 // --------------------------------------------------------------------
111
112 /**
113 * Select Min
114 *
115 * Generates a SELECT MIN(field) portion of a query
116 *
117 * @access public
118 * @param string the field
119 * @param string an alias
120 * @return object
121 */
122 function select_min($select = '', $alias='')
123 {
124 if (!is_string($select) || $select == '')
125 {
126 $this->display_error('db_invalid_query');
127 }
128
129 $alias = ($alias != '') ? $alias : $select;
130
131 $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
132
133 $this->ar_select[] = $sql;
134
135 return $this;
136 }
137
138 // --------------------------------------------------------------------
139
140 /**
141 * Select Average
142 *
143 * Generates a SELECT AVG(field) portion of a query
144 *
145 * @access public
146 * @param string the field
147 * @param string an alias
148 * @return object
149 */
150 function select_avg($select = '', $alias='')
151 {
152 if (!is_string($select) || $select == '')
153 {
154 $this->display_error('db_invalid_query');
155 }
156
157 $alias = ($alias != '') ? $alias : $select;
158
159 $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
160
161 $this->ar_select[] = $sql;
162
163 return $this;
164 }
165
166 // --------------------------------------------------------------------
167
168 /**
169 * Select Sum
170 *
171 * Generates a SELECT SUM(field) portion of a query
172 *
173 * @access public
174 * @param string the field
175 * @param string an alias
176 * @return object
177 */
178 function select_sum($select = '', $alias='')
179 {
180 if (!is_string($select) || $select == '')
181 {
182 $this->display_error('db_invalid_query');
183 }
184
185 $alias = ($alias != '') ? $alias : $select;
186
187 $sql = 'SUM('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
188
189 $this->ar_select[] = $sql;
190
191 return $this;
192 }
193
Derek Allard09de1852007-02-14 01:35:56 +0000194 // --------------------------------------------------------------------
195
196 /**
197 * DISTINCT
198 *
199 * Sets a flag which tells the query string compiler to add DISTINCT
200 *
201 * @access public
202 * @param bool
203 * @return object
204 */
205 function distinct($val = TRUE)
206 {
207 $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
208 return $this;
209 }
210
211 // --------------------------------------------------------------------
212
213 /**
214 * From
215 *
216 * Generates the FROM portion of the query
217 *
218 * @access public
219 * @param mixed can be a string or array
220 * @return object
221 */
222 function from($from)
223 {
224 foreach ((array)$from as $val)
225 {
Derek Allard39b622d2008-01-16 21:10:09 +0000226 $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val));
Derek Allard09de1852007-02-14 01:35:56 +0000227 }
Derek Allard5e128942007-12-28 21:33:03 +0000228
Derek Allard09de1852007-02-14 01:35:56 +0000229 return $this;
230 }
231
232 // --------------------------------------------------------------------
233
234 /**
235 * Join
236 *
237 * Generates the JOIN portion of the query
238 *
239 * @access public
240 * @param string
241 * @param string the join condition
242 * @param string the type of join
243 * @return object
244 */
245 function join($table, $cond, $type = '')
246 {
247 if ($type != '')
248 {
249 $type = strtoupper(trim($type));
250
251 if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE))
252 {
253 $type = '';
254 }
255 else
256 {
257 $type .= ' ';
258 }
259 }
260
Derek Allard09de1852007-02-14 01:35:56 +0000261 // If a DB prefix is used we might need to add it to the column names
262 if ($this->dbprefix)
263 {
Derek Allard39b622d2008-01-16 21:10:09 +0000264 $this->_track_aliases($table);
265
Derek Allard09de1852007-02-14 01:35:56 +0000266 // First we remove any existing prefixes in the condition to avoid duplicates
267 $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond);
268
269 // Next we add the prefixes to the condition
270 $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond);
Derek Allard5e128942007-12-28 21:33:03 +0000271 }
272
Derek Allard39b622d2008-01-16 21:10:09 +0000273 $this->ar_join[] = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond;
Derek Allard09de1852007-02-14 01:35:56 +0000274 return $this;
275 }
276
277 // --------------------------------------------------------------------
278
279 /**
280 * Where
281 *
282 * Generates the WHERE portion of the query. Separates
283 * multiple calls with AND
284 *
285 * @access public
286 * @param mixed
287 * @param mixed
288 * @return object
289 */
Derek Allard39b622d2008-01-16 21:10:09 +0000290 function where($key, $value = NULL, $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000291 {
Derek Allard39b622d2008-01-16 21:10:09 +0000292 return $this->_where($key, $value, 'AND ', $escape);
Derek Allard09de1852007-02-14 01:35:56 +0000293 }
294
295 // --------------------------------------------------------------------
296
297 /**
298 * OR Where
299 *
300 * Generates the WHERE portion of the query. Separates
301 * multiple calls with OR
302 *
303 * @access public
304 * @param mixed
305 * @param mixed
306 * @return object
307 */
Derek Allard39b622d2008-01-16 21:10:09 +0000308 function or_where($key, $value = NULL, $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000309 {
Derek Allard39b622d2008-01-16 21:10:09 +0000310 return $this->_where($key, $value, 'OR ', $escape);
Derek Allard09de1852007-02-14 01:35:56 +0000311 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000312
313 // --------------------------------------------------------------------
314
315 /**
316 * orwhere() is an alias of or_where()
317 * this function is here for backwards compatibility, as
318 * orwhere() has been deprecated
319 */
Derek Allard39b622d2008-01-16 21:10:09 +0000320 function orwhere($key, $value = NULL, $escape = TRUE)
Derek Allard218e2bc2007-12-17 21:18:14 +0000321 {
Derek Allard39b622d2008-01-16 21:10:09 +0000322 return $this->or_where($key, $value, $escape);
Derek Allard218e2bc2007-12-17 21:18:14 +0000323 }
Derek Allard67b44ed2008-01-12 16:18:02 +0000324
325 // --------------------------------------------------------------------
326
327 /**
Derek Allard09de1852007-02-14 01:35:56 +0000328 * Where
329 *
330 * Called by where() or orwhere()
331 *
332 * @access private
333 * @param mixed
334 * @param mixed
335 * @param string
336 * @return object
337 */
Derek Allard39b622d2008-01-16 21:10:09 +0000338 function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000339 {
340 if ( ! is_array($key))
341 {
342 $key = array($key => $value);
343 }
344
345 foreach ($key as $k => $v)
346 {
347 $prefix = (count($this->ar_where) == 0) ? '' : $type;
Derek Allard15ddc9d2007-12-20 13:54:39 +0000348
Derek Allard39b622d2008-01-16 21:10:09 +0000349 if ( ! $this->_has_operator($k) && is_null($key[$k]))
Derek Allard15ddc9d2007-12-20 13:54:39 +0000350 {
351 // value appears not to have been set, assign the test to IS NULL
352 $k .= ' IS NULL';
353 }
Derek Allard09de1852007-02-14 01:35:56 +0000354
355 if ( ! is_null($v))
356 {
Derek Allard39b622d2008-01-16 21:10:09 +0000357
358 if ($escape === TRUE)
359 {
360 // exception for "field<=" keys
361 if ($this->_has_operator($k))
362 {
363 $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_protect_identifiers('$1'), $k);
364 }
365 else
366 {
367 $k = $this->_protect_identifiers($k);
368 }
369 }
370
Derek Allard09de1852007-02-14 01:35:56 +0000371 if ( ! $this->_has_operator($k))
372 {
373 $k .= ' =';
374 }
Derek Allard39b622d2008-01-16 21:10:09 +0000375
Derek Allard09de1852007-02-14 01:35:56 +0000376 $v = ' '.$this->escape($v);
Derek Allard15ddc9d2007-12-20 13:54:39 +0000377
Derek Allard09de1852007-02-14 01:35:56 +0000378 }
379
380 $this->ar_where[] = $prefix.$k.$v;
381 }
382 return $this;
383 }
Derek Allard80dd7022007-12-18 23:55:06 +0000384
385 // --------------------------------------------------------------------
386
387 /**
388 * Where_in
389 *
Derek Allardc6935512007-12-19 14:23:19 +0000390 * Generates a WHERE field IN ('item', 'item') SQL query joined with
391 * AND if appropriate
Derek Allard80dd7022007-12-18 23:55:06 +0000392 *
393 * @access public
394 * @param string The field to search
395 * @param array The values searched on
Derek Allardc6935512007-12-19 14:23:19 +0000396
397 * @return object
398 */
399 function where_in($key = NULL, $values = NULL)
400 {
401 return $this->_where_in($key, $values);
402 }
403
404 // --------------------------------------------------------------------
405
406 /**
407 * Where_in_or
408 *
409 * Generates a WHERE field IN ('item', 'item') SQL query joined with
410 * OR if appropriate
411 *
412 * @access public
413 * @param string The field to search
414 * @param array The values searched on
415
416 * @return object
417 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000418 function or_where_in($key = NULL, $values = NULL)
Derek Allardc6935512007-12-19 14:23:19 +0000419 {
Derek Allard15ddc9d2007-12-20 13:54:39 +0000420 return $this->_where_in($key, $values, FALSE, 'OR ');
Derek Allardc6935512007-12-19 14:23:19 +0000421 }
422
423 // --------------------------------------------------------------------
424
425 /**
426 * Where_not_in
427 *
428 * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
429 * with AND if appropriate
430 *
431 * @access public
432 * @param string The field to search
433 * @param array The values searched on
434
435 * @return object
436 */
437 function where_not_in($key = NULL, $values = NULL)
438 {
439 return $this->_where_in($key, $values, TRUE);
440 }
441
442 // --------------------------------------------------------------------
443
444 /**
445 * Where_not_in_or
446 *
447 * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
448 * with OR if appropriate
449 *
450 * @access public
451 * @param string The field to search
452 * @param array The values searched on
453
454 * @return object
455 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000456 function or_where_not_in($key = NULL, $values = NULL)
Derek Allardc6935512007-12-19 14:23:19 +0000457 {
Derek Allard15ddc9d2007-12-20 13:54:39 +0000458 return $this->_where_in($key, $values, FALSE, 'OR ');
Derek Allardc6935512007-12-19 14:23:19 +0000459 }
460
461 // --------------------------------------------------------------------
462
463 /**
464 * Where_in
465 *
466 * Called by where_in, where_in_or, where_not_in, where_not_in_or
467 *
468 * @access public
469 * @param string The field to search
470 * @param array The values searched on
471 * @param boolean If the statement whould be IN or NOT IN
Derek Allard80dd7022007-12-18 23:55:06 +0000472 * @param string
473 * @return object
474 */
Derek Allard15ddc9d2007-12-20 13:54:39 +0000475 function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
Derek Allard80dd7022007-12-18 23:55:06 +0000476 {
477 if ($key === NULL || !is_array($values))
478 {
479 return;
480 }
481
Derek Allardc6935512007-12-19 14:23:19 +0000482 $not = ($not) ? ' NOT ' : '';
Derek Allard80dd7022007-12-18 23:55:06 +0000483
484 foreach ($values as $value)
485 {
486 $this->ar_wherein[] = $this->escape($value);
487 }
488
489 $prefix = (count($this->ar_where) == 0) ? '' : $type;
490
Derek Allard39b622d2008-01-16 21:10:09 +0000491 $this->ar_where[] = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
Derek Allard80dd7022007-12-18 23:55:06 +0000492
Derek Allard8f000212008-01-18 14:45:59 +0000493 // reset the array for multiple calls
494 $this->ar_wherein = array();
Derek Allard80dd7022007-12-18 23:55:06 +0000495 return $this;
496 }
497
Derek Allard09de1852007-02-14 01:35:56 +0000498 // --------------------------------------------------------------------
499
500 /**
501 * Like
502 *
503 * Generates a %LIKE% portion of the query. Separates
504 * multiple calls with AND
505 *
506 * @access public
507 * @param mixed
508 * @param mixed
509 * @return object
510 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000511 function like($field, $match = '', $side = 'both')
Derek Allard09de1852007-02-14 01:35:56 +0000512 {
Derek Allard218e2bc2007-12-17 21:18:14 +0000513 return $this->_like($field, $match, 'AND ', $side);
Derek Allard09de1852007-02-14 01:35:56 +0000514 }
Derek Allarde54e3d22007-12-19 15:53:44 +0000515
516 // --------------------------------------------------------------------
517
518 /**
519 * Not Like
520 *
521 * Generates a NOT LIKE portion of the query. Separates
522 * multiple calls with AND
523 *
524 * @access public
525 * @param mixed
526 * @param mixed
527 * @return object
528 */
529 function not_like($field, $match = '', $side = 'both')
530 {
531 return $this->_like($field, $match, 'AND ', $side, ' NOT');
532 }
533
Derek Allard09de1852007-02-14 01:35:56 +0000534 // --------------------------------------------------------------------
535
536 /**
537 * OR Like
538 *
539 * Generates a %LIKE% portion of the query. Separates
540 * multiple calls with OR
541 *
542 * @access public
543 * @param mixed
544 * @param mixed
545 * @return object
546 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000547 function or_like($field, $match = '', $side = 'both')
Derek Allard09de1852007-02-14 01:35:56 +0000548 {
Derek Allard218e2bc2007-12-17 21:18:14 +0000549 return $this->_like($field, $match, 'OR ', $side);
550 }
551
552 // --------------------------------------------------------------------
553
554 /**
Derek Allarde54e3d22007-12-19 15:53:44 +0000555 * OR Not Like
556 *
557 * Generates a NOT LIKE portion of the query. Separates
558 * multiple calls with OR
559 *
560 * @access public
561 * @param mixed
562 * @param mixed
563 * @return object
564 */
565 function or_not_like($field, $match = '', $side = 'both')
566 {
567 return $this->_like($field, $match, 'OR ', $side, 'NOT ');
568 }
569
570 // --------------------------------------------------------------------
571
572 /**
Derek Allard218e2bc2007-12-17 21:18:14 +0000573 * orlike() is an alias of or_like()
574 * this function is here for backwards compatibility, as
575 * orlike() has been deprecated
576 */
577 function orlike($field, $match = '', $side = 'both')
578 {
579 return $this->orlike($field, $match, $side);
Derek Allard09de1852007-02-14 01:35:56 +0000580 }
581
582 // --------------------------------------------------------------------
583
584 /**
585 * Like
586 *
587 * Called by like() or orlike()
588 *
589 * @access private
590 * @param mixed
591 * @param mixed
592 * @param string
593 * @return object
594 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000595 function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
Derek Allard09de1852007-02-14 01:35:56 +0000596 {
597 if ( ! is_array($field))
598 {
599 $field = array($field => $match);
600 }
601
602 foreach ($field as $k => $v)
Derek Allarde54e3d22007-12-19 15:53:44 +0000603 {
604
Derek Allard39b622d2008-01-16 21:10:09 +0000605 $k = $this->_protect_identifiers($k);
606
Derek Allard09de1852007-02-14 01:35:56 +0000607 $prefix = (count($this->ar_like) == 0) ? '' : $type;
Derek Allarde54e3d22007-12-19 15:53:44 +0000608
Derek Allard09de1852007-02-14 01:35:56 +0000609 $v = $this->escape_str($v);
Derek Allarde54e3d22007-12-19 15:53:44 +0000610
Derek Allard218e2bc2007-12-17 21:18:14 +0000611 if ($side == 'before')
612 {
Derek Allarde54e3d22007-12-19 15:53:44 +0000613 $this->ar_like[] = $prefix." $k $not LIKE '%{$v}'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000614 }
615 elseif ($side == 'after')
616 {
Derek Allarde54e3d22007-12-19 15:53:44 +0000617 $this->ar_like[] = $prefix." $k $not LIKE '{$v}%'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000618 }
619 else
620 {
Derek Allarde54e3d22007-12-19 15:53:44 +0000621 $this->ar_like[] = $prefix." $k $not LIKE '%{$v}%'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000622 }
Derek Allard09de1852007-02-14 01:35:56 +0000623 }
624 return $this;
625 }
626
627 // --------------------------------------------------------------------
628
629 /**
630 * GROUP BY
631 *
632 * @access public
633 * @param string
634 * @return object
635 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000636 function group_by($by)
Derek Allard09de1852007-02-14 01:35:56 +0000637 {
638 if (is_string($by))
639 {
640 $by = explode(',', $by);
641 }
642
643 foreach ($by as $val)
644 {
645 $val = trim($val);
646
647 if ($val != '')
Derek Allard39b622d2008-01-16 21:10:09 +0000648 $this->ar_groupby[] = $this->_protect_identifiers($val);
Derek Allard09de1852007-02-14 01:35:56 +0000649 }
650 return $this;
651 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000652
653 // --------------------------------------------------------------------
654
655 /**
656 * groupby() is an alias of group_by()
657 * this function is here for backwards compatibility, as
658 * groupby() has been deprecated
659 */
660 function groupby($by)
661 {
662 return $this->group_by($by);
663 }
664
Derek Allard09de1852007-02-14 01:35:56 +0000665 // --------------------------------------------------------------------
666
667 /**
668 * Sets the HAVING value
669 *
670 * Separates multiple calls with AND
671 *
672 * @access public
673 * @param string
674 * @param string
675 * @return object
676 */
677 function having($key, $value = '')
678 {
679 return $this->_having($key, $value, 'AND ');
680 }
681
682 // --------------------------------------------------------------------
683
684 /**
685 * Sets the OR HAVING value
686 *
687 * Separates multiple calls with OR
688 *
689 * @access public
690 * @param string
691 * @param string
692 * @return object
693 */
694 function orhaving($key, $value = '')
695 {
696 return $this->_having($key, $value, 'OR ');
697 }
698
699 // --------------------------------------------------------------------
700
701 /**
702 * Sets the HAVING values
703 *
704 * Called by having() or orhaving()
705 *
706 * @access private
707 * @param string
708 * @param string
709 * @return object
710 */
711 function _having($key, $value = '', $type = 'AND ')
712 {
713 if ( ! is_array($key))
714 {
715 $key = array($key => $value);
716 }
717
718 foreach ($key as $k => $v)
719 {
720 $prefix = (count($this->ar_having) == 0) ? '' : $type;
721
722 if ($v != '')
723 {
724 $v = ' '.$this->escape($v);
725 }
726
727 $this->ar_having[] = $prefix.$k.$v;
728 }
729 return $this;
730 }
731
732 // --------------------------------------------------------------------
733
734 /**
735 * Sets the ORDER BY value
736 *
737 * @access public
738 * @param string
739 * @param string direction: asc or desc
740 * @return object
741 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000742 function order_by($orderby, $direction = '')
Derek Allard09de1852007-02-14 01:35:56 +0000743 {
Derek Allard6ddb5a12007-12-18 17:22:50 +0000744 if (strtolower($direction) == 'random')
745 {
746 $orderby = ''; // Random results want or don't need a field name
747 $direction = $this->_random_keyword;
748 }
749 elseif (trim($direction) != '')
Derek Allard09de1852007-02-14 01:35:56 +0000750 {
Derek Allard92782492007-08-10 11:26:01 +0000751 $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
Derek Allard09de1852007-02-14 01:35:56 +0000752 }
753
Derek Allard05b3a5d2008-01-17 20:25:46 +0000754 $this->ar_orderby[] = $this->_protect_identifiers($orderby, TRUE).$direction;
Derek Allard09de1852007-02-14 01:35:56 +0000755 return $this;
756 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000757
Derek Allard218e2bc2007-12-17 21:18:14 +0000758 // --------------------------------------------------------------------
759
760 /**
761 * orderby() is an alias of order_by()
762 * this function is here for backwards compatibility, as
763 * orderby() has been deprecated
764 */
765 function orderby($orderby, $direction = '')
766 {
767 return $this->order_by($orderby, $direction);
768 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000769
Derek Allard09de1852007-02-14 01:35:56 +0000770 // --------------------------------------------------------------------
771
772 /**
773 * Sets the LIMIT value
774 *
775 * @access public
776 * @param integer the limit value
777 * @param integer the offset value
778 * @return object
779 */
780 function limit($value, $offset = '')
781 {
782 $this->ar_limit = $value;
783
784 if ($offset != '')
785 $this->ar_offset = $offset;
786
787 return $this;
788 }
789
790 // --------------------------------------------------------------------
791
792 /**
793 * Sets the OFFSET value
794 *
795 * @access public
796 * @param integer the offset value
797 * @return object
798 */
799 function offset($value)
800 {
801 $this->ar_offset = $value;
802 return $this;
803 }
804
805 // --------------------------------------------------------------------
806
807 /**
808 * The "set" function. Allows key/value pairs to be set for inserting or updating
809 *
810 * @access public
811 * @param mixed
812 * @param string
Derek Allard39b622d2008-01-16 21:10:09 +0000813 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +0000814 * @return object
815 */
Derek Allard39b622d2008-01-16 21:10:09 +0000816 function set($key, $value = '', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000817 {
818 $key = $this->_object_to_array($key);
819
820 if ( ! is_array($key))
821 {
822 $key = array($key => $value);
823 }
824
825 foreach ($key as $k => $v)
826 {
Derek Allard39b622d2008-01-16 21:10:09 +0000827 if ($escape === FALSE)
828 {
829 $this->ar_set[$this->_protect_identifiers($k)] = $v;
830 }
831 else
832 {
833 $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
834 }
835
Derek Allard09de1852007-02-14 01:35:56 +0000836 }
837
838 return $this;
839 }
840
841 // --------------------------------------------------------------------
842
843 /**
844 * Get
845 *
846 * Compiles the select statement based on the other functions called
847 * and runs the query
848 *
849 * @access public
Derek Allard694b5b82007-12-18 15:58:03 +0000850 * @param string the table
Derek Allard09de1852007-02-14 01:35:56 +0000851 * @param string the limit clause
852 * @param string the offset clause
853 * @return object
854 */
855 function get($table = '', $limit = null, $offset = null)
856 {
857 if ($table != '')
858 {
Derek Allard5e128942007-12-28 21:33:03 +0000859 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +0000860 $this->from($table);
861 }
862
863 if ( ! is_null($limit))
864 {
865 $this->limit($limit, $offset);
866 }
867
868 $sql = $this->_compile_select();
869
870 $result = $this->query($sql);
871 $this->_reset_select();
872 return $result;
873 }
874
Derek Allard09de1852007-02-14 01:35:56 +0000875 /**
Derek Allard694b5b82007-12-18 15:58:03 +0000876 * "Count All Results" query
877 *
878 * Generates a platform-specific query string that counts all records
879 * returned by an Active Record query.
880 *
881 * @access public
882 * @param string
883 * @return string
884 */
885 function count_all_results($table = '')
886 {
887 if ($table != '')
888 {
Derek Allard5e128942007-12-28 21:33:03 +0000889 $this->_track_aliases($table);
Derek Allard694b5b82007-12-18 15:58:03 +0000890 $this->from($table);
891 }
892
Derek Allard39b622d2008-01-16 21:10:09 +0000893 $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
Derek Allard694b5b82007-12-18 15:58:03 +0000894
895 $query = $this->query($sql);
896 $this->_reset_select();
897
898 if ($query->num_rows() == 0)
899 {
900 return '0';
901 }
902
903 $row = $query->row();
904 return $row->numrows;
905 }
906
907 // --------------------------------------------------------------------
908
909 /**
Derek Allard218e2bc2007-12-17 21:18:14 +0000910 * Get_Where
Derek Allard09de1852007-02-14 01:35:56 +0000911 *
912 * Allows the where clause, limit and offset to be added directly
913 *
914 * @access public
915 * @param string the where clause
916 * @param string the limit clause
917 * @param string the offset clause
918 * @return object
919 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000920 function get_where($table = '', $where = null, $limit = null, $offset = null)
Derek Allard09de1852007-02-14 01:35:56 +0000921 {
922 if ($table != '')
923 {
Derek Allard5e128942007-12-28 21:33:03 +0000924 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +0000925 $this->from($table);
926 }
927
928 if ( ! is_null($where))
929 {
930 $this->where($where);
931 }
932
933 if ( ! is_null($limit))
934 {
935 $this->limit($limit, $offset);
936 }
937
938 $sql = $this->_compile_select();
939
940 $result = $this->query($sql);
941 $this->_reset_select();
942 return $result;
943 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000944
945 // --------------------------------------------------------------------
946
947 /**
948 * getwhere() is an alias of get_where()
949 * this function is here for backwards compatibility, as
950 * getwhere() has been deprecated
951 */
952 function getwhere($table = '', $where = null, $limit = null, $offset = null)
953 {
954 return $this->get_where($table, $where, $limit, $offset);
955 }
Derek Allard09de1852007-02-14 01:35:56 +0000956
957 // --------------------------------------------------------------------
958
959 /**
960 * Insert
961 *
962 * Compiles an insert string and runs the query
963 *
964 * @access public
965 * @param string the table to retrieve the results from
966 * @param array an associative array of insert values
967 * @return object
968 */
969 function insert($table = '', $set = NULL)
970 {
971 if ( ! is_null($set))
972 {
973 $this->set($set);
974 }
975
976 if (count($this->ar_set) == 0)
977 {
978 if ($this->db_debug)
979 {
980 return $this->display_error('db_must_use_set');
981 }
982 return FALSE;
983 }
984
985 if ($table == '')
986 {
987 if ( ! isset($this->ar_from[0]))
988 {
989 if ($this->db_debug)
990 {
991 return $this->display_error('db_must_set_table');
992 }
993 return FALSE;
994 }
995
996 $table = $this->ar_from[0];
997 }
Derek Allard39b622d2008-01-16 21:10:09 +0000998
999 $sql = $this->_insert($this->_protect_identifiers($this->dbprefix.$table), array_keys($this->ar_set), array_values($this->ar_set));
Derek Allard09de1852007-02-14 01:35:56 +00001000
1001 $this->_reset_write();
1002 return $this->query($sql);
1003 }
1004
1005 // --------------------------------------------------------------------
1006
1007 /**
1008 * Update
1009 *
1010 * Compiles an update string and runs the query
1011 *
1012 * @access public
1013 * @param string the table to retrieve the results from
1014 * @param array an associative array of update values
1015 * @param mixed the where clause
1016 * @return object
1017 */
Derek Allard5e128942007-12-28 21:33:03 +00001018 function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001019 {
1020 if ( ! is_null($set))
1021 {
1022 $this->set($set);
1023 }
1024
1025 if (count($this->ar_set) == 0)
1026 {
1027 if ($this->db_debug)
1028 {
1029 return $this->display_error('db_must_use_set');
1030 }
1031 return FALSE;
1032 }
1033
1034 if ($table == '')
1035 {
1036 if ( ! isset($this->ar_from[0]))
1037 {
1038 if ($this->db_debug)
1039 {
1040 return $this->display_error('db_must_set_table');
1041 }
1042 return FALSE;
1043 }
1044
1045 $table = $this->ar_from[0];
1046 }
1047
Derek Allarde77d77c2007-12-19 15:01:55 +00001048 if ($where != NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001049 {
1050 $this->where($where);
1051 }
Derek Allardda6d2402007-12-19 14:49:29 +00001052
Derek Allarde77d77c2007-12-19 15:01:55 +00001053 if ($limit != NULL)
Derek Allardda6d2402007-12-19 14:49:29 +00001054 {
1055 $this->limit($limit);
1056 }
Derek Allard09de1852007-02-14 01:35:56 +00001057
Derek Allard39b622d2008-01-16 21:10:09 +00001058 $sql = $this->_update($this->_protect_identifiers($this->dbprefix.$table), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
Derek Allard09de1852007-02-14 01:35:56 +00001059
1060 $this->_reset_write();
1061 return $this->query($sql);
1062 }
Derek Allard39b622d2008-01-16 21:10:09 +00001063
1064 // --------------------------------------------------------------------
1065
1066 /**
1067 * Empty Table
1068 *
1069 * Compiles a delete string and runs "DELETE FROM table"
1070 *
1071 * @access public
1072 * @param string the table to empty
1073 * @return object
1074 */
1075 function empty_table($table = '')
1076 {
1077 if ($table == '')
1078 {
1079 if ( ! isset($this->ar_from[0]))
1080 {
1081 if ($this->db_debug)
1082 {
1083 return $this->display_error('db_must_set_table');
1084 }
1085 return FALSE;
1086 }
1087
1088 $table = $this->ar_from[0];
1089 }
1090 else
1091 {
1092 $table = $this->_protect_identifiers($this->dbprefix.$table);
1093 }
1094
1095
1096 $sql = $this->_delete($table);
1097
1098 $this->_reset_write();
1099
1100 return $this->query($sql);
1101 }
1102
1103 // --------------------------------------------------------------------
1104
1105 /**
1106 * Truncate
1107 *
1108 * Compiles a truncate string and runs the query
1109 * If the database does not support the truncate() command
1110 * This function maps to "DELETE FROM table"
1111 *
1112 * @access public
1113 * @param string the table to truncate
1114 * @return object
1115 */
1116 function truncate($table = '')
1117 {
1118 if ($table == '')
1119 {
1120 if ( ! isset($this->ar_from[0]))
1121 {
1122 if ($this->db_debug)
1123 {
1124 return $this->display_error('db_must_set_table');
1125 }
1126 return FALSE;
1127 }
1128
1129 $table = $this->ar_from[0];
1130 }
1131 else
1132 {
1133 $table = $this->_protect_identifiers($this->dbprefix.$table);
1134 }
1135
1136
1137 $sql = $this->_truncate($table);
1138
1139 $this->_reset_write();
1140
1141 return $this->query($sql);
1142 }
Derek Allard09de1852007-02-14 01:35:56 +00001143
1144 // --------------------------------------------------------------------
1145
1146 /**
1147 * Delete
1148 *
1149 * Compiles a delete string and runs the query
1150 *
1151 * @access public
Derek Allard41f60d42007-12-20 20:09:22 +00001152 * @param mixed the table(s) to delete from. String or array
Derek Allard09de1852007-02-14 01:35:56 +00001153 * @param mixed the where clause
Derek Allard41f60d42007-12-20 20:09:22 +00001154 * @param mixed the limit clause
1155 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +00001156 * @return object
1157 */
Derek Allard41f60d42007-12-20 20:09:22 +00001158 function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +00001159 {
1160 if ($table == '')
1161 {
1162 if ( ! isset($this->ar_from[0]))
1163 {
1164 if ($this->db_debug)
1165 {
1166 return $this->display_error('db_must_set_table');
1167 }
1168 return FALSE;
1169 }
Derek Allard39b622d2008-01-16 21:10:09 +00001170
Derek Allard09de1852007-02-14 01:35:56 +00001171 $table = $this->ar_from[0];
1172 }
Derek Allard39b622d2008-01-16 21:10:09 +00001173 elseif (is_array($table))
Derek Allard41f60d42007-12-20 20:09:22 +00001174 {
1175 foreach($table as $single_table)
1176 {
Derek Allard39b622d2008-01-16 21:10:09 +00001177 $this->delete($single_table, $where, $limit, FALSE);
Derek Allard41f60d42007-12-20 20:09:22 +00001178 }
Derek Allard39b622d2008-01-16 21:10:09 +00001179
Derek Allard41f60d42007-12-20 20:09:22 +00001180 $this->_reset_write();
1181 return;
1182 }
Derek Allard39b622d2008-01-16 21:10:09 +00001183 else
1184 {
1185 $table = $this->_protect_identifiers($this->dbprefix.$table);
1186 }
Derek Allard41f60d42007-12-20 20:09:22 +00001187
Derek Allard09de1852007-02-14 01:35:56 +00001188 if ($where != '')
1189 {
1190 $this->where($where);
1191 }
1192
Derek Allarde77d77c2007-12-19 15:01:55 +00001193 if ($limit != NULL)
1194 {
1195 $this->limit($limit);
1196 }
1197
Derek Allard39b622d2008-01-16 21:10:09 +00001198 if (count($this->ar_where) == 0 && count($this->ar_like) == 0)
Derek Allard09de1852007-02-14 01:35:56 +00001199 {
1200 if ($this->db_debug)
1201 {
1202 return $this->display_error('db_del_must_use_where');
1203 }
Derek Allard39b622d2008-01-16 21:10:09 +00001204
Derek Allard09de1852007-02-14 01:35:56 +00001205 return FALSE;
1206 }
Derek Allard41f60d42007-12-20 20:09:22 +00001207
Derek Allard39b622d2008-01-16 21:10:09 +00001208 $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
Derek Allard09de1852007-02-14 01:35:56 +00001209
Derek Allard41f60d42007-12-20 20:09:22 +00001210 if ($reset_data)
1211 {
1212 $this->_reset_write();
1213 }
Derek Allard39b622d2008-01-16 21:10:09 +00001214
Derek Allard09de1852007-02-14 01:35:56 +00001215 return $this->query($sql);
1216 }
Derek Allard15ddc9d2007-12-20 13:54:39 +00001217
Derek Allard09de1852007-02-14 01:35:56 +00001218 // --------------------------------------------------------------------
1219
1220 /**
1221 * Use Table - DEPRECATED
1222 *
1223 * @deprecated use $this->db->from instead
1224 */
1225 function use_table($table)
1226 {
1227 return $this->from($table);
1228 return $this;
1229 }
1230
1231 // --------------------------------------------------------------------
1232
1233 /**
Derek Allard09de1852007-02-14 01:35:56 +00001234 * Tests whether the string has an SQL operator
1235 *
1236 * @access private
1237 * @param string
1238 * @return bool
1239 */
1240 function _has_operator($str)
1241 {
1242 $str = trim($str);
1243 if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
1244 {
1245 return FALSE;
1246 }
1247
1248 return TRUE;
1249 }
1250
1251 // --------------------------------------------------------------------
1252
1253 /**
Derek Allard5e128942007-12-28 21:33:03 +00001254 * Track Aliases
1255 *
1256 * Used to track SQL statements written with aliased tables.
1257 *
1258 * @access private
1259 * @param string The table to inspect
1260 * @return string
1261 */
1262 function _track_aliases($table)
1263 {
1264 // if a table alias is used we can recognize it by a space
1265 if (strpos($table, " ") !== FALSE)
1266 {
1267 // if the alias is written with the AS keyowrd, get it out
Derek Allard39b622d2008-01-16 21:10:09 +00001268 $table = preg_replace('/ AS /i', ' ', $table);
Derek Allard5e128942007-12-28 21:33:03 +00001269
Derek Allard39b622d2008-01-16 21:10:09 +00001270 $this->ar_aliased_tables[] = trim(strrchr($table, " "));
Derek Allard5e128942007-12-28 21:33:03 +00001271 }
1272
1273 return $this->dbprefix.$table;
1274 }
1275
1276 // --------------------------------------------------------------------
1277
1278 /**
1279 * Filter Table Aliases
1280 *
1281 * Intelligently removes database prefixes from aliased tables
1282 *
1283 * @access private
1284 * @param array An array of compiled SQL
1285 * @return array Cleaned up statement with aliases accounted for
1286 */
1287 function _filter_table_aliases($statements)
1288 {
Derek Allard39b622d2008-01-16 21:10:09 +00001289 $statements_without_aliases = array();
Derek Allard5e128942007-12-28 21:33:03 +00001290
Derek Allard39b622d2008-01-16 21:10:09 +00001291 foreach ($statements as $k => $v)
Derek Allard5e128942007-12-28 21:33:03 +00001292 {
Derek Allard39b622d2008-01-16 21:10:09 +00001293 foreach ($this->ar_aliased_tables as $table)
Derek Allard5e128942007-12-28 21:33:03 +00001294 {
Derek Allard39b622d2008-01-16 21:10:09 +00001295 $statement = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $v); // makes `table.field`
1296 $statement = str_replace(array($this->dbprefix.$table, '.'), array($table, $this->_protect_identifiers('.')), $statement);
Derek Allard5e128942007-12-28 21:33:03 +00001297 }
1298
Derek Allard39b622d2008-01-16 21:10:09 +00001299 $statements[$k] = $statement;
Derek Allard5e128942007-12-28 21:33:03 +00001300 }
1301
Derek Allard39b622d2008-01-16 21:10:09 +00001302 return $statements;
Derek Allard5e128942007-12-28 21:33:03 +00001303 }
1304
1305 // --------------------------------------------------------------------
1306
1307 /**
Derek Allard09de1852007-02-14 01:35:56 +00001308 * Compile the SELECT statement
1309 *
1310 * Generates a query string based on which functions were used.
1311 * Should not be called directly. The get() function calls it.
1312 *
1313 * @access private
1314 * @return string
1315 */
Derek Allard694b5b82007-12-18 15:58:03 +00001316 function _compile_select($select_override = FALSE)
Derek Allard09de1852007-02-14 01:35:56 +00001317 {
1318 $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
1319
1320 $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select);
1321
Derek Allard694b5b82007-12-18 15:58:03 +00001322 if ($select_override !== FALSE)
1323 {
1324 $sql = $select_override;
1325 }
1326
Derek Allard09de1852007-02-14 01:35:56 +00001327 if (count($this->ar_from) > 0)
1328 {
1329 $sql .= "\nFROM ";
Derek Allard15ddc9d2007-12-20 13:54:39 +00001330 $sql .= '(' . implode(', ', $this->ar_from) . ')';
Derek Allard09de1852007-02-14 01:35:56 +00001331 }
1332
1333 if (count($this->ar_join) > 0)
Derek Allard5e128942007-12-28 21:33:03 +00001334 {
Derek Allard09de1852007-02-14 01:35:56 +00001335 $sql .= "\n";
Derek Allard5e128942007-12-28 21:33:03 +00001336
1337 // special consideration for table aliases
1338 if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
1339 {
1340 $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join));
1341 }
1342 else
1343 {
1344 $sql .= implode("\n", $this->ar_join);
1345 }
1346
Derek Allard09de1852007-02-14 01:35:56 +00001347 }
1348
1349 if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
1350 {
1351 $sql .= "\nWHERE ";
1352 }
1353
1354 $sql .= implode("\n", $this->ar_where);
1355
1356 if (count($this->ar_like) > 0)
1357 {
1358 if (count($this->ar_where) > 0)
1359 {
1360 $sql .= " AND ";
1361 }
1362
1363 $sql .= implode("\n", $this->ar_like);
1364 }
1365
1366 if (count($this->ar_groupby) > 0)
1367 {
Derek Allard5e128942007-12-28 21:33:03 +00001368
Derek Allard09de1852007-02-14 01:35:56 +00001369 $sql .= "\nGROUP BY ";
Derek Allard5e128942007-12-28 21:33:03 +00001370
1371 // special consideration for table aliases
1372 if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
1373 {
1374 $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby));
1375 }
1376 else
1377 {
1378 $sql .= implode(', ', $this->ar_groupby);
1379 }
Derek Allard09de1852007-02-14 01:35:56 +00001380 }
1381
1382 if (count($this->ar_having) > 0)
1383 {
1384 $sql .= "\nHAVING ";
1385 $sql .= implode("\n", $this->ar_having);
1386 }
1387
1388 if (count($this->ar_orderby) > 0)
1389 {
1390 $sql .= "\nORDER BY ";
1391 $sql .= implode(', ', $this->ar_orderby);
1392
1393 if ($this->ar_order !== FALSE)
1394 {
1395 $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
1396 }
1397 }
1398
1399 if (is_numeric($this->ar_limit))
1400 {
1401 $sql .= "\n";
1402 $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
1403 }
1404
1405 return $sql;
1406 }
1407
1408 // --------------------------------------------------------------------
1409
1410 /**
1411 * Object to Array
1412 *
1413 * Takes an object as input and converts the class variables to array key/vals
1414 *
1415 * @access public
1416 * @param object
1417 * @return array
1418 */
1419 function _object_to_array($object)
1420 {
1421 if ( ! is_object($object))
1422 {
1423 return $object;
1424 }
1425
1426 $array = array();
1427 foreach (get_object_vars($object) as $key => $val)
1428 {
Derek Allard848b7762007-12-31 16:43:05 +00001429 // There are some built in keys we need to ignore for this conversion
1430 if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table')
1431
Derek Allard09de1852007-02-14 01:35:56 +00001432 {
1433 $array[$key] = $val;
1434 }
1435 }
1436
1437 return $array;
1438 }
1439
1440 // --------------------------------------------------------------------
1441
1442 /**
1443 * Resets the active record values. Called by the get() function
1444 *
1445 * @access private
1446 * @return void
1447 */
1448 function _reset_select()
1449 {
1450 $this->ar_select = array();
1451 $this->ar_distinct = FALSE;
1452 $this->ar_from = array();
1453 $this->ar_join = array();
1454 $this->ar_where = array();
1455 $this->ar_like = array();
1456 $this->ar_groupby = array();
1457 $this->ar_having = array();
1458 $this->ar_limit = FALSE;
1459 $this->ar_offset = FALSE;
1460 $this->ar_order = FALSE;
1461 $this->ar_orderby = array();
Derek Allardc6935512007-12-19 14:23:19 +00001462 $this->ar_wherein = array();
Derek Allard5e128942007-12-28 21:33:03 +00001463 $this->ar_aliased_tables = array();
Derek Allard09de1852007-02-14 01:35:56 +00001464 }
1465
1466 // --------------------------------------------------------------------
1467
1468 /**
1469 * Resets the active record "write" values.
1470 *
Derek Allarde77d77c2007-12-19 15:01:55 +00001471 * Called by the insert() update() and delete() functions
Derek Allard09de1852007-02-14 01:35:56 +00001472 *
1473 * @access private
1474 * @return void
1475 */
1476 function _reset_write()
1477 {
1478 $this->ar_set = array();
1479 $this->ar_from = array();
1480 $this->ar_where = array();
Derek Allard39b622d2008-01-16 21:10:09 +00001481 $this->ar_like = array();
Derek Allardda6d2402007-12-19 14:49:29 +00001482 $this->ar_limit = FALSE;
Derek Allard39b622d2008-01-16 21:10:09 +00001483 $this->ar_order = FALSE;
1484 $this->ar_orderby = array();
Derek Allard09de1852007-02-14 01:35:56 +00001485 }
1486
1487}
1488
adminac94f382006-09-24 20:28:12 +00001489?>