Sign in Join

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

Mailing lists / lazarus / 2008-12

SQLite: How to create lookup fields?

14 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

User

Hi, I have two TSQLite3Dataset components:

DatasetSales with the fields: Code, Item, Amount, Price, Vendor DatasetItems with the fields: Code, Description

I have a TDBGrid component that shows the data of DatasetSales.

I want to make a lookup field associated to the Item DatasetSales field to show the Code and Description DatasetItems fields.

I do it:

Code:

procedure TForm1.FormCreate(Sender: TObject);
begin
  with DatasetSales do
  begin
  Open;
  DatasetItems.Open;
  FieldByName('Item').FieldKind := fkLookup;
  FieldByName('Item').LookupDataSet := DatasetItems;
  FieldByName('Item').LookupKeyFields := 'Code; Description';
  FieldByName('Item').LookupResultField := 'Code';
  end;
end;

but nothing happen.

Why?

Thanks and Merry Christmas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081224/9ab40639/attachment.html

Reply by email

Luiz Americo Pereira Camara
to User
User wrote 30 lines
Hi, I have two TSQLite3Dataset components: DatasetSales with the fields: Code, Item, Amount, Price, Vendor DatasetItems with the fields: Code, Description I have a TDBGrid component that shows the data of DatasetSales. I want to make a lookup field associated to the Item DatasetSales field to show the Code and Description DatasetItems fields. I do it: Code: procedure TForm1.FormCreate(Sender: TObject); begin with DatasetSales do begin Open; DatasetItems.Open; FieldByName('Item').FieldKind := fkLookup; FieldByName('Item').LookupDataSet := DatasetItems; FieldByName('Item').LookupKeyFields := 'Code; Description'; FieldByName('Item').LookupResultField := 'Code'; end; end; but nothing happen. Why?

It's not implemented in TSqlite3Dataset. In fact i don't know in which layer (TDataset / TDataset descendant / TDbGrid) should be implemented.

It's up to TDataset descendants implement this?

Does some descendant already implemented ?

Luiz

Reply by email

Alexander Klenin
to Luiz Americo Pereira Camara
Show quoted text 13 lines
> I do it: > procedure TForm1.FormCreate(Sender: TObject); > begin > with DatasetSales do > begin > Open; > DatasetItems.Open; > FieldByName('Item').FieldKind := fkLookup; > FieldByName('Item').LookupDataSet := DatasetItems; > FieldByName('Item').LookupKeyFields := 'Code; Description'; > FieldByName('Item').LookupResultField := 'Code'; > end; > end;

1) You forgot to set KeyFields
(or, rather, FieldName -- it should be different form KeyFields or DBGrid might be confused)
2) You probably mixed up LookupKeyFields with LookupResultField
3) If you want the lookup field to be editable, you will need to use Lazarus version later then http://bugs.freepascal.org/view.php?id=12347 and to set LookupCache := true
4) Even after this, there is some problems in SQLdb which I did not yet found time
to diagnose and fix properly. They cause AVs while scrolling DBGrid.

Luiz Americo Pereira Camara wrote 6 lines
It's not implemented in TSqlite3Dataset. In fact i don't know in which layer (TDataset / TDataset descendant / TDbGrid) should be implemented. It's up to TDataset descendants implement this? Does some descendant already implemented ?

It seems to be implemented in SQLdb (TBufDataset). So, in addition to the above, original poster should indeed drop sqlitedataset. Perhaps TSQLite3Connection can be ised instead?

Alexander S. Klenin

Reply by email

Unknown author
4) Even after this, there is some problems in SQLdb which I did not yet found time to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find

Dont spend too much time in this SQLite3DataSet has a lot of Bugs. ill tryed to fix all for month before i used zeos

Show quoted text 17 lines
On Thu, Dec 25, 2008 at 12:08, Luiz Americo Pereira Camara wrote: > It's not implemented in TSqlite3Dataset. In fact i don't know in which > layer (TDataset / TDataset descendant / TDbGrid) should be implemented. > > It's up to TDataset descendants implement this? > > Does some descendant already implemented ? It seems to be implemented in SQLdb (TBufDataset). So, in addition to the above, original poster should indeed drop sqlitedataset. Perhaps TSQLite3Connection can be ised instead? -- Alexander S. Klenin _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Unknown author
4) Even after this, there is some problems in SQLdb which I did not yet found time to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find

Dont spend too much time in this SQLite3DataSet has a lot of Bugs. ill tryed to fix all for month before i used zeos

Show quoted text 17 lines
On Thu, Dec 25, 2008 at 12:08, Luiz Americo Pereira Camara wrote: > It's not implemented in TSqlite3Dataset. In fact i don't know in which > layer (TDataset / TDataset descendant / TDbGrid) should be implemented. > > It's up to TDataset descendants implement this? > > Does some descendant already implemented ? It seems to be implemented in SQLdb (TBufDataset). So, in addition to the above, original poster should indeed drop sqlitedataset. Perhaps TSQLite3Connection can be ised instead? -- Alexander S. Klenin _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

