mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-25 21:32:51 +09:00
Support HAVING in XML queries
GROUP BY에 사용되는 <groups> 태그 안에 <having> 태그를 넣을 수 있습니다.
문법은 <conditions> 부분에 적용되는 것과 같습니다.
<query id="queryId" action="select">
...
<groups>
<group column="document_srl" />
<having>
<condition operation="more" column="document_srl" var="myvar" default="0" />
</having>
</groups>
...
</query>
결과: SELECT ... GROUP BY document_srl HAVING document_srl >= 0
This commit is contained in:
parent
2b5cded376
commit
20fa55a3fc
3 changed files with 89 additions and 6 deletions
|
|
@ -51,6 +51,12 @@ class Query extends BaseObject
|
|||
*/
|
||||
var $groups;
|
||||
|
||||
/**
|
||||
* having list
|
||||
* @var string|array
|
||||
*/
|
||||
var $having;
|
||||
|
||||
/**
|
||||
* order list
|
||||
* @var array
|
||||
|
|
@ -232,6 +238,27 @@ class Query extends BaseObject
|
|||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
function setHaving($conditions)
|
||||
{
|
||||
$this->having = array();
|
||||
if(!isset($conditions) || count($conditions) === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!is_array($conditions))
|
||||
{
|
||||
$conditions = array($conditions);
|
||||
}
|
||||
|
||||
foreach($conditions as $conditionGroup)
|
||||
{
|
||||
if($conditionGroup->show())
|
||||
{
|
||||
$this->having[] = $conditionGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setOrder($order)
|
||||
{
|
||||
if(!isset($order) || count($order) === 0)
|
||||
|
|
@ -552,6 +579,30 @@ class Query extends BaseObject
|
|||
return $groupBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return having sql
|
||||
* @param boolean $with_values
|
||||
* @return string
|
||||
*/
|
||||
function getHavingString($with_values = TRUE)
|
||||
{
|
||||
$having = '';
|
||||
$condition_count = 0;
|
||||
|
||||
foreach($this->having as $conditionGroup)
|
||||
{
|
||||
if($condition_count === 0)
|
||||
{
|
||||
$conditionGroup->setPipe("");
|
||||
}
|
||||
$condition_string = $conditionGroup->toString($with_values);
|
||||
$having .= $condition_string;
|
||||
$condition_count++;
|
||||
}
|
||||
|
||||
return trim($having);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return orderby sql
|
||||
* @return string
|
||||
|
|
@ -656,6 +707,19 @@ class Query extends BaseObject
|
|||
}
|
||||
}
|
||||
|
||||
// Having arguments
|
||||
if(countobj($this->having) > 0)
|
||||
{
|
||||
foreach($this->having as $conditionGroup)
|
||||
{
|
||||
$args = $conditionGroup->getArguments();
|
||||
if(countobj($args) > 0)
|
||||
{
|
||||
$this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation arguments
|
||||
if(countobj($this->orderby) > 0)
|
||||
{
|
||||
|
|
@ -669,6 +733,7 @@ class Query extends BaseObject
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue