Recent

Author Topic: Writing Data of Multiple StringGrid Data to SQLite3 Databases  (Read 2689 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Hi all

I have a GUI application that utilises various tabs (pages) and in each tab are one or more stringgrids. So there's a dozen or so of them. Each one has a different number of columns, and each one will have a different number of rows every time it is used to look at different data.

Several users have asked for the data in the stringgrids to be output to an SQLite database file.

I notice in Lazarus --> SQLDB tab --> TSQLite3Connection exists for such connectivity.

I am struggling a bit though (having never used database systems in programming) working out exactly where to start here. I get that I need an SQLite3Connection object adding to my form and then somehow I need to save the content of the stringgrids to the SQLite database. I assume a table would need to be created to represent and hold the data for each stringrid, and then somehow the content of each grid saved to the table in the SQLite DB.

I found this (http://forum.lazarus.freepascal.org/index.php?topic=28388.0) and this (http://forum.lazarus.freepascal.org/index.php?topic=27247.0) but due to some radactions of certain details and assumptions in the posts that make it specific to single fields or whatever, the step-by-step element is missing. 

So, assuming 3 x stringgrids where one has 4 columns with 100 rows, the other has 10 columns with a thousand rows and the other has 6 columsn with 500 rows, and one TSQL3Connection property, where does one go from there? I assume the steps are : Create DB --> Connect to DB --> Write new tables to DB --> Write content of grids to DB tables --> Commit --> Disconnect. But I'm not sure how to achieve those, or where the guides are to show an example of doing that.

Lastly, AFAIK, there is no StringGrid1.SaveToSQLiteDB or equivalent. And, I am curious to know how much better\easier it may be to convert all my stringgrids to DBGrids (Data Controls --> DBGrids). Would it be as easy as Find & Replace for all my stringgrids and change to the name of a DBGrid? Or is the way the data inserted very different?

Greatful for any wisdom.

Thanks

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Writing Data of Multiple StringGrid Data to SQLite3 Databases
« Reply #1 on: May 10, 2016, 09:06:22 am »
You don't use a persistent framework like tiOPF or MmORMot, it's better to you use TDBGrid instead of TStringGrid. TDBGrid is related to a dataset (dataset -> datasource -> DBGrid). It's build your grid underwater with filling data.

Take a look at this wiki page, SQLlite page and SQLdb tutorial pages
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018