Download MetaTrader 5

Retrive single value from MySQL

To add comments, please log in or register
Interested in earning money via MQL5 Cloud Network? Enter your profile!
Ingvar Engelbrecht
4502
Ingvar Engelbrecht 2011.09.16 20:43 

I am struggling with retrieving data from MySQL. There are quite a few samples around both for MT4 and MT5. I have tried a few of them and they work.

But they all retrieve complete rows of data from MySQL. I want to retrieve single values with qualified SQL-statements. Something like "Select Level, Takeprofit from Table1 where TradeID equals zzzz"

Spent hours searching the web.

Ingvar Engelbrecht
4502
Ingvar Engelbrecht 2011.10.26 15:00  


After more work I got it working in MQL4 (Sort of)

I have tarnsformed the code to MQL5

I am using code posted on the web that includes ANSITOUNICODE UNICODETOANSI.

ansiquery=UNICODE2ANSI(query2);
 int length=StringLen(query2);

int res2 = mysql_real_query(mysql,ansiquery,length);

int res = mysql_store_result(mysql);

row = mysql_fetch_row(res);            //Only pick up first occurrence.

row = ANSI2UNICODE(row);

Now "row" should be "MYSQL_ROW". Whatever that is

in MQL4 I can get correct results by stripping of the first 8 bytes on row declared as "string"

in MQL5 I get garbage at the end sometimes and sometimes correct results doing the same

I have tried to find out how the MYSQL_ROW is constructed but not found it






investeo
4098
investeo 2011.10.26 15:59  
ingvar_e:


After more work I got it working in MQL4 (Sort of)

I have tarnsformed the code to MQL5

I am using code posted on the web that includes ANSITOUNICODE UNICODETOANSI.

ansiquery=UNICODE2ANSI(query2);
 int length=StringLen(query2);

int res2 = mysql_real_query(mysql,ansiquery,length);

int res = mysql_store_result(mysql);

row = mysql_fetch_row(res);            //Only pick up first occurrence.

row = ANSI2UNICODE(row);

Now "row" should be "MYSQL_ROW". Whatever that is

in MQL4 I can get correct results by stripping of the first 8 bytes on row declared as "string"

in MQL5 I get garbage at the end sometimes and sometimes correct results doing the same

I have tried to find out how the MYSQL_ROW is constructed but not found it






https://www.mql5.com/en/articles/69

cheers 

Practical Application Of Databases For Markets Analysis
  • 2010.05.18
  • Alexander
  • www.mql5.com
Working with data has become the main task for modern software - both for standalone and network applications. To solve this problem a specialized software were created. These are Database Management Systems (DBMS), that can structure, systematize and organize data for their computer storage and processing. As for trading, the most of analysts don't use databases in their work. But there are tasks, where such a solution would have to be handy. This article provides an example of indicators, that can save and load data from databases both with client-server and file-server architectures.
Ingvar Engelbrecht
4502
Ingvar Engelbrecht 2011.10.26 18:10  

investeo,

thanks, but how does that help me working with my MySQL database?

Ingvar Engelbrecht
4502
Ingvar Engelbrecht 2011.10.26 18:16  

To add pain to injury.

I decided to try the function "mysql_result" that supposedly will give me the result directly. Tried both in MQL4  and MQL5

the mysql_result is defined in the 5.5 ref manual and I am using libmysql.dll from the 5.5 distribution.  Neither MQL4 nor MQL5 can find

mysql_result in the libmysql.dll


Sony AK
24
Sony AK 2012.10.23 11:45  

Did you try EAX_Mysql script?

It available here https://www.mql5.com/en/code/855

With some code modification we can connect to MySQL database easily.

EAX_Mysql - MySQL library
  • votes: 10
  • 2012.08.22
  • Michael Schoen | English Russian Portuguese
  • www.mql5.com
This library allows an easy interface to MySQL.
To add comments, please log in or register