Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 39905b77e3 | |||
| fce82ec56c | |||
| 2970c3bc6b | |||
| a35d0bb921 | |||
| fce2b8bcdb | |||
| ce92f310a5 | |||
| 28fa17ecfb | |||
| 9fc910f10f | |||
| 0a95e722d6 | |||
| 9f2611972f | |||
| b7e59d1c96 | |||
| 9b0ee54608 | |||
| 763a4baa57 | |||
| fe639bbd1f | |||
| e40de4ee4a | |||
| ffc2af69da | |||
| 218a38da48 | |||
| 5acb2f4600 | |||
| d6a07446bb | |||
| 6c936c3896 | |||
| 14448d824a |
+2
-4
@@ -148,8 +148,7 @@ class Command extends Component
|
||||
}
|
||||
}
|
||||
|
||||
$errorMsg = 'Max retry exceeded for SQL: ' . $this->sql;
|
||||
return $this->getLogger()->logCategory($errorMsg, 'mysql');
|
||||
return $this->getLogger()->logCategory('Max retry exceeded for SQL: ' . $this->sql, 'mysql');
|
||||
}
|
||||
|
||||
|
||||
@@ -213,8 +212,7 @@ class Command extends Component
|
||||
}
|
||||
}
|
||||
|
||||
$errorMsg = 'Max retry exceeded for SQL: ' . $this->sql;
|
||||
return $this->getLogger()->logCategory($errorMsg, 'mysql');
|
||||
return $this->getLogger()->logCategory('Max retry exceeded for SQL: ' . $this->sql, 'mysql');
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ class Connection extends Component
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getName(): string
|
||||
public function getName(): string
|
||||
{
|
||||
return strtolower($this->driver) . '.' . $this->cds;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class DatabasesProviders extends Providers
|
||||
return;
|
||||
}
|
||||
foreach ($databases as $key => $database) {
|
||||
$this->set($key, $this->_settings($database));
|
||||
$this->set($key, $this->_settings($key, $database));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,14 +64,15 @@ class DatabasesProviders extends Providers
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $database
|
||||
* @return array
|
||||
*/
|
||||
private function _settings(array $database): array
|
||||
private function _settings(string $key, array $database): array
|
||||
{
|
||||
$clientPool = $database['pool'] ?? ['min' => 1, 'max' => 5, 'tick' => 60];
|
||||
return [
|
||||
'id' => $database['id'],
|
||||
'id' => $key,
|
||||
'cds' => $database['cds'],
|
||||
'class' => Connection::class,
|
||||
'username' => $database['username'],
|
||||
|
||||
+24
-23
@@ -75,13 +75,13 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function update(array $attributes): bool|string
|
||||
{
|
||||
$conditions = $this->query;
|
||||
$this->query = [];
|
||||
$data = $this->__updateBuilder($this->makeParams($attributes));
|
||||
foreach ($conditions as $condition) {
|
||||
$this->query->pushParam($condition);
|
||||
$params = $this->query->params;
|
||||
$this->query->params = [];
|
||||
$array = $this->makeParams($attributes);
|
||||
foreach ($params as $name => $value) {
|
||||
$this->query->pushParam($value);
|
||||
}
|
||||
return $data;
|
||||
return $this->__updateBuilder($array);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,8 @@ class SqlBuilder extends Component
|
||||
if (empty($string)) {
|
||||
return Kiri::getLogger()->logCategory('None data update.');
|
||||
}
|
||||
return 'UPDATE ' . $this->getFromAlias() . ' SET ' . implode(',', $string) . $this->make();
|
||||
|
||||
return 'UPDATE ' . $this->getFromAlias() . ' ' . 'SET' . ' ' . implode(', ', $string) . ' ' . $this->make();
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +146,9 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function delete(): string
|
||||
{
|
||||
return 'DELETE FROM ' . $this->getFromAlias() . $this->make();
|
||||
return 'DELETE FROM ' .
|
||||
$this->getFromAlias() . ' ' .
|
||||
$this->make();
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +156,8 @@ class SqlBuilder extends Component
|
||||
* @param $attributes
|
||||
* @return array
|
||||
*/
|
||||
#[Pure] private function getFields(array $attributes): array
|
||||
#[Pure]
|
||||
private function getFields(array $attributes): array
|
||||
{
|
||||
return array_keys(current($attributes));
|
||||
}
|
||||
@@ -208,7 +212,7 @@ class SqlBuilder extends Component
|
||||
public function one(): string
|
||||
{
|
||||
$this->query->offset(0)->limit(1);
|
||||
return $this->makeSelect($this->query) . $this->make() . $this->makeLimit();
|
||||
return $this->all();
|
||||
}
|
||||
|
||||
|
||||
@@ -218,7 +222,7 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function all(): string
|
||||
{
|
||||
return $this->makeSelect($this->query) . $this->make() . $this->makeLimit();
|
||||
return $this->makeSelect($this->query) . ' ' . $this->make() . ' ' . $this->makeLimit();
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +232,7 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function count(): string
|
||||
{
|
||||
return $this->makeSelect(['COUNT(*)']) . $this->make();
|
||||
return $this->makeSelect(['COUNT(*)']) . ' ' . $this->make();
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +242,7 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
public function exists(): string
|
||||
{
|
||||
return $this->makeSelect(['0']) . $this->make();
|
||||
return $this->makeSelect(['0']) . ' ' . $this->make();
|
||||
}
|
||||
|
||||
|
||||
@@ -273,10 +277,7 @@ class SqlBuilder extends Component
|
||||
*/
|
||||
private function make(): string
|
||||
{
|
||||
$select = $this->makeCondition();
|
||||
$select .= $this->makeGroup();
|
||||
$select .= $this->makeOrder();
|
||||
return $select;
|
||||
return $this->makeCondition() . ' ' . $this->makeGroup() . ' ' . $this->makeOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,7 +289,7 @@ class SqlBuilder extends Component
|
||||
if (!is_array($select)) {
|
||||
$select = ['*'];
|
||||
}
|
||||
$sql = "SELECT " . implode(',', $select) . " FROM " . $this->getFromAlias();
|
||||
$sql = 'SELECT ' . implode(',', $select) . ' FROM ' . $this->getFromAlias();
|
||||
if ($this->query->join !== []) {
|
||||
$sql .= ' ' . implode(' ', $this->query->join);
|
||||
}
|
||||
@@ -302,7 +303,7 @@ class SqlBuilder extends Component
|
||||
private function makeGroup(): string
|
||||
{
|
||||
if ($this->query->group !== '' && $this->query->group !== '0') {
|
||||
return ' GROUP BY ' . $this->query->group;
|
||||
return 'GROUP BY ' . $this->query->group;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -314,7 +315,7 @@ class SqlBuilder extends Component
|
||||
private function makeOrder(): string
|
||||
{
|
||||
if (count($this->query->order) > 0) {
|
||||
return ' ORDER BY ' . implode(',', $this->query->order);
|
||||
return 'ORDER BY ' . implode(',', $this->query->order);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -329,7 +330,7 @@ class SqlBuilder extends Component
|
||||
if (empty($condition)) {
|
||||
return '';
|
||||
}
|
||||
return ' WHERE ' . $condition;
|
||||
return 'WHERE ' . $condition;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,9 +343,9 @@ class SqlBuilder extends Component
|
||||
if ($this->query->offset >= 0 && $this->query->limit >= 1) {
|
||||
$driver = $this->getDriver();
|
||||
if (in_array($driver, ['pgsql', 'postgresql'])) {
|
||||
return ' LIMIT ' . $this->query->limit . ' OFFSET ' . $this->query->offset;
|
||||
return 'LIMIT ' . $this->query->limit . ' OFFSET ' . $this->query->offset;
|
||||
}
|
||||
return ' LIMIT ' . $this->query->offset . ',' . $this->query->limit;
|
||||
return 'LIMIT ' . $this->query->offset . ',' . $this->query->limit;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -116,6 +116,18 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
|
||||
}
|
||||
|
||||
|
||||
public function __get(string $name)
|
||||
{
|
||||
if (property_exists($this, $name)) {
|
||||
return $this->$name;
|
||||
}
|
||||
if (method_exists($this, $name)) {
|
||||
return $this->$name();
|
||||
}
|
||||
return parent::__get($name); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Comply constructor.
|
||||
* @throws
|
||||
|
||||
Reference in New Issue
Block a user