51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1675|回复: 3
打印 上一主题 下一主题

那位高手能举一个数据库调用的例子

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2005-12-9 11:20:00 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
那位高手能举一个数据库调用的例子,如已经建立了一个odbc数据源名为test(access),如何建立连接,执行sql语句,返回结果,谢谢。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2005-12-12 13:35:31 | 只看该作者
请问该种情况应该选中那种协议,我如果仅选择了web/http协议,提示说vuser_init.c (9): undeclared identifier `InitInfo'
vuser_init.c (9): type error in argument 1 to `lrdfnc_init'; found `pointer to int' expected `const pointer to struct LRD_INIT_INFO'
vuser_init.c (9): undeclared identifier `DBTypeVersion'等等,请帮忙解答一下
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2005-12-11 15:42:59 | 只看该作者
/* -------------------------------------------------------------------------------
        Script Title       : ODBC Script Example
        Script Description :
                        
                        
        Recorder Version   : 1008
   ------------------------------------------------------------------------------- */

vuser_init()
{
//1        init
        lrd_init(&InitInfo, DBTypeVersion);

//2        open context :ctx2       
        lrd_open_context(&Ctx2, LRD_DBTYPE_ODBC, 0, 0, 0);
        lrd_db_option(Ctx2, OT_ODBC_OV_ODBC3, 0, 0);


//3         Allocates a connection structure:con2
        lrd_alloc_connection(&Con2, LRD_DBTYPE_ODBC, Ctx2, 0 /*Unused*/, 0);

//4        db option
        lrd_db_option(Con2, OT_ODBC_LOGIN_TIMEOUT, (void FAR const *)15, 0);
        lrd_db_option(Con2, OT_ODBC_SS_QUOTED_IDENT, "OFF", 0);
        lrd_db_option(Con2, OT_ODBC_SQL_PACKET_SIZE, (void FAR const *)4096, 0);
        lrd_db_option(Con2, OT_ODBC_SS_ANSI_NPW, "ON", 0);

//4        open_connection con2.
        lrd_open_connection(&Con2, LRD_DBTYPE_ODBC, "", lr_decrypt("439bcec4e"), "", lr_decrypt("439bcec47d1a6c4f5cb1a621ba48147321e9d548ffd0593b"
        "1ba1c5097e22f8bec49be99e63rrb76f20f5d7a8692187020d432b8e"
        "ed83601279b6ab6bff5233550fec251642bea0eeba743be1a2d3d0e1ca4e"
        "7beb2521f0790f2bf3789af6de1302a15a51d488bf2b4a282f4586f47fa1"
        "af1315c837"), Ctx2, 1, 0);

//5        open_cursor csr2
        lrd_open_cursor(&Csr2, Con2, 0);
       

        lrd_db_option(Csr2, OT_ODBC_CURSOR_UNBOUNDCOLS, 0, 0);
//6        db set. If you open “sql query”, query will set default.Sometimes it will influence the test result.  
        lrd_stmt(Csr2, "set nocount off\r\nset arithabort off\r\nset "
        "concat_null_yields_null off\r\nset ansi_nulls off\r\nset "
        "cursor_close_on_commit off\r\nset ansi_null_dflt_on off\r\n"
        "set implicit_transactions off\r\nset ansi_padding off\r\n"
        "set ansi_warnings off\r\nset quoted_identifier off\r\n", -1, 1 /*Direct exec*/, 0 /*None*/, 0);

/*all above script is to open and connect db.
next script is operation */       

        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
//7        DB: pubs
        lrd_stmt(Csr2, "use pubs\r\n", -1, 1 /*Direct exec*/, 0 /*None*/, 0);
        lrd_db_option(Csr2, OT_ODBC_CURSOR_UNBOUNDCOLS, 0, 0);
        lrd_result_set(Csr2, 0, 0, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);

/*select query
        You can get the transaction "query" time as the  sql execute time.And you can get the transaction
        "getData" time as the  sql data transmission time between db and aplication server.*/

        lr_start_transaction("query");

        lrd_stmt(Csr2, "select * from dbo.authors\r\n", -1, 1 /*Direct exec*/, 0 /*None*/, 0);
        lrd_bind_cols(Csr2, BCInfo_D37, 0);
        lr_end_transaction("query", LR_AUTO);

        lr_start_transaction("getData");

        lrd_fetch(Csr2, -23, 1, 0, PrintRow18, 0);
        GRID(18);
        lr_end_transaction("getData", LR_AUTO);

        lrd_db_option(Csr2, OT_ODBC_CURSOR_UNBOUNDCOLS, 0, 0);
        lrd_result_set(Csr2, 0, 0, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);

//        exec procedure
        lrd_stmt(Csr2, "exec dbo.byroyalty 100\r\n", -1, 1 /*Direct exec*/, 0 /*None*/, 0);
        lrd_bind_cols(Csr2, BCInfo_D39, 0);


        lrd_fetch(Csr2, -10, 1, 0, PrintRow20, 0);
        GRID(20);
       

        lrd_db_option(Csr2, OT_ODBC_CURSOR_UNBOUNDCOLS, 0, 0);
        lrd_result_set(Csr2, 0, 0, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_cancel(0, Csr2, 0 /*Unused*/, 0);
        lrd_result_set(Csr2, 0, 0, 0);
        lrd_db_option(Csr2, OT_ODBC_CURSOR_CLOSE, 0, 0);
        lrd_db_option(Csr2, OT_ODBC_CURSOR_UNBOUNDCOLS, 0, 0);
       
// script end . close cusor、connectio、context       
        lrd_close_cursor(&Csr2, 0);
        lrd_close_connection(&Con2, 0, 0);
        lrd_free_connection(&Con2, 0 /*Unused*/, 0);
        lrd_close_context(&Ctx2, 0, 0);
       
        return 0;
回复 支持 反对

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2005-12-9 15:21:52 | 只看该作者
版主帮帮忙啊,查不到相应的资料,求助同行们,呵呵
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-10-7 18:31 , Processed in 0.072631 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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