mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
reverse merge rollback
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10714 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
e3685a7bd8
commit
3afad81016
44 changed files with 333 additions and 742 deletions
|
|
@ -177,12 +177,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);
|
||||
|
|
@ -209,9 +203,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;
|
||||
}
|
||||
|
||||
|
|
@ -338,7 +332,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;
|
||||
|
||||
|
|
@ -346,40 +339,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;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -390,6 +381,7 @@
|
|||
* @return cache file
|
||||
**/
|
||||
function checkQueryCacheFile($query_id,$xml_file){
|
||||
|
||||
// first try finding cache file
|
||||
$cache_file = sprintf('%s%s%s.%s.%s.cache.php', _XE_PATH_, $this->cache_file, $query_id, __ZBXE_VERSION__, $this->db_type);
|
||||
|
||||
|
|
@ -428,7 +420,6 @@
|
|||
// execute appropriate query
|
||||
switch($output->getAction()) {
|
||||
case 'insert' :
|
||||
case 'insert-select' :
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeInsertAct($output);
|
||||
break;
|
||||
|
|
@ -854,4 +845,4 @@
|
|||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -834,8 +834,9 @@
|
|||
return $buff;
|
||||
}
|
||||
|
||||
function getParser($force = FALSE){
|
||||
return new DBParser('"', '"', $this->prefix);
|
||||
function &getParser($force = FALSE){
|
||||
$dbParser = new DBParser('"', '"', $this->prefix);
|
||||
return $dbParser;
|
||||
}
|
||||
|
||||
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
|
||||
|
|
|
|||
|
|
@ -540,8 +540,9 @@
|
|||
else return $this->queryPageLimit($queryObject, $result, $connection);
|
||||
}
|
||||
|
||||
function getParser($force = FALSE){
|
||||
return new DBParser("[", "]", $this->prefix);
|
||||
function &getParser($force = FALSE){
|
||||
$dbParser = new DBParser("[", "]", $this->prefix);
|
||||
return $dbParser;
|
||||
}
|
||||
|
||||
function queryError($queryObject){
|
||||
|
|
@ -614,7 +615,7 @@
|
|||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
return $buff;
|
||||
}
|
||||
|
||||
|
||||
$start_count = ($page - 1) * $list_count;
|
||||
$this->param = $queryObject->getArguments();
|
||||
$virtual_no = $total_count - $start_count;
|
||||
|
|
|
|||
|
|
@ -317,20 +317,9 @@ class DBMysql extends DB {
|
|||
if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column;
|
||||
else $columns = $xml_obj->table->column;
|
||||
|
||||
$primary_list = array();
|
||||
$unique_list = array();
|
||||
$index_list = array();
|
||||
|
||||
foreach($columns as $column) {
|
||||
$name = $column->attrs->name;
|
||||
$type = $column->attrs->type;
|
||||
$size = $column->attrs->size;
|
||||
$notnull = $column->attrs->notnull;
|
||||
$primary_key = $column->attrs->primary_key;
|
||||
$index = $column->attrs->index;
|
||||
$unique = $column->attrs->unique;
|
||||
$default = $column->attrs->default;
|
||||
$auto_increment = $column->attrs->auto_increment;
|
||||
$primary_list = array();
|
||||
$unique_list = array();
|
||||
$index_list = array();
|
||||
|
||||
foreach($columns as $column) {
|
||||
$name = $column->attrs->name;
|
||||
|
|
@ -379,22 +368,14 @@ class DBMysql extends DB {
|
|||
if(!$output) return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle selectAct
|
||||
*
|
||||
* In order to get a list of pages easily when selecting \n
|
||||
* it supports a method as navigation
|
||||
**/
|
||||
function _executeSelectAct($queryObject, $connection = null, $with_values = true) {
|
||||
$limit = $queryObject->getLimit();
|
||||
$result = NULL;
|
||||
if ($limit && $limit->isPageHandler())
|
||||
return $this->queryPageLimit($queryObject, $result, $connection, $with_values);
|
||||
else {
|
||||
$query = $this->getSelectSql($queryObject, $with_values);
|
||||
if (is_a($query, 'Object'))
|
||||
return;
|
||||
$query .= (__DEBUG_QUERY__ & 1 && $queryObject->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : '';
|
||||
/**
|
||||
* @brief Handle the insertAct
|
||||
**/
|
||||
function _executeInsertAct($queryObject, $with_values = true) {
|
||||
$query = $this->getInsertSql($queryObject, $with_values, true);
|
||||
if(is_a($query, 'Object')) return;
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle updateAct
|
||||
|
|
@ -448,41 +429,33 @@ class DBMysql extends DB {
|
|||
return mysql_insert_id($connection);
|
||||
}
|
||||
|
||||
function getParser($force = FALSE){
|
||||
return new DBParser('`', '`', $this->prefix);
|
||||
}
|
||||
function db_fetch_object(&$result)
|
||||
{
|
||||
return mysql_fetch_object($result);
|
||||
}
|
||||
function db_fetch_object(&$result)
|
||||
{
|
||||
return mysql_fetch_object($result);
|
||||
}
|
||||
|
||||
function db_free_result(&$result){
|
||||
return mysql_free_result($result);
|
||||
}
|
||||
|
||||
function queryPageLimit($queryObject, $result, $connection, $with_values = true){
|
||||
$limit = $queryObject->getLimit();
|
||||
// Total count
|
||||
$temp_where = $queryObject->getWhereString($with_values, false);
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString($with_values), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
|
||||
|
||||
// Check for distinct query and if found update count query structure
|
||||
$temp_select = $queryObject->getSelectString($with_values);
|
||||
$uses_distinct = false;
|
||||
if(strpos(strtolower($temp_select), "distinct") !== false) {
|
||||
$count_query = sprintf('select %s %s %s', 'FROM ' . $queryObject->getFromString($with_values), $temp_select, ($temp_where === '' ? '' : ' WHERE '. $temp_where));
|
||||
$uses_distinct = true;
|
||||
}
|
||||
|
||||
// If query uses grouping or distinct, count from original select
|
||||
if ($queryObject->getGroupByString() != '' || $uses_distinct) {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
function &getParser($force = FALSE){
|
||||
$dbParser = new DBParser('`', '`', $this->prefix);
|
||||
return $dbParser;
|
||||
}
|
||||
|
||||
$count_query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result_count = $this->_query($count_query, $connection);
|
||||
$count_output = $this->_fetch($result_count);
|
||||
$total_count = (int)(isset($count_output->count) ? $count_output->count : NULL);
|
||||
function queryError($queryObject){
|
||||
$limit = $queryObject->getLimit();
|
||||
if ($limit && $limit->isPageHandler()){
|
||||
$buff = new Object ();
|
||||
$buff->total_count = 0;
|
||||
$buff->total_page = 0;
|
||||
$buff->page = 1;
|
||||
$buff->data = array ();
|
||||
$buff->page_navigation = new PageHandler (/*$total_count*/0, /*$total_page*/1, /*$page*/1, /*$page_count*/10);//default page handler values
|
||||
return $buff;
|
||||
}else
|
||||
return;
|
||||
}
|
||||
|
||||
function queryPageLimit($queryObject, $result, $connection, $with_values = true){
|
||||
$limit = $queryObject->getLimit();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
<<<<<<< .working
|
||||
<?php
|
||||
|
||||
class Query extends Object {
|
||||
|
|
@ -94,65 +93,6 @@
|
|||
|
||||
$this->tables = $tables;
|
||||
}
|
||||
=======
|
||||
<?php
|
||||
|
||||
class Query extends Object {
|
||||
var $queryID;
|
||||
var $action;
|
||||
var $priority;
|
||||
|
||||
var $columns;
|
||||
var $tables;
|
||||
var $conditions;
|
||||
var $groups;
|
||||
var $orderby;
|
||||
var $limit;
|
||||
|
||||
var $arguments = null;
|
||||
|
||||
var $columnList = null;
|
||||
|
||||
var $_orderByString;
|
||||
|
||||
function Query($queryID = null
|
||||
, $action = null
|
||||
, $columns = null
|
||||
, $tables = null
|
||||
, $conditions = null
|
||||
, $groups = null
|
||||
, $orderby = null
|
||||
, $limit = null
|
||||
, $priority = null){
|
||||
$this->queryID = $queryID;
|
||||
$this->action = $action;
|
||||
$this->priority = $priority;
|
||||
|
||||
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(){
|
||||
return true;
|
||||
}
|
||||
|
||||
function setQueryId($queryID){
|
||||
$this->queryID = $queryID;
|
||||
}
|
||||
|
||||
function setAction($action){
|
||||
$this->action = $action;
|
||||
}
|
||||
>>>>>>> .merge-right.r10563
|
||||
|
||||
function setSubquery($subquery){
|
||||
$this->subquery = $subquery;
|
||||
}
|
||||
|
||||
function setConditions($conditions){
|
||||
$this->conditions = array();
|
||||
|
|
@ -246,21 +186,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";
|
||||
}
|
||||
|
||||
|
||||
<<<<<<< .working
|
||||
$valuesList = '';
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
|
|
@ -416,159 +341,3 @@
|
|||
|
||||
|
||||
?>
|
||||
=======
|
||||
$valuesList = '';
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$columnsList .= $column->getColumnName() . ', ';
|
||||
$valuesList .= $column->getValue($with_values) . ', ';
|
||||
}
|
||||
}
|
||||
$columnsList = substr($columnsList, 0, -2);
|
||||
$valuesList = substr($valuesList, 0, -2);
|
||||
|
||||
return "($columnsList) \n VALUES ($valuesList)";
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
// from table_a
|
||||
// from table_a inner join table_b on x=y
|
||||
// from (select * from table a) as x
|
||||
// from (select * from table t) as x inner join table y on y.x
|
||||
function getFromString($with_values = true){
|
||||
$from = '';
|
||||
$simple_table_count = 0;
|
||||
foreach($this->tables as $table){
|
||||
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
|
||||
else $from .= ', '.$table->toString($with_values) . ' ';
|
||||
|
||||
if(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
|
||||
|
||||
$simple_table_count++;
|
||||
}
|
||||
if(trim($from) == '') return '';
|
||||
return $from;
|
||||
}
|
||||
|
||||
function getWhereString($with_values = true, $with_optimization = true){
|
||||
$where = '';
|
||||
$condition_count = 0;
|
||||
|
||||
foreach ($this->conditions as $conditionGroup) {
|
||||
if ($condition_count === 0) {
|
||||
$conditionGroup->setPipe("");
|
||||
}
|
||||
$condition_string = $conditionGroup->toString($with_values);
|
||||
$where .= $condition_string;
|
||||
$condition_count++;
|
||||
}
|
||||
|
||||
if ($with_optimization &&
|
||||
(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) {
|
||||
|
||||
if ($condition_count !== 0)
|
||||
$where = '(' . $where . ') ';
|
||||
|
||||
foreach ($this->orderby as $order) {
|
||||
$colName = $order->getColumnName();
|
||||
if (strstr($colName, 'list_order') || strstr($colName, 'update_order')) {
|
||||
$opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
|
||||
if ($condition_count === 0)
|
||||
$opt_condition->setPipe("");
|
||||
$where .= $opt_condition->toString($with_values) . ' ';
|
||||
$condition_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trim($where);
|
||||
}
|
||||
|
||||
function getGroupByString(){
|
||||
$groupBy = '';
|
||||
if($this->groups) if($this->groups[0] !== "")
|
||||
$groupBy = implode(', ', $this->groups);
|
||||
return $groupBy;
|
||||
}
|
||||
|
||||
function getOrderByString(){
|
||||
if(!$this->_orderByString){
|
||||
if(count($this->orderby) === 0) return '';
|
||||
$orderBy = '';
|
||||
foreach($this->orderby as $order){
|
||||
$orderBy .= $order->toString() .', ';
|
||||
}
|
||||
$orderBy = substr($orderBy, 0, -2);
|
||||
$this->_orderByString = $orderBy;
|
||||
}
|
||||
return $this->_orderByString;
|
||||
}
|
||||
|
||||
function getLimit(){
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
function getLimitString(){
|
||||
$limit = '';
|
||||
if(count($this->limit) > 0){
|
||||
$limit = '';
|
||||
$limit .= $this->limit->toString();
|
||||
}
|
||||
return $limit;
|
||||
}
|
||||
|
||||
function getFirstTableName(){
|
||||
return $this->tables[0]->getName();
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
if(!isset($this->arguments)){
|
||||
$this->arguments = array();
|
||||
|
||||
// Join table arguments
|
||||
if(count($this->tables) > 0)
|
||||
{
|
||||
foreach($this->tables as $table)
|
||||
{
|
||||
if($table->isJoinTable())
|
||||
{
|
||||
$args = $table->getArguments();
|
||||
if($args) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Column arguments
|
||||
if(count($this->columns) > 0){ // The if is for delete statements, all others must have columns
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$args = $column->getArguments();
|
||||
if($args) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Condition arguments
|
||||
if(count($this->conditions) > 0)
|
||||
foreach($this->conditions as $conditionGroup){
|
||||
$args = $conditionGroup->getArguments();
|
||||
if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
|
||||
// Navigation arguments
|
||||
if(count($this->orderby) > 0)
|
||||
foreach($this->orderby as $order){
|
||||
$args = $order->getArguments();
|
||||
if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>>>>>>>> .merge-right.r10563
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@
|
|||
function getArgument(){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function getArguments(){
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue