Subject | RE: [IBO] FieldName in query with joins and aliases 4.7 bevahes different than 4.6 |
---|---|
Author | Jason Wharton |
Post date | 2006-12-01T01:50:53Z |
> Firebird SQL 1.5.3, Delphi 6proYou are observing the behavior of the BestFieldName property.
> The field name used by the IB_Query/IB_Cursor method FieldByName
> behaves different from previous versions, when Joins and field aliases
> are involved. In fact, while with previous versions the name of the
> column with alias was simply the alias, now it's always prefixed with
> the tablename qualifier.
> Don't know if this is a design decision, but risks to break a lot of
> code, so is good only if there are good reasons to do so.
>
> Have a look at these queries and FieldNames provided by the
> [FieldNames] tab of the Cursor in IB_SQL 4.6BC and 4.7b10:
> (btw 4.7beta10 behaves the same with FB 1.5.3 and 2.0)
>
> ==============================================================
> SELECT
> COMPANY ALIAS_1,
> CITY ALIAS_2
> FROM CUSTOMER
> LEFT JOIN ORDERS ON (CUSTOMER.CUSTNO = ORDERS.CUSTNO)
> WHERE COMPANY <= 'B'
> -------------------
> ALIAS_1
> ALIAS_2
> ==============================================================
> SELECT
> COMPANY ALIAS_1,
> CITY ALIAS_2,
> SALEDATE
> FROM CUSTOMER
> LEFT JOIN ORDERS ON (CUSTOMER.CUSTNO = ORDERS.CUSTNO)
> WHERE COMPANY <= 'B'
> -------------------
> ALIAS_1
> ALIAS_2
> ORDERS.SALEDATE
> ==============================================================
> SELECT
> COMPANY ALIAS_1,
> CITY ALIAS_2,
> SALEDATE ALIAS_3
> FROM CUSTOMER
> LEFT JOIN ORDERS ON (CUSTOMER.CUSTNO = ORDERS.CUSTNO)
> WHERE COMPANY <= 'B'
> -------------------
> ALIAS_1
> ALIAS_2
> ALIAS_3
>
> ==============================================================
> ==============================================================
> ==============================================================
>
> 4.7b10
> ==============================================================
> SELECT
> COMPANY ALIAS_1,
> CITY ALIAS_2
> FROM CUSTOMER
> LEFT JOIN ORDERS ON (CUSTOMER.CUSTNO = ORDERS.CUSTNO)
> WHERE COMPANY <= 'B'
> -------------------
> ALIAS_1
> ALIAS_2
> ==============================================================
> SELECT
> COMPANY ALIAS_1,
> CITY ALIAS_2,
> SALEDATE
> FROM CUSTOMER
> LEFT JOIN ORDERS ON (CUSTOMER.CUSTNO = ORDERS.CUSTNO)
> WHERE COMPANY <= 'B'
> -------------------
> CUSTOMER.ALIAS_1
> CUSTOMER.ALIAS_2
> ORDERS.SALEDATE
> ==============================================================
> SELECT
> COMPANY ALIAS_1,
> CITY ALIAS_2,
> SALEDATE ALIAS_3
> FROM CUSTOMER
> LEFT JOIN ORDERS ON (CUSTOMER.CUSTNO = ORDERS.CUSTNO)
> WHERE COMPANY <= 'B'
> -------------------
> CUSTOMER.ALIAS_1
> CUSTOMER.ALIAS_2
> ORDERS.ALIAS_3
It's an attempt to return the simplest identifier of the column necessary to
uniquely describe each row. If more than one table is detected among the
fields that are in the select list then it goes ahead and prepends the
column name with the table name (or the table alias if one is being used).
It's good to draw attention to this feature so people are aware.
Jason