51Testing软件测试网H0R9YO.Kd$B0A使用最新版的GetData.dll,可以对执行的sql语句进行参数化处理,51Testing软件测试网-QvXf6T;p
该dll新增加init_hstmt()以及disConnect_hstmt()两个API,51Testing软件测试网Za:eMU/b.@/L
init_hstmt()函数将传出一个long类型的hstmt变量,调用方式:
hN3`i5id0
A5z1JkF0long hstmt;
+N6K5aka;I B2br0init_hstmt(&hstmt);51Testing软件测试网%Bn N4M.tA
51Testing软件测试网L7G,m+?UUgS
disConnect_hstmt(hstmt);
*FW+Y[YG/~9@%~2^0下载地址:http://www.kernzhang.com/viewtopic.php?t=248
p7cq4L&QS0} _j A{/iQC0测试脚本如下:
E-ZPC4Cg n0vuser_init部分:
,F7r'c.L#v N:NtE3x0#include "web_api.h"51Testing软件测试网4eg]8|k3s~
#include "lrw_custom_body.h"
g)vB/hiw%\$n0Bs0r!zcp0Jyo#J9}\0vuser_init()51Testing软件测试网(E
fCD4Uc7j
{51Testing软件测试网i[d"H Z9z%dWp
int i=0;51Testing软件测试网"Sgl(g;}.c"x
lr_load_dll("GetData.dll");
U&o_L:Csf0i=init_db("DRIVER={SQL Server};SERVER=****;UID=***;PWD=***;DATABASE=****");51Testing软件测试网+w~
r T:P(E
if (i!=0)
rp3h1~7sm0{
+v#HI7M
}Y0 lr_error_message("init db error");
"{YnF,b0 return -1;51Testing软件测试网-UL | `L
}51Testing软件测试网2D-Z BWa4pW(d
return 0;51Testing软件测试网AZX&_;P
HX9|
} //判断初始化数据库是否执行成功,不成功,则输出错误信息51Testing软件测试网Pki"B;c6A
51Testing软件测试网q)HHb!u)`Action部分:51Testing软件测试网@3j|N%x,fE e
#include "web_api.h"51Testing软件测试网"b%@k3F/~X~o
51Testing软件测试网 eI.e#x.f!x,|)rM| {LkAction()51Testing软件测试网5g)e8g@c/Eq%c
{
&PHl4b@"A9opb0int i=0;51Testing软件测试网X7~mi]
o/D\Z^
long ll_hstmt;
vk%dQ+h'op0char SQLstatement[100];
qy'L#@7z0char * content = (char *)malloc(1024 * sizeof(char));51Testing软件测试网#I8k5C?8w#x3z
char * mobile = (char *)malloc(52 * sizeof(char));51Testing软件测试网.MKc6w3`2s
//malloc函数是分配一个内存块. 格式为void *malloc(size_tnum_bytes);51Testing软件测试网mc-VQp/zr
I _
num_bytes是指分配的内存块的大小。51Testing软件测试网$tnUQ2Y7r0V(F
init_hstmt(&ll_hstmt);
X)aTN0o~0
6o6x:^7|Ji0strcpy(SQLstatement,lr_eval_string("{NewParam}")); //把sql语句参数化,参数设置属性如下图51Testing软件测试网jj0WA"P*vpRc'N
//lr_eval_string函数是用一个指定参数替换当前值;
strcpy函数的功能是把lr_eval_string("{NewParam}")拷贝到SQLstatement。
51Testing软件测试网
uQ3B?\:Dh
execSQL(SQLstatement,ll_hstmt);
(J:ta'Ot;lE/j0bindCol(1,content,"c",77,ll_hstmt);
I+F
YN&GIm N/~
x6Z0bindCol(2,mobile,"c",12,ll_hstmt);51Testing软件测试网tu+@Y9H6y+hO_
.d:N)i4H_)L6g|0while (i!=100)
7b?;le6NkX0{51Testing软件测试网;@g7g [)_,Q
i=fetchData(ll_hstmt);
N W^A]"f.AOd2C~,Q0if(i!=100)
#a)Vt E*]7B;W0{
v(X:zxm6m(hUd0 lr_output_message("mobile=%s",mobile);
lr_output_message("content=%s",content);
1a"~'e
]R7U4i^1f0}51Testing软件测试网L;xL9Y"t6aM
}51Testing软件测试网O"M-Jr Fa
disConnect_hstmt(ll_hstmt);51Testing软件测试网$N9oi&|y7rmr
free(content); //释放内存51Testing软件测试网CH#|e;Fv5u
free(mobile);
/b.xsb'q{.^ r0return 0;51Testing软件测试网-M8feBR-P%g:O+X
}
SZ[5c_zB0vuser_end部分:
NU0R.M&B(m7U9U6Dc@0#include "web_api.h"
3RF@.]Tpg(^`0^ {4w nv,E0vuser_end()
!v P.?[5Uq0{51Testing软件测试网J(dD@"K:K$mE
disConnect();51Testing软件测试网D'f:[Y
^,`,Oj
return 0;
G7tDd6to0}
y5}3~2~4Q-i|!|#t051Testing软件测试网0H:L tF.LG2Vdy
51Testing软件测试网!g!k%dB:CFr.W'w备注:由于参数文件中有2条sql语句,故在运行脚本时,应设置迭代次数为2次。
'\i/LP
kVCfv[f o0参数属性:
!Y7T(l&j1f}| s0
)g2fY,N,CJ:n
p0