Revision 188 "testing".
Code: Select all
CREATE TABLE z1 (c1 VARCHAR(20),c2 VARCHAR(20),c3 SMALLINT,c4 NUMERIC,PRIMARY KEY (c1,c2,c3));
CREATE TABLE z2 (c1 VARCHAR(20),c2 VARCHAR(20),c3 SMALLINT,c4 SMALLINT,c5 VARCHAR(20), PRIMARY KEY (c1,c2,c3,c4));
CREATE TABLE z3 (c1 VARCHAR(20),c2 VARCHAR(20),c3 TIMESTAMPTZ,PRIMARY KEY (c1,c2));
INSERT INTO z1 VALUES ('A','ID1',1,287463.371);
INSERT INTO z1 VALUES ('A','ID1',2,46152.2361);
INSERT INTO z2 VALUES ('A','ID1',1,100,'XX');
INSERT INTO z2 VALUES ('A','ID1',2,200,'YY');
INSERT INTO z3 VALUES ('A','XX','2005-12-31 12:30');
INSERT INTO z3 VALUES ('A','YY','2005-10-31 14:30');
Code: Select all
SELECT SUM(z1.c4) AS amount
,z3.c3 AS DueDate
,AGE(z3.c3) AS age
FROM z1 LEFT JOIN z2 ON (z2.c1=z1.c1 AND z2.c2=z1.c2 AND z2.c3=z1.c3)
LEFT JOIN z2 s2 ON (s2.c1=z1.c1 AND s2.c2=z1.c2 AND s2.c3=z1.c3)
LEFT JOIN z3 ON (z3.c1=s2.c1 AND z3.c2=s2.c5)
WHERE z1.c1='A' AND z2.c4=200
GROUP BY DueDate,age
To see what happens, enable logging:
Modify file ZAbstractRODataset.pas to enable the logging facility:
Code: Select all
use ZDbcLogging;
procedure TZAbstractRODataset.InternalInitFieldDefs;
var
I, J, Size: Integer;
AutoInit: Boolean;
FieldType: TFieldType;
ResultSet: IZResultSet;
FieldName: string;
FName: string;
begin
FieldDefs.Clear;
ResultSet := Self.ResultSet;
AutoInit := ResultSet = nil;
try
{ Opens an internal result set if query is closed. }
if AutoInit then
begin
CheckSQLQuery;
CheckConnected;
ResultSet := CreateResultSet(FSQL.Statements[0].SQL, 0);
end;
if not Assigned(ResultSet) then
raise Exception.Create(SCanNotOpenResultSet);
{ Reads metadata from resultset. }
//log
with ResultSet.GetMetadata do begin
for I := 1 to GetColumnCount do
DriverManager.LogError(lcOther,'I='+IntToStr(I)+'--->'+GetColumnLabel(I)
,'TZSQLType='+IntToStr(Integer(GetColumnType(I)))
,Integer(ConvertDbcToDatasetType(GetColumnType(I)))
,'AAAAAAAAAA');
end;
with ResultSet.GetMetadata do
begin
for I := 1 to GetColumnCount do
begin
//log
DriverManager.LogError(lcOther,'I='+IntToStr(I)+'--->'+GetColumnLabel(I)
,'TZSQLType='+IntToStr(Integer(GetColumnType(I)))
,Integer(ConvertDbcToDatasetType(GetColumnType(I)))
,'BBBBBBBBBB');
FieldType := ConvertDbcToDatasetType(GetColumnType(I));
Code: Select all
2006-12-13 20:40:19 cat: Execute, proto: postgresql-8, msg: SELECT SUM(z1.c4) AS amount
,z3.c3 AS DueDate
,AGE(z3.c3) AS age
FROM z1 LEFT JOIN z2 ON (z2.c1=z1.c1 AND z2.c2=z1.c2 AND z2.c3=z1.c3)
LEFT JOIN z2 s2 ON (s2.c1=z1.c1 AND s2.c2=z1.c2 AND s2.c3=z1.c3)
LEFT JOIN z3 ON (z3.c1=s2.c1 AND z3.c2=s2.c5)
WHERE z1.c1='A' AND z2.c4=200
GROUP BY DueDate,age
2006-12-13 20:40:19 cat: Other, proto: I=1--->amount, msg: TZSQLType=7, errcode: 6, error: AAAAAAAAAA
2006-12-13 20:40:19 cat: Other, proto: I=2--->duedate, msg: TZSQLType=14, errcode: 11, error: AAAAAAAAAA
2006-12-13 20:40:19 cat: Other, proto: I=3--->age, msg: TZSQLType=9, errcode: 1, error: AAAAAAAAAA
2006-12-13 20:40:19 cat: Other, proto: I=1--->amount, msg: TZSQLType=7, errcode: 6, error: BBBBBBBBBB
2006-12-13 20:40:19 cat: Execute, proto: postgresql-8, msg: SELECT version()
2006-12-13 20:40:19 cat: Execute, proto: postgresql-8, msg: SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog') WHERE a.attnum > 0 AND NOT a.attisdropped AND c.relname LIKE 'z1' AND a.attname LIKE '%' ORDER BY nspname,relname,attnum
2006-12-13 20:40:19 cat: Execute, proto: postgresql-8, msg: SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog') WHERE a.attnum > 0 AND NOT a.attisdropped AND c.relname LIKE 'z2' AND a.attname LIKE '%' ORDER BY nspname,relname,attnum
2006-12-13 20:40:19 cat: Execute, proto: postgresql-8, msg: SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog') WHERE a.attnum > 0 AND NOT a.attisdropped AND c.relname LIKE 'z3' AND a.attname LIKE '%' ORDER BY nspname,relname,attnum
2006-12-13 20:40:19 cat: Other, proto: I=2--->duedate, msg: TZSQLType=3, errcode: 2, error: BBBBBBBBBB
2006-12-13 20:40:19 cat: Other, proto: I=3--->age, msg: TZSQLType=9, errcode: 1, error: BBBBBBBBBB
Code: Select all
function TZPostgreSQLDatabaseMetadata.GetColumns(const Catalog: string;
const SchemaPattern: string; const TableNamePattern: string;
const ColumnNamePattern: string): IZResultSet;