Reverted rev 10009 and 10010 related to db classes - will commit changes to 1.6.0 branch.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10012 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2012-01-05 12:08:50 +00:00
parent 1f5e256339
commit 00d2fdf2b1
8 changed files with 38 additions and 175 deletions

View file

@ -175,12 +175,6 @@
* @return list of supported db
**/
function _getSupportedList() {
static $get_supported_list = '';
if(is_array($get_supported_list)) {
$this->supported_list = $get_supported_list;
return $this->supported_list;
}
$get_supported_list = array();
$db_classes_path = _XE_PATH_."classes/db/";
$filter = "/^DB([^\.]+)\.class\.php/i";
$supported_list = FileHandler::readDir($db_classes_path, $filter, true);
@ -207,9 +201,9 @@
$obj->db_type = $db_type;
$obj->enable = $oDB->isSupported() ? true : false;
$get_supported_list[] = $obj;
$this->supported_list[] = $obj;
}
$this->supported_list = $get_supported_list;
return $this->supported_list;
}
@ -337,7 +331,6 @@
* @remarks this function finds xml file or cache file of $query_id, compiles it and then execute it
**/
function executeQuery($query_id, $args = NULL, $arg_columns = NULL) {
static $cache_file = array();
if(!$query_id) return new Object(-1, 'msg_invalid_queryid');
if(!$this->db_type) return;
@ -345,40 +338,38 @@
$this->query_id = $query_id;
if(!isset($cache_file[$query_id])) {
$id_args = explode('.', $query_id);
if(count($id_args) == 2) {
$target = 'modules';
$module = $id_args[0];
$id = $id_args[1];
} elseif(count($id_args) == 3) {
$target = $id_args[0];
if(!in_array($target, array('addons','widgets'))){
$this->actDBClassFinish();
return;
}
$module = $id_args[1];
$id = $id_args[2];
}
if(!$target || !$module || !$id){
$this->actDBClassFinish();
return new Object(-1, 'msg_invalid_queryid');
}
$id_args = explode('.', $query_id);
if(count($id_args) == 2) {
$target = 'modules';
$module = $id_args[0];
$id = $id_args[1];
} elseif(count($id_args) == 3) {
$target = $id_args[0];
if(!in_array($target, array('addons','widgets'))){
$this->actDBClassFinish();
return;
}
$module = $id_args[1];
$id = $id_args[2];
}
if(!$target || !$module || !$id){
$this->actDBClassFinish();
return new Object(-1, 'msg_invalid_queryid');
}
$xml_file = sprintf('%s%s/%s/queries/%s.xml', _XE_PATH_, $target, $module, $id);
if(!file_exists($xml_file)){
$this->actDBClassFinish();
return new Object(-1, 'msg_invalid_queryid');
}
$xml_file = sprintf('%s%s/%s/queries/%s.xml', _XE_PATH_, $target, $module, $id);
if(!file_exists($xml_file)){
$this->actDBClassFinish();
return new Object(-1, 'msg_invalid_queryid');
}
// look for cache file
$cache_file[$query_id] = $this->checkQueryCacheFile($query_id, $xml_file);
}
$result = $this->_executeQuery($cache_file[$query_id], $args, $query_id, $arg_columns);
// look for cache file
$cache_file = $this->checkQueryCacheFile($query_id, $xml_file);
$result = $this->_executeQuery($cache_file, $args, $query_id, $arg_columns);
$this->actDBClassFinish();
// execute query
return $result;
$this->actDBClassFinish();
// execute query
return $result;
}

View file

