@@ -352,11 +352,9 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
352
352
", \n" ,
353
353
array_map (
354
354
static function ($ key , $ value ) use ($ table , $ alias , $ that ) {
355
- $ fieldName = trim ($ key , '" ' );
356
-
357
355
return $ key . ($ value instanceof RawSql ?
358
356
' = ' . $ value :
359
- ' = ' . $ alias . '. ' . $ that ->castValue ( $ table , $ key , $ value ));
357
+ ' = ' . $ alias . '. ' . $ that ->cast ( $ value , $ that -> getFieldType ( $ table , $ key ) ));
360
358
},
361
359
array_keys ($ updateFields ),
362
360
$ updateFields
@@ -379,7 +377,7 @@ static function ($key, $value) use ($table, $alias, $that) {
379
377
return $ value ;
380
378
}
381
379
382
- return $ table . '. ' . $ value . ' = ' . $ alias . '. ' . $ that ->castValue ( $ table , $ value , $ value );
380
+ return $ table . '. ' . $ value . ' = ' . $ alias . '. ' . $ that ->cast ( $ value , $ that -> getFieldType ( $ table , $ value) );
383
381
},
384
382
array_keys ($ constraints ),
385
383
$ constraints
@@ -409,39 +407,36 @@ static function ($key, $value) use ($table, $alias, $that) {
409
407
}
410
408
411
409
/**
412
- * Returns cast value.
410
+ * Returns cast expression.
411
+ *
412
+ * @TODO move this to BaseBuilder in 4.5.0
413
413
*
414
- * @param string $table Protected Table name.
415
- * @param string $fieldName Field name. May be protected.
416
- * @param float|int|string $value Escaped value
414
+ * @param float|int|string $expression
417
415
*/
418
- private function castValue ( string $ table , string $ fieldName , $ value ): string
416
+ private function cast ( $ expression , ? string $ type ): string
419
417
{
420
- $ fieldName = trim ($ fieldName , $ this ->db ->escapeChar );
421
-
422
- if (! isset ($ this ->QBOptions ['fieldTypes ' ][$ table ])) {
423
- $ this ->getFieldTypes ($ table );
424
- }
425
-
426
- $ type = $ this ->QBOptions ['fieldTypes ' ][$ table ][$ fieldName ] ?? null ;
427
-
428
- return ($ type === null ) ? $ value : $ value . ':: ' . strtoupper ($ type );
418
+ return ($ type === null ) ? $ expression : $ expression . ':: ' . strtoupper ($ type );
429
419
}
430
420
431
421
/**
432
- * Gets filed types from database meta data.
422
+ * Returns the filed type from database meta data.
433
423
*
434
- * @param string $table Protected Table name.
424
+ * @param string $table Protected table name.
425
+ * @param string $fieldName Field name. May be protected.
435
426
*/
436
- private function getFieldTypes (string $ table ): void
427
+ private function getFieldType (string $ table, string $ fieldName ): ? string
437
428
{
438
- $ types = [] ;
429
+ $ fieldName = trim ( $ fieldName , $ this -> db -> escapeChar ) ;
439
430
440
- foreach ($ this ->db ->getFieldData ($ table ) as $ field ) {
441
- $ types [$ field ->name ] = $ field ->type ;
431
+ if (! isset ($ this ->QBOptions ['fieldTypes ' ][$ table ])) {
432
+ $ this ->QBOptions ['fieldTypes ' ][$ table ] = [];
433
+
434
+ foreach ($ this ->db ->getFieldData ($ table ) as $ field ) {
435
+ $ this ->QBOptions ['fieldTypes ' ][$ table ][$ field ->name ] = $ field ->type ;
436
+ }
442
437
}
443
438
444
- $ this ->QBOptions ['fieldTypes ' ][$ table ] = $ types ;
439
+ return $ this ->QBOptions ['fieldTypes ' ][$ table ][ $ fieldName ] ?? null ;
445
440
}
446
441
447
442
/**
0 commit comments