@@ -784,6 +784,24 @@ protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
784
784
}
785
785
}
786
786
787
+ /**
788
+ * Check if column data type is numeric
789
+ *
790
+ * Based on column description
791
+ *
792
+ * @param array $columnDescription
793
+ * @return bool
794
+ */
795
+ private function isNumericValue (array $ columnDescription ): bool
796
+ {
797
+ $ result = true ;
798
+ if (!empty ($ columnDescription ['DATA_TYPE ' ])
799
+ && in_array ($ columnDescription ['DATA_TYPE ' ], ['tinyint ' , 'smallint ' , 'mediumint ' , 'int ' , 'bigint ' ])) {
800
+ $ result = false ;
801
+ }
802
+ return $ result ;
803
+ }
804
+
787
805
/**
788
806
* Update existing object
789
807
*
@@ -793,29 +811,35 @@ protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
793
811
*/
794
812
protected function updateObject (\Magento \Framework \Model \AbstractModel $ object )
795
813
{
796
- $ condition = $ this ->getConnection ()->quoteInto ($ this ->getIdFieldName () . '=? ' , $ object ->getId ());
814
+ $ connection = $ this ->getConnection ();
815
+ $ tableDescription = $ connection ->describeTable ($ this ->getMainTable ());
816
+ $ preparedValue = $ connection ->prepareColumnValue ($ tableDescription [$ this ->getIdFieldName ()], $ object ->getId ());
817
+ $ condition = (!$ this ->isNumericValue ($ tableDescription [$ this ->getIdFieldName ()]))
818
+ ? sprintf ('%s=%d ' , $ this ->getIdFieldName (), $ preparedValue )
819
+ : $ connection ->quoteInto ($ this ->getIdFieldName () . '=? ' , $ preparedValue );
820
+
797
821
/**
798
822
* Not auto increment primary key support
799
823
*/
800
824
if ($ this ->_isPkAutoIncrement ) {
801
825
$ data = $ this ->prepareDataForUpdate ($ object );
802
826
if (!empty ($ data )) {
803
- $ this -> getConnection () ->update ($ this ->getMainTable (), $ data , $ condition );
827
+ $ connection ->update ($ this ->getMainTable (), $ data , $ condition );
804
828
}
805
829
} else {
806
- $ select = $ this -> getConnection () ->select ()->from (
830
+ $ select = $ connection ->select ()->from (
807
831
$ this ->getMainTable (),
808
832
[$ this ->getIdFieldName ()]
809
833
)->where (
810
834
$ condition
811
835
);
812
- if ($ this -> getConnection () ->fetchOne ($ select ) !== false ) {
836
+ if ($ connection ->fetchOne ($ select ) !== false ) {
813
837
$ data = $ this ->prepareDataForUpdate ($ object );
814
838
if (!empty ($ data )) {
815
- $ this -> getConnection () ->update ($ this ->getMainTable (), $ data , $ condition );
839
+ $ connection ->update ($ this ->getMainTable (), $ data , $ condition );
816
840
}
817
841
} else {
818
- $ this -> getConnection () ->insert (
842
+ $ connection ->insert (
819
843
$ this ->getMainTable (),
820
844
$ this ->_prepareDataForSave ($ object )
821
845
);
0 commit comments