Recent

Author Topic: [?] Connecting SQLite Tables with Lazarus  (Read 602 times)

Picard

  • New Member
  • *
  • Posts: 21
[?] Connecting SQLite Tables with Lazarus
« on: June 12, 2019, 09:47:10 pm »
I've been trying to follow the Pascal and SQLite video tutorials on YouTube to build a database and connect it with Lazarus; however, when I get to the point of connecting individual tables to Lazarus there are no instructions and I don't know what to do.  The database that I created has about 7 tables and I need to connect to each one of them separately and access their data.  How can I do that?  Is the problem in the way I created the database or is it in the Pascal Manager utility's connection property? 

Here are the videos that have helped me so far.

SQLite Tutorial 5 : How to Import CSV or Excel file into SQLite database
https://www.youtube.com/watch?v=ebYMbi_0Www

Lazarus SQL database video tutorial
https://www.youtube.com/watch?v=pq2oCiJePHo&t=98s

JanRoza

  • Hero Member
  • *****
  • Posts: 535
    • http://www.silentwings.nl
Re: [?] Connecting SQLite Tables with Lazarus
« Reply #1 on: June 12, 2019, 11:26:47 pm »
If you want to do it in a neat way: first create a datamodule, and on that datamodule form create a connection (TSQLiteConnection) to the database and a transaction (TSQLTransaction). Now for each table from that database create a query (TSQLQuery).
In the query select the connection to the database as the database property and in the SQL property click on the button behind it and fill in a SQL select statement like 'SELECT * FROM <tabele name>'.
That's it.
OS: Windows 10 (64 bit) / Ubuntu 19.04 (64 bit)
Laz: Lazarus 2.0.4 FPC 3.0.4 i386-win32-win32/win64

Picard

  • New Member
  • *
  • Posts: 21
Re: [?] Connecting SQLite Tables with Lazarus
« Reply #2 on: June 14, 2019, 02:59:43 am »
So in order to connect the database that I made with SQLite, I should use TSQLiteConnection, SQLTransaction and TSQLQuery.  Then in the TSQLQuery I use 'SELECT * FROM <tabele name>'.  Is this what you are suggesting?  What does the "T" in TSQLite mean?

JanRoza

  • Hero Member
  • *****
  • Posts: 535
    • http://www.silentwings.nl
Re: [?] Connecting SQLite Tables with Lazarus
« Reply #3 on: June 14, 2019, 02:02:59 pm »
Yes, that's what I mean.
OS: Windows 10 (64 bit) / Ubuntu 19.04 (64 bit)
Laz: Lazarus 2.0.4 FPC 3.0.4 i386-win32-win32/win64

howardpc

  • Hero Member
  • *****
  • Posts: 3177
Re: [?] Connecting SQLite Tables with Lazarus
« Reply #4 on: June 14, 2019, 02:59:47 pm »
What does the "T" in TSQLite mean?
The widespread convention of naming class types beginning with a capital "T" indicates that the word is a Type name, as opposed to the name of a variable or other identifier. Presumably the T is short for Type.

egsuh

  • Full Member
  • ***
  • Posts: 241
Re: [?] Connecting SQLite Tables with Lazarus
« Reply #5 on: June 17, 2019, 02:34:25 pm »
Simpler way is to use TSqlite3DataSet.
You assign the sqlite file name,  and then you may either assign table name or write the SQL statement (for example, "select * from table1"). Both will give you the same result. Then you can connect it to any visual control like TDBGrid, etc. through datasource.