Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c347bc373 | |||
| d5c9b3bc86 | |||
| ef7e85746d | |||
| 89f6949556 | |||
| 555d160b40 | |||
| 45b949747d | |||
| 94857ecb46 | |||
| 0f0a3349fb | |||
| 7fb9c3ea05 |
+1
-1
@@ -699,7 +699,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
||||
|
||||
$method = $prefix . 'Attribute';
|
||||
if (method_exists($this, $method)) {
|
||||
$this->_attributes[$name] = $this->{$method} ($value);
|
||||
$this->_attributes[$name] = $this->{$method}($value);
|
||||
} else {
|
||||
$this->_attributes[$name] = $value;
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,4 +1,5 @@
|
||||
<?php /** @noinspection ALL */
|
||||
<?php
|
||||
/** @noinspection ALL */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
@@ -189,7 +190,7 @@ class SqlBuilder extends Component
|
||||
if (is_null($value)) {
|
||||
return $keys;
|
||||
}
|
||||
if (preg_match('/^[+|-]\s\d+$/', $value)) {
|
||||
if (preg_match('/^[+|-]\s\d+$/', (string)$value)) {
|
||||
$keys[] = $key . '=' . $key . ' ' . $value;
|
||||
} else {
|
||||
$this->query->pushParam($value);
|
||||
@@ -205,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -215,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