Changeset 375

Show
Ignore:
Timestamp:
03/01/07 11:30:06 (2 years ago)
Author:
laurentj
Message:

fix bug ticket #125 : jDao, update methods are not generated correctly when primary table contains only primary keys; in this case, update is not consistent so an exception should be thrown

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix-modules/jelix/locales/en_EN/dao.ISO-8859-1.properties

    r354 r375  
    66 
    77error.keys.missing=(501) Identifier is missing 
     8error.update.impossible=(502)Update is impossible with this dao because table contains only primary keys (DAO: %1$s, file: %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_EN/dao.UTF-8.properties

    r354 r375  
    66 
    77error.keys.missing=(501) Identifier is missing 
     8error.update.impossible=(502)Update is impossible with this dao because table contains only primary keys (DAO: %1$s, file: %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_EN/daoxml.ISO-8859-1.properties

    r364 r375  
    4646method.condition.driver.notallowed= (561)DAO %1$s, method %3$, the driver of the database used here is not allowed accordind to the definition of the condition (file %2$s) 
    4747method.orderitem.parameter.unknow= (563)DAO %1$s, method %3$,  unknow parameter %4$s in the orderitem tag (file %2$s) 
     48method.update.forbidden= (564)DAO %1$s, update method %3$s is forbidden because the main table contains only primary keys (file %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_EN/daoxml.UTF-8.properties

    r364 r375  
    4646method.condition.driver.notallowed= (561)DAO %1$s, method %3$, the driver of the database used here is not allowed accordind to the definition of the condition (file %2$s) 
    4747method.orderitem.parameter.unknow= (563)DAO %1$s, method %3$,  unknow parameter %4$s in the orderitem tag (file %2$s) 
     48method.update.forbidden= (564)DAO %1$s, update method %3$s is forbidden because the main table contains only primary keys (file %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_US/dao.ISO-8859-1.properties

    r23 r375  
    66 
    77error.keys.missing=(501) Identifier is missing 
     8error.update.impossible=(502)Update is impossible with this dao because table contains only primary keys (DAO: %1$s, file: %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_US/dao.UTF-8.properties

    r354 r375  
    66 
    77error.keys.missing=(501) Identifier is missing 
     8error.update.impossible=(502)Update is impossible with this dao because table contains only primary keys (DAO: %1$s, file: %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_US/daoxml.ISO-8859-1.properties

    r364 r375  
    4646method.condition.driver.notallowed= (561)DAO %1$s, method %3$, the driver of the database used here is not allowed accordind to the definition of the condition (file %2$s) 
    4747method.orderitem.parameter.unknow= (563)DAO %1$s, method %3$,  unknow parameter %4$s in the orderitem tag (file %2$s) 
     48method.update.forbidden= (564)DAO %1$s, update method %3$s is forbidden because the main table contains only primary keys (file %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/en_US/daoxml.UTF-8.properties

    r364 r375  
    4646method.condition.driver.notallowed= (561)DAO %1$s, method %3$, the driver of the database used here is not allowed accordind to the definition of the condition (file %2$s) 
    4747method.orderitem.parameter.unknow= (563)DAO %1$s, method %3$,  unknow parameter %4$s in the orderitem tag (file %2$s) 
     48method.update.forbidden= (564)DAO %1$s, update method %3$s is forbidden because the main table contains only primary keys (file %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/fr_FR/dao.ISO-8859-1.properties

    r23 r375  
    66 
    77error.keys.missing=(501)Identifiant(s) manquant(s) 
     8error.update.impossible=(502)Update impossible sur une table ne contenant que des cl�primaires (DAO %1$s, fichier %2$s) 
    89 
  • trunk/lib/jelix-modules/jelix/locales/fr_FR/dao.UTF-8.properties

    r112 r375  
    66 
    77error.keys.missing=(501)Identifiant(s) manquant(s) 
    8  
     8error.update.impossible=(502)Update impossible sur une table ne contenant que des clés primaires (DAO %1$s, fichier %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/fr_FR/daoxml.ISO-8859-1.properties

    r364 r375  
    4646method.condition.driver.notallowed= (561)DAO %1$s, m�ode %3$, le driver de base de donn� utilis�'est pas autoris�'apr�la d�nition de la condition (fichier %2$s) 
    4747method.orderitem.parameter.unknow= (563)DAO %1$s, nom de param�e %4$s inconnu dans la balise orderitem de la m�ode %3$s (fichier %2$s) 
     48 
     49method.update.forbidden= (564)DAO %1$s, la m�ode %3$s de type update est interdite car la table principale ne contient que des cl�primaires (fichier %2$s) 
  • trunk/lib/jelix-modules/jelix/locales/fr_FR/daoxml.UTF-8.properties

    r364 r375  
    2828method.duplicate= (545)DAO %1$s, la méthode %3$s est déjà définie (fichier %2$s) 
    2929 
    30  
    3130method.condition.unknown= (546)DAO %1$s, méthode %3$s, la condition %4$s n'est pas reconnu (fichier %2$s) 
    3231method.property.unknown= (547)DAO %1$s, la méthode %3$s utilise une propriété (%4$s) qui n'existe pas dans la DAO (fichier %2$s) 
     
    4645method.condition.driver.notallowed= (561)DAO %1$s, méthode %3$, le driver de base de données utilisé n'est pas autorisé d'après la définition de la condition (fichier %2$s) 
    4746method.orderitem.parameter.unknow= (563)DAO %1$s, nom de paramètre %4$s inconnu dans la balise orderitem de la méthode %3$s (fichier %2$s) 
     47method.update.forbidden= (564)DAO %1$s, la méthode %3$s de type update est interdite car la table principale ne contient que des clés primaires (fichier %2$s) 
  • trunk/lib/jelix/core/jConfigCompiler.class.php

    r367 r375  
    158158                exit; 
    159159            } 
     160            if(substr($p,-1) !='/') 
     161                $p.='/'; 
    160162            $allBasePath[]=$p; 
    161163            if ($handle = opendir($p)) { 
     
    188190                exit; 
    189191            } 
     192            if(substr($p,-1) !='/') 
     193                $p.='/'; 
    190194#if ENABLE_PHP_JELIX 
    191195            $config->_allBasePath[]=$p; 
  • trunk/lib/jelix/dao/jDaoGenerator.class.php

    r368 r375  
    185185 
    186186      $src[] = 'public function update ($record){'; 
    187       $src[] = '   $query = \'UPDATE '.$pTableRealName.' SET '; 
    188  
    189187      list($fields, $values) = $this->_prepareValues($this->_getPropertiesBy('PrimaryFieldsExcludePk'),'updateMotif', 'record->'); 
    190  
    191       $sqlSet=''; 
    192       foreach($fields as $k=> $fname){ 
    193          $sqlSet.= ', '.$fname. '= '. $values[$k]; 
    194       } 
    195       $src[] = substr($sqlSet,1); 
    196  
    197       $sqlCondition = $this->_buildSimpleConditions($pkFields, 'record->', false); 
    198       if($sqlCondition!='') 
    199          $src[] = ' where '.$sqlCondition; 
    200  
    201       $src[] = "';"; 
    202       $src[] = '   return $this->_conn->exec ($query);'; 
    203       $src[] = " }";//ends the update function 
    204  
    205  
     188      if(count($fields)){ 
     189         $src[] = '   $query = \'UPDATE '.$pTableRealName.' SET '; 
     190         $sqlSet=''; 
     191         foreach($fields as $k=> $fname){ 
     192            $sqlSet.= ', '.$fname. '= '. $values[$k]; 
     193         } 
     194         $src[] = substr($sqlSet,1); 
     195     
     196         $sqlCondition = $this->_buildSimpleConditions($pkFields, 'record->', false); 
     197         if($sqlCondition!='') 
     198            $src[] = ' where '.$sqlCondition; 
     199     
     200         $src[] = "';"; 
     201         $src[] = '   return $this->_conn->exec ($query);'; 
     202         $src[] = " }";//ends the update function 
     203      }else{ 
     204         //the dao is mapped on a table which contains only primary key : update is impossible 
     205         // so we will generate an error on update 
     206         $src[] = "     throw new jException('jelix~dao.error.update.impossible',array('".jDaoCompiler::$daoId."','".jDaoCompiler::$daoPath."'));"; 
     207         $src[] = " }"; 
     208      } 
    206209      //----- other user methods 
    207210 
  • trunk/lib/jelix/dao/jDaoParser.class.php

    r364 r375  
    6363    private $_methods = array(); 
    6464 
     65    public $hasOnlyPrimaryKeys = false; 
    6566    /** 
    6667    * Constructor 
     
    9394 
    9495        if($debug == 2) return; 
    95  
     96        $countprop = 0; 
    9697        //add the record properties 
    9798        if(isset($xml->record) && isset($xml->record[0]->property)){ 
    9899            foreach ($xml->record[0]->property as $prop){ 
    99             $p = new jDaoProperty ($prop->attributes(), $this); 
    100             $this->_properties[$p->name] = $p; 
    101             $this->_tables[$p->table]['fields'][] = $p->name; 
    102             } 
     100                $p = new jDaoProperty ($prop->attributes(), $this); 
     101                $this->_properties[$p->name] = $p; 
     102                $this->_tables[$p->table]['fields'][] = $p->name; 
     103                if(($p->table == $this->_primaryTable) && !$p->isPK) 
     104                    $countprop ++; 
     105            } 
     106            $this->hasOnlyPrimaryKeys = ($countprop == 0); 
    103107        }else 
    104108            throw new jDaoXmlException ('properties.missing'); 
     
    401405 
    402406        if($this->type == 'update'){ 
     407            if($this->_def->hasOnlyPrimaryKeys) 
     408                throw new jDaoXmlException ('method.update.forbidden',array($this->name)); 
     409 
    403410            if(isset($method->values) && isset($method->values[0]->value)){ 
    404411                foreach ($method->values[0]->value as $val){ 
  • trunk/lib/jelix/utils/jDatatype.class.php

    r335 r375  
    281281 * @experimental 
    282282 */ 
    283 class jDatatypeMail extends jDatatype { 
     283class jDatatypeEmail extends jDatatype { 
    284284    public function check($value){ 
    285285        return jFilter::isEmail($value); 
  • trunk/testapp/modules/unittest/classes/utdao2.class.php

    r276 r375  
    335335    } 
    336336 
    337  
     337   function testBadUpdateMethod() { 
     338 $dao ='<?xml version="1.0"?> 
     339<dao xmlns="http://jelix.org/ns/dao/1.0"> 
     340  <datasources> 
     341    <primarytable name="news" primarykey="news_id,foo_id" /> 
     342  </datasources> 
     343  <record> 
     344    <property name="id" fieldname="news_id" datatype="autoincrement" /> 
     345    <property name="id2" fieldname="foo_id" datatype="integer" /> 
     346  </record> 
     347</dao>'; 
     348 
     349        $parser = new jDaoParser(); 
     350        $parser->parse(simplexml_load_string($dao),1); 
     351 
     352        $this->sendMessage("test bad update method "); 
     353        $xml= simplexml_load_string('<?xml version="1.0"?> 
     354          <method name="tryupdate" type="update"> 
     355            <parameter name="something" /> 
     356            <values> 
     357                <value property="foo_id" expr="$something" /> 
     358            </values> 
     359          </method>'); 
     360 
     361        try{ 
     362            $p = new jDaoMethod($xml, $parser); 
     363            $this->fail("Pas d'exception survenue !"); 
     364        }catch(jDaoXmlException $e){ 
     365            $this->assertEqual($e->getMessage(), 'jelix~daoxml.method.update.forbidden'); 
     366            $this->assertEqual($e->localeParams, array('','','tryupdate')); 
     367        }catch(Exception $e){ 
     368            $this->fail("Exception inconnue : ".$e->getMessage()); 
     369        } 
     370    } 
    338371} 
    339372 
Download in other formats: Unified Diff Zip Archive