Updated the query parts that work with arguments (conditions, update and insert expressions) to work with QueryArgument objects instead of string values.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8457 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-06-07 17:18:32 +00:00
parent e41c45433e
commit 313bfca8e8
18 changed files with 120 additions and 169 deletions

View file

@ -2,19 +2,39 @@
class Condition {
var $column_name;
var $value;
var $argument;
var $operation;
var $pipe;
function Condition($column_name, $value, $operation, $pipe = ""){
var $_value;
function Condition($column_name, $argument, $operation, $pipe = ""){
$this->column_name = $column_name;
$this->value = $value;
$this->argument = $argument;
$this->operation = $operation;
$this->pipe = $pipe;
if($this->hasArgument())
$this->_value = $argument->getValue();
else
$this->_value = $argument;
}
function hasArgument(){
return is_a($this->argument, 'Argument');
}
function toString(){
return $this->pipe . ' ' . $this->getConditionPart();
return $this->toStringWithValue();
}
function toStringWithoutValue(){
if($this->hasArgument())
return $this->pipe . ' ' . $this->getConditionPart("?");
else return $this->toString();
}
function toStringWithValue(){
return $this->pipe . ' ' . $this->getConditionPart($this->_value);
}
function setPipe($pipe){
@ -35,22 +55,20 @@
case 'notin' :
case 'notequal' :
// if variable is not set or is not string or number, return
if(!isset($this->value)) return false;
if($this->value === '') return false;
if(!in_array(gettype($this->value), array('string', 'integer'))) return false;
if(!isset($this->_value)) return false;
if($this->_value === '') return false;
if(!in_array(gettype($this->_value), array('string', 'integer'))) return false;
break;
case 'between' :
if(!is_array($this->value)) return false;
if(count($this->value)!=2) return false;
if(!is_array($this->_value)) return false;
if(count($this->_value)!=2) return false;
}
return true;
}
function getConditionPart() {
function getConditionPart($value) {
$name = $this->column_name;
$value = $this->value;
$operation = $this->operation;
switch($operation) {

View file

@ -6,6 +6,7 @@
*
*/
// TODO Fix this class
class DeleteExpression extends Expression {
var $value;

View file

@ -8,19 +8,20 @@
*/
class InsertExpression extends Expression {
var $value;
var $argument;
function InsertExpression($column_name, $value){
function InsertExpression($column_name, $argument){
parent::Expression($column_name);
$this->value = $value;
$this->argument = $argument;
}
function getValue(){
return $this->value;
return $this->argument->getValue();
}
function show(){
if(!isset($this->value)) return false;
$value = $this->argument->getValue();
if(!isset($value)) return false;
return true;
}
}

View file

@ -7,25 +7,35 @@
*/
class UpdateExpression extends Expression {
var $value;
var $argument;
function UpdateExpression($column_name, $value){
function UpdateExpression($column_name, $argument){
parent::Expression($column_name);
$this->value = $value;
$this->argument = $argument;
}
function getExpression(){
return "$this->column_name = $this->value";
return $this->getExpressionWithValue();
}
function getExpressionWithValue(){
$value = $this->argument->getValue();
return "$this->column_name = $value";
}
function getExpressionWithoutValue(){
return "$this->column_name = ?";
}
function getValue(){
// TODO Escape value according to column type instead of variable type
if(!is_numeric($this->value)) return "'".$this->value."'";
return $this->value;
$value = $this->argument->getValue();
if(!is_numeric($value)) return "'".$value."'";
return $value;
}
function show(){
if(!$this->value) return false;
if(!$this->argument->getValue()) return false;
return true;
}
}

View file

@ -24,12 +24,12 @@
}
function getLimit(){
return $this->list_count;
return $this->list_count->getValue();
}
function toString(){
if ($this->page) return $this->start . ' , ' . $this->list_count;
else return $this->list_count;
if ($this->page) return $this->start . ' , ' . $this->list_count->getValue();
else return $this->list_count->getValue();
}
}
?>

View file

@ -9,7 +9,10 @@
}
function toString(){
return $this->column_name . ' ' . $this->sort_order;
$result = is_a($this->column_name, 'Argument') ? $this->column_name->getValue() : $this->column_name;
$result .= ' ';
$result .= is_a($this->sort_order, 'Argument') ? $this->sort_order->getValue() : $this->sort_order;
return $result;
}
}

View file

@ -44,7 +44,6 @@
if(__DEBUG__==3) $start = getMicroTime();
$this->lang = Context::getLangType();
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
$this->input = str_replace(array('',''),array('',''),$this->input);

View file

@ -32,8 +32,9 @@
/* function &getDBParser(){
static $dbParser;
if(!$dbParser){
$oDB = &DB::getInstance();
$dbParser = $oDB->getParser();
//$oDB = &DB::getInstance();
//$dbParser = $oDB->getParser();
return new DBParser('"');
}
return $dbParser;
}*/

View file

@ -19,7 +19,7 @@
}
function getExpressionString(){
return sprintf('new InsertExpression(\'%s\', $%s_argument->getValue())'
return sprintf('new InsertExpression(\'%s\', $%s_argument)'
, $this->name
, $this->argument->argument_name);
}

View file

@ -21,7 +21,7 @@
}
function getExpressionString(){
return sprintf('new UpdateExpression(\'%s\', $%s_argument->getValue())'
return sprintf('new UpdateExpression(\'%s\', $%s_argument)'
, $this->name
, $this->argument->argument_name);
}

View file

@ -50,7 +50,7 @@
function getConditionString(){
return sprintf("new Condition('%s',%s,%s%s)"
, $this->column_name
, $this->default_column ? "'" . $this->default_column . "'" : '$' . $this->argument_name . '_argument->getValue()'
, $this->default_column ? "'" . $this->default_column . "'" : '$' . $this->argument_name . '_argument'
, '"'.$this->operation.'"'
, $this->pipe ? ", '" . $this->pipe . "'" : ''
);

View file

@ -26,7 +26,7 @@
}
function toString(){
return sprintf("new OrderByColumn(\$%s_argument->getValue(), %s)", $this->argument_name, $this->sort_order);
return sprintf("new OrderByColumn(\$%s_argument, %s)", $this->argument_name, $this->sort_order);
}
function getArguments(){

View file

@ -21,8 +21,8 @@
}
function toString(){
if ($this->page)return sprintf("new Limit(\$%s_argument->getValue(), \$%s_argument->getValue(), \$%s_argument->getValue())",$this->list_count->var, $this->page->var, $this->page_count->var);
else return sprintf("new Limit(\$%s_argument->getValue())", $this->list_count->var);
if ($this->page)return sprintf("new Limit(\$%s_argument, \$%s_argument, \$%s_argument)",$this->list_count->var, $this->page->var, $this->page_count->var);
else return sprintf("new Limit(\$%s_argument)", $this->list_count->var);
}
function getArguments(){