Changeset 94
- Timestamp:
- 05/27/2007 11:24:08 PM (18 months ago)
- Location:
- trunk
- Files:
-
- 10 modified
-
system/database/DB_active_rec.php (modified) (19 diffs)
-
system/database/drivers/mssql/mssql_driver.php (modified) (28 diffs)
-
system/database/drivers/mysql/mysql_driver.php (modified) (27 diffs)
-
system/database/drivers/mysqli/mysqli_driver.php (modified) (22 diffs)
-
system/database/drivers/oci8/oci8_driver.php (modified) (12 diffs)
-
system/database/drivers/odbc/odbc_driver.php (modified) (21 diffs)
-
system/database/drivers/postgre/postgre_driver.php (modified) (1 diff)
-
system/database/drivers/sqlite/sqlite_driver.php (modified) (25 diffs)
-
system/libraries/Input.php (modified) (45 diffs)
-
user_guide/libraries/input.html (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/database/DB_active_rec.php
r82 r94 28 28 class CI_DB_active_record extends CI_DB_driver { 29 29 30 var $ar_select = array(); 31 var $ar_distinct = FALSE; 32 var $ar_from = array(); 33 var $ar_join = array(); 34 var $ar_where = array(); 35 var $ar_like = array(); 36 var $ar_groupby = array(); 37 var $ar_having = array(); 38 var $ar_limit = FALSE; 39 var $ar_offset = FALSE; 40 var $ar_order = FALSE; 41 var $ar_orderby = array(); 42 var $ar_set = array(); 43 30 var $ar_select = array(); 31 var $ar_distinct = FALSE; 32 var $ar_from = array(); 33 var $ar_join = array(); 34 var $ar_where = array(); 35 var $ar_like = array(); 36 var $ar_groupby = array(); 37 var $ar_having = array(); 38 var $ar_limit = FALSE; 39 var $ar_offset = FALSE; 40 var $ar_order = FALSE; 41 var $ar_orderby = array(); 42 var $ar_set = array(); 44 43 45 44 /** … … 133 132 $type .= ' '; 134 133 } 135 }136 137 if ($this->dbprefix)138 {139 $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond);140 134 } 141 135 … … 309 303 function groupby($by) 310 304 { 311 if ( is_string($by))312 { 313 $by = explode(',', $by);305 if ( ! is_array($by)) 306 { 307 $by = explode(',', (string) $by); 314 308 } 315 309 … … 338 332 function having($key, $value = '') 339 333 { 340 return $this->_having($key, $value, 'AND ');334 return $this->_having($key, $value, 'AND'); 341 335 } 342 336 … … 355 349 function orhaving($key, $value = '') 356 350 { 357 return $this->_having($key, $value, 'OR ');351 return $this->_having($key, $value, 'OR'); 358 352 } 359 353 … … 370 364 * @return object 371 365 */ 372 function _having($key, $value = '', $type = 'AND ') 373 { 366 function _having($key, $value = '', $type = 'AND') 367 { 368 $type = trim($type).' '; 369 374 370 if ( ! is_array($key)) 375 371 { … … 379 375 foreach ($key as $k => $v) 380 376 { 381 $prefix = (count($this->ar_having) == 0) ? '' : $type;377 $prefix = (count($this->ar_having) < 1) ? '' : $type; 382 378 383 379 if ($v != '') … … 403 399 function orderby($orderby, $direction = '') 404 400 { 405 if (trim($direction) != '') 406 { 407 $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; 401 $direction = strtoupper(trim($direction)); 402 403 if ($direction != '') 404 { 405 $direction = (in_array($direction, array('ASC', 'DESC', 'RAND()'))) ? " $direction" : " ASC"; 408 406 } 409 407 … … 427 425 428 426 if ($offset != '') 427 { 429 428 $this->ar_offset = $offset; 429 } 430 430 431 431 return $this; … … 562 562 } 563 563 564 if (count($this->ar_set) == 0) 565 { 566 if ($this->db_debug) 567 { 568 return $this->display_error('db_must_use_set'); 569 } 570 return FALSE; 564 if ($this->ar_set == FALSE) 565 { 566 return ($this->db_debug ? $this->display_error('db_must_use_set') : FALSE); 571 567 } 572 568 … … 575 571 if ( ! isset($this->ar_from[0])) 576 572 { 577 if ($this->db_debug) 578 { 579 return $this->display_error('db_must_set_table'); 580 } 581 return FALSE; 573 return ($this->db_debug ? $this->display_error('db_must_set_table') : FALSE); 582 574 } 583 575 … … 611 603 } 612 604 613 if (count($this->ar_set) == 0) 614 { 615 if ($this->db_debug) 616 { 617 return $this->display_error('db_must_use_set'); 618 } 619 return FALSE; 605 if ($this->ar_set == FALSE) 606 { 607 return ($this->db_debug ? $this->display_error('db_must_use_set') : FALSE); 620 608 } 621 609 … … 624 612 if ( ! isset($this->ar_from[0])) 625 613 { 626 if ($this->db_debug) 627 { 628 return $this->display_error('db_must_set_table'); 629 } 630 return FALSE; 614 return ($this->db_debug ? $this->display_error('db_must_set_table') : FALSE); 631 615 } 632 616 … … 663 647 if ( ! isset($this->ar_from[0])) 664 648 { 665 if ($this->db_debug) 666 { 667 return $this->display_error('db_must_set_table'); 668 } 669 return FALSE; 649 return ($this->db_debug ? $this->display_error('db_must_set_table') : FALSE); 670 650 } 671 651 … … 678 658 } 679 659 680 if (count($this->ar_where) == 0) 681 { 682 if ($this->db_debug) 683 { 684 return $this->display_error('db_del_must_use_where'); 685 } 686 return FALSE; 660 if (count($this->ar_where) < 1) 661 { 662 return (($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE); 687 663 } 688 664 … … 737 713 { 738 714 return $this->from($table); 739 return $this;740 715 } 741 716 … … 764 739 { 765 740 $str = trim($str); 766 if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) 767 { 768 return FALSE; 769 } 770 771 return TRUE; 741 742 return (bool) preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str); 772 743 } 773 744 … … 889 860 function _reset_select() 890 861 { 891 $this->ar_select = array();892 $this->ar_distinct = FALSE;893 $this->ar_from = array();894 $this->ar_join = array();895 $this->ar_where = array();896 $this->ar_like = array();897 $this->ar_groupby = array();898 $this->ar_having = array();899 $this->ar_limit = FALSE;900 $this->ar_offset = FALSE;901 $this->ar_order = FALSE;902 $this->ar_orderby = array();862 $this->ar_select = array(); 863 $this->ar_distinct = FALSE; 864 $this->ar_from = array(); 865 $this->ar_join = array(); 866 $this->ar_where = array(); 867 $this->ar_like = array(); 868 $this->ar_groupby = array(); 869 $this->ar_having = array(); 870 $this->ar_limit = FALSE; 871 $this->ar_offset = FALSE; 872 $this->ar_order = FALSE; 873 $this->ar_orderby = array(); 903 874 } 904 875 … … 915 886 function _reset_write() 916 887 { 917 $this->ar_set = array();918 $this->ar_from = array();919 $this->ar_where = array();888 $this->ar_set = array(); 889 $this->ar_from = array(); 890 $this->ar_where = array(); 920 891 } 921 892 -
trunk/system/database/drivers/mssql/mssql_driver.php
r24 r94 36 36 * @access private called by the base class 37 37 * @return resource 38 */ 38 */ 39 39 function db_connect() 40 40 { 41 41 return @mssql_connect($this->hostname, $this->username, $this->password); 42 42 } 43 43 44 44 // -------------------------------------------------------------------- 45 45 … … 49 49 * @access private called by the base class 50 50 * @return resource 51 */ 51 */ 52 52 function db_pconnect() 53 53 { 54 54 return @mssql_pconnect($this->hostname, $this->username, $this->password); 55 55 } 56 56 57 57 // -------------------------------------------------------------------- 58 58 … … 62 62 * @access private called by the base class 63 63 * @return resource 64 */ 64 */ 65 65 function db_select() 66 66 { … … 69 69 70 70 // -------------------------------------------------------------------- 71 71 72 72 /** 73 73 * Version number query string … … 80 80 return "SELECT version() AS ver"; 81 81 } 82 82 83 83 // -------------------------------------------------------------------- 84 84 … … 89 89 * @param string an SQL query 90 90 * @return resource 91 */ 91 */ 92 92 function _execute($sql) 93 93 { … … 95 95 return @mssql_query($sql, $this->conn_id); 96 96 } 97 97 98 98 // -------------------------------------------------------------------- 99 99 … … 106 106 * @param string an SQL query 107 107 * @return string 108 */ 108 */ 109 109 function _prep_query($sql) 110 110 { … … 118 118 * 119 119 * @access public 120 * @return bool 121 */ 120 * @return bool 121 */ 122 122 function trans_begin($test_mode = FALSE) 123 123 { … … 126 126 return TRUE; 127 127 } 128 128 129 129 // When transactions are nested we only begin/commit/rollback the outermost ones 130 130 if ($this->_trans_depth > 0) … … 148 148 * 149 149 * @access public 150 * @return bool 151 */ 150 * @return bool 151 */ 152 152 function trans_commit() 153 153 { … … 173 173 * 174 174 * @access public 175 * @return bool 176 */ 175 * @return bool 176 */ 177 177 function trans_rollback() 178 178 { … … 191 191 return TRUE; 192 192 } 193 193 194 194 // -------------------------------------------------------------------- 195 195 … … 201 201 * @return string 202 202 */ 203 function escape_str($str) 204 { 203 function escape_str($str) 204 { 205 205 // Escape single quotes 206 206 return str_replace("'", "''", $str); 207 207 } 208 208 209 209 // -------------------------------------------------------------------- 210 210 … … 219 219 return @mssql_rows_affected($this->conn_id); 220 220 } 221 221 222 222 // -------------------------------------------------------------------- 223 223 … … 250 250 if ($table == '') 251 251 return '0'; 252 252 253 253 $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); 254 254 255 255 if ($query->num_rows() == 0) 256 256 return '0'; … … 272 272 function _list_tables() 273 273 { 274 return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; 274 return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; 275 275 } 276 276 … … 288 288 function _list_columns($table = '') 289 289 { 290 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; 290 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; 291 291 } 292 292 … … 304 304 function _field_data($table) 305 305 { 306 return "SELECT TOP 1 * FROM ".$this->_escape_table($table); 306 return "SELECT TOP 1 * FROM ".$this->_escape_table($table); 307 307 } 308 308 … … 320 320 return ''; 321 321 } 322 322 323 323 // -------------------------------------------------------------------- 324 324 … … 334 334 return ''; 335 335 } 336 336 337 337 // -------------------------------------------------------------------- 338 338 … … 350 350 { 351 351 // I don't believe this is necessary with MS SQL. Not sure, though. - Rick 352 352 353 353 /* 354 354 if (stristr($table, '.')) … … 357 357 } 358 358 */ 359 359 360 360 return $table; 361 } 362 361 } 362 363 363 // -------------------------------------------------------------------- 364 364 … … 375 375 */ 376 376 function _insert($table, $keys, $values) 377 { 377 { 378 378 return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; 379 379 } 380 380 381 381 // -------------------------------------------------------------------- 382 382 … … 398 398 $valstr[] = $key." = ".$val; 399 399 } 400 400 401 401 return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); 402 402 } 403 403 404 404 // -------------------------------------------------------------------- 405 405 … … 413 413 * @param array the where clause 414 414 * @return string 415 */ 415 */ 416 416 function _delete($table, $where) 417 417 { … … 435 435 { 436 436 $i = $limit + $offset; 437 438 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); 437 438 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); 439 439 } 440 440 … … 451 451 { 452 452 @mssql_close($conn_id); 453 } 453 } 454 454 455 455 } -
trunk/system/database/drivers/mysql/mysql_driver.php
r24 r94 35 35 * of affected rows to be shown. Uses a preg_replace when enabled, 36 36 * adding a bit more processing to all queries. 37 */ 37 */ 38 38 var $delete_hack = TRUE; 39 39 … … 43 43 * @access private called by the base class 44 44 * @return resource 45 */ 45 */ 46 46 function db_connect() 47 47 { 48 48 return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); 49 49 } 50 50 51 51 // -------------------------------------------------------------------- 52 52 … … 56 56 * @access private called by the base class 57 57 * @return resource 58 */ 58 */ 59 59 function db_pconnect() 60 60 { 61 61 return @mysql_pconnect($this->hostname, $this->username, $this->password); 62 62 } 63 63 64 64 // -------------------------------------------------------------------- 65 65 … … 69 69 * @access private called by the base class 70 70 * @return resource 71 */ 71 */ 72 72 function db_select() 73 73 { … … 96 96 * @param string an SQL query 97 97 * @return resource
