This commit is contained in:
2021-03-26 18:51:47 +08:00
parent 21dd7c0901
commit 4a7cfb90a7
2 changed files with 73 additions and 17 deletions
+38 -9
View File
@@ -204,16 +204,11 @@ class SqlBuilder extends Component
*/
private function _prefix($hasOrder = false): string
{
$select = $this->builderSelect($this->query->select) . ' FROM ' . $this->tableName();
if (!empty($this->query->alias)) {
$select .= $this->builderAlias($this->query->alias);
}
if (!empty($this->query->join)) {
$select .= $this->builderJoin($this->query->join);
}
if (!empty($condition = $this->conditionToString())) {
$select = sprintf('%s WHERE %s', $select, $condition);
$select = '';
if (!empty($this->query->from)) {
$select = $this->_selectPrefix();
}
$select = $this->_wherePrefix($select);
if (!empty($this->query->group)) {
$select .= $this->builderGroup($this->query->group);
}
@@ -224,6 +219,40 @@ class SqlBuilder extends Component
}
/**
* @param $select
* @return string
* @throws Exception
*/
private function _wherePrefix($select): string
{
$condition = $this->conditionToString();
if (empty($condition)) {
return $select;
} else if (empty($select)) {
return $condition;
}
return sprintf('%s WHERE %s', $select, $condition);
}
/**
* @return string
* @throws Exception
*/
private function _selectPrefix(): string
{
$select = $this->builderSelect($this->query->select) . ' FROM ' . $this->tableName();
if (!empty($this->query->alias)) {
$select .= $this->builderAlias($this->query->alias);
}
if (!empty($this->query->join)) {
$select .= $this->builderJoin($this->query->join);
}
return $select;
}
/**
* @param false $isCount
* @return string