I have a table:
Code: Select all
CREATE TABLE vinclient.tabletest (
testnum integer,
testtxt text
) WITH (OIDS = FALSE);
Code: Select all
CREATE TYPE vinclient.t_test AS (
testnum integer,
testtxt text
);
Code: Select all
CREATE OR REPLACE FUNCTION vinclient.f_test
(
IN p_testnum integer,
IN p_testtxt text
)
RETURNS vinclient.t_test AS
$$
declare
t_return vinclient.t_test%rowtype;
begin
insert into vinclient.tabletest (testnum, testtxt)
values(p_testnum, p_testtxt);
t_return.testnum = p_testnum;
t_return.testtxt = p_testtxt;
return t_return;
end
$$
LANGUAGE 'plpgsql'
VOLATILE
RETURNS NULL ON NULL INPUT
SECURITY INVOKER
COST 100;
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
myPgStoredProc: TPgStoredProc;
myTestNum: Integer;
myTestTxt: AnsiString;
begin
try
myPgStoredProc := TPgStoredProc.Create(nil);
with myPgStoredProc do begin
Connection := PgConnection1;
StoredProcName := 'f_test';
Sql.Add('SELECT (vinclient.f_test(:p_testnum, :p_testtxt)).*');
ParamByName('p_testnum').AsInteger := 1234;
ParamByName('p_testtxt').AsString := 'Sample String';
Execute;
if RecordCount > 0 then begin
myTestNum := Fields[0].AsInteger;
myTestTxt := Fields[1].AsString;
end;
Close;
ShowMessage('OK, only 1 record was posted to the database!');
end;
finally
myPgStoredProc.Free;
end;
end;
What is wrong here?
Thx & cheers,
Peter