mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-10 04:24:14 +09:00
Started unit tests for correlated subqueries - select, from, where.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8557 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
1353ade0c2
commit
e313076cc8
7 changed files with 147 additions and 14 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @class TableTag
|
* @class TableTag
|
||||||
* @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
|
||||||
|
|
@ -26,17 +25,22 @@
|
||||||
var $join_type;
|
var $join_type;
|
||||||
var $conditions;
|
var $conditions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialises Table Tag properties
|
||||||
|
* @param XML <table> tag $table
|
||||||
|
*/
|
||||||
function TableTag($table){
|
function TableTag($table){
|
||||||
$this->unescaped_name = $table->attrs->name;
|
|
||||||
|
|
||||||
$dbParser = XmlQueryParser::getDBParser();
|
$dbParser = XmlQueryParser::getDBParser();
|
||||||
|
|
||||||
|
$this->unescaped_name = $table->attrs->name;
|
||||||
$this->name = $dbParser->parseTableName($table->attrs->name);
|
$this->name = $dbParser->parseTableName($table->attrs->name);
|
||||||
$this->alias = $table->attrs->alias;
|
|
||||||
|
$this->alias = $table->attrs->alias;
|
||||||
if(!$this->alias) $this->alias = $table->attrs->name;
|
if(!$this->alias) $this->alias = $table->attrs->name;
|
||||||
//if(!$this->alias) $this->alias = $alias;
|
|
||||||
|
|
||||||
$this->join_type = $table->attrs->type;
|
$this->join_type = $table->attrs->type;
|
||||||
$this->conditions = $table->conditions;
|
|
||||||
|
$this->conditions = $table->conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isJoinTable(){
|
function isJoinTable(){
|
||||||
|
|
@ -53,6 +57,12 @@
|
||||||
return $this->unescaped_name;
|
return $this->unescaped_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 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(){
|
function getTableString(){
|
||||||
$dbParser = XmlQueryParser::getDBParser();
|
$dbParser = XmlQueryParser::getDBParser();
|
||||||
if($this->isJoinTable()){
|
if($this->isJoinTable()){
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class TablesTag
|
||||||
|
* @author Arnia Sowftare
|
||||||
|
* @brief Models the <tables> tag inside an XML Query file
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
* Example
|
||||||
|
* <tables>
|
||||||
|
* <table name="documents" alias="doc" />
|
||||||
|
* </tables>
|
||||||
|
* Attributes
|
||||||
|
* None.
|
||||||
|
* Children
|
||||||
|
* Can have children of type <table> or <query>
|
||||||
|
*/
|
||||||
|
|
||||||
class TablesTag {
|
class TablesTag {
|
||||||
var $tables;
|
var $tables;
|
||||||
|
|
||||||
|
|
@ -16,8 +32,7 @@
|
||||||
if(count($xml_tables)) require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
if(count($xml_tables)) require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||||
|
|
||||||
foreach($xml_tables as $table){
|
foreach($xml_tables as $table){
|
||||||
if($table->name === 'query') $this->tables[] = new QueryTag($table, true);
|
$this->tables[] = new TableTag($table);
|
||||||
else $this->tables[] = new TableTag($table);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$xml_queries) return;
|
if(!$xml_queries) return;
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,15 @@
|
||||||
class DBTest extends PHPUnit_Framework_TestCase {
|
class DBTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
function _testQuery($xml_file, $argsString, $expected, $methodName){
|
function _testQuery($xml_file, $argsString, $expected, $methodName){
|
||||||
|
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
|
||||||
|
echo $xml_file;
|
||||||
|
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
|
||||||
|
|
||||||
$tester = new QueryTester();
|
$tester = new QueryTester();
|
||||||
$outputString = $tester->getNewParserOutputString($xml_file, $argsString);
|
$outputString = $tester->getNewParserOutputString($xml_file, $argsString);
|
||||||
|
echo $outputString;
|
||||||
$output = eval($outputString);
|
$output = eval($outputString);
|
||||||
|
|
||||||
if(!is_a($output, 'Query')){
|
if(!is_a($output, 'Query')){
|
||||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||||
}else {
|
}else {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
function testSelectUncorrelated1(){
|
function testSelectUncorrelated1(){
|
||||||
$xml_file = $this->xmlPath . "select_uncorrelated1.xml";
|
$xml_file = $this->xmlPath . "select_uncorrelated1.xml";
|
||||||
echo $xml_file;
|
|
||||||
$argsString = '$args->user_id = 4;
|
$argsString = '$args->user_id = 4;
|
||||||
';
|
';
|
||||||
$expected = 'select "column_a" as "value_a"
|
$expected = 'select "column_a" as "value_a"
|
||||||
|
|
@ -32,7 +31,6 @@
|
||||||
|
|
||||||
function testSelectUncorrelated2(){
|
function testSelectUncorrelated2(){
|
||||||
$xml_file = $this->xmlPath . "select_uncorrelated2.xml";
|
$xml_file = $this->xmlPath . "select_uncorrelated2.xml";
|
||||||
echo $xml_file;
|
|
||||||
$argsString = '$args->user_id = 4;
|
$argsString = '$args->user_id = 4;
|
||||||
$args->user_name = 7;
|
$args->user_name = 7;
|
||||||
';
|
';
|
||||||
|
|
@ -49,7 +47,6 @@
|
||||||
|
|
||||||
function testFromUncorrelated(){
|
function testFromUncorrelated(){
|
||||||
$xml_file = $this->xmlPath . "from_uncorrelated1.xml";
|
$xml_file = $this->xmlPath . "from_uncorrelated1.xml";
|
||||||
echo $xml_file;
|
|
||||||
$argsString = '$args->user_id = 4;
|
$argsString = '$args->user_id = 4;
|
||||||
$args->user_name = 7;
|
$args->user_name = 7;
|
||||||
';
|
';
|
||||||
|
|
@ -65,13 +62,48 @@
|
||||||
|
|
||||||
function testWhereUncorrelated(){
|
function testWhereUncorrelated(){
|
||||||
$xml_file = $this->xmlPath . "where_uncorrelated1.xml";
|
$xml_file = $this->xmlPath . "where_uncorrelated1.xml";
|
||||||
echo $xml_file;
|
|
||||||
$argsString = '';
|
$argsString = '';
|
||||||
$expected = 'select * from
|
$expected = 'select * from
|
||||||
"xe_member" as "member"
|
"xe_member" as "member"
|
||||||
where "regdate" = (select max("regdate") as "maxregdate"
|
where "regdate" = (select max("regdate") as "maxregdate"
|
||||||
from "xe_documents" as "documents")';
|
from "xe_documents" as "documents")';
|
||||||
$this->_test($xml_file, $argsString, $expected);
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSelectCorrelated1(){
|
||||||
|
$xml_file = $this->xmlPath . "select_correlated1.xml";
|
||||||
|
$argsString = '$args->user_id = 7;';
|
||||||
|
$expected = 'select *,
|
||||||
|
(select count(*) as "count"
|
||||||
|
from "xe_documents" as "documents"
|
||||||
|
where "documents"."user_id" = "member"."user_id"
|
||||||
|
) as "totaldocumentcount"
|
||||||
|
from "xe_member" as "member"
|
||||||
|
where "user_id" = \'7\'';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testWhereCorrelated1(){
|
||||||
|
$xml_file = $this->xmlPath . "where_correlated1.xml";
|
||||||
|
$argsString = '';
|
||||||
|
$expected = ' SELECT *
|
||||||
|
FROM xe_member as member
|
||||||
|
WHERE regdate = (SELECT MAX(regdate) as regdate
|
||||||
|
FROM xe_documents as documents
|
||||||
|
WHERE documents.user_id = member.user_id)';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testFromCorrelated1(){
|
||||||
|
$xml_file = $this->xmlPath . "from_correlated1.xml";
|
||||||
|
$argsString = '';
|
||||||
|
$expected = 'SELECT m.member_srl, m.nickname, m.regdate, a.count
|
||||||
|
FROM (
|
||||||
|
SELECT documents.member_srl as member_srl, count(*) as count
|
||||||
|
FROM xe_documents as documents
|
||||||
|
GROUP BY documents.member_srl) a
|
||||||
|
INNER JOIN xe_members m on m.member_srl = a.member_srl';
|
||||||
|
$this->_test($xml_file, $argsString, $expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
27
test-phpUnit/db/xml_query/cubrid/data/from_correlated1.xml
Normal file
27
test-phpUnit/db/xml_query/cubrid/data/from_correlated1.xml
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<query id="getMemberInfo" action="select">
|
||||||
|
<tables>
|
||||||
|
<query alias="a">
|
||||||
|
<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>
|
||||||
|
<table name="member" alias="m" type="inner join">
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="m.member" default="a.member_srl" />
|
||||||
|
</conditions>
|
||||||
|
</table>
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="m.member_srl" />
|
||||||
|
<column name="m.nickname" />
|
||||||
|
<column name="m.regdate" />
|
||||||
|
<column name="a.count" />
|
||||||
|
</columns>
|
||||||
|
</query>
|
||||||
22
test-phpUnit/db/xml_query/cubrid/data/select_correlated1.xml
Normal file
22
test-phpUnit/db/xml_query/cubrid/data/select_correlated1.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<query id="getStatistics" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="member" alias="member" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="*" />
|
||||||
|
<query id="getMemberDocumentCount" alias="totalDocumentCount">
|
||||||
|
<tables>
|
||||||
|
<table name="documents" alias="documents" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="count(*)" alias="count" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="documents.user_id" default="member.user_id" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="user_id" var="user_id" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
22
test-phpUnit/db/xml_query/cubrid/data/where_correlated1.xml
Normal file
22
test-phpUnit/db/xml_query/cubrid/data/where_correlated1.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<query id="getMemberInfo" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="member" alias="member" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="*" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<query id="getDocumentMaxRegdate" alias="documentMaxRegdate" operation="equal" column="regdate" notnull="notnull">
|
||||||
|
<tables>
|
||||||
|
<table name="documents" alias="documents" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="max(regdate)" alias="maxregdate" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="documents.user_id" var="member.user_id" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
|
</condition>
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue