Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 3 | * CodeIgniter
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Allard | cdd2ab2 | 2008-01-23 00:05:38 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 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
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 26 | * @author ExpressionEngine Dev Team
|
Derek Allard | cdd2ab2 | 2008-01-23 00:05:38 +0000 | [diff] [blame] | 27 | * @link http://codeigniter.com/user_guide/database/
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 28 | */
|
| 29 | class 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 Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 44 | var $ar_wherein = array();
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 45 | var $ar_aliased_tables = array();
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 46 | var $ar_store_array = array();
|
| 47 |
|
| 48 | // Active Record Caching variables
|
| 49 | var $ar_caching = FALSE;
|
| 50 | var $ar_cache_select = array();
|
| 51 | var $ar_cache_from = array();
|
| 52 | var $ar_cache_join = array();
|
| 53 | var $ar_cache_where = array();
|
| 54 | var $ar_cache_like = array();
|
| 55 | var $ar_cache_groupby = array();
|
| 56 | var $ar_cache_having = array();
|
| 57 | var $ar_cache_limit = FALSE;
|
| 58 | var $ar_cache_offset = FALSE;
|
| 59 | var $ar_cache_order = FALSE;
|
| 60 | var $ar_cache_orderby = array();
|
| 61 | var $ar_cache_set = array();
|
| 62 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 63 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 64 | /**
|
Derek Allard | 3b11868 | 2008-01-22 23:44:32 +0000 | [diff] [blame] | 65 | * DB Prefix
|
| 66 | *
|
| 67 | * Prepends a database prefix if one exists in configuration
|
| 68 | *
|
| 69 | * @access public
|
| 70 | * @param string the table
|
| 71 | * @return string
|
| 72 | */
|
| 73 | function dbprefix($table = '')
|
| 74 | {
|
| 75 | if ($table == '')
|
| 76 | {
|
| 77 | $this->display_error('db_table_name_required');
|
| 78 | }
|
| 79 |
|
| 80 | return $this->dbprefix.$table;
|
| 81 | }
|
| 82 |
|
| 83 | // --------------------------------------------------------------------
|
| 84 |
|
| 85 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 86 | * Select
|
| 87 | *
|
| 88 | * Generates the SELECT portion of the query
|
| 89 | *
|
| 90 | * @access public
|
| 91 | * @param string
|
| 92 | * @return object
|
| 93 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 94 | function select($select = '*', $protect_identifiers = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 95 | {
|
| 96 | if (is_string($select))
|
| 97 | {
|
| 98 | $select = explode(',', $select);
|
| 99 | }
|
| 100 |
|
| 101 | foreach ($select as $val)
|
| 102 | {
|
| 103 | $val = trim($val);
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 104 |
|
| 105 | if ($val != '*' && $protect_identifiers !== FALSE)
|
| 106 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 107 | if (strpos($val, '.') !== FALSE)
|
| 108 | {
|
| 109 | $val = $this->dbprefix.$val;
|
| 110 | }
|
| 111 | else
|
| 112 | {
|
| 113 | $val = $this->_protect_identifiers($val);
|
| 114 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 115 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 116 |
|
| 117 | if ($val != '')
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 118 | {
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 119 | $this->ar_select[] = $val;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 120 | if ($this->ar_caching === TRUE)
|
| 121 | {
|
| 122 | $this->ar_cache_select[] = $val;
|
| 123 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 124 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 125 | }
|
| 126 | return $this;
|
| 127 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 128 |
|
| 129 | // --------------------------------------------------------------------
|
| 130 |
|
| 131 | /**
|
| 132 | * Select Max
|
| 133 | *
|
| 134 | * Generates a SELECT MAX(field) portion of a query
|
| 135 | *
|
| 136 | * @access public
|
| 137 | * @param string the field
|
| 138 | * @param string an alias
|
| 139 | * @return object
|
| 140 | */
|
| 141 | function select_max($select = '', $alias='')
|
| 142 | {
|
| 143 | if (!is_string($select) || $select == '')
|
| 144 | {
|
| 145 | $this->display_error('db_invalid_query');
|
| 146 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 147 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 148 | $alias = ($alias != '') ? $alias : $select;
|
| 149 |
|
| 150 | $sql = 'MAX('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
|
| 151 |
|
| 152 | $this->ar_select[] = $sql;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 153 | if ($this->ar_caching === TRUE)
|
| 154 | {
|
| 155 | $this->ar_cache_select[] = $sql;
|
| 156 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 157 |
|
| 158 | return $this;
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 159 | }
|
| 160 |
|
| 161 | // --------------------------------------------------------------------
|
| 162 |
|
| 163 | /**
|
| 164 | * Select Min
|
| 165 | *
|
| 166 | * Generates a SELECT MIN(field) portion of a query
|
| 167 | *
|
| 168 | * @access public
|
| 169 | * @param string the field
|
| 170 | * @param string an alias
|
| 171 | * @return object
|
| 172 | */
|
| 173 | function select_min($select = '', $alias='')
|
| 174 | {
|
| 175 | if (!is_string($select) || $select == '')
|
| 176 | {
|
| 177 | $this->display_error('db_invalid_query');
|
| 178 | }
|
| 179 |
|
| 180 | $alias = ($alias != '') ? $alias : $select;
|
| 181 |
|
| 182 | $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
|
| 183 |
|
| 184 | $this->ar_select[] = $sql;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 185 | if ($this->ar_caching === TRUE)
|
| 186 | {
|
| 187 | $this->ar_cache_select[] = $sql;
|
| 188 | }
|
| 189 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 190 | return $this;
|
| 191 | }
|
| 192 |
|
| 193 | // --------------------------------------------------------------------
|
| 194 |
|
| 195 | /**
|
| 196 | * Select Average
|
| 197 | *
|
| 198 | * Generates a SELECT AVG(field) portion of a query
|
| 199 | *
|
| 200 | * @access public
|
| 201 | * @param string the field
|
| 202 | * @param string an alias
|
| 203 | * @return object
|
| 204 | */
|
| 205 | function select_avg($select = '', $alias='')
|
| 206 | {
|
| 207 | if (!is_string($select) || $select == '')
|
| 208 | {
|
| 209 | $this->display_error('db_invalid_query');
|
| 210 | }
|
| 211 |
|
| 212 | $alias = ($alias != '') ? $alias : $select;
|
| 213 |
|
| 214 | $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
|
| 215 |
|
| 216 | $this->ar_select[] = $sql;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 217 | if ($this->ar_caching === TRUE)
|
| 218 | {
|
| 219 | $this->ar_cache_select[] = $sql;
|
| 220 | }
|
| 221 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 222 | return $this;
|
| 223 | }
|
| 224 |
|
| 225 | // --------------------------------------------------------------------
|
| 226 |
|
| 227 | /**
|
| 228 | * Select Sum
|
| 229 | *
|
| 230 | * Generates a SELECT SUM(field) portion of a query
|
| 231 | *
|
| 232 | * @access public
|
| 233 | * @param string the field
|
| 234 | * @param string an alias
|
| 235 | * @return object
|
| 236 | */
|
| 237 | function select_sum($select = '', $alias='')
|
| 238 | {
|
| 239 | if (!is_string($select) || $select == '')
|
| 240 | {
|
| 241 | $this->display_error('db_invalid_query');
|
| 242 | }
|
| 243 |
|
| 244 | $alias = ($alias != '') ? $alias : $select;
|
| 245 |
|
| 246 | $sql = 'SUM('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
|
| 247 |
|
| 248 | $this->ar_select[] = $sql;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 249 | if ($this->ar_caching === TRUE)
|
| 250 | {
|
| 251 | $this->ar_cache_select[] = $sql;
|
| 252 | }
|
| 253 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 254 | return $this;
|
| 255 | }
|
| 256 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 257 | // --------------------------------------------------------------------
|
| 258 |
|
| 259 | /**
|
| 260 | * DISTINCT
|
| 261 | *
|
| 262 | * Sets a flag which tells the query string compiler to add DISTINCT
|
| 263 | *
|
| 264 | * @access public
|
| 265 | * @param bool
|
| 266 | * @return object
|
| 267 | */
|
| 268 | function distinct($val = TRUE)
|
| 269 | {
|
| 270 | $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
|
| 271 | return $this;
|
| 272 | }
|
| 273 |
|
| 274 | // --------------------------------------------------------------------
|
| 275 |
|
| 276 | /**
|
| 277 | * From
|
| 278 | *
|
| 279 | * Generates the FROM portion of the query
|
| 280 | *
|
| 281 | * @access public
|
| 282 | * @param mixed can be a string or array
|
| 283 | * @return object
|
| 284 | */
|
| 285 | function from($from)
|
| 286 | {
|
| 287 | foreach ((array)$from as $val)
|
| 288 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 289 | $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val));
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 290 | if ($this->ar_caching === TRUE)
|
| 291 | {
|
Derek Allard | 9a4d1da | 2008-02-25 14:18:38 +0000 | [diff] [blame] | 292 | $this->ar_cache_from[] = $this->_protect_identifiers($this->_track_aliases($val));
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 293 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 294 | }
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 295 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 296 | return $this;
|
| 297 | }
|
| 298 |
|
| 299 | // --------------------------------------------------------------------
|
| 300 |
|
| 301 | /**
|
| 302 | * Join
|
| 303 | *
|
| 304 | * Generates the JOIN portion of the query
|
| 305 | *
|
| 306 | * @access public
|
| 307 | * @param string
|
| 308 | * @param string the join condition
|
| 309 | * @param string the type of join
|
| 310 | * @return object
|
| 311 | */
|
| 312 | function join($table, $cond, $type = '')
|
| 313 | {
|
| 314 | if ($type != '')
|
| 315 | {
|
| 316 | $type = strtoupper(trim($type));
|
| 317 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 318 | if (! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 319 | {
|
| 320 | $type = '';
|
| 321 | }
|
| 322 | else
|
| 323 | {
|
| 324 | $type .= ' ';
|
| 325 | }
|
| 326 | }
|
| 327 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 328 | // If a DB prefix is used we might need to add it to the column names
|
| 329 | if ($this->dbprefix)
|
| 330 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 331 | $this->_track_aliases($table);
|
| 332 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 333 | // First we remove any existing prefixes in the condition to avoid duplicates
|
| 334 | $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond);
|
| 335 |
|
| 336 | // Next we add the prefixes to the condition
|
| 337 | $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond);
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 338 | }
|
| 339 |
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 340 | $join = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond;
|
| 341 |
|
| 342 | $this->ar_join[] = $join;
|
| 343 | if ($this->ar_caching === TRUE)
|
| 344 | {
|
| 345 | $this->ar_cache_join[] = $join;
|
| 346 | }
|
| 347 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 348 | return $this;
|
| 349 | }
|
| 350 |
|
| 351 | // --------------------------------------------------------------------
|
| 352 |
|
| 353 | /**
|
| 354 | * Where
|
| 355 | *
|
| 356 | * Generates the WHERE portion of the query. Separates
|
| 357 | * multiple calls with AND
|
| 358 | *
|
| 359 | * @access public
|
| 360 | * @param mixed
|
| 361 | * @param mixed
|
| 362 | * @return object
|
| 363 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 364 | function where($key, $value = NULL, $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 365 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 366 | return $this->_where($key, $value, 'AND ', $escape);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 367 | }
|
| 368 |
|
| 369 | // --------------------------------------------------------------------
|
| 370 |
|
| 371 | /**
|
| 372 | * OR Where
|
| 373 | *
|
| 374 | * Generates the WHERE portion of the query. Separates
|
| 375 | * multiple calls with OR
|
| 376 | *
|
| 377 | * @access public
|
| 378 | * @param mixed
|
| 379 | * @param mixed
|
| 380 | * @return object
|
| 381 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 382 | function or_where($key, $value = NULL, $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 383 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 384 | return $this->_where($key, $value, 'OR ', $escape);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 385 | }
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 386 |
|
| 387 | // --------------------------------------------------------------------
|
| 388 |
|
| 389 | /**
|
| 390 | * orwhere() is an alias of or_where()
|
| 391 | * this function is here for backwards compatibility, as
|
| 392 | * orwhere() has been deprecated
|
| 393 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 394 | function orwhere($key, $value = NULL, $escape = TRUE)
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 395 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 396 | return $this->or_where($key, $value, $escape);
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 397 | }
|
Derek Allard | 67b44ed | 2008-01-12 16:18:02 +0000 | [diff] [blame] | 398 |
|
| 399 | // --------------------------------------------------------------------
|
| 400 |
|
| 401 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 402 | * Where
|
| 403 | *
|
| 404 | * Called by where() or orwhere()
|
| 405 | *
|
| 406 | * @access private
|
| 407 | * @param mixed
|
| 408 | * @param mixed
|
| 409 | * @param string
|
| 410 | * @return object
|
| 411 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 412 | function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 413 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 414 | if (! is_array($key))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 415 | {
|
| 416 | $key = array($key => $value);
|
| 417 | }
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 418 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 419 | foreach ($key as $k => $v)
|
| 420 | {
|
| 421 | $prefix = (count($this->ar_where) == 0) ? '' : $type;
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 422 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 423 | if (! $this->_has_operator($k) && is_null($key[$k]))
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 424 | {
|
| 425 | // value appears not to have been set, assign the test to IS NULL
|
| 426 | $k .= ' IS NULL';
|
| 427 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 428 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 429 | if (! is_null($v))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 430 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 431 |
|
| 432 | if ($escape === TRUE)
|
| 433 | {
|
| 434 | // exception for "field<=" keys
|
| 435 | if ($this->_has_operator($k))
|
| 436 | {
|
| 437 | $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_protect_identifiers('$1'), $k);
|
| 438 | }
|
| 439 | else
|
| 440 | {
|
| 441 | $k = $this->_protect_identifiers($k);
|
| 442 | }
|
| 443 | }
|
| 444 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 445 | if (! $this->_has_operator($k))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 446 | {
|
| 447 | $k .= ' =';
|
| 448 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 449 |
|
Derek Allard | 16629b1 | 2008-04-06 19:58:20 +0000 | [diff] [blame] | 450 | if ($v !== '' AND $v !== NULL)
|
Derek Allard | 96863ce | 2008-04-06 19:20:17 +0000 | [diff] [blame] | 451 | {
|
| 452 | $v = ' '.$this->escape($v);
|
| 453 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 454 | }
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 455 | else
|
| 456 | {
|
Derek Allard | 16629b1 | 2008-04-06 19:58:20 +0000 | [diff] [blame] | 457 |
|
| 458 | if ($escape === TRUE)
|
| 459 | {
|
| 460 | $k = $this->_protect_identifiers($k, TRUE);
|
| 461 | }
|
| 462 |
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 463 | }
|
| 464 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 465 | $this->ar_where[] = $prefix.$k.$v;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 466 | if ($this->ar_caching === TRUE)
|
| 467 | {
|
| 468 | $this->ar_cache_where[] = $prefix.$k.$v;
|
| 469 | }
|
| 470 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 471 | }
|
| 472 | return $this;
|
| 473 | }
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 474 |
|
| 475 | // --------------------------------------------------------------------
|
| 476 |
|
| 477 | /**
|
| 478 | * Where_in
|
| 479 | *
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 480 | * Generates a WHERE field IN ('item', 'item') SQL query joined with
|
| 481 | * AND if appropriate
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 482 | *
|
| 483 | * @access public
|
| 484 | * @param string The field to search
|
| 485 | * @param array The values searched on
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 486 | * @return object
|
| 487 | */
|
| 488 | function where_in($key = NULL, $values = NULL)
|
| 489 | {
|
| 490 | return $this->_where_in($key, $values);
|
| 491 | }
|
| 492 |
|
| 493 | // --------------------------------------------------------------------
|
| 494 |
|
| 495 | /**
|
| 496 | * Where_in_or
|
| 497 | *
|
| 498 | * Generates a WHERE field IN ('item', 'item') SQL query joined with
|
| 499 | * OR if appropriate
|
| 500 | *
|
| 501 | * @access public
|
| 502 | * @param string The field to search
|
| 503 | * @param array The values searched on
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 504 | * @return object
|
| 505 | */
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 506 | function or_where_in($key = NULL, $values = NULL)
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 507 | {
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 508 | return $this->_where_in($key, $values, FALSE, 'OR ');
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 509 | }
|
| 510 |
|
| 511 | // --------------------------------------------------------------------
|
| 512 |
|
| 513 | /**
|
| 514 | * Where_not_in
|
| 515 | *
|
| 516 | * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
|
| 517 | * with AND if appropriate
|
| 518 | *
|
| 519 | * @access public
|
| 520 | * @param string The field to search
|
| 521 | * @param array The values searched on
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 522 | * @return object
|
| 523 | */
|
| 524 | function where_not_in($key = NULL, $values = NULL)
|
| 525 | {
|
| 526 | return $this->_where_in($key, $values, TRUE);
|
| 527 | }
|
| 528 |
|
| 529 | // --------------------------------------------------------------------
|
| 530 |
|
| 531 | /**
|
| 532 | * Where_not_in_or
|
| 533 | *
|
| 534 | * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
|
| 535 | * with OR if appropriate
|
| 536 | *
|
| 537 | * @access public
|
| 538 | * @param string The field to search
|
| 539 | * @param array The values searched on
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 540 | * @return object
|
| 541 | */
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 542 | function or_where_not_in($key = NULL, $values = NULL)
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 543 | {
|
Derek Jones | d007243 | 2008-05-07 22:06:51 +0000 | [diff] [blame] | 544 | return $this->_where_in($key, $values, TRUE, 'OR ');
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 545 | }
|
| 546 |
|
| 547 | // --------------------------------------------------------------------
|
| 548 |
|
| 549 | /**
|
| 550 | * Where_in
|
| 551 | *
|
| 552 | * Called by where_in, where_in_or, where_not_in, where_not_in_or
|
| 553 | *
|
| 554 | * @access public
|
| 555 | * @param string The field to search
|
| 556 | * @param array The values searched on
|
| 557 | * @param boolean If the statement whould be IN or NOT IN
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 558 | * @param string
|
| 559 | * @return object
|
| 560 | */
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 561 | function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 562 | {
|
| 563 | if ($key === NULL || !is_array($values))
|
| 564 | {
|
| 565 | return;
|
| 566 | }
|
| 567 |
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 568 | $not = ($not) ? ' NOT ' : '';
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 569 |
|
| 570 | foreach ($values as $value)
|
| 571 | {
|
| 572 | $this->ar_wherein[] = $this->escape($value);
|
| 573 | }
|
| 574 |
|
| 575 | $prefix = (count($this->ar_where) == 0) ? '' : $type;
|
| 576 |
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 577 | $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
|
| 578 |
|
| 579 | $this->ar_where[] = $where_in;
|
| 580 | if ($this->ar_caching === TRUE)
|
| 581 | {
|
| 582 | $this->ar_cache_where[] = $where_in;
|
| 583 | }
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 584 |
|
Derek Allard | 8f00021 | 2008-01-18 14:45:59 +0000 | [diff] [blame] | 585 | // reset the array for multiple calls
|
| 586 | $this->ar_wherein = array();
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 587 | return $this;
|
| 588 | }
|
| 589 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 590 | // --------------------------------------------------------------------
|
| 591 |
|
| 592 | /**
|
| 593 | * Like
|
| 594 | *
|
| 595 | * Generates a %LIKE% portion of the query. Separates
|
| 596 | * multiple calls with AND
|
| 597 | *
|
| 598 | * @access public
|
| 599 | * @param mixed
|
| 600 | * @param mixed
|
| 601 | * @return object
|
| 602 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 603 | function like($field, $match = '', $side = 'both')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 604 | {
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 605 | return $this->_like($field, $match, 'AND ', $side);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 606 | }
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 607 |
|
| 608 | // --------------------------------------------------------------------
|
| 609 |
|
| 610 | /**
|
| 611 | * Not Like
|
| 612 | *
|
| 613 | * Generates a NOT LIKE portion of the query. Separates
|
| 614 | * multiple calls with AND
|
| 615 | *
|
| 616 | * @access public
|
| 617 | * @param mixed
|
| 618 | * @param mixed
|
| 619 | * @return object
|
| 620 | */
|
| 621 | function not_like($field, $match = '', $side = 'both')
|
| 622 | {
|
| 623 | return $this->_like($field, $match, 'AND ', $side, ' NOT');
|
| 624 | }
|
| 625 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 626 | // --------------------------------------------------------------------
|
| 627 |
|
| 628 | /**
|
| 629 | * OR Like
|
| 630 | *
|
| 631 | * Generates a %LIKE% portion of the query. Separates
|
| 632 | * multiple calls with OR
|
| 633 | *
|
| 634 | * @access public
|
| 635 | * @param mixed
|
| 636 | * @param mixed
|
| 637 | * @return object
|
| 638 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 639 | function or_like($field, $match = '', $side = 'both')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 640 | {
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 641 | return $this->_like($field, $match, 'OR ', $side);
|
| 642 | }
|
| 643 |
|
| 644 | // --------------------------------------------------------------------
|
| 645 |
|
| 646 | /**
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 647 | * OR Not Like
|
| 648 | *
|
| 649 | * Generates a NOT LIKE portion of the query. Separates
|
| 650 | * multiple calls with OR
|
| 651 | *
|
| 652 | * @access public
|
| 653 | * @param mixed
|
| 654 | * @param mixed
|
| 655 | * @return object
|
| 656 | */
|
| 657 | function or_not_like($field, $match = '', $side = 'both')
|
| 658 | {
|
| 659 | return $this->_like($field, $match, 'OR ', $side, 'NOT ');
|
| 660 | }
|
| 661 |
|
| 662 | // --------------------------------------------------------------------
|
| 663 |
|
| 664 | /**
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 665 | * orlike() is an alias of or_like()
|
| 666 | * this function is here for backwards compatibility, as
|
| 667 | * orlike() has been deprecated
|
| 668 | */
|
| 669 | function orlike($field, $match = '', $side = 'both')
|
| 670 | {
|
Derek Allard | 4a310b7 | 2008-01-30 21:32:47 +0000 | [diff] [blame] | 671 | return $this->or_like($field, $match, $side);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 672 | }
|
| 673 |
|
| 674 | // --------------------------------------------------------------------
|
| 675 |
|
| 676 | /**
|
| 677 | * Like
|
| 678 | *
|
| 679 | * Called by like() or orlike()
|
| 680 | *
|
| 681 | * @access private
|
| 682 | * @param mixed
|
| 683 | * @param mixed
|
| 684 | * @param string
|
| 685 | * @return object
|
| 686 | */
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 687 | function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 688 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 689 | if (! is_array($field))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 690 | {
|
| 691 | $field = array($field => $match);
|
| 692 | }
|
| 693 |
|
| 694 | foreach ($field as $k => $v)
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 695 | {
|
| 696 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 697 | $k = $this->_protect_identifiers($k);
|
| 698 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 699 | $prefix = (count($this->ar_like) == 0) ? '' : $type;
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 700 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 701 | $v = $this->escape_str($v);
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 702 |
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 703 | if ($side == 'before')
|
| 704 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 705 | $like_statement = $prefix." $k $not LIKE '%{$v}'";
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 706 | }
|
| 707 | elseif ($side == 'after')
|
| 708 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 709 | $like_statement = $prefix." $k $not LIKE '{$v}%'";
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 710 | }
|
| 711 | else
|
| 712 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 713 | $like_statement = $prefix." $k $not LIKE '%{$v}%'";
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 714 | }
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 715 |
|
| 716 | $this->ar_like[] = $like_statement;
|
| 717 | if ($this->ar_caching === TRUE)
|
| 718 | {
|
| 719 | $this->ar_cache_like[] = $like_statement;
|
| 720 | }
|
| 721 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 722 | }
|
| 723 | return $this;
|
| 724 | }
|
| 725 |
|
| 726 | // --------------------------------------------------------------------
|
| 727 |
|
| 728 | /**
|
| 729 | * GROUP BY
|
| 730 | *
|
| 731 | * @access public
|
| 732 | * @param string
|
| 733 | * @return object
|
| 734 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 735 | function group_by($by)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 736 | {
|
| 737 | if (is_string($by))
|
| 738 | {
|
| 739 | $by = explode(',', $by);
|
| 740 | }
|
| 741 |
|
| 742 | foreach ($by as $val)
|
| 743 | {
|
| 744 | $val = trim($val);
|
| 745 |
|
| 746 | if ($val != '')
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 747 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 748 | $this->ar_groupby[] = $this->_protect_identifiers($val);
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 749 | if ($this->ar_caching === TRUE)
|
| 750 | {
|
| 751 | $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
|
| 752 | }
|
| 753 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 754 | }
|
| 755 | return $this;
|
| 756 | }
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 757 |
|
| 758 | // --------------------------------------------------------------------
|
| 759 |
|
| 760 | /**
|
| 761 | * groupby() is an alias of group_by()
|
| 762 | * this function is here for backwards compatibility, as
|
| 763 | * groupby() has been deprecated
|
| 764 | */
|
| 765 | function groupby($by)
|
| 766 | {
|
| 767 | return $this->group_by($by);
|
| 768 | }
|
| 769 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 770 | // --------------------------------------------------------------------
|
| 771 |
|
| 772 | /**
|
| 773 | * Sets the HAVING value
|
| 774 | *
|
| 775 | * Separates multiple calls with AND
|
| 776 | *
|
| 777 | * @access public
|
| 778 | * @param string
|
| 779 | * @param string
|
| 780 | * @return object
|
| 781 | */
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 782 | function having($key, $value = '', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 783 | {
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 784 | return $this->_having($key, $value, 'AND ', $escape);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 785 | }
|
Derek Allard | 43e8cbf | 2008-03-01 23:14:43 +0000 | [diff] [blame] | 786 |
|
| 787 | // --------------------------------------------------------------------
|
| 788 |
|
| 789 | /**
|
| 790 | * orhaving() is an alias of or_having()
|
| 791 | * this function is here for backwards compatibility, as
|
| 792 | * orhaving() has been deprecated
|
| 793 | */
|
| 794 |
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 795 | function orhaving($key, $value = '', $escape = TRUE)
|
Derek Allard | 43e8cbf | 2008-03-01 23:14:43 +0000 | [diff] [blame] | 796 | {
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 797 | return $this->or_having($key, $value = '', $escape);
|
Derek Allard | 43e8cbf | 2008-03-01 23:14:43 +0000 | [diff] [blame] | 798 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 799 | // --------------------------------------------------------------------
|
| 800 |
|
| 801 | /**
|
| 802 | * Sets the OR HAVING value
|
| 803 | *
|
| 804 | * Separates multiple calls with OR
|
| 805 | *
|
| 806 | * @access public
|
| 807 | * @param string
|
| 808 | * @param string
|
| 809 | * @return object
|
| 810 | */
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 811 | function or_having($key, $value = '', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 812 | {
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 813 | return $this->_having($key, $value, 'OR ', $escape);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 814 | }
|
| 815 |
|
| 816 | // --------------------------------------------------------------------
|
| 817 |
|
| 818 | /**
|
| 819 | * Sets the HAVING values
|
| 820 | *
|
| 821 | * Called by having() or orhaving()
|
| 822 | *
|
| 823 | * @access private
|
| 824 | * @param string
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 825 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 826 | * @param string
|
| 827 | * @return object
|
| 828 | */
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 829 | function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 830 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 831 | if (! is_array($key))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 832 | {
|
| 833 | $key = array($key => $value);
|
| 834 | }
|
| 835 |
|
| 836 | foreach ($key as $k => $v)
|
| 837 | {
|
| 838 | $prefix = (count($this->ar_having) == 0) ? '' : $type;
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 839 |
|
| 840 | if ($escape === TRUE)
|
| 841 | {
|
| 842 | $k = $this->_protect_identifiers($k);
|
| 843 | }
|
| 844 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 845 |
|
| 846 | if ($v != '')
|
| 847 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 848 | $v = ' '.$this->escape_str($v);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 849 | }
|
| 850 |
|
| 851 | $this->ar_having[] = $prefix.$k.$v;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 852 | if ($this->ar_caching === TRUE)
|
| 853 | {
|
| 854 | $this->ar_cache_having[] = $prefix.$k.$v;
|
| 855 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 856 | }
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 857 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 858 | return $this;
|
| 859 | }
|
| 860 |
|
| 861 | // --------------------------------------------------------------------
|
| 862 |
|
| 863 | /**
|
| 864 | * Sets the ORDER BY value
|
| 865 | *
|
| 866 | * @access public
|
| 867 | * @param string
|
| 868 | * @param string direction: asc or desc
|
| 869 | * @return object
|
| 870 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 871 | function order_by($orderby, $direction = '')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 872 | {
|
Derek Allard | 6ddb5a1 | 2007-12-18 17:22:50 +0000 | [diff] [blame] | 873 | if (strtolower($direction) == 'random')
|
| 874 | {
|
| 875 | $orderby = ''; // Random results want or don't need a field name
|
| 876 | $direction = $this->_random_keyword;
|
| 877 | }
|
| 878 | elseif (trim($direction) != '')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 879 | {
|
Derek Allard | 9278249 | 2007-08-10 11:26:01 +0000 | [diff] [blame] | 880 | $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 881 | }
|
| 882 |
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 883 | $orderby_statement = $this->_protect_identifiers($orderby, TRUE).$direction;
|
| 884 |
|
| 885 | $this->ar_orderby[] = $orderby_statement;
|
| 886 | if ($this->ar_caching === TRUE)
|
| 887 | {
|
| 888 | $this->ar_cache_orderby[] = $orderby_statement;
|
| 889 | }
|
| 890 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 891 | return $this;
|
| 892 | }
|
Derek Allard | 6ddb5a1 | 2007-12-18 17:22:50 +0000 | [diff] [blame] | 893 |
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 894 | // --------------------------------------------------------------------
|
| 895 |
|
| 896 | /**
|
| 897 | * orderby() is an alias of order_by()
|
| 898 | * this function is here for backwards compatibility, as
|
| 899 | * orderby() has been deprecated
|
| 900 | */
|
| 901 | function orderby($orderby, $direction = '')
|
| 902 | {
|
| 903 | return $this->order_by($orderby, $direction);
|
| 904 | }
|
Derek Allard | 6ddb5a1 | 2007-12-18 17:22:50 +0000 | [diff] [blame] | 905 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 906 | // --------------------------------------------------------------------
|
| 907 |
|
| 908 | /**
|
| 909 | * Sets the LIMIT value
|
| 910 | *
|
| 911 | * @access public
|
| 912 | * @param integer the limit value
|
| 913 | * @param integer the offset value
|
| 914 | * @return object
|
| 915 | */
|
| 916 | function limit($value, $offset = '')
|
| 917 | {
|
| 918 | $this->ar_limit = $value;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 919 | if ($this->ar_caching === TRUE)
|
| 920 | {
|
| 921 | $this->ar_cache_limit[] = $value;
|
| 922 | }
|
| 923 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 924 | if ($offset != '')
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 925 | {
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 926 | $this->ar_offset = $offset;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 927 | if ($this->ar_caching === TRUE)
|
| 928 | {
|
| 929 | $this->ar_cache_offset[] = $offset;
|
| 930 | }
|
| 931 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 932 |
|
| 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 Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 945 | function offset($offset)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 946 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 947 | $this->ar_offset = $offset;
|
| 948 | if ($this->ar_caching === TRUE)
|
| 949 | {
|
| 950 | $this->ar_cache_offset[] = $offset;
|
| 951 | }
|
| 952 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 953 | return $this;
|
| 954 | }
|
| 955 |
|
| 956 | // --------------------------------------------------------------------
|
| 957 |
|
| 958 | /**
|
| 959 | * The "set" function. Allows key/value pairs to be set for inserting or updating
|
| 960 | *
|
| 961 | * @access public
|
| 962 | * @param mixed
|
| 963 | * @param string
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 964 | * @param boolean
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 965 | * @return object
|
| 966 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 967 | function set($key, $value = '', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 968 | {
|
| 969 | $key = $this->_object_to_array($key);
|
| 970 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 971 | if (! is_array($key))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 972 | {
|
| 973 | $key = array($key => $value);
|
| 974 | }
|
| 975 |
|
| 976 | foreach ($key as $k => $v)
|
| 977 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 978 | if ($escape === FALSE)
|
| 979 | {
|
| 980 | $this->ar_set[$this->_protect_identifiers($k)] = $v;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 981 | if ($this->ar_caching === TRUE)
|
| 982 | {
|
| 983 | $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v;
|
| 984 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 985 | }
|
| 986 | else
|
| 987 | {
|
| 988 | $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 989 | if ($this->ar_caching === TRUE)
|
| 990 | {
|
| 991 | $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v);
|
| 992 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 993 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 994 | }
|
| 995 |
|
| 996 | return $this;
|
| 997 | }
|
| 998 |
|
| 999 | // --------------------------------------------------------------------
|
| 1000 |
|
| 1001 | /**
|
| 1002 | * Get
|
| 1003 | *
|
| 1004 | * Compiles the select statement based on the other functions called
|
| 1005 | * and runs the query
|
| 1006 | *
|
| 1007 | * @access public
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1008 | * @param string the table
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1009 | * @param string the limit clause
|
| 1010 | * @param string the offset clause
|
| 1011 | * @return object
|
| 1012 | */
|
| 1013 | function get($table = '', $limit = null, $offset = null)
|
| 1014 | {
|
| 1015 | if ($table != '')
|
| 1016 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1017 | $this->_track_aliases($table);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1018 | $this->from($table);
|
| 1019 | }
|
| 1020 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1021 | if (! is_null($limit))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1022 | {
|
| 1023 | $this->limit($limit, $offset);
|
| 1024 | }
|
| 1025 |
|
| 1026 | $sql = $this->_compile_select();
|
| 1027 |
|
| 1028 | $result = $this->query($sql);
|
| 1029 | $this->_reset_select();
|
| 1030 | return $result;
|
| 1031 | }
|
| 1032 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1033 | /**
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1034 | * "Count All Results" query
|
| 1035 | *
|
| 1036 | * Generates a platform-specific query string that counts all records
|
| 1037 | * returned by an Active Record query.
|
| 1038 | *
|
| 1039 | * @access public
|
| 1040 | * @param string
|
| 1041 | * @return string
|
| 1042 | */
|
| 1043 | function count_all_results($table = '')
|
| 1044 | {
|
| 1045 | if ($table != '')
|
| 1046 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1047 | $this->_track_aliases($table);
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1048 | $this->from($table);
|
| 1049 | }
|
| 1050 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1051 | $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1052 |
|
| 1053 | $query = $this->query($sql);
|
| 1054 | $this->_reset_select();
|
| 1055 |
|
| 1056 | if ($query->num_rows() == 0)
|
| 1057 | {
|
| 1058 | return '0';
|
| 1059 | }
|
| 1060 |
|
| 1061 | $row = $query->row();
|
| 1062 | return $row->numrows;
|
| 1063 | }
|
| 1064 |
|
| 1065 | // --------------------------------------------------------------------
|
| 1066 |
|
| 1067 | /**
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 1068 | * Get_Where
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1069 | *
|
| 1070 | * Allows the where clause, limit and offset to be added directly
|
| 1071 | *
|
| 1072 | * @access public
|
| 1073 | * @param string the where clause
|
| 1074 | * @param string the limit clause
|
| 1075 | * @param string the offset clause
|
| 1076 | * @return object
|
| 1077 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 1078 | function get_where($table = '', $where = null, $limit = null, $offset = null)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1079 | {
|
| 1080 | if ($table != '')
|
| 1081 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1082 | $this->_track_aliases($table);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1083 | $this->from($table);
|
| 1084 | }
|
| 1085 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1086 | if (! is_null($where))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1087 | {
|
| 1088 | $this->where($where);
|
| 1089 | }
|
| 1090 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1091 | if (! is_null($limit))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1092 | {
|
| 1093 | $this->limit($limit, $offset);
|
| 1094 | }
|
| 1095 |
|
| 1096 | $sql = $this->_compile_select();
|
| 1097 |
|
| 1098 | $result = $this->query($sql);
|
| 1099 | $this->_reset_select();
|
| 1100 | return $result;
|
| 1101 | }
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 1102 |
|
| 1103 | // --------------------------------------------------------------------
|
| 1104 |
|
| 1105 | /**
|
| 1106 | * getwhere() is an alias of get_where()
|
| 1107 | * this function is here for backwards compatibility, as
|
| 1108 | * getwhere() has been deprecated
|
| 1109 | */
|
| 1110 | function getwhere($table = '', $where = null, $limit = null, $offset = null)
|
| 1111 | {
|
| 1112 | return $this->get_where($table, $where, $limit, $offset);
|
| 1113 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1114 |
|
| 1115 | // --------------------------------------------------------------------
|
| 1116 |
|
| 1117 | /**
|
| 1118 | * Insert
|
| 1119 | *
|
| 1120 | * Compiles an insert string and runs the query
|
| 1121 | *
|
| 1122 | * @access public
|
| 1123 | * @param string the table to retrieve the results from
|
| 1124 | * @param array an associative array of insert values
|
| 1125 | * @return object
|
| 1126 | */
|
| 1127 | function insert($table = '', $set = NULL)
|
| 1128 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1129 | if (! is_null($set))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1130 | {
|
| 1131 | $this->set($set);
|
| 1132 | }
|
| 1133 |
|
| 1134 | if (count($this->ar_set) == 0)
|
| 1135 | {
|
| 1136 | if ($this->db_debug)
|
| 1137 | {
|
| 1138 | return $this->display_error('db_must_use_set');
|
| 1139 | }
|
| 1140 | return FALSE;
|
| 1141 | }
|
| 1142 |
|
| 1143 | if ($table == '')
|
| 1144 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1145 | if (! isset($this->ar_from[0]))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1146 | {
|
| 1147 | if ($this->db_debug)
|
| 1148 | {
|
| 1149 | return $this->display_error('db_must_set_table');
|
| 1150 | }
|
| 1151 | return FALSE;
|
| 1152 | }
|
| 1153 |
|
| 1154 | $table = $this->ar_from[0];
|
| 1155 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1156 |
|
| 1157 | $sql = $this->_insert($this->_protect_identifiers($this->dbprefix.$table), array_keys($this->ar_set), array_values($this->ar_set));
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1158 |
|
| 1159 | $this->_reset_write();
|
| 1160 | return $this->query($sql);
|
| 1161 | }
|
| 1162 |
|
| 1163 | // --------------------------------------------------------------------
|
| 1164 |
|
| 1165 | /**
|
| 1166 | * Update
|
| 1167 | *
|
| 1168 | * Compiles an update string and runs the query
|
| 1169 | *
|
| 1170 | * @access public
|
| 1171 | * @param string the table to retrieve the results from
|
| 1172 | * @param array an associative array of update values
|
| 1173 | * @param mixed the where clause
|
| 1174 | * @return object
|
| 1175 | */
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1176 | function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1177 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1178 | if (! is_null($set))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1179 | {
|
| 1180 | $this->set($set);
|
| 1181 | }
|
| 1182 |
|
| 1183 | if (count($this->ar_set) == 0)
|
| 1184 | {
|
| 1185 | if ($this->db_debug)
|
| 1186 | {
|
| 1187 | return $this->display_error('db_must_use_set');
|
| 1188 | }
|
| 1189 | return FALSE;
|
| 1190 | }
|
| 1191 |
|
| 1192 | if ($table == '')
|
| 1193 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1194 | if (! isset($this->ar_from[0]))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1195 | {
|
| 1196 | if ($this->db_debug)
|
| 1197 | {
|
| 1198 | return $this->display_error('db_must_set_table');
|
| 1199 | }
|
| 1200 | return FALSE;
|
| 1201 | }
|
| 1202 |
|
| 1203 | $table = $this->ar_from[0];
|
| 1204 | }
|
| 1205 |
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1206 | if ($where != NULL)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1207 | {
|
| 1208 | $this->where($where);
|
| 1209 | }
|
Derek Allard | da6d240 | 2007-12-19 14:49:29 +0000 | [diff] [blame] | 1210 |
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1211 | if ($limit != NULL)
|
Derek Allard | da6d240 | 2007-12-19 14:49:29 +0000 | [diff] [blame] | 1212 | {
|
| 1213 | $this->limit($limit);
|
| 1214 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1215 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1216 | $sql = $this->_update($this->_protect_identifiers($this->dbprefix.$table), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1217 |
|
| 1218 | $this->_reset_write();
|
| 1219 | return $this->query($sql);
|
| 1220 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1221 |
|
| 1222 | // --------------------------------------------------------------------
|
| 1223 |
|
| 1224 | /**
|
| 1225 | * Empty Table
|
| 1226 | *
|
| 1227 | * Compiles a delete string and runs "DELETE FROM table"
|
| 1228 | *
|
| 1229 | * @access public
|
| 1230 | * @param string the table to empty
|
| 1231 | * @return object
|
| 1232 | */
|
| 1233 | function empty_table($table = '')
|
| 1234 | {
|
| 1235 | if ($table == '')
|
| 1236 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1237 | if (! isset($this->ar_from[0]))
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1238 | {
|
| 1239 | if ($this->db_debug)
|
| 1240 | {
|
| 1241 | return $this->display_error('db_must_set_table');
|
| 1242 | }
|
| 1243 | return FALSE;
|
| 1244 | }
|
| 1245 |
|
| 1246 | $table = $this->ar_from[0];
|
| 1247 | }
|
| 1248 | else
|
| 1249 | {
|
| 1250 | $table = $this->_protect_identifiers($this->dbprefix.$table);
|
| 1251 | }
|
| 1252 |
|
| 1253 |
|
| 1254 | $sql = $this->_delete($table);
|
| 1255 |
|
| 1256 | $this->_reset_write();
|
| 1257 |
|
| 1258 | return $this->query($sql);
|
| 1259 | }
|
| 1260 |
|
| 1261 | // --------------------------------------------------------------------
|
| 1262 |
|
| 1263 | /**
|
| 1264 | * Truncate
|
| 1265 | *
|
| 1266 | * Compiles a truncate string and runs the query
|
| 1267 | * If the database does not support the truncate() command
|
| 1268 | * This function maps to "DELETE FROM table"
|
| 1269 | *
|
| 1270 | * @access public
|
| 1271 | * @param string the table to truncate
|
| 1272 | * @return object
|
| 1273 | */
|
| 1274 | function truncate($table = '')
|
| 1275 | {
|
| 1276 | if ($table == '')
|
| 1277 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1278 | if (! isset($this->ar_from[0]))
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1279 | {
|
| 1280 | if ($this->db_debug)
|
| 1281 | {
|
| 1282 | return $this->display_error('db_must_set_table');
|
| 1283 | }
|
| 1284 | return FALSE;
|
| 1285 | }
|
| 1286 |
|
| 1287 | $table = $this->ar_from[0];
|
| 1288 | }
|
| 1289 | else
|
| 1290 | {
|
| 1291 | $table = $this->_protect_identifiers($this->dbprefix.$table);
|
| 1292 | }
|
| 1293 |
|
| 1294 |
|
| 1295 | $sql = $this->_truncate($table);
|
| 1296 |
|
| 1297 | $this->_reset_write();
|
| 1298 |
|
| 1299 | return $this->query($sql);
|
| 1300 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1301 |
|
| 1302 | // --------------------------------------------------------------------
|
| 1303 |
|
| 1304 | /**
|
| 1305 | * Delete
|
| 1306 | *
|
| 1307 | * Compiles a delete string and runs the query
|
| 1308 | *
|
| 1309 | * @access public
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1310 | * @param mixed the table(s) to delete from. String or array
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1311 | * @param mixed the where clause
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1312 | * @param mixed the limit clause
|
| 1313 | * @param boolean
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1314 | * @return object
|
| 1315 | */
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1316 | function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1317 | {
|
| 1318 | if ($table == '')
|
| 1319 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1320 | if (! isset($this->ar_from[0]))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1321 | {
|
| 1322 | if ($this->db_debug)
|
| 1323 | {
|
| 1324 | return $this->display_error('db_must_set_table');
|
| 1325 | }
|
| 1326 | return FALSE;
|
| 1327 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1328 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1329 | $table = $this->ar_from[0];
|
| 1330 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1331 | elseif (is_array($table))
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1332 | {
|
| 1333 | foreach($table as $single_table)
|
| 1334 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1335 | $this->delete($single_table, $where, $limit, FALSE);
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1336 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1337 |
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1338 | $this->_reset_write();
|
| 1339 | return;
|
| 1340 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1341 | else
|
| 1342 | {
|
| 1343 | $table = $this->_protect_identifiers($this->dbprefix.$table);
|
| 1344 | }
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1345 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1346 | if ($where != '')
|
| 1347 | {
|
| 1348 | $this->where($where);
|
| 1349 | }
|
| 1350 |
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1351 | if ($limit != NULL)
|
| 1352 | {
|
| 1353 | $this->limit($limit);
|
| 1354 | }
|
| 1355 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1356 | if (count($this->ar_where) == 0 && count($this->ar_like) == 0)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1357 | {
|
| 1358 | if ($this->db_debug)
|
| 1359 | {
|
| 1360 | return $this->display_error('db_del_must_use_where');
|
| 1361 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1362 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1363 | return FALSE;
|
| 1364 | }
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1365 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1366 | $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1367 |
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1368 | if ($reset_data)
|
| 1369 | {
|
| 1370 | $this->_reset_write();
|
| 1371 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1372 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1373 | return $this->query($sql);
|
| 1374 | }
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 1375 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1376 | // --------------------------------------------------------------------
|
| 1377 |
|
| 1378 | /**
|
| 1379 | * Use Table - DEPRECATED
|
| 1380 | *
|
| 1381 | * @deprecated use $this->db->from instead
|
| 1382 | */
|
| 1383 | function use_table($table)
|
| 1384 | {
|
| 1385 | return $this->from($table);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1386 | }
|
| 1387 |
|
| 1388 | // --------------------------------------------------------------------
|
| 1389 |
|
| 1390 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1391 | * Tests whether the string has an SQL operator
|
| 1392 | *
|
| 1393 | * @access private
|
| 1394 | * @param string
|
| 1395 | * @return bool
|
| 1396 | */
|
| 1397 | function _has_operator($str)
|
| 1398 | {
|
| 1399 | $str = trim($str);
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1400 | if (! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1401 | {
|
| 1402 | return FALSE;
|
| 1403 | }
|
| 1404 |
|
| 1405 | return TRUE;
|
| 1406 | }
|
| 1407 |
|
| 1408 | // --------------------------------------------------------------------
|
| 1409 |
|
| 1410 | /**
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1411 | * Track Aliases
|
| 1412 | *
|
| 1413 | * Used to track SQL statements written with aliased tables.
|
| 1414 | *
|
| 1415 | * @access private
|
| 1416 | * @param string The table to inspect
|
| 1417 | * @return string
|
| 1418 | */
|
| 1419 | function _track_aliases($table)
|
| 1420 | {
|
| 1421 | // if a table alias is used we can recognize it by a space
|
| 1422 | if (strpos($table, " ") !== FALSE)
|
| 1423 | {
|
| 1424 | // if the alias is written with the AS keyowrd, get it out
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1425 | $table = preg_replace('/ AS /i', ' ', $table);
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1426 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1427 | $this->ar_aliased_tables[] = trim(strrchr($table, " "));
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1428 | }
|
| 1429 |
|
| 1430 | return $this->dbprefix.$table;
|
| 1431 | }
|
| 1432 |
|
| 1433 | // --------------------------------------------------------------------
|
| 1434 |
|
| 1435 | /**
|
| 1436 | * Filter Table Aliases
|
| 1437 | *
|
| 1438 | * Intelligently removes database prefixes from aliased tables
|
| 1439 | *
|
| 1440 | * @access private
|
| 1441 | * @param array An array of compiled SQL
|
| 1442 | * @return array Cleaned up statement with aliases accounted for
|
| 1443 | */
|
| 1444 | function _filter_table_aliases($statements)
|
| 1445 | {
|
Derek Allard | 8b2f19b | 2008-03-06 15:51:55 +0000 | [diff] [blame] | 1446 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1447 | foreach ($statements as $k => $v)
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1448 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1449 | foreach ($this->ar_aliased_tables as $table)
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1450 | {
|
Derek Allard | 8b2f19b | 2008-03-06 15:51:55 +0000 | [diff] [blame] | 1451 | $statements[$k] = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $statements[$k]); // makes `table.field`
|
| 1452 | $statements[$k] = str_replace($this->dbprefix.$table.'.', $table.'.', $statements[$k]);
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1453 | }
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1454 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1455 | return $statements;
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1456 | }
|
| 1457 |
|
| 1458 | // --------------------------------------------------------------------
|
| 1459 |
|
| 1460 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1461 | * Compile the SELECT statement
|
| 1462 | *
|
| 1463 | * Generates a query string based on which functions were used.
|
| 1464 | * Should not be called directly. The get() function calls it.
|
| 1465 | *
|
| 1466 | * @access private
|
| 1467 | * @return string
|
| 1468 | */
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1469 | function _compile_select($select_override = FALSE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1470 | {
|
Derek Allard | 7825526 | 2008-02-06 13:54:23 +0000 | [diff] [blame] | 1471 | $this->_merge_cache();
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1472 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1473 | $sql = (! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1474 |
|
Derek Allard | 5162fc7 | 2008-04-15 20:05:37 +0000 | [diff] [blame] | 1475 | $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select));
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1476 |
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1477 | if ($select_override !== FALSE)
|
| 1478 | {
|
| 1479 | $sql = $select_override;
|
| 1480 | }
|
| 1481 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1482 | if (count($this->ar_from) > 0)
|
| 1483 | {
|
| 1484 | $sql .= "\nFROM ";
|
Derek Jones | c6ad023 | 2008-01-29 18:44:54 +0000 | [diff] [blame] | 1485 | $sql .= $this->_from_tables($this->ar_from);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1486 | }
|
| 1487 |
|
| 1488 | if (count($this->ar_join) > 0)
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1489 | {
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1490 | $sql .= "\n";
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1491 |
|
| 1492 | // special consideration for table aliases
|
| 1493 | if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
|
| 1494 | {
|
| 1495 | $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join));
|
| 1496 | }
|
| 1497 | else
|
| 1498 | {
|
| 1499 | $sql .= implode("\n", $this->ar_join);
|
| 1500 | }
|
| 1501 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1502 | }
|
| 1503 |
|
| 1504 | if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
|
| 1505 | {
|
| 1506 | $sql .= "\nWHERE ";
|
| 1507 | }
|
| 1508 |
|
| 1509 | $sql .= implode("\n", $this->ar_where);
|
| 1510 |
|
| 1511 | if (count($this->ar_like) > 0)
|
| 1512 | {
|
| 1513 | if (count($this->ar_where) > 0)
|
| 1514 | {
|
| 1515 | $sql .= " AND ";
|
| 1516 | }
|
| 1517 |
|
| 1518 | $sql .= implode("\n", $this->ar_like);
|
| 1519 | }
|
| 1520 |
|
| 1521 | if (count($this->ar_groupby) > 0)
|
| 1522 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1523 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1524 | $sql .= "\nGROUP BY ";
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1525 |
|
| 1526 | // special consideration for table aliases
|
| 1527 | if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
|
| 1528 | {
|
| 1529 | $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby));
|
| 1530 | }
|
| 1531 | else
|
| 1532 | {
|
| 1533 | $sql .= implode(', ', $this->ar_groupby);
|
| 1534 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1535 | }
|
| 1536 |
|
| 1537 | if (count($this->ar_having) > 0)
|
| 1538 | {
|
| 1539 | $sql .= "\nHAVING ";
|
| 1540 | $sql .= implode("\n", $this->ar_having);
|
| 1541 | }
|
| 1542 |
|
| 1543 | if (count($this->ar_orderby) > 0)
|
| 1544 | {
|
| 1545 | $sql .= "\nORDER BY ";
|
| 1546 | $sql .= implode(', ', $this->ar_orderby);
|
| 1547 |
|
| 1548 | if ($this->ar_order !== FALSE)
|
| 1549 | {
|
| 1550 | $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
|
| 1551 | }
|
| 1552 | }
|
| 1553 |
|
| 1554 | if (is_numeric($this->ar_limit))
|
| 1555 | {
|
| 1556 | $sql .= "\n";
|
| 1557 | $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
|
| 1558 | }
|
| 1559 |
|
| 1560 | return $sql;
|
| 1561 | }
|
| 1562 |
|
| 1563 | // --------------------------------------------------------------------
|
| 1564 |
|
| 1565 | /**
|
| 1566 | * Object to Array
|
| 1567 | *
|
| 1568 | * Takes an object as input and converts the class variables to array key/vals
|
| 1569 | *
|
| 1570 | * @access public
|
| 1571 | * @param object
|
| 1572 | * @return array
|
| 1573 | */
|
| 1574 | function _object_to_array($object)
|
| 1575 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1576 | if (! is_object($object))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1577 | {
|
| 1578 | return $object;
|
| 1579 | }
|
| 1580 |
|
| 1581 | $array = array();
|
| 1582 | foreach (get_object_vars($object) as $key => $val)
|
| 1583 | {
|
Derek Allard | 848b776 | 2007-12-31 16:43:05 +0000 | [diff] [blame] | 1584 | // There are some built in keys we need to ignore for this conversion
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 1585 | if (! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table')
|
Derek Allard | 848b776 | 2007-12-31 16:43:05 +0000 | [diff] [blame] | 1586 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1587 | {
|
| 1588 | $array[$key] = $val;
|
| 1589 | }
|
| 1590 | }
|
| 1591 |
|
| 1592 | return $array;
|
| 1593 | }
|
| 1594 |
|
| 1595 | // --------------------------------------------------------------------
|
| 1596 |
|
| 1597 | /**
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1598 | * Start Cache
|
| 1599 | *
|
| 1600 | * Starts AR caching
|
| 1601 | *
|
| 1602 | * @access public
|
| 1603 | * @return void
|
| 1604 | */
|
| 1605 | function start_cache()
|
| 1606 | {
|
| 1607 | $this->ar_caching = TRUE;
|
| 1608 | }
|
| 1609 |
|
| 1610 | // --------------------------------------------------------------------
|
| 1611 |
|
| 1612 | /**
|
| 1613 | * Stop Cache
|
| 1614 | *
|
| 1615 | * Stops AR caching
|
| 1616 | *
|
| 1617 | * @access public
|
| 1618 | * @return void
|
| 1619 | */
|
| 1620 | function stop_cache()
|
| 1621 | {
|
| 1622 | $this->ar_caching = FALSE;
|
| 1623 | }
|
| 1624 |
|
| 1625 |
|
| 1626 | // --------------------------------------------------------------------
|
| 1627 |
|
| 1628 | /**
|
| 1629 | * Flush Cache
|
| 1630 | *
|
| 1631 | * Empties the AR cache
|
| 1632 | *
|
| 1633 | * @access public
|
| 1634 | * @return void
|
| 1635 | */
|
| 1636 | function flush_cache()
|
| 1637 | {
|
| 1638 | $ar_reset_items = array(
|
| 1639 | 'ar_cache_select' => array(),
|
| 1640 | 'ar_cache_from' => array(),
|
| 1641 | 'ar_cache_join' => array(),
|
| 1642 | 'ar_cache_where' => array(),
|
| 1643 | 'ar_cache_like' => array(),
|
| 1644 | 'ar_cache_groupby' => array(),
|
| 1645 | 'ar_cache_having' =>array(),
|
| 1646 | 'ar_cache_orderby' => array(),
|
| 1647 | 'ar_cache_set' => array()
|
| 1648 | );
|
| 1649 |
|
| 1650 | $this->_reset_run($ar_reset_items);
|
| 1651 | }
|
| 1652 |
|
| 1653 | // --------------------------------------------------------------------
|
| 1654 |
|
| 1655 | /**
|
| 1656 | * Merge Cache
|
| 1657 | *
|
| 1658 | * When called, this function merges any cached AR arrays with
|
| 1659 | * locally called ones.
|
| 1660 | *
|
| 1661 | * @access private
|
| 1662 | * @return void
|
| 1663 | */
|
| 1664 | function _merge_cache()
|
| 1665 | {
|
| 1666 | $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set');
|
| 1667 |
|
| 1668 | foreach ($ar_items as $ar_item)
|
| 1669 | {
|
| 1670 | $ar_cache_item = 'ar_cache_'.$ar_item;
|
| 1671 | $ar_item = 'ar_'.$ar_item;
|
| 1672 | $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item));
|
| 1673 | }
|
| 1674 | }
|
| 1675 |
|
| 1676 | // --------------------------------------------------------------------
|
| 1677 |
|
| 1678 | /**
|
| 1679 | * Resets the active record values. Called by the get() function
|
| 1680 | *
|
| 1681 | * @access private
|
| 1682 | * @param array An array of fields to reset
|
| 1683 | * @return void
|
| 1684 | */
|
| 1685 | function _reset_run($ar_reset_items)
|
| 1686 | {
|
| 1687 | foreach ($ar_reset_items as $item => $default_value)
|
| 1688 | {
|
| 1689 | if (!in_array($item, $this->ar_store_array))
|
| 1690 | {
|
| 1691 | $this->$item = $default_value;
|
| 1692 | }
|
| 1693 | }
|
| 1694 | }
|
| 1695 |
|
| 1696 | // --------------------------------------------------------------------
|
| 1697 |
|
| 1698 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1699 | * Resets the active record values. Called by the get() function
|
| 1700 | *
|
| 1701 | * @access private
|
| 1702 | * @return void
|
| 1703 | */
|
| 1704 | function _reset_select()
|
| 1705 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1706 | $ar_reset_items = array(
|
| 1707 | 'ar_select' => array(),
|
| 1708 | 'ar_from' => array(),
|
| 1709 | 'ar_join' => array(),
|
| 1710 | 'ar_where' => array(),
|
| 1711 | 'ar_like' => array(),
|
| 1712 | 'ar_groupby' => array(),
|
| 1713 | 'ar_having' => array(),
|
| 1714 | 'ar_orderby' => array(),
|
| 1715 | 'ar_wherein' => array(),
|
| 1716 | 'ar_aliased_tables' => array(),
|
| 1717 | 'ar_distinct' => FALSE,
|
| 1718 | 'ar_limit' => FALSE,
|
| 1719 | 'ar_offset' => FALSE,
|
| 1720 | 'ar_order' => FALSE,
|
| 1721 | );
|
| 1722 |
|
| 1723 | $this->_reset_run($ar_reset_items);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1724 | }
|
| 1725 |
|
| 1726 | // --------------------------------------------------------------------
|
| 1727 |
|
| 1728 | /**
|
| 1729 | * Resets the active record "write" values.
|
| 1730 | *
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1731 | * Called by the insert() update() and delete() functions
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1732 | *
|
| 1733 | * @access private
|
| 1734 | * @return void
|
| 1735 | */
|
| 1736 | function _reset_write()
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1737 | {
|
| 1738 | $ar_reset_items = array(
|
| 1739 | 'ar_set' => array(),
|
| 1740 | 'ar_from' => array(),
|
| 1741 | 'ar_where' => array(),
|
| 1742 | 'ar_like' => array(),
|
| 1743 | 'ar_orderby' => array(),
|
| 1744 | 'ar_limit' => FALSE,
|
| 1745 | 'ar_order' => FALSE
|
| 1746 | );
|
| 1747 |
|
| 1748 | $this->_reset_run($ar_reset_items);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1749 | }
|
| 1750 |
|
| 1751 | }
|