Recent

Author Topic: Lookup fields do not return data.  (Read 32958 times)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #15 on: September 14, 2012, 09:32:45 am »
How many fields you have in the peopleQuery with the name fktitleid?

I can see 2 references 1 a fielddef reference of data type ftInteger and 2) a Tfield Object with field kind fklookup. You can't have
1) 2 fields with the same name in any single Query object.
2) a lookup field that has its FieldKeys = Fieldname.
Also the keyfields property must have fields on the dataset that the lookup field belongs to.

From the form definition you have shown it seems that the keyfields property is not connected to an existing data field.
 
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #16 on: September 14, 2012, 09:41:26 am »
theres only on fktitleid field, theres a query field def with the same name but that happens automatically as with the other query (not record) fields

So I'm really not following you ??
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #17 on: September 14, 2012, 09:49:20 am »
I'm sorry my, english fu is not as good as it should be.

You have a field fktitleid, which is of fieldkind fklookup correct?

Which is the keyfield in peopleQuery that fktitleid should update with data?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #18 on: September 14, 2012, 09:57:03 am »
no worries its better than anyother language of mine that English! :)

Code: [Select]
    object peopleQueryfktitleid: TLongintField
      DisplayWidth = 10
      FieldKind = fkLookup
      FieldName = 'fktitleidISNTTHISTHEQUERYFIELDNAME??'
      Index = 1
      KeyFields = 'AAA'
      LookupCache = True
      LookupDataSet = titleQuery
      LookupKeyFields = 'BBB'
      LookupResultField = 'CCC'
      ProviderFlags = [pfInUpdate, pfInWhere]
      ReadOnly = False
      Required = False
    end

people table has

peopleid <- AI PK
fktitleid <- foreign key to titles.titleid
name
address
etcetc

titles table

titleid <- AI PK
title <- string to display instead of foreign key way displaying a person record

what values should be in AAA, BBB, CCC

Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #19 on: September 14, 2012, 10:29:40 am »
OK then fkTitleID is a physical field (aka exists in database) which you can not define as a lookup field.
You need to change it back to fkData and add a new field as the look up.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #20 on: September 14, 2012, 11:03:26 am »
ah right! (thats, how its *supposed* to work!!!)

how ever when I try to make the people query active I get

peopleQuery : Field not found : "titleid"

which makes no sense at ALL !

does it mean the peopleQuery is failing because it can't find titleid in the foreign table ???

the titles query IS active and when I run its query I DO get a titleid field, the titleQuery does have a titleid field defined...

Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #21 on: September 14, 2012, 11:18:56 am »
Finally I'm back to the none working but not crashing and allowing the query to be active condition of the previous project that I scrapped PHEW!

please see the attachment

this will show a drop down with the correct selection of fields
but without a value in the cells

if I turn cache on I get an exception with a similar error to the one mentioned earlier and the IDE exits....
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #22 on: September 14, 2012, 11:27:22 am »
I have impression that you need to use persistent fields in both queries but I need some time to test it later today.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #23 on: September 15, 2012, 04:19:18 am »
I have impression that you need to use persistent fields in both queries but I need some time to test it later today.
if by persistent fields you mean that both queries have fielddefs then yes they both do!
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #24 on: September 15, 2012, 04:55:04 am »
I have impression that you need to use persistent fields in both queries but I need some time to test it later today.
if by persistent fields you mean that both queries have fielddefs then yes they both do!

Sorry Chris it was a long night tonight didn't had the time to take a closer look on your form.
Is it possible to send me an sql query to recreate the tables and a few lines of data for testing?
As always my test will be done with firebird but I do not expect any differences between the 2 databases.
I just need to have your fields in those 2 queries so you can just replace the IBConnection with a mysql connection and see how things work for you. Saturday to today I'll have more time to spend on the issue.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #25 on: September 15, 2012, 07:25:48 am »
I've taken the liberty of attaching the whole project so you can see the the problem, its just a single form with a single grid. (a mysql dump is included)

Please don't misunderstand I'm not demanding you fix my project, rather I have created (and recreated a number of times) this project so I can understand DBGrid better, it is my intention to create a tutorial but without complete understanding of this issue this isn't possible!

I think there are a great number of people find this issue troublesome and would greatly appreciate some kind of basic tutorial ...

really no .xz attachments ??
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #26 on: September 15, 2012, 01:35:52 pm »
I'm working on this as I type this. I have created the database and I'm trying to identify the problem.
At first I thought that your problem was the keyfield/listfield/listResultfield combination which was wrong then I realized that they ended up that way after you tried to identify the problem your self.

I am at the point where I see the exception in design time and trying to find why it behaves like this, so hopefully it want be long now.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #27 on: September 15, 2012, 04:17:09 pm »
oh I do hope you don't end up with the same blood stains on the wall as mine....

It would be really nice to get to the bottom of this though and know specifically what causes it and why, so we can work out what to do and just as importantly what NOT to do!
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lookup fields do not return data.
« Reply #28 on: September 15, 2012, 04:44:38 pm »
I am almost there (seen blood stains that is) there are a number of really weird checks in all the wrong places inside the Bufdataset. In one hand getting an error is better than silently failing to show data on the other hand it shouldn't fail while connecting the dataset to the database unless there is some kind of network or library error. I am still trying to figure out where this error originates and not being able to step in to sqldb code is a major pain in my back.
Building a debug ide as we speak so that might help to get things going a bit faster.
NEVER MIND that failed miserably I need to re install everything.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Lookup fields do not return data.
« Reply #29 on: September 15, 2012, 04:52:21 pm »
Thank for taking the time, I for one certainly appreciate it, I'm determined to make good use of your work to make a really good wiki tutorial so your effort will not be wasted!
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

 

TinyPortal © 2005-2018