I create 2 Tables and JOIN them.
TCRFieldDesc(FieldDesc).TableInfo.TableName will hold the wrong table.
Try this view lines of code and you will see it.
Create tables - Statement:
Code: Select all
DROP TABLE IF EXISTS first;
CREATE
-- TEMP
TABLE first
(
id SERIAL,
context character varying(32)
);
DROP TABLE IF EXISTS second;
CREATE
-- TEMP
TABLE second
(
id integer,
second_first_id integer,
context character varying(32)
);
-- Query to select Data
SELECT
first.context AS first_ctx,
second.context AS second_ctx,
*
FROM
first LEFT JOIN second ON first.id = second_first_id
Code: Select all
var Q1 : TPgQuery;
...
for I := 0 to Q1.FieldCount - 1 do begin
FieldDesc := TCustomDADataSet(Q1).GetFieldDesc(Q1.Fields[I]);
MemoSQLLog.Lines.Add(Q1.Fields[I].FieldName + ' -> ' + TCRFieldDesc(FieldDesc).TableInfo.TableName)
end;
Code: Select all
first_ctx -> first
second_ctx -> first !!!!!!!!!!!!!!!!!!!!! WRONG !!!!!!!!!!!!!!!!!!!!!!!
id -> first
context -> first
id_1 -> second
second_first_id -> second
context_1 -> second
if you execute this with temp tables everything is fine:
commt in the --TEMP blocks
Code: Select all
-- CREATE TABLES as TEMP tables (use Script above)
SELECT
first.context AS first_ctx,
second.context AS second_ctx
FROM
first LEFT JOIN second ON first.id = second_first_id
==========================
first_ctx -> first
second_ctx -> second