I have an SQL function that returns a table, and I would like to display the results in a grid.
Code: Select all
create or replace function get_table()
  returns table (group_name varchar(50), log_id integer, log_entry varchar(50))
as
$body$
select A.group_name, B.log_id, B.log_entry
from
(
	(select group_id, group_name from "group") A
		full outer join
	(select log_id, log_entry, group_id from log) B on A.group_id = B.group_id
)
$body$
language sql;Code: Select all
	TPgStoredProc* pgProc = new TPgStoredProc(NULL);
	pgProc->Connection = pgCon;
	pgProc->StoredProcName = "get_table";
	pgProc->PrepareSQL();
	pgProc->ExecProc();
	//Now what?
	grdMain->DataSet = ...Code: Select all
	TPgQuery* query = new TPgQuery(NULL);
	query->Connection = pgCon;
	query->SQL->Text = "select * from get_table();";
	query->Execute();
	//Now what?
	grdMain->DataSource = q->MasterSource;
	grdMain->Enabled = true;However, if there exists some way of both
showing and editing data that is joined like this using a TDBGrid,
it would be amazing.
Any insight on this is greatly appreciated :)
Also here are the tables:
Code: Select all
create table group (
    group_id integer primary key,
    group_name varchar(50)
);
create table log (
    log_id integer primary key,
    log_entry varchar(50),
    group_id integer references "group" (group_id)
)