Recent

Author Topic: SQLite3 Relational bases  (Read 15004 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 533
SQLite3 Relational bases
« on: December 16, 2021, 09:21:17 pm »
Hello, where can I find an example of a SQLite relational database written in lazarus?

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: SQLite3 Relational bases
« Reply #1 on: December 17, 2021, 08:21:23 am »
Is something unclear with https://wiki.freepascal.org/SQLite , https://wiki.freepascal.org/TSqlite3_Master_Detail_Example and some more site ? found with searchin on google with lazarus wiki sqlite

and in the wiki is a tutorial https://wiki.freepascal.org/SQLdb_Tutorial1
« Last Edit: December 17, 2021, 08:23:26 am by af0815 »
regards
Andreas

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SQLite3 Relational bases
« Reply #2 on: December 18, 2021, 11:30:26 am »
Do I need to duplicate components when creating a relational database?

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #3 on: December 18, 2021, 05:29:33 pm »
What components are you talking about?
Normally for databases you need one connection, one transaction and one or more queries per table in that database.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SQLite3 Relational bases
« Reply #4 on: December 19, 2021, 01:06:15 pm »
How do I build a SELECT query to display the entire contents of both tables?

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #5 on: December 19, 2021, 03:06:24 pm »
Something like SELECT * FROM table2 WHERE field1 = table1.field1
Not sure what you want exactly but I think the SQL JOIN is what you are looking for.
I advise you to visit W3schools website https://www.w3schools.com/sql/, they have tutorials for almost anything you can do with SQL.
« Last Edit: December 19, 2021, 03:11:13 pm by JanRoza »
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SQLite3 Relational bases
« Reply #6 on: December 19, 2021, 04:09:29 pm »
I want to combine these two queries
Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Text := 'SELECT * FROM table';
  2. SQLQuery2.SQL.Text := 'SELECT * FROM table_1 WHERE table_1.Col_id = :id';
  3.  
« Last Edit: December 19, 2021, 04:19:08 pm by Pe3s »

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #7 on: December 19, 2021, 04:56:08 pm »
Like I already mentioned, check out the SQL JOIN statement.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

balazsszekely

  • Guest
Re: SQLite3 Relational bases
« Reply #8 on: December 19, 2021, 05:04:48 pm »
@Pe3s
Quote
Like I already mentioned, check out the SQL JOIN statement.

Take a look at the union command, column count from table and table_1 must be the same. A better approach would be something like this:
Code: MySQL  [Select][+][-]
  1.   SQLQuery1.SQL.Text := 'select tb.id, tb.firstname, tb.lastname, tb.salary from table tb' +
  2.                         'union ' +
  3.                         'select tb_1.id, tb_1.firstname, tb_1.lastname, tb_1.salary from table_1 tb_1 where tb_1.id = :id';        
  4.  
« Last Edit: December 19, 2021, 05:07:36 pm by GetMem »

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #9 on: December 19, 2021, 06:49:18 pm »
Thanks GetMem, even better.  ;D
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SQLite3 Relational bases
« Reply #10 on: December 21, 2021, 10:44:53 am »
Thank you  ;D

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SQLite3 Relational bases
« Reply #11 on: December 21, 2021, 10:48:58 am »
I still have a question, how can we update the data in the table, e.g. after deleting the record, we are alive select or can we refresh the view differently?

paweld

  • Hero Member
  • *****
  • Posts: 1003
Re: SQLite3 Relational bases
« Reply #12 on: December 21, 2021, 11:49:24 am »
Code: Pascal  [Select][+][-]
  1. SQLQuery1.Refresh;
Best regards / Pozdrawiam
paweld

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SQLite3 Relational bases
« Reply #13 on: December 21, 2021, 04:53:57 pm »
Why is SQLQuery1.Refresh; causes an error Operation cannot be performed on an inactive dataset.

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #14 on: December 21, 2021, 05:22:31 pm »
I think you will have to show some code of how you delete and then refresh your table.
Now we can only guess.
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