mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-21 03:12:55 +09:00
fix pagination
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8625 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
7de48344cc
commit
6edd5f03a7
4 changed files with 231 additions and 173 deletions
|
|
@ -622,7 +622,7 @@
|
|||
* @brief Handle the insertAct
|
||||
**/
|
||||
function _executeInsertAct($queryObject) {
|
||||
$query = $this->getInsertSql($queryObject);
|
||||
$query = $this->getInsertSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -662,55 +662,102 @@
|
|||
else return $this->queryPageLimit($queryObject, $result);
|
||||
}
|
||||
|
||||
function queryError($queryObject){
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->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){
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
|
||||
// Total count
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString()));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result_count = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result_count);
|
||||
$total_count = (int)$count_output->count;
|
||||
|
||||
// Total pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
|
||||
} else $total_page = 1;
|
||||
|
||||
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
|
||||
$data = $this->_fetch($result, $virtual_no);
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page;
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page, $queryObject->getLimit()->page_count);
|
||||
}else{
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
function queryError($queryObject) {
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->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
|
||||
}else
|
||||
return;
|
||||
}
|
||||
|
||||
function queryPageLimit($queryObject, $result) {
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
|
||||
// Total count
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE ' . $queryObject->getWhereString()));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$count_query .= ( __DEBUG_QUERY__ & 1 && $output->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : '';
|
||||
$result_count = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result_count);
|
||||
$total_count = (int) $count_output->count;
|
||||
|
||||
// Total pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
|
||||
} else
|
||||
$total_page = 1;
|
||||
|
||||
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
|
||||
while ($tmp = ibase_fetch_object($result))
|
||||
$data[$virtual_no--] = $tmp;
|
||||
|
||||
if (!$this->transaction_started)
|
||||
@ibase_commit($this->fd);
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page->getValue();
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page->getValue(), $queryObject->getLimit()->page_count);
|
||||
}else {
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
function getParser() {
|
||||
return new DBParser('"');
|
||||
}
|
||||
|
||||
function getSelectSql($query, $with_values = true) {
|
||||
|
||||
if ($query->getLimit()) {
|
||||
$list_count = $query->getLimit()->list_count->getValue();
|
||||
if(!$query->getLimit()->page) $page = 1;
|
||||
else $page = $query->getLimit()->page->getValue();
|
||||
|
||||
$start_count = ($page - 1) * $list_count;
|
||||
$limit = sprintf('SELECT FIRST %d SKIP %d ', $list_count, $start_count);
|
||||
}
|
||||
|
||||
$select = $query->getSelectString($with_values);
|
||||
if ($select == '')
|
||||
return new Object(-1, "Invalid query");
|
||||
|
||||
if ($query->getLimit())
|
||||
$select = $limit . ' ' . $select;
|
||||
else
|
||||
$select = 'SELECT ' . $select;
|
||||
$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;
|
||||
|
||||
$groupBy = $query->getGroupByString();
|
||||
if ($groupBy != '')
|
||||
$groupBy = ' GROUP BY ' . $groupBy;
|
||||
|
||||
$orderBy = $query->getOrderByString();
|
||||
if ($orderBy != '')
|
||||
$orderBy = ' ORDER BY ' . $orderBy;
|
||||
|
||||
return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new DBFireBird;
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -493,9 +493,9 @@
|
|||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page;
|
||||
$buff->page = $queryObject->getLimit()->page->getValue();
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page, $queryObject->getLimit()->page_count);
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page->getValue(), $queryObject->getLimit()->page_count);
|
||||
}else{
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
|
|
|
|||
|
|
@ -614,9 +614,9 @@ class DBPostgresql extends DB
|
|||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page;
|
||||
$buff->page = $queryObject->getLimit()->page->getValue();
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page, $queryObject->getLimit()->page_count);
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page->getValue(), $queryObject->getLimit()->page_count);
|
||||
}else{
|
||||
$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
|
|
|
|||
|
|
@ -399,130 +399,141 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insertAct
|
||||
**/
|
||||
function _executeInsertAct($queryObject) {
|
||||
$query = $this->getInsertSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$this->_prepare($query);
|
||||
/**
|
||||
* @brief insertAct
|
||||
* */
|
||||
function _executeInsertAct($queryObject) {
|
||||
$query = $this->getInsertSql($queryObject);
|
||||
if (is_a($query, 'Object'))
|
||||
return;
|
||||
|
||||
$val_count = count($val_list);
|
||||
for($i=0;$i<$val_count;$i++) $this->_bind($val_list[$i]);
|
||||
$this->_prepare($query);
|
||||
|
||||
return $this->_execute();
|
||||
}
|
||||
$val_count = count($val_list);
|
||||
for ($i = 0; $i < $val_count; $i++)
|
||||
$this->_bind($val_list[$i]);
|
||||
|
||||
/**
|
||||
* @brief updateAct
|
||||
**/
|
||||
function _executeUpdateAct($queryObject) {
|
||||
$query = $this->getUpdateSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$this->_prepare($query);
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief deleteAct
|
||||
**/
|
||||
function _executeDeleteAct($queryObject) {
|
||||
$query = $this->getDeleteSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$this->_prepare($query);
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief selectAct
|
||||
*
|
||||
* To fetch a list of the page conveniently when selecting, \n
|
||||
* navigation method supported
|
||||
**/
|
||||
function _executeSelectAct($queryObject) {
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$this->_prepare($query);
|
||||
$data = $this->_execute();
|
||||
if($this->isError()) return;
|
||||
|
||||
if ($this->isError ()) return $this->queryError($queryObject);
|
||||
else return $this->queryPageLimit($queryObject, $data);
|
||||
}
|
||||
|
||||
function queryError($queryObject){
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->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, $data){
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
|
||||
// Total count
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString()));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$this->_prepare($count_query);
|
||||
$count_output = $this->_execute();
|
||||
$total_count = (int)$count_output->count;
|
||||
|
||||
// Total pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
|
||||
} else $total_page = 1;
|
||||
|
||||
$this->_prepare($this->getSelectSql($queryObject));
|
||||
$this->stmt->execute();
|
||||
if($this->stmt->errorCode() != '00000') {
|
||||
$this->setError($this->stmt->errorCode(), print_r($this->stmt->errorInfo(),true));
|
||||
$this->actFinish();
|
||||
return $buff;
|
||||
}
|
||||
|
||||
$output = null;
|
||||
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
|
||||
//$data = $this->_fetch($result, $virtual_no);
|
||||
while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
unset($obj);
|
||||
foreach($tmp as $key => $val) {
|
||||
$pos = strpos($key, '.');
|
||||
if($pos) $key = substr($key, $pos+1);
|
||||
$obj->{$key} = $val;
|
||||
}
|
||||
$data[$virtual_no--] = $obj;
|
||||
}
|
||||
|
||||
$this->stmt = null;
|
||||
$this->actFinish();
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page;
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page, $queryObject->getLimit()->page_count);
|
||||
}else{
|
||||
//$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief updateAct
|
||||
* */
|
||||
function _executeUpdateAct($queryObject) {
|
||||
$query = $this->getUpdateSql($queryObject);
|
||||
if (is_a($query, 'Object'))
|
||||
return;
|
||||
|
||||
$this->_prepare($query);
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief deleteAct
|
||||
* */
|
||||
function _executeDeleteAct($queryObject) {
|
||||
$query = $this->getDeleteSql($queryObject);
|
||||
if (is_a($query, 'Object'))
|
||||
return;
|
||||
|
||||
$this->_prepare($query);
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief selectAct
|
||||
*
|
||||
* To fetch a list of the page conveniently when selecting, \n
|
||||
* navigation method supported
|
||||
* */
|
||||
function _executeSelectAct($queryObject) {
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
if (is_a($query, 'Object'))
|
||||
return;
|
||||
|
||||
$this->_prepare($query);
|
||||
$data = $this->_execute();
|
||||
if ($this->isError())
|
||||
return;
|
||||
|
||||
if ($this->isError())
|
||||
return $this->queryError($queryObject);
|
||||
else
|
||||
return $this->queryPageLimit($queryObject, $data);
|
||||
}
|
||||
|
||||
function queryError($queryObject) {
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->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, $data) {
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
|
||||
// Total count
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE ' . $queryObject->getWhereString()));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$count_query .= ( __DEBUG_QUERY__ & 1 && $output->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : '';
|
||||
$this->_prepare($count_query);
|
||||
$count_output = $this->_execute();
|
||||
$total_count = (int) $count_output->count;
|
||||
|
||||
// Total pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
|
||||
} else
|
||||
$total_page = 1;
|
||||
|
||||
$this->_prepare($this->getSelectSql($queryObject));
|
||||
$this->stmt->execute();
|
||||
if ($this->stmt->errorCode() != '00000') {
|
||||
$this->setError($this->stmt->errorCode(), print_r($this->stmt->errorInfo(), true));
|
||||
$this->actFinish();
|
||||
return $buff;
|
||||
}
|
||||
|
||||
$output = null;
|
||||
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
|
||||
//$data = $this->_fetch($result, $virtual_no);
|
||||
while ($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
unset($obj);
|
||||
foreach ($tmp as $key => $val) {
|
||||
$pos = strpos($key, '.');
|
||||
if ($pos)
|
||||
$key = substr($key, $pos + 1);
|
||||
$obj->{$key} = $val;
|
||||
}
|
||||
$data[$virtual_no--] = $obj;
|
||||
}
|
||||
|
||||
$this->stmt = null;
|
||||
$this->actFinish();
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page->getValue();
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page->getValue(), $queryObject->getLimit()->page_count);
|
||||
}else {
|
||||
//$data = $this->_fetch($result);
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new DBSqlite3_pdo;
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue