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:
ucorina 2011-06-30 18:14:24 +00:00
parent 1353ade0c2
commit e313076cc8
7 changed files with 147 additions and 14 deletions

View file

@ -18,7 +18,6 @@
function testSelectUncorrelated1(){
$xml_file = $this->xmlPath . "select_uncorrelated1.xml";
echo $xml_file;
$argsString = '$args->user_id = 4;
';
$expected = 'select "column_a" as "value_a"
@ -32,7 +31,6 @@
function testSelectUncorrelated2(){
$xml_file = $this->xmlPath . "select_uncorrelated2.xml";
echo $xml_file;
$argsString = '$args->user_id = 4;
$args->user_name = 7;
';
@ -49,7 +47,6 @@
function testFromUncorrelated(){
$xml_file = $this->xmlPath . "from_uncorrelated1.xml";
echo $xml_file;
$argsString = '$args->user_id = 4;
$args->user_name = 7;
';
@ -65,13 +62,48 @@
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);
}
}
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);
}
}
?>

View 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>

View 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>

View 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>