Can't get DBGrid to update MySQL via ZQuery

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
svtdoug
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 05.11.2021, 01:58

Can't get DBGrid to update MySQL via ZQuery

Post by svtdoug »

I've run into a problem with DBGrid and ZQuery. I'm running Delphi 10.4.2. I have an application using TDBGrid, TDataSource, TZQuery, and TZConnection using a MySQL 8.0 DB. All works great, except I can't get changes made through the DBGrid to update the DB. I have another routine in code which inserts new records to the DB fine using the ZQuery and SQL text, but I also need to be able to edit records with the DBGrid.

Nothing is set to Read Only in the DBGrid or any of its column properties. I even tried setting a TDBEdit control on the form and trying to update one column in the db via it, and it fails. No error messages, the DB just does not get the update. I also added a TDBNavigator control, and using its commit button, and that does not work to update the DB.

Also of note, I can do a refresh of the ZQuery in code:

zquery1.Active:= False;
zquery1.SQL.Clear;
zquery1.SQL.Text:= 'Select * From mydata';
zquery1.ExecSQL;
zquery1.Active:= True;

and the updates from the DBGrid data are still there. So its like the ZQuery is remembering the changes, but they are not getting committed to the MySQL server.

With the above code, if I kill the ZConnection first, then reconnect, the data in the DBGrid reverts back to pre-edit conditions.

Any hints on how to get the DBGrid or DBEdit to post changes would be appreciated!

Thanks,
Doug

//Edit
I put the ZSQLMonitor on the form and wrote to a file. This is what is recorded when I edit a cell in the DBgrid and move to another cell.

"2021-11-21 18:29:44 cat: Prepare, proto: mysql-5, msg: Statement 7 : SHOW KEYS FROM exercisetracker.commlog
2021-11-21 18:29:44 cat: Execute prepared, proto: mysql-5, msg: Statement 7
2021-11-21 18:29:44 cat: Prepare, proto: mysql-5, msg: Statement 8 : UPDATE exercisetracker.commlog SET `RecNo`=?,`Op`=?,`Date`=?,`Time`=?,`ReporterCall`=?,`ReporterName`=?,`BlockTeam`=?,`Receiver`=?,`IncidNum`=?,`Resolved`=?,`What`=?,`WhereField`=?,`Status`=?,`Resolution`=?,`ResolvedTime`=? WHERE `RecNo`=? AND `Date`=? AND `Time`=? AND `ReporterCall`=? AND `BlockTeam`=? AND `Receiver`=? AND `IncidNum`=?
2021-11-21 18:29:44 cat: Execute prepared, proto: mysql-5, msg: Statement 8"

I don't know what to make of that...

Doug
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 787
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Can't get DBGrid to update MySQL via ZQuery

Post by aehimself »

What is the transaction isolation set to on your ZConnection component?
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Can't get DBGrid to update MySQL via ZQuery

Post by marsupilami »

Did you possibly disable autocommit on the TZConnection?
svtdoug
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 05.11.2021, 01:58

Re: Can't get DBGrid to update MySQL via ZQuery

Post by svtdoug »

Thanks for the replies!

AE - Transaction isolation on the ZConnection is set to none - I presume the default.

marsupilami - AutoCommit was set to false! Setting it to True, now the grid updates the DB! Phew! Thanks so much! Must have clicked that off in testing, trying to click on something else. Another lesson learned! I figured it was something simple, one little switch.

Working really well now!

Many thanks.
Doug
Post Reply