mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
Issue 667: 게시판 목록 가져오는 쿼리의 검토 필요
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9737 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
2e87a9461f
commit
0c5f501692
2 changed files with 114 additions and 115 deletions
|
|
@ -585,16 +585,24 @@
|
|||
* a method, navigation, is used
|
||||
**/
|
||||
function _executeSelectAct($queryObject, $connection = null){
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
$limit = $queryObject->getLimit();
|
||||
if ($limit && $limit->isPageHandler())
|
||||
return $this->queryPageLimit($queryObject, $result, $connection);
|
||||
else {
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result = $this->_query ($query, $connection);
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result = $this->_query ($query, $connection);
|
||||
|
||||
if ($this->isError ())
|
||||
return $this->queryError($queryObject);
|
||||
else
|
||||
return $this->queryPageLimit($queryObject, $result, $connection);
|
||||
if ($this->isError ())
|
||||
return $this->queryError($queryObject);
|
||||
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
return $buff;
|
||||
}
|
||||
}
|
||||
|
||||
function queryError($queryObject){
|
||||
|
|
@ -612,9 +620,6 @@
|
|||
}
|
||||
|
||||
function queryPageLimit($queryObject, $result, $connection){
|
||||
$limit = $queryObject->getLimit();
|
||||
if ($limit && $limit->isPageHandler()) {
|
||||
|
||||
// Total count
|
||||
$temp_where = $queryObject->getWhereString(true, false);
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
|
||||
|
|
@ -661,11 +666,6 @@
|
|||
$buff->page = $page;
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
}else{
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@
|
|||
if(isset($arrayIndexEndValue)) return $output;
|
||||
else return $output[0];
|
||||
}
|
||||
mysql_free_result($result);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -410,128 +411,126 @@
|
|||
* it supports a method as navigation
|
||||
**/
|
||||
function _executeSelectAct($queryObject, $connection = null) {
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
$limit = $queryObject->getLimit();
|
||||
if ($limit && $limit->isPageHandler())
|
||||
return $this->queryPageLimit($queryObject, $result, $connection);
|
||||
else {
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
|
||||
|
||||
if(is_a($query, 'Object')) return;
|
||||
$result = $this->_query ($query, $connection);
|
||||
if ($this->isError ()) return $this->queryError($queryObject);
|
||||
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
|
||||
|
||||
// TODO Add support for click count
|
||||
// TODO Add code for pagination
|
||||
|
||||
$result = $this->_query ($query, $connection);
|
||||
if ($this->isError ()) return $this->queryError($queryObject);
|
||||
else return $this->queryPageLimit($queryObject, $result, $connection);
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
return $buff;
|
||||
}
|
||||
}
|
||||
|
||||
function db_insert_id()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return mysql_insert_id($connection);
|
||||
}
|
||||
function db_insert_id()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return mysql_insert_id($connection);
|
||||
}
|
||||
|
||||
function db_fetch_object(&$result)
|
||||
{
|
||||
return mysql_fetch_object($result);
|
||||
}
|
||||
function db_fetch_object(&$result)
|
||||
{
|
||||
return mysql_fetch_object($result);
|
||||
}
|
||||
|
||||
function getParser(){
|
||||
return new DBParser('`', '`', $this->prefix);
|
||||
}
|
||||
function getParser(){
|
||||
return new DBParser('`', '`', $this->prefix);
|
||||
}
|
||||
|
||||
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 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){
|
||||
$limit = $queryObject->getLimit();
|
||||
if ($limit && $limit->isPageHandler()) {
|
||||
// Total count
|
||||
$temp_where = $queryObject->getWhereString(true, false);
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
function queryPageLimit($queryObject, $result, $connection){
|
||||
$limit = $queryObject->getLimit();
|
||||
// Total count
|
||||
$temp_where = $queryObject->getWhereString(true, false);
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$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)$count_output->count;
|
||||
$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)$count_output->count;
|
||||
|
||||
$list_count = $limit->list_count->getValue();
|
||||
if (!$list_count) $list_count = 20;
|
||||
$page_count = $limit->page_count->getValue();
|
||||
if (!$page_count) $page_count = 10;
|
||||
$page = $limit->page->getValue();
|
||||
if (!$page) $page = 1;
|
||||
$list_count = $limit->list_count->getValue();
|
||||
if (!$list_count) $list_count = 20;
|
||||
$page_count = $limit->page_count->getValue();
|
||||
if (!$page_count) $page_count = 10;
|
||||
$page = $limit->page->getValue();
|
||||
if (!$page) $page = 1;
|
||||
|
||||
// total pages
|
||||
if ($total_count)
|
||||
$total_page = (int) (($total_count - 1) / $list_count) + 1;
|
||||
else
|
||||
$total_page = 1;
|
||||
// total pages
|
||||
if ($total_count)
|
||||
$total_page = (int) (($total_count - 1) / $list_count) + 1;
|
||||
else
|
||||
$total_page = 1;
|
||||
|
||||
// check the page variables
|
||||
if ($page > $total_page) $page = $total_page;
|
||||
$start_count = ($page - 1) * $list_count;
|
||||
// check the page variables
|
||||
if ($page > $total_page) $page = $total_page;
|
||||
$start_count = ($page - 1) * $list_count;
|
||||
|
||||
$query = $this->getSelectPageSql($queryObject, true, $start_count, $list_count);
|
||||
$query = $this->getSelectPageSql($queryObject, true, $start_count, $list_count);
|
||||
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result = $this->_query ($query, $connection);
|
||||
if ($this->isError ())
|
||||
return $this->queryError($queryObject);
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result = $this->_query ($query, $connection);
|
||||
if ($this->isError ())
|
||||
return $this->queryError($queryObject);
|
||||
|
||||
$virtual_no = $total_count - ($page - 1) * $list_count;
|
||||
$data = $this->_fetch($result, $virtual_no);
|
||||
$virtual_no = $total_count - ($page - 1) * $list_count;
|
||||
$data = $this->_fetch($result, $virtual_no);
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $page;
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
}else{
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $page;
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
return $buff;
|
||||
}
|
||||
|
||||
$select = $query->getSelectString($with_values);
|
||||
if($select == '') return new Object(-1, "Invalid query");
|
||||
$select = 'SELECT ' .$select;
|
||||
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
|
||||
$select = $query->getSelectString($with_values);
|
||||
if($select == '') return new Object(-1, "Invalid query");
|
||||
$select = 'SELECT ' .$select;
|
||||
|
||||
$from = $query->getFromString($with_values);
|
||||
if($from == '') return new Object(-1, "Invalid query");
|
||||
$from = ' FROM '.$from;
|
||||
$from = $query->getFromString($with_values);
|
||||
if($from == '') return new Object(-1, "Invalid query");
|
||||
$from = ' FROM '.$from;
|
||||
|
||||
$where = $query->getWhereString($with_values);
|
||||
if($where != '') $where = ' WHERE ' . $where;
|
||||
$where = $query->getWhereString($with_values);
|
||||
if($where != '') $where = ' WHERE ' . $where;
|
||||
|
||||
$groupBy = $query->getGroupByString();
|
||||
if($groupBy != '') $groupBy = ' GROUP BY ' . $groupBy;
|
||||
$groupBy = $query->getGroupByString();
|
||||
if($groupBy != '') $groupBy = ' GROUP BY ' . $groupBy;
|
||||
|
||||
$orderBy = $query->getOrderByString();
|
||||
if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy;
|
||||
$orderBy = $query->getOrderByString();
|
||||
if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy;
|
||||
|
||||
$limit = $query->getLimitString();
|
||||
if ($limit != '') $limit = sprintf (' LIMIT %d, %d', $start_count, $list_count);
|
||||
$limit = $query->getLimitString();
|
||||
if ($limit != '') $limit = sprintf (' LIMIT %d, %d', $start_count, $list_count);
|
||||
|
||||
return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit;
|
||||
}
|
||||
return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit;
|
||||
}
|
||||
}
|
||||
|
||||
return new DBMysql;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue