Page 1 of 1
How to use UniStoredProc from the code
Posted: Tue 25 Feb 2014 07:26
by FCS
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
Re: How to use UniStoredProc from the code
Posted: Tue 25 Feb 2014 11:06
by AlexP
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;
Re: How to use UniStoredProc from the code
Posted: Tue 25 Feb 2014 11:25
by FCS
Hello,
Thanks.
How to send and receive more complicated structures like arrays or records.
How to get a dataset(-s) as output ?
Regards
Michal
Re: How to use UniStoredProc from the code
Posted: Tue 25 Feb 2014 13:52
by AlexP
Work with such types depends on the DB you are using. Please specify the DB name and types you are interested to work with.
Re: How to use UniStoredProc from the code
Posted: Tue 25 Feb 2014 17:55
by FCS
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
Re: How to use UniStoredProc from the code
Posted: Wed 26 Feb 2014 13:53
by AlexP
Before calling parameters, the UniStoredProc.Prepare method should be called
Re: How to use UniStoredProc from the code
Posted: Thu 27 Feb 2014 16:22
by FCS
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
Re: How to use UniStoredProc from the code
Posted: Mon 03 Mar 2014 13:44
by AlexP
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
Re: How to use UniStoredProc from the code
Posted: Mon 03 Mar 2014 14:57
by FCS
Thanks,
Regards
Michal
Re: How to use UniStoredProc from the code
Posted: Thu 06 Mar 2014 08:01
by AlexP
You are welcome. Feel free to contact us if you have any further questions about UniDAC.