I. ODBC environment configuration
System environment:
WIN7 64-bit system
1. Installation: MySQL driver _mysql-connector-odbc-5.1.6-win32
2, 64-bit system, in this directory C:\Windows\SysWOW64 find Odbcad32.exe Run, configure the MySQL data source (if you are 32-bit, under C:\Windows\System32 path)
Second, the ODBC Protocol script writing
1, can be recorded:
Step: Install Sqldbx, start LR vugen, select ODBC protocol, and record.
Cons: Recording scripts are complex and difficult to understand, and playback is not good.
2. Handwriting Code:
Step: 1 Connect Database 2 Execute SQL statement 3 Close the connection with the following code:
#include "lrd.h" Action () {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 definition of the code if the recording script, there is a definition in vdf.h, while there are other files//If the handwriting script, you need to manually add, mainly to define a variety of variables <pre name= "code" class= "OBJC" >//Query row number unsigned long count=0; Initial Lrd_init (&initinfo, dbtypeversion); Open Context Lrd_open_context (&ctx1, LRD_DBTYPE_ODBC, 0, 0, 0); Application for Connected memory lrd_alloc_connection (&con1, Lrd_dbtype_odbc, Ctx1, 0/*unused*/, 0); Open the connection, note that driver is the lrd_open_connection installed above (&con1, LRD_DBTYPE_ODBC, "root", Lr_decrypt (" 559b4a806ccaaba6117ac18b9fcdc6ff3f9c67f70903 ")," New_mysql ", Lr_decrypt (" 559b4a80e "), Ctx1, 0, 0); <pre name= "code" class= "OBJC" ><p re name= "code" class= "OBJC" >//Executes the first SQL statement lrd_open_cursor (&CSR1, Con1, 0); Lrd_stmt (CSR1, "select StartTime from Answer_logs WHERE starttime= ' 1385439793 '",-1, 1, 0/*none*/, 0); Lrd_row_count (CSR1, &count, 0); Lr_message ("count=%d", count); Lrd_close_cursor (&CSR1, 0);
<pre name= "code" class= "OBJC" ><pre name= "code" class= "OBJC" > //execute second SQL statement lrd_open_cursor ( &CSR1, Con1, 0); Lrd_stmt (CSR1, "select Ip from Answer_logs WHERE ip= ' 49.5.3.173 '",-1, 1, 0/*none*/, 0); Lrd_row_count (CSR1, &count, 0); Lr_message ("count=%d", count);
<pre name= "code" class= "OBJC" > //execute third SQL statement lrd_open_cursor (&CSR1, Con1, 0); Lrd_stmt (CSR1, "select IssueID from Answer_logs WHERE issueid= ' 2 '",-1, 1, 0/*none*/, 0); Lrd_row_count (CSR1, &count, 0); Lr_message ("count=%d", count); Lrd_close_cursor (&CSR1, 0); Then close the connection 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 Lrd_close_context again (&ctx1, 0, 0); Finished, returns 0 return 0; }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MySQL database testing using the ODBC protocol of LR