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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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,
Here goes the problem:
Any ideas of what could possibly have gone wrong?
Thanks in advance!
Hello,
Here goes the problem:
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.
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
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");
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");
Well, I followed your suggestions for the tables's name and the MySqlExecute(DB, "USE mt4") command but I still get the error message:
0 12:51:40.534 Script MySQL-002new EURUSD,M1: loaded successfully
0 12:51:40.549 MySQL-002new EURUSD,M1: initialized
0 12:51:40.549 MySQL-002new EURUSD,M1: MQLMySQL v2.0 Demo Copyright © 2014, FxCodex Laboratory
0 12:51:40.549 MySQL-002new EURUSD,M1: Host: , User: , Database:
0 12:51:40.549 MySQL-002new EURUSD,M1: Connecting...
0 12:51:40.565 MySQL-002new EURUSD,M1: Connected! DBID#0
0 12:51:40.565 MySQL-002new EURUSD,M1: Table `test_table` cannot be created. Error: Aucune base n'a ?t? s?lectionn?e
0 12:51:40.565 MySQL-002new EURUSD,M1: Disconnected. Script done!
0 12:51:40.565 MySQL-002new EURUSD,M1: uninit reason 0
0 12:51:40.565 Script MySQL-002new EURUSD,M1: removed
Hello Eugeniy Lugovoy,
Big Thanks for your useful project.
I'm trying to read a string field from a table that it is about 3,000 characters, I used "MySqlGetFieldAsString" like this:
if (Cursor >= 0)
{
Rows = MySqlCursorRows(Cursor);
for (int i=0; i<Rows; i++)
if (MySqlCursorFetchRow(Cursor))
{
Get_Setting = MySqlGetFieldAsString(Cursor, 4);
}
.....
But the problem is Get_String returns me only 1025 characters,
I need to read that field completely.
Can you help me to solve this?
Regards
Hello Eugeniy Lugovoy,
Big Thanks for your useful project.
I'm trying to read a string field from a table that it is about 3,000 characters, I used "MySqlGetFieldAsString" like this:
if (Cursor >= 0)
{
Rows = MySqlCursorRows(Cursor);
for (int i=0; i<Rows; i++)
if (MySqlCursorFetchRow(Cursor))
{
Get_Setting = MySqlGetFieldAsString(Cursor, 4);
}
.....
But the problem is Get_String returns me only 1025 characters,
I need to read that field completely.
Can you help me to solve this?
Regards
Well, I followed your suggestions for the tables's name and the MySqlExecute(DB, "USE mt4") command but I still get the error message:
0 12:51:40.534 Script MySQL-002new EURUSD,M1: loaded successfully
0 12:51:40.549 MySQL-002new EURUSD,M1: initialized
0 12:51:40.549 MySQL-002new EURUSD,M1: MQLMySQL v2.0 Demo Copyright © 2014, FxCodex Laboratory
0 12:51:40.549 MySQL-002new EURUSD,M1: Host: , User: , Database:
0 12:51:40.549 MySQL-002new EURUSD,M1: Connecting...
0 12:51:40.565 MySQL-002new EURUSD,M1: Connected! DBID#0
0 12:51:40.565 MySQL-002new EURUSD,M1: Table `test_table` cannot be created. Error: Aucune base n'a ?t? s?lectionn?e
0 12:51:40.565 MySQL-002new EURUSD,M1: Disconnected. Script done!
0 12:51:40.565 MySQL-002new EURUSD,M1: uninit reason 0
0 12:51:40.565 Script MySQL-002new EURUSD,M1: removed
Excellent!
Using MQL5 to generate data for MQL4.
Everything worked beautifully except that I had to remove the single quotes around tablename on the query command
Query = "SELECT Symbol,Composite,Pattern FROM summarytable";
works ok