Query cache file - added condition to skip null arguments that do not need validation and are not mandatory.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9066 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-09-06 15:50:30 +00:00
parent 34246aa267
commit 33df36e715
12 changed files with 148 additions and 116 deletions

View file

@ -11,7 +11,6 @@
var $_show; var $_show;
var $_value_to_string; var $_value_to_string;
function Condition($column_name, $argument, $operation, $pipe){ function Condition($column_name, $argument, $operation, $pipe){
$this->column_name = $column_name; $this->column_name = $column_name;
$this->argument = $argument; $this->argument = $argument;

View file

@ -3,11 +3,13 @@
class ConditionWithArgument extends Condition { class ConditionWithArgument extends Condition {
function ConditionWithArgument($column_name, $argument, $operation, $pipe = ""){ function ConditionWithArgument($column_name, $argument, $operation, $pipe = ""){
if($argument === null) { $this->_show = false; return; }
parent::Condition($column_name, $argument, $operation, $pipe); parent::Condition($column_name, $argument, $operation, $pipe);
$this->_value = $argument->getValue(); $this->_value = $argument->getValue();
} }
function getArgument(){ function getArgument(){
if(!$this->show()) return;
return $this->argument; return $this->argument;
} }
@ -25,10 +27,15 @@
} }
function show(){ function show(){
if(!$this->argument->isValid()) return false; if(!isset($this->_show)){
if($this->_value === '\'\'') return false; if(!$this->argument->isValid()) $this->_show = false;
if($this->_value === '\'\'') $this->_show = false;
if(!isset($this->_show)){
return parent::show(); return parent::show();
} }
} }
return $this->_show;
}
}
?> ?>

View file

@ -44,17 +44,14 @@
class XmlQueryParser extends XmlParser { class XmlQueryParser extends XmlParser {
static $dbParser = null;
var $db_type;
function XmlQueryParser($db_type = NULL){ function XmlQueryParser(){
$this->db_type = $db_type;
} }
function &getInstance($db_type = NULL){ function &getInstance(){
static $theInstance = null; static $theInstance = null;
if(!isset($theInstance)){ if(!isset($theInstance)){
$theInstance = new XmlQueryParser($db_type); $theInstance = new XmlQueryParser();
} }
return $theInstance; return $theInstance;
} }
@ -74,20 +71,14 @@
} }
// singleton // singleton
function &getDBParser(){ function &getDBParser($force = false){
if(!$self->dbParser){ static $dbParser = null;
is_a($this,'XmlQueryParser')?$self=&$this:$self=&XmlQueryParser::getInstance(); if(!$dbParser || $force) {
if(isset($self->db_type))
$oDB = &DB::getInstance($self->db_type);
else
$oDB = &DB::getInstance(); $oDB = &DB::getInstance();
$self->dbParser = $oDB->getParser(); $dbParser = $oDB->getParser();
}
return $self->dbParser;
} }
function setDBParser($value){ return $dbParser;
$self->dbParser = $value;
} }
function getXmlFileContent($xml_file){ function getXmlFileContent($xml_file){

View file

@ -51,33 +51,56 @@
} }
function toString(){ function toString(){
if($this->isConditionArgument()) if($this->argument_validator->hasOnlyDefaultValue()){
return sprintf("\n$%s_argument = %s;\n"
, $this->argument_name
, $this->argument_validator->getDefaultValueString()
);
}
if($this->isConditionArgument()){
// Instantiation
$arg = sprintf("\n$%s_argument = new ConditionArgument('%s', %s, '%s');\n" $arg = sprintf("\n$%s_argument = new ConditionArgument('%s', %s, '%s');\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
, '$args->'.$this->variable_name , '$args->'.$this->variable_name
, $this->operation , $this->operation
); );
// Call methods to validate argument and ensure default value
$arg .= $this->argument_validator->toString();
else // Prepare condition string
$arg .= sprintf("$%s_argument->createConditionValue();\n"
, $this->argument_name
);
// Check that argument passed validation, else return
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
, $this->argument_name
, $this->argument_name
);
}
else {
$arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n" $arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
, '$args->'.$this->variable_name); , '$args->'.$this->variable_name);
$arg .= $this->argument_validator->toString(); $arg .= $this->argument_validator->toString();
if($this->isConditionArgument()){
$arg .= sprintf("$%s_argument->createConditionValue();\n"
, $this->argument_name
);
}
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n" $arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
); );
}
// If the argument is null, skip it
if($this->argument_validator->isIgnorable()){
$arg = sprintf("if(isset(%s)) {", '$args->'.$this->variable_name)
. $arg
. sprintf("} else \n$%s_argument = null;", $this->argument_name);
}
return $arg; return $arg;
} }

View file

