Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c347bc373 | |||
| d5c9b3bc86 | |||
| ef7e85746d | |||
| 89f6949556 | |||
| 555d160b40 | |||
| 45b949747d |
+3
-2
@@ -206,7 +206,8 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function one(): string
|
||||
{
|
||||
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit($this->query->limit(1));
|
||||
$this->query->offset(0)->limit(1);
|
||||
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit();
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +217,7 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function all(): string
|
||||
{
|
||||
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit($this->query);
|
||||
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
{
|
||||
if ($callback instanceof Query) {
|
||||
$this->where[] = 'NOT EXISTS(' . $callback->build() . ')';
|
||||
$this->mergeParams($callback->getParams());
|
||||
} else {
|
||||
$this->where[] = 'NOT EXISTS(' . $this->makeClosureFunction($callback) . ')';
|
||||
}
|
||||
@@ -104,6 +105,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
{
|
||||
if ($callback instanceof Query) {
|
||||
$this->where[] = 'EXISTS(' . $callback->build() . ')';
|
||||
$this->mergeParams($callback->getParams());
|
||||
} else {
|
||||
$this->where[] = 'EXISTS(' . $this->makeClosureFunction($callback) . ')';
|
||||
}
|
||||
@@ -302,6 +304,18 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function mergeParams(array $params): void
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
$this->pushParam($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @param callable $callable
|
||||
@@ -442,6 +456,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
{
|
||||
if ($tableName instanceof Query) {
|
||||
$this->from = '(' . $tableName->build() . ')';
|
||||
$this->mergeParams($tableName->getParams());
|
||||
} else if ($tableName instanceof Closure) {
|
||||
$this->from = '(' . $this->makeClosureFunction($tableName) . ')';
|
||||
} else if (class_exists($tableName)) {
|
||||
@@ -806,6 +821,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
$this->where[] = $columns . ' IN (' . implode(',', $value) . ')';
|
||||
} else if ($value instanceof Query) {
|
||||
$this->where[] = $columns . ' IN (' . $value->build() . ')';
|
||||
$this->mergeParams($value->getParams());
|
||||
} else {
|
||||
$this->where[] = $columns . ' IN (' . $this->makeClosureFunction($value) . ')';
|
||||
}
|
||||
@@ -953,6 +969,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
} else {
|
||||
$generate->addArray($closure);
|
||||
}
|
||||
$this->mergeParams($generate->getParams());
|
||||
return $generate->build();
|
||||
}
|
||||
|
||||
@@ -1041,6 +1058,12 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
*/
|
||||
private function sprintf(string $column, mixed $value, string $opera = '='): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
[$alias, $field] = explode('.', $value);
|
||||
if (in_array($alias, $this->_alias)) {
|
||||
return $column . ' ' . $opera . ' ' . $value;
|
||||
}
|
||||
}
|
||||
$this->pushParam($value);
|
||||
return $column . ' ' . $opera . ' ?';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user