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

 
Eugeniy Lugovoy:

Hello James, 

I'm working at Upwork only on one big project currently. So, have no much free time nowadays. What's the problem you have with libs? How can I help you?

Hello,

I figured it out in the end, but thanks for the library anyway.... Very helpful!!

James
 

Why did everything stop working after upgrading to build 890 mt4?

The log says Access violation read to 0x00000000 in 'D:\MT4\MQL4\libraries\MQLMySQL.dll'.

 
also interested in ...
 
Itum:
also interested in ...
Guys, I'll try to check in the next few days.
 
Looking forward to it!
 
alhimik7:
Looking forward to it!

MT4 build 890 x32 just checked. Everything works.

Log of running test scripts:

2015.12.05 12:20:09.984 Script MySQL-005 EURUSD,H1: removed
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: uninit reason 0
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Disconnected. Script done!
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Passed!
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Closing cursors...
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Cursor 4 was opened.
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Cursor 3 was opened.
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Cursor 2 was opened.
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Cursor 1 was opened.
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Connected! DBID#0
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Connecting...
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: Host: 127.0.0.1, User: mt4, Database: mt4
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: MQLMySQL v2.2 x32 Copyright © 2014, FxCodex Laboratory
2015.12.05 12:20:09.984 MySQL-005 EURUSD,H1: initialized
2015.12.05 12:20:09.968 Script MySQL-005 EURUSD,H1: loaded successfully
2015.12.05 12:20:04.484 Script MySQL-004 EURUSD,H1: removed
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: uninit reason 0
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: Disconnected. Script done!
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: ROW[3]: id = 4, code = USDJPY, start_time = 2014.01.03 03:00:00
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: ROW[2]: id = 3, code = EURJPY, start_time = 2014.01.02 00:02:00
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: ROW[1]: id = 1, code = EURUSD, start_time = 2014.01.01 00:00:01
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: ROW[0]: id = 123279852, code = ACCOUNT, start_time = 2015.12.05 12:20:00
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: Rows affected: 4
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: 4 row(s) selected.
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: SQL> SELECT id, code, start_date FROM `test_table`
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: Connected! DBID#0
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: Connecting...
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: Host: 127.0.0.1, User: mt4, Database: mt4
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: MQLMySQL v2.2 x32 Copyright © 2014, FxCodex Laboratory
2015.12.05 12:20:04.484 MySQL-004 EURUSD,H1: initialized
2015.12.05 12:20:04.484 Script MySQL-004 EURUSD,H1: loaded successfully
2015.12.05 12:20:00.093 Script MySQL-003 EURUSD,H1: removed
2015.12.05 12:20:00.093 MySQL-003 EURUSD,H1: uninit reason 0
2015.12.05 12:20:00.093 MySQL-003 EURUSD,H1: Disconnected. Script done!
2015.12.05 12:20:00.093 MySQL-003 EURUSD,H1: Rows affected: 2
2015.12.05 12:20:00.093 MySQL-003 EURUSD,H1: Succeeded! 2 rows has been updated.
2015.12.05 12:20:00.078 MySQL-003 EURUSD,H1: Rows affected: 1
2015.12.05 12:20:00.078 MySQL-003 EURUSD,H1: Succeeded! 3 rows has been inserted by one query.
2015.12.05 12:20:00.031 MySQL-003 EURUSD,H1: Rows affected: 1
2015.12.05 12:20:00.031 MySQL-003 EURUSD,H1: Succeeded: INSERT INTO `test_table` (id, code, start_date) VALUES (123279852,'ACCOUNT','2015.12.05 12:20:00')
2015.12.05 12:20:00.031 MySQL-003 EURUSD,H1: Table `test_table` created.
2015.12.05 12:19:59.968 MySQL-003 EURUSD,H1: Connected! DBID#0
2015.12.05 12:19:59.953 MySQL-003 EURUSD,H1: Connecting...
2015.12.05 12:19:59.953 MySQL-003 EURUSD,H1: Host: 127.0.0.1, User: mt4, Database: mt4
2015.12.05 12:19:59.953 MySQL-003 EURUSD,H1: MQLMySQL v2.2 x32 Copyright © 2014, FxCodex Laboratory
2015.12.05 12:19:59.953 MySQL-003 EURUSD,H1: initialized
2015.12.05 12:19:59.953 Script MySQL-003 EURUSD,H1: loaded successfully
2015.12.05 12:19:55.531 Script MySQL-002 EURUSD,H1: removed
2015.12.05 12:19:55.531 MySQL-002 EURUSD,H1: uninit reason 0
2015.12.05 12:19:55.531 MySQL-002 EURUSD,H1: Disconnected. Script done!
2015.12.05 12:19:55.531 MySQL-002 EURUSD,H1: Table `test_table` created.
2015.12.05 12:19:55.218 MySQL-002 EURUSD,H1: Connected! DBID#0
2015.12.05 12:19:55.218 MySQL-002 EURUSD,H1: Connecting...
2015.12.05 12:19:55.218 MySQL-002 EURUSD,H1: Host: 127.0.0.1, User: mt4, Database: mt4
2015.12.05 12:19:55.218 MySQL-002 EURUSD,H1: MQLMySQL v2.2 x32 Copyright © 2014, FxCodex Laboratory
2015.12.05 12:19:55.218 MySQL-002 EURUSD,H1: initialized
2015.12.05 12:19:55.218 Script MySQL-002 EURUSD,H1: loaded successfully
2015.12.05 12:19:49.625 Script MySQL-001 EURUSD,H1: removed
2015.12.05 12:19:49.625 MySQL-001 EURUSD,H1: uninit reason 0
2015.12.05 12:19:49.625 MySQL-001 EURUSD,H1: All connections closed. Script done!
2015.12.05 12:19:49.625 MySQL-001 EURUSD,H1: Connected! DBID#2
2015.12.05 12:19:49.625 MySQL-001 EURUSD,H1: Connected! DBID#1
2015.12.05 12:19:49.625 MySQL-001 EURUSD,H1: Connected! DBID#0
2015.12.05 12:19:49.609 MySQL-001 EURUSD,H1: Connecting...
2015.12.05 12:19:49.609 MySQL-001 EURUSD,H1: Host: 127.0.0.1, User: mt4, Database: mt4
2015.12.05 12:19:49.609 MySQL-001 EURUSD,H1: MQLMySQL v2.2 x32 Copyright © 2014, FxCodex Laboratory
2015.12.05 12:19:49.609 MySQL-001 EURUSD,H1: initialized
2015.12.05 12:19:49.546 Script MySQL-001 EURUSD,H1: loaded successfully

