poonam
poonam

Reputation: 810

Delphi Postgres stored procedure

I am working on Delphi application which deals with stored procedures.I created stored procedure for insert statement and it works fine for my application. Now,I wanted to create the same for select statement.

CREATE TYPE list_all_firstname AS ( first_name character varying);  

CREATE FUNCTION select_sp()   
RETURNS SETOF list_all_firstname AS  
$$  
DECLARE  
rec record;  
BEGIN  
  FOR rec IN (SELECT first_name FROM person) LOOP  
  RETURN NEXT rec;  
END LOOP;  
END;  
$$ LANGUAGE plpgsql;  

The call is:

SELECT * FROM select_sp();

Till this everything is fine in postgres.I wanted to access this stored procedure in my delphi application. My code is:

 with StoredProc2 do begin
     StoredProcName :='select_sp';
     ExecProc;
     Edit5.Text:=ParamByName('list_all_firstname').AsString ;
    end;

But i gets the error saying "Could not find object".How do i access return values of stored procedure in delphi??

Upvotes: 1

Views: 1371

Answers (1)

poonam
poonam

Reputation: 810

I got the answer..could not find object is BDE error... Next thing is accessing values,no need to use stored procedure component.We can use TQuery as below...:

  Query1.SQL.Clear;
  Query1.SQL.Add('SELECT * FROM select_sp()');
  Query1.Active := True;

  for i:=0 to Query1.RowsAffected-1 do
          begin
             sval:=Query1.FieldByName('first_name').AsString;
             ShowMessage(sval);
             Query1.Next;
          end;

Upvotes: 1

Related Questions