Added support for selecting a subset of the columns specified in the XML query file.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8614 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-07-20 12:34:31 +00:00
parent 8b9468a165
commit e7fe19db1f
5 changed files with 71 additions and 39 deletions

View file

@ -13,6 +13,8 @@
var $arguments = null;
var $columnList = null;
function Query($queryID = null
, $action = null
, $columns = null
@ -24,12 +26,13 @@
$this->queryID = $queryID;
$this->action = $action;
$this->columns = $columns;
$this->tables = $tables;
$this->conditions = $conditions;
$this->groups = $groups;
$this->orderby = $orderby;
$this->limit = $limit;
if(!isset($tables)) return;
$this->columns = $this->setColumns($columns);
$this->tables = $this->setTables($tables);
$this->conditions = $this->setConditions($conditions);
$this->groups = $this->setGroups($groups);
$this->orderby = $this->setOrder($orderby);
$this->limit = $this->setLimit($limit);
}
function show(){
@ -44,6 +47,10 @@
$this->action = $action;
}
function setColumnList($columnList){
$this->columnList = $columnList;
}
function setColumns($columns){
if(!isset($columns) || count($columns) === 0){
$this->columns = array(new StarExpression());
@ -130,9 +137,21 @@
return $this->action;
}
function getSelectString($with_values = true){
function getSelectString($with_values = true){
if(isset($this->columnList)){
$selectColumns = array();
$dbParser = XmlQueryParser::getDBParser();
foreach($this->columnList as $columnName){
$columnName = $dbParser->escapeColumn($columnName);
$selectColumns[] = new SelectExpression($columnName);
}
}
else
$selectColumns = $this->columns;
$select = '';
foreach($this->columns as $column){
foreach($selectColumns as $column){
if($column->show())
if(is_a($column, 'Subquery')){
$select .= $column->toString($with_values) . ' as '. $column->getAlias() .', ';

View file

@ -1,7 +1,7 @@
<?php
class DBTest extends PHPUnit_Framework_TestCase {
function _testQuery($xml_file, $argsString, $expected, $methodName){
function _testQuery($xml_file, $argsString, $expected, $methodName, $columnList = null){
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
echo $xml_file;
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
@ -15,6 +15,7 @@
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
}else {
$db = &DB::getInstance();
if($columnList) $output->setColumnList($columnList);
$querySql = $db->{$methodName}($output);
// Remove whitespaces, tabs and all

View file

@ -21,7 +21,7 @@
$output = executeQuery('module.insertModule', $args);
$this->assertTrue(!$output->error);
$this->assertTrue(!$output->error, $output->message);
}
function test_document_insertDocument_defaultVarcharValue(){

View file

@ -7,7 +7,7 @@
$args->site_srl = 0;
$output = executeQuery('module.getMidInfo', $args);
$this->assertNotNull($output);
$this->assertNotNull($output->data);
$this->assertNotNull($output->data, $output->message);
$this->assertEquals($output->data->module_srl, 111);
}
@ -15,7 +15,7 @@
$args->site_srl = 0;
$output = executeQuery('module.getSiteInfo', $args);
$this->assertTrue(is_a($output, 'Object'));
$this->assertEquals(0, $output->error);
$this->assertEquals(0, $output->error, $output->message);
}
function test_document_getDocumentList_pagination(){
@ -29,5 +29,22 @@
$output = executeQuery('document.getDocumentList', $args);
$this->assertEquals(0, $output->error, $output->message);
}
}
function test_syndication_getDocumentList(){
$args->module_srl = NULL;
$args->exclude_module_srl = NULL;
$args->category_srl = NULL;
$args->sort_index = 'list_order';
$args->order_type = 'asc';
$args->page = 5;
$args->list_count = 30;
$args->page_count = 10;
$args->start_date = NULL;
$args->end_date = NULL;
$args->member_srl = NULL;
$output = executeQuery('document.getDocumentList', $args);
$this->assertTrue(is_int($output->page), $output->message);
}
}
?>

View file

@ -3,8 +3,8 @@
class CubridSelectTest extends CubridTest {
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql', $columnList);
}
function testSelectStar(){
@ -151,30 +151,6 @@
or "group_srl" = -2)
group by "module_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function test_syndication_getDocumentList(){
define('__ZBXE__', 1);
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
$db = &DB::getInstance('cubrid');
$args = new StdClass();
$args->module_srl = NULL;
$args->exclude_module_srl = NULL;
$args->category_srl = NULL;
$args->sort_index = 'list_order';
$args->order_type = 'asc';
$args->page = 5;
$args->list_count = 30;
$args->page_count = 10;
$args->start_date = NULL;
$args->end_date = NULL;
$args->member_srl = NULL;
$output = $db->executeQuery('document.getDocumentList', $args);
$this->assertTrue(is_int($output->page));
// $this->assertTrue($output->page == 5);
}
function test_document_getDocumentList(){
@ -194,5 +170,24 @@
}
/**
* Test column list
*/
function test_session_getSession(){
$xml_file = _XE_PATH_ . "modules/session/queries/getSession.xml";
$argsString = '$args->session_key = \'session_key\';';
$columnList = array('session_key', 'cur_mid', 'val');
$expected = 'select "session_key", "cur_mid", "val"
from "xe_session" as "session"
where "session_key" = \'session_key\'';
$this->_test($xml_file, $argsString, $expected, $columnList);
//$columnList = array('session_key', 'cur_mid', 'val');
//$output = executeQuery('session.getSession', $args, $columnList);
}
}