2

I'd like to know whether the TZQuery/TAConnection is capable to deal with the consecutive SQL statments and editing the database at the run time, that is :

ZQuery.Close;
ZQuery.SQL.Clear;
ZQuery.sql.add('select * from Table1');
ZQuery.Open;

ZQuery.FieldByName('First_Field').AsInteger := 5;
 /// I do my stuff here with Table1 here 

// I switch to another table 
ZQuery.Close;
ZQuery.SQL.Clear;
ZQuery.sql.add('select * from Table2');
ZQuery.Open;

ZQuery.FieldByName('First_Field_of_Table2').AsInteger := 12;

Any changes made at the run time in the database as shown wiwth above code are not reflected in the DBGrid and remains intact. I played around with many properties of TZConnection and TZQuery Components(auto commit, readCommited etc..) to get records to be showed up in datagrid but it was futile struggle.

Interestingly Every changes made to the database are applied exactly as I want it because I monitor it from FlameRobin and everything is fine, so there is not problem actually with database but instead the problem is with Datasource & DBGRid doesn't reflect the current condition of database.

Sonya Blade
  • 399
  • 7
  • 24
  • 1
    Just guessing, but it seems that you miss the ZQuery.Post (or Commit or whatever) and if the DBGrid does not reflect the changes automatically you may need to call some DBGrid.Refresh.. anyway you should be able to find out exactly what is going on and what is wrong using the debugger - as all the source codes you use are "open" – xmojmr Jul 16 '14 at 16:16
  • 2
    Calling `ZQuery.Refresh;` should update the view. @xmojmr, `DBGrid.Refresh` would just force the grid to repaint, which is not what is needed here I think. – TLama Jul 17 '14 at 08:24
  • Thank you both for the helping, there is ZQuery.Post method in the original code, probably I forgot to add it here. The real problem was that, I create a bunch of ZQuery-ZConnection components for visual representation, I also create only one indivdual query-connection pair to traverse all these ZQuery-ZConnection components as an iterator. Any changes made by iterator during traversal are not data-aware to the original ZQuery-ZConnections untiil you reset the connection. – Sonya Blade Jul 17 '14 at 09:43

1 Answers1

0

I have noticed the same behavior. I have updated my db from Lazarus and from PHP as well. Updates or inserts done from PHP are only visible after ZConnection Disconnect and Connect. Simple ZQuery Close and Open don't work. However when data is updated in Lazarus application Close and Open work.

Justin Le
  • 673
  • 1
  • 8
  • 24