Skip to content

Commit a520a6a

Browse files
committed
Fix set($data, '', false)
When using set without escape binds isn't used. Added code to get data from QBSet rather than binds and convert into array of arrays.
1 parent 1b48adb commit a520a6a

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

system/Database/BaseBuilder.php

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class BaseBuilder
170170
* sql?: string,
171171
* alias?: string
172172
* }
173+
*
173174
* @var array
174175
*/
175176
protected $QBOptions;
@@ -497,10 +498,10 @@ public function selectSubquery(BaseBuilder $subquery, string $as): self
497498
* @used-by selectAvg()
498499
* @used-by selectSum()
499500
*
500-
* @return $this
501-
*
502501
* @throws DatabaseException
503502
* @throws DataException
503+
*
504+
* @return $this
504505
*/
505506
protected function maxMinAvgSum(string $select = '', string $alias = '', string $type = 'MAX')
506507
{
@@ -909,9 +910,9 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
909910
*
910911
* @param array|BaseBuilder|Closure|null $values The values searched on, or anonymous function with subquery
911912
*
912-
* @return $this
913-
*
914913
* @throws InvalidArgumentException
914+
*
915+
* @return $this
915916
*/
916917
protected function _whereIn(?string $key = null, $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null, string $clause = 'QBWhere')
917918
{
@@ -1743,9 +1744,9 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
17431744
/**
17441745
* Compiles batch insert/update/upsert strings and runs the queries
17451746
*
1746-
* @return false|int|string[] Number of rows inserted or FALSE on failure, SQL array when testMode
1747-
*
17481747
* @throws DatabaseException
1748+
*
1749+
* @return false|int|string[] Number of rows inserted or FALSE on failure, SQL array when testMode
17491750
*/
17501751
protected function batchExecute(string $renderMethod, int $batchSize = 100)
17511752
{
@@ -1858,9 +1859,9 @@ public function setData($set, ?bool $escape = null, string $alias = '')
18581859
/**
18591860
* Compiles an upsert query and returns the sql
18601861
*
1861-
* @return string
1862-
*
18631862
* @throws DatabaseException
1863+
*
1864+
* @return string
18641865
*/
18651866
public function getCompiledUpsert()
18661867
{
@@ -1878,17 +1879,24 @@ public function getCompiledUpsert()
18781879
*
18791880
* @param array|object|null $set
18801881
*
1881-
* @return false|int|string[] Number of affected rows or FALSE on failure, SQL array when testMode
1882-
*
18831882
* @throws DatabaseException
1883+
*
1884+
* @return false|int|string[] Number of affected rows or FALSE on failure, SQL array when testMode
18841885
*/
18851886
public function upsert($set = null, ?bool $escape = null)
18861887
{
1887-
if ($set === null) {
1888-
$set = empty($this->binds) ? null : [array_map(static fn ($columnName) => $columnName[0], $this->binds)];
1888+
if ($set === null && ! empty($this->binds)) {
1889+
$set = [array_map(static fn ($columnName) => $columnName[0], $this->binds)];
18891890

18901891
$this->binds = [];
18911892

1893+
$this->resetRun([
1894+
'QBSet' => [],
1895+
'QBKeys' => [],
1896+
]);
1897+
} elseif ($set === null && ! empty($this->QBSet)) {
1898+
$set = [$this->QBSet];
1899+
18921900
$this->resetRun([
18931901
'QBSet' => [],
18941902
'QBKeys' => [],
@@ -1907,9 +1915,9 @@ public function upsert($set = null, ?bool $escape = null)
19071915
*
19081916
* @param array|object|string|null $set a dataset or select query
19091917
*
1910-
* @return false|int|string[] Number of affected rows or FALSE on failure, SQL array when testMode
1911-
*
19121918
* @throws DatabaseException
1919+
*
1920+
* @return false|int|string[] Number of affected rows or FALSE on failure, SQL array when testMode
19131921
*/
19141922
public function upsertBatch($set = null, ?bool $escape = null, int $batchSize = 100)
19151923
{
@@ -2114,9 +2122,9 @@ public function setInsertBatch($key, string $value = '', ?bool $escape = null)
21142122
/**
21152123
* Compiles an insert query and returns the sql
21162124
*
2117-
* @return bool|string
2118-
*
21192125
* @throws DatabaseException
2126+
*
2127+
* @return bool|string
21202128
*/
21212129
public function getCompiledInsert(bool $reset = true)
21222130
{
@@ -2147,9 +2155,9 @@ public function getCompiledInsert(bool $reset = true)
21472155
*
21482156
* @param array|object|null $set
21492157
*
2150-
* @return bool
2151-
*
21522158
* @throws DatabaseException
2159+
*
2160+
* @return bool
21532161
*/
21542162
public function insert($set = null, ?bool $escape = null)
21552163
{
@@ -2237,9 +2245,9 @@ protected function _insert(string $table, array $keys, array $unescapedKeys): st
22372245
/**
22382246
* Compiles a replace into string and runs the query
22392247
*
2240-
* @return BaseResult|false|Query|string
2241-
*
22422248
* @throws DatabaseException
2249+
*
2250+
* @return BaseResult|false|Query|string
22432251
*/
22442252
public function replace(?array $set = null)
22452253
{
@@ -2490,10 +2498,10 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
24902498
*
24912499
* @param array|object $key
24922500
*
2493-
* @return $this
2494-
*
24952501
* @throws DatabaseException
24962502
*
2503+
* @return $this
2504+
*
24972505
* @deprecated
24982506
*/
24992507
public function setUpdateBatch($key, string $index = '', ?bool $escape = null)
@@ -2576,9 +2584,9 @@ public function getCompiledDelete(bool $reset = true): string
25762584
*
25772585
* @param mixed $where
25782586
*
2579-
* @return bool|string
2580-
*
25812587
* @throws DatabaseException
2588+
*
2589+
* @return bool|string
25822590
*/
25832591
public function delete($where = '', ?int $limit = null, bool $resetData = true)
25842592
{

0 commit comments

Comments
 (0)