Changeset 2060

Show
Ignore:
Timestamp:
02/15/2008 10:33:49 AM (11 months ago)
Author:
zombor
Message:

Adding NOT IN support too.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Database.php

    r2058 r2060  
    789789 
    790790        /** 
    791          * Adds an "in" condition to the where clause 
     791         * Adds an "IN" condition to the where clause 
    792792         *  
    793793         * @param   string  Name of the column being examined 
    794794         * @param   mixed   An array or string to match against 
     795         * @param   bool    Generate a NOT IN clause instead 
    795796         * @return  object  This Database object. 
    796797         */ 
    797         public function in($field, $values)  
     798        public function in($field, $values, $not = FALSE)  
    798799        { 
    799800                if (is_array($values)) 
     
    813814                        $values = implode(",", $escaped_values); 
    814815                } 
    815                 $this->where($this->driver->escape_column($field).' IN('.$values.')'); 
    816                  
    817                 return $this; 
     816                $this->where($this->driver->escape_column($field).' '.(!$not) ? 'NOT ' : ''.'IN ('.$values.')'); 
     817 
     818                return $this; 
     819        } 
     820 
     821        /** 
     822         * Adds a "NOT IN" condition to the where clause 
     823         *  
     824         * @param   string  Name of the column being examined 
     825         * @param   mixed   An array or string to match against 
     826         * @return  object  This Database object. 
     827         */ 
     828        public function notin($field, $values)  
     829        { 
     830                return $this->in($field, $values, TRUE); 
    818831        } 
    819832