Changeset 2327
- Timestamp:
- 03/23/2008 03:43:03 AM (8 months ago)
- Location:
- branches/2.2-database/system/libraries
- Files:
-
- 4 modified
-
Database_Insert.php (modified) (2 diffs)
-
Database_Query_Builder.php (modified) (37 diffs)
-
Database_Update.php (modified) (1 diff)
-
Database_Where.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2-database/system/libraries/Database_Insert.php
r2307 r2327 17 17 * @param string table name 18 18 * @param array array of key/value pairs to insert 19 * @return object This Database object.19 * @return object Database_Result 20 20 */ 21 21 public function insert($table = '', $set = NULL) … … 26 26 } 27 27 28 if ($this->set == NULL)28 if ($this->set === NULL) 29 29 throw new Kohana_Database_Exception('database.must_use_set'); 30 30 -
branches/2.2-database/system/libraries/Database_Query_Builder.php
r2323 r2327 29 29 * Selects the column names for a database query. 30 30 * 31 * @chainable 31 32 * @param string string or array of column names to select 32 33 * @return object This Database object. … … 58 59 $this->distinct = TRUE; 59 60 } 60 else 61 elseif (strpos($val, '.') !== FALSE) 61 62 { 62 $val = (strpos($val, '.') !== FALSE) ? $this->config['table_prefix'].$val :$val;63 $val = $this->config['table_prefix'].$val; 63 64 } 64 65 … … 75 76 * Selects the from table(s) for a database query. 76 77 * 78 * @chainable 77 79 * @param string string or array of tables to select 78 80 * @return object This Database object. … … 82 84 foreach((array) $sql as $val) 83 85 { 84 if (($val = trim($val)) == '') continue;86 if (($val = trim($val)) === '') continue; 85 87 86 88 $this->from[] = $this->config['table_prefix'].$val; … … 93 95 * Generates the JOIN portion of the query. 94 96 * 97 * @chainable 95 98 * @param string table name 96 99 * @param string|array where key or array of key => value pairs … … 109 112 $type = ''; 110 113 } 111 else112 {113 $type .= ' ';114 }115 114 } 116 115 117 116 $cond = array(); 118 $keys = is_array($key) ? $key : array($key => $value); 117 $keys = is_array($key) ? $key : array($key => $value); 118 119 119 foreach ($keys as $key => $value) 120 120 { … … 123 123 } 124 124 125 $this->join[] = $type.' JOIN '.$this->driver->escape_column($this->config['table_prefix'].$table).' ON '.implode(' ', $cond);125 $this->join[] = $type.' JOIN '.$this->driver->escape_column($this->config['table_prefix'].$table).' ON '.implode(' ', $cond); 126 126 127 127 return $this; … … 131 131 * Selects the where(s) for a database query. 132 132 * 133 * @chainable 133 134 * @param string|array key name or array of key => value pairs 134 135 * @param string value to match with key … … 153 154 * Selects the or where(s) for a database query. 154 155 * 156 * @chainable 155 157 * @param string|array key name or array of key => value pairs 156 158 * @param string value to match with key … … 175 177 * Selects the like(s) for a database query. 176 178 * 179 * @chainable 177 180 * @param string|array field name or array of field => match pairs 178 181 * @param string like value to match with field … … 195 198 * Selects the or like(s) for a database query. 196 199 * 200 * @chainable 197 201 * @param string|array field name or array of field => match pairs 198 202 * @param string like value to match with field … … 215 219 * Selects the not like(s) for a database query. 216 220 * 221 * @chainable 217 222 * @param string|array field name or array of field => match pairs 218 223 * @param string like value to match with field … … 235 240 * Selects the or not like(s) for a database query. 236 241 * 242 * @chainable 237 243 * @param string|array field name or array of field => match pairs 238 244 * @param string like value to match with field … … 255 261 * Selects the like(s) for a database query. 256 262 * 263 * @chainable 257 264 * @param string|array field name or array of field => match pairs 258 265 * @param string like value to match with field … … 275 282 * Selects the or like(s) for a database query. 276 283 * 284 * @chainable 277 285 * @param string|array field name or array of field => match pairs 278 286 * @param string like value to match with field … … 295 303 * Selects the not regex(s) for a database query. 296 304 * 305 * @chainable 297 306 * @param string|array field name or array of field => match pairs 298 307 * @param string regex value to match with field … … 315 324 * Selects the or not regex(s) for a database query. 316 325 * 326 * @chainable 317 327 * @param string|array field name or array of field => match pairs 318 328 * @param string regex value to match with field … … 335 345 * Chooses the column to group by in a select query. 336 346 * 347 * @chainable 337 348 * @param string column name to group by 338 349 * @return object This Database object. … … 347 358 foreach ($by as $val) 348 359 { 349 $val = trim($val); 350 351 if ($val != '') 360 if (($val = trim($val)) !== '') 352 361 { 353 362 $this->groupby[] = $val; … … 361 370 * Selects the having(s) for a database query. 362 371 * 372 * @chainable 363 373 * @param string|array key name or array of key => value pairs 364 374 * @param string value to match with key … … 369 379 { 370 380 $this->having[] = $this->driver->where($key, $value, 'AND', count($this->having), TRUE); 381 371 382 return $this; 372 383 } … … 375 386 * Selects the or having(s) for a database query. 376 387 * 388 * @chainable 377 389 * @param string|array key name or array of key => value pairs 378 390 * @param string value to match with key … … 383 395 { 384 396 $this->having[] = $this->driver->where($key, $value, 'OR', count($this->having), TRUE); 397 385 398 return $this; 386 399 } … … 389 402 * Chooses which column(s) to order the select query by. 390 403 * 404 * @chainable 391 405 * @param string|array column(s) to order on, can be an array, single column, or comma seperated list of columns 392 406 * @param string direction of the order … … 416 430 foreach ($orderby as $field) 417 431 { 418 $field = trim($field); 419 420 if ($field != '') 432 if (($field = trim($field)) !== '') 421 433 { 422 434 $order[] = $this->driver->escape_column($field); … … 424 436 } 425 437 $this->orderby[] = implode(',', $order).$direction; 438 426 439 return $this; 427 440 } … … 430 443 * Selects the limit section of a query. 431 444 * 445 * @chainable 432 446 * @param integer number of rows to limit result to 433 447 * @param integer offset in result to start returning rows from … … 436 450 public function limit($limit, $offset = FALSE) 437 451 { 438 $this->limit = (int) $limit;439 $this->offset( ($offset === FALSE)? 0 :$offset);452 $this->limit = (int) $limit; 453 $this->offset($offset); 440 454 441 455 return $this; … … 445 459 * Sets the offset portion of a query. 446 460 * 461 * @chainable 447 462 * @param integer offset value 448 463 * @return object This Database object. … … 458 473 * Allows key/value pairs to be set for inserting or updating. 459 474 * 475 * @chainable 460 476 * @param string|array key name or array of key => value pairs 461 477 * @param string value to match with key … … 479 495 /** 480 496 * Adds an "IN" condition to the where clause 481 * 497 * 498 * @chainable 482 499 * @param string Name of the column being examined 483 500 * @param mixed An array or string to match against … … 501 518 } 502 519 } 503 $values = implode( ",", $escaped_values);520 $values = implode(',', $escaped_values); 504 521 } 505 522 $this->where($this->driver->escape_column($field).' '.($not === TRUE ? 'NOT ' : '').'IN ('.$values.')'); … … 510 527 /** 511 528 * Adds a "NOT IN" condition to the where clause 512 * 529 * 530 * @chainable 513 531 * @param string Name of the column being examined 514 532 * @param mixed An array or string to match against … … 525 543 * @param string table name 526 544 * @param array array of key/value pairs to merge 527 * @return object This Database object.545 * @return object Database_Result 528 546 */ 529 547 public function merge($table = '', $set = NULL) … … 534 552 } 535 553 536 if ($this->set == NULL)554 if ($this->set === NULL) 537 555 throw new Kohana_Database_Exception('database.must_use_set'); 538 556 … … 561 579 public function compile($table = '', $limit = NULL, $offset = NULL) 562 580 { 563 if ($table != '')581 if ($table !== '') 564 582 { 565 583 $this->from($table); … … 574 592 575 593 $this->reset(); 576 577 594 return $sql; 578 595 } -
branches/2.2-database/system/libraries/Database_Update.php
r2307 r2327 21 21 * @param array associative array of update values 22 22 * @param array where clause 23 * @return object This Database object.23 * @return object Database_Result 24 24 */ 25 25 public function update($table = '', $set = NULL, $where = NULL) 26 26 { 27 if ( is_array($set))27 if (is_array($set)) 28 28 { 29 29 $this->set($set); -
branches/2.2-database/system/libraries/Database_Where.php
r2323 r2327 32 32 private function add($args, $type) 33 33 { 34 // Count the arguments: one, two or three? 34 35 $num_args = count($args); 35 // Get the arguments. We can have one, two or three 36 if ($num_args == 1 AND is_object($args[0])) // A where object was passed 36 37 // A where object was passed 38 if ($num_args === 1 AND is_object($args[0])) 37 39 { 38 40 $this->where[] = array($args[0], $type); 39 41 } 40 elseif ($num_args == 2 OR ($num_args == 1 AND is_array($args[0]))) // An array for the conditions 42 // An array for the conditions 43 elseif ($num_args === 2 OR ($num_args === 1 AND is_array($args[0]))) 41 44 { 42 $operator = $num_args == 2 ? $args[1] : '=';45 $operator = $num_args === 2 ? $args[1] : '='; 43 46 44 47 foreach ($args as $key => $value) … … 47 50 } 48 51 } 49 elseif ($num_args == 3) // Seperate conditions 52 // Separate conditions 53 elseif ($num_args === 3) 50 54 { 51 55 $this->where[] = array(array('key' => $args[0], 'value' => $args[1], 'op' => $args[2]), $type); … … 72 76 foreach ($this->where as $where) 73 77 { 74 $where_string .=$this->db->driver->escape_column($where[0]['key']).' '.$where[0]['op'].' '.$this->db->driver->escape($where[0]['value']).(count($this->where) > 1 ? ' '.$where[1].' ' : '');78 $where_string .= $this->db->driver->escape_column($where[0]['key']).' '.$where[0]['op'].' '.$this->db->driver->escape($where[0]['value']).(count($this->where) > 1 ? ' '.$where[1].' ' : ''); 75 79 } 76 $where_string .=')';80 $where_string .= ')'; 77 81 78 82 return $where_string;
