Skip to content

Commit de00e5e

Browse files
Mon1kborro
authored andcommitted
hinting for select query;
1 parent 8b9619b commit de00e5e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

framework/db/ar/CActiveFinder.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ class CJoinQuery
12741274
*/
12751275
public $elements=array();
12761276

1277+
public $hints=array();
1278+
12771279
/**
12781280
* Constructor.
12791281
* @param CJoinElement $joinElement The root join tree.
@@ -1303,6 +1305,9 @@ public function __construct($joinElement,$criteria=null)
13031305
$this->conditions[]=$joinElement->getPrimaryKeyRange();
13041306
}
13051307
$this->elements[$joinElement->id]=true;
1308+
1309+
if ($criteria!==null && $criteria->hints)
1310+
$this->hints=array_merge($this->hints,$criteria->hints);
13061311
}
13071312

13081313
/**
@@ -1330,6 +1335,10 @@ public function join($element)
13301335
$this->params=$element->relation->params;
13311336
}
13321337
$this->elements[$element->id]=true;
1338+
1339+
1340+
if (!empty($element->relation->hints))
1341+
$this->hints[]=$element->relation->hints;
13331342
}
13341343

13351344
/**
@@ -1339,7 +1348,18 @@ public function join($element)
13391348
*/
13401349
public function createCommand($builder)
13411350
{
1342-
$sql=($this->distinct ? 'SELECT DISTINCT ':'SELECT ') . implode(', ',$this->selects);
1351+
$sql='SELECT ';
1352+
if($this->hints)
1353+
{
1354+
$sql.='/*+';
1355+
foreach($this->hints as $hint)
1356+
{
1357+
$sql.=$hint.' ';
1358+
}
1359+
$sql.='*/ ';
1360+
}
1361+
1362+
$sql.=($this->distinct?'DISTINCT ':'').implode(', ',$this->selects);
13431363
$sql.=' FROM ' . implode(' ',array_unique($this->joins));
13441364

13451365
$conditions=array();

framework/db/ar/CActiveRecord.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,8 @@ class CBaseActiveRelation extends CComponent
19991999
*/
20002000
public $order='';
20012001

2002+
public $hints=array();
2003+
20022004
/**
20032005
* Constructor.
20042006
* @param string $name name of the relation

framework/db/schema/CDbCriteria.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class CDbCriteria extends CComponent
150150
*/
151151
public $scopes;
152152

153+
154+
public $hints=array();
155+
153156
/**
154157
* Constructor.
155158
* @param array $data criteria initial property values (indexed by property name)

0 commit comments

Comments
 (0)