Compare commits

...

9 Commits

Author SHA1 Message Date
as2252258 7c347bc373 eee 2025-07-09 10:34:46 +08:00
as2252258 d5c9b3bc86 eee 2025-07-09 10:28:20 +08:00
as2252258 ef7e85746d eee 2025-05-19 11:20:32 +08:00
as2252258 89f6949556 eee 2025-05-19 11:19:20 +08:00
as2252258 555d160b40 eee 2025-05-19 11:09:33 +08:00
as2252258 45b949747d eee 2025-05-19 11:06:27 +08:00
as2252258 94857ecb46 eee 2025-02-17 16:29:10 +08:00
as2252258 0f0a3349fb eee 2025-02-17 16:26:32 +08:00
as2252258 7fb9c3ea05 eee 2025-01-18 20:28:24 +08:00
3 changed files with 30 additions and 5 deletions
+1 -1
View File
@@ -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
View File
@@ -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();
}
+23
View File
@@ -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 . ' ?';
}