Code: Select all
CREATE TABLE `temp` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`f` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf16;
And then:
Code: Select all
ZQuery1.SQL.Text('SELECT * FROM TEMP');
ZQuery1.Open;
ZQuery1.CachedUpdates := True;
Try
ZConnection1.StartTransaction;
ZQuery1.Edit;
ZQuery1.FieldByName('f').AsInteger := Random(100000);
ZQuery1.Post;
If ZQUery1.UpdatesPending Then ZQuery1.ApplyUpdates;
ZConnection1.Commit;
Finally
ZQuery1.CachedUpdates := False;
End;
"Project Project1.exe raised exception class EZSQLException with message '0 record(s) updated. Only one record should have been updated.'."
during setting cachedupdates to false.
SQLMonitor results:
'2020-06-05 16:06:06' cat: Execute, proto: mysql, msg: Native SetAutoCommit False call <- ZConnection1.StartTransaction
'2020-06-05 16:06:06' cat: Prepare, proto: mysql, msg: Statement 6 : SHOW KEYS FROM personal.temp
'2020-06-05 16:06:06' cat: Execute, proto: mysql, msg: Statement 6 : SHOW KEYS FROM personal.temp
'2020-06-05 16:06:06' cat: Prepare, proto: mysql, msg: Statement 7 : UPDATE personal.temp SET f=? WHERE `ID`=?
'2020-06-05 16:06:06' cat: Bind prepared, proto: mysql, msg: Statement 7 : 455,4
'2020-06-05 16:06:06' cat: Execute, proto: mysql, msg: Statement 7 : UPDATE personal.temp SET f=? WHERE `ID`=? <- ZQuery1.ApplyUpdates
'2020-06-05 16:06:06' cat: Execute, proto: mysql, msg: Native Commit call <- ZConnection1.Commit
'2020-06-05 16:06:06' cat: Bind prepared, proto: mysql, msg: Statement 7 : 455,4
'2020-06-05 16:06:06' cat: Execute, proto: mysql, msg: Statement 7 : UPDATE personal.temp SET f=? WHERE `ID`=? <- ZQuery1.CachedUpdates := False;
Stack trace is:
ZAbstractDataSet.TZAbstractDataSet.SetCachedUpdates(False);
ZDbcCachedResultSet.TZAbstractCachedResultSet.SetCachedUpdates(False);
ZDbcCachedResultSet.TZAbstractCachedResultSet.PostUpdates;
ZDbcCachedResultSet.TZAbstractCachedResultSet.PostRowUpdates;
ZDbcMySqlResultSet.TZMySQLCachedResolver.PostUpdates;
ZDbcGenericResolver.TZGenerateSQLCachedResolver.PostUpdates;
I attempted to modify the following:
Code: Select all
procedure TZAbstractCachedResultSet.SetCachedUpdates(Value: Boolean);
begin
if FCachedUpdates <> Value then
begin
FCachedUpdates := Value;
if not FCachedUpdates And Self.IsPendingUpdates then
PostUpdates;
end;
end;