mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
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:
parent
e313076cc8
commit
909276e16b
8 changed files with 54 additions and 55 deletions
|
|
@ -18,7 +18,7 @@ class QueryParser {
|
|||
function QueryParser($query, $isSubQuery = false){
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
|
||||
|
||||
function getTableInfo($query_id, $table_name){
|
||||
$column_type = array();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,31 +16,25 @@
|
|||
* Can have children of type <table> or <query>
|
||||
*/
|
||||
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||
|
||||
class TablesTag {
|
||||
var $tables;
|
||||
|
||||
function TablesTag($xml_tables_tag){
|
||||
$xml_tables = $xml_tables_tag->table;
|
||||
$xml_queries = $xml_tables_tag->query;
|
||||
|
||||
function TablesTag($xml_tables_tag){
|
||||
$this->tables = array();
|
||||
|
||||
|
||||
if($xml_tables){
|
||||
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){
|
||||
$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);
|
||||
}
|
||||
$xml_tables = $xml_tables_tag->table;
|
||||
if(!is_array($xml_tables)) $xml_tables = array($xml_tables);
|
||||
|
||||
foreach($xml_tables as $tag){
|
||||
if($tag->attrs->query == 'true'){
|
||||
$this->tables[] = new QueryTag($tag, true);
|
||||
}
|
||||
else {
|
||||
$this->tables[] = new TableTag($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
function getNewParserOutput($xml_file){
|
||||
$newXmlQueryParser = new XmlQueryParser();
|
||||
$xml_obj = $newXmlQueryParser->getXmlFileContent($xml_file);
|
||||
|
||||
$xml_obj = $newXmlQueryParser->getXmlFileContent($xml_file);
|
||||
$parser = new QueryParser($xml_obj->query);
|
||||
return $parser->toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
class DBTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function _testQuery($xml_file, $argsString, $expected, $methodName){
|
||||
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
|
||||
echo $xml_file;
|
||||
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
|
||||
//echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
|
||||
//echo $xml_file;
|
||||
//echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
|
||||
|
||||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, $argsString);
|
||||
echo $outputString;
|
||||
//echo $outputString;
|
||||
$output = eval($outputString);
|
||||
|
||||
if(!is_a($output, 'Query')){
|
||||
|
|
|
|||
|
|
@ -86,23 +86,30 @@
|
|||
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)';
|
||||
$expected = 'select *
|
||||
from "xe_member" as "member"
|
||||
where "regdate" = (
|
||||
select max("regdate") as "maxregdate"
|
||||
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';
|
||||
$expected = 'select "m"."member_srl"
|
||||
, "m"."nickname"
|
||||
, "m"."regdate"
|
||||
, "a"."count"
|
||||
from (
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<query id="getMemberInfo" action="select">
|
||||
<tables>
|
||||
<query alias="a">
|
||||
<table query="true" alias="a">
|
||||
<tables>
|
||||
<table name="documents" alias="documents" />
|
||||
</tables>
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
<groups>
|
||||
<group column="member_srl" />
|
||||
</groups>
|
||||
</query>
|
||||
<table name="member" alias="m" type="inner join">
|
||||
</table>
|
||||
<table name="member" alias="m" type="left join">
|
||||
<conditions>
|
||||
<condition operation="equal" column="m.member" default="a.member_srl" />
|
||||
</conditions>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<query id="getMemberInfo" action="select">
|
||||
<tables>
|
||||
<query alias="documentCountByMember">
|
||||
<table query="true" alias="documentCountByMember">
|
||||
<tables>
|
||||
<table name="documents" alias="documents" />
|
||||
</tables>
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
<groups>
|
||||
<group column="member_srl" />
|
||||
</groups>
|
||||
</query>
|
||||
</table>
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="MAX(documentCountByMember.count)" alias="maxCount" />
|
||||
|
|
|
|||
|
|
@ -6,17 +6,16 @@
|
|||
<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>
|
||||
<query 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" default="member.user_id" notnull="notnull" />
|
||||
</conditions>
|
||||
</query>
|
||||
</conditions>
|
||||
</query>
|
||||
Loading…
Add table
Add a link
Reference in a new issue