LR系列--LR指令碼中動態擷取資料庫的值作為參數進行處理__資料庫

來源:互聯網
上載者:User
 

使用最新版的GetData.dll,可以對執行的sql語句進行參數化處理,
該dll新增加init_hstmt()以及disConnect_hstmt()兩個API,
init_hstmt()函數將傳出一個long類型的hstmt變數,調用方式:
long hstmt;
init_hstmt(&hstmt);
disConnect_hstmt(hstmt);
下載地址:http://www.kernzhang.com/viewtopic.php?t=248

測試指令碼如下:
vuser_init部分:

#include "web_api.h"

#include "lrw_custom_body.h"

vuser_init(){
int i=0;
lr_load_dll("GetData.dll");
i=init_db("DRIVER={SQL Server};SERVER=****;UID=***;PWD=***;DATABASE=****");
if (i!=0)

   lr_error_message("init db error");
 return -1;

 return 0;

}
//判斷初始化資料庫是否執行成功,不成功,則輸出錯誤資訊

Action部分:

#include "web_api.h"

action 

{

int i=0;
long ll_hstmt;
char SQLstatement[100];
char * content = (char *)malloc(1024 * sizeof(char));

char * mobile =  (char *)malloc(52 * sizeof(char));

  //malloc函數是分配一個記憶體塊. 格式為void *malloc(size_tnum_bytes);
  
num_bytes是指分配的記憶體塊的大小。 init_hstmt(&ll_hstmt); strcpy(SQLstatement,lr_eval_string(" {NewParam}"));  //把sql語句參數化,參數設定屬性如下圖   //lr_eval_string函數是用一個指定參數替換當前值;     strcpy函數的功能是把lr_eval_string("{NewParam}")拷貝到SQLstatement。
execSQL(SQLstatement,ll_hstmt); bindCol(1,content,"c",77,ll_hstmt);
bindCol(2,mobile,"c",12,ll_hstmt);
while (i!=100) {

if(i!=100)
{
 lr_output_message("mobile=%s",mobile);  lr_output_message("content=%s",content); 
} }
disConnect_hstmt(ll_hstmt); free(content);  //釋放記憶體 free(mobile); return 0;
}

vuser_end部分:
#include "web_api.h"

vuser_end()

{

   disConnect();

return 0;

}

備忘:由於參數檔案中有2條sql語句,故在運行指令碼時,應設定迭代次數為2次。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.