Changeset 2327

Show
Ignore:
Timestamp:
03/23/2008 03:43:03 AM (8 months ago)
Author:
Geert
Message:

Database 2.2 cleanup

Location:
branches/2.2-database/system/libraries
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/2.2-database/system/libraries/Database_Insert.php

    r2307 r2327  
    1717         * @param   string  table name 
    1818         * @param   array   array of key/value pairs to insert 
    19          * @return  object  This Database object. 
     19         * @return  object  Database_Result 
    2020         */ 
    2121        public function insert($table = '', $set = NULL) 
     
    2626                } 
    2727 
    28                 if ($this->set == NULL) 
     28                if ($this->set === NULL) 
    2929                        throw new Kohana_Database_Exception('database.must_use_set'); 
    3030 
  • branches/2.2-database/system/libraries/Database_Query_Builder.php

    r2323 r2327  
    2929         * Selects the column names for a database query. 
    3030         * 
     31         * @chainable 
    3132         * @param   string  string or array of column names to select 
    3233         * @return  object  This Database object. 
     
    5859                                        $this->distinct = TRUE; 
    5960                                } 
    60                                 else 
     61                                elseif (strpos($val, '.') !== FALSE) 
    6162                                { 
    62                                         $val = (strpos($val, '.') !== FALSE) ? $this->config['table_prefix'].$val : $val; 
     63                                        $val = $this->config['table_prefix'].$val; 
    6364                                } 
    6465 
     
    7576         * Selects the from table(s) for a database query. 
    7677         * 
     78         * @chainable 
    7779         * @param   string  string or array of tables to select 
    7880         * @return  object  This Database object. 
     
    8284                foreach((array) $sql as $val) 
    8385                { 
    84                         if (($val = trim($val)) == '') continue; 
     86                        if (($val = trim($val)) === '') continue; 
    8587 
    8688                        $this->from[] = $this->config['table_prefix'].$val; 
     
    9395         * Generates the JOIN portion of the query. 
    9496         * 
     97         * @chainable 
    9598         * @param   string        table name 
    9699         * @param   string|array  where key or array of key => value pairs 
     
    109112                                $type = ''; 
    110113                        } 
    111                         else 
    112                         { 
    113                                 $type .= ' '; 
    114                         } 
    115114                } 
    116115 
    117116                $cond = array(); 
    118                 $keys  = is_array($key) ? $key : array($key => $value); 
     117                $keys = is_array($key) ? $key : array($key => $value); 
     118 
    119119                foreach ($keys as $key => $value) 
    120120                { 
     
    123123                } 
    124124 
    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); 
    126126 
    127127                return $this; 
     
    131131         * Selects the where(s) for a database query. 
    132132         * 
     133         * @chainable 
    133134         * @param   string|array  key name or array of key => value pairs 
    134135         * @param   string        value to match with key 
     
    153154         * Selects the or where(s) for a database query. 
    154155         * 
     156         * @chainable 
    155157         * @param   string|array  key name or array of key => value pairs 
    156158         * @param   string        value to match with key 
     
    175177         * Selects the like(s) for a database query. 
    176178         * 
     179         * @chainable 
    177180         * @param   string|array  field name or array of field => match pairs 
    178181         * @param   string        like value to match with field 
     
    195198         * Selects the or like(s) for a database query. 
    196199         * 
     200         * @chainable 
    197201         * @param   string|array  field name or array of field => match pairs 
    198202         * @param   string        like value to match with field 
     
    215219         * Selects the not like(s) for a database query. 
    216220         * 
     221         * @chainable 
    217222         * @param   string|array  field name or array of field => match pairs 
    218223         * @param   string        like value to match with field 
     
    235240         * Selects the or not like(s) for a database query. 
    236241         * 
     242         * @chainable 
    237243         * @param   string|array  field name or array of field => match pairs 
    238244         * @param   string        like value to match with field 
     
    255261         * Selects the like(s) for a database query. 
    256262         * 
     263         * @chainable 
    257264         * @param   string|array  field name or array of field => match pairs 
    258265         * @param   string        like value to match with field 
     
    275282         * Selects the or like(s) for a database query. 
    276283         * 
     284         * @chainable 
    277285         * @param   string|array  field name or array of field => match pairs 
    278286         * @param   string        like value to match with field 
     
    295303         * Selects the not regex(s) for a database query. 
    296304         * 
     305         * @chainable 
    297306         * @param   string|array  field name or array of field => match pairs 
    298307         * @param   string        regex value to match with field 
     
    315324         * Selects the or not regex(s) for a database query. 
    316325         * 
     326         * @chainable 
    317327         * @param   string|array  field name or array of field => match pairs 
    318328         * @param   string        regex value to match with field 
     
    335345         * Chooses the column to group by in a select query. 
    336346         * 
     347         * @chainable 
    337348         * @param   string  column name to group by 
    338349         * @return  object  This Database object. 
     
    347358                foreach ($by as $val) 
    348359                { 
    349                         $val = trim($val); 
    350  
    351                         if ($val != '') 
     360                        if (($val = trim($val)) !== '') 
    352361                        { 
    353362                                $this->groupby[] = $val; 
     
    361370         * Selects the having(s) for a database query. 
    362371         * 
     372         * @chainable 
    363373         * @param   string|array  key name or array of key => value pairs 
    364374         * @param   string        value to match with key 
     
    369379        { 
    370380                $this->having[] = $this->driver->where($key, $value, 'AND', count($this->having), TRUE); 
     381 
    371382                return $this; 
    372383        } 
     
    375386         * Selects the or having(s) for a database query. 
    376387         * 
     388         * @chainable 
    377389         * @param   string|array  key name or array of key => value pairs 
    378390         * @param   string        value to match with key 
     
    383395        { 
    384396                $this->having[] = $this->driver->where($key, $value, 'OR', count($this->having), TRUE); 
     397 
    385398                return $this; 
    386399        } 
     
    389402         * Chooses which column(s) to order the select query by. 
    390403         * 
     404         * @chainable 
    391405         * @param   string|array  column(s) to order on, can be an array, single column, or comma seperated list of columns 
    392406         * @param   string        direction of the order 
     
    416430                foreach ($orderby as $field) 
    417431                { 
    418                         $field = trim($field); 
    419  
    420                         if ($field != '') 
     432                        if (($field = trim($field)) !== '') 
    421433                        { 
    422434                                $order[] = $this->driver->escape_column($field); 
     
    424436                } 
    425437                $this->orderby[] = implode(',', $order).$direction; 
     438 
    426439                return $this; 
    427440        } 
     
    430443         * Selects the limit section of a query. 
    431444         * 
     445         * @chainable 
    432446         * @param   integer  number of rows to limit result to 
    433447         * @param   integer  offset in result to start returning rows from 
     
    436450        public function limit($limit, $offset = FALSE) 
    437451        { 
    438                 $this->limit  = (int) $limit; 
    439                 $this->offset(($offset === FALSE)? 0 : $offset); 
     452                $this->limit = (int) $limit; 
     453                $this->offset($offset); 
    440454 
    441455                return $this; 
     
    445459         * Sets the offset portion of a query. 
    446460         * 
     461         * @chainable 
    447462         * @param   integer  offset value 
    448463         * @return  object   This Database object. 
     
    458473         * Allows key/value pairs to be set for inserting or updating. 
    459474         * 
     475         * @chainable 
    460476         * @param   string|array  key name or array of key => value pairs 
    461477         * @param   string        value to match with key 
     
    479495        /** 
    480496         * Adds an "IN" condition to the where clause 
    481          *  
     497         * 
     498         * @chainable 
    482499         * @param   string  Name of the column being examined 
    483500         * @param   mixed   An array or string to match against 
     
    501518                                } 
    502519                        } 
    503                         $values = implode(",", $escaped_values); 
     520                        $values = implode(',', $escaped_values); 
    504521                } 
    505522                $this->where($this->driver->escape_column($field).' '.($not === TRUE ? 'NOT ' : '').'IN ('.$values.')'); 
     
    510527        /** 
    511528         * Adds a "NOT IN" condition to the where clause 
    512          *  
     529         * 
     530         * @chainable 
    513531         * @param   string  Name of the column being examined 
    514532         * @param   mixed   An array or string to match against 
     
    525543         * @param   string  table name 
    526544         * @param   array   array of key/value pairs to merge 
    527          * @return  object  This Database object. 
     545         * @return  object  Database_Result 
    528546         */ 
    529547        public function merge($table = '', $set = NULL) 
     
    534552                } 
    535553 
    536                 if ($this->set == NULL) 
     554                if ($this->set === NULL) 
    537555                        throw new Kohana_Database_Exception('database.must_use_set'); 
    538556 
     
    561579        public function compile($table = '', $limit = NULL, $offset = NULL) 
    562580        { 
    563                 if ($table != '') 
     581                if ($table !== '') 
    564582                { 
    565583                        $this->from($table); 
     
    574592 
    575593                $this->reset(); 
    576  
    577594                return $sql; 
    578595        } 
  • branches/2.2-database/system/libraries/Database_Update.php

    r2307 r2327  
    2121         * @param   array   associative array of update values 
    2222         * @param   array   where clause 
    23          * @return  object  This Database object. 
     23         * @return  object  Database_Result 
    2424         */ 
    2525        public function update($table = '', $set = NULL, $where = NULL) 
    2626        { 
    27                 if ( is_array($set)) 
     27                if (is_array($set)) 
    2828                { 
    2929                        $this->set($set); 
  • branches/2.2-database/system/libraries/Database_Where.php

    r2323 r2327  
    3232        private function add($args, $type) 
    3333        { 
     34                // Count the arguments: one, two or three? 
    3435                $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])) 
    3739                { 
    3840                        $this->where[] = array($args[0], $type); 
    3941                } 
    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]))) 
    4144                { 
    42                         $operator = $num_args == 2 ? $args[1] : '='; 
     45                        $operator = $num_args === 2 ? $args[1] : '='; 
    4346 
    4447                        foreach ($args as $key => $value) 
     
    4750                        } 
    4851                } 
    49                 elseif ($num_args == 3) // Seperate conditions 
     52                // Separate conditions 
     53                elseif ($num_args === 3) 
    5054                { 
    5155                        $this->where[] = array(array('key' => $args[0], 'value' => $args[1], 'op' => $args[2]), $type); 
     
    7276                foreach ($this->where as $where) 
    7377                { 
    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].' ' : ''); 
    7579                } 
    76                 $where_string.=')'; 
     80                $where_string .= ')'; 
    7781 
    7882                return $where_string;