Guys, clarify:

1. On what operation it gives"Access violation read" ?

2. When running the MySQL-001 script, what version of MQLMySQL is shown on the Experts tab? should be: MQLMySQL v2.2 x32 Copyright © 2014, FxCodex Laboratory

3. What version of MySQL database?

4. Is MySQL used locally or on a remote host?

5. Under which operating system do you run the terminal?

Please check and report back, as I can't reproduce the error.

I will create a similar environment and test.

 

Hello,

I am trying to connect Metatrader to Mysql via your files. 
After the download and the installation I changed the file "MyConnection" by setting the info of my DB.

Here goes the problem:

At first, everything worked just fine; the scripts were creating tables inside the DB. Then I made a little change in the code (just changed the table's name) and deleted the table from the database so that the script would create a new one from scratch without droping the previous one. And all I got was the creation of the columns but without any data. 
So I decided to use the old scripts again. Then I got nothing; not even a table was created. Since then I have a DB that stays empty. 

Any ideas of what could possibly have gone wrong?

Thanks in advance!

 
peg:

Hello,

I am trying to connect Metatrader to Mysql via your files. 
After the download and the installation I changed the file "MyConnection" by setting the info of my DB.

Here goes the problem:

At first, everything worked just fine; the scripts were creating tables inside the DB. Then I made a little change in the code (just changed the table's name) and deleted the table from the database so that the script would create a new one from scratch without droping the previous one. And all I got was the creation of the columns but without any data. 
So I decided to use the old scripts again. Then I got nothing; not even a table was created. Since then I have a DB that stays empty. 

Any ideas of what could possibly have gone wrong?

Thanks in advance!

Hello Peg,

To create table use SQL command CREATE TABLE  http://dev.mysql.com/doc/refman/5.7/en/create-table.html

For inserting data use SQL command INSERT INTO https://dev.mysql.com/doc/refman/5.6/en/insert.html 

To execute such commands use the function MySqlExecute.

Also you can provide your code and I would be able to figure out the problem. 

MySQL :: MySQL 5.7 Reference Manual :: 13.1.14 CREATE TABLE Syntax
  • dev.mysql.com
creates a table with the given name. You must have the privilege for the table. Rules for permissible table names are given in Section 9.2, “Schema Object Names”. By default, the table is created in the default database, using the storage engine. An error occurs if the table exists, if there is no default database, or if the database does not...
 
Eugeniy Lugovoy:

Hello Peg,

To create table use SQL command CREATE TABLE  http://dev.mysql.com/doc/refman/5.7/en/create-table.html

For inserting data use SQL command INSERT INTO https://dev.mysql.com/doc/refman/5.6/en/insert.html 

To execute such commands use the function MySqlExecute.

Also you can provide your code and I would be able to figure out the problem. 

Hello Eugeniy,

Thank you for the links.

At first I used your code to connect to my database (I was using mySql Server in case it is useful). And I could see the table. Then I changed the table's name at your MySQL-002 Script (as you can see below) and thought it seemed to work it wouldn't create my table. Now I'm using WampServer and  I get:

0 11:09:37.579 Script MySQL-002 EURUSD,H1: loaded successfully

0 11:09:37.730 MySQL-002 EURUSD,H1: initialized

0 11:09:37.730 MySQL-002 EURUSD,H1: MQLMySQL v2.0 Demo Copyright © 2014, FxCodex Laboratory

0 11:09:37.730 MySQL-002 EURUSD,H1: Host: , User: , Database: 

0 11:09:37.730 MySQL-002 EURUSD,H1: Connecting...

0 11:09:37.741 MySQL-002 EURUSD,H1: Connected! DBID#0

0 11:09:37.742 MySQL-002 EURUSD,H1: Table `table` cannot be created. Error: Aucune base n'a ?t? s?lectionn?e

0 11:09:37.742 MySQL-002 EURUSD,H1: Disconnected. Script done!

0 11:09:37.742 MySQL-002 EURUSD,H1: uninit reason 0

0 11:09:37.743 Script MySQL-002 EURUSD,H1: removed

//+------------------------------------------------------------------+
//|                                                    MySQL-002.mq4 |
//|                                   Copyright 2014, Eugene Lugovoy |
//|                                        http://www.fxcodexlab.com |
//| Table creation (DEMO)                                            |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Eugene Lugovoy."
#property link      "http://www.fxcodexlab.com"
#property version   "1.00"
#property strict

#include <MQLMySQL.mqh>

string INI;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
 string Host, User, Password, Database, Socket; // database credentials
 int Port,ClientFlag;
 int DB; // database identifier
 
 Print (MySqlVersion());

 INI = TerminalPath()+"\\MQL4\\Scripts\\MyConnection.ini";
 
 // reading database credentials from INI file
 Host = ReadIni(INI, "MYSQL", "Host");
 User = ReadIni(INI, "MYSQL", "User");
 Password = ReadIni(INI, "MYSQL", "Password");
 Database = ReadIni(INI, "MYSQL", "Database");
 Port     = StrToInteger(ReadIni(INI, "MYSQL", "Port"));
 Socket   = ReadIni(INI, "MYSQL", "Socket");
 ClientFlag = StrToInteger(ReadIni(INI, "MYSQL", "ClientFlag"));  

 Print ("Host: ",Host, ", User: ", User, ", Database: ",Database);
 
 // open database connection
 Print ("Connecting...");
 
 DB = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
 
 if (DB == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB);}
 
 string Query;
 Query = "DROP TABLE IF EXISTS `test`";
 MySqlExecute(DB, Query);
 
 Query = "CREATE TABLE `test` (id int, code varchar(50), start_date datetime)";
 if (MySqlExecute(DB, Query))
    {
     Print ("Table `test` created.");
    }
 else
    {
     Print ("Table `test` cannot be created. Error: ", MySqlErrorDescription);
    }
 
 MySqlDisconnect(DB);
 Print ("Disconnected. Script done!");
}
//+------------------------------------------------------------------+
 
