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:
ucorina 2011-10-25 16:11:24 +00:00
parent 2e87a9461f
commit 0c5f501692
2 changed files with 114 additions and 115 deletions

View file

@ -585,6 +585,10 @@
* a method, navigation, is used * a method, navigation, is used
**/ **/
function _executeSelectAct($queryObject, $connection = null){ function _executeSelectAct($queryObject, $connection = null){
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler())
return $this->queryPageLimit($queryObject, $result, $connection);
else {
$query = $this->getSelectSql($queryObject); $query = $this->getSelectSql($queryObject);
if(is_a($query, 'Object')) return; if(is_a($query, 'Object')) return;
@ -593,8 +597,12 @@
if ($this->isError ()) if ($this->isError ())
return $this->queryError($queryObject); return $this->queryError($queryObject);
else
return $this->queryPageLimit($queryObject, $result, $connection); $data = $this->_fetch($result);
$buff = new Object ();
$buff->data = $data;
return $buff;
}
} }
function queryError($queryObject){ function queryError($queryObject){
@ -612,9 +620,6 @@
} }
function queryPageLimit($queryObject, $result, $connection){ function queryPageLimit($queryObject, $result, $connection){
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler()) {
// Total count // Total count
$temp_where = $queryObject->getWhereString(true, false); $temp_where = $queryObject->getWhereString(true, false);
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where)); $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->page = $page;
$buff->data = $data; $buff->data = $data;
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); $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; return $buff;
} }

View file

@ -156,6 +156,7 @@
if(isset($arrayIndexEndValue)) return $output; if(isset($arrayIndexEndValue)) return $output;
else return $output[0]; else return $output[0];
} }
mysql_free_result($result);
return $output; return $output;
} }
@ -410,18 +411,22 @@
* it supports a method as navigation * it supports a method as navigation
**/ **/
function _executeSelectAct($queryObject, $connection = null) { function _executeSelectAct($queryObject, $connection = null) {
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler())
return $this->queryPageLimit($queryObject, $result, $connection);
else {
$query = $this->getSelectSql($queryObject); $query = $this->getSelectSql($queryObject);
if(is_a($query, 'Object')) return; if(is_a($query, 'Object')) return;
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):''; $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); $result = $this->_query ($query, $connection);
if ($this->isError ()) return $this->queryError($queryObject); 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() function db_insert_id()
@ -455,7 +460,6 @@
function queryPageLimit($queryObject, $result, $connection){ function queryPageLimit($queryObject, $result, $connection){
$limit = $queryObject->getLimit(); $limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler()) {
// Total count // Total count
$temp_where = $queryObject->getWhereString(true, false); $temp_where = $queryObject->getWhereString(true, false);
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where)); $count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
@ -501,15 +505,10 @@
$buff->page = $page; $buff->page = $page;
$buff->data = $data; $buff->data = $data;
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); $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; return $buff;
} }
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
$select = $query->getSelectString($with_values); $select = $query->getSelectString($with_values);
if($select == '') return new Object(-1, "Invalid query"); if($select == '') return new Object(-1, "Invalid query");
$select = 'SELECT ' .$select; $select = 'SELECT ' .$select;