Changeset 94

Show
Ignore:
Timestamp:
05/27/2007 11:24:08 PM (18 months ago)
Author:
Shadowhand
Message:

Fixing #1 (changes to User Guide) and #47

Changed files:
user_guide/libraries/Input.php
system/database/DB_active_rec.php
system/database/drivers/*/*_driver.php (escape_str method)

Location:
trunk
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/database/DB_active_rec.php

    r82 r94  
    2828class CI_DB_active_record extends CI_DB_driver { 
    2929 
    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(); 
    4443 
    4544        /** 
     
    133132                                $type .= ' '; 
    134133                        } 
    135                 } 
    136  
    137                 if ($this->dbprefix) 
    138                 { 
    139                         $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); 
    140134                } 
    141135 
     
    309303        function groupby($by) 
    310304        { 
    311                 if (is_string($by)) 
    312                 { 
    313                         $by = explode(',', $by); 
     305                if ( ! is_array($by)) 
     306                { 
     307                        $by = explode(',', (string) $by); 
    314308                } 
    315309 
     
    338332        function having($key, $value = '') 
    339333        { 
    340                 return $this->_having($key, $value, 'AND '); 
     334                return $this->_having($key, $value, 'AND'); 
    341335        } 
    342336 
     
    355349        function orhaving($key, $value = '') 
    356350        { 
    357                 return $this->_having($key, $value, 'OR '); 
     351                return $this->_having($key, $value, 'OR'); 
    358352        } 
    359353 
     
    370364         * @return      object 
    371365         */ 
    372         function _having($key, $value = '', $type = 'AND ') 
    373         { 
     366        function _having($key, $value = '', $type = 'AND') 
     367        { 
     368                $type = trim($type).' '; 
     369 
    374370                if ( ! is_array($key)) 
    375371                { 
     
    379375                foreach ($key as $k => $v) 
    380376                { 
    381                         $prefix = (count($this->ar_having) == 0) ? '' : $type; 
     377                        $prefix = (count($this->ar_having) < 1) ? '' : $type; 
    382378 
    383379                        if ($v != '') 
     
    403399        function orderby($orderby, $direction = '') 
    404400        { 
    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"; 
    408406                } 
    409407 
     
    427425 
    428426                if ($offset != '') 
     427                { 
    429428                        $this->ar_offset = $offset; 
     429                } 
    430430 
    431431                return $this; 
     
    562562                } 
    563563 
    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); 
    571567                } 
    572568 
     
    575571                        if ( ! isset($this->ar_from[0])) 
    576572                        { 
    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); 
    582574                        } 
    583575 
     
    611603                } 
    612604 
    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); 
    620608                } 
    621609 
     
    624612                        if ( ! isset($this->ar_from[0])) 
    625613                        { 
    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); 
    631615                        } 
    632616 
     
    663647                        if ( ! isset($this->ar_from[0])) 
    664648                        { 
    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); 
    670650                        } 
    671651 
     
    678658                } 
    679659 
    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); 
    687663                } 
    688664 
     
    737713        { 
    738714                return $this->from($table); 
    739                 return $this; 
    740715        } 
    741716 
     
    764739        { 
    765740                $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); 
    772743        } 
    773744 
     
    889860        function _reset_select() 
    890861        { 
    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(); 
    903874        } 
    904875 
     
    915886        function _reset_write() 
    916887        { 
    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(); 
    920891        } 
    921892 
  • trunk/system/database/drivers/mssql/mssql_driver.php

    r24 r94  
    3636         * @access      private called by the base class 
    3737         * @return      resource 
    38          */      
     38         */ 
    3939        function db_connect() 
    4040        { 
    4141                return @mssql_connect($this->hostname, $this->username, $this->password); 
    4242        } 
    43          
     43 
    4444        // -------------------------------------------------------------------- 
    4545 
     
    4949         * @access      private called by the base class 
    5050         * @return      resource 
    51          */      
     51         */ 
    5252        function db_pconnect() 
    5353        { 
    5454                return @mssql_pconnect($this->hostname, $this->username, $this->password); 
    5555        } 
    56          
     56 
    5757        // -------------------------------------------------------------------- 
    5858 
     
    6262         * @access      private called by the base class 
    6363         * @return      resource 
    64          */      
     64         */ 
    6565        function db_select() 
    6666        { 
     
    6969 
    7070        // -------------------------------------------------------------------- 
    71          
     71 
    7272        /** 
    7373         * Version number query string 
     
    8080                return "SELECT version() AS ver"; 
    8181        } 
    82          
     82 
    8383        // -------------------------------------------------------------------- 
    8484 
     
    8989         * @param       string  an SQL query 
    9090         * @return      resource 
    91          */      
     91         */ 
    9292        function _execute($sql) 
    9393        { 
     
    9595                return @mssql_query($sql, $this->conn_id); 
    9696        } 
    97          
     97 
    9898        // -------------------------------------------------------------------- 
    9999 
     
    106106         * @param       string  an SQL query 
    107107         * @return      string 
    108          */      
     108         */ 
    109109        function _prep_query($sql) 
    110110        { 
     
    118118         * 
    119119         * @access      public 
    120          * @return      bool             
    121          */      
     120         * @return      bool 
     121         */ 
    122122        function trans_begin($test_mode = FALSE) 
    123123        { 
     
    126126                        return TRUE; 
    127127                } 
    128                  
     128 
    129129                // When transactions are nested we only begin/commit/rollback the outermost ones 
    130130                if ($this->_trans_depth > 0) 
     
    148148         * 
    149149         * @access      public 
    150          * @return      bool             
    151          */      
     150         * @return      bool 
     151         */ 
    152152        function trans_commit() 
    153153        { 
     
    173173         * 
    174174         * @access      public 
    175          * @return      bool             
    176          */      
     175         * @return      bool 
     176         */ 
    177177        function trans_rollback() 
    178178        { 
     
    191191                return TRUE; 
    192192        } 
    193          
     193 
    194194        // -------------------------------------------------------------------- 
    195195 
     
    201201         * @return      string 
    202202         */ 
    203         function escape_str($str)        
    204         {        
     203        function escape_str($str) 
     204        { 
    205205                // Escape single quotes 
    206206                return str_replace("'", "''", $str); 
    207207        } 
    208          
     208 
    209209        // -------------------------------------------------------------------- 
    210210 
     
    219219                return @mssql_rows_affected($this->conn_id); 
    220220        } 
    221          
     221 
    222222        // -------------------------------------------------------------------- 
    223223 
     
    250250                if ($table == '') 
    251251                        return '0'; 
    252          
     252 
    253253                $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); 
    254                  
     254 
    255255                if ($query->num_rows() == 0) 
    256256                        return '0'; 
     
    272272        function _list_tables() 
    273273        { 
    274                 return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";             
     274                return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; 
    275275        } 
    276276 
     
    288288        function _list_columns($table = '') 
    289289        { 
    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)."'"; 
    291291        } 
    292292 
     
    304304        function _field_data($table) 
    305305        { 
    306                 return "SELECT TOP 1 * FROM ".$this->_escape_table($table);      
     306                return "SELECT TOP 1 * FROM ".$this->_escape_table($table); 
    307307        } 
    308308 
     
    320320                return ''; 
    321321        } 
    322          
     322 
    323323        // -------------------------------------------------------------------- 
    324324 
     
    334334                return ''; 
    335335        } 
    336          
     336 
    337337        // -------------------------------------------------------------------- 
    338338 
     
    350350        { 
    351351                // I don't believe this is necessary with MS SQL.  Not sure, though. - Rick 
    352          
     352 
    353353                /* 
    354354                if (stristr($table, '.')) 
     
    357357                } 
    358358                */ 
    359                  
     359 
    360360                return $table; 
    361         }        
    362          
     361        } 
     362 
    363363        // -------------------------------------------------------------------- 
    364364 
     
    375375         */ 
    376376        function _insert($table, $keys, $values) 
    377         {        
     377        { 
    378378                return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; 
    379379        } 
    380          
     380 
    381381        // -------------------------------------------------------------------- 
    382382 
     
    398398                        $valstr[] = $key." = ".$val; 
    399399                } 
    400          
     400 
    401401                return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); 
    402402        } 
    403          
     403 
    404404        // -------------------------------------------------------------------- 
    405405 
     
    413413         * @param       array   the where clause 
    414414         * @return      string 
    415          */      
     415         */ 
    416416        function _delete($table, $where) 
    417417        { 
     
    435435        { 
    436436                $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); 
    439439        } 
    440440 
     
    451451        { 
    452452                @mssql_close($conn_id); 
    453         }        
     453        } 
    454454 
    455455} 
  • trunk/system/database/drivers/mysql/mysql_driver.php

    r24 r94  
    3535         * of affected rows to be shown. Uses a preg_replace when enabled, 
    3636         * adding a bit more processing to all queries. 
    37          */      
     37         */ 
    3838        var $delete_hack = TRUE; 
    3939 
     
    4343         * @access      private called by the base class 
    4444         * @return      resource 
    45          */      
     45         */ 
    4646        function db_connect() 
    4747        { 
    4848                return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); 
    4949        } 
    50          
     50 
    5151        // -------------------------------------------------------------------- 
    5252 
     
    5656         * @access      private called by the base class 
    5757         * @return      resource 
    58          */      
     58         */ 
    5959        function db_pconnect() 
    6060        { 
    6161                return @mysql_pconnect($this->hostname, $this->username, $this->password); 
    6262        } 
    63          
     63 
    6464        // -------------------------------------------------------------------- 
    6565 
     
    6969         * @access      private called by the base class 
    7070         * @return      resource 
    71          */      
     71         */ 
    7272        function db_select() 
    7373        { 
     
    9696         * @param       string  an SQL query 
    9797         * @return      resource