blob: c899b7f4f3c1c355915c621468931a248d981261 [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
493 return $this;
494 }
495
Derek Allard09de1852007-02-14 01:35:56 +0000496 // --------------------------------------------------------------------
497
498 /**
499 * Like
500 *
501 * Generates a %LIKE% portion of the query. Separates
502 * multiple calls with AND
503 *
504 * @access public
505 * @param mixed
506 * @param mixed
507 * @return object
508 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000509 function like($field, $match = '', $side = 'both')
Derek Allard09de1852007-02-14 01:35:56 +0000510 {
Derek Allard218e2bc2007-12-17 21:18:14 +0000511 return $this->_like($field, $match, 'AND ', $side);
Derek Allard09de1852007-02-14 01:35:56 +0000512 }
Derek Allarde54e3d22007-12-19 15:53:44 +0000513
514 // --------------------------------------------------------------------
515
516 /**
517 * Not Like
518 *
519 * Generates a NOT LIKE portion of the query. Separates
520 * multiple calls with AND
521 *
522 * @access public
523 * @param mixed
524 * @param mixed
525 * @return object
526 */
527 function not_like($field, $match = '', $side = 'both')
528 {
529 return $this->_like($field, $match, 'AND ', $side, ' NOT');
530 }
531
Derek Allard09de1852007-02-14 01:35:56 +0000532 // --------------------------------------------------------------------
533
534 /**
535 * OR Like
536 *
537 * Generates a %LIKE% portion of the query. Separates
538 * multiple calls with OR
539 *
540 * @access public
541 * @param mixed
542 * @param mixed
543 * @return object
544 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000545 function or_like($field, $match = '', $side = 'both')
Derek Allard09de1852007-02-14 01:35:56 +0000546 {
Derek Allard218e2bc2007-12-17 21:18:14 +0000547 return $this->_like($field, $match, 'OR ', $side);
548 }
549
550 // --------------------------------------------------------------------
551
552 /**
Derek Allarde54e3d22007-12-19 15:53:44 +0000553 * OR Not Like
554 *
555 * Generates a NOT LIKE portion of the query. Separates
556 * multiple calls with OR
557 *
558 * @access public
559 * @param mixed
560 * @param mixed
561 * @return object
562 */
563 function or_not_like($field, $match = '', $side = 'both')
564 {
565 return $this->_like($field, $match, 'OR ', $side, 'NOT ');
566 }
567
568 // --------------------------------------------------------------------
569
570 /**
Derek Allard218e2bc2007-12-17 21:18:14 +0000571 * orlike() is an alias of or_like()
572 * this function is here for backwards compatibility, as
573 * orlike() has been deprecated
574 */
575 function orlike($field, $match = '', $side = 'both')
576 {
577 return $this->orlike($field, $match, $side);
Derek Allard09de1852007-02-14 01:35:56 +0000578 }
579
580 // --------------------------------------------------------------------
581
582 /**
583 * Like
584 *
585 * Called by like() or orlike()
586 *
587 * @access private
588 * @param mixed
589 * @param mixed
590 * @param string
591 * @return object
592 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000593 function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
Derek Allard09de1852007-02-14 01:35:56 +0000594 {
595 if ( ! is_array($field))
596 {
597 $field = array($field => $match);
598 }
599
600 foreach ($field as $k => $v)
Derek Allarde54e3d22007-12-19 15:53:44 +0000601 {
602
Derek Allard39b622d2008-01-16 21:10:09 +0000603 $k = $this->_protect_identifiers($k);
604
Derek Allard09de1852007-02-14 01:35:56 +0000605 $prefix = (count($this->ar_like) == 0) ? '' : $type;
Derek Allarde54e3d22007-12-19 15:53:44 +0000606
Derek Allard09de1852007-02-14 01:35:56 +0000607 $v = $this->escape_str($v);
Derek Allarde54e3d22007-12-19 15:53:44 +0000608
Derek Allard218e2bc2007-12-17 21:18:14 +0000609 if ($side == 'before')
610 {
Derek Allarde54e3d22007-12-19 15:53:44 +0000611 $this->ar_like[] = $prefix." $k $not LIKE '%{$v}'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000612 }
613 elseif ($side == 'after')
614 {
Derek Allarde54e3d22007-12-19 15:53:44 +0000615 $this->ar_like[] = $prefix." $k $not LIKE '{$v}%'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000616 }
617 else
618 {
Derek Allarde54e3d22007-12-19 15:53:44 +0000619 $this->ar_like[] = $prefix." $k $not LIKE '%{$v}%'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000620 }
Derek Allard09de1852007-02-14 01:35:56 +0000621 }
622 return $this;
623 }
624
625 // --------------------------------------------------------------------
626
627 /**
628 * GROUP BY
629 *
630 * @access public
631 * @param string
632 * @return object
633 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000634 function group_by($by)
Derek Allard09de1852007-02-14 01:35:56 +0000635 {
636 if (is_string($by))
637 {
638 $by = explode(',', $by);
639 }
640
641 foreach ($by as $val)
642 {
643 $val = trim($val);
644
645 if ($val != '')
Derek Allard39b622d2008-01-16 21:10:09 +0000646 $this->ar_groupby[] = $this->_protect_identifiers($val);
Derek Allard09de1852007-02-14 01:35:56 +0000647 }
648 return $this;
649 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000650
651 // --------------------------------------------------------------------
652
653 /**
654 * groupby() is an alias of group_by()
655 * this function is here for backwards compatibility, as
656 * groupby() has been deprecated
657 */
658 function groupby($by)
659 {
660 return $this->group_by($by);
661 }
662
Derek Allard09de1852007-02-14 01:35:56 +0000663 // --------------------------------------------------------------------
664
665 /**
666 * Sets the HAVING value
667 *
668 * Separates multiple calls with AND
669 *
670 * @access public
671 * @param string
672 * @param string
673 * @return object
674 */
675 function having($key, $value = '')
676 {
677 return $this->_having($key, $value, 'AND ');
678 }
679
680 // --------------------------------------------------------------------
681
682 /**
683 * Sets the OR HAVING value
684 *
685 * Separates multiple calls with OR
686 *
687 * @access public
688 * @param string
689 * @param string
690 * @return object
691 */
692 function orhaving($key, $value = '')
693 {
694 return $this->_having($key, $value, 'OR ');
695 }
696
697 // --------------------------------------------------------------------
698
699 /**
700 * Sets the HAVING values
701 *
702 * Called by having() or orhaving()
703 *
704 * @access private
705 * @param string
706 * @param string
707 * @return object
708 */
709 function _having($key, $value = '', $type = 'AND ')
710 {
711 if ( ! is_array($key))
712 {
713 $key = array($key => $value);
714 }
715
716 foreach ($key as $k => $v)
717 {
718 $prefix = (count($this->ar_having) == 0) ? '' : $type;
719
720 if ($v != '')
721 {
722 $v = ' '.$this->escape($v);
723 }
724
725 $this->ar_having[] = $prefix.$k.$v;
726 }
727 return $this;
728 }
729
730 // --------------------------------------------------------------------
731
732 /**
733 * Sets the ORDER BY value
734 *
735 * @access public
736 * @param string
737 * @param string direction: asc or desc
738 * @return object
739 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000740 function order_by($orderby, $direction = '')
Derek Allard09de1852007-02-14 01:35:56 +0000741 {
Derek Allard6ddb5a12007-12-18 17:22:50 +0000742 if (strtolower($direction) == 'random')
743 {
744 $orderby = ''; // Random results want or don't need a field name
745 $direction = $this->_random_keyword;
746 }
747 elseif (trim($direction) != '')
Derek Allard09de1852007-02-14 01:35:56 +0000748 {
Derek Allard92782492007-08-10 11:26:01 +0000749 $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
Derek Allard09de1852007-02-14 01:35:56 +0000750 }
751
Derek Allard05b3a5d2008-01-17 20:25:46 +0000752 $this->ar_orderby[] = $this->_protect_identifiers($orderby, TRUE).$direction;
753
Derek Allard09de1852007-02-14 01:35:56 +0000754 return $this;
755 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000756
Derek Allard218e2bc2007-12-17 21:18:14 +0000757 // --------------------------------------------------------------------
758
759 /**
760 * orderby() is an alias of order_by()
761 * this function is here for backwards compatibility, as
762 * orderby() has been deprecated
763 */
764 function orderby($orderby, $direction = '')
765 {
766 return $this->order_by($orderby, $direction);
767 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000768
Derek Allard09de1852007-02-14 01:35:56 +0000769 // --------------------------------------------------------------------
770
771 /**
772 * Sets the LIMIT value
773 *
774 * @access public
775 * @param integer the limit value
776 * @param integer the offset value
777 * @return object
778 */
779 function limit($value, $offset = '')
780 {
781 $this->ar_limit = $value;
782
783 if ($offset != '')
784 $this->ar_offset = $offset;
785
786 return $this;
787 }
788
789 // --------------------------------------------------------------------
790
791 /**
792 * Sets the OFFSET value
793 *
794 * @access public
795 * @param integer the offset value
796 * @return object
797 */
798 function offset($value)
799 {
800 $this->ar_offset = $value;
801 return $this;
802 }
803
804 // --------------------------------------------------------------------
805
806 /**
807 * The "set" function. Allows key/value pairs to be set for inserting or updating
808 *
809 * @access public
810 * @param mixed
811 * @param string
Derek Allard39b622d2008-01-16 21:10:09 +0000812 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +0000813 * @return object
814 */
Derek Allard39b622d2008-01-16 21:10:09 +0000815 function set($key, $value = '', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000816 {
817 $key = $this->_object_to_array($key);
818
819 if ( ! is_array($key))
820 {
821 $key = array($key => $value);
822 }
823
824 foreach ($key as $k => $v)
825 {
Derek Allard39b622d2008-01-16 21:10:09 +0000826 if ($escape === FALSE)
827 {
828 $this->ar_set[$this->_protect_identifiers($k)] = $v;
829 }
830 else
831 {
832 $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
833 }
834
Derek Allard09de1852007-02-14 01:35:56 +0000835 }
836
837 return $this;
838 }
839
840 // --------------------------------------------------------------------
841
842 /**
843 * Get
844 *
845 * Compiles the select statement based on the other functions called
846 * and runs the query
847 *
848 * @access public
Derek Allard694b5b82007-12-18 15:58:03 +0000849 * @param string the table
Derek Allard09de1852007-02-14 01:35:56 +0000850 * @param string the limit clause
851 * @param string the offset clause
852 * @return object
853 */
854 function get($table = '', $limit = null, $offset = null)
855 {
856 if ($table != '')
857 {
Derek Allard5e128942007-12-28 21:33:03 +0000858 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +0000859 $this->from($table);
860 }
861
862 if ( ! is_null($limit))
863 {
864 $this->limit($limit, $offset);
865 }
866
867 $sql = $this->_compile_select();
868
869 $result = $this->query($sql);
870 $this->_reset_select();
871 return $result;
872 }
873
Derek Allard09de1852007-02-14 01:35:56 +0000874 /**
Derek Allard694b5b82007-12-18 15:58:03 +0000875 * "Count All Results" query
876 *
877 * Generates a platform-specific query string that counts all records
878 * returned by an Active Record query.
879 *
880 * @access public
881 * @param string
882 * @return string
883 */
884 function count_all_results($table = '')
885 {
886 if ($table != '')
887 {
Derek Allard5e128942007-12-28 21:33:03 +0000888 $this->_track_aliases($table);
Derek Allard694b5b82007-12-18 15:58:03 +0000889 $this->from($table);
890 }
891
Derek Allard39b622d2008-01-16 21:10:09 +0000892 $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
Derek Allard694b5b82007-12-18 15:58:03 +0000893
894 $query = $this->query($sql);
895 $this->_reset_select();
896
897 if ($query->num_rows() == 0)
898 {
899 return '0';
900 }
901
902 $row = $query->row();
903 return $row->numrows;
904 }
905
906 // --------------------------------------------------------------------
907
908 /**
Derek Allard218e2bc2007-12-17 21:18:14 +0000909 * Get_Where
Derek Allard09de1852007-02-14 01:35:56 +0000910 *
911 * Allows the where clause, limit and offset to be added directly
912 *
913 * @access public
914 * @param string the where clause
915 * @param string the limit clause
916 * @param string the offset clause
917 * @return object
918 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000919 function get_where($table = '', $where = null, $limit = null, $offset = null)
Derek Allard09de1852007-02-14 01:35:56 +0000920 {
921 if ($table != '')
922 {
Derek Allard5e128942007-12-28 21:33:03 +0000923 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +0000924 $this->from($table);
925 }
926
927 if ( ! is_null($where))
928 {
929 $this->where($where);
930 }
931
932 if ( ! is_null($limit))
933 {
934 $this->limit($limit, $offset);
935 }
936
937 $sql = $this->_compile_select();
938
939 $result = $this->query($sql);
940 $this->_reset_select();
941 return $result;
942 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000943
944 // --------------------------------------------------------------------
945
946 /**
947 * getwhere() is an alias of get_where()
948 * this function is here for backwards compatibility, as
949 * getwhere() has been deprecated
950 */
951 function getwhere($table = '', $where = null, $limit = null, $offset = null)
952 {
953 return $this->get_where($table, $where, $limit, $offset);
954 }
Derek Allard09de1852007-02-14 01:35:56 +0000955
956 // --------------------------------------------------------------------
957
958 /**
959 * Insert
960 *
961 * Compiles an insert string and runs the query
962 *
963 * @access public
964 * @param string the table to retrieve the results from
965 * @param array an associative array of insert values
966 * @return object
967 */
968 function insert($table = '', $set = NULL)
969 {
970 if ( ! is_null($set))
971 {
972 $this->set($set);
973 }
974
975 if (count($this->ar_set) == 0)
976 {
977 if ($this->db_debug)
978 {
979 return $this->display_error('db_must_use_set');
980 }
981 return FALSE;
982 }
983
984 if ($table == '')
985 {
986 if ( ! isset($this->ar_from[0]))
987 {
988 if ($this->db_debug)
989 {
990 return $this->display_error('db_must_set_table');
991 }
992 return FALSE;
993 }
994
995 $table = $this->ar_from[0];
996 }
Derek Allard39b622d2008-01-16 21:10:09 +0000997
998 $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 +0000999
1000 $this->_reset_write();
1001 return $this->query($sql);
1002 }
1003
1004 // --------------------------------------------------------------------
1005
1006 /**
1007 * Update
1008 *
1009 * Compiles an update string and runs the query
1010 *
1011 * @access public
1012 * @param string the table to retrieve the results from
1013 * @param array an associative array of update values
1014 * @param mixed the where clause
1015 * @return object
1016 */
Derek Allard5e128942007-12-28 21:33:03 +00001017 function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001018 {
1019 if ( ! is_null($set))
1020 {
1021 $this->set($set);
1022 }
1023
1024 if (count($this->ar_set) == 0)
1025 {
1026 if ($this->db_debug)
1027 {
1028 return $this->display_error('db_must_use_set');
1029 }
1030 return FALSE;
1031 }
1032
1033 if ($table == '')
1034 {
1035 if ( ! isset($this->ar_from[0]))
1036 {
1037 if ($this->db_debug)
1038 {
1039 return $this->display_error('db_must_set_table');
1040 }
1041 return FALSE;
1042 }
1043
1044 $table = $this->ar_from[0];
1045 }
1046
Derek Allarde77d77c2007-12-19 15:01:55 +00001047 if ($where != NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001048 {
1049 $this->where($where);
1050 }
Derek Allardda6d2402007-12-19 14:49:29 +00001051
Derek Allarde77d77c2007-12-19 15:01:55 +00001052 if ($limit != NULL)
Derek Allardda6d2402007-12-19 14:49:29 +00001053 {
1054 $this->limit($limit);
1055 }
Derek Allard09de1852007-02-14 01:35:56 +00001056
Derek Allard39b622d2008-01-16 21:10:09 +00001057 $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 +00001058
1059 $this->_reset_write();
1060 return $this->query($sql);
1061 }
Derek Allard39b622d2008-01-16 21:10:09 +00001062
1063 // --------------------------------------------------------------------
1064
1065 /**
1066 * Empty Table
1067 *
1068 * Compiles a delete string and runs "DELETE FROM table"
1069 *
1070 * @access public
1071 * @param string the table to empty
1072 * @return object
1073 */
1074 function empty_table($table = '')
1075 {
1076 if ($table == '')
1077 {
1078 if ( ! isset($this->ar_from[0]))
1079 {
1080 if ($this->db_debug)
1081 {
1082 return $this->display_error('db_must_set_table');
1083 }
1084 return FALSE;
1085 }
1086
1087 $table = $this->ar_from[0];
1088 }
1089 else
1090 {
1091 $table = $this->_protect_identifiers($this->dbprefix.$table);
1092 }
1093
1094
1095 $sql = $this->_delete($table);
1096
1097 $this->_reset_write();
1098
1099 return $this->query($sql);
1100 }
1101
1102 // --------------------------------------------------------------------
1103
1104 /**
1105 * Truncate
1106 *
1107 * Compiles a truncate string and runs the query
1108 * If the database does not support the truncate() command
1109 * This function maps to "DELETE FROM table"
1110 *
1111 * @access public
1112 * @param string the table to truncate
1113 * @return object
1114 */
1115 function truncate($table = '')
1116 {
1117 if ($table == '')
1118 {
1119 if ( ! isset($this->ar_from[0]))
1120 {
1121 if ($this->db_debug)
1122 {
1123 return $this->display_error('db_must_set_table');
1124 }
1125 return FALSE;
1126 }
1127
1128 $table = $this->ar_from[0];
1129 }
1130 else
1131 {
1132 $table = $this->_protect_identifiers($this->dbprefix.$table);
1133 }
1134
1135
1136 $sql = $this->_truncate($table);
1137
1138 $this->_reset_write();
1139
1140 return $this->query($sql);
1141 }
Derek Allard09de1852007-02-14 01:35:56 +00001142
1143 // --------------------------------------------------------------------
1144
1145 /**
1146 * Delete
1147 *
1148 * Compiles a delete string and runs the query
1149 *
1150 * @access public
Derek Allard41f60d42007-12-20 20:09:22 +00001151 * @param mixed the table(s) to delete from. String or array
Derek Allard09de1852007-02-14 01:35:56 +00001152 * @param mixed the where clause
Derek Allard41f60d42007-12-20 20:09:22 +00001153 * @param mixed the limit clause
1154 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +00001155 * @return object
1156 */
Derek Allard41f60d42007-12-20 20:09:22 +00001157 function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +00001158 {
1159 if ($table == '')
1160 {
1161 if ( ! isset($this->ar_from[0]))
1162 {
1163 if ($this->db_debug)
1164 {
1165 return $this->display_error('db_must_set_table');
1166 }
1167 return FALSE;
1168 }
Derek Allard39b622d2008-01-16 21:10:09 +00001169
Derek Allard09de1852007-02-14 01:35:56 +00001170 $table = $this->ar_from[0];
1171 }
Derek Allard39b622d2008-01-16 21:10:09 +00001172 elseif (is_array($table))
Derek Allard41f60d42007-12-20 20:09:22 +00001173 {
1174 foreach($table as $single_table)
1175 {
Derek Allard39b622d2008-01-16 21:10:09 +00001176 $this->delete($single_table, $where, $limit, FALSE);
Derek Allard41f60d42007-12-20 20:09:22 +00001177 }
Derek Allard39b622d2008-01-16 21:10:09 +00001178
Derek Allard41f60d42007-12-20 20:09:22 +00001179 $this->_reset_write();
1180 return;
1181 }
Derek Allard39b622d2008-01-16 21:10:09 +00001182 else
1183 {
1184 $table = $this->_protect_identifiers($this->dbprefix.$table);
1185 }
Derek Allard41f60d42007-12-20 20:09:22 +00001186
Derek Allard09de1852007-02-14 01:35:56 +00001187 if ($where != '')
1188 {
1189 $this->where($where);
1190 }
1191
Derek Allarde77d77c2007-12-19 15:01:55 +00001192 if ($limit != NULL)
1193 {
1194 $this->limit($limit);
1195 }
1196
Derek Allard39b622d2008-01-16 21:10:09 +00001197 if (count($this->ar_where) == 0 && count($this->ar_like) == 0)
Derek Allard09de1852007-02-14 01:35:56 +00001198 {
1199 if ($this->db_debug)
1200 {
1201 return $this->display_error('db_del_must_use_where');
1202 }
Derek Allard39b622d2008-01-16 21:10:09 +00001203
Derek Allard09de1852007-02-14 01:35:56 +00001204 return FALSE;
1205 }
Derek Allard41f60d42007-12-20 20:09:22 +00001206
Derek Allard39b622d2008-01-16 21:10:09 +00001207 $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
Derek Allard09de1852007-02-14 01:35:56 +00001208
Derek Allard41f60d42007-12-20 20:09:22 +00001209 if ($reset_data)
1210 {
1211 $this->_reset_write();
1212 }
Derek Allard39b622d2008-01-16 21:10:09 +00001213
Derek Allard09de1852007-02-14 01:35:56 +00001214 return $this->query($sql);
1215 }
Derek Allard15ddc9d2007-12-20 13:54:39 +00001216
Derek Allard09de1852007-02-14 01:35:56 +00001217 // --------------------------------------------------------------------
1218
1219 /**
1220 * Use Table - DEPRECATED
1221 *
1222 * @deprecated use $this->db->from instead
1223 */
1224 function use_table($table)
1225 {
1226 return $this->from($table);
1227 return $this;
1228 }
1229
1230 // --------------------------------------------------------------------
1231
1232 /**
Derek Allard09de1852007-02-14 01:35:56 +00001233 * Tests whether the string has an SQL operator
1234 *
1235 * @access private
1236 * @param string
1237 * @return bool
1238 */
1239 function _has_operator($str)
1240 {
1241 $str = trim($str);
1242 if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
1243 {
1244 return FALSE;
1245 }
1246
1247 return TRUE;
1248 }
1249
1250 // --------------------------------------------------------------------
1251
1252 /**
Derek Allard5e128942007-12-28 21:33:03 +00001253 * Track Aliases
1254 *
1255 * Used to track SQL statements written with aliased tables.
1256 *
1257 * @access private
1258 * @param string The table to inspect
1259 * @return string
1260 */
1261 function _track_aliases($table)
1262 {
1263 // if a table alias is used we can recognize it by a space
1264 if (strpos($table, " ") !== FALSE)
1265 {
1266 // if the alias is written with the AS keyowrd, get it out
Derek Allard39b622d2008-01-16 21:10:09 +00001267 $table = preg_replace('/ AS /i', ' ', $table);
Derek Allard5e128942007-12-28 21:33:03 +00001268
Derek Allard39b622d2008-01-16 21:10:09 +00001269 $this->ar_aliased_tables[] = trim(strrchr($table, " "));
Derek Allard5e128942007-12-28 21:33:03 +00001270 }
1271
1272 return $this->dbprefix.$table;
1273 }
1274
1275 // --------------------------------------------------------------------
1276
1277 /**
1278 * Filter Table Aliases
1279 *
1280 * Intelligently removes database prefixes from aliased tables
1281 *
1282 * @access private
1283 * @param array An array of compiled SQL
1284 * @return array Cleaned up statement with aliases accounted for
1285 */
1286 function _filter_table_aliases($statements)
1287 {
Derek Allard39b622d2008-01-16 21:10:09 +00001288 $statements_without_aliases = array();
Derek Allard5e128942007-12-28 21:33:03 +00001289
Derek Allard39b622d2008-01-16 21:10:09 +00001290 foreach ($statements as $k => $v)
Derek Allard5e128942007-12-28 21:33:03 +00001291 {
Derek Allard39b622d2008-01-16 21:10:09 +00001292 foreach ($this->ar_aliased_tables as $table)
Derek Allard5e128942007-12-28 21:33:03 +00001293 {
Derek Allard39b622d2008-01-16 21:10:09 +00001294 $statement = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $v); // makes `table.field`
1295 $statement = str_replace(array($this->dbprefix.$table, '.'), array($table, $this->_protect_identifiers('.')), $statement);
Derek Allard5e128942007-12-28 21:33:03 +00001296 }
1297
Derek Allard39b622d2008-01-16 21:10:09 +00001298 $statements[$k] = $statement;
Derek Allard5e128942007-12-28 21:33:03 +00001299 }
1300
Derek Allard39b622d2008-01-16 21:10:09 +00001301 return $statements;
Derek Allard5e128942007-12-28 21:33:03 +00001302 }
1303
1304 // --------------------------------------------------------------------
1305
1306 /**
Derek Allard09de1852007-02-14 01:35:56 +00001307 * Compile the SELECT statement
1308 *
1309 * Generates a query string based on which functions were used.
1310 * Should not be called directly. The get() function calls it.
1311 *
1312 * @access private
1313 * @return string
1314 */
Derek Allard694b5b82007-12-18 15:58:03 +00001315 function _compile_select($select_override = FALSE)
Derek Allard09de1852007-02-14 01:35:56 +00001316 {
1317 $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
1318
1319 $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select);
1320
Derek Allard694b5b82007-12-18 15:58:03 +00001321 if ($select_override !== FALSE)
1322 {
1323 $sql = $select_override;
1324 }
1325
Derek Allard09de1852007-02-14 01:35:56 +00001326 if (count($this->ar_from) > 0)
1327 {
1328 $sql .= "\nFROM ";
Derek Allard15ddc9d2007-12-20 13:54:39 +00001329 $sql .= '(' . implode(', ', $this->ar_from) . ')';
Derek Allard09de1852007-02-14 01:35:56 +00001330 }
1331
1332 if (count($this->ar_join) > 0)
Derek Allard5e128942007-12-28 21:33:03 +00001333 {
Derek Allard09de1852007-02-14 01:35:56 +00001334 $sql .= "\n";
Derek Allard5e128942007-12-28 21:33:03 +00001335
1336 // special consideration for table aliases
1337 if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
1338 {
1339 $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join));
1340 }
1341 else
1342 {
1343 $sql .= implode("\n", $this->ar_join);
1344 }
1345
Derek Allard09de1852007-02-14 01:35:56 +00001346 }
1347
1348 if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
1349 {
1350 $sql .= "\nWHERE ";
1351 }
1352
1353 $sql .= implode("\n", $this->ar_where);
1354
1355 if (count($this->ar_like) > 0)
1356 {
1357 if (count($this->ar_where) > 0)
1358 {
1359 $sql .= " AND ";
1360 }
1361
1362 $sql .= implode("\n", $this->ar_like);
1363 }
1364
1365 if (count($this->ar_groupby) > 0)
1366 {
Derek Allard5e128942007-12-28 21:33:03 +00001367
Derek Allard09de1852007-02-14 01:35:56 +00001368 $sql .= "\nGROUP BY ";
Derek Allard5e128942007-12-28 21:33:03 +00001369
1370 // special consideration for table aliases
1371 if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
1372 {
1373 $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby));
1374 }
1375 else
1376 {
1377 $sql .= implode(', ', $this->ar_groupby);
1378 }
Derek Allard09de1852007-02-14 01:35:56 +00001379 }
1380
1381 if (count($this->ar_having) > 0)
1382 {
1383 $sql .= "\nHAVING ";
1384 $sql .= implode("\n", $this->ar_having);
1385 }
1386
1387 if (count($this->ar_orderby) > 0)
1388 {
1389 $sql .= "\nORDER BY ";
1390 $sql .= implode(', ', $this->ar_orderby);
1391
1392 if ($this->ar_order !== FALSE)
1393 {
1394 $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
1395 }
1396 }
1397
1398 if (is_numeric($this->ar_limit))
1399 {
1400 $sql .= "\n";
1401 $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
1402 }
1403
1404 return $sql;
1405 }
1406
1407 // --------------------------------------------------------------------
1408
1409 /**
1410 * Object to Array
1411 *
1412 * Takes an object as input and converts the class variables to array key/vals
1413 *
1414 * @access public
1415 * @param object
1416 * @return array
1417 */
1418 function _object_to_array($object)
1419 {
1420 if ( ! is_object($object))
1421 {
1422 return $object;
1423 }
1424
1425 $array = array();
1426 foreach (get_object_vars($object) as $key => $val)
1427 {
Derek Allard848b7762007-12-31 16:43:05 +00001428 // There are some built in keys we need to ignore for this conversion
1429 if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table')
1430
Derek Allard09de1852007-02-14 01:35:56 +00001431 {
1432 $array[$key] = $val;
1433 }
1434 }
1435
1436 return $array;
1437 }
1438
1439 // --------------------------------------------------------------------
1440
1441 /**
1442 * Resets the active record values. Called by the get() function
1443 *
1444 * @access private
1445 * @return void
1446 */
1447 function _reset_select()
1448 {
1449 $this->ar_select = array();
1450 $this->ar_distinct = FALSE;
1451 $this->ar_from = array();
1452 $this->ar_join = array();
1453 $this->ar_where = array();
1454 $this->ar_like = array();
1455 $this->ar_groupby = array();
1456 $this->ar_having = array();
1457 $this->ar_limit = FALSE;
1458 $this->ar_offset = FALSE;
1459 $this->ar_order = FALSE;
1460 $this->ar_orderby = array();
Derek Allardc6935512007-12-19 14:23:19 +00001461 $this->ar_wherein = array();
Derek Allard5e128942007-12-28 21:33:03 +00001462 $this->ar_aliased_tables = array();
Derek Allard09de1852007-02-14 01:35:56 +00001463 }
1464
1465 // --------------------------------------------------------------------
1466
1467 /**
1468 * Resets the active record "write" values.
1469 *
Derek Allarde77d77c2007-12-19 15:01:55 +00001470 * Called by the insert() update() and delete() functions
Derek Allard09de1852007-02-14 01:35:56 +00001471 *
1472 * @access private
1473 * @return void
1474 */
1475 function _reset_write()
1476 {
1477 $this->ar_set = array();
1478 $this->ar_from = array();
1479 $this->ar_where = array();
Derek Allard39b622d2008-01-16 21:10:09 +00001480 $this->ar_like = array();
Derek Allardda6d2402007-12-19 14:49:29 +00001481 $this->ar_limit = FALSE;
Derek Allard39b622d2008-01-16 21:10:09 +00001482 $this->ar_order = FALSE;
1483 $this->ar_orderby = array();
Derek Allard09de1852007-02-14 01:35:56 +00001484 }
1485
1486}
1487
adminac94f382006-09-24 20:28:12 +00001488?>