User
to Alexander Klenin: 1) You forgot to set KeyFields (or, rather, FieldName -- it should be different form…

Hi again, my TSQLite3Dataset components:

DatasetSales with the fields: Code, Item, Amount, Price, Vendor DatasetItems with the fields: Code, Description

I do not want that the lookup field to be editable.

My new code:

procedure TForm1.FormCreate(Sender: TObject);
var
  TempField: TStringField;
begin
  DatasetSales.Active := true;
  TempField := TStringField.Create(DatasetSales);
  with TempField do
    begin
      FieldName := 'New field';
      Lookup := True;
      FieldKind := fkLookup;
      KeyFields := 'Item';
      LookupDataSet := DatasetItems;
      LookupKeyFields := 'Code';
      LookupResultField := 'Description';
      DatasetSales := Self.DatasetSales;
    end;
end;

but nothing happen. Why?

2008/12/25 Alexander Klenin :

Show quoted text 45 lines
>> I do it: >> procedure TForm1.FormCreate(Sender: TObject); >> begin >> with DatasetSales do >> begin >> Open; >> DatasetItems.Open; >> FieldByName('Item').FieldKind := fkLookup; >> FieldByName('Item').LookupDataSet := DatasetItems; >> FieldByName('Item').LookupKeyFields := 'Code; Description'; >> FieldByName('Item').LookupResultField := 'Code'; >> end; >> end; 1) You forgot to set KeyFields (or, rather, FieldName -- it should be different form KeyFields or DBGrid might be confused) 2) You probably mixed up LookupKeyFields with LookupResultField 3) If you want the lookup field to be editable, you will need to use Lazarus version later then http://bugs.freepascal.org/view.php?id=12347 and to set LookupCache := true 4) Even after this, there is some problems in SQLdb which I did not yet found time to diagnose and fix properly. They cause AVs while scrolling DBGrid. On Thu, Dec 25, 2008 at 12:08, Luiz Americo Pereira Camara wrote: > It's not implemented in TSqlite3Dataset. In fact i don't know in which > layer (TDataset / TDataset descendant / TDbGrid) should be implemented. > > It's up to TDataset descendants implement this? > > Does some descendant already implemented ? It seems to be implemented in SQLdb (TBufDataset). So, in addition to the above, original poster should indeed drop sqlitedataset. Perhaps TSQLite3Connection can be ised instead? -- Alexander S. Klenin _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Luiz Americo Pereira Camara
to Unknown author: Dont spend too much time in this SQLite3DataSet has a lot of Bugs. ill tryed to fix all…
Show quoted text 9 lines
> 4) Even after this, there is some problems in SQLdb which I did not > yet found time > to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find > Dont spend too much time in this SQLite3DataSet has a lot of Bugs. ill tryed to fix all for month before i used zeos

Can you point what bugs? Maybe you can report them.

All reported bugs, that are inherently to Sqlite3Dataset and doable of reproduction where fixed.

Luiz

Reply by email

Luiz Americo Pereira Camara
to User: Hi again, my TSQLite3Dataset components: DatasetSales with the fields: Code, Item,…
User wrote 30 lines
Hi again, my TSQLite3Dataset components: DatasetSales with the fields: Code, Item, Amount, Price, Vendor DatasetItems with the fields: Code, Description I do not want that the lookup field to be editable. My new code: procedure TForm1.FormCreate(Sender: TObject); var TempField: TStringField; begin DatasetSales.Active := true; TempField := TStringField.Create(DatasetSales); with TempField do begin FieldName := 'New field'; Lookup := True; FieldKind := fkLookup; KeyFields := 'Item'; LookupDataSet := DatasetItems; LookupKeyFields := 'Code'; LookupResultField := 'Description'; DatasetSales := Self.DatasetSales; end; end; but nothing happen. Why?

1) There's a bug in your code:

DatasetSales := Self.DatasetSales;
should be
Dataset := DatasetSales;

and Active should be set after the field setup.

Another caution is to have DatasetItems opened before DatasetSales

2) It's not implemented in TSqlite3Dataset
I looked at the implementation and got how it works, so i can implement in Sqlite3Dataset soon.

Luiz

Reply by email

Joost van der Sluis
to Unknown author: Dont spend too much time in this SQLite3DataSet has a lot of Bugs. ill tryed to fix all…

Op donderdag 25-12-2008 om 14:06 uur [tijdzone +0100], schreef :

Show quoted text 6 lines
>4) Even after this, there is some problems in SQLdb which I did not >yet found time >to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find Dont spend too much time in this SQLite3DataSet has a lot of Bugs. ill tryed to fix all for month before i used zeos

So where are all those bug-reports? Without those they will never get solved.

Becides that, ZEOS is made for another purpose. TSQLite3DataSet is made for what SQlite is made for: a lite and quick database-access layer.

