祝愿大家身体健康!

 站点注册  找回密码
 站点注册

QQ登录

只需一步,快速开始

查看: 3716|回复: 0

[转帖]如何在PowerBuilder中调用MS SQL SERVER的存储过程

[复制链接]

[转帖]如何在PowerBuilder中调用MS SQL SERVER的存储过程

[复制链接]
ehxz

主题

0

回帖

58万

积分

管理员

积分
588671
贡献
在线时间
小时
2007-6-26 12:10:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?站点注册

×
 

Overview

The examples in this document are intended to extend the information provided with our Online Documentation and manuals.

How do I get the output parameters back from the server if my stored procedure is also returning a resultset?

There are a couple of different ways to get the RESULTSET and OUTPUT parameter from a stored procedure.

Code Sample 1: DECLARE, EXECUTE and FETCH ResultSet and Output parameters:

The first is to declare, execute and fetch the resultset and then when the sqlcode = 100 get out of loop and fetch the procedure a second time.  The code would look like this:

//declare local variable
LONG l_parm1
LONG l_out_parm

STRING s_message

CONNECT USING SQLCA;

//Initialize the input parameter - this could be hard coded.
l_parm1 = 35

DECLARE testproc PROCEDURE FOR dbo.testproc @Parm1 = :l_parm1, @OutParm = :l_out_parm OUTPUT USING SQLCA;

EXECUTE testproc;
//First, fetch the RESULTSET
do while sqlca.sqlcode = 0
FETCH testproc INTO :s_message;
if sqlca.sqlcode = 0 then
MessageBox( "s_message", s_message)
end if

loop
//Now fetch the OUTPUT PARM
FETCH testproc INTO :l_out_parm;
MessageBox( "l_out_parm", String(l_out_parm))
CLOSE testproc;
DISCONNECT USING SQLCA;

The second way this can be accomplished is by using the RPC method.  This is discussed in the "Application Techniques" manual.

Code sample 2:   Dynamic SQL Format 4 declaring a stored procedure

The sample in our help file illustrates ways to use format 4 using a declared cursor.  This script uses Format 4 embedded SQL statements and a declared stored procedure. This example assumes you know that there will be only one output descriptor and that it will be an integer. You can expand this example to support any number of output descriptors and any data type by wrapping the CHOOSE CASE statement in a loop and expanding the CASE statements.

string ls_procname, ls_sql, ls_Temp
int li_job_id, li_Ctr, li_Temp
int li_rtn

li_job_id = dw_emp.getitemNumber(1, "job_id")
setNull(li_job_id)

ls_procname = 'pr_405237'
ls_sql = 'execute ' + ls_procname + ' @job_id=' + '?'

PREPARE SQLSA FROM :ls_sql using sqlca;
DESCRIBE SQLSA INTO SQLDA ;

DECLARE my_procudure DYNAMIC PROCEDURE FOR SQLSA ;
li_rtn = SQLDA.SetDynamicParm(1, li_job_id)
sle_1.Text = String(li_rtn)
EXECUTE DYNAMIC my_procudure USING DESCRIPTOR SQLDA ;
FETCH my_procudure USING DESCRIPTOR SQLDA ;
If Sqlca.Sqlcode <> 0 then
    Messagebox("Error ", String(Sqlca.Sqlcode) + sqlca.sqlerrtext)
 else
       for li_Ctr = 1 to sqlda.NumOutputs
          CHOOSE CASE SQLDA.OutParmType[li_Ctr]
            CASE TypeString!
              ls_Temp = GetDynamicString(SQLDA, li_Ctr)
            CASE TypeInteger!
              li_Temp = GetDynamicNumber(SQLDA, li_Ctr)
          END CHOOSE
       next
  end if

CLOSE my_procedure ;

共享共进共赢Sharing And Win-win Results
SYBASEBBS - 免责申明1、欢迎访问“SYBASEBBS.COM”,本文内容及相关资源来源于网络,版权归版权方所有!本站原创内容版权归本站所有,请勿转载!
2、本文内容仅代表作者观点,不代表本站立场,作者自负,本站资源仅供学习研究,请勿非法使用,否则后果自负!请下载后24小时内删除!
3、本文内容,包括但不限于源码、文字、图片等,仅供参考。本站不对其安全性,正确性等作出保证。但本站会尽量审核会员发表的内容。
4、如本帖侵犯到任何版权问题,请立即告知本站 ,本站将及时删除并致以最深的歉意!客服邮箱:admin@sybasebbs.com
您需要登录后才可以回帖 登录 | 站点注册

本版积分规则

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com

QQ|Archiver|PowerBuilder(PB)BBS社区 ( 鲁ICP备2021027222号-1 )

GMT+8, 2024-11-24 10:22 , Processed in 0.037090 second(s), 8 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表