Discussion of article "How to Access the MySQL Database from MQL5 (MQL4)" - page 2

 

Thanks for this new approach! I have tried different solutions but this one looks the best so far. I made a minor addition to your library where I return the number of fields for a SELECT query, using mysql_num_fields, so that I know how many fields I need to process and return in the MQL side. Thanks so much again for putting this together, really helped!!

MQL Code:

int fields = MySqlNumFields(cursor);
for (int j=0; j<fields;j++)
{
    data[j] = MySqlGetFieldAsString(cursor, j);
}
 
sokramm:

Thanks for this new approach! I have tried different solutions but this one looks the best so far. I made a minor addition to your library where I return the number of fields for a SELECT query, using mysql_num_fields, so that I know how many fields I need to process and return in the MQL side. Thanks so much again for putting this together, really helped!!

Thanks for the kind words. It's basic solution and it keeps general functionality I'm using in real.

I've used next rules during development of this solution: robustness, easy to study, simple using and minimal support.

Sure, you may change this project and add any addition functions regarding your project needs.

Good luck,

Eugene 

 

Hello friends,

Well, if you like this solution and trying it for real projects (not just for fun) I have an update.

I'm starting to write new article about working with different databases, such as MS SQL Server, MS Access, Oracle, IBM DB/2, PostgreSQL.

The decision would be robust and easy to use like this one, but I have no time to complete it.

So, if you want to support this project can you send a few $$ over paypal for me: e.a.lugovoy@gmail.com

The amount of sum doesn't matter, I just would like to know is such decision really needs to be completed. 

Thank you all,

Eugene 

 

hello,Eugeniy Lugovoy~


I want to know why ‘ MySqlGetFieldAsDouble(Cursor, 3);’ can‘t write its value to data[i]?


  Print("data[i]",data[3]);——always displa 0.0.    what's wrong ? thank you sir!



     for (i=0; i<Rows; i++)
         if (MySqlCursorFetchRow(Cursor))
        
         {

           double data[] ;

          ArrayResize(data,Rows); 

          data[i]= MySqlGetFieldAsDouble(Cursor, 3);

          Print("data[i]",data[3]);
        }

Person - schema.org
  • schema.org
PropertyExpected TypeDescription Properties from Person The Global Location Number (GLN, sometimes also referred to as International Location Number or ILN) of the respective organization, person, or place. The GLN is a 13-digit number used to identify parties and physical locations. A count of a specific user interactions...
 
elugovoy:

Hello friends,

Well, if you like this solution and trying it for real projects (not just for fun) I have an update.

I'm starting to write new article about working with different databases, such as MS SQL Server, MS Access, Oracle, IBM DB/2, PostgreSQL.

The decision would be robust and easy to use like this one, but I have no time to complete it.

So, if you want to support this project can you send a few $$ over paypal for me: e.a.lugovoy@gmail.com

The amount of sum doesn't matter, I just would like to know is such decision really needs to be completed. 

Thank you all,

Eugene 

in sometimes,array is necessary——for example ,we need to match the data to a specify date(of the tick)——it may be relate to algorithm that is convenient to make it in array than MYSQL。can you give me a help sir?thanks a lot~!
 
illman:

hello,Eugeniy Lugovoy~

I want to know why ‘ MySqlGetFieldAsDouble(Cursor, 3);’ can‘t write its value to data[i]?

Print("data[i]",data[3]);——always displa 0.0.    what's wrong ? thank you sir!

for (i=0; i<Rows; i++)

        if (MySqlCursorFetchRow(Cursor))
        
         {

           double data[] ;

          ArrayResize(data,Rows); 

          data[i]= MySqlGetFieldAsDouble(Cursor, 3);

          Print("data[i]",data[3]);
        }

You are trying to define array every time in cycle and print empty array item.

Try this:

// I guess the Rows gets number of rows already before this workaround.
double data[];
ArrayResize(data, Rows);  

for (i=0; i<Rows; i++)
    {
     if (MySqlCursorFetchRow(Cursor))
        {
          data[i]= MySqlGetFieldAsDouble(Cursor, 3);
        }
    }

// here you'll get filled array "data"
Print("data[",3,"]",data[3]);

So, you have to define array once before fetching cycle, then resize, and then write routine for getting data.

By the way, the number 3 in  MySqlGetFieldAsDouble(Cursor, 3); means 4th column in SELECT list, because the numeration starts with 0, i.e. SELECT Open, High, Low, Close FROM ... means 0 - Open, 1 - High, 2 - Low and 3 - Close .

Hope this wil help. 

Regards,

Eugene 

 
elugovoy:

You are trying to define array every time in cycle and print empty array item.

Try this:

So, you have to define array once before fetching cycle, then resize, and then write routine for getting data.

By the way, the number 3 in  MySqlGetFieldAsDouble(Cursor, 3); means 4th column in SELECT list, because the numeration starts with 0, i.e. SELECT Open, High, Low, Close FROM ... means 0 - Open, 1 - High, 2 - Low and 3 - Close .

Hope this wil help. 

Regards,

Eugene 

Thanks for helping sir ,I have solved my problems about the array。You did a good job on mysql-mql indeed~!

 
For MetaTrader5 x64 use the following library (attached in the discussion):
[Deleted]  

Hello elugovoy

 Awesome article and great libraries.

 I'm trying to use your examples under MT5 but I'm getting this error: 

2014.12.15 15:44:16.387 MySQL-001 'C:\Users\....\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\libraries\MQLMySQL.dll' is not 64-bit version

Are you  running MT5 under 32-bit env?

 Could you pleas help me with it? 

 Thanks very much!

 Carmine Marrone. 

 
carmine.marrone:

Hello elugovoy

 Awesome article and great libraries.

 I'm trying to use your examples under MT5 but I'm getting this error: 

2014.12.15 15:44:16.387 MySQL-001 'C:\Users\....\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\libraries\MQLMySQL.dll' is not 64-bit version

Are you  running MT5 under 32-bit env?

 Could you pleas help me with it? 

 Thanks very much!

 Carmine Marrone. 

Hello Carmine

The above in discussion I have attached project for x64, take a look and/or download from this post.

Hope this helps.

Regards,

Eugene