blob: d2d2632a77fd142feb05c0f1fa006fbe9706a4a2 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard09de1852007-02-14 01:35:56 +00002/**
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
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Rick Ellis37b3ecf2008-09-12 23:34:18 +00009 * @copyright Copyright (c) 2008, EllisLab, Inc.
Derek Allardcdd2ab22008-01-23 00:05:38 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard09de1852007-02-14 01:35:56 +000012 * @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
Derek Allard3d879d52008-01-18 19:41:32 +000026 * @author ExpressionEngine Dev Team
Derek Allardcdd2ab22008-01-23 00:05:38 +000027 * @link http://codeigniter.com/user_guide/database/
Derek Allard09de1852007-02-14 01:35:56 +000028 */
29class CI_DB_active_record extends CI_DB_driver {
30
Rick Ellis59523592008-10-17 04:07:40 +000031 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();
44 var $ar_wherein = array();
Derek Allard5e128942007-12-28 21:33:03 +000045 var $ar_aliased_tables = array();
Rick Ellis59523592008-10-17 04:07:40 +000046 var $ar_store_array = array();
47
Derek Allard9b3e7b52008-02-04 23:20:34 +000048 // Active Record Caching variables
Rick Ellis59523592008-10-17 04:07:40 +000049 var $ar_caching = FALSE;
Rick Ellis392f09d2008-10-18 02:03:14 +000050 var $ar_cache_exists = array();
Rick Ellis59523592008-10-17 04:07:40 +000051 var $ar_cache_select = array();
52 var $ar_cache_from = array();
53 var $ar_cache_join = array();
54 var $ar_cache_where = array();
55 var $ar_cache_like = array();
56 var $ar_cache_groupby = array();
57 var $ar_cache_having = array();
58 var $ar_cache_limit = FALSE;
59 var $ar_cache_offset = FALSE;
60 var $ar_cache_order = FALSE;
61 var $ar_cache_orderby = array();
62 var $ar_cache_set = array();
Derek Allard9b3e7b52008-02-04 23:20:34 +000063
Derek Allard09de1852007-02-14 01:35:56 +000064
Derek Allard3b118682008-01-22 23:44:32 +000065 // --------------------------------------------------------------------
66
67 /**
Derek Allard09de1852007-02-14 01:35:56 +000068 * Select
69 *
70 * Generates the SELECT portion of the query
71 *
72 * @access public
73 * @param string
74 * @return object
75 */
Rick Ellis59523592008-10-17 04:07:40 +000076 function select($select = '*', $escape = NULL)
Derek Allard09de1852007-02-14 01:35:56 +000077 {
Rick Ellis59523592008-10-17 04:07:40 +000078 // Set the global value if this was sepecified
79 if (is_bool($escape))
80 {
81 $this->_protect_identifiers = $escape;
82 }
83
Derek Allard09de1852007-02-14 01:35:56 +000084 if (is_string($select))
85 {
Rick Ellis59523592008-10-17 04:07:40 +000086 $select = explode(',', $select);
Derek Allard09de1852007-02-14 01:35:56 +000087 }
Derek Allard5fe155e2008-05-12 19:14:57 +000088
Derek Allard09de1852007-02-14 01:35:56 +000089 foreach ($select as $val)
90 {
91 $val = trim($val);
Derek Allard39b622d2008-01-16 21:10:09 +000092
Derek Allard09de1852007-02-14 01:35:56 +000093 if ($val != '')
Derek Allard39b622d2008-01-16 21:10:09 +000094 {
Derek Allard09de1852007-02-14 01:35:56 +000095 $this->ar_select[] = $val;
Rick Ellis59523592008-10-17 04:07:40 +000096
Derek Allard9b3e7b52008-02-04 23:20:34 +000097 if ($this->ar_caching === TRUE)
98 {
99 $this->ar_cache_select[] = $val;
Rick Ellis392f09d2008-10-18 02:03:14 +0000100 $this->ar_cache_exists[] = 'select';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000101 }
Derek Allard39b622d2008-01-16 21:10:09 +0000102 }
Derek Allard09de1852007-02-14 01:35:56 +0000103 }
104 return $this;
105 }
Derek Allard39b622d2008-01-16 21:10:09 +0000106
107 // --------------------------------------------------------------------
108
109 /**
110 * Select Max
111 *
112 * Generates a SELECT MAX(field) portion of a query
113 *
114 * @access public
115 * @param string the field
116 * @param string an alias
117 * @return object
118 */
Rick Ellis59523592008-10-17 04:07:40 +0000119 function select_max($select = '', $alias = '')
Derek Allard39b622d2008-01-16 21:10:09 +0000120 {
Rick Ellis59523592008-10-17 04:07:40 +0000121 return $this->_max_min_avg_sum($select, $alias, 'MAX');
Derek Allard39b622d2008-01-16 21:10:09 +0000122 }
Rick Ellis59523592008-10-17 04:07:40 +0000123
Derek Allard39b622d2008-01-16 21:10:09 +0000124 // --------------------------------------------------------------------
125
126 /**
127 * Select Min
128 *
129 * Generates a SELECT MIN(field) portion of a query
130 *
131 * @access public
132 * @param string the field
133 * @param string an alias
134 * @return object
135 */
Rick Ellis59523592008-10-17 04:07:40 +0000136 function select_min($select = '', $alias = '')
Derek Allard39b622d2008-01-16 21:10:09 +0000137 {
Rick Ellis59523592008-10-17 04:07:40 +0000138 return $this->_max_min_avg_sum($select, $alias, 'MIN');
Derek Allard39b622d2008-01-16 21:10:09 +0000139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Select Average
145 *
146 * Generates a SELECT AVG(field) portion of a query
147 *
148 * @access public
149 * @param string the field
150 * @param string an alias
151 * @return object
152 */
Rick Ellis59523592008-10-17 04:07:40 +0000153 function select_avg($select = '', $alias = '')
Derek Allard39b622d2008-01-16 21:10:09 +0000154 {
Rick Ellis59523592008-10-17 04:07:40 +0000155 return $this->_max_min_avg_sum($select, $alias, 'AVG');
Derek Allard39b622d2008-01-16 21:10:09 +0000156 }
157
158 // --------------------------------------------------------------------
Derek Allard5fe155e2008-05-12 19:14:57 +0000159
Derek Allard39b622d2008-01-16 21:10:09 +0000160 /**
161 * Select Sum
162 *
163 * Generates a SELECT SUM(field) portion of a query
164 *
165 * @access public
166 * @param string the field
167 * @param string an alias
168 * @return object
169 */
Rick Ellis59523592008-10-17 04:07:40 +0000170 function select_sum($select = '', $alias = '')
171 {
172 return $this->_max_min_avg_sum($select, $alias, 'SUM');
173 }
174
175 // --------------------------------------------------------------------
176
177 /**
178 * Processing Function for the four functions above:
179 *
180 * select_max()
181 * select_min()
182 * select_avg()
183 * select_sum()
184 *
185 * @access public
186 * @param string the field
187 * @param string an alias
188 * @return object
189 */
190 function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
Derek Allard39b622d2008-01-16 21:10:09 +0000191 {
Derek Jones0b59f272008-05-13 04:22:33 +0000192 if ( ! is_string($select) OR $select == '')
Derek Allard39b622d2008-01-16 21:10:09 +0000193 {
194 $this->display_error('db_invalid_query');
195 }
Derek Allard39b622d2008-01-16 21:10:09 +0000196
Rick Ellis59523592008-10-17 04:07:40 +0000197 $type = strtoupper($type);
198
199 if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM')))
200 {
201 show_error('Invalid function type: '.$type);
202 }
203
204 if ($alias == '')
205 {
206 $alias = $this->_create_alias_from_table(trim($select));
207 }
208
209 $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias;
Derek Allard39b622d2008-01-16 21:10:09 +0000210
211 $this->ar_select[] = $sql;
Rick Ellis59523592008-10-17 04:07:40 +0000212
Derek Allard9b3e7b52008-02-04 23:20:34 +0000213 if ($this->ar_caching === TRUE)
214 {
215 $this->ar_cache_select[] = $sql;
Rick Ellis392f09d2008-10-18 02:03:14 +0000216 $this->ar_cache_exists[] = 'select';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000217 }
Rick Ellis59523592008-10-17 04:07:40 +0000218
Derek Allard39b622d2008-01-16 21:10:09 +0000219 return $this;
220 }
221
Derek Allard09de1852007-02-14 01:35:56 +0000222 // --------------------------------------------------------------------
223
224 /**
Rick Ellis59523592008-10-17 04:07:40 +0000225 * Determines the alias name based on the table
226 *
227 * @access private
228 * @param string
229 * @return string
230 */
231 function _create_alias_from_table($item)
232 {
233 if (strpos($item, '.') !== FALSE)
234 {
235 return end(explode('.', $item));
236 }
237
238 return $item;
239 }
240
241 // --------------------------------------------------------------------
242
243 /**
Derek Allard09de1852007-02-14 01:35:56 +0000244 * DISTINCT
245 *
246 * Sets a flag which tells the query string compiler to add DISTINCT
247 *
248 * @access public
249 * @param bool
250 * @return object
251 */
252 function distinct($val = TRUE)
253 {
254 $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
255 return $this;
256 }
257
258 // --------------------------------------------------------------------
259
260 /**
261 * From
262 *
263 * Generates the FROM portion of the query
264 *
265 * @access public
266 * @param mixed can be a string or array
267 * @return object
268 */
269 function from($from)
270 {
271 foreach ((array)$from as $val)
272 {
Rick Ellis59523592008-10-17 04:07:40 +0000273 // Extract any aliases that might exist. We use this information
274 // in the _protect_identifiers to know whether to add a table prefix
275 $this->_track_aliases($val);
276
277 $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
278
Derek Allard9b3e7b52008-02-04 23:20:34 +0000279 if ($this->ar_caching === TRUE)
280 {
Rick Ellis59523592008-10-17 04:07:40 +0000281 $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
Rick Ellis392f09d2008-10-18 02:03:14 +0000282 $this->ar_cache_exists[] = 'from';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000283 }
Derek Allard09de1852007-02-14 01:35:56 +0000284 }
Derek Allard5e128942007-12-28 21:33:03 +0000285
Derek Allard09de1852007-02-14 01:35:56 +0000286 return $this;
287 }
Derek Allard5fe155e2008-05-12 19:14:57 +0000288
Derek Allard09de1852007-02-14 01:35:56 +0000289 // --------------------------------------------------------------------
290
291 /**
292 * Join
293 *
294 * Generates the JOIN portion of the query
295 *
296 * @access public
297 * @param string
298 * @param string the join condition
299 * @param string the type of join
300 * @return object
301 */
302 function join($table, $cond, $type = '')
303 {
304 if ($type != '')
305 {
306 $type = strtoupper(trim($type));
307
Rick Ellis59523592008-10-17 04:07:40 +0000308 if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
Derek Allard09de1852007-02-14 01:35:56 +0000309 {
310 $type = '';
311 }
312 else
313 {
314 $type .= ' ';
315 }
316 }
317
Rick Ellis59523592008-10-17 04:07:40 +0000318 // Extract any aliases that might exist. We use this information
319 // in the _protect_identifiers to know whether to add a table prefix
320 $this->_track_aliases($table);
321
322 // Strip apart the condition and protect the identifiers
323 if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
Derek Allard09de1852007-02-14 01:35:56 +0000324 {
Rick Ellis59523592008-10-17 04:07:40 +0000325 $match[1] = $this->_protect_identifiers($match[1]);
326 $match[3] = $this->_protect_identifiers($match[3]);
327
328 $cond = $match[1].$match[2].$match[3];
Derek Allard5fe155e2008-05-12 19:14:57 +0000329 }
Rick Ellis59523592008-10-17 04:07:40 +0000330
331 // Assemble the JOIN statement
332 $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
Derek Allard9b3e7b52008-02-04 23:20:34 +0000333
334 $this->ar_join[] = $join;
335 if ($this->ar_caching === TRUE)
336 {
337 $this->ar_cache_join[] = $join;
Rick Ellis392f09d2008-10-18 02:03:14 +0000338 $this->ar_cache_exists[] = 'join';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000339 }
340
Derek Allard09de1852007-02-14 01:35:56 +0000341 return $this;
342 }
Derek Allard5fe155e2008-05-12 19:14:57 +0000343
Derek Allard09de1852007-02-14 01:35:56 +0000344 // --------------------------------------------------------------------
345
346 /**
347 * Where
348 *
349 * Generates the WHERE portion of the query. Separates
350 * multiple calls with AND
351 *
352 * @access public
353 * @param mixed
354 * @param mixed
355 * @return object
356 */
Derek Allard39b622d2008-01-16 21:10:09 +0000357 function where($key, $value = NULL, $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000358 {
Derek Allard39b622d2008-01-16 21:10:09 +0000359 return $this->_where($key, $value, 'AND ', $escape);
Derek Allard09de1852007-02-14 01:35:56 +0000360 }
361
362 // --------------------------------------------------------------------
363
364 /**
365 * OR Where
366 *
367 * Generates the WHERE portion of the query. Separates
368 * multiple calls with OR
369 *
370 * @access public
371 * @param mixed
372 * @param mixed
373 * @return object
374 */
Derek Allard39b622d2008-01-16 21:10:09 +0000375 function or_where($key, $value = NULL, $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000376 {
Derek Allard39b622d2008-01-16 21:10:09 +0000377 return $this->_where($key, $value, 'OR ', $escape);
Derek Allard09de1852007-02-14 01:35:56 +0000378 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000379
380 // --------------------------------------------------------------------
381
382 /**
383 * orwhere() is an alias of or_where()
384 * this function is here for backwards compatibility, as
385 * orwhere() has been deprecated
386 */
Derek Allard39b622d2008-01-16 21:10:09 +0000387 function orwhere($key, $value = NULL, $escape = TRUE)
Derek Allard218e2bc2007-12-17 21:18:14 +0000388 {
Derek Allard39b622d2008-01-16 21:10:09 +0000389 return $this->or_where($key, $value, $escape);
Derek Allard218e2bc2007-12-17 21:18:14 +0000390 }
Derek Allard67b44ed2008-01-12 16:18:02 +0000391
392 // --------------------------------------------------------------------
393
394 /**
Derek Allard09de1852007-02-14 01:35:56 +0000395 * Where
396 *
397 * Called by where() or orwhere()
398 *
399 * @access private
400 * @param mixed
401 * @param mixed
402 * @param string
403 * @return object
404 */
Rick Ellis59523592008-10-17 04:07:40 +0000405 function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
Derek Allard09de1852007-02-14 01:35:56 +0000406 {
Derek Jones0b59f272008-05-13 04:22:33 +0000407 if ( ! is_array($key))
Derek Allard09de1852007-02-14 01:35:56 +0000408 {
409 $key = array($key => $value);
410 }
Rick Ellis59523592008-10-17 04:07:40 +0000411
412 // If the escape value was not set will will base it on the global setting
413 if ( ! is_bool($escape))
414 {
415 $escape = $this->_protect_identifiers;
416 }
Derek Allard9b3e7b52008-02-04 23:20:34 +0000417
Derek Allard09de1852007-02-14 01:35:56 +0000418 foreach ($key as $k => $v)
419 {
Rick Ellis000f89d2008-10-17 23:26:15 +0000420 $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
Derek Allard15ddc9d2007-12-20 13:54:39 +0000421
Derek Allardd8364c42008-06-04 17:01:00 +0000422 if (is_null($v) && ! $this->_has_operator($k))
Derek Allard15ddc9d2007-12-20 13:54:39 +0000423 {
424 // value appears not to have been set, assign the test to IS NULL
425 $k .= ' IS NULL';
426 }
Derek Allard09de1852007-02-14 01:35:56 +0000427
Derek Jones0b59f272008-05-13 04:22:33 +0000428 if ( ! is_null($v))
Derek Allard09de1852007-02-14 01:35:56 +0000429 {
Derek Allard39b622d2008-01-16 21:10:09 +0000430 if ($escape === TRUE)
431 {
Rick Ellis59523592008-10-17 04:07:40 +0000432 $k = $this->_protect_identifiers($k, FALSE, $escape);
Derek Allardd8364c42008-06-04 17:01:00 +0000433
434 $v = ' '.$this->escape($v);
Derek Allard39b622d2008-01-16 21:10:09 +0000435 }
436
Derek Jones0b59f272008-05-13 04:22:33 +0000437 if ( ! $this->_has_operator($k))
Derek Allard09de1852007-02-14 01:35:56 +0000438 {
439 $k .= ' =';
440 }
Derek Allard09de1852007-02-14 01:35:56 +0000441 }
Derek Allard9b3e7b52008-02-04 23:20:34 +0000442 else
443 {
Rick Ellis59523592008-10-17 04:07:40 +0000444 $k = $this->_protect_identifiers($k, FALSE, $escape);
Derek Allard9b3e7b52008-02-04 23:20:34 +0000445 }
446
Derek Allard09de1852007-02-14 01:35:56 +0000447 $this->ar_where[] = $prefix.$k.$v;
Derek Allardd8364c42008-06-04 17:01:00 +0000448
Derek Allard9b3e7b52008-02-04 23:20:34 +0000449 if ($this->ar_caching === TRUE)
450 {
451 $this->ar_cache_where[] = $prefix.$k.$v;
Rick Ellis392f09d2008-10-18 02:03:14 +0000452 $this->ar_cache_exists[] = 'where';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000453 }
454
Derek Allard09de1852007-02-14 01:35:56 +0000455 }
Derek Jones7e98a272008-06-04 17:05:44 +0000456
Derek Allard09de1852007-02-14 01:35:56 +0000457 return $this;
458 }
Derek Allard80dd7022007-12-18 23:55:06 +0000459
460 // --------------------------------------------------------------------
461
462 /**
463 * Where_in
464 *
Derek Allardc6935512007-12-19 14:23:19 +0000465 * Generates a WHERE field IN ('item', 'item') SQL query joined with
466 * AND if appropriate
Derek Allard80dd7022007-12-18 23:55:06 +0000467 *
468 * @access public
469 * @param string The field to search
470 * @param array The values searched on
Derek Allardc6935512007-12-19 14:23:19 +0000471 * @return object
472 */
473 function where_in($key = NULL, $values = NULL)
Rick Ellis59523592008-10-17 04:07:40 +0000474 {
Derek Allardc6935512007-12-19 14:23:19 +0000475 return $this->_where_in($key, $values);
476 }
477
478 // --------------------------------------------------------------------
479
480 /**
481 * Where_in_or
482 *
483 * Generates a WHERE field IN ('item', 'item') SQL query joined with
484 * OR if appropriate
485 *
486 * @access public
487 * @param string The field to search
488 * @param array The values searched on
Derek Allardc6935512007-12-19 14:23:19 +0000489 * @return object
490 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000491 function or_where_in($key = NULL, $values = NULL)
Derek Allard5fe155e2008-05-12 19:14:57 +0000492 {
Derek Allard15ddc9d2007-12-20 13:54:39 +0000493 return $this->_where_in($key, $values, FALSE, 'OR ');
Derek Allardc6935512007-12-19 14:23:19 +0000494 }
495
496 // --------------------------------------------------------------------
497
498 /**
499 * Where_not_in
500 *
501 * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
502 * with AND if appropriate
503 *
504 * @access public
505 * @param string The field to search
506 * @param array The values searched on
Derek Allardc6935512007-12-19 14:23:19 +0000507 * @return object
508 */
509 function where_not_in($key = NULL, $values = NULL)
Derek Allard5fe155e2008-05-12 19:14:57 +0000510 {
Derek Allardc6935512007-12-19 14:23:19 +0000511 return $this->_where_in($key, $values, TRUE);
512 }
513
514 // --------------------------------------------------------------------
515
516 /**
517 * Where_not_in_or
518 *
519 * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
520 * with OR if appropriate
521 *
522 * @access public
523 * @param string The field to search
524 * @param array The values searched on
Derek Allardc6935512007-12-19 14:23:19 +0000525 * @return object
526 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000527 function or_where_not_in($key = NULL, $values = NULL)
Derek Allard5fe155e2008-05-12 19:14:57 +0000528 {
Derek Jonesd0072432008-05-07 22:06:51 +0000529 return $this->_where_in($key, $values, TRUE, 'OR ');
Derek Allardc6935512007-12-19 14:23:19 +0000530 }
531
532 // --------------------------------------------------------------------
533
534 /**
535 * Where_in
536 *
537 * Called by where_in, where_in_or, where_not_in, where_not_in_or
538 *
539 * @access public
540 * @param string The field to search
541 * @param array The values searched on
Rick Ellis59523592008-10-17 04:07:40 +0000542 * @param boolean If the statement would be IN or NOT IN
Derek Allard80dd7022007-12-18 23:55:06 +0000543 * @param string
544 * @return object
545 */
Derek Allard15ddc9d2007-12-20 13:54:39 +0000546 function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
Derek Allard5fe155e2008-05-12 19:14:57 +0000547 {
Rick Ellis59523592008-10-17 04:07:40 +0000548 if ($key === NULL OR $values === NULL)
Derek Allard80dd7022007-12-18 23:55:06 +0000549 {
550 return;
551 }
Rick Ellis59523592008-10-17 04:07:40 +0000552
553 if ( ! is_array($values))
554 {
555 $values = array($values);
556 }
557
558 $not = ($not) ? ' NOT' : '';
Derek Allard80dd7022007-12-18 23:55:06 +0000559
560 foreach ($values as $value)
561 {
562 $this->ar_wherein[] = $this->escape($value);
563 }
564
565 $prefix = (count($this->ar_where) == 0) ? '' : $type;
Derek Allard5fe155e2008-05-12 19:14:57 +0000566
Derek Allard9b3e7b52008-02-04 23:20:34 +0000567 $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
568
569 $this->ar_where[] = $where_in;
570 if ($this->ar_caching === TRUE)
571 {
572 $this->ar_cache_where[] = $where_in;
Rick Ellis392f09d2008-10-18 02:03:14 +0000573 $this->ar_cache_exists[] = 'where';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000574 }
Derek Allard80dd7022007-12-18 23:55:06 +0000575
Derek Allard8f000212008-01-18 14:45:59 +0000576 // reset the array for multiple calls
577 $this->ar_wherein = array();
Derek Allard80dd7022007-12-18 23:55:06 +0000578 return $this;
579 }
580
Derek Allard09de1852007-02-14 01:35:56 +0000581 // --------------------------------------------------------------------
582
583 /**
584 * Like
585 *
586 * Generates a %LIKE% portion of the query. Separates
587 * multiple calls with AND
588 *
589 * @access public
590 * @param mixed
591 * @param mixed
592 * @return object
593 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000594 function like($field, $match = '', $side = 'both')
Derek Allard09de1852007-02-14 01:35:56 +0000595 {
Derek Allard218e2bc2007-12-17 21:18:14 +0000596 return $this->_like($field, $match, 'AND ', $side);
Derek Allard09de1852007-02-14 01:35:56 +0000597 }
Derek Allarde54e3d22007-12-19 15:53:44 +0000598
599 // --------------------------------------------------------------------
600
601 /**
602 * Not Like
603 *
604 * Generates a NOT LIKE portion of the query. Separates
605 * multiple calls with AND
606 *
607 * @access public
608 * @param mixed
609 * @param mixed
610 * @return object
611 */
612 function not_like($field, $match = '', $side = 'both')
613 {
Rick Ellis59523592008-10-17 04:07:40 +0000614 return $this->_like($field, $match, 'AND ', $side, 'NOT');
Derek Allarde54e3d22007-12-19 15:53:44 +0000615 }
616
Derek Allard09de1852007-02-14 01:35:56 +0000617 // --------------------------------------------------------------------
618
619 /**
620 * OR Like
621 *
622 * Generates a %LIKE% portion of the query. Separates
623 * multiple calls with OR
624 *
625 * @access public
626 * @param mixed
627 * @param mixed
628 * @return object
629 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000630 function or_like($field, $match = '', $side = 'both')
Derek Allard09de1852007-02-14 01:35:56 +0000631 {
Derek Allard218e2bc2007-12-17 21:18:14 +0000632 return $this->_like($field, $match, 'OR ', $side);
633 }
634
635 // --------------------------------------------------------------------
636
637 /**
Derek Allarde54e3d22007-12-19 15:53:44 +0000638 * OR Not Like
639 *
640 * Generates a NOT LIKE portion of the query. Separates
641 * multiple calls with OR
642 *
643 * @access public
644 * @param mixed
645 * @param mixed
646 * @return object
647 */
648 function or_not_like($field, $match = '', $side = 'both')
649 {
Rick Ellis59523592008-10-17 04:07:40 +0000650 return $this->_like($field, $match, 'OR ', $side, 'NOT');
Derek Allarde54e3d22007-12-19 15:53:44 +0000651 }
652
653 // --------------------------------------------------------------------
654
655 /**
Derek Allard218e2bc2007-12-17 21:18:14 +0000656 * orlike() is an alias of or_like()
657 * this function is here for backwards compatibility, as
658 * orlike() has been deprecated
659 */
660 function orlike($field, $match = '', $side = 'both')
661 {
Derek Allard4a310b72008-01-30 21:32:47 +0000662 return $this->or_like($field, $match, $side);
Derek Allard09de1852007-02-14 01:35:56 +0000663 }
664
665 // --------------------------------------------------------------------
666
667 /**
668 * Like
669 *
670 * Called by like() or orlike()
671 *
672 * @access private
673 * @param mixed
674 * @param mixed
675 * @param string
676 * @return object
677 */
Derek Allarde54e3d22007-12-19 15:53:44 +0000678 function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
Derek Allard09de1852007-02-14 01:35:56 +0000679 {
Derek Jones0b59f272008-05-13 04:22:33 +0000680 if ( ! is_array($field))
Derek Allard09de1852007-02-14 01:35:56 +0000681 {
682 $field = array($field => $match);
683 }
684
685 foreach ($field as $k => $v)
Rick Ellis59523592008-10-17 04:07:40 +0000686 {
Derek Allard39b622d2008-01-16 21:10:09 +0000687 $k = $this->_protect_identifiers($k);
688
Derek Allard09de1852007-02-14 01:35:56 +0000689 $prefix = (count($this->ar_like) == 0) ? '' : $type;
Derek Allarde54e3d22007-12-19 15:53:44 +0000690
Rick Ellis59523592008-10-17 04:07:40 +0000691 $v = $this->escape_str($v);
Derek Allarde54e3d22007-12-19 15:53:44 +0000692
Derek Allard218e2bc2007-12-17 21:18:14 +0000693 if ($side == 'before')
694 {
Derek Allard9b3e7b52008-02-04 23:20:34 +0000695 $like_statement = $prefix." $k $not LIKE '%{$v}'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000696 }
697 elseif ($side == 'after')
698 {
Derek Allard9b3e7b52008-02-04 23:20:34 +0000699 $like_statement = $prefix." $k $not LIKE '{$v}%'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000700 }
701 else
702 {
Derek Allard9b3e7b52008-02-04 23:20:34 +0000703 $like_statement = $prefix." $k $not LIKE '%{$v}%'";
Derek Allard218e2bc2007-12-17 21:18:14 +0000704 }
Derek Allard9b3e7b52008-02-04 23:20:34 +0000705
706 $this->ar_like[] = $like_statement;
707 if ($this->ar_caching === TRUE)
708 {
709 $this->ar_cache_like[] = $like_statement;
Rick Ellis392f09d2008-10-18 02:03:14 +0000710 $this->ar_cache_exists[] = 'like';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000711 }
712
Derek Allard09de1852007-02-14 01:35:56 +0000713 }
714 return $this;
715 }
716
717 // --------------------------------------------------------------------
718
719 /**
720 * GROUP BY
721 *
722 * @access public
723 * @param string
724 * @return object
725 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000726 function group_by($by)
Derek Allard09de1852007-02-14 01:35:56 +0000727 {
728 if (is_string($by))
729 {
730 $by = explode(',', $by);
731 }
732
733 foreach ($by as $val)
734 {
735 $val = trim($val);
736
737 if ($val != '')
Derek Allard9b3e7b52008-02-04 23:20:34 +0000738 {
Derek Allard39b622d2008-01-16 21:10:09 +0000739 $this->ar_groupby[] = $this->_protect_identifiers($val);
Rick Ellis59523592008-10-17 04:07:40 +0000740
Derek Allard9b3e7b52008-02-04 23:20:34 +0000741 if ($this->ar_caching === TRUE)
742 {
743 $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
Rick Ellis392f09d2008-10-18 02:03:14 +0000744 $this->ar_cache_exists[] = 'groupby';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000745 }
746 }
Derek Allard09de1852007-02-14 01:35:56 +0000747 }
748 return $this;
749 }
Derek Allard218e2bc2007-12-17 21:18:14 +0000750
751 // --------------------------------------------------------------------
752
753 /**
754 * groupby() is an alias of group_by()
755 * this function is here for backwards compatibility, as
756 * groupby() has been deprecated
757 */
758 function groupby($by)
759 {
760 return $this->group_by($by);
761 }
762
Derek Allard09de1852007-02-14 01:35:56 +0000763 // --------------------------------------------------------------------
764
765 /**
766 * Sets the HAVING value
767 *
768 * Separates multiple calls with AND
769 *
770 * @access public
771 * @param string
772 * @param string
773 * @return object
774 */
Derek Allarde808aac2008-04-06 18:22:00 +0000775 function having($key, $value = '', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000776 {
Derek Allarde808aac2008-04-06 18:22:00 +0000777 return $this->_having($key, $value, 'AND ', $escape);
Derek Allard09de1852007-02-14 01:35:56 +0000778 }
Derek Allard43e8cbf2008-03-01 23:14:43 +0000779
780 // --------------------------------------------------------------------
781
782 /**
783 * orhaving() is an alias of or_having()
784 * this function is here for backwards compatibility, as
785 * orhaving() has been deprecated
786 */
787
Derek Allarde808aac2008-04-06 18:22:00 +0000788 function orhaving($key, $value = '', $escape = TRUE)
Derek Allard43e8cbf2008-03-01 23:14:43 +0000789 {
Derek Allarda459b462008-05-22 13:01:39 +0000790 return $this->or_having($key, $value, $escape);
Derek Allard43e8cbf2008-03-01 23:14:43 +0000791 }
Derek Allard09de1852007-02-14 01:35:56 +0000792 // --------------------------------------------------------------------
793
794 /**
795 * Sets the OR HAVING value
796 *
797 * Separates multiple calls with OR
798 *
799 * @access public
800 * @param string
801 * @param string
802 * @return object
803 */
Derek Allarde808aac2008-04-06 18:22:00 +0000804 function or_having($key, $value = '', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000805 {
Derek Allarde808aac2008-04-06 18:22:00 +0000806 return $this->_having($key, $value, 'OR ', $escape);
Derek Allard09de1852007-02-14 01:35:56 +0000807 }
808
809 // --------------------------------------------------------------------
810
811 /**
812 * Sets the HAVING values
813 *
Rick Ellisff734012008-09-30 20:38:12 +0000814 * Called by having() or or_having()
Derek Allard09de1852007-02-14 01:35:56 +0000815 *
816 * @access private
817 * @param string
818 * @param string
819 * @return object
820 */
Derek Allarde808aac2008-04-06 18:22:00 +0000821 function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000822 {
Derek Jones0b59f272008-05-13 04:22:33 +0000823 if ( ! is_array($key))
Derek Allard09de1852007-02-14 01:35:56 +0000824 {
825 $key = array($key => $value);
826 }
827
828 foreach ($key as $k => $v)
829 {
830 $prefix = (count($this->ar_having) == 0) ? '' : $type;
Derek Allarde808aac2008-04-06 18:22:00 +0000831
832 if ($escape === TRUE)
833 {
834 $k = $this->_protect_identifiers($k);
835 }
836
Derek Allarda459b462008-05-22 13:01:39 +0000837 if ( ! $this->_has_operator($k))
838 {
839 $k .= ' = ';
840 }
841
Derek Allard09de1852007-02-14 01:35:56 +0000842 if ($v != '')
843 {
Rick Ellis59523592008-10-17 04:07:40 +0000844 $v = ' '.$this->escape_str($v);
Derek Allard09de1852007-02-14 01:35:56 +0000845 }
846
847 $this->ar_having[] = $prefix.$k.$v;
Derek Allard9b3e7b52008-02-04 23:20:34 +0000848 if ($this->ar_caching === TRUE)
849 {
850 $this->ar_cache_having[] = $prefix.$k.$v;
Rick Ellis392f09d2008-10-18 02:03:14 +0000851 $this->ar_cache_exists[] = 'having';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000852 }
Derek Allard09de1852007-02-14 01:35:56 +0000853 }
Derek Allard9b3e7b52008-02-04 23:20:34 +0000854
Derek Allard09de1852007-02-14 01:35:56 +0000855 return $this;
856 }
857
858 // --------------------------------------------------------------------
859
860 /**
861 * Sets the ORDER BY value
862 *
863 * @access public
864 * @param string
865 * @param string direction: asc or desc
866 * @return object
867 */
Derek Allard218e2bc2007-12-17 21:18:14 +0000868 function order_by($orderby, $direction = '')
Derek Allard09de1852007-02-14 01:35:56 +0000869 {
Derek Allard6ddb5a12007-12-18 17:22:50 +0000870 if (strtolower($direction) == 'random')
871 {
872 $orderby = ''; // Random results want or don't need a field name
873 $direction = $this->_random_keyword;
874 }
875 elseif (trim($direction) != '')
Derek Allard09de1852007-02-14 01:35:56 +0000876 {
Derek Allard92782492007-08-10 11:26:01 +0000877 $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
Derek Allard09de1852007-02-14 01:35:56 +0000878 }
879
Rick Ellis59523592008-10-17 04:07:40 +0000880 $orderby_statement = $this->_protect_identifiers($orderby).$direction;
Derek Allard9b3e7b52008-02-04 23:20:34 +0000881
882 $this->ar_orderby[] = $orderby_statement;
883 if ($this->ar_caching === TRUE)
884 {
885 $this->ar_cache_orderby[] = $orderby_statement;
Rick Ellis392f09d2008-10-18 02:03:14 +0000886 $this->ar_cache_exists[] = 'orderby';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000887 }
888
Derek Allard09de1852007-02-14 01:35:56 +0000889 return $this;
890 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000891
Derek Allard218e2bc2007-12-17 21:18:14 +0000892 // --------------------------------------------------------------------
893
894 /**
895 * orderby() is an alias of order_by()
896 * this function is here for backwards compatibility, as
897 * orderby() has been deprecated
898 */
899 function orderby($orderby, $direction = '')
900 {
901 return $this->order_by($orderby, $direction);
902 }
Derek Allard6ddb5a12007-12-18 17:22:50 +0000903
Derek Allard09de1852007-02-14 01:35:56 +0000904 // --------------------------------------------------------------------
905
906 /**
907 * Sets the LIMIT value
908 *
909 * @access public
910 * @param integer the limit value
911 * @param integer the offset value
912 * @return object
913 */
914 function limit($value, $offset = '')
915 {
916 $this->ar_limit = $value;
Derek Allard9b3e7b52008-02-04 23:20:34 +0000917 if ($this->ar_caching === TRUE)
918 {
919 $this->ar_cache_limit[] = $value;
Rick Ellis392f09d2008-10-18 02:03:14 +0000920 $this->ar_cache_exists[] = 'limit';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000921 }
922
Derek Allard09de1852007-02-14 01:35:56 +0000923 if ($offset != '')
Derek Allard9b3e7b52008-02-04 23:20:34 +0000924 {
Derek Allard09de1852007-02-14 01:35:56 +0000925 $this->ar_offset = $offset;
Derek Allard9b3e7b52008-02-04 23:20:34 +0000926 if ($this->ar_caching === TRUE)
927 {
928 $this->ar_cache_offset[] = $offset;
Rick Ellis392f09d2008-10-18 02:03:14 +0000929 $this->ar_cache_exists[] = 'limit';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000930 }
931 }
Derek Allard09de1852007-02-14 01:35:56 +0000932
933 return $this;
934 }
935
936 // --------------------------------------------------------------------
937
938 /**
939 * Sets the OFFSET value
940 *
941 * @access public
942 * @param integer the offset value
943 * @return object
944 */
Derek Allard9b3e7b52008-02-04 23:20:34 +0000945 function offset($offset)
Derek Allard09de1852007-02-14 01:35:56 +0000946 {
Derek Allard9b3e7b52008-02-04 23:20:34 +0000947 $this->ar_offset = $offset;
948 if ($this->ar_caching === TRUE)
949 {
950 $this->ar_cache_offset[] = $offset;
Rick Ellis392f09d2008-10-18 02:03:14 +0000951 $this->ar_cache_exists[] = 'offset';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000952 }
953
Derek Allard09de1852007-02-14 01:35:56 +0000954 return $this;
955 }
956
957 // --------------------------------------------------------------------
958
959 /**
960 * The "set" function. Allows key/value pairs to be set for inserting or updating
961 *
962 * @access public
963 * @param mixed
964 * @param string
Derek Allard39b622d2008-01-16 21:10:09 +0000965 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +0000966 * @return object
967 */
Derek Allard39b622d2008-01-16 21:10:09 +0000968 function set($key, $value = '', $escape = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +0000969 {
970 $key = $this->_object_to_array($key);
971
Derek Jones0b59f272008-05-13 04:22:33 +0000972 if ( ! is_array($key))
Derek Allard09de1852007-02-14 01:35:56 +0000973 {
974 $key = array($key => $value);
975 }
976
977 foreach ($key as $k => $v)
978 {
Derek Allard39b622d2008-01-16 21:10:09 +0000979 if ($escape === FALSE)
980 {
981 $this->ar_set[$this->_protect_identifiers($k)] = $v;
Rick Ellis59523592008-10-17 04:07:40 +0000982
Derek Allard9b3e7b52008-02-04 23:20:34 +0000983 if ($this->ar_caching === TRUE)
984 {
985 $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v;
Rick Ellis392f09d2008-10-18 02:03:14 +0000986 $this->ar_cache_exists[] = 'offset';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000987 }
Derek Allard39b622d2008-01-16 21:10:09 +0000988 }
989 else
990 {
991 $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
Rick Ellis59523592008-10-17 04:07:40 +0000992
Derek Allard9b3e7b52008-02-04 23:20:34 +0000993 if ($this->ar_caching === TRUE)
994 {
995 $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v);
Rick Ellis392f09d2008-10-18 02:03:14 +0000996 $this->ar_cache_exists[] = 'offset';
Derek Allard9b3e7b52008-02-04 23:20:34 +0000997 }
Derek Allard39b622d2008-01-16 21:10:09 +0000998 }
Derek Allard09de1852007-02-14 01:35:56 +0000999 }
1000
1001 return $this;
1002 }
1003
1004 // --------------------------------------------------------------------
1005
1006 /**
1007 * Get
1008 *
1009 * Compiles the select statement based on the other functions called
1010 * and runs the query
1011 *
1012 * @access public
Derek Allard694b5b82007-12-18 15:58:03 +00001013 * @param string the table
Derek Allard09de1852007-02-14 01:35:56 +00001014 * @param string the limit clause
1015 * @param string the offset clause
1016 * @return object
1017 */
1018 function get($table = '', $limit = null, $offset = null)
1019 {
1020 if ($table != '')
1021 {
Derek Allard5e128942007-12-28 21:33:03 +00001022 $this->_track_aliases($table);
Derek Allard09de1852007-02-14 01:35:56 +00001023 $this->from($table);
1024 }
1025
Derek Jones0b59f272008-05-13 04:22:33 +00001026 if ( ! is_null($limit))
Derek Allard09de1852007-02-14 01:35:56 +00001027 {
1028 $this->limit($limit, $offset);
1029 }
1030
1031 $sql = $this->_compile_select();
1032
1033 $result = $this->query($sql);
1034 $this->_reset_select();
1035 return $result;
1036 }
1037
Derek Allard09de1852007-02-14 01:35:56 +00001038 /**
Derek Allard694b5b82007-12-18 15:58:03 +00001039 * "Count All Results" query
1040 *
1041 * Generates a platform-specific query string that counts all records
1042 * returned by an Active Record query.
1043 *
1044 * @access public
1045 * @param string
1046 * @return string
1047 */
1048 function count_all_results($table = '')
1049 {
1050 if ($table != '')
1051 {
Derek Allard5e128942007-12-28 21:33:03 +00001052 $this->_track_aliases($table);
Derek Allard694b5b82007-12-18 15:58:03 +00001053 $this->from($table);
1054 }
1055
Derek Allard39b622d2008-01-16 21:10:09 +00001056 $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
Derek Allard694b5b82007-12-18 15:58:03 +00001057
1058 $query = $this->query($sql);
1059 $this->_reset_select();
1060
1061 if ($query->num_rows() == 0)
1062 {
1063 return '0';
1064 }
1065
1066 $row = $query->row();
1067 return $row->numrows;
1068 }
1069
1070 // --------------------------------------------------------------------
1071
1072 /**
Derek Allard218e2bc2007-12-17 21:18:14 +00001073 * Get_Where
Derek Allard09de1852007-02-14 01:35:56 +00001074 *
1075 * Allows the where clause, limit and offset to be added directly
1076 *
1077 * @access public
1078 * @param string the where clause
1079 * @param string the limit clause
1080 * @param string the offset clause
1081 * @return object
1082 */
Derek Allard218e2bc2007-12-17 21:18:14 +00001083 function get_where($table = '', $where = null, $limit = null, $offset = null)
Derek Allard09de1852007-02-14 01:35:56 +00001084 {
1085 if ($table != '')
1086 {
1087 $this->from($table);
1088 }
1089
Derek Jones0b59f272008-05-13 04:22:33 +00001090 if ( ! is_null($where))
Derek Allard09de1852007-02-14 01:35:56 +00001091 {
1092 $this->where($where);
1093 }
1094
Derek Jones0b59f272008-05-13 04:22:33 +00001095 if ( ! is_null($limit))
Derek Allard09de1852007-02-14 01:35:56 +00001096 {
1097 $this->limit($limit, $offset);
1098 }
1099
1100 $sql = $this->_compile_select();
1101
1102 $result = $this->query($sql);
1103 $this->_reset_select();
1104 return $result;
1105 }
Derek Allard218e2bc2007-12-17 21:18:14 +00001106
1107 // --------------------------------------------------------------------
1108
1109 /**
1110 * getwhere() is an alias of get_where()
1111 * this function is here for backwards compatibility, as
1112 * getwhere() has been deprecated
1113 */
1114 function getwhere($table = '', $where = null, $limit = null, $offset = null)
1115 {
1116 return $this->get_where($table, $where, $limit, $offset);
1117 }
Derek Allard09de1852007-02-14 01:35:56 +00001118
1119 // --------------------------------------------------------------------
1120
1121 /**
1122 * Insert
1123 *
1124 * Compiles an insert string and runs the query
1125 *
1126 * @access public
1127 * @param string the table to retrieve the results from
1128 * @param array an associative array of insert values
1129 * @return object
1130 */
1131 function insert($table = '', $set = NULL)
1132 {
Derek Jones0b59f272008-05-13 04:22:33 +00001133 if ( ! is_null($set))
Derek Allard09de1852007-02-14 01:35:56 +00001134 {
1135 $this->set($set);
1136 }
1137
1138 if (count($this->ar_set) == 0)
1139 {
1140 if ($this->db_debug)
1141 {
1142 return $this->display_error('db_must_use_set');
1143 }
1144 return FALSE;
1145 }
1146
1147 if ($table == '')
1148 {
Derek Jones0b59f272008-05-13 04:22:33 +00001149 if ( ! isset($this->ar_from[0]))
Derek Allard09de1852007-02-14 01:35:56 +00001150 {
1151 if ($this->db_debug)
1152 {
1153 return $this->display_error('db_must_set_table');
1154 }
1155 return FALSE;
1156 }
1157
1158 $table = $this->ar_from[0];
1159 }
Derek Allard39b622d2008-01-16 21:10:09 +00001160
Rick Ellis59523592008-10-17 04:07:40 +00001161 $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
Derek Allard09de1852007-02-14 01:35:56 +00001162
1163 $this->_reset_write();
1164 return $this->query($sql);
1165 }
1166
1167 // --------------------------------------------------------------------
1168
1169 /**
1170 * Update
1171 *
1172 * Compiles an update string and runs the query
1173 *
1174 * @access public
1175 * @param string the table to retrieve the results from
1176 * @param array an associative array of update values
1177 * @param mixed the where clause
1178 * @return object
1179 */
Derek Allard5e128942007-12-28 21:33:03 +00001180 function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001181 {
Derek Jones0b59f272008-05-13 04:22:33 +00001182 if ( ! is_null($set))
Derek Allard09de1852007-02-14 01:35:56 +00001183 {
1184 $this->set($set);
1185 }
1186
1187 if (count($this->ar_set) == 0)
1188 {
1189 if ($this->db_debug)
1190 {
1191 return $this->display_error('db_must_use_set');
1192 }
1193 return FALSE;
1194 }
1195
1196 if ($table == '')
1197 {
Derek Jones0b59f272008-05-13 04:22:33 +00001198 if ( ! isset($this->ar_from[0]))
Derek Allard09de1852007-02-14 01:35:56 +00001199 {
1200 if ($this->db_debug)
1201 {
1202 return $this->display_error('db_must_set_table');
1203 }
1204 return FALSE;
1205 }
1206
1207 $table = $this->ar_from[0];
1208 }
1209
Derek Allarde77d77c2007-12-19 15:01:55 +00001210 if ($where != NULL)
Derek Allard09de1852007-02-14 01:35:56 +00001211 {
1212 $this->where($where);
1213 }
Derek Allardda6d2402007-12-19 14:49:29 +00001214
Derek Allarde77d77c2007-12-19 15:01:55 +00001215 if ($limit != NULL)
Derek Allardda6d2402007-12-19 14:49:29 +00001216 {
1217 $this->limit($limit);
1218 }
Derek Allard09de1852007-02-14 01:35:56 +00001219
Rick Ellis59523592008-10-17 04:07:40 +00001220 $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
Derek Allard09de1852007-02-14 01:35:56 +00001221
1222 $this->_reset_write();
1223 return $this->query($sql);
1224 }
Derek Allard39b622d2008-01-16 21:10:09 +00001225
1226 // --------------------------------------------------------------------
1227
1228 /**
1229 * Empty Table
1230 *
1231 * Compiles a delete string and runs "DELETE FROM table"
1232 *
1233 * @access public
1234 * @param string the table to empty
1235 * @return object
1236 */
1237 function empty_table($table = '')
1238 {
1239 if ($table == '')
1240 {
Derek Jones0b59f272008-05-13 04:22:33 +00001241 if ( ! isset($this->ar_from[0]))
Derek Allard39b622d2008-01-16 21:10:09 +00001242 {
1243 if ($this->db_debug)
1244 {
1245 return $this->display_error('db_must_set_table');
1246 }
1247 return FALSE;
1248 }
1249
1250 $table = $this->ar_from[0];
1251 }
1252 else
1253 {
Rick Ellis59523592008-10-17 04:07:40 +00001254 $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
Derek Allard39b622d2008-01-16 21:10:09 +00001255 }
1256
Derek Allard39b622d2008-01-16 21:10:09 +00001257 $sql = $this->_delete($table);
1258
1259 $this->_reset_write();
1260
1261 return $this->query($sql);
1262 }
1263
1264 // --------------------------------------------------------------------
1265
1266 /**
1267 * Truncate
1268 *
1269 * Compiles a truncate string and runs the query
1270 * If the database does not support the truncate() command
1271 * This function maps to "DELETE FROM table"
1272 *
1273 * @access public
1274 * @param string the table to truncate
1275 * @return object
1276 */
1277 function truncate($table = '')
1278 {
1279 if ($table == '')
1280 {
Derek Jones0b59f272008-05-13 04:22:33 +00001281 if ( ! isset($this->ar_from[0]))
Derek Allard39b622d2008-01-16 21:10:09 +00001282 {
1283 if ($this->db_debug)
1284 {
1285 return $this->display_error('db_must_set_table');
1286 }
1287 return FALSE;
1288 }
1289
1290 $table = $this->ar_from[0];
1291 }
1292 else
1293 {
Rick Ellis59523592008-10-17 04:07:40 +00001294 $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
Derek Allard39b622d2008-01-16 21:10:09 +00001295 }
1296
Derek Allard39b622d2008-01-16 21:10:09 +00001297 $sql = $this->_truncate($table);
1298
1299 $this->_reset_write();
1300
1301 return $this->query($sql);
1302 }
Derek Allard09de1852007-02-14 01:35:56 +00001303
1304 // --------------------------------------------------------------------
1305
1306 /**
1307 * Delete
1308 *
1309 * Compiles a delete string and runs the query
1310 *
1311 * @access public
Derek Allard41f60d42007-12-20 20:09:22 +00001312 * @param mixed the table(s) to delete from. String or array
Derek Allard09de1852007-02-14 01:35:56 +00001313 * @param mixed the where clause
Derek Allard41f60d42007-12-20 20:09:22 +00001314 * @param mixed the limit clause
1315 * @param boolean
Derek Allard09de1852007-02-14 01:35:56 +00001316 * @return object
1317 */
Derek Allard41f60d42007-12-20 20:09:22 +00001318 function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
Derek Allard09de1852007-02-14 01:35:56 +00001319 {
1320 if ($table == '')
1321 {
Derek Jones0b59f272008-05-13 04:22:33 +00001322 if ( ! isset($this->ar_from[0]))
Derek Allard09de1852007-02-14 01:35:56 +00001323 {
1324 if ($this->db_debug)
1325 {
1326 return $this->display_error('db_must_set_table');
1327 }
1328 return FALSE;
1329 }
Derek Allard39b622d2008-01-16 21:10:09 +00001330
Derek Allard09de1852007-02-14 01:35:56 +00001331 $table = $this->ar_from[0];
1332 }
Derek Allard39b622d2008-01-16 21:10:09 +00001333 elseif (is_array($table))
Derek Allard41f60d42007-12-20 20:09:22 +00001334 {
1335 foreach($table as $single_table)
1336 {
Derek Allard39b622d2008-01-16 21:10:09 +00001337 $this->delete($single_table, $where, $limit, FALSE);
Derek Allard41f60d42007-12-20 20:09:22 +00001338 }
Derek Allard39b622d2008-01-16 21:10:09 +00001339
Derek Allard41f60d42007-12-20 20:09:22 +00001340 $this->_reset_write();
1341 return;
1342 }
Derek Allard39b622d2008-01-16 21:10:09 +00001343 else
1344 {
Rick Ellis59523592008-10-17 04:07:40 +00001345 $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
Derek Allard39b622d2008-01-16 21:10:09 +00001346 }
Derek Allard41f60d42007-12-20 20:09:22 +00001347
Derek Allard09de1852007-02-14 01:35:56 +00001348 if ($where != '')
1349 {
1350 $this->where($where);
1351 }
1352
Derek Allarde77d77c2007-12-19 15:01:55 +00001353 if ($limit != NULL)
1354 {
1355 $this->limit($limit);
1356 }
1357
Derek Allard39b622d2008-01-16 21:10:09 +00001358 if (count($this->ar_where) == 0 && count($this->ar_like) == 0)
Derek Allard09de1852007-02-14 01:35:56 +00001359 {
1360 if ($this->db_debug)
1361 {
1362 return $this->display_error('db_del_must_use_where');
1363 }
Derek Allard39b622d2008-01-16 21:10:09 +00001364
Derek Allard09de1852007-02-14 01:35:56 +00001365 return FALSE;
1366 }
Derek Allard41f60d42007-12-20 20:09:22 +00001367
Derek Allard39b622d2008-01-16 21:10:09 +00001368 $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
Derek Allard09de1852007-02-14 01:35:56 +00001369
Derek Allard41f60d42007-12-20 20:09:22 +00001370 if ($reset_data)
1371 {
1372 $this->_reset_write();
1373 }
Derek Allard39b622d2008-01-16 21:10:09 +00001374
Derek Allard09de1852007-02-14 01:35:56 +00001375 return $this->query($sql);
1376 }
Derek Allard15ddc9d2007-12-20 13:54:39 +00001377
Derek Allard09de1852007-02-14 01:35:56 +00001378 // --------------------------------------------------------------------
1379
1380 /**
Rick Ellis59523592008-10-17 04:07:40 +00001381 * DB Prefix
Derek Allard09de1852007-02-14 01:35:56 +00001382 *
Rick Ellis59523592008-10-17 04:07:40 +00001383 * Prepends a database prefix if one exists in configuration
1384 *
1385 * @access public
1386 * @param string the table
1387 * @return string
Derek Allard09de1852007-02-14 01:35:56 +00001388 */
Rick Ellis59523592008-10-17 04:07:40 +00001389 function dbprefix($table = '')
Derek Allard09de1852007-02-14 01:35:56 +00001390 {
Rick Ellis59523592008-10-17 04:07:40 +00001391 if ($table == '')
1392 {
1393 $this->display_error('db_table_name_required');
1394 }
1395
1396 return $this->dbprefix.$table;
Derek Allard09de1852007-02-14 01:35:56 +00001397 }
Derek Allard09de1852007-02-14 01:35:56 +00001398
Derek Allard09de1852007-02-14 01:35:56 +00001399 // --------------------------------------------------------------------
1400
1401 /**
Derek Allard5e128942007-12-28 21:33:03 +00001402 * Track Aliases
1403 *
1404 * Used to track SQL statements written with aliased tables.
1405 *
1406 * @access private
1407 * @param string The table to inspect
1408 * @return string
1409 */
1410 function _track_aliases($table)
1411 {
Rick Ellis59523592008-10-17 04:07:40 +00001412 if (is_array($table))
1413 {
1414 foreach ($table as $t)
1415 {
1416 $this->_track_aliases($t);
1417 }
1418 return;
1419 }
1420
1421 // Does the string contain a comma? If so, we need to separate
1422 // the string into discreet statements
1423 if (strpos($table, ',') !== FALSE)
1424 {
1425 return $this->_track_aliases(explode(',', $table));
1426 }
1427
Derek Allard5e128942007-12-28 21:33:03 +00001428 // if a table alias is used we can recognize it by a space
1429 if (strpos($table, " ") !== FALSE)
1430 {
Rick Ellis59523592008-10-17 04:07:40 +00001431 // if the alias is written with the AS keyword, remove it
1432 $table = preg_replace('/ AS /i', ' ', $table);
1433
1434 // Grab the alias
1435 $table = trim(strrchr($table, " "));
1436
1437 // Store the alias, if it doesn't already exist
1438 if ( ! in_array($table, $this->ar_aliased_tables))
Derek Allard5e128942007-12-28 21:33:03 +00001439 {
Rick Ellis59523592008-10-17 04:07:40 +00001440 $this->ar_aliased_tables[] = $table;
Derek Allard5e128942007-12-28 21:33:03 +00001441 }
Derek Allard5e128942007-12-28 21:33:03 +00001442 }
Derek Allard5e128942007-12-28 21:33:03 +00001443 }
1444
1445 // --------------------------------------------------------------------
1446
1447 /**
Derek Allard09de1852007-02-14 01:35:56 +00001448 * Compile the SELECT statement
1449 *
1450 * Generates a query string based on which functions were used.
1451 * Should not be called directly. The get() function calls it.
1452 *
1453 * @access private
1454 * @return string
1455 */
Derek Allard694b5b82007-12-18 15:58:03 +00001456 function _compile_select($select_override = FALSE)
Derek Allard09de1852007-02-14 01:35:56 +00001457 {
Derek Allard78255262008-02-06 13:54:23 +00001458 $this->_merge_cache();
Derek Allard9b3e7b52008-02-04 23:20:34 +00001459
Rick Ellis59523592008-10-17 04:07:40 +00001460 // ----------------------------------------------------------------
1461
1462 // Write the "select" portion of the query
Derek Allard09de1852007-02-14 01:35:56 +00001463
Derek Allard694b5b82007-12-18 15:58:03 +00001464 if ($select_override !== FALSE)
1465 {
1466 $sql = $select_override;
1467 }
Rick Ellis59523592008-10-17 04:07:40 +00001468 else
1469 {
1470 $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
1471
1472 if (count($this->ar_select) == 0)
1473 {
1474 $sql .= '*';
1475 }
1476 else
1477 {
1478 // Cycle through the "select" portion of the query and prep each column name.
1479 // The reason we protect identifiers here rather then in the select() function
1480 // is because until the user calls the from() function we don't know if there are aliases
1481 foreach ($this->ar_select as $key => $val)
1482 {
1483 $this->ar_select[$key] = $this->_protect_identifiers($val);
1484 }
1485
1486 $sql .= implode(', ', $this->ar_select);
1487 }
1488 }
1489
1490 // ----------------------------------------------------------------
1491
1492 // Write the "FROM" portion of the query
Derek Allard694b5b82007-12-18 15:58:03 +00001493
Derek Allard09de1852007-02-14 01:35:56 +00001494 if (count($this->ar_from) > 0)
1495 {
1496 $sql .= "\nFROM ";
Rick Ellis59523592008-10-17 04:07:40 +00001497
Derek Jonesc6ad0232008-01-29 18:44:54 +00001498 $sql .= $this->_from_tables($this->ar_from);
Derek Allard09de1852007-02-14 01:35:56 +00001499 }
1500
Rick Ellis59523592008-10-17 04:07:40 +00001501 // ----------------------------------------------------------------
1502
1503 // Write the "JOIN" portion of the query
1504
Derek Allard09de1852007-02-14 01:35:56 +00001505 if (count($this->ar_join) > 0)
Derek Allard5e128942007-12-28 21:33:03 +00001506 {
Derek Allard09de1852007-02-14 01:35:56 +00001507 $sql .= "\n";
Derek Allard5e128942007-12-28 21:33:03 +00001508
Rick Ellis59523592008-10-17 04:07:40 +00001509 $sql .= implode("\n", $this->ar_join);
Derek Allard09de1852007-02-14 01:35:56 +00001510 }
1511
Rick Ellis59523592008-10-17 04:07:40 +00001512 // ----------------------------------------------------------------
1513
1514 // Write the "WHERE" portion of the query
1515
Derek Allard09de1852007-02-14 01:35:56 +00001516 if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
1517 {
Rick Ellis59523592008-10-17 04:07:40 +00001518 $sql .= "\n";
1519
1520 $sql .= "WHERE ";
Derek Allard09de1852007-02-14 01:35:56 +00001521 }
1522
1523 $sql .= implode("\n", $this->ar_where);
Rick Ellis59523592008-10-17 04:07:40 +00001524
1525 // ----------------------------------------------------------------
Derek Allard09de1852007-02-14 01:35:56 +00001526
Rick Ellis59523592008-10-17 04:07:40 +00001527 // Write the "LIKE" portion of the query
1528
Derek Allard09de1852007-02-14 01:35:56 +00001529 if (count($this->ar_like) > 0)
1530 {
1531 if (count($this->ar_where) > 0)
1532 {
Rick Ellis59523592008-10-17 04:07:40 +00001533 $sql .= "\nAND ";
Derek Allard09de1852007-02-14 01:35:56 +00001534 }
1535
1536 $sql .= implode("\n", $this->ar_like);
1537 }
Rick Ellis59523592008-10-17 04:07:40 +00001538
1539 // ----------------------------------------------------------------
Derek Allard09de1852007-02-14 01:35:56 +00001540
Rick Ellis59523592008-10-17 04:07:40 +00001541 // Write the "GROUP BY" portion of the query
1542
Derek Allard09de1852007-02-14 01:35:56 +00001543 if (count($this->ar_groupby) > 0)
1544 {
1545 $sql .= "\nGROUP BY ";
Derek Allard5e128942007-12-28 21:33:03 +00001546
Rick Ellis59523592008-10-17 04:07:40 +00001547 $sql .= implode(', ', $this->ar_groupby);
Derek Allard09de1852007-02-14 01:35:56 +00001548 }
Rick Ellis59523592008-10-17 04:07:40 +00001549
1550 // ----------------------------------------------------------------
1551
1552 // Write the "HAVING" portion of the query
Derek Allard09de1852007-02-14 01:35:56 +00001553
1554 if (count($this->ar_having) > 0)
1555 {
1556 $sql .= "\nHAVING ";
1557 $sql .= implode("\n", $this->ar_having);
1558 }
1559
Rick Ellis59523592008-10-17 04:07:40 +00001560 // ----------------------------------------------------------------
1561
1562 // Write the "ORDER BY" portion of the query
1563
Derek Allard09de1852007-02-14 01:35:56 +00001564 if (count($this->ar_orderby) > 0)
1565 {
1566 $sql .= "\nORDER BY ";
1567 $sql .= implode(', ', $this->ar_orderby);
1568
1569 if ($this->ar_order !== FALSE)
1570 {
1571 $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
1572 }
1573 }
Rick Ellis59523592008-10-17 04:07:40 +00001574
1575 // ----------------------------------------------------------------
1576
1577 // Write the "LIMIT" portion of the query
Derek Allard09de1852007-02-14 01:35:56 +00001578
1579 if (is_numeric($this->ar_limit))
1580 {
1581 $sql .= "\n";
1582 $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
1583 }
1584
1585 return $sql;
1586 }
1587
1588 // --------------------------------------------------------------------
1589
1590 /**
1591 * Object to Array
1592 *
1593 * Takes an object as input and converts the class variables to array key/vals
1594 *
1595 * @access public
1596 * @param object
1597 * @return array
1598 */
1599 function _object_to_array($object)
1600 {
Derek Jones0b59f272008-05-13 04:22:33 +00001601 if ( ! is_object($object))
Derek Allard09de1852007-02-14 01:35:56 +00001602 {
1603 return $object;
1604 }
1605
1606 $array = array();
1607 foreach (get_object_vars($object) as $key => $val)
1608 {
Derek Allard848b7762007-12-31 16:43:05 +00001609 // There are some built in keys we need to ignore for this conversion
Derek Jones0b59f272008-05-13 04:22:33 +00001610 if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table')
Derek Allard09de1852007-02-14 01:35:56 +00001611 {
1612 $array[$key] = $val;
1613 }
1614 }
1615
1616 return $array;
1617 }
1618
1619 // --------------------------------------------------------------------
1620
1621 /**
Derek Allard9b3e7b52008-02-04 23:20:34 +00001622 * Start Cache
1623 *
1624 * Starts AR caching
1625 *
1626 * @access public
1627 * @return void
1628 */
1629 function start_cache()
1630 {
1631 $this->ar_caching = TRUE;
1632 }
1633
1634 // --------------------------------------------------------------------
1635
1636 /**
1637 * Stop Cache
1638 *
1639 * Stops AR caching
1640 *
1641 * @access public
1642 * @return void
1643 */
1644 function stop_cache()
1645 {
1646 $this->ar_caching = FALSE;
1647 }
1648
Derek Allard9b3e7b52008-02-04 23:20:34 +00001649 // --------------------------------------------------------------------
1650
1651 /**
1652 * Flush Cache
1653 *
1654 * Empties the AR cache
1655 *
1656 * @access public
1657 * @return void
1658 */
1659 function flush_cache()
1660 {
1661 $ar_reset_items = array(
Rick Ellis59523592008-10-17 04:07:40 +00001662 'ar_cache_select' => array(),
1663 'ar_cache_from' => array(),
1664 'ar_cache_join' => array(),
1665 'ar_cache_where' => array(),
1666 'ar_cache_like' => array(),
1667 'ar_cache_groupby' => array(),
Rick Ellis23012592008-10-18 02:11:06 +00001668 'ar_cache_having' => array(),
Rick Ellis59523592008-10-17 04:07:40 +00001669 'ar_cache_orderby' => array(),
Rick Ellis23012592008-10-18 02:11:06 +00001670 'ar_cache_set' => array(),
1671 'ar_cache_exists' => array()
Rick Ellis59523592008-10-17 04:07:40 +00001672 );
Derek Allard9b3e7b52008-02-04 23:20:34 +00001673
1674 $this->_reset_run($ar_reset_items);
1675 }
1676
1677 // --------------------------------------------------------------------
1678
1679 /**
1680 * Merge Cache
1681 *
1682 * When called, this function merges any cached AR arrays with
1683 * locally called ones.
1684 *
1685 * @access private
1686 * @return void
1687 */
1688 function _merge_cache()
1689 {
Rick Ellis392f09d2008-10-18 02:03:14 +00001690 if (count($this->ar_cache_exists) == 0)
Rick Ellis59523592008-10-17 04:07:40 +00001691 {
1692 return;
1693 }
Rick Ellis392f09d2008-10-18 02:03:14 +00001694
1695 foreach ($this->ar_cache_exists as $val)
Derek Allard9b3e7b52008-02-04 23:20:34 +00001696 {
Rick Ellis000f89d2008-10-17 23:26:15 +00001697 $ar_variable = 'ar_'.$val;
1698 $ar_cache_var = 'ar_cache_'.$val;
1699
1700 if (count($this->$ar_cache_var) == 0)
1701 {
1702 continue;
1703 }
Rick Ellis392f09d2008-10-18 02:03:14 +00001704
Rick Ellis000f89d2008-10-17 23:26:15 +00001705 $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable));
Derek Allard9b3e7b52008-02-04 23:20:34 +00001706 }
Rick Ellis392f09d2008-10-18 02:03:14 +00001707
Rick Ellis59523592008-10-17 04:07:40 +00001708 // If we are "protecting identifiers" we need to examine the "from"
1709 // portion of the query to determine if there are any aliases
Rick Ellis392f09d2008-10-18 02:03:14 +00001710 if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0)
Rick Ellis59523592008-10-17 04:07:40 +00001711 {
1712 $this->_track_aliases($this->ar_from);
1713 }
Derek Allard9b3e7b52008-02-04 23:20:34 +00001714 }
1715
1716 // --------------------------------------------------------------------
1717
1718 /**
1719 * Resets the active record values. Called by the get() function
1720 *
1721 * @access private
1722 * @param array An array of fields to reset
1723 * @return void
1724 */
1725 function _reset_run($ar_reset_items)
1726 {
1727 foreach ($ar_reset_items as $item => $default_value)
1728 {
Derek Jones0b59f272008-05-13 04:22:33 +00001729 if ( ! in_array($item, $this->ar_store_array))
Derek Allard9b3e7b52008-02-04 23:20:34 +00001730 {
1731 $this->$item = $default_value;
1732 }
1733 }
1734 }
Rick Ellis59523592008-10-17 04:07:40 +00001735
Derek Allard9b3e7b52008-02-04 23:20:34 +00001736 // --------------------------------------------------------------------
1737
1738 /**
Derek Allard09de1852007-02-14 01:35:56 +00001739 * Resets the active record values. Called by the get() function
1740 *
1741 * @access private
1742 * @return void
1743 */
1744 function _reset_select()
1745 {
Derek Allard9b3e7b52008-02-04 23:20:34 +00001746 $ar_reset_items = array(
Rick Ellis59523592008-10-17 04:07:40 +00001747 'ar_select' => array(),
1748 'ar_from' => array(),
1749 'ar_join' => array(),
1750 'ar_where' => array(),
1751 'ar_like' => array(),
1752 'ar_groupby' => array(),
1753 'ar_having' => array(),
1754 'ar_orderby' => array(),
1755 'ar_wherein' => array(),
1756 'ar_aliased_tables' => array(),
1757 'ar_distinct' => FALSE,
1758 'ar_limit' => FALSE,
1759 'ar_offset' => FALSE,
1760 'ar_order' => FALSE,
1761 );
Derek Allard9b3e7b52008-02-04 23:20:34 +00001762
1763 $this->_reset_run($ar_reset_items);
Derek Allard09de1852007-02-14 01:35:56 +00001764 }
1765
1766 // --------------------------------------------------------------------
1767
1768 /**
1769 * Resets the active record "write" values.
1770 *
Derek Allarde77d77c2007-12-19 15:01:55 +00001771 * Called by the insert() update() and delete() functions
Derek Allard09de1852007-02-14 01:35:56 +00001772 *
1773 * @access private
1774 * @return void
1775 */
1776 function _reset_write()
Derek Allard9b3e7b52008-02-04 23:20:34 +00001777 {
1778 $ar_reset_items = array(
Rick Ellis59523592008-10-17 04:07:40 +00001779 'ar_set' => array(),
1780 'ar_from' => array(),
1781 'ar_where' => array(),
1782 'ar_like' => array(),
1783 'ar_orderby' => array(),
1784 'ar_limit' => FALSE,
1785 'ar_order' => FALSE
1786 );
Derek Allard9b3e7b52008-02-04 23:20:34 +00001787
1788 $this->_reset_run($ar_reset_items);
Derek Allard09de1852007-02-14 01:35:56 +00001789 }
1790
1791}
Derek Allarda6325892008-05-12 17:51:47 +00001792
1793/* End of file DB_active_rec.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +00001794/* Location: ./system/database/DB_active_rec.php */