#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;
//Above defined code if the recording script is defined in Vdf.h, and there are other files
//If the handwriting script, you need to manually add, mainly to define a variety of 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);
//apply for 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 Cursors
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 takes%f seconds", trans_time);//Outputs the time
lr_end_transaction ("Selectmysql", Lr_auto);
//Count rows to count variable
Lrd_row_count (CSR1, &count, 0);
//Print Messages
lr_message ("count=%d", count);
//close cursor First
lrd_close_cursor (&CSR1, 0);
//Close the connection again
lrd_close_connection (&con1, 0, 0);
//Release connection, echo with Alloc, otherwise memory leak
lrd_free_connection (&con1, 0/*unused*/, 0);
//Close context again
Lrd_close_context (&ctx1, 0, 0);
//finished, return 0
return 0;
}
This article is from the "Automated Test development" blog, so be sure to keep this source http://3641932.blog.51cto.com/3631932/1885632
LoadRunner logging MySQL database statements via ODBC