How to use UniStoredProc from the code

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

How to use UniStoredProc from the code

Post by FCS » Tue 25 Feb 2014 07:26

Hello,

What is the proper way to use Stored Procedures from code?
I want create a UniStoredProc object from code. How declare input and output parameters and its types?
Could you write some examples for different input and output types ?

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use UniStoredProc from the code

Post by AlexP » Tue 25 Feb 2014 11:06

Hello,

To create TUniStoredProc and parameter setting, you can use the following code.

Code: Select all

var
  UniStoredProc: TUniStoredProc;
begin
  UniStoredProc := TUniStoredProc.Create(nil);
  try
    UniStoredProc.Connection := UniConnection1;
    UniStoredProc.StoredProcName := 'my_storedproc';
    UniStoredProc.ParamByName('p1').ParamType := ptInput;
    UniStoredProc.ParamByName('p1').DataType := ftInteger;
    UniStoredProc.ParamByName('p2').ParamType := ptOutput;
    UniStoredProc.ParamByName('p2').DataType := ftString;
    UniStoredProc.Execute;
    ShowMessage(UniStoredProc.ParamByName('p2').AsString);
  finally
    UniStoredProc.Free;
  end;
end;

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: How to use UniStoredProc from the code

Post by FCS » Tue 25 Feb 2014 11:25

Hello,

Thanks.

How to send and receive more complicated structures like arrays or records.
How to get a dataset(-s) as output ?

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use UniStoredProc from the code

Post by AlexP » Tue 25 Feb 2014 13:52

Work with such types depends on the DB you are using. Please specify the DB name and types you are interested to work with.

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: How to use UniStoredProc from the code

Post by FCS » Tue 25 Feb 2014 17:55

Hello,

The example code doesn't work:
UniStoredProc.ParamByName('p1').ParamType := ptInput;
UniStoredProc.ParamByName('p1').DataType := ftInteger;

I receive error message "Parameter 'p1' not found.

I'm using PostgreSQL.

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use UniStoredProc from the code

Post by AlexP » Wed 26 Feb 2014 13:53

Before calling parameters, the UniStoredProc.Prepare method should be called

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: How to use UniStoredProc from the code

Post by FCS » Thu 27 Feb 2014 16:22

Thanks,

But what of these questions:

How to send and receive more complicated structures like arrays or records.
How to get a dataset(-s) as output ?

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use UniStoredProc from the code

Post by AlexP » Mon 03 Mar 2014 13:44

You can work with such types only as with strings
If a procedure or a function returns the cursor (DataSet), then you can work with TUniStoredProc as with a normal DataSet

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: How to use UniStoredProc from the code

Post by FCS » Mon 03 Mar 2014 14:57

Thanks,

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use UniStoredProc from the code

Post by AlexP » Thu 06 Mar 2014 08:01

You are welcome. Feel free to contact us if you have any further questions about UniDAC.

Post Reply