Skip to content

Commit 36f2432

Browse files
committed
Fix use of setAlias()
Added $this->db->addTableAlias($alias) to setAlias(). This keeps track of the alias and prevents adding the database prefix when using $this->db->protectIdentifiers(). There was some issues with this. Also made some fixes to updateBatch() and use of RawSql. Just a small fix that allows key value pairs with RawSql.
1 parent 603239c commit 36f2432

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

system/Database/BaseBuilder.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
19691969
public function setAlias(string $alias): BaseBuilder
19701970
{
19711971
if ($alias !== '') {
1972+
$this->db->addTableAlias($alias);
19721973
$this->QBOptions['alias'] = $this->db->protectIdentifiers($alias);
19731974
}
19741975

@@ -2044,6 +2045,10 @@ public function onConstraint($set)
20442045
$value = $this->db->protectIdentifiers($value);
20452046
}
20462047

2048+
if (is_string($key)) {
2049+
$key = $this->db->protectIdentifiers($key);
2050+
}
2051+
20472052
$this->QBOptions['constraints'][$key] = $value;
20482053
}
20492054
}
@@ -2462,9 +2467,20 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
24622467
$sql .= 'WHERE ' . implode(
24632468
' AND ',
24642469
array_map(
2465-
static fn ($key) => ($key instanceof RawSql ?
2466-
$key :
2467-
$table . '.' . $key . ' = ' . $alias . '.' . $key),
2470+
static fn ($key, $value) => (
2471+
($value instanceof RawSql && is_string($key))
2472+
?
2473+
$table . '.' . $key . ' = ' . $value
2474+
:
2475+
(
2476+
$value instanceof RawSql
2477+
?
2478+
$value
2479+
:
2480+
$table . '.' . $value . ' = ' . $alias . '.' . $value
2481+
)
2482+
),
2483+
array_keys($constraints),
24682484
$constraints
24692485
)
24702486
);

0 commit comments

Comments
 (0)