how to call procedure by UniQuery in sqlserver

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
daizhicun
Posts: 109
Joined: Thu 21 Jan 2010 11:49

how to call procedure by UniQuery in sqlserver

Post by daizhicun » Mon 15 Nov 2010 13:54

In Oracle:

when can use UniQuery call Procedure,for example:

Code: Select all

  UniQuery.Sql.text:='begin  proc1(:a,:b,:c) end';
  UniQuery.params[0].datatype:=ftString;
   .....
  UniQuery.execute;

but i find that UniQuery can not call Procedure In sqlserver;
for exmaple :

Code: Select all

UniQuery.Sql.text:=
'{:RETURN_VALUE = CALL GETAffiMsg (:PICK, :TaskContNo, :Msg)}';
....
  UniQuery.execute

we Must use UniStoredPorc in sqlserver;

i think UniQuery can instead of UniStoredPorc ;

can you give me a demo fro UniQuery instead of UniStoredPorc in mssql?

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

Post by AlexP » Mon 15 Nov 2010 15:52

Hello,

To call a stored procedure in UniQuery you should use the following code:


UniQuery.Sql.text:= 'SELECT GETAffiMsg (:PICK, :TaskContNo, :Msg)';
UniQuery.ParamByName('PICK').as...:= xxx ;
....
UniQuery.execute

daizhicun
Posts: 109
Joined: Thu 21 Jan 2010 11:49

Post by daizhicun » Tue 16 Nov 2010 01:34

To call a stored procedure in UniQuery you should use the following code:


UniQuery.Sql.text:= 'SELECT GETAffiMsg (:PICK, :TaskContNo, :Msg)';
UniQuery.ParamByName('PICK').as...:= xxx ;
....
UniQuery.execute
it is only can call function; it is not the methed of call procedure;

and my demo GETAffiMsg's Parameters :TaskContNo, :Msg is output parameter;




i only can use this method call procedre in mssql:


Code: Select all

DECLARE	        @PICK VARCHAR(20),
		@TaskContNo bigint,
		@Msg varchar(500)
          SET @PICK=:PICK;

EXEC	 [dbo].[GetAffiMsg]
		@PICK,
		 @TaskContNo OUTPUT,
	    @Msg OUTPUT

SELECT	@TaskContNo as N'@TaskContNo',
		@Msg as N'@Msg'
only input parameter can be used ;output parameter can't be get .

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

Post by AlexP » Tue 16 Nov 2010 07:53

hello,

To execute a stored procedure with output parameter in TUniQuery you can use the following code:

create procedure calc(@a int, @b int, @c int out)
as
begin
SET @c = @a+ @b;
end


var
n: integer;
begin
UniQuery1.SQL.clear();
UniQuery1.SQL.Text:='exec calc :a, :b, :c output';
UniQuery1.ParamByName('a').AsInteger := 5;
UniQuery1.ParamByName('b').AsInteger := 3;
UniQuery1.ParamByName('c').ParamType:= ptOutput;
UniQuery1.ExecSQL;
ShowMessage(UniQuery1.ParamByName('c').AsString);

Post Reply