Download MQLMySQL Technical Reference MQL4 PDF

TitleMQLMySQL Technical Reference MQL4
File Size123.7 KB
Total Pages7
Document Text Contents
Page 2

http://dev.mysql.com/doc/refman/5.0/en/c-api-functions.html

Page 6

6

string vServer = ReadIni("C:\\Metatrader4\\MQL4\\Experts\\MyConnection.ini", "MYSQL", "Server");

2. Using multi-statements query
For transferring big arrays of data from Metatrader to database and reduce the
number of calls and network traffic, you may use multi-statements queries. It looks
like usual queries separated by semicolon “;”:

string Query = "INSERT INTO my_table(field1) VALUES (1); UPDATE my_table SET field1 = 2;";

To execute such query you can use MySqlExecute function. But you have to open
the database connection with pClientFlag = CLIENT_MULTI_STATEMENTS (decimal
value 65536). For example:

int DB = MySqlConnect(vHost, vUser, vPass, vDatabase, 3306, "", CLIENT_MULTI_STATEMENTS);

Here is a list of possible pClientFlag constants:
#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
#define CLIENT_LONG_FLAG 4 /* Get all column flags */
#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
#define CLIENT_COMPRESS 32 /* Can use compression protocol */
#define CLIENT_ODBC 64 /* Odbc client */
#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
#define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */
#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
#define CLIENT_SSL 2048 /* Switch to SSL after handshake */
#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */
#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
#define CLIENT_MULTI_STATEMENTS 65536 /* Enable/disable multi-stmt support */
#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */
#define CLIENT_PS_MULTI_RESULTS 262144 /* Multi-results in PS-protocol */

Examples

Include MQLMySQL into your MQL project:

#include "..\Include\MqlMySql.mqh"

Connection to MySQL:

int DBConnection = MySqlConnect("localhost", "root", "ioctrl", "metatrader", 3306, "", 0);
if (DBConnection==-1)
{
Print("Error #", MySqlErrorNumber, ": ", MySqlErrorDescription);
return (1);
}
else Print ("Connected!");

Execution of non-SELECT statements:

string query;
query = "INSERT INTO Metatrader.Ticks_" + Symbol() + " (price_ask, price_bid, spread) " +
"VALUES (" + DoubleToStr(Ask, Digits) + ", " + DoubleToStr(Bid, Digits) + ", " +
DoubleToStr(((Ask - Bid) / Point), 0) + ")";
if (!MySqlExecute(DBConnection, query))
{
Comment("Error #", MySqlErrorNumber, ": ", MySqlErrorDescription,
"\nProblem with query: ",query);

Similer Documents