peg:

Hello Eugeniy,

Thank you for the links.

At first I used your code to connect to my database (I was using mySql Server in case it is useful). And I could see the table. Then I changed the table's name at your MySQL-002 Script (as you can see below) and thought it seemed to work it wouldn't create my table. Now I'm using WampServer and  I get:

0 11:09:37.579 Script MySQL-002 EURUSD,H1: loaded successfully

0 11:09:37.730 MySQL-002 EURUSD,H1: initialized

0 11:09:37.730 MySQL-002 EURUSD,H1: MQLMySQL v2.0 Demo Copyright © 2014, FxCodex Laboratory

0 11:09:37.730 MySQL-002 EURUSD,H1: Host: , User: , Database: 

0 11:09:37.730 MySQL-002 EURUSD,H1: Connecting...

0 11:09:37.741 MySQL-002 EURUSD,H1: Connected! DBID#0

0 11:09:37.742 MySQL-002 EURUSD,H1: Table `table` cannot be created. Error: Aucune base n'a ?t? s?lectionn?e

0 11:09:37.742 MySQL-002 EURUSD,H1: Disconnected. Script done!

0 11:09:37.742 MySQL-002 EURUSD,H1: uninit reason 0

0 11:09:37.743 Script MySQL-002 EURUSD,H1: removed

Based on error I see from your log:  0 11:09:37.742 MySQL-002 EURUSD,H1: Table `table` cannot be created.

you are uses name "table" which is keyword of mysql database and cannot be used as table name, try to change to for example to "table1" just to check is it works. 

or possible the database was not selected or was not set. you can execute command "USE database_name" right after connection, where the database_name is the name of your database.

for example if my database is "mysql":

DB = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);

if (DB == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB);} 

 MySqlExecute(DB, "USE mysql");