Last year I was working on an EA that relies on calling data from MySQL using "mql4-mysql.mqh" include and "libmysql.dll" dll library.
Due to life and what not I had to put it on the back burner for a while. I fired it up again this week to find it crashing the terminal.
I have tracked it down to the mql4_mysql_ansi2unicode function which is called from the include file.
For the life of me I can't work out what has happened.
Code: Select all
void LastCandle()
{
Print("Last candle");
string query =StringConcatenate("Select concat ('->',concat_ws ('->',CAST(MQLTime as char))) from eurusd_m1 ORDER BY MQLTime DESC LIMIT 1;"); // take the first candle latest DB
Print("query = ",query);
int row="";
string ultimacandela="";
int length = 0;
uchar queryChar[];
StringToCharArray(query, queryChar);
length = StringLen (query);
mysql_real_query (dbConnectId, queryChar, length);
int myerr = mysql_errno (dbConnectId);
if (myerr> 0)
Print ("error =", myerr);
int result = mysql_store_result (dbConnectId);
Print("result=",result);
int numOfRows = mysql_num_rows (result);
Print("numrows=",numOfRows);
if (numOfRows> 0)
{
row = mysql_fetch_row (result);
Print("row=",row);
row = mql4_mysql_ansi2unicode(row);
Print("ansiiRow=",row);
row = StringTrimLeft(row);
Print("TrimmedANSI=",row);
row = StringSubstr(row,8,80);
Print("row2 = ",row);
}
mysql_free_result (result);
return;
}Cheers,
BobbyT
Edit: I should probably say that there are no issues connecting to the database nor writing data to it. In fact, the above function has a block removed which adds all the available data when there is non present in the target table. What code is left is meant to retrieve the datatime stamp of the last bar entered to the database. This value is then used by other functions to back fill any missing data.