Discussion of article "How to Access the MySQL Database from MQL5 (MQL4)" - page 7
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Ok, I see you have written an expert advisor for this purposes, and it is written without recommendations I've posted in article.
So, let's move step by step: 1.
1. The calling of " DB = cMySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag); " should be made inside OnInit() standard function instead of OnTick(). 2.
2. You are uses cMySqlConnect - it's imported function form DLL, you have to use MySqlConnect function instead of cMySqlConnect function !
3. You have to call MySqlDisconnect function inside OnDeinit() stundard function.
4. You have to check database connection identifier inside OnTick() standard function to be sure that connect was successful.
Finally it will looks like.
Ok, I see you have written an expert advisor for this purposes, and it is written without recommendations I've posted in article.
So, let's move step by step: 1.
1. The calling of " DB = cMySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag); " should be made inside OnInit() standard function instead of OnTick(). 2.
2. You are uses cMySqlConnect - it's imported function form DLL, you have to use MySqlConnect function instead of cMySqlConnect function !
3. You have to call MySqlDisconnect function inside OnDeinit() stundard function.
4. You have to check database connection identifier inside OnTick() standard function to be sure that connect was successful.
Finally it will looks like.
Ok, I see you have written an expert advisor for this purposes, and it is written without recommendations I've posted in article.
So, let's move step by step: 1.
1. The calling of " DB = cMySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag); " should be made inside OnInit() standard function instead of OnTick(). 2.
2. You are uses cMySqlConnect - it's imported function form DLL, you have to use MySqlConnect function instead of cMySqlConnect function !
3. You have to call MySqlDisconnect function inside OnDeinit() stundard function.
4. You have to check database connection identifier inside OnTick() standard function to be sure that connect was successful.
Finally it will looks like.
I changed step by step, but the problem is still exist when use the expert in one mt4 for four or more symbols. it print " Access violation read to 0x0000000B in '... .MQLMySQL.dll'
"
the code is followed
<--
#include <MQLMySQL.mqh
int MySqlErrorNumber; // recent MySQL error number
string MySqlErrorDescription; // error description
//+------------------------------------------------------------------+
//| Expert initialisation function & nbsp; |
//+------------------------------------------------------------------+
int OnInit()
OnInit(); int OnInit()
EventSetTimer(timeSeconds);
DB = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag); if( DB == -1 )
if( DB == -1 )
{
Print("Database is not connected ..."); if( DB == -1 ) { print("Database is not connected ... "); }
}
return(INIT_SUCCEEDED); }
}
//+------------------------------------------------------------------+
//| Expert deinitialisation function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
MySqlDisconnect(DB);
EventKillTimer();
ObjectsDeleteAll();
}
void OnTimer()
{
//Alert(TimeCurrent());
OnTick();
}
//+------------------------------------------------------------------+
//| Expert tick function & nbsp; |
//+------------------------------------------------------------------+
void OnTick()
{
if( DB == -1 )
{
Alert("Database is not connected ... "); return; { Alert("Database is not connected ...")
return; }
}
if( IsExpertEnabled() && IsConnected() && AccountNumber() > 0 && DB ! = -1 )
{
int account = AccountNumber();
string symbol = Symbol(); if( cmd !
if( cmd ! = "" && cmd ! = NULL )
{
symbol = cmd; }
}
symbolOrder = symbol + "_table";
double spread = (Ask - Bid); } symbolOrder = symbol + "_table"; }
admission = spread*MathPow(10, Digits).
//int DB = cMySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
Query = "SELECT * FROM " + symbol + " where AccountNumber = " + (string)AccountNumber();
//Print(Query);
int Cursor1 = MySqlCursorOpen(DB, Query);
if (Cursor1 >= 0)
{
int Rows1 = MySqlCursorRows(Cursor1); int Cursor1 = MySqlCursorOpen(DB, Query); if (Cursor1 >= 0)
int dataRows1 = Rows1;
//Alert(dataRows);
if( dataRows1 > 0 )
{
Query = "update " + symbol + " set Bid = " + (string)Bid + ", Ask = " + ( string)Ask
+ ", Spread = " + DoubleToStr(spread, Digits)
+ ", Time = '" + TimeToString(TimeLocal(), TIME_DATE|TIME_SECONDS ) + "' where AccountNumber = "
+ (string)account; // + "' and Symbol = '" + symbol + "'".
MySqlExecute(DB, Query);
MySqlCursorClose(Cursor1);
}
else if( dataRows1 == 0 )
{
Query = "CREATE TABLE IF NOT EXISTS " + symbol + " (id int NOT NULL AUTO_ INCREMENT PRIMARY KEY, AccountNumber int, "
+ "Symbol char(20), Bid double, Ask double, Spread double,"
+ "Memo char(50), "
+ "Time datetime) ENGINE=MEMORY DEFAULT CHARSET=utf8 ";
MySqlExecute(DB, Query);
Query = "INSERT INTO " + symbol + "(AccountNumber, Symbol, Bid, Ask, Spread. Memo, Time) VALUES ("
+ (string)account + ", '" + symbol + "', "+(string)Bid+","+ (string)Ask + ", "
+ DoubleToStr(spread, Digits)
+ ", '" + (string)AccountCompany()
+ "', \'"+TimeToString(TimeLocal(), TIME_DATE|TIME_SECONDS)+"\')"";
if(MySqlExecute(DB, Query) ! = true )
{
//Query = "DROP TABLE IF EXISTS `data_table`";
//MySqlExecute(DB, Query);
Query = "CREATE TABLE IF NOT EXISTS " + symbol + "(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AccountNumber int, "
+ "Symbol char(20), Bid double, Ask double, Spread double,"
+ "Memo char(50), "
+ "Time datetime) ENGINE=MEMORY DEFAULT CHARSET= utf8 ";
MySqlExecute(DB, Query);
}
}
MySqlCursorClose(Cursor1); // NEVER FORGET TO CLOSE CURSOR !!!!
}
}
}
-->
Ok, I see you have written an expert advisor for this purposes, and it is written without recommendations I've posted in article.
So, let's move step by step: 1.
1. The calling of " DB = cMySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag); " should be made inside OnInit() standard function instead of OnTick(). 2.
2. You are uses cMySqlConnect - it's imported function form DLL, you have to use MySqlConnect function instead of cMySqlConnect function !
3. You have to call MySqlDisconnect function inside OnDeinit() stundard function.
4. You have to check database connection identifier inside OnTick() standard function to be sure that connect was successful.
Finally it will looks like.
The problem is it can't use in one mt4 for more than two symbols, if use in only one symbol, it's normal. When use in four or more, it's run fine, but after a few minutes, it prints the problem "OnTick()". minutes, it prints the problem "Access violation read to 0x0000000B in '...MQLMySQL.db'". .MQLMySQL.dll'"
The exambles is all scripts, it's run only one times, You may try one experts call the dll in four or more symbols in one or two mt4, You may find the problem.
Would be the dll needs a memeoy release or garbe collection?
CRT to dump leaks followi ng static data destruction, and this causes ο spurious leak reports for objects which allocated memory before MFC was initialised and which thus are destroyed after MFC nbsp;
spurious leak reports for objects which allocated memory before MFC
was initialised and which thus are destroyed after MFC exits. This is
commonly observed when using the MFC DLL in a program that also uses
the C++ runtime DLL.
Hello once again.
Based on the code you have provided I guess you are new to MQL.
I'm sorry, I have no time to teach you, but I have time for testing the software I've developed.
I'm sorry, I have no time to teach you, but I have time for testing the software I've developed. So, here are logs attached.
Have build testing EA for you, based on your logic: each table defined for each currency pair and can keep the online market data for different accounts.
You can inspect the logs, no one error "Access violation..." was raised. You can inspect the logs, no one error "Access violation..." was raised.
The problem is not in MQLMySQL library.
Testing EA.
This is right logic of using the library.
Due to optimisation you can even do not use SELECT statement, just execute UPDATE statement , than check if (MySqlRowsAffected()==0) means no one row was You have ~100% of updates, so apply the INSERT statement.
You have ~100% of updates, so this workaround can increase the performance and reduce network traffik.
And at the end, full source codes of project (include DLL development) has been attached to the article, you may change it on your own way.
If you fill that the problem in MqlMySQL.DLL anyway, you can debug it and fix for yourself.
Best wishes, Eugene
Eugene
Great work, Thank you very much Eugeniy .
Your codes help me so much, i can save so much time. I tried to do INSERT, SELECT, UPDATE and DELETE query successfully. If i am not wrong, the "Cursor" is needed only for SELECT query only ??
= pedma
Great work, Thank you very much Eugeniy .
Your codes help me so much, i can save so much time. I tried to do INSERT, SELECT, UPDATE and DELETE query successfully. If i am not wrong, the "Cursor" is needed only for SELECT query only ??
= pedma
Exactly man!
The cursors used only for data selection because we have to receive data from db into MQL variable, not just to send the sql command to database.
I'm glad that my solution helps you.
Good luck,
Eugene
Hi Eugene,
I was just wondering if you still do paid development projects as I am looking to create a remote trade copier which is integrated into an EA that I will be selling?
I looked on Upwork and you don't appear to have completed any freelancer projects recently.
I had a go myself using the library you created, but it didn't turn out too well. Though I'm sure it would be easy for someone with your programming ability!
Thanks in advance,
James
Hi Eugene,
I was just wondering if you still do paid development projects as I am looking to create a remote trade copier which is integrated into an EA that I will be selling?
I looked on Upwork and you don't appear to have completed any freelancer projects recently.
I had a go myself using the library you created, but it didn't turn out too well. Though I'm sure it would be easy for someone with your programming ability!
Thanks in advance,
James
Hello James,
I'm working at Upwork only on one big project currently. So, have no much free time nowadays. What's the problem you have with libs? How can I help you?