From 0b78e26357f39d3e64eaaf173d073b932d7400c5 Mon Sep 17 00:00:00 2001 From: mosmartin Date: Fri, 27 May 2011 11:39:45 +0000 Subject: [PATCH] Fix condition/ConditionGroup.class.php when all conditions have no value. Add page navigation mechanism. git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8399 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/db/DBCubrid.class.php | 54 +++++++++++++++++-- .../condition/ConditionGroup.class.php | 2 + classes/db/queryparts/limit/Limit.class.php | 18 +++++-- .../tags/navigation/LimitTag.class.php | 3 +- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/classes/db/DBCubrid.class.php b/classes/db/DBCubrid.class.php index 54aca4125..04a86c357 100644 --- a/classes/db/DBCubrid.class.php +++ b/classes/db/DBCubrid.class.php @@ -802,15 +802,59 @@ } $query = $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit; - + //$query = sprintf ("select %s from %s %s %s %s", $columns, implode (',',$table_list), implode (' ',$left_join), $condition, //$groupby_query.$orderby_query); //$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):''; $result = $this->_query ($query); - if ($this->isError ()) return; - $data = $this->_fetch ($result); + if ($this->isError ()) { + if ($limit && $output->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; + } - $buff = new Object (); - $buff->data = $data; + if ($limit && $output->limit->isPageHandler()) { + $count_query = sprintf('select count(*) as "count" %s %s', $from, $where); + if (count($output->groups)) { + $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) / $output->limit->list_count) + 1; + } else $total_page = 1; + + $virtual_no = $total_count - ($output->limit->page - 1) * $output->limit->list_count; + while ($tmp = cubrid_fetch ($result, CUBRID_OBJECT)) { + if ($tmp) { + foreach ($tmp as $k => $v) { + $tmp->{$k} = rtrim($v); + } + } + $data[$virtual_no--] = $tmp; + } + + $buff = new Object (); + $buff->total_count = $total_count; + $buff->total_page = $total_page; + $buff->page = $output->limit->page; + $buff->data = $data; + $buff->page_navigation = new PageHandler ($total_count, $total_page, $output->limit->page, $output->limit->page_count); + }else{ + $data = $this->_fetch ($result); + $buff = new Object (); + $buff->data = $data; + } return $buff; } diff --git a/classes/db/queryparts/condition/ConditionGroup.class.php b/classes/db/queryparts/condition/ConditionGroup.class.php index 5e9a943b9..cab975d7d 100644 --- a/classes/db/queryparts/condition/ConditionGroup.class.php +++ b/classes/db/queryparts/condition/ConditionGroup.class.php @@ -23,6 +23,8 @@ $cond_indx++; } } + // If the group has no conditions in it, return '' + if($cond_indx === 0) return ''; if($this->pipe !== "") $group .= ')'; diff --git a/classes/db/queryparts/limit/Limit.class.php b/classes/db/queryparts/limit/Limit.class.php index fc20d3fbe..46090ddff 100644 --- a/classes/db/queryparts/limit/Limit.class.php +++ b/classes/db/queryparts/limit/Limit.class.php @@ -1,15 +1,23 @@ start = ($page-1)*$list_count; - $this->end = $list_count; + $this->list_count = $list_count; + $this->page_count = $page_count; + $this->page = $page; + } + + function isPageHandler(){//in case you choose to use query limit in other cases than page select + return true; } function toString(){ - return $this->start . ' , ' . $this->end; + return $this->start . ' , ' . $this->list_count; } } diff --git a/classes/xml/xmlquery/tags/navigation/LimitTag.class.php b/classes/xml/xmlquery/tags/navigation/LimitTag.class.php index 52b81b8d0..a6d2734ae 100644 --- a/classes/xml/xmlquery/tags/navigation/LimitTag.class.php +++ b/classes/xml/xmlquery/tags/navigation/LimitTag.class.php @@ -14,10 +14,11 @@ require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php'); $this->arguments[] = new QueryArgument($index->page); $this->arguments[] = new QueryArgument($index->list_count); + $this->arguments[] = new QueryArgument($index->page_count); } function toString(){ - return sprintf("new Limit(\$%s_argument->getValue(), \$%s_argument->getValue())", $this->page->var, $this->list_count->var); + return sprintf("new Limit(\$%s_argument->getValue(), \$%s_argument->getValue(), \$%s_argument->getValue())", $this->page->var, $this->list_count->var, $this->page_count->var); } function getArguments(){