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 |
|
| 487 | * @return object
|
| 488 | */
|
| 489 | function where_in($key = NULL, $values = NULL)
|
| 490 | {
|
| 491 | return $this->_where_in($key, $values);
|
| 492 | }
|
| 493 |
|
| 494 | // --------------------------------------------------------------------
|
| 495 |
|
| 496 | /**
|
| 497 | * Where_in_or
|
| 498 | *
|
| 499 | * Generates a WHERE field IN ('item', 'item') SQL query joined with
|
| 500 | * OR if appropriate
|
| 501 | *
|
| 502 | * @access public
|
| 503 | * @param string The field to search
|
| 504 | * @param array The values searched on
|
| 505 |
|
| 506 | * @return object
|
| 507 | */
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 508 | function or_where_in($key = NULL, $values = NULL)
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 509 | {
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 510 | return $this->_where_in($key, $values, FALSE, 'OR ');
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 511 | }
|
| 512 |
|
| 513 | // --------------------------------------------------------------------
|
| 514 |
|
| 515 | /**
|
| 516 | * Where_not_in
|
| 517 | *
|
| 518 | * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
|
| 519 | * with AND if appropriate
|
| 520 | *
|
| 521 | * @access public
|
| 522 | * @param string The field to search
|
| 523 | * @param array The values searched on
|
| 524 |
|
| 525 | * @return object
|
| 526 | */
|
| 527 | function where_not_in($key = NULL, $values = NULL)
|
| 528 | {
|
| 529 | return $this->_where_in($key, $values, TRUE);
|
| 530 | }
|
| 531 |
|
| 532 | // --------------------------------------------------------------------
|
| 533 |
|
| 534 | /**
|
| 535 | * Where_not_in_or
|
| 536 | *
|
| 537 | * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
|
| 538 | * with OR if appropriate
|
| 539 | *
|
| 540 | * @access public
|
| 541 | * @param string The field to search
|
| 542 | * @param array The values searched on
|
| 543 |
|
| 544 | * @return object
|
| 545 | */
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 546 | function or_where_not_in($key = NULL, $values = NULL)
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 547 | {
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 548 | return $this->_where_in($key, $values, FALSE, 'OR ');
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 549 | }
|
| 550 |
|
| 551 | // --------------------------------------------------------------------
|
| 552 |
|
| 553 | /**
|
| 554 | * Where_in
|
| 555 | *
|
| 556 | * Called by where_in, where_in_or, where_not_in, where_not_in_or
|
| 557 | *
|
| 558 | * @access public
|
| 559 | * @param string The field to search
|
| 560 | * @param array The values searched on
|
| 561 | * @param boolean If the statement whould be IN or NOT IN
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 562 | * @param string
|
| 563 | * @return object
|
| 564 | */
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 565 | function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 566 | {
|
| 567 | if ($key === NULL || !is_array($values))
|
| 568 | {
|
| 569 | return;
|
| 570 | }
|
| 571 |
|
Derek Allard | c693551 | 2007-12-19 14:23:19 +0000 | [diff] [blame] | 572 | $not = ($not) ? ' NOT ' : '';
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 573 |
|
| 574 | foreach ($values as $value)
|
| 575 | {
|
| 576 | $this->ar_wherein[] = $this->escape($value);
|
| 577 | }
|
| 578 |
|
| 579 | $prefix = (count($this->ar_where) == 0) ? '' : $type;
|
| 580 |
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 581 | $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
|
| 582 |
|
| 583 | $this->ar_where[] = $where_in;
|
| 584 | if ($this->ar_caching === TRUE)
|
| 585 | {
|
| 586 | $this->ar_cache_where[] = $where_in;
|
| 587 | }
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 588 |
|
Derek Allard | 8f00021 | 2008-01-18 14:45:59 +0000 | [diff] [blame] | 589 | // reset the array for multiple calls
|
| 590 | $this->ar_wherein = array();
|
Derek Allard | 80dd702 | 2007-12-18 23:55:06 +0000 | [diff] [blame] | 591 | return $this;
|
| 592 | }
|
| 593 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 594 | // --------------------------------------------------------------------
|
| 595 |
|
| 596 | /**
|
| 597 | * Like
|
| 598 | *
|
| 599 | * Generates a %LIKE% portion of the query. Separates
|
| 600 | * multiple calls with AND
|
| 601 | *
|
| 602 | * @access public
|
| 603 | * @param mixed
|
| 604 | * @param mixed
|
| 605 | * @return object
|
| 606 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 607 | function like($field, $match = '', $side = 'both')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 608 | {
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 609 | return $this->_like($field, $match, 'AND ', $side);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 610 | }
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 611 |
|
| 612 | // --------------------------------------------------------------------
|
| 613 |
|
| 614 | /**
|
| 615 | * Not Like
|
| 616 | *
|
| 617 | * Generates a NOT LIKE portion of the query. Separates
|
| 618 | * multiple calls with AND
|
| 619 | *
|
| 620 | * @access public
|
| 621 | * @param mixed
|
| 622 | * @param mixed
|
| 623 | * @return object
|
| 624 | */
|
| 625 | function not_like($field, $match = '', $side = 'both')
|
| 626 | {
|
| 627 | return $this->_like($field, $match, 'AND ', $side, ' NOT');
|
| 628 | }
|
| 629 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 630 | // --------------------------------------------------------------------
|
| 631 |
|
| 632 | /**
|
| 633 | * OR Like
|
| 634 | *
|
| 635 | * Generates a %LIKE% portion of the query. Separates
|
| 636 | * multiple calls with OR
|
| 637 | *
|
| 638 | * @access public
|
| 639 | * @param mixed
|
| 640 | * @param mixed
|
| 641 | * @return object
|
| 642 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 643 | function or_like($field, $match = '', $side = 'both')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 644 | {
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 645 | return $this->_like($field, $match, 'OR ', $side);
|
| 646 | }
|
| 647 |
|
| 648 | // --------------------------------------------------------------------
|
| 649 |
|
| 650 | /**
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 651 | * OR Not Like
|
| 652 | *
|
| 653 | * Generates a NOT LIKE portion of the query. Separates
|
| 654 | * multiple calls with OR
|
| 655 | *
|
| 656 | * @access public
|
| 657 | * @param mixed
|
| 658 | * @param mixed
|
| 659 | * @return object
|
| 660 | */
|
| 661 | function or_not_like($field, $match = '', $side = 'both')
|
| 662 | {
|
| 663 | return $this->_like($field, $match, 'OR ', $side, 'NOT ');
|
| 664 | }
|
| 665 |
|
| 666 | // --------------------------------------------------------------------
|
| 667 |
|
| 668 | /**
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 669 | * orlike() is an alias of or_like()
|
| 670 | * this function is here for backwards compatibility, as
|
| 671 | * orlike() has been deprecated
|
| 672 | */
|
| 673 | function orlike($field, $match = '', $side = 'both')
|
| 674 | {
|
Derek Allard | 4a310b7 | 2008-01-30 21:32:47 +0000 | [diff] [blame] | 675 | return $this->or_like($field, $match, $side);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 676 | }
|
| 677 |
|
| 678 | // --------------------------------------------------------------------
|
| 679 |
|
| 680 | /**
|
| 681 | * Like
|
| 682 | *
|
| 683 | * Called by like() or orlike()
|
| 684 | *
|
| 685 | * @access private
|
| 686 | * @param mixed
|
| 687 | * @param mixed
|
| 688 | * @param string
|
| 689 | * @return object
|
| 690 | */
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 691 | function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 692 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 693 | if (! is_array($field))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 694 | {
|
| 695 | $field = array($field => $match);
|
| 696 | }
|
| 697 |
|
| 698 | foreach ($field as $k => $v)
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 699 | {
|
| 700 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 701 | $k = $this->_protect_identifiers($k);
|
| 702 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 703 | $prefix = (count($this->ar_like) == 0) ? '' : $type;
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 704 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 705 | $v = $this->escape_str($v);
|
Derek Allard | e54e3d2 | 2007-12-19 15:53:44 +0000 | [diff] [blame] | 706 |
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 707 | if ($side == 'before')
|
| 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 | elseif ($side == 'after')
|
| 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 | }
|
| 715 | else
|
| 716 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 717 | $like_statement = $prefix." $k $not LIKE '%{$v}%'";
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 718 | }
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 719 |
|
| 720 | $this->ar_like[] = $like_statement;
|
| 721 | if ($this->ar_caching === TRUE)
|
| 722 | {
|
| 723 | $this->ar_cache_like[] = $like_statement;
|
| 724 | }
|
| 725 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 726 | }
|
| 727 | return $this;
|
| 728 | }
|
| 729 |
|
| 730 | // --------------------------------------------------------------------
|
| 731 |
|
| 732 | /**
|
| 733 | * GROUP BY
|
| 734 | *
|
| 735 | * @access public
|
| 736 | * @param string
|
| 737 | * @return object
|
| 738 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 739 | function group_by($by)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 740 | {
|
| 741 | if (is_string($by))
|
| 742 | {
|
| 743 | $by = explode(',', $by);
|
| 744 | }
|
| 745 |
|
| 746 | foreach ($by as $val)
|
| 747 | {
|
| 748 | $val = trim($val);
|
| 749 |
|
| 750 | if ($val != '')
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 751 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 752 | $this->ar_groupby[] = $this->_protect_identifiers($val);
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 753 | if ($this->ar_caching === TRUE)
|
| 754 | {
|
| 755 | $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
|
| 756 | }
|
| 757 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 758 | }
|
| 759 | return $this;
|
| 760 | }
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 761 |
|
| 762 | // --------------------------------------------------------------------
|
| 763 |
|
| 764 | /**
|
| 765 | * groupby() is an alias of group_by()
|
| 766 | * this function is here for backwards compatibility, as
|
| 767 | * groupby() has been deprecated
|
| 768 | */
|
| 769 | function groupby($by)
|
| 770 | {
|
| 771 | return $this->group_by($by);
|
| 772 | }
|
| 773 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 774 | // --------------------------------------------------------------------
|
| 775 |
|
| 776 | /**
|
| 777 | * Sets the HAVING value
|
| 778 | *
|
| 779 | * Separates multiple calls with AND
|
| 780 | *
|
| 781 | * @access public
|
| 782 | * @param string
|
| 783 | * @param string
|
| 784 | * @return object
|
| 785 | */
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 786 | function having($key, $value = '', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 787 | {
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 788 | return $this->_having($key, $value, 'AND ', $escape);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 789 | }
|
Derek Allard | 43e8cbf | 2008-03-01 23:14:43 +0000 | [diff] [blame] | 790 |
|
| 791 | // --------------------------------------------------------------------
|
| 792 |
|
| 793 | /**
|
| 794 | * orhaving() is an alias of or_having()
|
| 795 | * this function is here for backwards compatibility, as
|
| 796 | * orhaving() has been deprecated
|
| 797 | */
|
| 798 |
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 799 | function orhaving($key, $value = '', $escape = TRUE)
|
Derek Allard | 43e8cbf | 2008-03-01 23:14:43 +0000 | [diff] [blame] | 800 | {
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 801 | return $this->or_having($key, $value = '', $escape);
|
Derek Allard | 43e8cbf | 2008-03-01 23:14:43 +0000 | [diff] [blame] | 802 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 803 | // --------------------------------------------------------------------
|
| 804 |
|
| 805 | /**
|
| 806 | * Sets the OR HAVING value
|
| 807 | *
|
| 808 | * Separates multiple calls with OR
|
| 809 | *
|
| 810 | * @access public
|
| 811 | * @param string
|
| 812 | * @param string
|
| 813 | * @return object
|
| 814 | */
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 815 | function or_having($key, $value = '', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 816 | {
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 817 | return $this->_having($key, $value, 'OR ', $escape);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 818 | }
|
| 819 |
|
| 820 | // --------------------------------------------------------------------
|
| 821 |
|
| 822 | /**
|
| 823 | * Sets the HAVING values
|
| 824 | *
|
| 825 | * Called by having() or orhaving()
|
| 826 | *
|
| 827 | * @access private
|
| 828 | * @param string
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 829 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 830 | * @param string
|
| 831 | * @return object
|
| 832 | */
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 833 | function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 834 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 835 | if (! is_array($key))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 836 | {
|
| 837 | $key = array($key => $value);
|
| 838 | }
|
| 839 |
|
| 840 | foreach ($key as $k => $v)
|
| 841 | {
|
| 842 | $prefix = (count($this->ar_having) == 0) ? '' : $type;
|
Derek Allard | e808aac | 2008-04-06 18:22:00 +0000 | [diff] [blame] | 843 |
|
| 844 | if ($escape === TRUE)
|
| 845 | {
|
| 846 | $k = $this->_protect_identifiers($k);
|
| 847 | }
|
| 848 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 849 |
|
| 850 | if ($v != '')
|
| 851 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 852 | $v = ' '.$this->escape_str($v);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 853 | }
|
| 854 |
|
| 855 | $this->ar_having[] = $prefix.$k.$v;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 856 | if ($this->ar_caching === TRUE)
|
| 857 | {
|
| 858 | $this->ar_cache_having[] = $prefix.$k.$v;
|
| 859 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 860 | }
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 861 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 862 | return $this;
|
| 863 | }
|
| 864 |
|
| 865 | // --------------------------------------------------------------------
|
| 866 |
|
| 867 | /**
|
| 868 | * Sets the ORDER BY value
|
| 869 | *
|
| 870 | * @access public
|
| 871 | * @param string
|
| 872 | * @param string direction: asc or desc
|
| 873 | * @return object
|
| 874 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 875 | function order_by($orderby, $direction = '')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 876 | {
|
Derek Allard | 6ddb5a1 | 2007-12-18 17:22:50 +0000 | [diff] [blame] | 877 | if (strtolower($direction) == 'random')
|
| 878 | {
|
| 879 | $orderby = ''; // Random results want or don't need a field name
|
| 880 | $direction = $this->_random_keyword;
|
| 881 | }
|
| 882 | elseif (trim($direction) != '')
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 883 | {
|
Derek Allard | 9278249 | 2007-08-10 11:26:01 +0000 | [diff] [blame] | 884 | $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 885 | }
|
| 886 |
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 887 | $orderby_statement = $this->_protect_identifiers($orderby, TRUE).$direction;
|
| 888 |
|
| 889 | $this->ar_orderby[] = $orderby_statement;
|
| 890 | if ($this->ar_caching === TRUE)
|
| 891 | {
|
| 892 | $this->ar_cache_orderby[] = $orderby_statement;
|
| 893 | }
|
| 894 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 895 | return $this;
|
| 896 | }
|
Derek Allard | 6ddb5a1 | 2007-12-18 17:22:50 +0000 | [diff] [blame] | 897 |
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 898 | // --------------------------------------------------------------------
|
| 899 |
|
| 900 | /**
|
| 901 | * orderby() is an alias of order_by()
|
| 902 | * this function is here for backwards compatibility, as
|
| 903 | * orderby() has been deprecated
|
| 904 | */
|
| 905 | function orderby($orderby, $direction = '')
|
| 906 | {
|
| 907 | return $this->order_by($orderby, $direction);
|
| 908 | }
|
Derek Allard | 6ddb5a1 | 2007-12-18 17:22:50 +0000 | [diff] [blame] | 909 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 910 | // --------------------------------------------------------------------
|
| 911 |
|
| 912 | /**
|
| 913 | * Sets the LIMIT value
|
| 914 | *
|
| 915 | * @access public
|
| 916 | * @param integer the limit value
|
| 917 | * @param integer the offset value
|
| 918 | * @return object
|
| 919 | */
|
| 920 | function limit($value, $offset = '')
|
| 921 | {
|
| 922 | $this->ar_limit = $value;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 923 | if ($this->ar_caching === TRUE)
|
| 924 | {
|
| 925 | $this->ar_cache_limit[] = $value;
|
| 926 | }
|
| 927 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 928 | if ($offset != '')
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 929 | {
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 930 | $this->ar_offset = $offset;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 931 | if ($this->ar_caching === TRUE)
|
| 932 | {
|
| 933 | $this->ar_cache_offset[] = $offset;
|
| 934 | }
|
| 935 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 936 |
|
| 937 | return $this;
|
| 938 | }
|
| 939 |
|
| 940 | // --------------------------------------------------------------------
|
| 941 |
|
| 942 | /**
|
| 943 | * Sets the OFFSET value
|
| 944 | *
|
| 945 | * @access public
|
| 946 | * @param integer the offset value
|
| 947 | * @return object
|
| 948 | */
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 949 | function offset($offset)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 950 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 951 | $this->ar_offset = $offset;
|
| 952 | if ($this->ar_caching === TRUE)
|
| 953 | {
|
| 954 | $this->ar_cache_offset[] = $offset;
|
| 955 | }
|
| 956 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 957 | return $this;
|
| 958 | }
|
| 959 |
|
| 960 | // --------------------------------------------------------------------
|
| 961 |
|
| 962 | /**
|
| 963 | * The "set" function. Allows key/value pairs to be set for inserting or updating
|
| 964 | *
|
| 965 | * @access public
|
| 966 | * @param mixed
|
| 967 | * @param string
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 968 | * @param boolean
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 969 | * @return object
|
| 970 | */
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 971 | function set($key, $value = '', $escape = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 972 | {
|
| 973 | $key = $this->_object_to_array($key);
|
| 974 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 975 | if (! is_array($key))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 976 | {
|
| 977 | $key = array($key => $value);
|
| 978 | }
|
| 979 |
|
| 980 | foreach ($key as $k => $v)
|
| 981 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 982 | if ($escape === FALSE)
|
| 983 | {
|
| 984 | $this->ar_set[$this->_protect_identifiers($k)] = $v;
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 985 | if ($this->ar_caching === TRUE)
|
| 986 | {
|
| 987 | $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v;
|
| 988 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 989 | }
|
| 990 | else
|
| 991 | {
|
| 992 | $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 993 | if ($this->ar_caching === TRUE)
|
| 994 | {
|
| 995 | $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v);
|
| 996 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 997 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 998 | }
|
| 999 |
|
| 1000 | return $this;
|
| 1001 | }
|
| 1002 |
|
| 1003 | // --------------------------------------------------------------------
|
| 1004 |
|
| 1005 | /**
|
| 1006 | * Get
|
| 1007 | *
|
| 1008 | * Compiles the select statement based on the other functions called
|
| 1009 | * and runs the query
|
| 1010 | *
|
| 1011 | * @access public
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1012 | * @param string the table
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1013 | * @param string the limit clause
|
| 1014 | * @param string the offset clause
|
| 1015 | * @return object
|
| 1016 | */
|
| 1017 | function get($table = '', $limit = null, $offset = null)
|
| 1018 | {
|
| 1019 | if ($table != '')
|
| 1020 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1021 | $this->_track_aliases($table);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1022 | $this->from($table);
|
| 1023 | }
|
| 1024 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1025 | if (! is_null($limit))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1026 | {
|
| 1027 | $this->limit($limit, $offset);
|
| 1028 | }
|
| 1029 |
|
| 1030 | $sql = $this->_compile_select();
|
| 1031 |
|
| 1032 | $result = $this->query($sql);
|
| 1033 | $this->_reset_select();
|
| 1034 | return $result;
|
| 1035 | }
|
| 1036 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1037 | /**
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1038 | * "Count All Results" query
|
| 1039 | *
|
| 1040 | * Generates a platform-specific query string that counts all records
|
| 1041 | * returned by an Active Record query.
|
| 1042 | *
|
| 1043 | * @access public
|
| 1044 | * @param string
|
| 1045 | * @return string
|
| 1046 | */
|
| 1047 | function count_all_results($table = '')
|
| 1048 | {
|
| 1049 | if ($table != '')
|
| 1050 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1051 | $this->_track_aliases($table);
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1052 | $this->from($table);
|
| 1053 | }
|
| 1054 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1055 | $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1056 |
|
| 1057 | $query = $this->query($sql);
|
| 1058 | $this->_reset_select();
|
| 1059 |
|
| 1060 | if ($query->num_rows() == 0)
|
| 1061 | {
|
| 1062 | return '0';
|
| 1063 | }
|
| 1064 |
|
| 1065 | $row = $query->row();
|
| 1066 | return $row->numrows;
|
| 1067 | }
|
| 1068 |
|
| 1069 | // --------------------------------------------------------------------
|
| 1070 |
|
| 1071 | /**
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 1072 | * Get_Where
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1073 | *
|
| 1074 | * Allows the where clause, limit and offset to be added directly
|
| 1075 | *
|
| 1076 | * @access public
|
| 1077 | * @param string the where clause
|
| 1078 | * @param string the limit clause
|
| 1079 | * @param string the offset clause
|
| 1080 | * @return object
|
| 1081 | */
|
Derek Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 1082 | function get_where($table = '', $where = null, $limit = null, $offset = null)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1083 | {
|
| 1084 | if ($table != '')
|
| 1085 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1086 | $this->_track_aliases($table);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1087 | $this->from($table);
|
| 1088 | }
|
| 1089 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1090 | if (! is_null($where))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1091 | {
|
| 1092 | $this->where($where);
|
| 1093 | }
|
| 1094 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1095 | if (! is_null($limit))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1096 | {
|
| 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 Allard | 218e2bc | 2007-12-17 21:18:14 +0000 | [diff] [blame] | 1106 |
|
| 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 Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1118 |
|
| 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 Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1133 | if (! is_null($set))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1134 | {
|
| 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 Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1149 | if (! isset($this->ar_from[0]))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1150 | {
|
| 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 Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1160 |
|
| 1161 | $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] | 1162 |
|
| 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 Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1180 | function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1181 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1182 | if (! is_null($set))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1183 | {
|
| 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 Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1198 | if (! isset($this->ar_from[0]))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1199 | {
|
| 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 Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1210 | if ($where != NULL)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1211 | {
|
| 1212 | $this->where($where);
|
| 1213 | }
|
Derek Allard | da6d240 | 2007-12-19 14:49:29 +0000 | [diff] [blame] | 1214 |
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1215 | if ($limit != NULL)
|
Derek Allard | da6d240 | 2007-12-19 14:49:29 +0000 | [diff] [blame] | 1216 | {
|
| 1217 | $this->limit($limit);
|
| 1218 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1219 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1220 | $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] | 1221 |
|
| 1222 | $this->_reset_write();
|
| 1223 | return $this->query($sql);
|
| 1224 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1225 |
|
| 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 Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1241 | if (! isset($this->ar_from[0]))
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1242 | {
|
| 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 | {
|
| 1254 | $table = $this->_protect_identifiers($this->dbprefix.$table);
|
| 1255 | }
|
| 1256 |
|
| 1257 |
|
| 1258 | $sql = $this->_delete($table);
|
| 1259 |
|
| 1260 | $this->_reset_write();
|
| 1261 |
|
| 1262 | return $this->query($sql);
|
| 1263 | }
|
| 1264 |
|
| 1265 | // --------------------------------------------------------------------
|
| 1266 |
|
| 1267 | /**
|
| 1268 | * Truncate
|
| 1269 | *
|
| 1270 | * Compiles a truncate string and runs the query
|
| 1271 | * If the database does not support the truncate() command
|
| 1272 | * This function maps to "DELETE FROM table"
|
| 1273 | *
|
| 1274 | * @access public
|
| 1275 | * @param string the table to truncate
|
| 1276 | * @return object
|
| 1277 | */
|
| 1278 | function truncate($table = '')
|
| 1279 | {
|
| 1280 | if ($table == '')
|
| 1281 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1282 | if (! isset($this->ar_from[0]))
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1283 | {
|
| 1284 | if ($this->db_debug)
|
| 1285 | {
|
| 1286 | return $this->display_error('db_must_set_table');
|
| 1287 | }
|
| 1288 | return FALSE;
|
| 1289 | }
|
| 1290 |
|
| 1291 | $table = $this->ar_from[0];
|
| 1292 | }
|
| 1293 | else
|
| 1294 | {
|
| 1295 | $table = $this->_protect_identifiers($this->dbprefix.$table);
|
| 1296 | }
|
| 1297 |
|
| 1298 |
|
| 1299 | $sql = $this->_truncate($table);
|
| 1300 |
|
| 1301 | $this->_reset_write();
|
| 1302 |
|
| 1303 | return $this->query($sql);
|
| 1304 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1305 |
|
| 1306 | // --------------------------------------------------------------------
|
| 1307 |
|
| 1308 | /**
|
| 1309 | * Delete
|
| 1310 | *
|
| 1311 | * Compiles a delete string and runs the query
|
| 1312 | *
|
| 1313 | * @access public
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1314 | * @param mixed the table(s) to delete from. String or array
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1315 | * @param mixed the where clause
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1316 | * @param mixed the limit clause
|
| 1317 | * @param boolean
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1318 | * @return object
|
| 1319 | */
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1320 | function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1321 | {
|
| 1322 | if ($table == '')
|
| 1323 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1324 | if (! isset($this->ar_from[0]))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1325 | {
|
| 1326 | if ($this->db_debug)
|
| 1327 | {
|
| 1328 | return $this->display_error('db_must_set_table');
|
| 1329 | }
|
| 1330 | return FALSE;
|
| 1331 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1332 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1333 | $table = $this->ar_from[0];
|
| 1334 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1335 | elseif (is_array($table))
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1336 | {
|
| 1337 | foreach($table as $single_table)
|
| 1338 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1339 | $this->delete($single_table, $where, $limit, FALSE);
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1340 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1341 |
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1342 | $this->_reset_write();
|
| 1343 | return;
|
| 1344 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1345 | else
|
| 1346 | {
|
| 1347 | $table = $this->_protect_identifiers($this->dbprefix.$table);
|
| 1348 | }
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1349 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1350 | if ($where != '')
|
| 1351 | {
|
| 1352 | $this->where($where);
|
| 1353 | }
|
| 1354 |
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1355 | if ($limit != NULL)
|
| 1356 | {
|
| 1357 | $this->limit($limit);
|
| 1358 | }
|
| 1359 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1360 | if (count($this->ar_where) == 0 && count($this->ar_like) == 0)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1361 | {
|
| 1362 | if ($this->db_debug)
|
| 1363 | {
|
| 1364 | return $this->display_error('db_del_must_use_where');
|
| 1365 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1366 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1367 | return FALSE;
|
| 1368 | }
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1369 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1370 | $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] | 1371 |
|
Derek Allard | 41f60d4 | 2007-12-20 20:09:22 +0000 | [diff] [blame] | 1372 | if ($reset_data)
|
| 1373 | {
|
| 1374 | $this->_reset_write();
|
| 1375 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1376 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1377 | return $this->query($sql);
|
| 1378 | }
|
Derek Allard | 15ddc9d | 2007-12-20 13:54:39 +0000 | [diff] [blame] | 1379 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1380 | // --------------------------------------------------------------------
|
| 1381 |
|
| 1382 | /**
|
| 1383 | * Use Table - DEPRECATED
|
| 1384 | *
|
| 1385 | * @deprecated use $this->db->from instead
|
| 1386 | */
|
| 1387 | function use_table($table)
|
| 1388 | {
|
| 1389 | return $this->from($table);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1390 | }
|
| 1391 |
|
| 1392 | // --------------------------------------------------------------------
|
| 1393 |
|
| 1394 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1395 | * Tests whether the string has an SQL operator
|
| 1396 | *
|
| 1397 | * @access private
|
| 1398 | * @param string
|
| 1399 | * @return bool
|
| 1400 | */
|
| 1401 | function _has_operator($str)
|
| 1402 | {
|
| 1403 | $str = trim($str);
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1404 | if (! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1405 | {
|
| 1406 | return FALSE;
|
| 1407 | }
|
| 1408 |
|
| 1409 | return TRUE;
|
| 1410 | }
|
| 1411 |
|
| 1412 | // --------------------------------------------------------------------
|
| 1413 |
|
| 1414 | /**
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1415 | * Track Aliases
|
| 1416 | *
|
| 1417 | * Used to track SQL statements written with aliased tables.
|
| 1418 | *
|
| 1419 | * @access private
|
| 1420 | * @param string The table to inspect
|
| 1421 | * @return string
|
| 1422 | */
|
| 1423 | function _track_aliases($table)
|
| 1424 | {
|
| 1425 | // if a table alias is used we can recognize it by a space
|
| 1426 | if (strpos($table, " ") !== FALSE)
|
| 1427 | {
|
| 1428 | // if the alias is written with the AS keyowrd, get it out
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1429 | $table = preg_replace('/ AS /i', ' ', $table);
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1430 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1431 | $this->ar_aliased_tables[] = trim(strrchr($table, " "));
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1432 | }
|
| 1433 |
|
| 1434 | return $this->dbprefix.$table;
|
| 1435 | }
|
| 1436 |
|
| 1437 | // --------------------------------------------------------------------
|
| 1438 |
|
| 1439 | /**
|
| 1440 | * Filter Table Aliases
|
| 1441 | *
|
| 1442 | * Intelligently removes database prefixes from aliased tables
|
| 1443 | *
|
| 1444 | * @access private
|
| 1445 | * @param array An array of compiled SQL
|
| 1446 | * @return array Cleaned up statement with aliases accounted for
|
| 1447 | */
|
| 1448 | function _filter_table_aliases($statements)
|
| 1449 | {
|
Derek Allard | 8b2f19b | 2008-03-06 15:51:55 +0000 | [diff] [blame] | 1450 |
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1451 | foreach ($statements as $k => $v)
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1452 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1453 | foreach ($this->ar_aliased_tables as $table)
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1454 | {
|
Derek Allard | 8b2f19b | 2008-03-06 15:51:55 +0000 | [diff] [blame] | 1455 | $statements[$k] = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $statements[$k]); // makes `table.field`
|
| 1456 | $statements[$k] = str_replace($this->dbprefix.$table.'.', $table.'.', $statements[$k]);
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1457 | }
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1458 | }
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 1459 | return $statements;
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1460 | }
|
| 1461 |
|
| 1462 | // --------------------------------------------------------------------
|
| 1463 |
|
| 1464 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1465 | * Compile the SELECT statement
|
| 1466 | *
|
| 1467 | * Generates a query string based on which functions were used.
|
| 1468 | * Should not be called directly. The get() function calls it.
|
| 1469 | *
|
| 1470 | * @access private
|
| 1471 | * @return string
|
| 1472 | */
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1473 | function _compile_select($select_override = FALSE)
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1474 | {
|
Derek Allard | 7825526 | 2008-02-06 13:54:23 +0000 | [diff] [blame] | 1475 | $this->_merge_cache();
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1476 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1477 | $sql = (! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1478 |
|
Derek Allard | 5162fc7 | 2008-04-15 20:05:37 +0000 | [diff] [blame] | 1479 | $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] | 1480 |
|
Derek Allard | 694b5b8 | 2007-12-18 15:58:03 +0000 | [diff] [blame] | 1481 | if ($select_override !== FALSE)
|
| 1482 | {
|
| 1483 | $sql = $select_override;
|
| 1484 | }
|
| 1485 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1486 | if (count($this->ar_from) > 0)
|
| 1487 | {
|
| 1488 | $sql .= "\nFROM ";
|
Derek Jones | c6ad023 | 2008-01-29 18:44:54 +0000 | [diff] [blame] | 1489 | $sql .= $this->_from_tables($this->ar_from);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1490 | }
|
| 1491 |
|
| 1492 | if (count($this->ar_join) > 0)
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1493 | {
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1494 | $sql .= "\n";
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1495 |
|
| 1496 | // special consideration for table aliases
|
| 1497 | if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
|
| 1498 | {
|
| 1499 | $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join));
|
| 1500 | }
|
| 1501 | else
|
| 1502 | {
|
| 1503 | $sql .= implode("\n", $this->ar_join);
|
| 1504 | }
|
| 1505 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1506 | }
|
| 1507 |
|
| 1508 | if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
|
| 1509 | {
|
| 1510 | $sql .= "\nWHERE ";
|
| 1511 | }
|
| 1512 |
|
| 1513 | $sql .= implode("\n", $this->ar_where);
|
| 1514 |
|
| 1515 | if (count($this->ar_like) > 0)
|
| 1516 | {
|
| 1517 | if (count($this->ar_where) > 0)
|
| 1518 | {
|
| 1519 | $sql .= " AND ";
|
| 1520 | }
|
| 1521 |
|
| 1522 | $sql .= implode("\n", $this->ar_like);
|
| 1523 | }
|
| 1524 |
|
| 1525 | if (count($this->ar_groupby) > 0)
|
| 1526 | {
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1527 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1528 | $sql .= "\nGROUP BY ";
|
Derek Allard | 5e12894 | 2007-12-28 21:33:03 +0000 | [diff] [blame] | 1529 |
|
| 1530 | // special consideration for table aliases
|
| 1531 | if (count($this->ar_aliased_tables) > 0 && $this->dbprefix)
|
| 1532 | {
|
| 1533 | $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby));
|
| 1534 | }
|
| 1535 | else
|
| 1536 | {
|
| 1537 | $sql .= implode(', ', $this->ar_groupby);
|
| 1538 | }
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1539 | }
|
| 1540 |
|
| 1541 | if (count($this->ar_having) > 0)
|
| 1542 | {
|
| 1543 | $sql .= "\nHAVING ";
|
| 1544 | $sql .= implode("\n", $this->ar_having);
|
| 1545 | }
|
| 1546 |
|
| 1547 | if (count($this->ar_orderby) > 0)
|
| 1548 | {
|
| 1549 | $sql .= "\nORDER BY ";
|
| 1550 | $sql .= implode(', ', $this->ar_orderby);
|
| 1551 |
|
| 1552 | if ($this->ar_order !== FALSE)
|
| 1553 | {
|
| 1554 | $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
|
| 1555 | }
|
| 1556 | }
|
| 1557 |
|
| 1558 | if (is_numeric($this->ar_limit))
|
| 1559 | {
|
| 1560 | $sql .= "\n";
|
| 1561 | $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
|
| 1562 | }
|
| 1563 |
|
| 1564 | return $sql;
|
| 1565 | }
|
| 1566 |
|
| 1567 | // --------------------------------------------------------------------
|
| 1568 |
|
| 1569 | /**
|
| 1570 | * Object to Array
|
| 1571 | *
|
| 1572 | * Takes an object as input and converts the class variables to array key/vals
|
| 1573 | *
|
| 1574 | * @access public
|
| 1575 | * @param object
|
| 1576 | * @return array
|
| 1577 | */
|
| 1578 | function _object_to_array($object)
|
| 1579 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame^] | 1580 | if (! is_object($object))
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1581 | {
|
| 1582 | return $object;
|
| 1583 | }
|
| 1584 |
|
| 1585 | $array = array();
|
| 1586 | foreach (get_object_vars($object) as $key => $val)
|
| 1587 | {
|
Derek Allard | 848b776 | 2007-12-31 16:43:05 +0000 | [diff] [blame] | 1588 | // 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^] | 1589 | 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] | 1590 |
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1591 | {
|
| 1592 | $array[$key] = $val;
|
| 1593 | }
|
| 1594 | }
|
| 1595 |
|
| 1596 | return $array;
|
| 1597 | }
|
| 1598 |
|
| 1599 | // --------------------------------------------------------------------
|
| 1600 |
|
| 1601 | /**
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1602 | * Start Cache
|
| 1603 | *
|
| 1604 | * Starts AR caching
|
| 1605 | *
|
| 1606 | * @access public
|
| 1607 | * @return void
|
| 1608 | */
|
| 1609 | function start_cache()
|
| 1610 | {
|
| 1611 | $this->ar_caching = TRUE;
|
| 1612 | }
|
| 1613 |
|
| 1614 | // --------------------------------------------------------------------
|
| 1615 |
|
| 1616 | /**
|
| 1617 | * Stop Cache
|
| 1618 | *
|
| 1619 | * Stops AR caching
|
| 1620 | *
|
| 1621 | * @access public
|
| 1622 | * @return void
|
| 1623 | */
|
| 1624 | function stop_cache()
|
| 1625 | {
|
| 1626 | $this->ar_caching = FALSE;
|
| 1627 | }
|
| 1628 |
|
| 1629 |
|
| 1630 | // --------------------------------------------------------------------
|
| 1631 |
|
| 1632 | /**
|
| 1633 | * Flush Cache
|
| 1634 | *
|
| 1635 | * Empties the AR cache
|
| 1636 | *
|
| 1637 | * @access public
|
| 1638 | * @return void
|
| 1639 | */
|
| 1640 | function flush_cache()
|
| 1641 | {
|
| 1642 | $ar_reset_items = array(
|
| 1643 | 'ar_cache_select' => array(),
|
| 1644 | 'ar_cache_from' => array(),
|
| 1645 | 'ar_cache_join' => array(),
|
| 1646 | 'ar_cache_where' => array(),
|
| 1647 | 'ar_cache_like' => array(),
|
| 1648 | 'ar_cache_groupby' => array(),
|
| 1649 | 'ar_cache_having' =>array(),
|
| 1650 | 'ar_cache_orderby' => array(),
|
| 1651 | 'ar_cache_set' => array()
|
| 1652 | );
|
| 1653 |
|
| 1654 | $this->_reset_run($ar_reset_items);
|
| 1655 | }
|
| 1656 |
|
| 1657 | // --------------------------------------------------------------------
|
| 1658 |
|
| 1659 | /**
|
| 1660 | * Merge Cache
|
| 1661 | *
|
| 1662 | * When called, this function merges any cached AR arrays with
|
| 1663 | * locally called ones.
|
| 1664 | *
|
| 1665 | * @access private
|
| 1666 | * @return void
|
| 1667 | */
|
| 1668 | function _merge_cache()
|
| 1669 | {
|
| 1670 | $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set');
|
| 1671 |
|
| 1672 | foreach ($ar_items as $ar_item)
|
| 1673 | {
|
| 1674 | $ar_cache_item = 'ar_cache_'.$ar_item;
|
| 1675 | $ar_item = 'ar_'.$ar_item;
|
| 1676 | $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item));
|
| 1677 | }
|
| 1678 | }
|
| 1679 |
|
| 1680 | // --------------------------------------------------------------------
|
| 1681 |
|
| 1682 | /**
|
| 1683 | * Resets the active record values. Called by the get() function
|
| 1684 | *
|
| 1685 | * @access private
|
| 1686 | * @param array An array of fields to reset
|
| 1687 | * @return void
|
| 1688 | */
|
| 1689 | function _reset_run($ar_reset_items)
|
| 1690 | {
|
| 1691 | foreach ($ar_reset_items as $item => $default_value)
|
| 1692 | {
|
| 1693 | if (!in_array($item, $this->ar_store_array))
|
| 1694 | {
|
| 1695 | $this->$item = $default_value;
|
| 1696 | }
|
| 1697 | }
|
| 1698 | }
|
| 1699 |
|
| 1700 | // --------------------------------------------------------------------
|
| 1701 |
|
| 1702 | /**
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1703 | * Resets the active record values. Called by the get() function
|
| 1704 | *
|
| 1705 | * @access private
|
| 1706 | * @return void
|
| 1707 | */
|
| 1708 | function _reset_select()
|
| 1709 | {
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1710 | $ar_reset_items = array(
|
| 1711 | 'ar_select' => array(),
|
| 1712 | 'ar_from' => array(),
|
| 1713 | 'ar_join' => array(),
|
| 1714 | 'ar_where' => array(),
|
| 1715 | 'ar_like' => array(),
|
| 1716 | 'ar_groupby' => array(),
|
| 1717 | 'ar_having' => array(),
|
| 1718 | 'ar_orderby' => array(),
|
| 1719 | 'ar_wherein' => array(),
|
| 1720 | 'ar_aliased_tables' => array(),
|
| 1721 | 'ar_distinct' => FALSE,
|
| 1722 | 'ar_limit' => FALSE,
|
| 1723 | 'ar_offset' => FALSE,
|
| 1724 | 'ar_order' => FALSE,
|
| 1725 | );
|
| 1726 |
|
| 1727 | $this->_reset_run($ar_reset_items);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1728 | }
|
| 1729 |
|
| 1730 | // --------------------------------------------------------------------
|
| 1731 |
|
| 1732 | /**
|
| 1733 | * Resets the active record "write" values.
|
| 1734 | *
|
Derek Allard | e77d77c | 2007-12-19 15:01:55 +0000 | [diff] [blame] | 1735 | * Called by the insert() update() and delete() functions
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1736 | *
|
| 1737 | * @access private
|
| 1738 | * @return void
|
| 1739 | */
|
| 1740 | function _reset_write()
|
Derek Allard | 9b3e7b5 | 2008-02-04 23:20:34 +0000 | [diff] [blame] | 1741 | {
|
| 1742 | $ar_reset_items = array(
|
| 1743 | 'ar_set' => array(),
|
| 1744 | 'ar_from' => array(),
|
| 1745 | 'ar_where' => array(),
|
| 1746 | 'ar_like' => array(),
|
| 1747 | 'ar_orderby' => array(),
|
| 1748 | 'ar_limit' => FALSE,
|
| 1749 | 'ar_order' => FALSE
|
| 1750 | );
|
| 1751 |
|
| 1752 | $this->_reset_run($ar_reset_items);
|
Derek Allard | 09de185 | 2007-02-14 01:35:56 +0000 | [diff] [blame] | 1753 | }
|
| 1754 |
|
| 1755 | }
|
admin | ac94f38 | 2006-09-24 20:28:12 +0000 | [diff] [blame] | 1756 | ?> |