@ -22,6 +22,11 @@
$this->max_length = $tag->attrs->max_length; $this->max_length = $tag->attrs->max_length;
} }
function isIgnorable(){
if(isset($this->default_value) || isset($this->notnull)) return false;
return true;
}
function toString(){ function toString(){
$validator = ''; $validator = '';
if(isset($this->default_value)){ if(isset($this->default_value)){

View file

@ -84,15 +84,19 @@ class QueryTag {
$prebuff = ''; $prebuff = '';
foreach($arguments as $argument){ foreach($arguments as $argument){
if(isset($argument) && $argument->getArgumentName()){ if(isset($argument)){
$arg_name = $argument->getArgumentName();
if($arg_name){
$prebuff .= $argument->toString(); $prebuff .= $argument->toString();
$column_type = $this->column_type[$this->getQueryId()][$argument->getColumnName()]; $column_type = $this->column_type[$this->getQueryId()][$argument->getColumnName()];
if(isset($column_type)) if(isset($column_type))
$prebuff .= sprintf("$%s_argument->setColumnType('%s');\n" $prebuff .= sprintf("if($%s_argument !== null) $%s_argument->setColumnType('%s');\n"
, $argument->getArgumentName() , $arg_name
, $arg_name
, $column_type ); , $column_type );
} }
} }
}
$prebuff .= "\n"; $prebuff .= "\n";
return $this->preBuff = $prebuff; return $this->preBuff = $prebuff;

View file

@ -34,6 +34,8 @@
// remove cache dir // remove cache dir
FileHandler::removeDir( _XE_PATH_ . 'files/cache'); FileHandler::removeDir( _XE_PATH_ . 'files/cache');
XmlQueryParser::getDBParser(true);
} }
/** /**
@ -41,7 +43,6 @@
*/ */
protected function tearDown() { protected function tearDown() {
unset($GLOBALS['__DB__']); unset($GLOBALS['__DB__']);
XmlQueryParser::setDBParser(null);
} }
} }
?> ?>

View file

@ -16,6 +16,7 @@
$db_info->slave_db = array(array('db_type' => 'cubrid','db_table_prefix' => 'xe_')); $db_info->slave_db = array(array('db_type' => 'cubrid','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info); $oContext->setDbInfo($db_info);
XmlQueryParser::getDBParser(true);
} }
/** /**
@ -23,7 +24,6 @@
*/ */
protected function tearDown() { protected function tearDown() {
unset($GLOBALS['__DB__']); unset($GLOBALS['__DB__']);
XmlQueryParser::setDBParser(null);
} }
} }
?> ?>

View file

@ -34,6 +34,8 @@
// remove cache dir // remove cache dir
FileHandler::removeDir( _XE_PATH_ . 'files/cache'); FileHandler::removeDir( _XE_PATH_ . 'files/cache');
XmlQueryParser::getDBParser(true);
} }
/** /**
@ -41,7 +43,6 @@
*/ */
protected function tearDown() { protected function tearDown() {
unset($GLOBALS['__DB__']); unset($GLOBALS['__DB__']);
XmlQueryParser::setDBParser(null);
} }
} }
?> ?>

View file

@ -14,11 +14,12 @@
$db_info->slave_db = array(array('db_type' => 'mssql','db_table_prefix' => 'xe_')); $db_info->slave_db = array(array('db_type' => 'mssql','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info); $oContext->setDbInfo($db_info);
XmlQueryParser::getDBParser(true);
} }
protected function tearDown() { protected function tearDown() {
unset($GLOBALS['__DB__']); unset($GLOBALS['__DB__']);
XmlQueryParser::setDBParser(null);
} }
} }
?> ?>

View file

@ -14,7 +14,7 @@
$this->_test($xml_file, $argsString, $expected); $this->_test($xml_file, $argsString, $expected);
} }
function testRquiredParameter(){ function testRequiredParameter(){
$xml_file = _XE_PATH_ . "modules/module/queries/getAdminId.xml"; $xml_file = _XE_PATH_ . "modules/module/queries/getAdminId.xml";
$argsString = ''; $argsString = '';
$expected = 'Date incorecte! Query-ul nu a putut fi executat.'; $expected = 'Date incorecte! Query-ul nu a putut fi executat.';

View file

@ -14,7 +14,7 @@
$this->_test($xml_file, $argsString, $expected, array(10)); $this->_test($xml_file, $argsString, $expected, array(10));
} }
function testRquiredParameter(){ function testRequiredParameter(){
$xml_file = _XE_PATH_ . "modules/module/queries/getAdminId.xml"; $xml_file = _XE_PATH_ . "modules/module/queries/getAdminId.xml";
$argsString = ''; $argsString = '';
$expected = 'Date incorecte! Query-ul nu a putut fi executat.'; $expected = 'Date incorecte! Query-ul nu a putut fi executat.';