效能測試工具操作資料庫(二)-Loadrunner與oracle
阿新 • • 發佈:2019-01-01
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;
}