@@ -1312,6 +1312,12 @@ private function bulkInsert($attributes)
13121312 ', ' ,
13131313 array_map (
13141314 function ($ value ) {
1315+
1316+ if (\is_null ($ value )) {
1317+ return 'NULL ' ;
1318+ }
1319+
1320+
13151321 $ this ->bindings [] = $ value ;
13161322
13171323 return $ this ->getValueType ($ value );
@@ -1453,7 +1459,9 @@ private function prepareAttributeForSaveOrUpdate($isUpdate = false)
14531459 $ this ->bindings [] = \is_array ($ this ->_model ->{$ column })
14541460 || \is_object ($ this ->_model ->{$ column })
14551461 ? wp_json_encode ($ this ->_model ->{$ column }) : $ this ->_model ->{$ column };
1456- } else {
1462+ } elseif (\is_null ($ this ->_model ->{$ column })) {
1463+ $ this ->bindings [] = null ;
1464+ }else {
14571465 $ this ->bindings [] = '' ;
14581466 }
14591467 }
@@ -1497,10 +1505,17 @@ private function prepareInsert()
14971505 . implode (
14981506 ', ' ,
14991507 array_map (
1500- function ($ value ) {
1508+ function ($ value , $ key ) {
1509+ if (\is_null ($ value )) {
1510+ unset($ this ->bindings [$ key ]);
1511+
1512+ return 'NULL ' ;
1513+ }
1514+
15011515 return $ this ->getValueType ($ value );
15021516 },
1503- $ this ->bindings
1517+ $ this ->bindings ,
1518+ array_keys ($ this ->bindings )
15041519 )
15051520 ) . ') ' ;
15061521
@@ -1519,7 +1534,15 @@ private function prepareUpdate()
15191534 $ sql .= ' SET ' ;
15201535 $ columnCount = \count ($ this ->update );
15211536 foreach ($ this ->update as $ key => $ column ) {
1522- $ sql .= $ column . ' = ' . $ this ->getValueType ($ this ->bindings [$ key ]);
1537+ // $sql .= $column . ' = ' . $this->getValueType($this->bindings[$key]);
1538+
1539+ if (\is_null ($ this ->bindings [$ key ])) {
1540+ $ sql .= $ column . ' = NULL ' ;
1541+ unset($ this ->bindings [$ key ]);
1542+ } else {
1543+ $ sql .= $ column . ' = ' . $ this ->getValueType ($ this ->bindings [$ key ]);
1544+ }
1545+
15231546 if ($ key < $ columnCount - 1 ) {
15241547 $ sql .= ', ' ;
15251548 }
0 commit comments