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