diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 581908366..490d2d2e2 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.class.php @@ -346,4 +346,4 @@ class Argument } } /* End of file Argument.class.php */ -/* Location: ./classes/xml/xmlquery/Argument.class.php */ +/* Location: ./classes/xml/xmlquery/argument/Argument.class.php */ diff --git a/classes/xml/xmlquery/argument/ConditionArgument.class.php b/classes/xml/xmlquery/argument/ConditionArgument.class.php index e5471a79c..cfa0fbbdd 100644 --- a/classes/xml/xmlquery/argument/ConditionArgument.class.php +++ b/classes/xml/xmlquery/argument/ConditionArgument.class.php @@ -1,122 +1,127 @@ 1, 'notin'=>1, 'not_in'=>1, 'between'=>1); - if(isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != ''){ - $value = str_replace(' ', '', $value); - $value = str_replace('\'', '', $value); - $value = explode(',', $value); - } - parent::Argument($name, $value); - $this->operation = $operation; + /** + * constructor + * @param string $name + * @param mixed $value + * @param string $operation + * @return void + */ + function ConditionArgument($name, $value, $operation) + { + $operationList = array('in'=>1, 'notin'=>1, 'not_in'=>1, 'between'=>1); + if(isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != '') + { + $value = str_replace(' ', '', $value); + $value = str_replace('\'', '', $value); + $value = explode(',', $value); } + parent::Argument($name, $value); + $this->operation = $operation; + } - /** - * create condition value. set $this->value - * @return void - */ - function createConditionValue(){ - if(!isset($this->value)) return; + /** + * create condition value. set $this->value + * @return void + */ + function createConditionValue() + { + if(!isset($this->value)) return; - $operation = $this->operation; - $value = $this->value; + $operation = $this->operation; + $value = $this->value; - switch($operation) { - case 'like_prefix' : - if(defined('__CUBRID_VERSION__') - && __CUBRID_VERSION__ >= '8.4.1') { - $this->value = '^' . str_replace('%', '(.*)', preg_quote($value)); - } - else - $this->value = $value.'%'; - break; - case 'like_tail' : - if(defined('__CUBRID_VERSION__') - && __CUBRID_VERSION__ >= '8.4.1') - $this->value = str_replace('%', '(.*)', preg_quote($value)) . '$'; - else - $this->value = '%'.$value; - break; - case 'like' : - if(defined('__CUBRID_VERSION__') - && __CUBRID_VERSION__ >= '8.4.1') { - $this->value = str_replace('%', '(.*)', preg_quote($value)); - } - else - $this->value = '%'.$value.'%'; - break; - case 'notlike' : - $this->value = '%'.$value.'%'; - break; - case 'notlike_prefix' : - $this->value = $value.'%'; - break; - case 'notlike_tail' : - $this->value = '%'.$value; - break; - case 'in': - if(!is_array($value)) $this->value = array($value); - break; - case 'notin': - case 'not_in': - if(!is_array($value)) $this->value = array($value); - break; - } + switch($operation) + { + case 'like_prefix' : + if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') + { + $this->value = '^' . str_replace('%', '(.*)', preg_quote($value)); + } + else + $this->value = $value.'%'; + break; + case 'like_tail' : + if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') + $this->value = str_replace('%', '(.*)', preg_quote($value)) . '$'; + else + $this->value = '%'.$value; + break; + case 'like' : + if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') + { + $this->value = str_replace('%', '(.*)', preg_quote($value)); + } + else + $this->value = '%'.$value.'%'; + break; + case 'notlike' : + $this->value = '%'.$value.'%'; + break; + case 'notlike_prefix' : + $this->value = $value.'%'; + break; + case 'notlike_tail' : + $this->value = '%'.$value; + break; + case 'in': + if(!is_array($value)) $this->value = array($value); + break; + case 'notin': + case 'not_in': + if(!is_array($value)) $this->value = array($value); + break; } + } - /** - * Since ConditionArgument is used in WHERE clause, - * where the argument value is compared to a table column, - * it is assumed that all arguments have type. There are cases though - * where the column does not have any type - if it was removed from - * the XML schema for example - see the is_secret column in xe_documents table. - * In this case, the column type is retrieved according to argument - * value type (using the PHP function is_numeric). - * - * @return type string - */ - function getType(){ - if($this->type) - { - return $this->type; - } - else if(!is_numeric($this->value)) - { - return 'varchar'; - } - else - { - return ''; - } + /** + * Since ConditionArgument is used in WHERE clause, + * where the argument value is compared to a table column, + * it is assumed that all arguments have type. There are cases though + * where the column does not have any type - if it was removed from + * the XML schema for example - see the is_secret column in xe_documents table. + * In this case, the column type is retrieved according to argument + * value type (using the PHP function is_numeric). + * + * @return type string + */ + function getType() + { + if($this->type) + { + return $this->type; } - - function setColumnType($column_type){ - if(!isset($this->value)) return; - if($column_type === '') return; - - $this->type = $column_type; + else if(!is_numeric($this->value)) + { + return 'varchar'; } + else + { + return ''; + } + } - } + function setColumnType($column_type) + { + if(!isset($this->value)) return; + if($column_type === '') return; -?> + $this->type = $column_type; + } + +} +/* End of file ConditionArgument.class.php */ +/* Location: ./classes/xml/xmlquery/argument/ConditionArgument.class.php */ diff --git a/classes/xml/xmlquery/argument/SortArgument.class.php b/classes/xml/xmlquery/argument/SortArgument.class.php index fc83d1c6f..8936c26ce 100644 --- a/classes/xml/xmlquery/argument/SortArgument.class.php +++ b/classes/xml/xmlquery/argument/SortArgument.class.php @@ -1,16 +1,16 @@ getUnescapedValue(); - } - - } - -?> +/** + * SortArgument class + * @author NHN (developers@xpressengine.com) + * @package /classes/xml/xmlquery/argument + * @version 0.1 + */ +class SortArgument extends Argument +{ + function getValue() + { + return $this->getUnescapedValue(); + } +} +/* End of file SortArgument.class.php */ +/* Location: ./classes/xml/xmlquery/argument/SortArgument.class.php */ diff --git a/classes/xml/xmlquery/queryargument/DefaultValue.class.php b/classes/xml/xmlquery/queryargument/DefaultValue.class.php index e5fa9793d..61d7e85ac 100644 --- a/classes/xml/xmlquery/queryargument/DefaultValue.class.php +++ b/classes/xml/xmlquery/queryargument/DefaultValue.class.php @@ -1,146 +1,160 @@ column_name = $dbParser->parseColumnName($column_name); - $this->value = $value; - $this->value = $this->_setValue(); - } - - function isString(){ - return $this->_is_string; - $str_pos = strpos($this->value, '('); - if($str_pos===false) return true; - return false; - } - - function isStringFromFunction(){ - return $this->_is_string_from_function; - } - - function isSequence(){ - return $this->is_sequence; - } - - function isOperation(){ - return $this->is_operation; - } - - function getOperation(){ - return $this->operation; - } - - function _setValue(){ - 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) { - $this->_is_string = true; - return '\''.$this->value.'\''; - } - //if($str_pos===false) return $this->value; - - $func_name = substr($this->value, 0, $str_pos); - $args = substr($this->value, $str_pos+1, -1); - - switch($func_name) { - case 'ipaddress' : - $val = '$_SERVER[\'REMOTE_ADDR\']'; - $this->_is_string_from_function = true; - break; - case 'unixtime' : - $val = 'time()'; - break; - case 'curdate' : - $val = 'date("YmdHis")'; - $this->_is_string_from_function = true; - break; - case 'sequence' : - $this->is_sequence = true; - $val = '$sequence'; - break; - case 'plus' : - $args = abs($args); - $this->is_operation = true; - $this->operation = '+'; - $val = sprintf('%d', $args); - break; - case 'minus' : - $args = abs($args); - $this->is_operation = true; - $this->operation = '-'; - $val = sprintf('%d', $args); - break; - case 'multiply' : - $args = intval($args); - $this->is_operation = true; - $this->operation = '*'; - $val = sprintf('%d', $args); - break; - default : - $val = '\'' . $this->value . '\''; - //$val = $this->value; - } - - return $val; - } - - function toString(){ - return $this->value; - } + /** + * constructor + * @param string $column_name column name + * @param mixed $value value + * @return void + */ + function DefaultValue($column_name, $value) + { + $dbParser = &DB::getParser(); + $this->column_name = $dbParser->parseColumnName($column_name); + $this->value = $value; + $this->value = $this->_setValue(); } + + function isString() + { + return $this->_is_string; + $str_pos = strpos($this->value, '('); + if($str_pos===false) return true; + return false; + } + + function isStringFromFunction() + { + return $this->_is_string_from_function; + } + + function isSequence() + { + return $this->is_sequence; + } + + function isOperation() + { + return $this->is_operation; + } + + function getOperation() + { + return $this->operation; + } + + function _setValue() + { + 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) + { + $this->_is_string = true; + return '\''.$this->value.'\''; + } + //if($str_pos===false) return $this->value; + + $func_name = substr($this->value, 0, $str_pos); + $args = substr($this->value, $str_pos+1, -1); + + switch($func_name) + { + case 'ipaddress' : + $val = '$_SERVER[\'REMOTE_ADDR\']'; + $this->_is_string_from_function = true; + break; + case 'unixtime' : + $val = 'time()'; + break; + case 'curdate' : + $val = 'date("YmdHis")'; + $this->_is_string_from_function = true; + break; + case 'sequence' : + $this->is_sequence = true; + $val = '$sequence'; + break; + case 'plus' : + $args = abs($args); + $this->is_operation = true; + $this->operation = '+'; + $val = sprintf('%d', $args); + break; + case 'minus' : + $args = abs($args); + $this->is_operation = true; + $this->operation = '-'; + $val = sprintf('%d', $args); + break; + case 'multiply' : + $args = intval($args); + $this->is_operation = true; + $this->operation = '*'; + $val = sprintf('%d', $args); + break; + default : + $val = '\'' . $this->value . '\''; + //$val = $this->value; + } + + return $val; + } + + function toString() + { + return $this->value; + } +} +/* End of file DefaultValue.class.php */ +/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */ diff --git a/classes/xml/xmlquery/queryargument/QueryArgument.class.php b/classes/xml/xmlquery/queryargument/QueryArgument.class.php index ebeb7a30f..1b119481d 100644 --- a/classes/xml/xmlquery/queryargument/QueryArgument.class.php +++ b/classes/xml/xmlquery/queryargument/QueryArgument.class.php @@ -5,7 +5,8 @@ * @package /classes/xml/xmlquery/queryargument * @version 0.1 */ -class QueryArgument { +class QueryArgument +{ /** * Argument name * @var string @@ -48,13 +49,14 @@ class QueryArgument { * @param bool $ignore_value * @return void */ - function QueryArgument($tag, $ignore_value = false) { + function QueryArgument($tag, $ignore_value = false) + { static $number_of_arguments = 0; $this->argument_name = $tag->attrs->var; - if (!$this->argument_name) + if(!$this->argument_name) $this->argument_name = str_replace('.', '_', $tag->attrs->name); - if (!$this->argument_name) + if(!$this->argument_name) $this->argument_name = str_replace('.', '_', $tag->attrs->column); $this->variable_name = $this->argument_name; @@ -63,41 +65,47 @@ class QueryArgument { $this->argument_name .= $number_of_arguments; $name = $tag->attrs->name; - if (!$name) + if(!$name) $name = $tag->attrs->column; - if (strpos($name, '.') === false) + if(strpos($name, '.') === false) $this->column_name = $name; - else { + else + { list($prefix, $name) = explode('.', $name); $this->column_name = $name; $this->table_name = $prefix; } - if ($tag->attrs->operation) + if($tag->attrs->operation) $this->operation = $tag->attrs->operation; $this->argument_validator = new QueryArgumentValidator($tag, $this); $this->ignore_value = $ignore_value; } - function getArgumentName() { + function getArgumentName() + { return $this->argument_name; } - function getColumnName() { + function getColumnName() + { return $this->column_name; } - - function getTableName(){ + + function getTableName() + { return $this->table_name; } - function getValidatorString() { + function getValidatorString() + { return $this->argument_validator->toString(); } - function isConditionArgument() { - if ($this->operation) + function isConditionArgument() + { + if($this->operation) return true; return false; } @@ -106,52 +114,56 @@ class QueryArgument { * Change QueryArgument object to string * @return string */ - function toString() { - if ($this->isConditionArgument()) { + function toString() + { + if($this->isConditionArgument()) + { // Instantiation $arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n" - , $this->argument_name - , $this->variable_name - , '$args->' . $this->variable_name - , $this->operation - ); + , $this->argument_name + , $this->variable_name + , '$args->' . $this->variable_name + , $this->operation + ); // Call methods to validate argument and ensure default value $arg .= $this->argument_validator->toString(); // Prepare condition string $arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n" - , $this->argument_name - ); + , $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 { + , $this->argument_name + , $this->argument_name + ); + } + else + { $arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n" - , $this->argument_name - , $this->variable_name - , $this->ignore_value ? 'null' : '$args->{\'' . $this->variable_name . '\'}'); + , $this->argument_name + , $this->variable_name + , $this->ignore_value ? 'null' : '$args->{\'' . $this->variable_name . '\'}'); $arg .= $this->argument_validator->toString(); $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()) { + if($this->argument_validator->isIgnorable()) + { $arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name) - . $arg - . sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name); + . $arg + . sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name); } return $arg; } - } - -?> +/* End of file QueryArgument.class.php */ +/* Location: ./classes/xml/xmlquery/queryargument/QueryArgument.class.php */ diff --git a/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php b/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php index e99486f1f..aa3640331 100644 --- a/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php +++ b/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php @@ -1,29 +1,30 @@ argument_name - , $this->argument_name - , '$args->'.$this->variable_name); + function toString() + { + $arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n" + , $this->argument_name + , $this->argument_name + , '$args->'.$this->variable_name); + $arg .= $this->argument_validator->toString(); - - $arg .= $this->argument_validator->toString(); - - $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" - , $this->argument_name - , $this->argument_name - ); - return $arg; - } - } -?> + $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" + , $this->argument_name + , $this->argument_name + ); + return $arg; + } +} +/* End of file DefaultValue.class.php */ +/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */ diff --git a/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php b/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php index dbf8ce3a9..f2d6e0dfe 100644 --- a/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php +++ b/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php @@ -1,113 +1,125 @@ argument = $argument; - $this->argument_name = $this->argument->getArgumentName(); + /** + * constructor + * @param Xml_Node_ $tag tag object by Query xml file parse + * @param QueryArgument $argument + * @return void + */ + function QueryArgumentValidator($tag, $argument) + { + $this->argument = $argument; + $this->argument_name = $this->argument->getArgumentName(); - $this->default_value = $tag->attrs->default; - $this->notnull = $tag->attrs->notnull; - $this->filter = $tag->attrs->filter; - $this->min_length = $tag->attrs->min_length; - $this->max_length = $tag->attrs->max_length; - } - - function isIgnorable(){ - if(isset($this->default_value) || isset($this->notnull)) return false; - return true; - } - - function toString(){ - $validator = ''; - if($this->filter){ - $validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n" - , $this->argument_name - , $this->filter - ); - } - if($this->min_length){ - $validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n" - , $this->argument_name - , $this->min_length - ); - } - if($this->max_length){ - $validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);'. "\n" - , $this->argument_name - , $this->max_length - ); - } - if(isset($this->default_value)){ - $this->default_value = new DefaultValue($this->argument_name, $this->default_value); - if($this->default_value->isSequence()) - $validator .= '$db = &DB::getInstance(); $sequence = $db->getNextSequence(); '; - if($this->default_value->isOperation()) - $validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n" - , $this->argument_name - , $this->default_value->getOperation() - ); - $validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n" - , $this->argument_name - , $this->default_value->toString() - ); - } - if($this->notnull){ - $validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n" - , $this->argument_name - ); - } - return $validator; - } + $this->default_value = $tag->attrs->default; + $this->notnull = $tag->attrs->notnull; + $this->filter = $tag->attrs->filter; + $this->min_length = $tag->attrs->min_length; + $this->max_length = $tag->attrs->max_length; } -?> + function isIgnorable() + { + if(isset($this->default_value) || isset($this->notnull)) return false; + return true; + } + + function toString() + { + $validator = ''; + if($this->filter) + { + $validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n" + , $this->argument_name + , $this->filter + ); + } + if($this->min_length) + { + $validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n" + , $this->argument_name + , $this->min_length + ); + } + if($this->max_length) + { + $validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);'. "\n" + , $this->argument_name + , $this->max_length + ); + } + if(isset($this->default_value)) + { + $this->default_value = new DefaultValue($this->argument_name, $this->default_value); + if($this->default_value->isSequence()) + $validator .= '$db = &DB::getInstance(); $sequence = $db->getNextSequence(); '; + if($this->default_value->isOperation()) + { + $validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n" + , $this->argument_name + , $this->default_value->getOperation() + ); + } + $validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n" + , $this->argument_name + , $this->default_value->toString() + ); + } + if($this->notnull) + { + $validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n" + , $this->argument_name + ); + } + return $validator; + } +} + +/* End of file QueryArgumentValidator.class.php */ +/* Location: ./classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php */ diff --git a/classes/xml/xmlquery/tags/column/ColumnTag.class.php b/classes/xml/xmlquery/tags/column/ColumnTag.class.php index 33edeba26..13f14608c 100644 --- a/classes/xml/xmlquery/tags/column/ColumnTag.class.php +++ b/classes/xml/xmlquery/tags/column/ColumnTag.class.php @@ -1,28 +1,32 @@ tag inside an XML Query file + * Since the tag supports different attributes depending on + * the type of query (select, update, insert, delete) this is only + * the base class for the classes that will model each type tag. + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class ColumnTag +{ /** - * ColumnTag class - * Models the tag inside an XML Query file - * Since the tag supports different attributes depending on - * the type of query (select, update, insert, delete) this is only - * the base class for the classes that will model each type tag. - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * Column name + * @var string */ - class ColumnTag { - /** - * Column name - * @var string - */ - var $name; - - /** - * constructor - * @param string $name - * @return void - */ - function ColumnTag($name){ - $this->name = $name; - } + var $name; + + /** + * constructor + * @param string $name + * @return void + */ + function ColumnTag($name) + { + $this->name = $name; } +} +/* End of file ColumnTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/ColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php b/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php index 0bef31920..6ebff8bb4 100644 --- a/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php +++ b/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php @@ -1,40 +1,45 @@ tag inside an XML Query file whose action is 'insert' + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class InsertColumnTag extends ColumnTag +{ /** - * InsertColumnTag - * Models the tag inside an XML Query file whose action is 'insert' - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * argument + * @var QueryArgument object */ - class InsertColumnTag extends ColumnTag { - /** - * argument - * @var QueryArgument object - */ - var $argument; - - /** - * constructor - * @param object $column - * @return void - */ - function InsertColumnTag($column) { - parent::ColumnTag($column->attrs->name); - $dbParser = DB::getParser(); - $this->name = $dbParser->parseColumnName($this->name); - $this->argument = new QueryArgument($column); - } - - function getExpressionString(){ - return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})' - , $this->name - , $this->argument->argument_name); - } - - function getArgument(){ - return $this->argument; - } + var $argument; + /** + * constructor + * @param object $column + * @return void + */ + function InsertColumnTag($column) + { + parent::ColumnTag($column->attrs->name); + $dbParser = DB::getParser(); + $this->name = $dbParser->parseColumnName($this->name); + $this->argument = new QueryArgument($column); } -?> + + function getExpressionString() + { + return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})' + , $this->name + , $this->argument->argument_name); + } + + function getArgument() + { + return $this->argument; + } + +} +/* End of file InsertColumnTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php b/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php index 86ac458dc..ead87944b 100644 --- a/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php +++ b/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php @@ -1,31 +1,36 @@ tag inside an XML Query file whose action is 'insert-select' + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class InsertColumnTagWithoutArgument extends ColumnTag +{ /** - * InsertColumnTagWithoutArgument - * Models the tag inside an XML Query file whose action is 'insert-select' - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * constructor + * @param object $column + * @return void */ - class InsertColumnTagWithoutArgument extends ColumnTag { - /** - * constructor - * @param object $column - * @return void - */ - function InsertColumnTagWithoutArgument($column) { - parent::ColumnTag($column->attrs->name); - $dbParser = DB::getParser(); - $this->name = $dbParser->parseColumnName($this->name); - } - - function getExpressionString(){ - return sprintf('new Expression(\'%s\')', $this->name); - } - - function getArgument(){ - return null; - } - + function InsertColumnTagWithoutArgument($column) + { + parent::ColumnTag($column->attrs->name); + $dbParser = DB::getParser(); + $this->name = $dbParser->parseColumnName($this->name); } -?> + + function getExpressionString() + { + return sprintf('new Expression(\'%s\')', $this->name); + } + + function getArgument() + { + return null; + } + +} +/* End of file InsertColumnTagWithoutArgument.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php */ diff --git a/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php b/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php index 0cfca653c..1fb19643e 100644 --- a/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php +++ b/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php @@ -1,65 +1,72 @@ tag inside an XML Query file whose action is 'insert' + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class InsertColumnsTag +{ /** - * InsertColumnsTag class - * Models the tag inside an XML Query file whose action is 'insert' - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * Column list + * @var array value is InsertColumnTag object */ - class InsertColumnsTag{ - /** - * Column list - * @var array value is InsertColumnTag object - */ - var $columns; + var $columns; - /** - * constructor - * @param array|string $xml_columns - * @return void - */ - function InsertColumnsTag($xml_columns) { - $this->columns = array(); + /** + * constructor + * @param array|string $xml_columns + * @return void + */ + function InsertColumnsTag($xml_columns) + { + $this->columns = array(); - if(!$xml_columns) - return; + if(!$xml_columns) + return; - if(!is_array($xml_columns)) $xml_columns = array($xml_columns); + if(!is_array($xml_columns)) $xml_columns = array($xml_columns); - foreach($xml_columns as $column){ - if($column->name === 'query') $this->columns[] = new QueryTag($column, true); - else if(!isset($column->attrs->var) && !isset($column->attrs->default)) $this->columns[] = new InsertColumnTagWithoutArgument($column); - else $this->columns[] = new InsertColumnTag($column); - } + foreach($xml_columns as $column) + { + if($column->name === 'query') $this->columns[] = new QueryTag($column, true); + else if(!isset($column->attrs->var) && !isset($column->attrs->default)) $this->columns[] = new InsertColumnTagWithoutArgument($column); + else $this->columns[] = new InsertColumnTag($column); } - - /** - * InsertColumnTag object to string - * @return string - */ - function toString(){ - $output_columns = 'array(' . PHP_EOL; - foreach($this->columns as $column){ - $output_columns .= $column->getExpressionString() . PHP_EOL . ','; - } - $output_columns = substr($output_columns, 0, -1); - $output_columns .= ')'; - return $output_columns; - } - - /** - * Return argument list - * @return array - */ - function getArguments(){ - $arguments = array(); - foreach($this->columns as $column){ - $arguments[] = $column->getArgument(); - } - return $arguments; - } - } -?> + /** + * InsertColumnTag object to string + * @return string + */ + function toString() + { + $output_columns = 'array(' . PHP_EOL; + foreach($this->columns as $column) + { + $output_columns .= $column->getExpressionString() . PHP_EOL . ','; + } + $output_columns = substr($output_columns, 0, -1); + $output_columns .= ')'; + return $output_columns; + } + + /** + * Return argument list + * @return array + */ + function getArguments() + { + $arguments = array(); + foreach($this->columns as $column) + { + $arguments[] = $column->getArgument(); + } + return $arguments; + } + +} +/* End of file InsertColumnsTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php b/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php index bef7e0fd2..abf314df0 100644 --- a/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php +++ b/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php @@ -1,53 +1,58 @@ tag inside an XML Query file whose action is 'select' + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class SelectColumnTag extends ColumnTag +{ /** - * SelectColumnTag - * Models the tag inside an XML Query file whose action is 'select' - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * alias + * @var string */ - class SelectColumnTag extends ColumnTag{ - /** - * alias - * @var string - */ - var $alias; - /** - * click count status - * @var bool - */ - var $click_count; - - /** - * constructor - * @param string|object $column - * @return void - */ - function SelectColumnTag($column){ - if ($column == "*" || $column->attrs->name == '*') - { - parent::ColumnTag(NULL); - $this->name = "*"; - } - else - { - parent::ColumnTag($column->attrs->name); - $dbParser = new DB(); $dbParser = &$dbParser->getParser(); - $this->name = $dbParser->parseExpression($this->name); - - $this->alias = $column->attrs->alias; - $this->click_count = $column->attrs->click_count; - } + var $alias; + /** + * click count status + * @var bool + */ + var $click_count; + + /** + * constructor + * @param string|object $column + * @return void + */ + function SelectColumnTag($column) + { + if ($column == "*" || $column->attrs->name == '*') + { + parent::ColumnTag(NULL); + $this->name = "*"; } - - function getExpressionString(){ - if($this->name == '*') return "new StarExpression()"; - if($this->click_count) - return sprintf('new ClickCountExpression(%s, %s, $args->%s)', $this->name, $this->alias,$this->click_count); - if(strpos($this->name, '$') === 0) - return sprintf('new SelectExpression($args->%s)', substr($this->name, 1)); - $dbParser = DB::getParser(); - return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \''.$dbParser->escape($this->alias) .'\'': ''); + else + { + parent::ColumnTag($column->attrs->name); + $dbParser = new DB(); $dbParser = &$dbParser->getParser(); + $this->name = $dbParser->parseExpression($this->name); + + $this->alias = $column->attrs->alias; + $this->click_count = $column->attrs->click_count; } } + + function getExpressionString() + { + if($this->name == '*') return "new StarExpression()"; + if($this->click_count) + return sprintf('new ClickCountExpression(%s, %s, $args->%s)', $this->name, $this->alias,$this->click_count); + if(strpos($this->name, '$') === 0) + return sprintf('new SelectExpression($args->%s)', substr($this->name, 1)); + $dbParser = DB::getParser(); + return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \''.$dbParser->escape($this->alias) .'\'': ''); + } +} +/* End of file SelectColumnTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php b/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php index 47ec7446f..9fb702234 100644 --- a/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php +++ b/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php @@ -1,83 +1,94 @@ column; - $xml_queries = $xml_columns_tag->query; + $xml_columns = $xml_columns_tag->column; + $xml_queries = $xml_columns_tag->query; - $this->columns = array(); + $this->columns = array(); - if(!$xml_columns) { - $this->columns[] = new SelectColumnTag("*"); - return; - } - - if(!is_array($xml_columns)) $xml_columns = array($xml_columns); - - foreach($xml_columns as $column){ - $this->columns[] = new SelectColumnTag($column); - } - - - if(!$xml_queries) { - return; - } - - if(!is_array($xml_queries)) $xml_queries = array($xml_queries); - - foreach($xml_queries as $column){ - $this->columns[] = new QueryTag($column, true); - } + if(!$xml_columns) + { + $this->columns[] = new SelectColumnTag("*"); + return; } - /** - * SelectColumnTag object to string - * @return string - */ - function toString(){ - $output_columns = 'array(' . PHP_EOL; - foreach($this->columns as $column){ - if(is_a($column, 'QueryTag')) - $output_columns .= $column->toString() . PHP_EOL . ','; - else - $output_columns .= $column->getExpressionString() . PHP_EOL . ','; - } - $output_columns = substr($output_columns, 0, -1); - $output_columns .= ')'; - return $output_columns; + if(!is_array($xml_columns)) $xml_columns = array($xml_columns); + + foreach($xml_columns as $column) + { + $this->columns[] = new SelectColumnTag($column); } - /** - * Return argument list - * @return array - */ - function getArguments(){ - $arguments = array(); - foreach($this->columns as $column){ - if(is_a($column, 'QueryTag')) - $arguments = array_merge($arguments, $column->getArguments()); - } - return $arguments; + + if(!$xml_queries) + { + return; + } + + if(!is_array($xml_queries)) $xml_queries = array($xml_queries); + + foreach($xml_queries as $column) + { + $this->columns[] = new QueryTag($column, true); } } -?> + + /** + * SelectColumnTag object to string + * @return string + */ + function toString() + { + $output_columns = 'array(' . PHP_EOL; + foreach($this->columns as $column) + { + if(is_a($column, 'QueryTag')) + $output_columns .= $column->toString() . PHP_EOL . ','; + else + $output_columns .= $column->getExpressionString() . PHP_EOL . ','; + } + $output_columns = substr($output_columns, 0, -1); + $output_columns .= ')'; + return $output_columns; + } + + /** + * Return argument list + * @return array + */ + function getArguments() + { + $arguments = array(); + foreach($this->columns as $column) + { + if(is_a($column, 'QueryTag')) + $arguments = array_merge($arguments, $column->getArguments()); + } + return $arguments; + } +} +/* End of file SelectColumnsTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php b/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php index e2616ac34..3831ac5b6 100644 --- a/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php +++ b/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php @@ -1,73 +1,83 @@ tag inside an XML Query file whose action is 'update' + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class UpdateColumnTag extends ColumnTag +{ /** - * UpdateColumnTag - * Models the tag inside an XML Query file whose action is 'update' - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * argument + * @var QueryArgument object */ - class UpdateColumnTag extends ColumnTag { - /** - * argument - * @var QueryArgument object - */ - var $argument; - /** - * default value - * @var string - */ - var $default_value; + var $argument; + /** + * default value + * @var string + */ + var $default_value; - /** - * constructor - * @param object $column - * @return void - */ - function UpdateColumnTag($column) { - parent::ColumnTag($column->attrs->name); - $dbParser = DB::getParser(); - $this->name = $dbParser->parseColumnName($this->name); - if($column->attrs->var) - $this->argument = new QueryArgument($column); - else { - if(strpos($column->attrs->default, '.') !== false) - $this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'"; - else { - $default_value = new DefaultValue($this->name, $column->attrs->default); - if($default_value->isOperation()) - $this->argument = new QueryArgument($column, true); - //else $this->default_value = $dbParser->parseColumnName($column->attrs->default); - else { - $this->default_value = $default_value->toString(); - if($default_value->isStringFromFunction()){ - $this->default_value = '"\'".' . $this->default_value . '."\'"'; - } - if($default_value->isString()){ - $this->default_value = '"' . $this->default_value . '"'; - } - } - - - } - } - } - - function getExpressionString(){ - if($this->argument) - return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})' - , $this->name - , $this->argument->argument_name); - else { - return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)' - , $this->name - , $this->default_value); - } - } - - function getArgument(){ - return $this->argument; + /** + * constructor + * @param object $column + * @return void + */ + function UpdateColumnTag($column) + { + parent::ColumnTag($column->attrs->name); + $dbParser = DB::getParser(); + $this->name = $dbParser->parseColumnName($this->name); + if($column->attrs->var) + $this->argument = new QueryArgument($column); + else + { + if(strpos($column->attrs->default, '.') !== false) + $this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'"; + else + { + $default_value = new DefaultValue($this->name, $column->attrs->default); + if($default_value->isOperation()) + $this->argument = new QueryArgument($column, true); + //else $this->default_value = $dbParser->parseColumnName($column->attrs->default); + else + { + $this->default_value = $default_value->toString(); + if($default_value->isStringFromFunction()) + { + $this->default_value = '"\'".' . $this->default_value . '."\'"'; + } + if($default_value->isString()) + { + $this->default_value = '"' . $this->default_value . '"'; + } + } + } } } -?> + function getExpressionString() + { + if($this->argument) + { + return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})' + , $this->name + , $this->argument->argument_name); + } + else + { + return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)' + , $this->name + , $this->default_value); + } + } + + function getArgument() + { + return $this->argument; + } +} +/* End of file UpdateColumnTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php b/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php index dfa6b9a6b..95915fecf 100644 --- a/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php +++ b/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php @@ -1,61 +1,67 @@ tag inside an XML Query file whose action is 'update' + * + * @author Arnia Software + * @package /classes/xml/xmlquery/tags/column + * @version 0.1 + */ +class UpdateColumnsTag +{ /** - * UpdateColumnsTag - * Models the tag inside an XML Query file whose action is 'update' - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/column - * @version 0.1 + * Column list + * @var array value is UpdateColumnTag object */ - class UpdateColumnsTag{ - /** - * Column list - * @var array value is UpdateColumnTag object - */ - var $columns; + var $columns; - /** - * constructor - * @param array|string $xml_columns - * @return void - */ - function UpdateColumnsTag($xml_columns) { - $this->columns = array(); + /** + * constructor + * @param array|string $xml_columns + * @return void + */ + function UpdateColumnsTag($xml_columns) + { + $this->columns = array(); - if(!is_array($xml_columns)) $xml_columns = array($xml_columns); + if(!is_array($xml_columns)) $xml_columns = array($xml_columns); - foreach($xml_columns as $column){ - if($column->name === 'query') $this->columns[] = new QueryTag($column, true); - else $this->columns[] = new UpdateColumnTag($column); - } + foreach($xml_columns as $column) + { + if($column->name === 'query') $this->columns[] = new QueryTag($column, true); + else $this->columns[] = new UpdateColumnTag($column); } - - /** - * UpdateColumnTag object to string - * @return string - */ - function toString(){ - $output_columns = 'array(' . PHP_EOL; - foreach($this->columns as $column){ - $output_columns .= $column->getExpressionString() . PHP_EOL . ','; - } - $output_columns = substr($output_columns, 0, -1); - $output_columns .= ')'; - return $output_columns; - } - - /** - * Return argument list - * @return array - */ - function getArguments(){ - $arguments = array(); - foreach($this->columns as $column){ - $arguments[] = $column->getArgument(); - } - return $arguments; - } - } -?> + /** + * UpdateColumnTag object to string + * @return string + */ + function toString() + { + $output_columns = 'array(' . PHP_EOL; + foreach($this->columns as $column) + { + $output_columns .= $column->getExpressionString() . PHP_EOL . ','; + } + $output_columns = substr($output_columns, 0, -1); + $output_columns .= ')'; + return $output_columns; + } + + /** + * Return argument list + * @return array + */ + function getArguments() + { + $arguments = array(); + foreach($this->columns as $column) + { + $arguments[] = $column->getArgument(); + } + return $arguments; + } +} +/* End of file UpdateColumnsTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php b/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php index 068c62479..dc17bb225 100644 --- a/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php +++ b/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php @@ -1,66 +1,74 @@ pipe = $pipe; + /** + * constructor + * @param string|array $conditions + * @param string $pipe + * @return void + */ + function ConditionGroupTag($conditions, $pipe = "") + { + $this->pipe = $pipe; - if(!is_array($conditions)) $conditions = array($conditions); + if(!is_array($conditions)) $conditions = array($conditions); - foreach($conditions as $condition){ - //if($condition->node_name === 'query') $this->conditions[] = new QueryTag($condition, true); - $this->conditions[] = new ConditionTag($condition); - } + foreach($conditions as $condition) + { + //if($condition->node_name === 'query') $this->conditions[] = new QueryTag($condition, true); + $this->conditions[] = new ConditionTag($condition); } - - function getConditions(){ - return $this->conditions; - } - - /** - * ConditionTag object to string - * @return string - */ - function getConditionGroupString(){ - $conditions_string = 'array('.PHP_EOL; - foreach($this->conditions as $condition){ - $conditions_string .= $condition->getConditionString() . PHP_EOL . ','; - } - $conditions_string = substr($conditions_string, 0, -2);//remove ',' - $conditions_string .= ')'; - - return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\''.$this->pipe . '\'': ''); - } - - function getArguments(){ - $arguments = array(); - foreach($this->conditions as $condition){ - $arguments = array_merge($arguments, $condition->getArguments()); - } - return $arguments; - } - } -?> + + function getConditions() + { + return $this->conditions; + } + + /** + * ConditionTag object to string + * @return string + */ + function getConditionGroupString() + { + $conditions_string = 'array('.PHP_EOL; + foreach($this->conditions as $condition) + { + $conditions_string .= $condition->getConditionString() . PHP_EOL . ','; + } + $conditions_string = substr($conditions_string, 0, -2);//remove ',' + $conditions_string .= ')'; + + return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\''.$this->pipe . '\'': ''); + } + + function getArguments() + { + $arguments = array(); + foreach($this->conditions as $condition) + { + $arguments = array_merge($arguments, $condition->getArguments()); + } + return $arguments; + } +} +/* End of file ConditionGroupTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/ConditionTag.class.php b/classes/xml/xmlquery/tags/condition/ConditionTag.class.php index 41d845a40..1295318c8 100644 --- a/classes/xml/xmlquery/tags/condition/ConditionTag.class.php +++ b/classes/xml/xmlquery/tags/condition/ConditionTag.class.php @@ -1,156 +1,165 @@ tag inside an XML Query file. Base class. + * + * @author Corina + * @package /classes/xml/xmlquery/tags/condition + * @version 0.1 + */ +class ConditionTag +{ /** - * ConditionTag - * Models the tag inside an XML Query file. Base class. - * - * @author Corina - * @package /classes/xml/xmlquery/tags/condition - * @version 0.1 + * operation for example 'in', 'between', 'not in'... + * @var string */ - class ConditionTag { - /** - * operation for example 'in', 'between', 'not in'... - * @var string - */ - var $operation; - /** - * Column name - * @var string - */ - var $column_name; - /** - * Pipe - * @var string - */ - var $pipe; - /** - * Argument name - * @var string - */ - var $argument_name; - /** - * QueryArgument object - * @var QueryArgument - */ - var $argument; - /** - * Default column - * @var string - */ - var $default_column; - /** - * QueryTag object - * @var QueryTag - */ - var $query; + var $operation; + /** + * Column name + * @var string + */ + var $column_name; + /** + * Pipe + * @var string + */ + var $pipe; + /** + * Argument name + * @var string + */ + var $argument_name; + /** + * QueryArgument object + * @var QueryArgument + */ + var $argument; + /** + * Default column + * @var string + */ + var $default_column; + /** + * QueryTag object + * @var QueryTag + */ + var $query; - /** - * constructor - * @param object $condition - * @return void - */ - function ConditionTag($condition){ - $this->operation = $condition->attrs->operation; - $this->pipe = $condition->attrs->pipe; - $dbParser = DB::getParser(); - $this->column_name = $dbParser->parseExpression($condition->attrs->column); + /** + * constructor + * @param object $condition + * @return void + */ + function ConditionTag($condition) + { + $this->operation = $condition->attrs->operation; + $this->pipe = $condition->attrs->pipe; + $dbParser = DB::getParser(); + $this->column_name = $dbParser->parseExpression($condition->attrs->column); - // If default value is column name, it should be escaped - if($isColumnName = (strpos($condition->attrs->default, '.') !== false - && strpos($condition->attrs->default, '.') !== 0 - && strpos($condition->attrs->default, '%') === false )) - { - $condition->attrs->default = $dbParser->parseExpression($condition->attrs->default); - } + // If default value is column name, it should be escaped + if($isColumnName = (strpos($condition->attrs->default, '.') !== false + && strpos($condition->attrs->default, '.') !== 0 + && strpos($condition->attrs->default, '%') === false )) + { + $condition->attrs->default = $dbParser->parseExpression($condition->attrs->default); + } - if($condition->node_name == 'query') + if($condition->node_name == 'query') + { + $this->query = new QueryTag($condition, TRUE); + $this->default_column = $this->query->toString(); + } + else if($condition->attrs->var && !strpos($condition->attrs->var, '.')) + { + $this->argument = new QueryArgument($condition); + $this->argument_name = $this->argument->getArgumentName(); + } + else + { + if(isset($condition->attrs->default)) { - $this->query = new QueryTag($condition, TRUE); - $this->default_column = $this->query->toString(); - } - else if($condition->attrs->var && !strpos($condition->attrs->var, '.')) - { - $this->argument = new QueryArgument($condition); - $this->argument_name = $this->argument->getArgumentName(); - } - else - { - if(isset($condition->attrs->default)) + $operationList = array('in' => 1, 'between' => 1, 'not in' => 1); + if(isset($operationList[$this->operation])) { - $operationList = array('in' => 1, 'between' => 1, 'not in' => 1); - if(isset($operationList[$this->operation])) + $default_value = $condition->attrs->default; + if(strpos($default_value, "'") !== FALSE) + $default_value = "\"" . $default_value . "\""; + else + { + $default_value = "'" . $default_value . "'"; + } + } + else + { + $default_value_object = new DefaultValue($this->column_name, $condition->attrs->default); + $default_value = $default_value_object->toString(); + + if($default_value_object->isStringFromFunction()) + { + $default_value = '"\'".' . $default_value . '."\'"'; + } + + if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default)) { - $default_value = $condition->attrs->default; if(strpos($default_value, "'") !== FALSE) $default_value = "\"" . $default_value . "\""; else - { - $default_value = "'" . $default_value . "'"; - } + $default_value = "'" . $default_value . "'"; } - else - { - $default_value_object = new DefaultValue($this->column_name, $condition->attrs->default); - $default_value = $default_value_object->toString(); - - if($default_value_object->isStringFromFunction()) - { - $default_value = '"\'".' . $default_value . '."\'"'; - } - - if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default)) - { - if(strpos($default_value, "'") !== FALSE) - $default_value = "\"" . $default_value . "\""; - else - $default_value = "'" . $default_value . "'"; - } - } - $this->default_column = $default_value; } - else - $this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'"; + $this->default_column = $default_value; } - } - - function setPipe($pipe){ - $this->pipe = $pipe; - } - - function getArguments(){ - $arguments = array(); - if($this->query) - $arguments = array_merge($arguments, $this->query->getArguments()); - if($this->argument) - $arguments[] = $this->argument; - return $arguments; - } - - function getConditionString(){ - if($this->query){ - return sprintf("new ConditionSubquery('%s',%s,%s%s)" - , $this->column_name - , $this->default_column - , '"'.$this->operation.'"' - , $this->pipe ? ", '" . $this->pipe . "'" : '' - ); - } - else if(isset($this->default_column)){ - return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)" - , $this->column_name - , $this->default_column - , '"'.$this->operation.'"' - , $this->pipe ? ", '" . $this->pipe . "'" : '' - ); - } - else{ - return sprintf("new ConditionWithArgument('%s',%s,%s%s)" - , $this->column_name - , '$' . $this->argument_name . '_argument' - , '"'.$this->operation.'"' - , $this->pipe ? ", '" . $this->pipe . "'" : '' - ); - } + else + $this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'"; } } -?> + + function setPipe($pipe) + { + $this->pipe = $pipe; + } + + function getArguments() + { + $arguments = array(); + if($this->query) + $arguments = array_merge($arguments, $this->query->getArguments()); + if($this->argument) + $arguments[] = $this->argument; + return $arguments; + } + + function getConditionString() + { + if($this->query) + { + return sprintf("new ConditionSubquery('%s',%s,%s%s)" + , $this->column_name + , $this->default_column + , '"'.$this->operation.'"' + , $this->pipe ? ", '" . $this->pipe . "'" : '' + ); + } + else if(isset($this->default_column)) + { + return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)" + , $this->column_name + , $this->default_column + , '"'.$this->operation.'"' + , $this->pipe ? ", '" . $this->pipe . "'" : '' + ); + } + else + { + return sprintf("new ConditionWithArgument('%s',%s,%s%s)" + , $this->column_name + , '$' . $this->argument_name . '_argument' + , '"'.$this->operation.'"' + , $this->pipe ? ", '" . $this->pipe . "'" : '' + ); + } + } +} +/* End of file ConditionTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/condition/ConditionTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php b/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php index e5a6ef206..a1baf1fd6 100644 --- a/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php +++ b/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php @@ -1,70 +1,81 @@ condition_groups = array(); - if (!$xml_conditions) - return; + /** + * constructor + * @param object $xml_conditions + * @return void + */ + function ConditionsTag($xml_conditions) + { + $this->condition_groups = array(); + if(!$xml_conditions) + return; - $xml_condition_list = array(); - if($xml_conditions->condition) - $xml_condition_list = $xml_conditions->condition; + $xml_condition_list = array(); + if($xml_conditions->condition) + $xml_condition_list = $xml_conditions->condition; - if($xml_conditions->query){ - if(!is_array($xml_condition_list)) $xml_condition_list = array($xml_condition_list); - if(!is_array($xml_conditions->query)) $xml_conditions->query = array($xml_conditions->query); - $xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query); - } - if($xml_condition_list){ - $this->condition_groups[] = new ConditionGroupTag($xml_condition_list); - } - - $xml_groups = $xml_conditions->group; - if($xml_groups){ - if(!is_array($xml_groups)) $xml_groups = array($xml_groups); - foreach($xml_groups as $group){ - $this->condition_groups[] = new ConditionGroupTag($group->condition, $group->attrs->pipe); - } - } + if($xml_conditions->query) + { + if(!is_array($xml_condition_list)) $xml_condition_list = array($xml_condition_list); + if(!is_array($xml_conditions->query)) $xml_conditions->query = array($xml_conditions->query); + $xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query); + } + if($xml_condition_list) + { + $this->condition_groups[] = new ConditionGroupTag($xml_condition_list); } - /** - * ConditionGroupTag object to string - * @return string - */ - function toString(){ - $output_conditions = 'array(' . PHP_EOL; - foreach($this->condition_groups as $condition){ - $output_conditions .= $condition->getConditionGroupString() . PHP_EOL . ','; + $xml_groups = $xml_conditions->group; + if($xml_groups) + { + if(!is_array($xml_groups)) $xml_groups = array($xml_groups); + foreach($xml_groups as $group) + { + $this->condition_groups[] = new ConditionGroupTag($group->condition, $group->attrs->pipe); } - $output_conditions = substr($output_conditions, 0, -1); - $output_conditions .= ')'; - return $output_conditions; - } - - function getArguments(){ - $arguments = array(); - foreach($this->condition_groups as $condition){ - $arguments = array_merge($arguments, $condition->getArguments()); - } - return $arguments; } } -?> + + /** + * ConditionGroupTag object to string + * @return string + */ + function toString() + { + $output_conditions = 'array(' . PHP_EOL; + foreach($this->condition_groups as $condition) + { + $output_conditions .= $condition->getConditionGroupString() . PHP_EOL . ','; + } + $output_conditions = substr($output_conditions, 0, -1); + $output_conditions .= ')'; + return $output_conditions; + } + + function getArguments() + { + $arguments = array(); + foreach($this->condition_groups as $condition) + { + $arguments = array_merge($arguments, $condition->getArguments()); + } + return $arguments; + } +} +/* End of file ConditionsTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/condition/ConditionsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php b/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php index 690b1893d..9e6ce186b 100644 --- a/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php +++ b/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php @@ -1,21 +1,23 @@ condition_groups[0]->conditions[0]->setPipe(""); - } + function JoinConditionsTag($xml_conditions) + { + parent::ConditionsTag($xml_conditions); + $this->condition_groups[0]->conditions[0]->setPipe(""); } - -?> +} +/* End of file JoinConditionsTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/group/GroupsTag.class.php b/classes/xml/xmlquery/tags/group/GroupsTag.class.php index 5da76bd08..c826aeac2 100644 --- a/classes/xml/xmlquery/tags/group/GroupsTag.class.php +++ b/classes/xml/xmlquery/tags/group/GroupsTag.class.php @@ -1,50 +1,56 @@ groups = array(); - - if($xml_groups) { - if(!is_array($xml_groups)) $xml_groups = array($xml_groups); - - $dbParser = &DB::getParser(); - for($i=0;$iattrs->column); - if(!$column) continue; - - $column = $dbParser->parseExpression($column); - $this->groups[] = $column; - } - } - } - - function toString(){ - $output = 'array(' . PHP_EOL; - foreach($this->groups as $group){ - $output .= "'" . $group . "' ,"; + var $groups; + + /** + * constructor + * @param array|string $xml_groups + * @return void + */ + function GroupsTag($xml_groups) + { + $this->groups = array(); + + if($xml_groups) + { + if(!is_array($xml_groups)) $xml_groups = array($xml_groups); + + $dbParser = &DB::getParser(); + for($i=0;$iattrs->column); + if(!$column) continue; + + $column = $dbParser->parseExpression($column); + $this->groups[] = $column; } - $output = substr($output, 0, -1); - $output .= ')'; - return $output; } } -?> + function toString() + { + $output = 'array(' . PHP_EOL; + foreach($this->groups as $group) + { + $output .= "'" . $group . "' ,"; + } + $output = substr($output, 0, -1); + $output .= ')'; + return $output; + } +} +/* End of file GroupsTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/group/GroupsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/navigation/IndexTag.class.php b/classes/xml/xmlquery/tags/navigation/IndexTag.class.php index 3f3a5bc7c..e5d5b7b44 100644 --- a/classes/xml/xmlquery/tags/navigation/IndexTag.class.php +++ b/classes/xml/xmlquery/tags/navigation/IndexTag.class.php @@ -1,77 +1,82 @@ argument_name = $index->attrs->var; + /** + * constructor + * @param object $index + * @return void + */ + function IndexTag($index) + { + $this->argument_name = $index->attrs->var; - // Sort index - column by which to sort - //$dbParser = new DB(); $dbParser = &$dbParser->getParser(); - //$index->attrs->default = $dbParser->parseExpression($index->attrs->default); - $this->default = $index->attrs->default; - $this->argument = new QueryArgument($index); + // Sort index - column by which to sort + //$dbParser = new DB(); $dbParser = &$dbParser->getParser(); + //$index->attrs->default = $dbParser->parseExpression($index->attrs->default); + $this->default = $index->attrs->default; + $this->argument = new QueryArgument($index); - // Sort order - asc / desc - $this->sort_order = $index->attrs->order; - $sortList = array('asc'=>1, 'desc'=>1); - if(!isset($sortList[$this->sort_order])){ - $arg = new Xml_Node_(); - $arg->attrs = new Xml_Node_(); - $arg->attrs->var = $this->sort_order; - $arg->attrs->default = 'asc'; - $this->sort_order_argument = new SortQueryArgument($arg); - $this->sort_order = '$'.$this->sort_order_argument->getArgumentName().'_argument'; - } - else $this->sort_order = '"'.$this->sort_order.'"'; - } - - function toString(){ - return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order); - } - - function getArguments(){ - $arguments = array(); - $arguments[] = $this->argument; - if($this->sort_order_argument) - $arguments[] = $this->sort_order_argument; - return $arguments; + // Sort order - asc / desc + $this->sort_order = $index->attrs->order; + $sortList = array('asc'=>1, 'desc'=>1); + if(!isset($sortList[$this->sort_order])) + { + $arg = new Xml_Node_(); + $arg->attrs = new Xml_Node_(); + $arg->attrs->var = $this->sort_order; + $arg->attrs->default = 'asc'; + $this->sort_order_argument = new SortQueryArgument($arg); + $this->sort_order = '$'.$this->sort_order_argument->getArgumentName().'_argument'; } + else $this->sort_order = '"'.$this->sort_order.'"'; } -?> + function toString() + { + return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order); + } + + function getArguments() + { + $arguments = array(); + $arguments[] = $this->argument; + if($this->sort_order_argument) + $arguments[] = $this->sort_order_argument; + return $arguments; + } +} +/* End of file IndexTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/navigation/IndexTag.class.php */ diff --git a/classes/xml/xmlquery/tags/navigation/LimitTag.class.php b/classes/xml/xmlquery/tags/navigation/LimitTag.class.php index c77c928c3..77d6ed062 100644 --- a/classes/xml/xmlquery/tags/navigation/LimitTag.class.php +++ b/classes/xml/xmlquery/tags/navigation/LimitTag.class.php @@ -1,57 +1,63 @@ page && $index->page->attrs && $index->page_count && $index->page_count->attrs){ - $this->page = new QueryArgument($index->page); - $this->page_count = new QueryArgument($index->page_count); - $this->arguments[] = $this->page; - $this->arguments[] = $this->page_count; - } - - $this->list_count = new QueryArgument($index->list_count); - $this->arguments[] = $this->list_count; + /** + * constructor + * @param object $index + * @return void + */ + function LimitTag($index) + { + if($index->page && $index->page->attrs && $index->page_count && $index->page_count->attrs) + { + $this->page = new QueryArgument($index->page); + $this->page_count = new QueryArgument($index->page_count); + $this->arguments[] = $this->page; + $this->arguments[] = $this->page_count; } - function toString(){ - if ($this->page)return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName()); - else return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName()); - } - - function getArguments(){ - return $this->arguments; - } + $this->list_count = new QueryArgument($index->list_count); + $this->arguments[] = $this->list_count; } -?> + + function toString() + { + if($this->page)return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName()); + else return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName()); + } + + function getArguments() + { + return $this->arguments; + } +} +/* End of file LimitTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/navigation/LimitTag.class.php */ diff --git a/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php b/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php index d5f66c873..f06374787 100644 --- a/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php +++ b/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php @@ -1,99 +1,109 @@ order = array(); - if($xml_navigation) { - $order = $xml_navigation->index; - if($order) { - if(!is_array($order)) $order = array($order); - foreach($order as $order_info) { - $this->order[] = new IndexTag($order_info); - } + /** + * constructor + * @param object $xml_navigation + * @return void + */ + function NavigationTag($xml_navigation) + { + $this->order = array(); + if($xml_navigation) + { + $order = $xml_navigation->index; + if($order) + { + if(!is_array($order)) $order = array($order); + foreach($order as $order_info) + { + $this->order[] = new IndexTag($order_info); + } - if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs) - $this->limit = new LimitTag($xml_navigation); + if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs) + $this->limit = new LimitTag($xml_navigation); - if ($xml_navigation->list_count) - $this->list_count = $xml_navigation->list_count->attrs; + if($xml_navigation->list_count) + $this->list_count = $xml_navigation->list_count->attrs; - if ($xml_navigation->page_count) - $this->page_count = $xml_navigation->page_count->attrs; + if($xml_navigation->page_count) + $this->page_count = $xml_navigation->page_count->attrs; - if ($xml_navigation->page) - $this->page = $xml_navigation->page->attrs; - } - } - } - - /** - * NavigationTag object to string - * @return string - */ - function getOrderByString(){ - $output = 'array(' . PHP_EOL; - foreach($this->order as $order){ - $output .= $order->toString() . PHP_EOL . ','; + if($xml_navigation->page) + $this->page = $xml_navigation->page->attrs; } - $output = substr($output, 0, -1); - $output .= ')'; - return $output; - } - - /** - * LimitTag object to string - * @return string - */ - function getLimitString(){ - if ($this->limit) return $this->limit->toString(); - else return ""; - } - - function getArguments(){ - $arguments = array(); - foreach($this->order as $order){ - $arguments = array_merge($order->getArguments(), $arguments); - } - if($this->limit) $arguments = array_merge($this->limit->getArguments(), $arguments); - return $arguments; } } -?> + /** + * NavigationTag object to string + * @return string + */ + function getOrderByString() + { + $output = 'array(' . PHP_EOL; + foreach($this->order as $order) + { + $output .= $order->toString() . PHP_EOL . ','; + } + $output = substr($output, 0, -1); + $output .= ')'; + return $output; + } + + /** + * LimitTag object to string + * @return string + */ + function getLimitString() + { + if($this->limit) return $this->limit->toString(); + else return ""; + } + + function getArguments() + { + $arguments = array(); + foreach($this->order as $order) + { + $arguments = array_merge($order->getArguments(), $arguments); + } + if($this->limit) $arguments = array_merge($this->limit->getArguments(), $arguments); + return $arguments; + } +} +/* End of file NavigationTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/navigation/NavigationTag.class.php */ diff --git a/classes/xml/xmlquery/tags/query/QueryTag.class.php b/classes/xml/xmlquery/tags/query/QueryTag.class.php index ef9dab3e2..335fab0b8 100644 --- a/classes/xml/xmlquery/tags/query/QueryTag.class.php +++ b/classes/xml/xmlquery/tags/query/QueryTag.class.php @@ -6,7 +6,8 @@ * @package /classes/xml/xmlquery/tags/query * @version 0.1 */ -class QueryTag { +class QueryTag +{ /** * Action for example, 'select', 'insert', 'delete'... * @var string @@ -99,15 +100,17 @@ class QueryTag { * @param bool $isSubQuery * @return void */ - function QueryTag($query, $isSubQuery = false) { + function QueryTag($query, $isSubQuery = false) + { $this->action = $query->attrs->action; $this->query_id = $query->attrs->id; $this->priority = $query->attrs->priority; $this->query = $query; $this->isSubQuery = $isSubQuery; - if ($this->isSubQuery) + if($this->isSubQuery) $this->action = 'select'; - if ($query->attrs->alias) { + if($query->attrs->alias) + { $dbParser = DB::getParser(); $this->alias = $dbParser->escape($query->attrs->alias); } @@ -120,35 +123,42 @@ class QueryTag { $this->getConditions(); $this->getGroups(); $this->getNavigation(); - - + $this->getPrebuff(); $this->getBuff(); } - function show() { + function show() + { return true; } - function getQueryId() { + function getQueryId() + { return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id; } - function getPriority() { + function getPriority() + { return $this->query->attrs->priority; } - function getAction() { + function getAction() + { return $this->query->attrs->action; } - function setTableColumnTypes($tables) { + function setTableColumnTypes($tables) + { $query_id = $this->getQueryId(); - if (!isset($this->column_type[$query_id])) { + if(!isset($this->column_type[$query_id])) + { $table_tags = $tables->getTables(); $column_type = array(); - foreach ($table_tags as $table_tag) { - if (is_a($table_tag, 'TableTag')) { + foreach ($table_tags as $table_tag) + { + if(is_a($table_tag, 'TableTag')) + { $table_name = $table_tag->getTableName(); $table_alias = $table_tag->getTableAlias(); $tag_column_type = QueryParser::getTableInfo($query_id, $table_name); @@ -159,36 +169,48 @@ class QueryTag { } } - function getColumns(){ - if($this->action == 'select'){ + function getColumns() + { + if($this->action == 'select') + { return $this->columns = new SelectColumnsTag($this->query->columns); - }else if($this->action == 'insert' || $this->action == 'insert-select'){ + } + else if($this->action == 'insert' || $this->action == 'insert-select') + { return $this->columns = new InsertColumnsTag($this->query->columns->column); - }else if($this->action == 'update') { + } + else if($this->action == 'update') + { return $this->columns = new UpdateColumnsTag($this->query->columns->column); - }else if($this->action == 'delete') { + } + else if($this->action == 'delete') + { return $this->columns = null; } } - function getPrebuff() { + function getPrebuff() + { if($this->isSubQuery) return; // TODO Check if this work with arguments in join clause $arguments = $this->getArguments(); $prebuff = ''; - foreach ($arguments as $argument) { - if (isset($argument)) { + foreach ($arguments as $argument) + { + if(isset($argument)) + { $arg_name = $argument->getArgumentName(); - if ($arg_name) { + if($arg_name) + { unset($column_type); $prebuff .= $argument->toString(); - + $table_alias = $argument->getTableName(); if(isset($table_alias)) { if (isset($this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()])) - $column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()]; + $column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()]; } else { @@ -200,13 +222,14 @@ class QueryTag { $column_type = $current_table[$column_name]; } } - - + if (isset($column_type)) + { $prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n" - , $arg_name - , $arg_name - , $column_type); + , $arg_name + , $arg_name + , $column_type); + } } } } @@ -215,9 +238,11 @@ class QueryTag { return $this->preBuff = $prebuff; } - function getBuff() { + function getBuff() + { $buff = ''; - if ($this->isSubQuery) { + if($this->isSubQuery) + { $buff = 'new Subquery('; $buff .= "'" . $this->alias . '\', '; $buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL; @@ -239,77 +264,87 @@ class QueryTag { $buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n"); $buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n"); $buff .= $this->preBuff; - if ($this->columns) + if($this->columns) $buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL; - $buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL; + $buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL; if($this->action == 'insert-select') - $buff .= '$query->setSubquery(' . $this->subquery->toString() .');'.PHP_EOL; - $buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL; - $buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL; - $buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL; + $buff .= '$query->setSubquery(' . $this->subquery->toString() .');'.PHP_EOL; + $buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL; + $buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL; + $buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL; $buff .= '$query->setLimit(' . $this->navigation->getLimitString() .');'.PHP_EOL; $this->buff = $buff; return $this->buff; } - function getTables() { + function getTables() + { if($this->query->index_hint && ($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 getSubquery(){ - if($this->query->query){ + function getSubquery() + { + if($this->query->query) + { $this->subquery = new QueryTag($this->query->query, true); } } - - function getConditions(){ + + function getConditions() + { return $this->conditions = new ConditionsTag($this->query->conditions); } - function getGroups() { - if ($this->query->groups) - return $this->groups = new GroupsTag($this->query->groups->group); + function getGroups() + { + if($this->query->groups) + return $this->groups = new GroupsTag($this->query->groups->group); else - return $this->groups = new GroupsTag(NULL); + return $this->groups = new GroupsTag(NULL); } - function getNavigation() { + function getNavigation() + { return $this->navigation = new NavigationTag($this->query->navigation); } - function toString() { + function toString() + { return $this->buff; } - function getTableString() { + function getTableString() + { return $this->buff; } - function getConditionString() { + function getConditionString() + { return $this->buff; } - function getExpressionString() { + function getExpressionString() + { return $this->buff; } - function getArguments(){ + function getArguments() + { $arguments = array(); - if ($this->columns) + if($this->columns) $arguments = array_merge($arguments, $this->columns->getArguments()); if($this->action =='insert-select') $arguments = array_merge($arguments, $this->subquery->getArguments()); - $arguments = array_merge($arguments, $this->tables->getArguments()); + $arguments = array_merge($arguments, $this->tables->getArguments()); $arguments = array_merge($arguments, $this->conditions->getArguments()); $arguments = array_merge($arguments, $this->navigation->getArguments()); return $arguments; } - } - -?> +/* End of file QueryTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/navigation/QueryTag.class.php */ diff --git a/classes/xml/xmlquery/tags/table/HintTableTag.class.php b/classes/xml/xmlquery/tags/table/HintTableTag.class.php index 2c23a786c..54454806d 100644 --- a/classes/xml/xmlquery/tags/table/HintTableTag.class.php +++ b/classes/xml/xmlquery/tags/table/HintTableTag.class.php @@ -1,54 +1,60 @@ tag inside an XML Query file and the corresponding tag + * + * @author Arnia Sowftare + * @package /classes/xml/xmlquery/tags/table + * @version 0.1 + */ +class HintTableTag extends TableTag +{ /** - * HintTableTag - * Models the tag inside an XML Query file and the corresponding tag - * - * @author Arnia Sowftare - * @package /classes/xml/xmlquery/tags/table - * @version 0.1 + * Action for example, 'select', 'insert', 'delete'... + * @var array */ - class HintTableTag extends TableTag { - /** - * Action for example, 'select', 'insert', 'delete'... - * @var array - */ - var $index; + var $index; - /** - * constructor - * Initialises Table Tag properties - * @param object $table XML
tag - * @param array $index - * @return void - */ - 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 == 'Mysqli' ? 'Mysql' : $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(); - } + /** + * constructor + * Initialises Table Tag properties + * @param object $table XML
tag + * @param array $index + * @return void + */ + 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 == 'Mysqli' ? 'Mysql' : $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(); + } +} +/* End of file HintTableTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/table/HintTableTag.class.php */ diff --git a/classes/xml/xmlquery/tags/table/TableTag.class.php b/classes/xml/xmlquery/tags/table/TableTag.class.php index 1c4d066af..11c05328d 100644 --- a/classes/xml/xmlquery/tags/table/TableTag.class.php +++ b/classes/xml/xmlquery/tags/table/TableTag.class.php @@ -1,118 +1,126 @@ tag inside an XML Query file + * @abstract + * Example + *
+ *
+ * Attributes + * name - name of the table - table prefix will be automatically added + * alias - table alias. If no value is specified, the table name will be set as default alias + * join_type - in case the table is part of a join clause, this specifies the type of join: left, right etc. + * - permitted values: 'left join','left outer join','right join','right outer join' + * Children + * Can have children of type + * + * @author Arnia Sowftare + * @package /classes/xml/xmlquery/tags/table + * @version 0.1 + */ +class TableTag +{ /** - * TableTag - * Models the
tag inside an XML Query file - * @abstract - * Example - *
- *
- * Attributes - * name - name of the table - table prefix will be automatically added - * alias - table alias. If no value is specified, the table name will be set as default alias - * join_type - in case the table is part of a join clause, this specifies the type of join: left, right etc. - * - permitted values: 'left join','left outer join','right join','right outer join' - * Children - * Can have children of type - * - * @author Arnia Sowftare - * @package /classes/xml/xmlquery/tags/table - * @version 0.1 + * Unescaped name + * @var string */ - class TableTag { - /** - * Unescaped name - * @var string - */ - var $unescaped_name; - /** - * name - * @var string - */ - var $name; - /** - * alias - * @var string - */ - var $alias; - /** - * Join type - * @example 'left join', 'left outer join', 'right join', 'right outer join' - * @var string - */ - var $join_type; - /** - * Condition object - * @var object - */ - var $conditions; - /** - * JoinConditionsTag - * @var JoinConditionsTag object - */ - var $conditionsTag; + var $unescaped_name; + /** + * name + * @var string + */ + var $name; + /** + * alias + * @var string + */ + var $alias; + /** + * Join type + * @example 'left join', 'left outer join', 'right join', 'right outer join' + * @var string + */ + var $join_type; + /** + * Condition object + * @var object + */ + var $conditions; + /** + * JoinConditionsTag + * @var JoinConditionsTag object + */ + var $conditionsTag; - /** - * constructor - * Initialises Table Tag properties - * @param object $table XML
tag - * @return void - */ - function TableTag($table){ - $dbParser = DB::getParser(); - - $this->unescaped_name = $table->attrs->name; - $this->name = $dbParser->parseTableName($table->attrs->name); - - $this->alias = $table->attrs->alias; - if(!$this->alias) $this->alias = $table->attrs->name; - - $this->join_type = $table->attrs->type; - - $this->conditions = $table->conditions; - - if($this->isJoinTable()) - $this->conditionsTag = new JoinConditionsTag($this->conditions); - } - - function isJoinTable(){ - $joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1); - if(isset($joinList[$this->join_type]) - && count($this->conditions)) return true; - return false; - } - - function getTableAlias(){ - return $this->alias; - } - - function getTableName(){ - return $this->unescaped_name; - } - - /** - * Returns string for printing in PHP query cache file - * The string contains code for instantiation of either - * a Table or a JoinTable object - * @return string - */ - function getTableString(){ - $dbParser = DB::getParser(); + /** + * constructor + * Initialises Table Tag properties + * @param object $table XML
tag + * @return void + */ + function TableTag($table) + { + $dbParser = DB::getParser(); - if($this->isJoinTable()){ - return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)' - , $dbParser->escape($this->name) - , $dbParser->escape($this->alias) - , $this->join_type, $this->conditionsTag->toString()); - } - return sprintf('new Table(\'%s\'%s)' - , $dbParser->escape($this->name) - , $this->alias ? ', \'' . $dbParser->escape($this->alias) .'\'' : ''); - } - - function getArguments(){ - if(!isset($this->conditionsTag)) return array(); - return $this->conditionsTag->getArguments(); - } + $this->unescaped_name = $table->attrs->name; + $this->name = $dbParser->parseTableName($table->attrs->name); + + $this->alias = $table->attrs->alias; + if(!$this->alias) $this->alias = $table->attrs->name; + + $this->join_type = $table->attrs->type; + + $this->conditions = $table->conditions; + + if($this->isJoinTable()) + $this->conditionsTag = new JoinConditionsTag($this->conditions); } -?> + function isJoinTable() + { + $joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1); + if(isset($joinList[$this->join_type]) + && count($this->conditions)) return true; + return false; + } + + function getTableAlias() + { + return $this->alias; + } + + function getTableName() + { + return $this->unescaped_name; + } + + /** + * Returns string for printing in PHP query cache file + * The string contains code for instantiation of either + * a Table or a JoinTable object + * @return string + */ + function getTableString() + { + $dbParser = DB::getParser(); + + if($this->isJoinTable()) + { + return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)' + , $dbParser->escape($this->name) + , $dbParser->escape($this->alias) + , $this->join_type, $this->conditionsTag->toString()); + } + return sprintf('new Table(\'%s\'%s)' + , $dbParser->escape($this->name) + , $this->alias ? ', \'' . $dbParser->escape($this->alias) .'\'' : ''); + } + + function getArguments() + { + if(!isset($this->conditionsTag)) return array(); + return $this->conditionsTag->getArguments(); + } +} +/* End of file TableTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/table/TableTag.class.php */ diff --git a/classes/xml/xmlquery/tags/table/TablesTag.class.php b/classes/xml/xmlquery/tags/table/TablesTag.class.php index bd48e66d0..72b0795e2 100644 --- a/classes/xml/xmlquery/tags/table/TablesTag.class.php +++ b/classes/xml/xmlquery/tags/table/TablesTag.class.php @@ -1,87 +1,99 @@ tag inside an XML Query file + * @abstract + * Example + * + *
+ * + * Attributes + * None. + * Children + * Can have children of type
or + * + * @author Arnia Sowftare + * @package /classes/xml/xmlquery/tags/table + * @version 0.1 + */ +class TablesTag +{ /** - * TablesTag class - * Models the tag inside an XML Query file - * @abstract - * Example - * - *
- * - * Attributes - * None. - * Children - * Can have children of type
or - * - * @author Arnia Sowftare - * @package /classes/xml/xmlquery/tags/table - * @version 0.1 + * Table list + * @var array */ - class TablesTag { - /** - * Table list - * @var array - */ - var $tables; + var $tables; - /** - * constructor - * @param object $xml_tables_tag - * @param object $xml_index_hints_tag - * @return void - */ - function TablesTag($xml_tables_tag, $xml_index_hints_tag = NULL){ - $this->tables = array(); + /** + * constructor + * @param object $xml_tables_tag + * @param object $xml_index_hints_tag + * @return void + */ + 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); + $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(!isset($indexes[$index_node->attrs->table])) $indexes[$index_node->attrs->table] = array(); - $count = count($indexes[$index_node->attrs->table]); - $indexes[$index_node->attrs->table][$count] = (object) NULL; - $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 { - if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name]) - $this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]); - else - $this->tables[] = new TableTag($tag); - } - } - } - - function getTables(){ - return $this->tables; - } - - function toString(){ - $output_tables = 'array(' . PHP_EOL; - foreach($this->tables as $table){ - if(is_a($table, 'QueryTag')) - $output_tables .= $table->toString() . PHP_EOL . ','; - else - $output_tables .= $table->getTableString() . PHP_EOL . ','; + 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(!isset($indexes[$index_node->attrs->table])) $indexes[$index_node->attrs->table] = array(); + $count = count($indexes[$index_node->attrs->table]); + $indexes[$index_node->attrs->table][$count] = (object) NULL; + $indexes[$index_node->attrs->table][$count]->name = $index_node->attrs->name; + $indexes[$index_node->attrs->table][$count]->type = $index_node->attrs->type; } - $output_tables = substr($output_tables, 0, -1); - $output_tables .= ')'; - return $output_tables; } - function getArguments(){ - $arguments = array(); - foreach($this->tables as $table) - $arguments = array_merge($arguments, $table->getArguments()); - return $arguments; - } + foreach($xml_tables as $tag) + { + if($tag->attrs->query == 'true') + { + $this->tables[] = new QueryTag($tag, true); + } + else + { + if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name]) + $this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]); + else + $this->tables[] = new TableTag($tag); + } + } } -?> + + function getTables() + { + return $this->tables; + } + + function toString() + { + $output_tables = 'array(' . PHP_EOL; + foreach($this->tables as $table) + { + if(is_a($table, 'QueryTag')) + $output_tables .= $table->toString() . PHP_EOL . ','; + else + $output_tables .= $table->getTableString() . PHP_EOL . ','; + } + $output_tables = substr($output_tables, 0, -1); + $output_tables .= ')'; + return $output_tables; + } + + function getArguments() + { + $arguments = array(); + foreach($this->tables as $table) + $arguments = array_merge($arguments, $table->getArguments()); + return $arguments; + } +} +/* End of file TablesTag.class.php */ +/* Location: ./classes/xml/xmlquery/tags/table/TablesTag.class.php */