diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index bec5666a1..85339e092 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -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; } diff --git a/classes/db/queryparts/Query.class.php b/classes/db/queryparts/Query.class.php index 33f233a1a..729ca46e4 100644 --- a/classes/db/queryparts/Query.class.php +++ b/classes/db/queryparts/Query.class.php @@ -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()){ diff --git a/classes/xml/XmlQueryParser.150.class.php b/classes/xml/XmlQueryParser.150.class.php index c90402e63..f42920447 100644 --- a/classes/xml/XmlQueryParser.150.class.php +++ b/classes/xml/XmlQueryParser.150.class.php @@ -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'); diff --git a/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php b/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php deleted file mode 100644 index 011800840..000000000 --- a/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php +++ /dev/null @@ -1,27 +0,0 @@ - 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; - } - - } -?> \ No newline at end of file diff --git a/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php b/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php index d849952db..88ed19ccb 100644 --- a/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php +++ b/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php @@ -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); } } diff --git a/classes/xml/xmlquery/tags/query/QueryTag.class.php b/classes/xml/xmlquery/tags/query/QueryTag.class.php index d65af090b..ac9a2a6c4 100644 --- a/classes/xml/xmlquery/tags/query/QueryTag.class.php +++ b/classes/xml/xmlquery/tags/query/QueryTag.class.php @@ -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; diff --git a/tests/classes/db/db/xml_query/mysql/MysqlInsertTest.php b/tests/classes/db/db/xml_query/mysql/MysqlInsertTest.php deleted file mode 100644 index f064ca626..000000000 --- a/tests/classes/db/db/xml_query/mysql/MysqlInsertTest.php +++ /dev/null @@ -1,44 +0,0 @@ -_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 */ diff --git a/tests/classes/db/db/xml_query/mysql/data/insert_select.xml b/tests/classes/db/db/xml_query/mysql/data/insert_select.xml deleted file mode 100644 index 4aa87f26c..000000000 --- a/tests/classes/db/db/xml_query/mysql/data/insert_select.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - -
- - - - - - - - - - - \ No newline at end of file