Updates to unit tests for correlated subqueries.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8560 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-07-01 08:15:43 +00:00
parent e313076cc8
commit 909276e16b
8 changed files with 54 additions and 55 deletions

View file

@ -18,7 +18,7 @@ class QueryParser {
function QueryParser($query, $isSubQuery = false){ function QueryParser($query, $isSubQuery = false){
$this->queryTag = new QueryTag($query, $isSubQuery); $this->queryTag = new QueryTag($query, $isSubQuery);
} }
function getTableInfo($query_id, $table_name){ function getTableInfo($query_id, $table_name){
$column_type = array(); $column_type = array();

View file

@ -16,31 +16,25 @@
* Can have children of type <table> or <query> * Can have children of type <table> or <query>
*/ */
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
class TablesTag { class TablesTag {
var $tables; var $tables;
function TablesTag($xml_tables_tag){ function TablesTag($xml_tables_tag){
$xml_tables = $xml_tables_tag->table;
$xml_queries = $xml_tables_tag->query;
$this->tables = array(); $this->tables = array();
$xml_tables = $xml_tables_tag->table;
if($xml_tables){ if(!is_array($xml_tables)) $xml_tables = array($xml_tables);
if(!is_array($xml_tables)) $xml_tables = array($xml_tables);
foreach($xml_tables as $tag){
if(count($xml_tables)) require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php'); if($tag->attrs->query == 'true'){
$this->tables[] = new QueryTag($tag, true);
foreach($xml_tables as $table){ }
$this->tables[] = new TableTag($table); else {
} $this->tables[] = new TableTag($tag);
} }
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(){

View file

@ -14,8 +14,7 @@
function getNewParserOutput($xml_file){ function getNewParserOutput($xml_file){
$newXmlQueryParser = new XmlQueryParser(); $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);
return $parser->toString(); return $parser->toString();
} }

View file

@ -2,13 +2,13 @@
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 PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
echo $xml_file; //echo $xml_file;
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL; //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; //echo $outputString;
$output = eval($outputString); $output = eval($outputString);
if(!is_a($output, 'Query')){ if(!is_a($output, 'Query')){

View file

@ -86,23 +86,30 @@
function testWhereCorrelated1(){ function testWhereCorrelated1(){
$xml_file = $this->xmlPath . "where_correlated1.xml"; $xml_file = $this->xmlPath . "where_correlated1.xml";
$argsString = ''; $argsString = '';
$expected = ' SELECT * $expected = 'select *
FROM xe_member as member from "xe_member" as "member"
WHERE regdate = (SELECT MAX(regdate) as regdate where "regdate" = (
FROM xe_documents as documents select max("regdate") as "maxregdate"
WHERE documents.user_id = member.user_id)'; from "xe_documents" as "documents"
where "documents"."user_id" = "member"."user_id"
)';
$this->_test($xml_file, $argsString, $expected); $this->_test($xml_file, $argsString, $expected);
} }
function testFromCorrelated1(){ function testFromCorrelated1(){
$xml_file = $this->xmlPath . "from_correlated1.xml"; $xml_file = $this->xmlPath . "from_correlated1.xml";
$argsString = ''; $argsString = '';
$expected = 'SELECT m.member_srl, m.nickname, m.regdate, a.count $expected = 'select "m"."member_srl"
FROM ( , "m"."nickname"
SELECT documents.member_srl as member_srl, count(*) as count , "m"."regdate"
FROM xe_documents as documents , "a"."count"
GROUP BY documents.member_srl) a from (
INNER JOIN xe_members m on m.member_srl = a.member_srl'; select "member_srl" as "member_srl"
, count(*) as "count"
from "xe_documents" as "documents"
group by "member_srl"
) as "a"
left join "xe_member" as "m" on "m"."member" = "a"."member_srl"';
$this->_test($xml_file, $argsString, $expected); $this->_test($xml_file, $argsString, $expected);
} }
} }

View file

@ -1,6 +1,6 @@
<query id="getMemberInfo" action="select"> <query id="getMemberInfo" action="select">
<tables> <tables>
<query alias="a"> <table query="true" alias="a">
<tables> <tables>
<table name="documents" alias="documents" /> <table name="documents" alias="documents" />
</tables> </tables>
@ -11,8 +11,8 @@
<groups> <groups>
<group column="member_srl" /> <group column="member_srl" />
</groups> </groups>
</query> </table>
<table name="member" alias="m" type="inner join"> <table name="member" alias="m" type="left join">
<conditions> <conditions>
<condition operation="equal" column="m.member" default="a.member_srl" /> <condition operation="equal" column="m.member" default="a.member_srl" />
</conditions> </conditions>

View file

@ -1,6 +1,6 @@
<query id="getMemberInfo" action="select"> <query id="getMemberInfo" action="select">
<tables> <tables>
<query alias="documentCountByMember"> <table query="true" alias="documentCountByMember">
<tables> <tables>
<table name="documents" alias="documents" /> <table name="documents" alias="documents" />
</tables> </tables>
@ -11,7 +11,7 @@
<groups> <groups>
<group column="member_srl" /> <group column="member_srl" />
</groups> </groups>
</query> </table>
</tables> </tables>
<columns> <columns>
<column name="MAX(documentCountByMember.count)" alias="maxCount" /> <column name="MAX(documentCountByMember.count)" alias="maxCount" />

View file

@ -6,17 +6,16 @@
<column name="*" /> <column name="*" />
</columns> </columns>
<conditions> <conditions>
<query id="getDocumentMaxRegdate" alias="documentMaxRegdate" operation="equal" column="regdate" notnull="notnull"> <query alias="documentMaxRegdate" operation="equal" column="regdate" notnull="notnull">
<tables> <tables>
<table name="documents" alias="documents" /> <table name="documents" alias="documents" />
</tables> </tables>
<columns> <columns>
<column name="max(regdate)" alias="maxregdate" /> <column name="max(regdate)" alias="maxregdate" />
</columns> </columns>
<conditions> <conditions>
<condition operation="equal" column="documents.user_id" var="member.user_id" notnull="notnull" /> <condition operation="equal" column="documents.user_id" default="member.user_id" notnull="notnull" />
</conditions> </conditions>
</query> </query>
</condition>
</conditions> </conditions>
</query> </query>