Changeset 149
- Timestamp:
- 04/27/06 22:40:01 (3 years ago)
- Files:
-
- trunk/lib/jelix/dao/jDAOGenerator.class.php (modified) (4 diffs)
- trunk/lib/jelix/dao/jDAOParser.class.php (modified) (3 diffs)
- trunk/lib/jelix/docs/ns/dao.rng (modified) (2 diffs)
- trunk/testapp/modules/testapp/daos/testnews.dao.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jelix/dao/jDAOGenerator.class.php
r141 r149 266 266 267 267 case 'count': 268 $src[] = ' $query = \'SELECT COUNT(*) as c \'.$this->_fromClause.$this->_whereClause;'; 268 if($method->distinct !=''){ 269 $prop=$this->_datasParser->getProperties (); 270 $prop = $prop[$method->distinct]; 271 $count=' DISTINCT '.$tables[$prop->table]['name'] .'.'.$prop->fieldName; 272 }else{ 273 $count='*'; 274 } 275 $src[] = ' $query = \'SELECT COUNT('.$count.') as c \'.$this->_fromClause.$this->_whereClause;'; 269 276 $glueCondition = ($sqlWhereClause !='' ? ' AND ':' WHERE '); 270 277 break; … … 272 279 case 'select': 273 280 default: 274 $src[] = ' $query = $this->_selectClause.$this->_fromClause.$this->_whereClause;'; 281 if($method->distinct !=''){ 282 $select = '\''.$this->_getSelectClause($method->distinct).'\''; 283 }else{ 284 $select=' $this->_selectClause'; 285 } 286 $src[] = ' $query = '.$select.'.$this->_fromClause.$this->_whereClause;'; 275 287 $glueCondition = ($sqlWhereClause !='' ? ' AND ':' WHERE '); 276 288 if( ($lim = $method->getLimit ()) !==null){ … … 401 413 * build SELECT clause for all SELECT queries 402 414 */ 403 private function _getSelectClause ( ){415 private function _getSelectClause ($distinct=''){ 404 416 $result = array(); 405 417 … … 416 428 //in oracle we must escape name 417 429 if ($driverName == 'oci8') { 418 $ result[]= $table.$prop->fieldName.' "'.$prop->name.'"';430 $field = $table.$prop->fieldName.' "'.$prop->name.'"'; 419 431 }else{ 420 $ result[]= $table.$prop->fieldName.' as '.$prop->name;432 $field = $table.$prop->fieldName.' as '.$prop->name; 421 433 } 422 434 }else{ 423 $ result[]= $table.$prop->fieldName;435 $field = $table.$prop->fieldName; 424 436 } 425 437 }else{ 426 438 //in oracle we must escape name 427 439 if ($driverName == 'oci8') { 428 $ result[]= sprintf ($prop->selectMotif, $table.$prop->fieldName).' "'.$prop->name.'"';440 $field = sprintf ($prop->selectMotif, $table.$prop->fieldName).' "'.$prop->name.'"'; 429 441 }else{ 430 $ result[]= sprintf ($prop->selectMotif, $table.$prop->fieldName).' as '.$prop->name;442 $field = sprintf ($prop->selectMotif, $table.$prop->fieldName).' as '.$prop->name; 431 443 } 432 444 } 433 } 434 } 435 436 return 'SELECT '.(implode (', ',$result)); 445 446 if($distinct == $prop->name) 447 array_unshift($result, $field); 448 else 449 $result[]=$field; 450 } 451 } 452 453 return 'SELECT '.($distinct!=''?'DISTINCT ':'').(implode (', ',$result)); 437 454 } 438 455 trunk/lib/jelix/dao/jDAOParser.class.php
r142 r149 332 332 public $name; 333 333 public $type; 334 public $distinct=''; 334 335 private $_conditions = null; 335 336 private $_parameters = array(); … … 343 344 $this->_def = $def; 344 345 345 $params = $def->getAttr($method, array('name', 'type', 'call' ));346 $params = $def->getAttr($method, array('name', 'type', 'call','distinct')); 346 347 347 348 if ($params['name']===null){ … … 399 400 } 400 401 return; 402 } 403 404 if(($this->type == 'select' || $this->type == 'count') && strlen($params['distinct'])){ 405 $props = $this->_def->getProperties(); 406 407 if (!isset ($props[$params['distinct']])){ 408 $this->_def->_compiler->doDefError('method.property.unknown', array($this->name, $params['distinct'])); 409 } 410 $this->distinct=$params['distinct']; 401 411 } 402 412 trunk/lib/jelix/docs/ns/dao.rng
r135 r149 98 98 99 99 <element name="method"> 100 <attribute name="type"> 101 <choice> 102 <value>count</value> 103 <value>delete</value> 104 </choice> 105 </attribute> 100 <attribute name="type"><value>delete</value></attribute> 106 101 <ref name="method.common" /> 107 102 <ref name="method.conditions"/> 103 </element> 104 105 <element name="method"> 106 <attribute name="type"><value>count</value></attribute> 107 <optional> 108 <attribute name="distinct" /> 109 </optional> 110 <ref name="method.common" /> 111 <ref name="method.conditions"/> 108 112 </element> 109 113 … … 123 127 </choice> 124 128 </attribute> 129 </optional> 130 <optional> 131 <attribute name="distinct" /> 125 132 </optional> 126 133 <ref name="method.common" /> trunk/testapp/modules/testapp/daos/testnews.dao.xml
r131 r149 32 32 <limit offset="0" count="$limit" /> 33 33 </method> 34 <method name="selectdistinct" type="select" distinct="titre"> 35 <parameter name="limit" /> 36 <conditions> 37 <eq property="valider" value="3" /> 38 </conditions> 39 <order> 40 <orderitem property="date" way="desc" /> 41 </order> 42 <limit offset="0" count="$limit" /> 43 </method> 44 <method name="countdistinct" type="count" distinct="titre"> 45 <parameter name="limit" /> 46 <conditions> 47 <eq property="valider" value="3" /> 48 </conditions> 49 </method> 50 51 34 52 </factory> 35 53 </dao>
