#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;
}
---------------------
转载,仅作分享,侵删
作者:fin_123
原文:https://blog.csdn.net/zouhui1003it/article/details/53861926
|
|