File tree Expand file tree Collapse file tree 2 files changed +36
-17
lines changed
tests/system/Database/Live Expand file tree Collapse file tree 2 files changed +36
-17
lines changed Original file line number Diff line number Diff line change @@ -1885,35 +1885,28 @@ public function getCompiledUpsert()
1885
1885
*/
1886
1886
public function upsert ($ set = null , ?bool $ escape = null )
1887
1887
{
1888
+ // if set() function was used then we need to convert to setData()
1888
1889
if ($ set === null && ! empty ($ this ->binds )) {
1889
- $ set = [array_map (static fn ($ columnName ) => $ columnName [0 ], $ this ->binds )];
1890
-
1890
+ $ set = [array_map (static fn ($ columnName ) => $ columnName [0 ], $ this ->binds )];
1891
1891
$ this ->binds = [];
1892
-
1893
- $ this ->resetRun ([
1894
- 'QBSet ' => [],
1895
- 'QBKeys ' => [],
1896
- ]);
1897
1892
} elseif ($ set === null && ! empty ($ this ->QBSet )) {
1898
- $ set = [$ this ->QBSet ];
1899
-
1900
- $ this ->resetRun ([
1901
- 'QBSet ' => [],
1902
- 'QBKeys ' => [],
1903
- ]);
1904
- } else {
1905
- $ set = [$ set ];
1893
+ $ set = $ this ->QBSet ;
1906
1894
}
1907
1895
1896
+ $ this ->resetRun ([
1897
+ 'QBSet ' => [],
1898
+ 'QBKeys ' => [],
1899
+ ]);
1900
+
1908
1901
$ this ->setData ($ set , $ escape );
1909
1902
1910
- return $ this ->batchExecute ('_upsertBatch ' , 1 );
1903
+ return $ this ->batchExecute ('_upsertBatch ' );
1911
1904
}
1912
1905
1913
1906
/**
1914
1907
* Compiles batch upsert strings and runs the queries
1915
1908
*
1916
- * @param array|object|string| null $set a dataset or select query
1909
+ * @param array|object|null $set a dataset
1917
1910
*
1918
1911
* @throws DatabaseException
1919
1912
*
Original file line number Diff line number Diff line change @@ -242,6 +242,32 @@ public function testGetCompiledUpsert()
242
242
->getCompiledUpsert ());
243
243
}
244
244
245
+ public function testGetCompiledUpsertBatch ()
246
+ {
247
+ $ userData = [
248
+ [
249
+
250
+ 'name ' => 'Ahmadinejad ' ,
251
+ 'country ' => 'Iran ' ,
252
+ ],
253
+ [
254
+
255
+ 'name ' => 'Pedro ' ,
256
+ 'country ' => 'El Salvador ' ,
257
+ ],
258
+ ];
259
+
260
+ $ sql = $ this ->db ->table ('user ' )
261
+ ->setData ($ userData )
262
+ ->getCompiledUpsert ();
263
+
264
+ $ pos =
strpos (
$ sql,
'[email protected] ' );
265
+ $ this ->assertTrue (($ pos !== false ));
266
+
267
+ $ pos =
strpos (
$ sql,
'[email protected] ' );
268
+ $ this ->assertTrue (($ pos !== false ));
269
+ }
270
+
245
271
public function testUpsertCauseConstraintError ()
246
272
{
247
273
$ userData = [
You can’t perform that action at this time.
0 commit comments