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

 
Dmitry Melnichenko:

I created a new user, tried connecting under his details, it didn't help!

then it is unlikely that this is a problem of MySQL or database organisation, i.e. there is obviously some bug either in the EA/script or in the interface library.

Can you give me an example where this is minimised? So that I can demonstrate a short code, and find out its problems here in a forum thread.

 
Maxim Kuznetsov:

then it is unlikely that it is a problem of MySQL or database organisation, i.e. obviously some bug either in the EA/script or in the interface library.

Can you give an example where this is minimised? So that you can demonstrate a short code, and then find out its problems in a forum thread here

if(connect >= 0)
   {
      string sql = SelectNewOrdersSQL();
      
      int Cursor1 = MySqlCursorOpen(connect, sql);
      
      if(Cursor1 >= 0)
      {
         int Rows = MySqlCursorRows(Cursor1);
         
         for(int i = 0; i < Rows; i++)
         {
            ResetLastError();
            
            if(MySqlCursorFetchRow(Cursor1))
            {
               int ticket = MySqlGetFieldAsInt(Cursor1, 0);
               string s = MySqlGetFieldAsString(Cursor1, 1);
               int order_type = MySqlGetFieldAsInt(Cursor1, 2);
               double lot = MySqlGetFieldAsDouble(Cursor1, 3);
               double open_price = MySqlGetFieldAsDouble(Cursor1, 4);
               
               string symbol = GetSymbol(s);
               
               Print(ticket);
               
               int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
               int open_ticket = -1;
               if((open_ticket = OrderSend(symbol, order_type, NormalizeDouble(lot, 2), NormalizeDouble(open_price, digits), 150, 0, 0, (string)ticket)) <= 0)
               {
                  Print(symbol, ": failed to open a position. Error ", GetLastError());
               }
               else
               {
                  MySqlExecute(connect, SqlModifyClient(ticket, open_ticket));
               }
            }
         }
         
         MySqlCursorClose(Cursor1);
      }
   }
string SelectNewOrdersSQL()
{
   string res = "SELECT Ticket, Symbol, OrderType, Lot, OpenPrice, StopLoss, TakeProfit ";
   res += "FROM orders (WHERE Client2 = 0 AND HistoryMaster = 0 AND Account = " + (string)MasterAccount;
   res += " AND Magic = " + (string)MasterMagic + ")";
   
   return res;
}
 
do you have MQL4 or 5 ???
 
Maxim Kuznetsov:
do you have MQL4 or 5???
MQL4
 
Dmitry Melnichenko:
MQL4
and the error is only when closing the cursor, i.e. all records are pulled out normally, but at the end this nonsense pops up?
 
Maxim Kuznetsov:
and the error is only when closing the cursor, i.e. all records are pulled out normally, but at the end this nonsense pops up?
Yes, it writes that the number of selected rows ( printed in Print), but when closing the cursor it writes this error.
 
Amy Liu:

Hi Eugeniy,

Sorry for late response. Here is what i did with your code. I just modified one function cMySqlGetRowField to use MultiByteToWideChar. The original code is commented for compare.

Thanks your guys are great. I tried your code .Don't forget includ widechar head, or it'll not work.

#include <wchar.h>



 

 

Hello teacher, I am using mt4 software, local win10 system using ea to connect mysql can be used normally, but put into win2008 server will not work, has been prompted '... \libraries\MQLMySQL.dll' is not loaded... ...' error.

I have downloaded all the versions including mt4, mt5, 64bit, 32bit, but it still doesn't work. What should I do?

 

Hi I have loaded dll in Libraries folder but it report an error " "Cnnot call 'cMySqlVersion', '....\Libraries\MQLMySQL.dll' is not loaded

How is it possible?

 
GreenKobra:

Hi I have loaded dll in Libraries folder but it report an error " "Cnnot call 'cMySqlVersion', '....\Libraries\MQLMySQL.dll' is not loaded

How is it possible?

I have the same issue than you.

Using MT5 with Windows 10 - 64bits.