LoadRunner logging MySQL database statements via ODBC

Source: Internet
Author: User

#include "Lrd.h"
Action ()
{
Double trans_time; Defines a double type variable to hold the transaction execution time

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;
The above defined code is defined in Vdf.h if the script is recorded, and there are some other files
If you have a handwritten script, you need to add it manually, mostly by defining variables
Number of rows queried
unsigned long count=0;


Initial
Lrd_init (&initinfo, dbtypeversion);
Open context
Lrd_open_context (&ctx1, LRD_DBTYPE_ODBC, 0, 0, 0);
Request a connected memory
Lrd_alloc_connection (&con1, Lrd_dbtype_odbc, Ctx1, 0/*unused*/, 0);
Open the connection, note that the driver is installed above
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);
Open cursor
Lrd_open_cursor (&CSR1, Con1, 0);


Lr_rendezvous ("Selectmysql");
Lr_start_transaction ("Selectmysql");

SQL statement, note that 1 means to execute immediately
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"); Get the execution time of the SQL

Lr_output_message ("Start_select Transaction time%f seconds", trans_time); Output this time
Lr_end_transaction ("Selectmysql", Lr_auto);


Counting rows to the count variable
Lrd_row_count (CSR1, &count, 0);
Print messages
Lr_message ("count=%d", count);
Close the cursor first
Lrd_close_cursor (&CSR1, 0);
Close the connection again
Lrd_close_connection (&con1, 0, 0);
Release the connection, and echo the alloc, otherwise there is a memory leak
Lrd_free_connection (&con1, 0/*unused*/, 0);
Close the context again
Lrd_close_context (&ctx1, 0, 0);
Finished, return 0

return 0;
}


Http://product.dangdang.com/24157493.html

This article is from the "Automated Test development" blog, so be sure to keep this source http://3641932.blog.51cto.com/3631932/1885617

LoadRunner logging MySQL database statements via ODBC

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.