[Gambas-user] Looking up data from a second table

Christof Thalhofer chrisml at deganius.de
Mon Feb 19 22:37:43 CET 2018


Am 19.02.2018 um 21:17 schrieb bkv at mailbox.org:

> I have a form with a Datasource and the datasource's Table property is
> set to a table called /patron./ I have some fields from /patron/ in my
> form and I view and update them.
> 
> Now, patron also has a foreign key to a table called /krutt,/ named
> /krutt_id./ I need to get one field out of /krutt/ and display it on my
> form (read only).
> 
> I can do this with a db.select using the /krutt_id/ from /patron/ as key
> to table /krutt/ when I put the field /krutt_id/ from /patron/ on my
> form and make it visible. But I don't want to display the field
> /krutt_id /on my form.
> 
> Is there any way I can get the value of /krutt_id/ without putting it on
> the form? I have looked at the Datasource object with no result.
> 
> Or is there a complete different solution?

Normally such is done with a sql query like:

"select patron_a, patron_b, thisisfromkrutt from patron, krutt where
patron.krutt_id = krutt.id;"

if for every patron is a tuple in krutt.

Or:

"select patron_a, patron_b, thisisfromkrutt from patron left join krutt
on patron.krutt_id = krutt.id;"

if not every parton has a corresponding tuple in krutt.

You can store this sql string into DataSource.Table instead of tablename.

You also could store this sql string in your database as a view and use
the view's name as tablename.

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180219/a6a3349e/attachment-0001.sig>


More information about the User mailing list