I have seen a message that Build 600 of MT4 and higher does not support ANSI.
I started out with ANSI on MT4.
I have seen a message that Build 600 of MT4 and higher does not support ANSI.
I started out with ANSI on MT4.
Yes MT4 uses now Unicode string.
How can we help ? Can you provide a snippet of code to demonstrate your issue ?
Yes MT4 uses now Unicode string.
How can we help ? Can you provide a snippet of code to demonstrate your issue ?
ingvar_e
Code in MQL4 EA and MQL5 EA #ifdef __MQL5__ #import "MySQLFunc.ex5" bool SetParms(string host,string user, string pass,string signalsDB,string signalsTable,string parmsTable,uint port); bool connectToSQL(); bool CreateParmsTable(); #import #else #import "MySQLFunc.ex4" bool SetParms(string host,string user, string pass,string signalsDB,string signalsTable,string parmsTable,uint port); bool connectToSQL(); bool CreateParmsTable(); #import #endif
Code in MQL4 and MQL5. Resides in one ex4 library and one ex5 library: bool connectToSQL() export { string moduleID = "[ConnectToSQL] "; MyDB2 = UNICODE2ANSI(MyDB); MyHost2 = UNICODE2ANSI(MyHost); MyUser2 = UNICODE2ANSI(MyUser); MyPass2 = UNICODE2ANSI(MyPass); /* MyDB2 = MyDB; //if before build 600 MyHost2 = MyHost; MyUser2 = MyUser; MyPass2 = MyPass; */ mysql = mysql_init(mysql); //This works ok in MT4 and MT5 if(mysql == 0) { Print(moduleID+"Init mysql_init failed!"); mysqlOK = false; return(false); } Print("Init mysql_init ok: " + mysql); int res = mysql_real_connect(mysql,MyHost2,MyUser2,MyPass2,MyDB2,MyPort,"",0); if(res != mysql) { Print(moduleID+" Connectfailed res : " + res + " mysql: " + mysql); Print("errno: " + mysql_errno(mysql)); string ww = mysql_error(mysql); Print("error: " + ww); string ww2 = ANSI2UNICODE(ww); Print("Error translated : " + ww2); return false; } return true; }
Results:
running MT5 with correct PW
Mysql_init OK
Print: "Tables created"
Running in MT5 with bad PW
mysql_init ok
Print: "Error 1045"
Print A lot of japanese symbols
Print translated: Access denied for user
So MT5 behaves as expected
Running MT4 with correct PW
Print "error: 2003
Print Just a bunch of question marks and a couple of number 4 digits
Print translated: nothing, blank
It probably means there is something in UNICODE2ANSI that doesn't work with mql4.
Why not simply use StringToCharArray() ?
It probably means there is something in UNICODE2ANSI that doesn't work with mql4.
Why not simply use StringToCharArray()?
Interesting thought. Will investigate. Thanks
Hmm. Nobody been using MT4 >600 with MySQL?
Been looking around. Problem has been around for quite a while. No good solutions found.
What would be nice is MQL4 source for ANSI2UNICODE and UNICODE2ANSI. I really do not like to use "wrappers" which seems to be the solution suggested
I am using a Library for my MySQL functions and I would like it o be common for MQL5 and MQL4 (Compiler directives accepted) and it has these functions in MQL5
Sorry about that
Found the solution. The originator of the ANSI2UNICODE and UNICODE2ANSI had made an update to the original code from 2010
http://mqlmagazine.com/mql-programming/dll-hell-mql5-edition-unicode-vs-ansi/
Look in comments!
Very simple to change with compiler directives so that the code works both in MQL4 and MQL5
Tested OK, Case closed
- mqlmagazine.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have working code for access to MySQL in MT5/MQL5. It uses the modules ANSI2UNICODE and UNICODE2ANSI
works file in MT5. tested with bad password and the translatd message comes out fine.
I have exactly the same code in MT4/MQL 4.
Gives my errno 2003 and untranslatable errormessage
?