loadrunner通过odbc测mysql数据库语句
#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;
}
最新文章
- 抽象类和抽象方法(关键字abstract)
- win 7安装 linux
- 设置搜狗输入法在任何时候按左右两侧的shift激活
- Ext学习-高级组件介绍
- ImageButton如何让图片按比例缩放不被拉伸
- poj 2559 Largest Rectangle in a Histogram (单调栈)
- ltrace killed by SIGTRAP
- chgrp命令
- css首行缩进两个字符串
- hdu Color the ball
- uptime命令具体解释——linux性能分析
- 201521123070 《JAVA程序设计》第12周学习总结
- Linux端口被占用的解决(附Python专版)
- springboot 项目中读取资源文件内容 如图片、文档文件
- python 模块之platform模块(基本了解)
- pytest文档21-pytest-html报告优化(nodeid中文显示[\u6350\u52a9\u6211\u4eec]问题解决)
- 深入浅出SharePoint2012——安装Report Service
- java中error和exception
- BZOJ1086 SCOI2005王室联邦
- 九度OJ 上剑指 offer 习题目录