Recent

Author Topic: Master Detail with SQlite3  (Read 4948 times)

folkeu08

  • New Member
  • *
  • Posts: 47
Master Detail with SQlite3
« on: July 09, 2021, 11:36:39 am »
Good morning all,
I started from an example of Master / Detail tables under SQLite3.
I don't want to use the DBNavigator component to manage the records of my tables.
I would like to replace it with 3 simple buttons: Add, Edit and delete.
It works great for the Master table.
I used the same method for the detail table but I get an error message when I want to add a city in record. It cannot find the City_mane field in the SQLQuery1 which corresponds to the master (countries) table or this field is in the Detail (Cities) table.
By forcing the recorder, the recording starts again and goes well. The new city attached to the country appears in the grid.
I attach my source to you, there may be something that escapes me.
Thank you
Francois

devEric69

  • Hero Member
  • *****
  • Posts: 559
Re: Master Detail with SQlite3
« Reply #1 on: July 09, 2021, 03:23:57 pm »
I don't want to use the DBNavigator component to manage the records of my tables.
I would like to replace it with 3 simple buttons: Add, Edit and delete.

Hello, (just for information, to be sure) did you know that you can make certain DBNavigator's buttons invisible?
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

folkeu08

  • New Member
  • *
  • Posts: 47
Re: Master Detail with SQlite3
« Reply #2 on: July 09, 2021, 03:56:10 pm »
Yes but I just left the DBnavigator as in the original source of the example.
I don't want to use them at all.
François

wp

  • Hero Member
  • *****
  • Posts: 8732
Re: Master Detail with SQlite3
« Reply #3 on: July 09, 2021, 05:30:02 pm »
Then remove it. What's the problem?

Add your three buttons. Add a TActionList. Add these standard actions to the Actionlist: TDatasetEdit, TDatasetDelete, TDatasetInsert (or whatever you need); link the actions to your dataset. Put the actions into the Action property of the buttons - done.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

folkeu08

  • New Member
  • *
  • Posts: 47
Re: Master Detail with SQlite3
« Reply #4 on: July 09, 2021, 05:54:10 pm »
This is what I did indirectly with my 3 buttons.
It is the addition of a row in the detail table that goes wrong. I can't find the problem.
« Last Edit: July 09, 2021, 06:09:32 pm by folkeu08 »

wp

  • Hero Member
  • *****
  • Posts: 8732
Re: Master Detail with SQlite3
« Reply #5 on: July 09, 2021, 08:55:38 pm »
http://www.festra.com/fp/sqlite04.htm contains two master-detail tables with sqlite3. In the attachment there is a modified version in which I removed the dbNavigator of the detail table and replaced its functionality by five buttons (Insert, Edit, Delete, Post, Cancel) which use standard actions as I described above. -- It is working correctly.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

folkeu08

  • New Member
  • *
  • Posts: 47
Re: Master Detail with SQlite3
« Reply #6 on: July 09, 2021, 10:28:13 pm »
Thanks for your attention wp. What you propose, I know how to do.
What I'm having trouble with in my attached source:
- By clicking on the button for adding data in the detail table, it opens a modal window containing non-DB fields.
 - in this modal window, by clicking this time on the record button, the data contained in the simple fields must be recorded in the table.
When this registered button is clicked, I am told that the "City_name" field does not exist in the master table. This is normal since it is present in the detail table.
This stops the registration process.
Thanks
« Last Edit: July 13, 2021, 04:42:25 pm by folkeu08 »

Zvoni

  • Hero Member
  • *****
  • Posts: 683
Re: Master Detail with SQlite3
« Reply #7 on: July 12, 2021, 08:54:40 am »
Is it "city-mane" or "city_name"?
« Last Edit: July 12, 2021, 09:20:22 am by Zvoni »
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

folkeu08

  • New Member
  • *
  • Posts: 47
Re: Master Detail with SQlite3
« Reply #8 on: July 13, 2021, 04:43:08 pm »
Hi,
It's "city_name".
Thanks

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1031
Re: Master Detail with SQlite3
« Reply #9 on: July 13, 2021, 05:13:27 pm »
hello folkeu08,
have you try what i have suggested in the french lazarus forum here.
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

folkeu08

  • New Member
  • *
  • Posts: 47
Re: Master Detail with SQlite3
« Reply #10 on: July 13, 2021, 06:59:00 pm »
Hi Jurassic Pork,
Yes, I have try it but not on the SQLquery2.
I close the SQLQuery1 and it search not the "City_Mane" field.
I must modifie the rest of the code to open after the SQLQuery1 for view the two grid.
I will resubmit my code afterwards because I am not sure that it is "clean" as it says in the middle. I am an amateur!
François


 

TinyPortal © 2005-2018