Added index hints for CUBRID and Mysql.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9472 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-10-03 17:35:25 +00:00
parent 0b8949cfeb
commit 96b60466be
18 changed files with 350 additions and 4 deletions

View file

@ -139,7 +139,10 @@ class QueryTag {
}
function getTables(){
return $this->tables = new TablesTag($this->query->tables);
if($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
else
return $this->tables = new TablesTag($this->query->tables);
}
function getConditions(){

View file

@ -0,0 +1,48 @@
<?php
/**
* @class HintTableTag
* @author Arnia Sowftare
* @brief Models the <table> tag inside an XML Query file
* and the corresponding <index_hint> tag
*
*/
class HintTableTag extends TableTag {
var $index;
/**
* @brief Initialises Table Tag properties
* @param XML <table> tag $table
*/
function HintTableTag($table, $index){
parent::TableTag($table);
$this->index = $index;
}
function getTableString(){
$dbParser = DB::getParser();
$dbType = ucfirst(Context::getDBType());
$result = sprintf('new %sTableWithHint(\'%s\'%s, array('
, $dbType
, $dbParser->escape($this->name)
, $this->alias ? ', \'' . $dbParser->escape($this->alias) .'\'' : ', null'
//, ', \'' . $dbParser->escape($this->index->name) .'\', \'' . $this->index->type .'\''
);
foreach($this->index as $indx){
$result .= "new IndexHint(";
$result .= '\'' . $dbParser->escape($indx->name) .'\', \'' . $indx->type .'\'' . ') , ';
}
$result = substr($result, 0, -2);
$result .= '))';
return $result;
}
function getArguments(){
if(!isset($this->conditionsTag)) return array();
return $this->conditionsTag->getArguments();
}
}
?>

View file

@ -19,18 +19,32 @@
class TablesTag {
var $tables;
function TablesTag($xml_tables_tag){
function TablesTag($xml_tables_tag, $xml_index_hints_tag = NULL){
$this->tables = array();
$xml_tables = $xml_tables_tag->table;
if(!is_array($xml_tables)) $xml_tables = array($xml_tables);
if($xml_index_hints_tag){
$index_nodes = $xml_index_hints_tag->index;
if(!is_array($index_nodes)) $index_nodes = array($index_nodes);
foreach($index_nodes as $index_node) {
if(!$indexes[$index_node->attrs->table]) $indexes[$index_node->attrs->table] = array();
$count = count($indexes[$index_node->attrs->table]);
$indexes[$index_node->attrs->table][$count]->name = $index_node->attrs->name;
$indexes[$index_node->attrs->table][$count]->type = $index_node->attrs->type;
}
}
foreach($xml_tables as $tag){
if($tag->attrs->query == 'true'){
$this->tables[] = new QueryTag($tag, true);
}
else {
$this->tables[] = new TableTag($tag);
if($indexes && $indexes[$tag->attrs->name])
$this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]);
else
$this->tables[] = new TableTag($tag);
}
}
}