Changeset 1020

Show
Ignore:
Timestamp:
07/18/08 22:48:10 (1 month ago)
Author:
laurentj
Message:

bug #572: bad sql syntax when using jDaoConditions with in/not operators. p=julien

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0.x/lib/jelix/CREDITS

    r1010 r1020  
    7474 - form plugin create always a form with method post (#592) 
    7575 - jDao: attribute groupby for method selectfirst (#447) 
     76 - jDao: fixed bug with jDaoConditions and IN operator (#572) 
    7677 - jZipCreator: empty dirs are not included in the archive (#570) 
    7778 - jForms: fixed bugs in jforms.js based on Martus' report (#554) 
  • branches/1.0.x/lib/jelix/dao/jDaoFactoryBase.class.php

    r1006 r1020  
    88 * @copyright   2005-2007 Laurent Jouanneau 
    99 * @copyright   2007 Loic Mathaud 
    10  * @copyright   2007 Julien Issler 
     10 * @copyright   2007-2008 Julien Issler 
    1111 * @link        http://www.jelix.org 
    1212 * @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    362362                $prefixNoCondition = $prop['fieldName']; 
    363363 
    364             $prefix = $prefixNoCondition.' '.$cond['operator'].' '; // ' ' for LIKE.. 
    365  
    366             if (!is_array ($cond['value'])){ 
    367                 $value = $this->_prepareValue($cond['value'],$prop['datatype']); 
     364            $op = strtoupper($cond['operator']); 
     365            $prefix = $prefixNoCondition.' '.$op.' '; // ' ' for LIKE.. 
     366 
     367            if ($op == 'IN' || $op == 'NOT IN') { 
     368                if (is_array($cond['value'])) { 
     369                    $values = array(); 
     370                    foreach($cond['value'] as $value) 
     371                        $values[] = $this->_prepareValue($value, $prop['datatype']); 
     372                    $values = join(',', $values); 
     373                } 
     374                else 
     375                    $values = $cond['value']; 
     376 
     377                $r .= $prefix.'('.$values.')'; 
     378            } 
     379            else if (!is_array ($cond['value'])){ 
     380                $value = $this->_prepareValue($cond['value'], $prop['datatype']); 
    368381                if ($value === 'NULL'){ 
    369                     if($cond['operator'] == '='){ 
     382                    if($op == '='){ 
    370383                        $r .= $prefixNoCondition.' IS NULL'; 
    371384                    }else{ 
     
    375388                    $r .= $prefix.$value; 
    376389                } 
    377             }else
     390            } else
    378391                $r .= ' ( '; 
    379392                $firstCV = true; 
     
    382395                        $r .= ' or '; 
    383396                    } 
    384                     $value = $this->_prepareValue($conditionValue,$prop['datatype']); 
     397                    $value = $this->_prepareValue($conditionValue, $prop['datatype']); 
    385398                    if ($value === 'NULL'){ 
    386                         if($cond['operator'] == '='){ 
     399                        if($op == '='){ 
    387400                            $r .= $prefixNoCondition.' IS NULL'; 
    388401                        }else{ 
     
    402415                $r .= ' '.$condition->glueOp.' '; 
    403416            }else{ 
    404                 $notfirst=true; 
     417                $notfirst = true; 
    405418            } 
    406419            $r .= $this->_generateCondition($conditionDetail, $fields, $forSelect, false); 
  • branches/1.0.x/lib/jelix/forms/jFormsCompiler.class.php

    r968 r1020  
    244244                    $hasSelectedValues = true; 
    245245                }elseif(isset($control['selectedvalue'])){ 
    246                     $source[]='$ctrl->defaultValue=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');'; 
     246                    if ($controltype == 'menulist' ||  $controltype == 'radiobuttons') { 
     247                        $source[]='$ctrl->defaultValue=\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\';'; 
     248                    } else { 
     249                        $source[]='$ctrl->defaultValue=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');'; 
     250                    } 
    247251                    $hasSelectedValues = true; 
    248252                } 
  • branches/1.0.x/lib/jelix/forms/jFormsControl.class.php

    r790 r1020  
    133133class jFormsControlRadiobuttons extends jFormsControlDatasource { 
    134134    public $type="radiobuttons"; 
     135    public $defaultValue=''; 
    135136} 
    136137 
     
    181182class jFormsControlMenulist extends jFormsControlDatasource { 
    182183    public $type="menulist"; 
     184    public $defaultValue=''; 
    183185} 
    184186 
     
    311313} 
    312314 
    313  
    314315?> 
  • trunk/lib/jelix/CREDITS

    r1016 r1020  
    2222 - form plugin create always a form with method post (#592) 
    2323 - jDao: attribute groupby for method selectfirst (#447) 
     24 - jDao: fixed bug with jDaoConditions and IN operator (#572) 
    2425 - jZipCreator: empty dirs are not included in the archive (#570) 
    2526 - jForms: fixed bugs in jforms.js based on Martus' report (#554) 
  • trunk/lib/jelix/dao/jDaoFactoryBase.class.php

    r1015 r1020  
    88 * @copyright   2005-2007 Laurent Jouanneau 
    99 * @copyright   2007 Loic Mathaud 
    10  * @copyright   2007 Julien Issler 
     10 * @copyright   2007-2008 Julien Issler 
    1111 * @copyright   2008 Thomas 
    1212 * @link        http://www.jelix.org 
     
    272272                $count = 'DISTINCT '.$this->_tables[$props[$distinct]['table']]['realname'].'.'.$props[$distinct]['fieldName']; 
    273273        } 
    274          
     274 
    275275        $query = 'SELECT COUNT('.$count.') as c '.$this->_fromClause.$this->_whereClause; 
    276276        if ($searchcond->hasConditions ()){ 
     
    362362            } 
    363363        } 
    364          
     364 
    365365        if (count ($group)) { 
    366366            return ' GROUP BY '.implode(', ', $group); 
     
    368368        return ''; 
    369369    } 
    370      
     370 
    371371    /** 
    372372     * @internal it don't support isExpr property of a condition because of security issue (SQL injection) 
     
    389389                $prefixNoCondition = $prop['fieldName']; 
    390390 
    391             $prefix = $prefixNoCondition.' '.$cond['operator'].' '; // ' ' for LIKE.. 
    392  
    393             if (!is_array ($cond['value'])){ 
     391            $op = strtoupper($cond['operator']); 
     392            $prefix = $prefixNoCondition.' '.$op.' '; // ' ' for LIKE.. 
     393 
     394            if ($op == 'IN' || $op == 'NOT IN'){ 
     395                if(is_array($cond['value'])){ 
     396                    $values = array(); 
     397                    foreach($cond['value'] as $value) 
     398                        $values[] = $this->_prepareValue($value,$prop['datatype']); 
     399                    $values = join(',', $values); 
     400                } 
     401                else 
     402                    $values = $cond['value']; 
     403 
     404                $r .= $prefix.'('.$values.')'; 
     405            } 
     406            else if (!is_array ($cond['value'])){ 
    394407                $value = $this->_prepareValue($cond['value'],$prop['datatype']); 
    395408                if ($value === 'NULL'){ 
    396                     if($cond['operator'] == '='){ 
     409                    if($op == '='){ 
    397410                        $r .= $prefixNoCondition.' IS NULL'; 
    398411                    }else{ 
     
    411424                    $value = $this->_prepareValue($conditionValue,$prop['datatype']); 
    412425                    if ($value === 'NULL'){ 
    413                         if($cond['operator'] == '='){ 
     426                        if($op == '='){ 
    414427                            $r .= $prefixNoCondition.' IS NULL'; 
    415428                        }else{ 
Download in other formats: Unified Diff Zip Archive