Bram Kuijvenhoven wrote:
Hi Andrea,
Andrea Mauri wrote:
I am using TSQLquery with a TIBconnection to an interbase database.
I have a query like this:
select
T1.ID, T1.FIELD1, T2.ID, T2.FIELD1
from TABLE1 T1
left join
TABLE2 T2
on T1.ID = T2.ID
If I use this query with TSQL query I get an error
duplicate fieldname ID
Why? If I commit the same query using a SQL manager I don't get the
error an the query works properly.
Is it a bug? Any help?
It is a limitation of the database components.
- The FieldNames of the TFields of a TDataset are required to be unique
- Currently the FieldNames consist solely of the column names in a
result set
- Column names are not unique (but usually the 4-tuple (CatalogName,
SchemaName, TableName, ColumnName) is)
See e.g. this thread at the fpc-devel mailing list:
http://lists.freepascal.org/lists/fpc-devel/2007-April/010405.html.
It is possible to use some renaming scheme to guarantee uniqueness of
the FieldNames, but then we'd need a well-defined standard. Also, I
wonder what impact it would have on ApplyUpdates etc.
Ehm, or you use some func like GetUniqueName (don't recall the exact
name) which generates a (component)name with a numeric postfix
Just tried in delphi, and it posfixed dup names with a _1 _2 etc
Marc
BTW you could also prefix your field names with a table-specific prefix.
This saves you providing all the column aliases in each query. It is
common practice. E.g.
tblCustomer: custID, custName
tblInvoice: invID, invTotal
(Or: cust_id, cust_name, etc.)
Regards,
Bram
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives