how to refresh FIBL after insert or update? lazarus / 16-Databases ---------------------------------------------------------------------- researcher · 2009-05-22 21:55 We're moving everything in our research project nicely from Windows over to Linux with Lazarus. SQLdb had a few glitches with Locate, so we tried FIBL (Sergey Smirnov's port of FreeIB by Greg Deatz) which didn't have those glitches, but it's not obvious how to refresh the dataset after inserts or updates (which are successful). Closing and opening the FIBDataSet does not display the new data. Closing FIBTransaction and reopening it just crashes the app consistently.  What is the correct way to do that with FIBL? Thanks! ---------------------------------------------------------------------- clauslack · 2009-05-23 18:00 As Firebird use transactions, to "refresh" a DBGrid. In the query of the DBGrid. query.commit query.StartTransaction      //appear the new transactions of the insert-update Works fine with TIBConnection and Flamerobin (using IBPP library) ---------------------------------------------------------------------- researcher · 2009-05-24 12:31 Thanks Clauslack, We are using FIBDataSet to display the entire data and to allow scrolling. The insert and update are done with a separate FIBQuery. I tried setting autocommit and autostarttransaction but this did not change the behaviour. The update does work, but we have to close the app and restart it to see the new data. The code below shows how we disengaged the DBGrid.DataSource and added a MessageDlg. This seems to successfully post, commit and then allow display the new data - but this is clearly not the correct way to do it... Even adding a long sleep without the messagedlg seems to work. Is this a glitch of the DBGrid? Has anyone used FIBL to update and view the new data immediately?   DBGrid1.DataSource := nil;   if messagedlg('continue',mtconfirmation,[mbok],0) = mrok then     begin       sleep(800);       FIBDataSet1.Active := False;       FIBTransaction1.Active := False;       FIBTransaction1.Active := True;       FIBDataSet1.Active := True;       FIBDataSet1.First;       FIBDataSet1.Last;       FIBDataSet1.First;       FIBDataSet1.Locate('idnum',currentidnum,[]);       sleep(800);     end;   DBGrid1.DataSource := DataSource1; ----------------------------- We are also trying another method from the FIBL documentation that comes with the source. This method uses the same FIBDataSet for select, update and insert. This method seems to refresh the dataset without problems, but it does not update. Anyone have similar experience?   FIBDataSet1.QUpdate.Params.ByName['notes'].AsString := EditNoteComment1.text;   FIBDataSet1.QUpdate.ExecQuery;   FIBDataSet1.ApplyUpdates;   FIBDataSet1.QRefresh.Params.ByName['idnum'].asInteger := currentidnum;   FIBDataSet1.Refresh; -------------------------- ---------------------------------------------------------------------- clauslack · 2009-05-24 15:51 Well Here you have an example for refresh after "update-insert". Please give me your email to send you the full source. Works fine for me. procedure TForm1.Button1Click(Sender: TObject); begin            //select with FIBDataSet1 in DBGrid    if not FIBDatabase1.Connected then FIBDatabase1.Open;     if FIBTransaction1.Active then FIBTransaction1.Commit;     FIBDataSet1.Close;     FIBDataSet1.SelectSQL.clear;     FIBDataSet1.SelectSQL.AddStrings(memo1.lines);     FIBTransaction1.StartTransaction;     FIBDataSet1.Open; end; procedure TForm1.Button2Click(Sender: TObject); begin    //insert-update with FIBQuery1     if not FIBDatabase1.Connected then FIBDatabase1.Open;     FIBQuery1.close;     FIBQuery1.SQL.clear;     FIBQuery1.SQL.AddStrings(memo2.lines);     FIBTransaction2.StartTransaction;     FIBQuery1.ExecQuery;     FIBTransaction2.Commit;     Button1Click(Sender);   //refresh the DBGrid end;                    Regards clauslack@gmail.com ---------------------------------------------------------------------- Loesje · 2009-05-25 20:14 Quote from: researcher on May 22, 2009, 11:55:30 pmSQLdb had a few glitches with Locate, so we tried FIBL (Sergey Smirnov's port of FreeIB by Greg Deatz) which didn't have those glitches, but it's not obvious how to refresh the dataset after inserts or updates (which are successful). What glitches? I don't know of any? ---------------------------------------------------------------------- researcher · 2009-05-27 14:01 The SQLdb glitch was with Locate. After inserting or updating a record, we wanted to go to that record using a key field, but the DBGrid just froze up, then after a click, allowed some movement, but to a different record, then froze again. Tried to make it work many times before we installed FIBL. Have you done that successfully? What is the standard procedure? Can we add these standard procedures as beginning examples "for getting started " to the Lazarus Documentation? ---------------------------------------------------------------------- researcher · 2009-06-01 18:44 Thanks Clauslack, That code sample helped find the right sequence. Now the DBGrid can refresh very nicely and the locate works, so it all is in good usable shape, .... except ... the app seems to crash when - the app is open, and we switch to a text editor to pick up data, then switch back to the application then input the data - then it inserts correctly, then crashes!  upon restarting, the data is there! (is this a DBGrid thing, a DataSource change thing?) I'm still exploring this funny behaviour, but the grid does refresh and the app is accepting data, so Thanks! ---------------------------------------------------------------------- clauslack · 2009-06-01 19:35 I have this code in my home I will send you for e-mail the complete project, because is not normal so many crash. But be careful, Version 0.7.3 released in 2007-10-23, is too old, may be it have some bugs. ---------------------------------------------------------------------- clauslack · 2009-06-02 22:56 I upload the full project example_fib_refresh.zip Tested with Lazarus 0.9.27 svn 20212 fpc 2.2.4 Windows XP SP3 requires fib 0.7.3. Firebird database for test. Regards ---------------------------------------------------------------------- Loesje · 2009-06-07 13:13 Can you create a bug-report for the problems you have with TSQLQuery.Locate? ---------------------------------------------------------------------- clauslack · 2009-06-09 03:29 Loesje I created a bug-report about TDataset.Locate ****** Locate don't raise an error in a closed TDataset, just return false. http://bugs.freepascal.org/view.php?id=13938 Regards