Subject How to access field when there are dupe field names
Author Eyal
Hi,

I use an IB_Query to compare table rows to an external source and
insert rows that don't exists in the table. I generate the query in
code and provide separate SQLs for select and insert. Here is a
simplified version of those queries (the actual version is too long):

SELECT aaa.num, aaa.name, ppp.num, ppp.mod_date
FROM aaa
JOIN ppp ON ppp.aaa_id=aaa.id // ppp is a SP

INSERT INTO aaa VALUES (:id, :num, :name)

I read data from the external source, and use Locate to check if it's
already in the dataset. If not, I use the following code to insert the
new row (again simplified):

query.Insert;
query['id']:=query.GeneratorValue('gen_aaa_id', 1);
query['num']:=...;
query['name']:=...;
query.Post;

Problems/questions:


1. When I looked at the resulting table I noticed that the 'num'
column was empty in all new rows . I was puzzled at first because I
explicitly set the value of the num field.

Then I realized that I have two fields named 'num', one from table
'aaa' and one from the SP 'ppp'. So I intended to set 'aaa.id' but
ended up setting 'ppp.id'.

How do I access the correct field when there are several fields with
the same name?


2. I tried to be clever and use the fully qualified name -
query['aaa.num']:=... only to discover that IBO ignores the table name
and only uses the field name.

Is this a bug or an intended behavior? Is there any way to access
fields using the fully qualified name?


A possible solution is to use aliases for all fields, but this makes
query building very cumbersome, and really pointless as "table name +
field name" already provides a unique identifier.


Regards,

Eyal.