loadrunner通過odbc測mysql資料庫語句

來源:互聯網
上載者:User

標籤:效能測試   資料庫   loadrunner   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;
 } 
 

本文出自 “自動化測試開發” 部落格,請務必保留此出處http://3641932.blog.51cto.com/3631932/1885632

loadrunner通過odbc測mysql資料庫語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.