1

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??

1
  • If StoredProc2 is a TDataset descendant, you would have to be using FieldByName. With a TDataset descendant ParamByName is for the parameters that are passed TO the query/storedproc, not the results returned by it. Commented May 28, 2012 at 9:21

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.