Removed legacy methods from DB and DBCubrid classes.

Added Query object to hold together query parts. 
Updated structure of query cache file to return Query object. 
Added support for array query arguments - used in the IN clause.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8438 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-06-02 13:06:08 +00:00
parent c384f6c753
commit 0cd318fcf5
9 changed files with 210 additions and 891 deletions

View file

@ -127,20 +127,20 @@ class QueryParser {
$prebuff .= "\n";
$buff = '';
$buff .= '$output->columns = ' . $columns->toString() . ';'.PHP_EOL;
$buff .= '$output->tables = ' . $tables->toString() .';'.PHP_EOL;
$buff .= '$output->conditions = '.$conditions->toString() .';'.PHP_EOL;
$buff .= '$output->groups = ' . $groups->toString() . ';';
$buff .= '$output->orderby = ' . $navigation->getOrderByString() .';';
$buff .= $navigation->getLimitString()?'$output->limit = ' . $navigation->getLimitString() .';':"";
$buff .= '$query->setColumns(' . $columns->toString() . ');'.PHP_EOL;
$buff .= '$query->setTables(' . $tables->toString() .');'.PHP_EOL;
$buff .= '$query->setConditions('.$conditions->toString() .');'.PHP_EOL;
$buff .= '$query->setGroups(' . $groups->toString() . ');'.PHP_EOL;
$buff .= '$query->setOrder(' . $navigation->getOrderByString() .');'.PHP_EOL;
$buff .= $navigation->getLimitString()?'$query->setLimit(' . $navigation->getLimitString() .');'.PHP_EOL:"";
return "<?php if(!defined('__ZBXE__')) exit();\n"
. sprintf('$output->query_id = "%s";%s', $this->query_id, "\n")
. sprintf('$output->action = "%s";%s', $this->action, "\n")
. '$query = new Query();'.PHP_EOL
. sprintf('$query->setQueryId("%s");%s', $this->query_id, "\n")
. sprintf('$query->setAction("%s");%s', $this->action, "\n")
. $prebuff
. $buff
. 'return $output; ?>';
. 'return $query; ?>';
}

View file

@ -14,6 +14,7 @@
}
function getValue(){
if(is_array($this->value)) return implode(',', $this->value);
return $this->value;
}
@ -34,12 +35,19 @@
if(!isset($this->value)) return;
if($column_type === '') return;
//if($column_type === '') $column_type = 'varchar';
if(in_array($column_type, array('date', 'varchar', 'char', 'bigtext')))
$this->value = '\''.$this->value.'\'';
if(in_array($column_type, array('date', 'varchar', 'char','text', 'bigtext'))){
if(!is_array($this->value))
$this->value = '\''.$this->value.'\'';
else {
$total = count($this->value);
for($i = 0; $i < $total; $i++)
$this->value[$i] = '\''.$this->value[$i].'\'';
}
}
}
function checkFilter($filter_type){
if(isset($this->value)){
if(isset($this->value) && $this->value != ''){
$val = $this->value;
$key = $this->name;
switch($filter_type) {

View file

@ -25,6 +25,19 @@
case 'like' :
$this->value = '%'.$value.'%';
break;
case 'in' :
if(is_array($value))
{
//$value = $this->addQuotesArray($value);
//if($type=='number') return join(',',$value);
//else
//$this->value = "['". join("','",$value)."']";
}
else
{
$this->value = $value;
}
break;
}
/*
//if(!in_array($operation,array('in','notin','between')) && is_array($value)){

View file

@ -18,6 +18,12 @@
function toString(){
if(!isset($this->value)) return;
// If value contains comma separated values and does not contain paranthesis
// -> default value is an array
if(strpos($this->value, ',') !== false && strpos($this->value, '(') === false) {
return sprintf('array(%s)', $this->value);
}
$str_pos = strpos($this->value, '(');
// // TODO Replace this with parseExpression
if($str_pos===false) return '\''.$this->value.'\'';

View file

@ -14,6 +14,8 @@
if(!$this->argument_name) $this->ignoreValue = true;
else $this->ignoreValue = false;
if(!$this->argument_name) $this->argument_name = $tag->attrs->name;
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->column);
@ -26,6 +28,9 @@
}
if($tag->attrs->operation) $this->operation = $tag->attrs->operation;
// If we work with ConditionArgument, check if default value exists, and if yes, create argument
if($this->operation && $tag->attrs->default) $this->ignoreValue = false;
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
$this->argument_validator = new QueryArgumentValidator($tag, $this);

View file

@ -39,7 +39,7 @@
);
}
if($this->filter){
$validator .= sprintf("$%s_argument->checkFilter(%s);\n"
$validator .= sprintf("$%s_argument->checkFilter('%s');\n"
, $this->argument_name
, $this->filter
);