ZEOS is made for 'heavier' usage, and often overkill when it comes to sqlite. And considerably slower.

Both have their own uses.

Joost.

Reply by email

Unknown author
Show quoted text 10 lines
Op donderdag 25-12-2008 om 14:06 uur [tijdzone +0100], schreef : > >4) Even after this, there is some problems in SQLdb which I did not > >yet found time > >to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find > > Dont spend too much time in this SQLite3DataSet has a lot of Bugs. > ill tryed to fix all for month before i used zeos So where are all those bug-reports? Without those they will never get solved.

http://bugs.freepascal.org/view.php?id=11423 at example

some of the problems i had was very hard to not reproduceable and the first bugreports i made are ignored so i use zeos and have no problem. when i become bad answers or the developer ignores me when i make bugreports and patches i dont use the component anymore.

when somebody is realy intrested in my patches for it please send an mail to me then i will send back my patches when ill find them i have resolved all problems i can so taht sqlite3dataset had react like an normal tdataset descendant (master detail & co) but after that some very hard errors with crashes & co remains and it was to bad for me, so i searched another solution wich was zeos.

best regards
Christian

Show quoted text 10 lines
Becides that, ZEOS is made for another purpose. TSQLite3DataSet is made for what SQlite is made for: a lite and quick database-access layer. ZEOS is made for 'heavier' usage, and often overkill when it comes to sqlite. And considerably slower. Both have their own uses. Joost. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Joost van der Sluis
to Unknown author

Op zaterdag 27-12-2008 om 14:06 uur [tijdzone +0100], schreef :

Show quoted text 17 lines
>Op donderdag 25-12-2008 om 14:06 uur [tijdzone +0100], schreef >: >> >4) Even after this, there is some problems in SQLdb which I did not >> >yet found time >> >to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find >> >> Dont spend too much time in this SQLite3DataSet has a lot of Bugs. >> ill tryed to fix all for month before i used zeos >So where are all those bug-reports? Without those they will never get >solved. http://bugs.freepascal.org/view.php?id=11423 at example some of the problems i had was very hard to not reproduceable and the first bugreports i made are ignored so i use zeos and have no problem. when i become bad answers or the developer ignores me when i make bugreports and patches i dont use the component anymore.

In the bug report you said you would send an example. But I still don't see it. Can you send it, so we can actually look at your bug?

Joost.

Reply by email

Unknown author
Show quoted text 21 lines
Op zaterdag 27-12-2008 om 14:06 uur [tijdzone +0100], schreef : > >Op donderdag 25-12-2008 om 14:06 uur [tijdzone +0100], schreef > >: > >> >4) Even after this, there is some problems in SQLdb which I did not > >> >yet found time > >> >to diagnose and fix properly. They cause AVs while scrolling DBGrid.at are very hard t find > >> > >> Dont spend too much time in this SQLite3DataSet has a lot of Bugs. > >> ill tryed to fix all for month before i used zeos > >So where are all those bug-reports? Without those they will never get > >solved. > > http://bugs.freepascal.org/view.php?id=11423 at example > > some of the problems i had was very hard to not reproduceable > and the first bugreports i made are ignored so i use zeos and have no problem. > when i become bad answers or the developer ignores me when i make bugreports and patches > i dont use the component anymore. In the bug report you said you would send an example. But I still don't see it. Can you send it, so we can actually look at your bug?

havend time for now. Maybe later its good described should be manageable to have in 5 min an example. But i must go now must be at the ostsee in 3h ;)

best reagrds
Christian

Show quoted text 5 lines
Joost. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Luiz Americo Pereira Camara
to Luiz Americo Pereira Camara: 1) There's a bug in your code: DatasetSales := Self.DatasetSales; should be Dataset :=…
Luiz Americo Pereira Camara wrote 33 lines
User escreveu: > Hi again, my TSQLite3Dataset components: > > DatasetSales with the fields: Code, Item, Amount, Price, Vendor > DatasetItems with the fields: Code, Description > > I do not want that the lookup field to be editable. > > My new code: > > procedure TForm1.FormCreate(Sender: TObject); > var > TempField: TStringField; > begin > DatasetSales.Active := true; > TempField := TStringField.Create(DatasetSales); > with TempField do > begin > FieldName := 'New field'; > Lookup := True; > FieldKind := fkLookup; > KeyFields := 'Item'; > LookupDataSet := DatasetItems; > LookupKeyFields := 'Code'; > LookupResultField := 'Description'; > DatasetSales := Self.DatasetSales; > end; > end; > > but nothing happen. Why? > >

[..]

2) It's not implemented in TSqlite3Dataset I looked at the implementation and got how it works, so i can implement in Sqlite3Dataset soon.

I implemented support to Calc/Lookup fields in fpc trunk. It would be good if someone could test because i don't use this feature much.

Luiz

Reply by email