wmxli 发表于 2006-11-23 18:28:32

winrunner 连接数据库的问题

我现在有一个问题:
1.从EXCEL中读取数据BILL_ID;
2.然后根据BILL_ID到数据库中查询OS_STATUS
3.根据OS_STATUS不同值,执行不同的录制脚本 ,

在winrunner 中怎么实现第2步,第3步?sdlkfj9

InfoTester 发表于 2006-11-24 11:41:47

连接数据库小结

如果你的数据库是SQL server.你可以把下列代码复制到你的程序中,并按照注释内容做一些相应的改动。
public OS_STATUS,BILL_ID,recorder_number=0;
while(!recorder_number){
BILL_ID = create_input_dialog("Please give your bill ID");
# Here you can input your Bill_ID. If Bill_ID has been assigned a value,say,from the access,this step is not nessessary.
sql = "select OS_STATUS from tableName where BILL_ID="&BILL_ID;
db_connect("ConnectSample","driver=sql server;server=prcsgifs03;database=CNSMS;uid=sa;pwd=sa",30);
# In the case of choosing SQL server as the database, please refer driver as sql,server as your server name,so do you database,userId and password
db_execute_query("ConnectSample",sql,recorder_number);
#recorder_number is the number of records returnded from the database
if(recorder_number==1){
OS_STATUS = db_get_field_value("ConnectSample","#"&i,"OS_STATUS");
switch(OS_STATUS){
   case "STATU1":
    call statu1();
   case "STATU2":
    call statu2();
   #...
   default:
   choice = create_list_dialog("Alert!","Do you want continue?","YES,NO");
   if(choice=="YES"){
    recorder_number = 0;
    continue;
   }
   else
    break;
}

}
else if(recorder_number==0)
continue;
else
report_msg("There are more then one OS_STATUS mapping to one Bill ID!");
}
db_disconnect("ConnectSample");




##################################################3
如果你的数据库是Access,只需设置好你的DSN,然后将
db_connect("ConnectSample","driver=sql server;server=prcsgifs03;database=CNSMS;uid=sa;pwd=sa",30);
这句改为
db_connet("ConnectSample","DNS=youdnsName",30);
然后,sql改为
sql = "select OS_STATUS from tableName where BILL_ID="&"'"&BILL_ID&"'";


#######################################################
由于你提供的信息不详细,我没有对代码进行验证。如有疑问可以提供代码或者跟贴。

foxmishy 发表于 2006-11-24 13:43:00

关注。sdlkfj1

wmxli 发表于 2006-11-28 13:17:37

谢谢,我试试:)

谢谢,我试试:)

wmxli 发表于 2006-11-28 15:11:03

现在又有一个问题

我从EXECL中参数化的数据,怎么在winrunner中做为变量应用
比如:
edit_set ("txtBillId", ddt_val(table,"bill_id"));
其中bill_id是参数化execl中的一个字段

我想把他作为SQL中的一个变量
比如
select * from id_map where bill_id="bill_id"

各位大侠知道怎么实现吗?sdlkfj5

wmxli 发表于 2006-11-28 16:35:42

上面的问题,已经解决拉

利用函数ddt_value(table,bill_id)就可以解决上面的问题sdlkfj3
页: [1]
查看完整版本: winrunner 连接数据库的问题