posts - 97,  comments - 5,  trackbacks - 0
#include "lrd.h"
 Action()
 {
double trans_time;  //定义一个double型变量用来保存事务执行时间

 static LRD_INIT_INFO InitInfo = {LRD_INIT_INFO_EYECAT};
 static LRD_DEFAULT_DB_VERSION DBTypeVersion[] =
 {
   {LRD_DBTYPE_ODBC, LRD_DBVERSION_ODBC_30},
   {LRD_DBTYPE_NONE, LRD_DBVERSION_NONE}
 };
 static LRD_CONTEXT FAR * Ctx1;
 static LRD_CONNECTION FAR * Con1;
 static LRD_CURSOR FAR *     Csr1;
 //上面的定义的代码如果录制脚本,在vdf.h中就有定义,同时还有一些其他文件
//如果手写脚本,则需要手工添加,主要是定义各种变量
//查询行数
unsigned long count=0;


 //初始
lrd_init(&InitInfo, DBTypeVersion);
 //打开上下文
lrd_open_context(&Ctx1, LRD_DBTYPE_ODBC, 0, 0, 0);
 //申请连接的内存
lrd_alloc_connection(&Con1, LRD_DBTYPE_ODBC, Ctx1, 0 /*Unused*/, 0);
 //打开连接,注意DRIVER就是上面安装的
lrd_open_connection(&Con1, LRD_DBTYPE_ODBC, "", "","", "DRIVER=MySQL ODBC 3.51 Driver;UID=bydapp;PWD=Rootuser;SERVER=10.66.64.20;DATABASE=bydfans; PORT=3306", Ctx1, 1, 0);
 //打开游标
lrd_open_cursor(&Csr1, Con1, 0);


lr_rendezvous("selectmysql");
lr_start_transaction("selectmysql");

 //Sql语句,注意1代表的意思是,立马执行
lrd_stmt(Csr1, "select n_user_id, c_user_accounts, c_user_password, c_user_name, c_user_phone, c_user_mail, c_user_status, c_user_reg, c_user_second, c_phone_token, c_account_weight_value, c_user_no "
               "from t_user_account "
               "WHERE ( c_user_accounts = 'wuguo' and c_user_password = 'e10adc3949ba59abbe56e057f20f883e' and c_user_status = '1' )",
          -1, 1, 0 /*None*/, 0);


lrd_stmt(Csr1, "select * from t_user_account", -1, 1, 0 /*None*/, 0);

trans_time=lr_get_transaction_duration( "selectmysql" ); //获得该SQL的执行时间

lr_output_message("start_select事务耗时 %f 秒", trans_time); //输出该时间
lr_end_transaction("selectmysql", LR_AUTO);


 //统计行数到count变量中
lrd_row_count(Csr1, &count, 0);
 //打印消息
lr_message("count= %d",count);
 //先关闭游标
lrd_close_cursor(&Csr1, 0);
 //再关闭连接
lrd_close_connection(&Con1, 0, 0);
 //释放连接,和alloc相呼应,否则有内存泄露
lrd_free_connection(&Con1, 0 /*Unused*/, 0);
 //再关闭上下文
lrd_close_context(&Ctx1, 0, 0);
 //完毕,返回0

 return 0;
 }
 

 

天猫 软件自动化测试开发

posted on 2014-03-23 18:02 zouhui 阅读(541) 评论(0)  编辑  收藏 所属分类: 2.软件测试 性能自动化

只有注册用户登录后才能发表评论。


网站导航:
 
<2014年3月>
2324252627281
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(2)

随笔分类(94)

随笔档案(94)

搜索

  •  

最新评论

阅读排行榜

评论排行榜