Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-10

SQLite: Several foreign keys

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Usuario Anónimo

If I want to create a simple master/detail relationship of one-to-many, it is easy:

Tables and fields:

Contact: [u]Code[/u], Name <-- Master table
Phone: [u]Number[/u], Contact (Contact is a foreign key) <-- Detail table

Contact TDataSource properties:
- DataSet: ContactDataset
- Name: ContactDataSource

Contact TSqlite3Dataset properties:
- Name: ContactDataset
- TableName: Contact

Phone TDataSource properties:
- DataSet: PhoneDataset
- Name: PhoneDataSource

Contact TSqlite3Dataset properties:
- Name: PhoneDataset
- TableName: Phone
- IndexFieldNames: Contact
- MasterFields: Code
- MasterSource: ContactDataSource

But, if I want to create a master/detail relationship of one-to-many with several foreign keys, how I do it?

For example I want to create this relationship:

Contact: [u]Code[/u], Name <-- Master table
Company: [u]Code[/u], Name <-- Master table
Phone: [u]Number[/u], Contact, Company (Contact and Company are foreigns keys) <-- Detail table

How I do it?

Best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081013/448619f5/attachment.html

Reply by email

Luiz Americo Pereira Camara
to Usuario Anónimo
Usuario An?nimo wrote
If I want to create a simple master/detail relationship of one-to-many, it is easy:

[]

Show quoted text 12 lines
But, if I want to create a master/detail relationship of one-to-many with several foreign keys, how I do it? For example I want to create this relationship: Contact: [u]Code[/u], Name <-- Master table Company: [u]Code[/u], Name <-- Master table Phone: [u]Number[/u], Contact, Company (Contact and Company are foreigns keys) <-- Detail table How I do it?

What is the application design?
You will have a Contact grid and a Company grid in the same window sharing the same Phone table/grid?
Or you will have a window with Contact + Phone and other window with Company + Phone?

Luiz

Reply by email

Usuario Anónimo
to Luiz Americo Pereira Camara

I have three TDBGrids.

Phone has two foreigns keys: Contact and Company.

2008/10/15 Luiz Americo Pereira Camara

Show quoted text 32 lines
Usuario An?nimo wrote: > If I want to create a simple master/detail relationship of > one-to-many, it is easy: > [] > > But, if I want to create a master/detail relationship of one-to-many > with several foreign keys, how I do it? > > For example I want to create this relationship: > > Contact: [u]Code[/u], Name <-- Master table > Company: [u]Code[/u], Name <-- Master table > Phone: [u]Number[/u], Contact, Company (Contact and Company are > foreigns keys) <-- Detail table > > How I do it? What is the application design? You will have a Contact grid and a Company grid in the same window sharing the same Phone table/grid? Or you will have a window with Contact + Phone and other window with Company + Phone? Luiz _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081019/938eebf4/attachment.html

Reply by email

Luiz Americo Pereira Camara
to Usuario Anónimo
Usuario An?nimo wrote
I have three TDBGrids. Phone has two foreigns keys: Contact and Company.

The automatic master/source relationship provided by MasterSource property will not work in this case.
You will need to do manually.

- Clear the MasterSource/IndexFieldNames properties
- Create a procedure UpdatePhone and put

  PhoneDataset.Sql := 'Select * from PhoneTable where Contact = ' +
ContactDataset.FieldByName('IdField').AsString + ' And ' +
  'Company = ' + ContactDataset.FieldByName('IdField').AsString;
  PhoneDataset.Close;
  PhoneDataset.Open;

- Call UpdatePhone inside OnAfterScroll events of ContactDataset and CompanyDataset

Some refinement may be needed to handle corner cases (no contact etc)

Luiz

Reply by email