blob: 3cc65aff4e98d6535d4b0ead1fdae182b1fec9ed [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 Allard39b622d2008-01-16 21:10:09 +0000752 $this->ar_orderby[] = $this->_protect_identifiers($orderby).$direction;
Derek Allard09de1852007-02-14 01:35:56 +0000753 return $this;
754 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000755
Derek Allard218e2bc2007-12-17 21:18:14 +0000756 // --------------------------------------------------------------------
757
758 /**
759 * orderby() is an alias of order_by()
760 * this function is here for backwards compatibility, as
761 * orderby() has been deprecated
762 */
763 function orderby($orderby, $direction = '')
764 {
765 return $this->order_by($orderby, $direction);
766 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000767
Derek Allard09de1852007-02-14 01:35:56 +0000768 // --------------------------------------------------------------------
769
770 /**
771 * Sets the LIMIT value
772 *
773 * @access public
774 * @param integer the limit value
775 * @param integer the offset value
776 * @return object
777 */
778 function limit($value, $offset = '')
779 {
780 $this->ar_limit = $value;
781
782 if ($offset != '')
783 $this->ar_offset = $offset;
784
785 return $this;
786 }
787
788 // --------------------------------------------------------------------
789
790 /**
791 * Sets the OFFSET value
792 *
793 * @access public
794 * @param integer the offset value
795 * @return object
796 */
797 function offset($value)
798 {
799 $this->ar_offset = $value;
800 return $this;
801 }
802
803 // --------------------------------------------------------------------
804
805 /**
806 * The "set" function. Allows key/value pairs to be set for inserting or updating
807 *
808 * @access public
809 * @param mixed
810 * @param string
Derek Allard39b622d2008-01-16 21:10:09 +0000811 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +0000812 * @return object
813 */
Derek Allard39b622d2008-01-16 21:10:09 +0000814 function set($key, $value = '', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000815 {
816 $key = $this->_object_to_array($key);
817
818 if ( ! is_array($key))
819 {
820 $key = array($key => $value);
821 }
822
823 foreach ($key as $k => $v)
824 {
Derek Allard39b622d2008-01-16 21:10:09 +0000825 if ($escape === FALSE)
826 {
827 $this->ar_set[$this->_protect_identifiers($k)] = $v;
828 }
829 else
830 {
831 $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
832 }
833
Derek Allard09de1852007-02-14 01:35:56 +0000834 }
835
836 return $this;
837 }
838
839 // --------------------------------------------------------------------
840
841 /**
842 * Get
843 *
844 * Compiles the select statement based on the other functions called
845 * and runs the query
846 *
847 * @access public
Derek Allard694b5b82007-12-18 15:58:03 +0000848 * @param string the table
Derek Allard09de1852007-02-14 01:35:56 +0000849 * @param string the limit clause
850 * @param string the offset clause
851 * @return object
852 */
853 function get($table = '', $limit = null, $offset = null)
854 {
855 if ($table != '')
856 {
Derek Allard5e128942007-12-28 21:33:03 +0000857 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +0000858 $this->from($table);
859 }
860
861 if ( ! is_null($limit))
862 {
863 $this->limit($limit, $offset);
864 }
865
866 $sql = $this->_compile_select();
867
868 $result = $this->query($sql);
869 $this->_reset_select();
870 return $result;
871 }
872
Derek Allard09de1852007-02-14 01:35:56 +0000873 /**
Derek Allard694b5b82007-12-18 15:58:03 +0000874 * "Count All Results" query
875 *
876 * Generates a platform-specific query string that counts all records
877 * returned by an Active Record query.
878 *
879 * @access public
880 * @param string
881 * @return string
882 */
883 function count_all_results($table = '')
884 {
885 if ($table != '')
886 {
Derek Allard5e128942007-12-28 21:33:03 +0000887 $this->_track_aliases($table);
Derek Allard694b5b82007-12-18 15:58:03 +0000888 $this->from($table);
889 }
890
Derek Allard39b622d2008-01-16 21:10:09 +0000891 $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
Derek Allard694b5b82007-12-18 15:58:03 +0000892
893 $query = $this->query($sql);
894 $this->_reset_select();
895
896 if ($query->num_rows() == 0)
897 {
898 return '0';
899 }
900
901 $row = $query->row();
902 return $row->numrows;
903 }
904
905 // --------------------------------------------------------------------
906
907 /**
Derek Allard218e2bc2007-12-17 21:18:14 +0000908 * Get_Where
Derek Allard09de1852007-02-14 01:35:56 +0000909 *
910 * Allows the where clause, limit and offset to be added directly
911 *
912 * @access public
913 * @param string the where clause
914 * @param string the limit clause
915 * @param string the offset clause
916 * @return object
917 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000918 function get_where($table = '', $where = null, $limit = null, $offset = null)
Derek Allard09de1852007-02-14 01:35:56 +0000919 {
920 if ($table != '')
921 {
Derek Allard5e128942007-12-28 21:33:03 +0000922 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +0000923 $this->from($table);
924 }
925
926 if ( ! is_null($where))
927 {
928 $this->where($where);
929 }
930
931 if ( ! is_null($limit))
932 {
933 $this->limit($limit, $offset);
934 }
935
936 $sql = $this->_compile_select();
937
938 $result = $this->query($sql);
939 $this->_reset_select();
940 return $result;
941 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000942
943 // --------------------------------------------------------------------
944
945 /**
946 * getwhere() is an alias of get_where()
947 * this function is here for backwards compatibility, as
948 * getwhere() has been deprecated
949 */
950 function getwhere($table = '', $where = null, $limit = null, $offset = null)
951 {
952 return $this->get_where($table, $where, $limit, $offset);
953 }
Derek Allard09de1852007-02-14 01:35:56 +0000954
955 // --------------------------------------------------------------------
956
957 /**
958 * Insert
959 *
960 * Compiles an insert string and runs the query
961 *
962 * @access public
963 * @param string the table to retrieve the results from
964 * @param array an associative array of insert values
965 * @return object
966 */
967 function insert($table = '', $set = NULL)
968 {
969 if ( ! is_null($set))
970 {
971 $this->set($set);
972 }
973
974 if (count($this->ar_set) == 0)
975 {
976 if ($this->db_debug)
977 {
978 return $this->display_error('db_must_use_set');
979 }
980 return FALSE;
981 }
982
983 if ($table == '')
984 {
985 if ( ! isset($this->ar_from[0]))
986 {
987 if ($this->db_debug)
988 {
989 return $this->display_error('db_must_set_table');
990 }
991 return FALSE;
992 }
993
994 $table = $this->ar_from[0];
995 }
Derek Allard39b622d2008-01-16 21:10:09 +0000996
997 $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 +0000998
999 $this->_reset_write();
1000 return $this->query($sql);
1001 }
1002
1003 // --------------------------------------------------------------------
1004
1005 /**
1006 * Update
1007 *
1008 * Compiles an update string and runs the query
1009 *
1010 * @access public
1011 * @param string the table to retrieve the results from
1012 * @param array an associative array of update values
1013 * @param mixed the where clause
1014 * @return object
1015 */
Derek Allard5e128942007-12-28 21:33:03 +00001016 function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001017 {
1018 if ( ! is_null($set))
1019 {
1020 $this->set($set);
1021 }
1022
1023 if (count($this->ar_set) == 0)
1024 {
1025 if ($this->db_debug)
1026 {
1027 return $this->display_error('db_must_use_set');
1028 }
1029 return FALSE;
1030 }
1031
1032 if ($table == '')
1033 {
1034 if ( ! isset($this->ar_from[0]))
1035 {
1036 if ($this->db_debug)
1037 {
1038 return $this->display_error('db_must_set_table');
1039 }
1040 return FALSE;
1041 }
1042
1043 $table = $this->ar_from[0];
1044 }
1045
Derek Allarde77d77c2007-12-19 15:01:55 +00001046 if ($where != NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001047 {
1048 $this->where($where);
1049 }
Derek Allardda6d2402007-12-19 14:49:29 +00001050
Derek Allarde77d77c2007-12-19 15:01:55 +00001051 if ($limit != NULL)
Derek Allardda6d2402007-12-19 14:49:29 +00001052 {
1053 $this->limit($limit);
1054 }
Derek Allard09de1852007-02-14 01:35:56 +00001055
Derek Allard39b622d2008-01-16 21:10:09 +00001056 $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 +00001057
1058 $this->_reset_write();
1059 return $this->query($sql);
1060 }
Derek Allard39b622d2008-01-16 21:10:09 +00001061
1062 // --------------------------------------------------------------------
1063
1064 /**
1065 * Empty Table
1066 *
1067 * Compiles a delete string and runs "DELETE FROM table"
1068 *
1069 * @access public
1070 * @param string the table to empty
1071 * @return object
1072 */
1073 function empty_table($table = '')
1074 {
1075 if ($table == '')
1076 {
1077 if ( ! isset($this->ar_from[0]))
1078 {
1079 if ($this->db_debug)
1080 {
1081 return $this->display_error('db_must_set_table');
1082 }
1083 return FALSE;
1084 }
1085
1086 $table = $this->ar_from[0];
1087 }
1088 else
1089 {
1090 $table = $this->_protect_identifiers($this->dbprefix.$table);
1091 }
1092
1093
1094 $sql = $this->_delete($table);
1095
1096 $this->_reset_write();
1097
1098 return $this->query($sql);
1099 }
1100
1101 // --------------------------------------------------------------------
1102
1103 /**
1104 * Truncate
1105 *
1106 * Compiles a truncate string and runs the query
1107 * If the database does not support the truncate() command
1108 * This function maps to "DELETE FROM table"
1109 *
1110 * @access public
1111 * @param string the table to truncate
1112 * @return object
1113 */
1114 function truncate($table = '')
1115 {
1116 if ($table == '')
1117 {
1118 if ( ! isset($this->ar_from[0]))
1119 {
1120 if ($this->db_debug)
1121 {
1122 return $this->display_error('db_must_set_table');
1123 }
1124 return FALSE;
1125 }
1126
1127 $table = $this->ar_from[0];
1128 }
1129 else
1130 {
1131 $table = $this->_protect_identifiers($this->dbprefix.$table);
1132 }
1133
1134
1135 $sql = $this->_truncate($table);
1136
1137 $this->_reset_write();
1138
1139 return $this->query($sql);
1140 }
Derek Allard09de1852007-02-14 01:35:56 +00001141
1142 // --------------------------------------------------------------------
1143
1144 /**
1145 * Delete
1146 *
1147 * Compiles a delete string and runs the query
1148 *
1149 * @access public
Derek Allard41f60d42007-12-20 20:09:22 +00001150 * @param mixed the table(s) to delete from. String or array
Derek Allard09de1852007-02-14 01:35:56 +00001151 * @param mixed the where clause
Derek Allard41f60d42007-12-20 20:09:22 +00001152 * @param mixed the limit clause
1153 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +00001154 * @return object
1155 */
Derek Allard41f60d42007-12-20 20:09:22 +00001156 function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +00001157 {
1158 if ($table == '')
1159 {
1160 if ( ! isset($this->ar_from[0]))
1161 {
1162 if ($this->db_debug)
1163 {
1164 return $this->display_error('db_must_set_table');
1165 }
1166 return FALSE;
1167 }
Derek Allard39b622d2008-01-16 21:10:09 +00001168
Derek Allard09de1852007-02-14 01:35:56 +00001169 $table = $this->ar_from[0];
1170 }
Derek Allard39b622d2008-01-16 21:10:09 +00001171 elseif (is_array($table))
Derek Allard41f60d42007-12-20 20:09:22 +00001172 {
1173 foreach($table as $single_table)
1174 {
Derek Allard39b622d2008-01-16 21:10:09 +00001175 $this->delete($single_table, $where, $limit, FALSE);
Derek Allard41f60d42007-12-20 20:09:22 +00001176 }
Derek Allard39b622d2008-01-16 21:10:09 +00001177
Derek Allard41f60d42007-12-20 20:09:22 +00001178 $this->_reset_write();
1179 return;
1180 }
Derek Allard39b622d2008-01-16 21:10:09 +00001181 else
1182 {
1183 $table = $this->_protect_identifiers($this->dbprefix.$table);
1184 }
Derek Allard41f60d42007-12-20 20:09:22 +00001185
Derek Allard09de1852007-02-14 01:35:56 +00001186 if ($where != '')
1187 {
1188 $this->where($where);
1189 }
1190
Derek Allarde77d77c2007-12-19 15:01:55 +00001191 if ($limit != NULL)
1192 {
1193 $this->limit($limit);
1194 }
1195
Derek Allard39b622d2008-01-16 21:10:09 +00001196 if (count($this->ar_where) == 0 && count($this->ar_like) == 0)
Derek Allard09de1852007-02-14 01:35:56 +00001197 {
1198 if ($this->db_debug)
1199 {
1200 return $this->display_error('db_del_must_use_where');
1201 }
Derek Allard39b622d2008-01-16 21:10:09 +00001202
Derek Allard09de1852007-02-14 01:35:56 +00001203 return FALSE;
1204 }
Derek Allard41f60d42007-12-20 20:09:22 +00001205
Derek Allard39b622d2008-01-16 21:10:09 +00001206 $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
Derek Allard09de1852007-02-14 01:35:56 +00001207
Derek Allard41f60d42007-12-20 20:09:22 +00001208 if ($reset_data)
1209 {
1210 $this->_reset_write();
1211 }
Derek Allard39b622d2008-01-16 21:10:09 +00001212
Derek Allard09de1852007-02-14 01:35:56 +00001213 return $this->query($sql);
1214 }
Derek Allard15ddc9d2007-12-20 13:54:39 +00001215
Derek Allard09de1852007-02-14 01:35:56 +00001216 // --------------------------------------------------------------------
1217
1218 /**
1219 * Use Table - DEPRECATED
1220 *
1221 * @deprecated use $this->db->from instead
1222 */
1223 function use_table($table)
1224 {
1225 return $this->from($table);
1226 return $this;
1227 }
1228
1229 // --------------------------------------------------------------------
1230
1231 /**
Derek Allard09de1852007-02-14 01:35:56 +00001232 * Tests whether the string has an SQL operator
1233 *
1234 * @access private
1235 * @param string
1236 * @return bool
1237 */
1238 function _has_operator($str)
1239 {
1240 $str = trim($str);
1241 if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
1242 {
1243 return FALSE;
1244 }
1245
1246 return TRUE;
1247 }
1248
1249 // --------------------------------------------------------------------
1250
1251 /**
Derek Allard5e128942007-12-28 21:33:03 +00001252 * Track Aliases
1253 *
1254 * Used to track SQL statements written with aliased tables.
1255 *
1256 * @access private
1257 * @param string The table to inspect
1258 * @return string
1259 */
1260 function _track_aliases($table)
1261 {
1262 // if a table alias is used we can recognize it by a space
1263 if (strpos($table, " ") !== FALSE)
1264 {
1265 // if the alias is written with the AS keyowrd, get it out
Derek Allard39b622d2008-01-16 21:10:09 +00001266 $table = preg_replace('/ AS /i', ' ', $table);
Derek Allard5e128942007-12-28 21:33:03 +00001267
Derek Allard39b622d2008-01-16 21:10:09 +00001268 $this->ar_aliased_tables[] = trim(strrchr($table, " "));
Derek Allard5e128942007-12-28 21:33:03 +00001269 }
1270
1271 return $this->dbprefix.$table;
1272 }
1273
1274 // --------------------------------------------------------------------
1275
1276 /**
1277 * Filter Table Aliases
1278 *
1279 * Intelligently removes database prefixes from aliased tables
1280 *
1281 * @access private
1282 * @param array An array of compiled SQL
1283 * @return array Cleaned up statement with aliases accounted for
1284 */
1285 function _filter_table_aliases($statements)
1286 {
Derek Allard39b622d2008-01-16 21:10:09 +00001287 $statements_without_aliases = array();
Derek Allard5e128942007-12-28 21:33:03 +00001288
Derek Allard39b622d2008-01-16 21:10:09 +00001289 foreach ($statements as $k => $v)
Derek Allard5e128942007-12-28 21:33:03 +00001290 {
Derek Allard39b622d2008-01-16 21:10:09 +00001291 foreach ($this->ar_aliased_tables as $table)
Derek Allard5e128942007-12-28 21:33:03 +00001292 {
Derek Allard39b622d2008-01-16 21:10:09 +00001293 $statement = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $v); // makes `table.field`
1294 $statement = str_replace(array($this->dbprefix.$table, '.'), array($table, $this->_protect_identifiers('.')), $statement);
Derek Allard5e128942007-12-28 21:33:03 +00001295 }
1296
Derek Allard39b622d2008-01-16 21:10:09 +00001297 $statements[$k] = $statement;
Derek Allard5e128942007-12-28 21:33:03 +00001298 }
1299
Derek Allard39b622d2008-01-16 21:10:09 +00001300 return $statements;
Derek Allard5e128942007-12-28 21:33:03 +00001301 }
1302
1303 // --------------------------------------------------------------------
1304
1305 /**
Derek Allard09de1852007-02-14 01:35:56 +00001306 * Compile the SELECT statement
1307 *
1308 * Generates a query string based on which functions were used.
1309 * Should not be called directly. The get() function calls it.
1310 *
1311 * @access private
1312 * @return string
1313 */
Derek Allard694b5b82007-12-18 15:58:03 +00001314 function _compile_select($select_override = FALSE)
Derek Allard09de1852007-02-14 01:35:56 +00001315 {
1316 $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
1317
1318 $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select);
1319
Derek Allard694b5b82007-12-18 15:58:03 +00001320 if ($select_override !== FALSE)
1321 {
1322 $sql = $select_override;
1323 }
1324
Derek Allard09de1852007-02-14 01:35:56 +00001325 if (count($this->ar_from) > 0)
1326 {
1327 $sql .= "\nFROM ";
Derek Allard15ddc9d2007-12-20 13:54:39 +00001328 $sql .= '(' . implode(', ', $this->ar_from) . ')';
Derek Allard09de1852007-02-14 01:35:56 +00001329 }
1330
1331 if (count($this->ar_join) > 0)
Derek Allard5e128942007-12-28 21:33:03 +00001332 {
Derek Allard09de1852007-02-14 01:35:56 +00001333 $sql .= "\n";
Derek Allard5e128942007-12-28 21:33:03 +00001334
1335 // special consideration for table aliases
1336 if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
1337 {
1338 $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join));
1339 }
1340 else
1341 {
1342 $sql .= implode("\n", $this->ar_join);
1343 }
1344
Derek Allard09de1852007-02-14 01:35:56 +00001345 }
1346
1347 if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
1348 {
1349 $sql .= "\nWHERE ";
1350 }
1351
1352 $sql .= implode("\n", $this->ar_where);
1353
1354 if (count($this->ar_like) > 0)
1355 {
1356 if (count($this->ar_where) > 0)
1357 {
1358 $sql .= " AND ";
1359 }
1360
1361 $sql .= implode("\n", $this->ar_like);
1362 }
1363
1364 if (count($this->ar_groupby) > 0)
1365 {
Derek Allard5e128942007-12-28 21:33:03 +00001366
Derek Allard09de1852007-02-14 01:35:56 +00001367 $sql .= "\nGROUP BY ";
Derek Allard5e128942007-12-28 21:33:03 +00001368
1369 // special consideration for table aliases
1370 if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
1371 {
1372 $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby));
1373 }
1374 else
1375 {
1376 $sql .= implode(', ', $this->ar_groupby);
1377 }
Derek Allard09de1852007-02-14 01:35:56 +00001378 }
1379
1380 if (count($this->ar_having) > 0)
1381 {
1382 $sql .= "\nHAVING ";
1383 $sql .= implode("\n", $this->ar_having);
1384 }
1385
1386 if (count($this->ar_orderby) > 0)
1387 {
1388 $sql .= "\nORDER BY ";
1389 $sql .= implode(', ', $this->ar_orderby);
1390
1391 if ($this->ar_order !== FALSE)
1392 {
1393 $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
1394 }
1395 }
1396
1397 if (is_numeric($this->ar_limit))
1398 {
1399 $sql .= "\n";
1400 $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
1401 }
1402
1403 return $sql;
1404 }
1405
1406 // --------------------------------------------------------------------
1407
1408 /**
1409 * Object to Array
1410 *
1411 * Takes an object as input and converts the class variables to array key/vals
1412 *
1413 * @access public
1414 * @param object
1415 * @return array
1416 */
1417 function _object_to_array($object)
1418 {
1419 if ( ! is_object($object))
1420 {
1421 return $object;
1422 }
1423
1424 $array = array();
1425 foreach (get_object_vars($object) as $key => $val)
1426 {
Derek Allard848b7762007-12-31 16:43:05 +00001427 // There are some built in keys we need to ignore for this conversion
1428 if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table')
1429
Derek Allard09de1852007-02-14 01:35:56 +00001430 {
1431 $array[$key] = $val;
1432 }
1433 }
1434
1435 return $array;
1436 }
1437
1438 // --------------------------------------------------------------------
1439
1440 /**
1441 * Resets the active record values. Called by the get() function
1442 *
1443 * @access private
1444 * @return void
1445 */
1446 function _reset_select()
1447 {
1448 $this->ar_select = array();
1449 $this->ar_distinct = FALSE;
1450 $this->ar_from = array();
1451 $this->ar_join = array();
1452 $this->ar_where = array();
1453 $this->ar_like = array();
1454 $this->ar_groupby = array();
1455 $this->ar_having = array();
1456 $this->ar_limit = FALSE;
1457 $this->ar_offset = FALSE;
1458 $this->ar_order = FALSE;
1459 $this->ar_orderby = array();
Derek Allardc6935512007-12-19 14:23:19 +00001460 $this->ar_wherein = array();
Derek Allard5e128942007-12-28 21:33:03 +00001461 $this->ar_aliased_tables = array();
Derek Allard09de1852007-02-14 01:35:56 +00001462 }
1463
1464 // --------------------------------------------------------------------
1465
1466 /**
1467 * Resets the active record "write" values.
1468 *
Derek Allarde77d77c2007-12-19 15:01:55 +00001469 * Called by the insert() update() and delete() functions
Derek Allard09de1852007-02-14 01:35:56 +00001470 *
1471 * @access private
1472 * @return void
1473 */
1474 function _reset_write()
1475 {
1476 $this->ar_set = array();
1477 $this->ar_from = array();
1478 $this->ar_where = array();
Derek Allard39b622d2008-01-16 21:10:09 +00001479 $this->ar_like = array();
Derek Allardda6d2402007-12-19 14:49:29 +00001480 $this->ar_limit = FALSE;
Derek Allard39b622d2008-01-16 21:10:09 +00001481 $this->ar_order = FALSE;
1482 $this->ar_orderby = array();
Derek Allard09de1852007-02-14 01:35:56 +00001483 }
1484
1485}
1486
adminac94f382006-09-24 20:28:12 +00001487?>