版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎访问我的博客 https://blog.csdn.net/smooth00/article/details/67631769
1、Loadrunner支持oracle协议,可以选择协议录制方式,或手写脚本方式,本文讲的手写脚本方式,简洁方便。
2、vuser_init文件代码(连接全放到init中,因为连接耗时耗资源,以保证性能测试时少连接):
vuser_init()
{
lrd_init(&InitInfo, DBTypeVersion);
lrd_initialize_db(LRD_DBTYPE_ORACLE, 2, 0);
lrd_env_init(LRD_DBTYPE_ORACLE, &OraEnv1, 0, 0);
lrd_ora8_handle_alloc(OraEnv1, SERVER, &OraSrv1, 0);
lrd_ora8_handle_alloc(OraEnv1, SVCCTX, &OraSvc1, 0);
lrd_ora8_handle_alloc(OraEnv1, SESSION, &OraSes1, 0);
lrd_ora8_handle_alloc(OraEnv1, SESSION, &OraSes2, 0);
//lrd_server_attach(OraSrv1, "qa70/orcl", 9, 0, 0);
lrd_server_attach(OraSrv1, "qa70", -1, 0, 0);//lrd_server_attach(OraSrv1, "qa70", 4, 0, 0)
lrd_ora8_attr_set_from_handle(OraSvc1, SERVER, OraSrv1, 0, 0);
lrd_ora8_attr_set(OraSes1, USERNAME, "xtjg_test", -1, 0);//lr_decrypt("58b3e02f8ba0e4201c2c")
//lrd_ora8_attr_set(OraSes1, PASSWORD, lr_decrypt("5487fff63e812b81"), -1, 0);
lrd_ora8_attr_set(OraSes1, PASSWORD, "123456", -1, 0);
lrd_ora8_attr_set_from_handle(OraSvc1, SESSION, OraSes1, 0, 0);
lrd_session_begin(OraSvc1, OraSes1, 1, 0, 0);
lrd_ora8_handle_alloc(OraEnv1, STMT, &OraStm1, 0);
return 0;
}
2、action文件代码
Action()
{
char *test;
lr_load_dll("ole32.dll"); //引用windows生成GUID的API
test=lr_guid_gen("GUID"); //调用上面lr_guid_gen()方法
lr_save_string(test,"GUID");
lr_start_transaction("test-insert");
lrd_ora8_handle_alloc(OraEnv1, STMT, &OraStm7, 0);
lrd_ora8_stmt(OraStm7, "insert into ent_unionpunish "
" (id, limlow, lowdes, limdatefrom, limdateto, senddep, senddepname, recdep, recdepname, infotype,"
"pripid, remark, organizationid, dataproway, errcode, subdate, feedbackdate, hanobjtype,"
"persontype, name, certype, cerno, entname, uniscid, regno)"
"values "
"('{GUID}', 'v_limlow', 'v_lowdes', to_date('2016-12-11','yyyy/mm/dd'),"
"to_date('2016-12-11','yyyy/mm/dd'),"
"'v_senddep', 'v_senddepname', 'v_recdep', 'v_recdepname', 'v_infotype', 'v_pripid', 'v_remark',"
"'v_organizationid', 'v_dataproway', 'v_errcode',"
"to_date('2016-12-11','yyyy/mm/dd'),to_date('2016-12-11','yyyy/mm/dd'), '1',"
"'v_persontype', 'v_name', 'v_certype', 'v_cerno', 'v_entname', 'v_uniscid', 'v_regno')", 1, 0, 0);
/*lrd_ora8_stmt(OraStm7, "update ent_unionpunish set hanobjtype=1 where name='smooth", 1, 0, 0);*/
lrd_ora8_exec(OraSvc1, OraStm7, 1, 0, &uliRowsProcessed, 0, 0, 0, 0, 0);
lrd_handle_free(&OraStm7, 0);
lr_end_transaction("test-insert", LR_AUTO);
lr_start_transaction("test-select");
lrd_ora8_handle_alloc(OraEnv1, STMT, &OraStm7, 0);
lrd_ora8_stmt(OraStm7, "select * from ry_jbxx,dz_zzxx where dz_zzxx.zzbh=ry_jbxx.RYZZBH and "
" ry_jbxx.xm='{RYDZ_XM}' and ry_jbxx.csrq='{RYDZ_CSRQ}'", 1, 32, 0);
lrd_ora8_exec(OraSvc1, OraStm7, 0, 0, &uliRowsProcessed, 0, 0, 0, 0, 0);//注意参数与insert的区别
lrd_handle_free(&OraStm7, 0);
lr_end_transaction("test-select", LR_AUTO);
return 0;
}
3、vuser_end文件代码
vuser_end()
{
lrd_session_end(OraSvc1, OraSes1, 0, 0);
lrd_server_detach(OraSrv1, 0, 0);
lrd_handle_free(&OraEnv1, 0);
return 0;
}