• Loadrunner 如何访问数据库


    在Loadrunner中也提供了C对数据库操作的相关功能函数,以下这些数据库功能函数只能用于Web Services协议。

    lr_db_connect

    连接数据库

    lr_db_disconnect

    断开数据库的连接

    lr_db_executeSQLStatement

    执行SQL语句

    lr_db_dataset_action

    对数据库执行操作

    lr_db_getValue

    从数据集中检索值

    各函数语法如下:

    lr_db_connect("StepName", "ConnectionString=<connection_string>", "ConnectionName=<connection_name>", "ConnectionType=<connection_type>", LAST);

    lr_db_disconnect("StepName=<step_name>", "ConnectionName=<connection_name>", LAST);

    lr_db_executeSQLStatement("StepName=<step_name>", "ConnectionName=<connection_name>", "SQLStatement=<statement>", ["DatasetName=<dataset_name>",] LAST);

    lr_db_dataset_action("StepName=<step_name>", "DatasetName=<dataset_name>", "Action=<action>", LAST);

    lr_db_getValue("StepName=<step_name>", "DatasetName=<dataset_name>", "Column=<column>", "Row=<row>", "OutParam=<output_parm>", LAST);

    下面以oracle数据库为例:

    Action()
    {
    int NumRows=0;
    int i=1;

    //建立数据库连接
    lr_db_connect("StepName=DatabaseConnection",
    "ConnectionString=Provider=OraOLEDB.Oracle.1;Password = test ;Persist Security Info=True; User ID = test ; Data Source = betadb ; Server = 172.19.188.191",
    "ConnectionName=InvDatabaseConnection",
    "ConnectionType=OLEDB",
    LAST);

    //执行SQL语句
    NumRows = lr_db_executeSQLStatement("StepName=PerformQuery",
    "ConnectionName=InvDatabaseConnection",
    "SQLStatement=SELECT cons_no,cons_id FROM c_cons where rownum<10",
    "DatasetName=MyDataset",
    LAST);
    lr_output_message(
    "The query returned %d rows.", NumRows);

    //打印出结果
    lr_db_dataset_action("StepName=PrintDataset",
    "DatasetName=MyDataset",
    "Action=PRINT",
    LAST);


    //利用循环检索数据值
    while (i<10) {
    lr_db_getvalue(
    "StepName=GetValue",
    "DatasetName=MyDataset",
    "Column=CONS_NO",
    "Row=next",
    "OutParam=MyOutputParam",
    LAST);
    lr_output_message(
    "The value is: %s", lr_eval_string("{MyOutputParam}") );
    i
    =i+1; }


    //释放结果
    lr_db_dataset_action("StepName=RemoveDataset",
    "DatasetName=MyDataset",
    "Action=REMOVE",
    LAST);


    //断开数据库连接
    lr_db_disconnect("StepName=Disconnect",
    "ConnectionName=InvDatabaseConnection",
    LAST);

    return 0;
    }

    运行后,输出信息如下:

    Virtual User Script started
    Starting action vuser_init.
    Ending action vuser_init.
    Running Vuser...
    Starting iteration 1.
    Starting action Action.
    Action.c(6): DB Connection "DatabaseConnection" started ... Wait ....
    Action.c(6): DB connection was successful
    Action.c(13): SQL Statement  execution "PerformQuery" started
    Action.c(13): SQL Statement  execution was successful
    Action.c(13): ================================================
    Action.c(18): The query returned 9 rows.
    Action.c(20): Dataset action "PrintDataset" started
    Action.c(20):
    Action.c(20): ******** Start printing ***********
    Action.c(20): Number of records in dataset  = 9
    Action.c(20): Num.   CONS_NO                  CONS_ID                 
    Action.c(20): =========================================================
    Action.c(20): 1      3096451321               310306247               
    Action.c(20): 2      3097730300               3376536                 
    Action.c(20): 3      0000265443               3376537                 
    Action.c(20): 4      0000265456               3376538                 
    Action.c(20): 5      0000265469               3376539                 
    Action.c(20): 6      0000265472               3376540                 
    Action.c(20): 7      3098976354               314348099               
    Action.c(20): 8      0000265498               3376542                 
    Action.c(20): 9      0000265502               3376543                 
    Action.c(20): ********End printing ***********
    Action.c(20):
    Action.c(20): Dataset action was successful
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 3096451321
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 3097730300
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 0000265443
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 0000265456
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 0000265469
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 0000265472
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 3098976354
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 0000265498
    Action.c(27): Get db value "GetValue" started
    Action.c(27): Get db value was successful
    Action.c(27): ================================================
    Action.c(33): The value is: 0000265502
    Action.c(36): Dataset action "RemoveDataset" started
    Action.c(36): Dataset action was successful
    Action.c(41): DB disconnect "Disconnect" started
    Action.c(41): DB disconnect was successful
    Action.c(41): ================================================
    Ending action Action.
    Ending iteration 1.
    Ending Vuser...
    Starting action vuser_end.
    Ending action vuser_end.
    Vuser Terminated.

    专注于自动化、性能研究,博客为原创,转载请注明文章来源于:http://www.cnblogs.com/Automation_software/ 只求在IT界有一个清闲的世界让我静心的去专研,不求功名利禄,只为心中的那份成就感及自我成长、自我实现的快感。
  • 相关阅读:
    嵌入式
    c语言
    c++的内存分配
    免费的Skype没有打败固定电话,而付费的移动电话却战胜了固定电话,免费看来并不是关键。在蓝光还没有彻底取代DVD的时候,在线视频出现了,同时颠覆了DVD和蓝光光盘,无论你的光盘容量变得如何大,都不能代表未来,只有在线才是未来。
    直到有了3G,用户才第一次体验到了永远在线的感觉,如果用手机上网也许比找个电源插座还简单,这就是在线的普及趋势。而3G只是个开始,4G、5G会让在线的速度更快更流畅。
    50多万年前的关键字是光明与黑暗,50多年前的关键字是数位和模拟,而今天的关键字是在线与离线。
    “大数据”这个名字叫错了,今天数据的意义并不在于有多“大”,真正有意思的是数据变得在线了。
    云计算是关于信任的生意,有人说他要做三年赚200亿美元的互联网项目,但他要依靠别人的云计算服务,没有这个勇气,是不可能创新的。
    做APP是别人的花园里弄盆栽,因为苹果和安卓已经圈了一个花园,你种点花草是没有问题的,但是想做点有生命力的东西,还是有挑战性的。
    私有云根本就称不上是云,云计算的本质是服务,如果不能够将计算资源规模化、大范围地进行共享,就根本算不上是云计算,传统IT巨头所谓的“私有云”就换汤不换药的升级版IT解决方案。
  • 原文地址:https://www.cnblogs.com/Automation_software/p/2093290.html
Copyright © 2020-2023  润新知