@ -92,10 +92,6 @@
$this->tables = $tables;
}
function setSubquery($subquery){
$this->subquery = $subquery;
}
function setConditions($conditions){
$this->conditions = array();
@ -189,20 +185,6 @@
function getInsertString($with_values = true){
$columnsList = '';
if($this->subquery){ // means we have insert-select
foreach($this->columns as $column){
$columnsList .= $column->getColumnName() . ', ';
}
$columnsList = substr($columnsList, 0, -2);
$selectStatement = $this->subquery->toString($with_values);
$selectStatement = substr($selectStatement, 1, -1);
return "($columnsList) \n $selectStatement";
}
$valuesList = '';
foreach($this->columns as $column){
if($column->show()){

View file

@ -21,7 +21,6 @@
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/ColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');

View file

@ -1,27 +0,0 @@
<?php
/**
* @class InsertColumnTagWithoutArgument
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file whose action is 'insert-select'
*
**/
class InsertColumnTagWithoutArgument extends ColumnTag {
function InsertColumnTagWithoutArgument($column) {
parent::ColumnTag($column->attrs->name);
$dbParser = DB::getParser();
$this->name = $dbParser->parseColumnName($this->name);
}
function getExpressionString(){
var_dump($this->name);
return sprintf('new Expression(\'%s\')', $this->name);
}
function getArgument(){
return null;
}
}
?>

View file

@ -19,7 +19,6 @@
foreach($xml_columns as $column){
if($column->name === 'query') $this->columns[] = new QueryTag($column, true);
else if(!isset($column->attrs->var) && !isset($column->attrs->default)) $this->columns[] = new InsertColumnTagWithoutArgument($column);
else $this->columns[] = new InsertColumnTag($column);
}
}

View file

@ -10,7 +10,6 @@ class QueryTag {
//xml tags
var $columns;
var $tables;
var $subquery;
var $conditions;
var $groups;
var $navigation;
@ -38,12 +37,9 @@ class QueryTag {
$this->getColumns();
$tables = $this->getTables();
$this->setTableColumnTypes($tables);
$this->getSubquery(); // Used for insert-select
$this->getConditions();
$this->getGroups();
$this->getNavigation();
$this->getPrebuff();
$this->getBuff();
}
@ -82,7 +78,7 @@ class QueryTag {
function getColumns(){
if($this->action == 'select'){
return $this->columns = new SelectColumnsTag($this->query->columns);
}else if($this->action == 'insert' || $this->action == 'insert-select'){
}else if($this->action == 'insert'){
return $this->columns = new InsertColumnsTag($this->query->columns->column);
}else if($this->action == 'update') {
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
@ -92,7 +88,6 @@ class QueryTag {
}
function getPrebuff(){
if($this->isSubQuery) return;
// TODO Check if this work with arguments in join clause
$arguments = $this->getArguments();
@ -144,8 +139,6 @@ class QueryTag {
$buff .= '$query->setColumns(' . $this->columns->toString() . ');'.PHP_EOL;
$buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL;
if($this->action == 'insert-select')
$buff .= '$query->setSubquery(' . $this->subquery->toString() .');'.PHP_EOL;
$buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL;
$buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL;
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL;
@ -156,18 +149,12 @@ class QueryTag {
}
function getTables(){
if($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
else
return $this->tables = new TablesTag($this->query->tables);
if($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
else
return $this->tables = new TablesTag($this->query->tables);
}
function getSubquery(){
if($this->query->query){
$this->subquery = new QueryTag($this->query->query, true);
}
}
function getConditions(){
return $this->conditions = new ConditionsTag($this->query->conditions);
}
@ -196,13 +183,12 @@ class QueryTag {
return $this->buff;
}
function getArguments(){
$arguments = array();
if($this->columns)
$arguments = array_merge($arguments, $this->columns->getArguments());
if($this->action =='insert-select')
$arguments = array_merge($arguments, $this->subquery->getArguments());
$arguments = array_merge($arguments, $this->tables->getArguments());
$arguments = array_merge($arguments, $this->tables->getArguments());
$arguments = array_merge($arguments, $this->conditions->getArguments());
$arguments = array_merge($arguments, $this->navigation->getArguments());
return $arguments;

View file

@ -1,44 +0,0 @@
<?php
/**
* @class MysqlInsertTest
* @brief Constains all test method for insert statements, using Mysql SQL syntax
* @developer Corina Udrescu (xe_dev@arnia.ro)
*/
class MysqlInsertTest extends MysqlTest
{
/**
* @brief _test - local helper method
* @developer Corina Udrescu (xe_dev@arnia.ro)
* @access private
* @param $xml_file string - Path to XML file containing the query to be tested
* @param $argsString string - String containing PHP code that initializez the arguments that the query receives
* @param $expected string - Expected SQL query as string
* @param $columnList array - Array containing the column names that will be retrieved, in case only a part of the ones in the query file are needed
* @return void
*/
function _test($xml_file, $argsString, $expected, $columnList = NULL)
{
$this->_testQuery($xml_file, $argsString, $expected, 'getInsertSql', $columnList);
}
/**
* @brief testInsertSelectStatement - checks that when query action is 'insert-selct' an 'INSERT INTO .. SELECT ...' statement is properly generated
* @developer Corina Udrescu (xe_dev@arnia.ro)
* @access public
* @return void
*/
function testInsertSelectStatement()
{
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/insert_select.xml";
$argsString = '$args->condition_value = 7;';
$expected = 'insert into `xe_table1` (`column1`, `column2`, `column3`)
select `column4`, `column5`, `column6`
from `xe_table2` as `table2`
where `column4` >= 7';
$this->_test($xml_file, $argsString, $expected);
}
}
/* End of file MysqlInsertTest.php */
/* Location: ./tests/classes/db/db/xml_query/mysql/MysqlInsertTest.php */

View file

@ -1,23 +0,0 @@
<query id="QUERY_ID" action="insert-select">
<tables>
<table name="table1" />
</tables>
<columns>
<column name="column1" />
<column name="column2" />
<column name="column3" />
</columns>
<query>
<tables>
<table name="table2" />
</tables>
<columns>
<column name="column4" />
<column name="column5" />
<column name="column6" />
</columns>
<conditions>
<condition operation="more" column="column4" default="100" var="condition_value" />
</conditions>
</query>
</query>