mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-03 17:22:20 +09:00
Added unit tests for correlated subqueries - select, from, where.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8556 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
5d1eb1c21e
commit
1353ade0c2
41 changed files with 661 additions and 256 deletions
|
|
@ -319,6 +319,7 @@
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
||||||
|
require_once(_XE_PATH_.'classes/db/queryparts/Subquery.class.php');
|
||||||
|
|
||||||
|
|
||||||
$output = include($cache_file);
|
$output = include($cache_file);
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@
|
||||||
/**
|
/**
|
||||||
* @brief Fetch results
|
* @brief Fetch results
|
||||||
**/
|
**/
|
||||||
function _fetch($result) {
|
function _fetch($result, $arrayIndexEndValue = NULL) {
|
||||||
if(!$this->isConnected() || $this->isError() || !$result) return;
|
if(!$this->isConnected() || $this->isError() || !$result) return;
|
||||||
|
|
||||||
$c = sqlsrv_num_fields($result);
|
$c = sqlsrv_num_fields($result);
|
||||||
|
|
@ -212,10 +212,14 @@
|
||||||
for($i=0;$i<$c;$i++){
|
for($i=0;$i<$c;$i++){
|
||||||
$row->{$m[$i]['Name']} = sqlsrv_get_field( $result, $i, SQLSRV_PHPTYPE_STRING( 'utf-8' ));
|
$row->{$m[$i]['Name']} = sqlsrv_get_field( $result, $i, SQLSRV_PHPTYPE_STRING( 'utf-8' ));
|
||||||
}
|
}
|
||||||
$output[] = $row;
|
if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $row;
|
||||||
|
else $output[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($output)==1) return $output[0];
|
if(count($output)==1) {
|
||||||
|
if(isset($arrayIndexEndValue)) return $output;
|
||||||
|
else return $output[0];
|
||||||
|
}
|
||||||
return $output;
|
return $output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,7 @@
|
||||||
foreach($this->columns as $column){
|
foreach($this->columns as $column){
|
||||||
if($column->show())
|
if($column->show())
|
||||||
if(is_a($column, 'Subquery')){
|
if(is_a($column, 'Subquery')){
|
||||||
$oDB = &DB::getInstance();
|
$select .= $column->toString($with_values) . ' as '. $column->getAlias() .', ';
|
||||||
$select .= '(' .$oDB->getSelectSql($column, $with_values) . ') as \''. $column->getAlias().'\', ';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$select .= $column->getExpression($with_values) . ', ';
|
$select .= $column->getExpression($with_values) . ', ';
|
||||||
|
|
@ -169,12 +168,18 @@
|
||||||
return $this->tables;
|
return $this->tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from table_a
|
||||||
|
// from table_a inner join table_b on x=y
|
||||||
|
// from (select * from table a) as x
|
||||||
|
// from (select * from table t) as x inner join table y on y.x
|
||||||
function getFromString($with_values = true){
|
function getFromString($with_values = true){
|
||||||
$from = '';
|
$from = '';
|
||||||
$simple_table_count = 0;
|
$simple_table_count = 0;
|
||||||
foreach($this->tables as $table){
|
foreach($this->tables as $table){
|
||||||
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
|
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
|
||||||
else $from .= ', '.$table->toString($with_values) . ' ';
|
else $from .= ', '.$table->toString($with_values) . ' ';
|
||||||
|
if(!$table->isJoinTable()) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
|
||||||
|
|
||||||
$simple_table_count++;
|
$simple_table_count++;
|
||||||
}
|
}
|
||||||
if(trim($from) == '') return '';
|
if(trim($from) == '') return '';
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
class Subquery extends Query {
|
class Subquery extends Query {
|
||||||
var $alias;
|
var $alias;
|
||||||
|
var $join_type;
|
||||||
function Subquery($alias, $columns, $tables, $conditions, $groups, $orderby, $limit){
|
|
||||||
|
function Subquery($alias, $columns, $tables, $conditions, $groups, $orderby, $limit, $join_type = null){
|
||||||
$this->alias = $alias;
|
$this->alias = $alias;
|
||||||
|
|
||||||
$this->queryID = null;
|
$this->queryID = null;
|
||||||
$this->action = null;
|
$this->action = "select";
|
||||||
|
|
||||||
$this->columns = $columns;
|
$this->columns = $columns;
|
||||||
$this->tables = $tables;
|
$this->tables = $tables;
|
||||||
|
|
@ -15,11 +16,23 @@
|
||||||
$this->groups = $groups;
|
$this->groups = $groups;
|
||||||
$this->orderby = $orderby;
|
$this->orderby = $orderby;
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
|
$this->join_type = $join_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAlias(){
|
function getAlias(){
|
||||||
return $this->alias;
|
return $this->alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isJoinTable(){
|
||||||
|
if($this->join_type) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toString($with_values = true){
|
||||||
|
$oDB = &DB::getInstance();
|
||||||
|
return '(' .$oDB->getSelectSql($this, $with_values) . ')';
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
$this->pipe = $pipe;
|
$this->pipe = $pipe;
|
||||||
if($this->hasArgument())
|
if($this->hasArgument())
|
||||||
$this->_value = $argument->getValue();
|
$this->_value = $argument->getValue();
|
||||||
|
else if(is_a($this->argument, 'Subquery'))
|
||||||
|
$this->_value = $argument->toString();
|
||||||
else
|
else
|
||||||
$this->_value = $argument;
|
$this->_value = $argument;
|
||||||
}
|
}
|
||||||
|
|
@ -50,27 +52,27 @@
|
||||||
|
|
||||||
function show(){
|
function show(){
|
||||||
switch($this->operation) {
|
switch($this->operation) {
|
||||||
case 'equal' :
|
case 'equal' :
|
||||||
case 'more' :
|
case 'more' :
|
||||||
case 'excess' :
|
case 'excess' :
|
||||||
case 'less' :
|
case 'less' :
|
||||||
case 'below' :
|
case 'below' :
|
||||||
case 'like_tail' :
|
case 'like_tail' :
|
||||||
case 'like_prefix' :
|
case 'like_prefix' :
|
||||||
case 'like' :
|
case 'like' :
|
||||||
case 'in' :
|
case 'in' :
|
||||||
case 'notin' :
|
case 'notin' :
|
||||||
case 'notequal' :
|
case 'notequal' :
|
||||||
// if variable is not set or is not string or number, return
|
// if variable is not set or is not string or number, return
|
||||||
if(!isset($this->_value)) return false;
|
if(!isset($this->_value)) return false;
|
||||||
if($this->_value === '') return false;
|
if($this->_value === '') return false;
|
||||||
if(!in_array(gettype($this->_value), array('string', 'integer'))) return false;
|
if(!in_array(gettype($this->_value), array('string', 'integer'))) return false;
|
||||||
break;
|
break;
|
||||||
case 'between' :
|
case 'between' :
|
||||||
if(!is_array($this->_value)) return false;
|
if(!is_array($this->_value)) return false;
|
||||||
if(count($this->_value)!=2) return false;
|
if(count($this->_value)!=2) return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,43 +80,43 @@
|
||||||
$name = $this->column_name;
|
$name = $this->column_name;
|
||||||
$operation = $this->operation;
|
$operation = $this->operation;
|
||||||
|
|
||||||
switch($operation) {
|
switch($operation) {
|
||||||
case 'equal' :
|
case 'equal' :
|
||||||
return $name.' = '.$value;
|
return $name.' = '.$value;
|
||||||
break;
|
break;
|
||||||
case 'more' :
|
case 'more' :
|
||||||
return $name.' >= '.$value;
|
return $name.' >= '.$value;
|
||||||
break;
|
break;
|
||||||
case 'excess' :
|
case 'excess' :
|
||||||
return $name.' > '.$value;
|
return $name.' > '.$value;
|
||||||
break;
|
break;
|
||||||
case 'less' :
|
case 'less' :
|
||||||
return $name.' <= '.$value;
|
return $name.' <= '.$value;
|
||||||
break;
|
break;
|
||||||
case 'below' :
|
case 'below' :
|
||||||
return $name.' < '.$value;
|
return $name.' < '.$value;
|
||||||
break;
|
break;
|
||||||
case 'like_tail' :
|
case 'like_tail' :
|
||||||
case 'like_prefix' :
|
case 'like_prefix' :
|
||||||
case 'like' :
|
case 'like' :
|
||||||
return $name.' like '.$value;
|
return $name.' like '.$value;
|
||||||
break;
|
break;
|
||||||
case 'in' :
|
case 'in' :
|
||||||
return $name.' in ('.$value.')';
|
return $name.' in ('.$value.')';
|
||||||
break;
|
break;
|
||||||
case 'notin' :
|
case 'notin' :
|
||||||
return $name.' not in ('.$value.')';
|
return $name.' not in ('.$value.')';
|
||||||
break;
|
break;
|
||||||
case 'notequal' :
|
case 'notequal' :
|
||||||
return $name.' <> '.$value;
|
return $name.' <> '.$value;
|
||||||
break;
|
break;
|
||||||
case 'notnull' :
|
case 'notnull' :
|
||||||
return $name.' is not null';
|
return $name.' is not null';
|
||||||
break;
|
break;
|
||||||
case 'null' :
|
case 'null' :
|
||||||
return $name.' is null';
|
return $name.' is null';
|
||||||
break;
|
break;
|
||||||
case 'between' :
|
case 'between' :
|
||||||
return $name.' between ' . $value[0] . ' and ' . $value[1];
|
return $name.' between ' . $value[0] . ' and ' . $value[1];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function toString(){
|
function toString(){
|
||||||
return sprintf("%s%s", $this->name, $this->alias ? ' as ' . $this->alias : '');
|
return $this->name;
|
||||||
|
//return sprintf("%s%s", $this->name, $this->alias ? ' as ' . $this->alias : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName(){
|
function getName(){
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,21 @@
|
||||||
require_once(_XE_PATH_.'classes/xml/xmlquery/QueryParser.class.php');
|
require_once(_XE_PATH_.'classes/xml/xmlquery/QueryParser.class.php');
|
||||||
|
|
||||||
class XmlQueryParser extends XmlParser {
|
class XmlQueryParser extends XmlParser {
|
||||||
var $dbParser;
|
static $dbParser = null;
|
||||||
var $db_type;
|
var $db_type;
|
||||||
|
|
||||||
function XmlQueryParser($db_type = NULL){
|
function XmlQueryParser($db_type = NULL){
|
||||||
$this->db_type = $db_type;
|
$this->db_type = $db_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function &getInstance($db_type = NULL){
|
||||||
|
static $theInstance = null;
|
||||||
|
if(!isset($theInstance)){
|
||||||
|
$theInstance = new XmlQueryParser($db_type);
|
||||||
|
}
|
||||||
|
return $theInstance;
|
||||||
|
}
|
||||||
|
|
||||||
function parse($query_id, $xml_file, $cache_file) {
|
function parse($query_id, $xml_file, $cache_file) {
|
||||||
|
|
||||||
// Read xml file
|
// Read xml file
|
||||||
|
|
@ -36,15 +44,19 @@
|
||||||
|
|
||||||
// singleton
|
// singleton
|
||||||
function &getDBParser(){
|
function &getDBParser(){
|
||||||
static $dbParser;
|
if(!$self->dbParser){
|
||||||
if(!$dbParser){
|
is_a($this,'XmlQueryParser')?$self=&$this:$self=&XmlQueryParser::getInstance();
|
||||||
if(isset($this->db_type))
|
if(isset($self->db_type))
|
||||||
$oDB = &DB::getInstance($this->db_type);
|
$oDB = &DB::getInstance($self->db_type);
|
||||||
else
|
else
|
||||||
$oDB = &DB::getInstance();
|
$oDB = &DB::getInstance();
|
||||||
$dbParser = $oDB->getParser();
|
$self->dbParser = $oDB->getParser();
|
||||||
}
|
}
|
||||||
return $dbParser;
|
return $self->dbParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDBParser($value){
|
||||||
|
$self->dbParser = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getXmlFileContent($xml_file){
|
function getXmlFileContent($xml_file){
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@
|
||||||
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){
|
foreach($xml_columns as $column){
|
||||||
if($column->node_name == 'query') $this->columns[] = new QueryTag($column, true);
|
$this->columns[] = new SelectColumnTag($column);
|
||||||
else $this->columns[] = new SelectColumnTag($column);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@
|
||||||
if(count($conditions))require_once(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
if(count($conditions))require_once(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||||
|
|
||||||
foreach($conditions as $condition){
|
foreach($conditions as $condition){
|
||||||
if($condition->name === 'query') $this->conditions[] = new QueryTag($condition, true);
|
//if($condition->node_name === 'query') $this->conditions[] = new QueryTag($condition, true);
|
||||||
else $this->conditions[] = new ConditionTag($condition);
|
$this->conditions[] = new ConditionTag($condition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,8 +22,9 @@
|
||||||
|
|
||||||
function getConditionGroupString(){
|
function getConditionGroupString(){
|
||||||
$conditions_string = 'array('.PHP_EOL;
|
$conditions_string = 'array('.PHP_EOL;
|
||||||
foreach($this->conditions as $condition)
|
foreach($this->conditions as $condition){
|
||||||
$conditions_string .= $condition->getConditionString() . PHP_EOL . ',';
|
$conditions_string .= $condition->getConditionString() . PHP_EOL . ',';
|
||||||
|
}
|
||||||
$conditions_string = substr($conditions_string, 0, -2);//remove ','
|
$conditions_string = substr($conditions_string, 0, -2);//remove ','
|
||||||
$conditions_string .= ')';
|
$conditions_string .= ')';
|
||||||
|
|
||||||
|
|
@ -33,6 +34,9 @@
|
||||||
function getArguments(){
|
function getArguments(){
|
||||||
$arguments = array();
|
$arguments = array();
|
||||||
foreach($this->conditions as $condition){
|
foreach($this->conditions as $condition){
|
||||||
|
if(is_a($condition, 'QueryTag'))
|
||||||
|
$arguments = array_merge($arguments, $condition->getArguments());
|
||||||
|
else
|
||||||
$arguments[] = $condition->getArgument();
|
$arguments[] = $condition->getArgument();
|
||||||
}
|
}
|
||||||
return $arguments;
|
return $arguments;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
var $argument;
|
var $argument;
|
||||||
var $default_column;
|
var $default_column;
|
||||||
|
|
||||||
|
var $query;
|
||||||
function ConditionTag($condition){
|
function ConditionTag($condition){
|
||||||
$this->operation = $condition->attrs->operation;
|
$this->operation = $condition->attrs->operation;
|
||||||
$this->pipe = $condition->attrs->pipe;
|
$this->pipe = $condition->attrs->pipe;
|
||||||
|
|
@ -23,20 +24,20 @@
|
||||||
$this->column_name = $dbParser->parseColumnName($condition->attrs->column);
|
$this->column_name = $dbParser->parseColumnName($condition->attrs->column);
|
||||||
|
|
||||||
$isColumnName = strpos($condition->attrs->default, '.');
|
$isColumnName = strpos($condition->attrs->default, '.');
|
||||||
|
|
||||||
if($condition->attrs->var || $isColumnName === false){
|
if($condition->node_name == 'query'){
|
||||||
|
$this->query = new QueryTag($condition, true);
|
||||||
|
$this->default_column = $this->query->toString();
|
||||||
|
}
|
||||||
|
else if($condition->attrs->var || $isColumnName === false){
|
||||||
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||||
//$this->argument_name = $condition->attrs->var;
|
|
||||||
|
|
||||||
$this->argument = new QueryArgument($condition);
|
$this->argument = new QueryArgument($condition);
|
||||||
$this->argument_name = $this->argument->getArgumentName();
|
$this->argument_name = $this->argument->getArgumentName();
|
||||||
}
|
}
|
||||||
//else if($isColumnName === false){
|
|
||||||
// $this->default_column = $condition->attrs->default;
|
|
||||||
//}
|
|
||||||
else {
|
else {
|
||||||
$this->default_column = $dbParser->parseColumnName($condition->attrs->default);
|
$this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->default) . "'" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPipe($pipe){
|
function setPipe($pipe){
|
||||||
|
|
@ -49,11 +50,11 @@
|
||||||
|
|
||||||
function getConditionString(){
|
function getConditionString(){
|
||||||
return sprintf("new Condition('%s',%s,%s%s)"
|
return sprintf("new Condition('%s',%s,%s%s)"
|
||||||
, $this->column_name
|
, $this->column_name
|
||||||
, $this->default_column ? "'" . $this->default_column . "'" : '$' . $this->argument_name . '_argument'
|
, $this->default_column ? $this->default_column: '$' . $this->argument_name . '_argument'
|
||||||
, '"'.$this->operation.'"'
|
, '"'.$this->operation.'"'
|
||||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
@ -5,7 +5,15 @@
|
||||||
function ConditionsTag($xml_conditions){
|
function ConditionsTag($xml_conditions){
|
||||||
$this->condition_groups = array();
|
$this->condition_groups = array();
|
||||||
|
|
||||||
$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){
|
if($xml_condition_list){
|
||||||
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||||
$this->condition_groups[] = new ConditionGroupTag($xml_condition_list);
|
$this->condition_groups[] = new ConditionGroupTag($xml_condition_list);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class QueryTag {
|
||||||
var $buff;
|
var $buff;
|
||||||
var $isSubQuery;
|
var $isSubQuery;
|
||||||
|
|
||||||
|
var $join_type;
|
||||||
var $alias;
|
var $alias;
|
||||||
|
|
||||||
function QueryTag($query, $isSubQuery = false){
|
function QueryTag($query, $isSubQuery = false){
|
||||||
|
|
@ -26,6 +27,7 @@ class QueryTag {
|
||||||
$this->isSubQuery = $isSubQuery;
|
$this->isSubQuery = $isSubQuery;
|
||||||
if($this->isSubQuery) $this->action = 'select';
|
if($this->isSubQuery) $this->action = 'select';
|
||||||
$this->alias = $query->attrs->alias;
|
$this->alias = $query->attrs->alias;
|
||||||
|
$this->join_type = $query->attrs->join_type;
|
||||||
|
|
||||||
$this->getColumns();
|
$this->getColumns();
|
||||||
$tables = $this->getTables();
|
$tables = $this->getTables();
|
||||||
|
|
@ -55,8 +57,10 @@ class QueryTag {
|
||||||
$table_tags = $tables->getTables();
|
$table_tags = $tables->getTables();
|
||||||
$column_type = array();
|
$column_type = array();
|
||||||
foreach($table_tags as $table_tag){
|
foreach($table_tags as $table_tag){
|
||||||
|
if(is_a($table_tag, 'TableTag')){
|
||||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_tag->getTableName());
|
$tag_column_type = QueryParser::getTableInfo($query_id, $table_tag->getTableName());
|
||||||
$column_type = array_merge($column_type, $tag_column_type);
|
$column_type = array_merge($column_type, $tag_column_type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->column_type[$query_id] = $column_type;
|
$this->column_type[$query_id] = $column_type;
|
||||||
}
|
}
|
||||||
|
|
@ -94,17 +98,17 @@ class QueryTag {
|
||||||
|
|
||||||
function getBuff(){
|
function getBuff(){
|
||||||
$buff = '';
|
$buff = '';
|
||||||
//echo 'Luam un query care e '.$this->isSubQuery;
|
|
||||||
if($this->isSubQuery){
|
if($this->isSubQuery){
|
||||||
$buff = 'new Subquery(';
|
$buff = 'new Subquery(';
|
||||||
$buff .= "'" . $this->alias . '\', ';
|
$buff .= "'\"" . $this->alias . '"\', ';
|
||||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ). ', '.PHP_EOL;
|
$buff .= ($this->columns ? $this->columns->toString() : 'null' ). ', '.PHP_EOL;
|
||||||
$buff .= $this->tables->toString() .','.PHP_EOL;
|
$buff .= $this->tables->toString() .','.PHP_EOL;
|
||||||
$buff .= $this->conditions->toString() .',' .PHP_EOL;
|
$buff .= $this->conditions->toString() .',' .PHP_EOL;
|
||||||
$buff .= $this->groups->toString() . ',' .PHP_EOL;
|
$buff .= $this->groups->toString() . ',' .PHP_EOL;
|
||||||
$buff .= $this->navigation->getOrderByString() .','.PHP_EOL;
|
$buff .= $this->navigation->getOrderByString() .','.PHP_EOL;
|
||||||
$limit = $this->navigation->getLimitString() ;
|
$limit = $this->navigation->getLimitString() ;
|
||||||
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
||||||
|
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
|
||||||
$buff .= ')';
|
$buff .= ')';
|
||||||
|
|
||||||
$this->buff = $buff;
|
$this->buff = $buff;
|
||||||
|
|
@ -129,7 +133,7 @@ class QueryTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTables(){
|
function getTables(){
|
||||||
return $this->tables = new TablesTag($this->query->tables->table);
|
return $this->tables = new TablesTag($this->query->tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConditions(){
|
function getConditions(){
|
||||||
|
|
@ -160,6 +164,7 @@ class QueryTag {
|
||||||
return $this->buff;
|
return $this->buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getArguments(){
|
function getArguments(){
|
||||||
$arguments = array();
|
$arguments = array();
|
||||||
if($this->columns)
|
if($this->columns)
|
||||||
|
|
@ -170,4 +175,4 @@ class QueryTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,17 @@
|
||||||
* @author Arnia Sowftare
|
* @author Arnia Sowftare
|
||||||
* @brief Models the <table> tag inside an XML Query file
|
* @brief Models the <table> tag inside an XML Query file
|
||||||
*
|
*
|
||||||
|
* @abstract
|
||||||
|
* Example
|
||||||
|
* <table name="modules" />
|
||||||
|
* <table name="documents" alias="doc" />
|
||||||
|
* 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 <conditions>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class TableTag {
|
class TableTag {
|
||||||
|
|
@ -16,7 +27,6 @@
|
||||||
var $conditions;
|
var $conditions;
|
||||||
|
|
||||||
function TableTag($table){
|
function TableTag($table){
|
||||||
|
|
||||||
$this->unescaped_name = $table->attrs->name;
|
$this->unescaped_name = $table->attrs->name;
|
||||||
|
|
||||||
$dbParser = XmlQueryParser::getDBParser();
|
$dbParser = XmlQueryParser::getDBParser();
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,29 @@
|
||||||
class TablesTag {
|
class TablesTag {
|
||||||
var $tables;
|
var $tables;
|
||||||
|
|
||||||
function TablesTag($xml_tables){
|
function TablesTag($xml_tables_tag){
|
||||||
$this->tables = array();
|
$xml_tables = $xml_tables_tag->table;
|
||||||
if(!is_array($xml_tables)) $xml_tables = array($xml_tables);
|
$xml_queries = $xml_tables_tag->query;
|
||||||
|
|
||||||
if(count($xml_tables)) require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
$this->tables = array();
|
||||||
|
|
||||||
foreach($xml_tables as $table){
|
|
||||||
if($table->name === 'query') $this->tables[] = new QueryTag($table, true);
|
if($xml_tables){
|
||||||
else $this->tables[] = new TableTag($table);
|
if(!is_array($xml_tables)) $xml_tables = array($xml_tables);
|
||||||
}
|
|
||||||
|
if(count($xml_tables)) require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||||
|
|
||||||
|
foreach($xml_tables as $table){
|
||||||
|
if($table->name === 'query') $this->tables[] = new QueryTag($table, true);
|
||||||
|
else $this->tables[] = new TableTag($table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!$xml_queries) return;
|
||||||
|
if(!is_array($xml_queries)) $xml_queries = array($xml_queries);
|
||||||
|
|
||||||
|
foreach($xml_queries as $table){
|
||||||
|
$this->tables[] = new QueryTag($table, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTables(){
|
function getTables(){
|
||||||
|
|
@ -21,8 +34,11 @@
|
||||||
|
|
||||||
function toString(){
|
function toString(){
|
||||||
$output_tables = 'array(' . PHP_EOL;
|
$output_tables = 'array(' . PHP_EOL;
|
||||||
foreach($this->tables as $table){
|
foreach($this->tables as $table){
|
||||||
$output_tables .= $table->getTableString() . PHP_EOL . ',';
|
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 = substr($output_tables, 0, -1);
|
||||||
$output_tables .= ')';
|
$output_tables .= ')';
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* @brief set the include of the class file and other environment configurations
|
* @brief set the include of the class file and other environment configurations
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@error_reporting(E_ALL ^ E_NOTICE);
|
@error_reporting((E_ALL ^ E_NOTICE) ^ E_DEPRECATED);
|
||||||
|
|
||||||
if(!defined('__ZBXE__')) exit();
|
if(!defined('__ZBXE__')) exit();
|
||||||
|
|
||||||
|
|
|
||||||
14
nbproject/project.properties
Normal file
14
nbproject/project.properties
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
include.path=\
|
||||||
|
${php.global.include.path}
|
||||||
|
php.version=PHP_5
|
||||||
|
phpunit.bootstrap=test-phpUnit/config/config.inc.php
|
||||||
|
phpunit.bootstrap.create.tests=true
|
||||||
|
phpunit.configuration=
|
||||||
|
phpunit.run.test.files=false
|
||||||
|
phpunit.suite=
|
||||||
|
source.encoding=UTF-8
|
||||||
|
src.dir=.
|
||||||
|
tags.asp=false
|
||||||
|
tags.short=true
|
||||||
|
test.src.dir=test-phpUnit
|
||||||
|
web.root=.
|
||||||
9
nbproject/project.xml
Normal file
9
nbproject/project.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.php.project</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/php-project/1">
|
||||||
|
<name>mssql</name>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Helper {
|
class Helper {
|
||||||
function cleanQuery($query){
|
static function cleanQuery($query){
|
||||||
$query = trim(preg_replace('/\s+/', ' ',$query));
|
$query = trim(preg_replace('/\s+/', ' ',$query));
|
||||||
$query = str_replace(" , ", ', ', $query);
|
$query = str_replace(" , ", ', ', $query);
|
||||||
$query = str_replace("( ", '(', $query);
|
$query = str_replace("( ", '(', $query);
|
||||||
|
|
@ -9,6 +9,12 @@
|
||||||
$query = strtolower($query);
|
$query = strtolower($query);
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getXmlObject($xml_file){
|
||||||
|
$xmlParser = XmlQueryParser::getInstance();
|
||||||
|
return $xmlParser->getXmlFileContent($xml_file);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
return _XE_PATH_ . $type ."/".$name."/queries/" . $query_name . ".xml";
|
return _XE_PATH_ . $type ."/".$name."/queries/" . $query_name . ".xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNewParserOutput($xml_file, $escape_char = '"', $db_type = NULL){
|
function getNewParserOutput($xml_file){
|
||||||
$newXmlQueryParser = new XmlQueryParser($db_type);
|
$newXmlQueryParser = new XmlQueryParser();
|
||||||
$xml_obj = $newXmlQueryParser->getXmlFileContent($xml_file);
|
$xml_obj = $newXmlQueryParser->getXmlFileContent($xml_file);
|
||||||
|
|
||||||
$parser = new QueryParser($xml_obj->query);
|
$parser = new QueryParser($xml_obj->query);
|
||||||
|
|
@ -58,9 +58,9 @@
|
||||||
.'</pre>';
|
.'</pre>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNewParserOutputString($xml_file, $escape_char, $argsString, $db_type = NULL){
|
function getNewParserOutputString($xml_file, $argsString){
|
||||||
$outputString = '';
|
$outputString = '';
|
||||||
$outputString = $this->getNewParserOutput($xml_file, $escape_char, $db_type);
|
$outputString = $this->getNewParserOutput($xml_file);
|
||||||
$outputString = $this->cleanOutputAndAddArgs($outputString, $argsString);
|
$outputString = $this->cleanOutputAndAddArgs($outputString, $argsString);
|
||||||
return $outputString;
|
return $outputString;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
134
test-phpUnit/classes/xml/xmlquery/tags/table/TableTagTest.php
Normal file
134
test-phpUnit/classes/xml/xmlquery/tags/table/TableTagTest.php
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
<?php
|
||||||
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for TableTag.
|
||||||
|
*/
|
||||||
|
class TableTagTest extends CubridTest {
|
||||||
|
|
||||||
|
var $xmlPath = "data/";
|
||||||
|
|
||||||
|
function TableTagTest(){
|
||||||
|
$this->xmlPath = str_replace('TableTagTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a simple <table> tag:
|
||||||
|
* <table name="modules" />
|
||||||
|
*/
|
||||||
|
function testTableTagWithName(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$expected = "new Table('\"xe_modules\"', '\"modules\"')";
|
||||||
|
$actual = $tag->getTableString();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a <table> tag with name and alias
|
||||||
|
* <table name="modules" alias="mod" />
|
||||||
|
*/
|
||||||
|
function testTableTagWithNameAndAlias(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name_alias.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$expected = "new Table('\"xe_modules\"', '\"mod\"')";
|
||||||
|
$actual = $tag->getTableString();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a <table> tag used for joins
|
||||||
|
* <table name="module_categories" alias="module_categories" type="left join">
|
||||||
|
* <conditions>
|
||||||
|
* <condition operation="equal" column="module_categories.module_category_srl" default="modules.module_category_srl" />
|
||||||
|
* </conditions>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function testTableTagWithJoinCondition(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name_alias_type.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$actual = $tag->getTableString();
|
||||||
|
|
||||||
|
$expected = 'new JoinTable(\'"xe_module_categories"\', \'"module_categories"\', "left join", array(
|
||||||
|
new ConditionGroup(array(
|
||||||
|
new Condition(\'"module_categories"."module_category_srl"\',\'"modules"."module_category_srl"\',"equal")
|
||||||
|
))
|
||||||
|
))';
|
||||||
|
$actual = Helper::cleanQuery($actual);
|
||||||
|
$expected = Helper::cleanQuery($expected);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a table tag has the type attribute and condition children
|
||||||
|
* it means it is meant to be used inside a join
|
||||||
|
*/
|
||||||
|
function testTagWithTypeIsJoinTable(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name_alias_type.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$this->assertEquals(true, $tag->isJoinTable());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that a simple table tag is not a join table
|
||||||
|
*/
|
||||||
|
function testTagWithoutTypeIsNotJoinTable(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name_alias.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$this->assertEquals(false, $tag->isJoinTable());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If no alias is specified, test that table name is used
|
||||||
|
*/
|
||||||
|
function testTableAliasWhenAliasNotSpecified(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$this->assertEquals("modules", $tag->getTableAlias());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If alias is specified, test that it is used
|
||||||
|
*/
|
||||||
|
function testTableAliasWhenAliasSpecified(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name_alias.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$this->assertEquals("mod", $tag->getTableAlias());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table name propery should returned unescaped and unprefixed table name
|
||||||
|
* (The one in the XML file)
|
||||||
|
*/
|
||||||
|
function testTableName(){
|
||||||
|
$xml_file = $this->xmlPath . "table_name_alias.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
|
||||||
|
$tag = new TableTag($xml_obj->table);
|
||||||
|
|
||||||
|
$this->assertEquals("modules", $tag->getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<table name="modules" />
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<table name="modules" alias="mod" />
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<table name="module_categories" alias="module_categories" type="left join">
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="module_categories.module_category_srl" default="modules.module_category_srl" />
|
||||||
|
</conditions>
|
||||||
|
</table>
|
||||||
|
|
@ -1,17 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
error_reporting(E_ALL ^ E_NOTICE);
|
error_reporting(E_ALL ^ E_NOTICE);
|
||||||
define('_XE_PATH_', str_replace('test-phpUnit/config.inc.php', '', str_replace('\\', '/', __FILE__)));
|
define('_XE_PATH_', str_replace('test-phpUnit/config/config.inc.php', '', str_replace('\\', '/', __FILE__)));
|
||||||
//define('_TEST_PATH_', substr(_XE_PATH_,0,strrpos(substr(_XE_PATH_,0.-1),'/')));
|
define('_TEST_PATH_', _XE_PATH_ . 'test-phpUnit/');
|
||||||
|
|
||||||
if(!defined('__DEBUG__')) define('__DEBUG__', 4);
|
if(!defined('__DEBUG__')) define('__DEBUG__', 4);
|
||||||
|
|
||||||
require_once(_XE_PATH_.'test-phpUnit/Helper.class.php');
|
require_once(_XE_PATH_.'test-phpUnit/Helper.class.php');
|
||||||
|
require_once(_XE_PATH_.'test-phpUnit/QueryTester.class.php');
|
||||||
|
require_once(_XE_PATH_.'test-phpUnit/db/DBTest.php');
|
||||||
|
require_once(_XE_PATH_.'test-phpUnit/db/CubridTest.php');
|
||||||
|
|
||||||
|
|
||||||
require_once(_XE_PATH_.'classes/object/Object.class.php');
|
require_once(_XE_PATH_.'classes/object/Object.class.php');
|
||||||
require_once(_XE_PATH_.'classes/handler/Handler.class.php');
|
require_once(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||||
require_once(_XE_PATH_.'classes/context/Context.class.php');
|
require_once(_XE_PATH_.'classes/context/Context.class.php');
|
||||||
require_once(_XE_PATH_.'classes/file/FileHandler.class.php');
|
require_once(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||||
require_once('QueryTester.class.php');
|
|
||||||
require_once(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
require_once(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||||
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
|
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
|
||||||
|
|
||||||
|
|
@ -35,5 +38,8 @@
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
||||||
|
require_once(_XE_PATH_.'classes/db/queryparts/Subquery.class.php');
|
||||||
|
|
||||||
|
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
24
test-phpUnit/db/CubridTest.php
Normal file
24
test-phpUnit/db/CubridTest.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CubridTest extends DBTest {
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$oContext = &Context::getInstance();
|
||||||
|
|
||||||
|
$db_info->db_type = 'cubrid';
|
||||||
|
$db_info->db_table_prefix = 'xe';
|
||||||
|
|
||||||
|
$oContext->setDbInfo($db_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown() {
|
||||||
|
unset($GLOBALS['__DB__']);
|
||||||
|
XmlQueryParser::setDBParser(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
54
test-phpUnit/db/DBTest.php
Normal file
54
test-phpUnit/db/DBTest.php
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
class DBTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
function _testQuery($xml_file, $argsString, $expected, $methodName){
|
||||||
|
$tester = new QueryTester();
|
||||||
|
$outputString = $tester->getNewParserOutputString($xml_file, $argsString);
|
||||||
|
$output = eval($outputString);
|
||||||
|
|
||||||
|
if(!is_a($output, 'Query')){
|
||||||
|
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||||
|
}else {
|
||||||
|
$db = &DB::getInstance();
|
||||||
|
$querySql = $db->{$methodName}($output);
|
||||||
|
|
||||||
|
// Remove whitespaces, tabs and all
|
||||||
|
$querySql = Helper::cleanQuery($querySql);
|
||||||
|
$expected = Helper::cleanQuery($expected);
|
||||||
|
}
|
||||||
|
$this->assertEquals($expected, $querySql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _testPreparedQuery($xml_file, $argsString, $expected, $methodName, $expectedArgs = NULL){
|
||||||
|
$tester = new QueryTester();
|
||||||
|
$outputString = $tester->getNewParserOutputString($xml_file, $argsString);
|
||||||
|
$output = eval($outputString);
|
||||||
|
|
||||||
|
if(!is_a($output, 'Query')){
|
||||||
|
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||||
|
}else {
|
||||||
|
$db = &DB::getInstance();
|
||||||
|
$querySql = $db->{$methodName}($output);
|
||||||
|
$queryArguments = $output->getArguments();
|
||||||
|
|
||||||
|
// Remove whitespaces, tabs and all
|
||||||
|
$querySql = Helper::cleanQuery($querySql);
|
||||||
|
$expected = Helper::cleanQuery($expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test
|
||||||
|
$this->assertEquals($expected, $querySql);
|
||||||
|
|
||||||
|
// Test query arguments
|
||||||
|
$argCount = count($expectedArgs);
|
||||||
|
for($i = 0; $i < $argCount; $i++){
|
||||||
|
//echo "$i: $expectedArgs[$i] vs $queryArguments[$i]->getValue()";
|
||||||
|
$this->assertEquals($expectedArgs[$i], $queryArguments[$i]->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
require(_XE_PATH_ . 'test-phpUnit/config.inc.php');
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
|
|
||||||
class ExpressionParserTest extends PHPUnit_Framework_TestCase {
|
class ExpressionParserTest extends PHPUnit_Framework_TestCase {
|
||||||
/* Escape char for:
|
/* Escape char for:
|
||||||
|
|
|
||||||
24
test-phpUnit/db/MssqlTest.php
Normal file
24
test-phpUnit/db/MssqlTest.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class MssqlTest extends DBTest {
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$oContext = &Context::getInstance();
|
||||||
|
|
||||||
|
$db_info->db_type = 'mssql';
|
||||||
|
$db_info->db_table_prefix = 'xe';
|
||||||
|
|
||||||
|
$oContext->setDbInfo($db_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown() {
|
||||||
|
unset($GLOBALS['__DB__']);
|
||||||
|
XmlQueryParser::setDBParser(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -1,28 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
require(_XE_PATH_ . 'test-phpUnit/config.inc.php');
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
require(_XE_PATH_ . 'test-phpUnit/db/xml_query/cubrid/config.cubrid.inc.php');
|
|
||||||
|
|
||||||
class CubridDeleteTest extends PHPUnit_Framework_TestCase {
|
class CubridDeleteTest extends CubridTest {
|
||||||
|
|
||||||
function _test($xml_file, $argsString, $expected){
|
function _test($xml_file, $argsString, $expected){
|
||||||
$tester = new QueryTester();
|
$this->_testQuery($xml_file, $argsString, $expected, 'getDeleteSql');
|
||||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
|
||||||
$output = eval($outputString);
|
|
||||||
|
|
||||||
if(!is_a($output, 'Query')){
|
|
||||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
|
||||||
}else {
|
|
||||||
$db = &DB::getInstance();
|
|
||||||
var_dump($db);
|
|
||||||
$querySql = $db->getDeleteSql($output);
|
|
||||||
|
|
||||||
// Remove whitespaces, tabs and all
|
|
||||||
$querySql = Helper::cleanQuery($querySql);
|
|
||||||
$expected = Helper::cleanQuery($expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test
|
|
||||||
$this->assertEquals($expected, $querySql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_module_deleteActionForward(){
|
function test_module_deleteActionForward(){
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
require(_XE_PATH_ . 'test-phpUnit/config.inc.php');
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
require(_XE_PATH_ . 'test-phpUnit/db/xml_query/cubrid/config.cubrid.inc.php');
|
|
||||||
|
|
||||||
class CubridInsertTest extends PHPUnit_Framework_TestCase {
|
class CubridInsertTest extends CubridTest {
|
||||||
|
|
||||||
function _test($xml_file, $argsString, $expected){
|
function _test($xml_file, $argsString, $expected){
|
||||||
$tester = new QueryTester();
|
$this->_testQuery($xml_file, $argsString, $expected, 'getInsertSql');
|
||||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
|
||||||
$output = eval($outputString);
|
|
||||||
|
|
||||||
if(!is_a($output, 'Query')){
|
|
||||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
|
||||||
}else {
|
|
||||||
$db = &DB::getInstance();
|
|
||||||
$querySql = $db->getInsertSql($output);
|
|
||||||
|
|
||||||
// Remove whitespaces, tabs and all
|
|
||||||
$querySql = Helper::cleanQuery($querySql);
|
|
||||||
$expected = Helper::cleanQuery($expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test
|
|
||||||
$this->assertEquals($expected, $querySql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: this test can fail when comaparing regdate from the $args with
|
* Note: this test can fail when comaparing regdate from the $args with
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
require(_XE_PATH_ . 'test-phpUnit/config.inc.php');
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
require(_XE_PATH_ . 'test-phpUnit/db/xml_query/cubrid/config.cubrid.inc.php');
|
|
||||||
|
|
||||||
class CubridSelectTest extends PHPUnit_Framework_TestCase {
|
class CubridSelectTest extends CubridTest {
|
||||||
|
|
||||||
function _test($xml_file, $argsString, $expected){
|
function _test($xml_file, $argsString, $expected){
|
||||||
$tester = new QueryTester();
|
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
|
||||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
|
||||||
|
|
||||||
//echo $outputString;
|
|
||||||
$output = eval($outputString);
|
|
||||||
|
|
||||||
if(!is_a($output, 'Query')){
|
|
||||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
|
||||||
}else {
|
|
||||||
//$db = new DBCubrid();
|
|
||||||
$db = &DB::getInstance();
|
|
||||||
$querySql = $db->getSelectSql($output);
|
|
||||||
|
|
||||||
// Remove whitespaces, tabs and all
|
|
||||||
$querySql = Helper::cleanQuery($querySql);
|
|
||||||
$expected = Helper::cleanQuery($expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test
|
|
||||||
$this->assertEquals($expected, $querySql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSelectStar(){
|
function testSelectStar(){
|
||||||
|
|
|
||||||
77
test-phpUnit/db/xml_query/cubrid/CubridSubqueryTest.php
Normal file
77
test-phpUnit/db/xml_query/cubrid/CubridSubqueryTest.php
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CubridSubqueryTest extends CubridTest {
|
||||||
|
var $xmlPath = 'data/';
|
||||||
|
|
||||||
|
function CubridSubqueryTest(){
|
||||||
|
$this->xmlPath = str_replace('CubridSubqueryTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _test($xml_file, $argsString, $expected){
|
||||||
|
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSelectUncorrelated1(){
|
||||||
|
$xml_file = $this->xmlPath . "select_uncorrelated1.xml";
|
||||||
|
echo $xml_file;
|
||||||
|
$argsString = '$args->user_id = 4;
|
||||||
|
';
|
||||||
|
$expected = 'select "column_a" as "value_a"
|
||||||
|
, (select max("column_b") as "count"
|
||||||
|
from "xe_table_b" as "table_b"
|
||||||
|
) as "value_b"
|
||||||
|
from "xe_table_a" as "table_a"
|
||||||
|
where "column_a" = 4';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSelectUncorrelated2(){
|
||||||
|
$xml_file = $this->xmlPath . "select_uncorrelated2.xml";
|
||||||
|
echo $xml_file;
|
||||||
|
$argsString = '$args->user_id = 4;
|
||||||
|
$args->user_name = 7;
|
||||||
|
';
|
||||||
|
$expected = 'SELECT "column_a" as "value_a"
|
||||||
|
, "column_b" as "value_b"
|
||||||
|
, "column_c" as "value_c"
|
||||||
|
, (SELECT max("column_b") as "count"
|
||||||
|
FROM "xe_table_b" as "table_b"
|
||||||
|
WHERE "column_ab" = 7) as "value_b"
|
||||||
|
FROM "xe_table_a" as "table_a"
|
||||||
|
WHERE "column_a" = 4';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testFromUncorrelated(){
|
||||||
|
$xml_file = $this->xmlPath . "from_uncorrelated1.xml";
|
||||||
|
echo $xml_file;
|
||||||
|
$argsString = '$args->user_id = 4;
|
||||||
|
$args->user_name = 7;
|
||||||
|
';
|
||||||
|
$expected = 'select max("documentcountbymember"."count") as "maxcount"
|
||||||
|
from (
|
||||||
|
select "member_srl" as "member_srl"
|
||||||
|
, count(*) as "count"
|
||||||
|
from "xe_documents" as "documents"
|
||||||
|
group by "member_srl"
|
||||||
|
) as "documentcountbymember"';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testWhereUncorrelated(){
|
||||||
|
$xml_file = $this->xmlPath . "where_uncorrelated1.xml";
|
||||||
|
echo $xml_file;
|
||||||
|
$argsString = '';
|
||||||
|
$expected = 'select * from
|
||||||
|
"xe_member" as "member"
|
||||||
|
where "regdate" = (select max("regdate") as "maxregdate"
|
||||||
|
from "xe_documents" as "documents")';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -1,26 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
require(_XE_PATH_ . 'test-phpUnit/config.inc.php');
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
require(_XE_PATH_ . 'test-phpUnit/db/xml_query/cubrid/config.cubrid.inc.php');
|
|
||||||
|
|
||||||
class CubridUpdateTest extends PHPUnit_Framework_TestCase {
|
class CubridUpdateTest extends CubridTest {
|
||||||
|
|
||||||
function _test($xml_file, $argsString, $expected){
|
function _test($xml_file, $argsString, $expected){
|
||||||
$tester = new QueryTester();
|
$this->_testQuery($xml_file, $argsString, $expected, 'getUpdateSql');
|
||||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
|
||||||
$output = eval($outputString);
|
|
||||||
if(!is_a($output, 'Query')){
|
|
||||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
|
||||||
}else {
|
|
||||||
$db = &DB::getInstance();
|
|
||||||
$querySql = $db->getUpdateSql($output);
|
|
||||||
|
|
||||||
// Remove whitespaces, tabs and all
|
|
||||||
$querySql = Helper::cleanQuery($querySql);
|
|
||||||
$expected = Helper::cleanQuery($expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test
|
|
||||||
$this->assertEquals($expected, $querySql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_module_updateModule(){
|
function test_module_updateModule(){
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
$oContext = &Context::getInstance();
|
|
||||||
|
|
||||||
$db_info->db_type = 'cubrid';
|
|
||||||
$db_info->db_table_prefix = 'xe';
|
|
||||||
|
|
||||||
$oContext->setDbInfo($db_info);
|
|
||||||
?>
|
|
||||||
19
test-phpUnit/db/xml_query/cubrid/data/from_uncorrelated1.xml
Normal file
19
test-phpUnit/db/xml_query/cubrid/data/from_uncorrelated1.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<query id="getMemberInfo" action="select">
|
||||||
|
<tables>
|
||||||
|
<query alias="documentCountByMember">
|
||||||
|
<tables>
|
||||||
|
<table name="documents" alias="documents" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="member_srl" alias="member_srl" />
|
||||||
|
<column name="count(*)" alias="count" />
|
||||||
|
</columns>
|
||||||
|
<groups>
|
||||||
|
<group column="member_srl" />
|
||||||
|
</groups>
|
||||||
|
</query>
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="MAX(documentCountByMember.count)" alias="maxCount" />
|
||||||
|
</columns>
|
||||||
|
</query>
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<query id="select_uncorrelated" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="table_a" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="column_a" alias="value_a" />
|
||||||
|
<query alias="value_b">
|
||||||
|
<tables>
|
||||||
|
<table name="table_b" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="max(column_b)" alias="count" />
|
||||||
|
</columns>
|
||||||
|
</query>
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="column_a" var="user_id" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<query id="select_uncorrelated" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="table_a" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="column_a" alias="value_a" />
|
||||||
|
<column name="column_b" alias="value_b" />
|
||||||
|
<query alias="value_b">
|
||||||
|
<tables>
|
||||||
|
<table name="table_b" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="max(column_b)" alias="count" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="column_ab" var="user_name" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
|
<column name="column_c" alias="value_c" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="column_a" var="user_id" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
<query id="getMemberInfo" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="member" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="*" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<query operation="equal" column="regdate" alias="documentMaxRegdate">
|
||||||
|
<tables>
|
||||||
|
<table name="documents" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="max(regdate)" alias="maxregdate" />
|
||||||
|
</columns>
|
||||||
|
</query>
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
|
|
@ -1,36 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
require(_XE_PATH_ . 'test-phpUnit/config.inc.php');
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
require(_XE_PATH_ . 'test-phpUnit/db/xml_query/mssql/config.mssql.inc.php');
|
|
||||||
|
|
||||||
class MssqlSelectTest extends PHPUnit_Framework_TestCase {
|
class MssqlSelectTest extends MssqlTest {
|
||||||
|
|
||||||
function _test($xml_file, $argsString, $expected, $expectedArgs = NULL){
|
function _test($xml_file, $argsString, $expected, $expectedArgs = NULL){
|
||||||
$tester = new QueryTester();
|
$this->_testPreparedQuery($xml_file, $argsString, $expected, 'getSelectSql', $expectedArgs = NULL);
|
||||||
$outputString = $tester->getNewParserOutputString($xml_file, '[', $argsString);
|
|
||||||
//echo $outputString;
|
|
||||||
$output = eval($outputString);
|
|
||||||
|
|
||||||
if(!is_a($output, 'Query')){
|
|
||||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
|
||||||
}else {
|
|
||||||
$db = &DB::getInstance();
|
|
||||||
$querySql = $db->getSelectSql($output);
|
|
||||||
$queryArguments = $output->getArguments();
|
|
||||||
|
|
||||||
// Remove whitespaces, tabs and all
|
|
||||||
$querySql = Helper::cleanQuery($querySql);
|
|
||||||
$expected = Helper::cleanQuery($expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test
|
|
||||||
$this->assertEquals($expected, $querySql);
|
|
||||||
|
|
||||||
// Test query arguments
|
|
||||||
$argCount = count($expectedArgs);
|
|
||||||
for($i = 0; $i < $argCount; $i++){
|
|
||||||
//echo "$i: $expectedArgs[$i] vs $queryArguments[$i]->getValue()";
|
|
||||||
$this->assertEquals($expectedArgs[$i], $queryArguments[$i]->getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSelectStar(){
|
function testSelectStar(){
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
$oContext = &Context::getInstance();
|
|
||||||
|
|
||||||
$db_info->db_type = 'mssql';
|
|
||||||
$db_info->db_table_prefix = 'xe';
|
|
||||||
|
|
||||||
$oContext->setDbInfo($db_info);
|
|
||||||
?>
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
require('config.inc.php');
|
require('config/config.inc.php');
|
||||||
|
|
||||||
$oDB = &DB::getInstance('mssql');
|
$oDB = &DB::getInstance('mssql');
|
||||||
//$oDB = &DB::getInstance();
|
//$oDB = &DB::getInstance();
|
||||||
$dbParser = $oDB->getParser();
|
$dbParser = $oDB->getParser();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue