Retrive single value from MySQL

 

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.

 


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






 
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.
 

investeo,

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

 

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

 

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.
Reason: