Skip to content

Commit e61b266

Browse files
committed
改进pgsql驱动
1 parent 4a4988a commit e61b266

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/db/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ protected function parseDateTime(Query $query, $value, string $key, int $bindTyp
508508
}
509509

510510
if (is_int($value)) {
511-
if (preg_match('/(datetime|timestamp)/is', $type)) {
511+
if (preg_match('/(datetime|timestamp|string)/is', $type)) {
512512
// 日期及时间戳类型
513513
$value = date('Y-m-d H:i:s', $value);
514514
} elseif (preg_match('/(date)/is', $type)) {

src/db/builder/Pgsql.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,20 @@ public function parseKey(Query $query, string|int|Raw $key, bool $strict = false
8383
// JSON字段支持
8484
[$field, $name] = explode('->', $key);
8585
$key = '"' . $field . '"' . '->>\'' . $name . '\'';
86-
} elseif (str_contains($key, '.')) {
87-
[$table, $key] = explode('.', $key, 2);
86+
} else {
87+
if (str_contains($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
88+
[$table, $key] = explode('.', $key, 2);
8889

89-
$alias = $query->getOption('alias');
90+
$alias = $query->getOption('alias');
9091

91-
if ('__TABLE__' == $table) {
92-
$table = $query->getOption('table');
93-
$table = is_array($table) ? array_shift($table) : $table;
94-
}
92+
if ('__TABLE__' == $table) {
93+
$table = $query->getOption('table');
94+
$table = is_array($table) ? array_shift($table) : $table;
95+
}
9596

96-
if (isset($alias[$table])) {
97-
$table = $alias[$table];
97+
if (isset($alias[$table])) {
98+
$table = $alias[$table];
99+
}
98100
}
99101

100102
if ('*' != $key && !preg_match('/[,\"\*\(\).\s]/', $key)) {
@@ -103,7 +105,11 @@ public function parseKey(Query $query, string|int|Raw $key, bool $strict = false
103105
}
104106

105107
if (isset($table)) {
106-
$key = $table . '.' . $key;
108+
if (str_contains($table, '.')) {
109+
$table = str_replace('.', '"."', $table);
110+
}
111+
112+
$key = '"' . $table . '".' . $key;
107113
}
108114

109115
return $key;

0 commit comments

Comments
 (0)