Subject | FieldName in query with joins and aliases 4.7 bevahes different than 4.6 |
---|---|
Author | Marco Menardi |
Post date | 2006-11-30T22:41:24Z |
Firebird SQL 1.5.3, Delphi 6pro
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
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