打印本文 打印本文 关闭窗口 关闭窗口
SQL relay的C接口
作者:武汉SEO闵涛  文章来源:敏韬网  点击数11410  更新时间:2007/11/14 13:07:07  文章录入:mintao  责任编辑:mintao
returned through output parameters.

To create the stored procedure, run a query like the following.

create procedure testproc(in1 in number, in2 in number, in3 in varchar2, out1 out number, out2 out number, out3 out varchar2) is
begin
        out1:=in1;
        out2:=in2;
        out3:=in3;
end;

To execute the stored procedure from an SQL Relay program, use code like the following.

sqlrcur_prepareQuery(cur,"begin testproc(:in1,:in2,:in3,:out1,:out2,:out3); end;");
sqlrcur_inputBindLong(cur,"in1",1);
sqlrcur_inputBindDouble(cur,"in2",1.1,2,1);
sqlrcur_inputBindString(cur,"in3","hello");
sqlrcur_defineOutputBind(cur,"out1",20);
sqlrcur_defineOutputBind(cur,"out2",20);
sqlrcur_defineOutputBind(cur,"out3",20);
sqlrcur_executeQuery(cur);
char    *out1=sqlrcur_getOutputBind(cur,"out1");
char    *out2=sqlrcur_getOutputBind(cur,"out2");
char    *out3=sqlrcur_getOutputBind(cur,"out3");

To drop the stored procedure, run a query like the following.

drop procedure testproc
Sybase and Microsoft SQL Server

To create the stored procedure, run a query like the following.

create procedure testproc @in1 int, @in2 float, @in3 varchar(20), @out1 int output, @out2 int output, @out3 int output as
        select @out1=convert(varchar(20),@in1),
                @out2=convert(varchar(20),@in2),
                @out2=convert(varchar(20),@in2)

To execute the stored procedure from an SQL Relay program, use code like the following.

sqlrcur_prepareQuery(cur,"exec testproc");
sqlrcur_inputBindLong(cur,"in1",1);
sqlrcur_inputBindDouble(cur,"in2",1.1,2,1);
sqlrcur_inputBindString(cur,"in3","hello");
sqlrcur_defineOutputBind(cur,"out1",20);
sqlrcur_defineOutputBind(cur,"out2",20);
sqlrcur_defineOutputBind(cur,"out3",20);
sqlrcur_executeQuery(cur);
char    *out1=sqlrcur_getOutputBind(cur,"out1");
char    *out2=sqlrcur_getOutputBind(cur,"out2");
char    *out3=sqlrcur_getOutputBind(cur,"out3");

To drop the stored procedure, run a query like the following.

drop procedure testproc
Interbase and Firebird

To create the stored procedure, run a query like the following.

create procedure testproc(in1 integer, in2 float, in3 varchar(20)) returns (out1 integer, out2 float, out3 varchar(20)) as
begin
        out1=in1;
        out2=in2;
        out3=in3;
        suspend;
end;

To execute the stored procedure from an SQL Relay program, use code like the following.

sqlrcur_prepareQuery(cur,"select * from testproc(?,?,?)");
sqlrcur_inputBindLong(cur,"1",1);
sqlrcur_inputBindDouble(cur,"2",1.1,2,1);
sqlrcur_inputBindString(cur,"3","hello");
sqlrcur_executeQuery(cur);
char    *out1=sqlrcur_getFieldByIndex(cur,0,0);
char    *out2=sqlrcur_getFieldByIndex(cur,0,1);
char    *out3=sqlrcur_getFieldByIndex(cur,0,2);

Alternatively, you can run a query like the following and receive the result using a output bind variables. Note that in Interbase/Firebird, input and output bind variable indices are distict from one another. The index of the first output bind variable is 1 rather than 4, even though there were 3 input bind variables.

sqlrcur_prepareQuery(cur,"execute procedure testproc ?, ?, ?");
sqlrcur_inputBindLong(cur,"1",1);
sqlrcur_inputBindDouble(cur,"2",1.1,2,1);
sqlrcur_inputBindString(cur,"3","hello");
sqlrcur_defineOutputBind(cur,"1",20);
sqlrcur_defineOutputBind(cur,"2",20);
sqlrcur_defineOutputBind(cur,"3",20);
sqlrcur_executeQuery(cur);

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ...  下一页 >> 

打印本文 打印本文 关闭窗口 关闭窗口