Recent

Author Topic: SQLite DB read TBGrid while writing  (Read 4386 times)

phr0x

  • New Member
  • *
  • Posts: 20
SQLite DB read TBGrid while writing
« on: May 07, 2018, 03:09:18 pm »
Hey there,

I have a probably fairly simple issue, just don't know where to look for the solution that's why I am posting here.
First what I want to do:
I want to save data out of a constant stream I get via an USB connection. And while doing so I want to be able to have a look at the data with a TDBGrid Component and a Tchart Component.

I have no problem with saving the data coming in or displaying it as it is. My Problem is that I want to see my Data in the Grid while I am writing. Every time I write into the DB I open and close the TSQL.Query and that's what I think causes the issue. When I filter my DB to display the Results in the Grid and then afterwards continue writing into the DB the Data shown in the Grid just dissapears again. But I want to keep that data there to see it and use it in a chart and for calculation.
Can you guys pinpoint me in a direction where I can get a solution for this or do you maybe even have a solution already?

Short example:
Code: Pascal  [Select][+][-]
  1. //this is what I do on creating the form
  2. DBConnection.Connected := True;
  3. SQLTransaction1.Active := True;
  4. SQLQuery1.Open;
  5.  
  6. //this is the basics of the function I use to write into the DB
  7. SQLQuery1.SQL.Text := 'INSERT INTO db (sensor) values (:PH_val)';
  8. SQL.Query1.Params.ParamByName('PH_val').AsInteger := 2
  9. SQLQuery.ExecSQL;
  10. SQLTransaction1.Commit;
  11.  
  12. //this is the basics of the function I use to filter and display the valus in a grid
  13. SQLQuery1.SQL.Text := 'select * from db';
  14. SQLQuery1.Open;
  15. SQLQUery1.Applyupdates;
  16.  

Best Regards  :D

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite DB read TBGrid while writing
« Reply #1 on: May 07, 2018, 10:59:19 pm »
Why not use commitretain instead of commit? That updates your datbase without closing it.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

phr0x

  • New Member
  • *
  • Posts: 20
Re: SQLite DB read TBGrid while writing
« Reply #2 on: June 11, 2018, 08:32:24 pm »
Well, that solved it. Thank you very much.  :D

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite DB read TBGrid while writing
« Reply #3 on: June 12, 2018, 07:20:30 am »
You're welcome!  :D
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

 

TinyPortal © 2005-2018