MySQL for new MQL4 (tested in version 600) - MetaTrader 4 library
Originally created by Russell , then modified by Wade Royd and now forked by Lukins
Since the release of MT4 version 600, it is no longer easy to communicate with DLLs that use ANSI string format, since strings in MQL4 are now in UNICODE format (learn more here ).
This library is based on vedroid's modified Russel MySQL wrapper and uses technology from the EAX_Mysql library and from fragments released via gchrmt4
Any contributions are appreciated.
#includestring host = "localhost" ; string user = "root" ; string pass = "123456" ; string database name = "information architecture" ; integer port = 3306 ; integer socket = 0 ; integer client = 0 ; integer database connection id = 0 ; boolean good connection = bad ; integer start() { goodConnect = init_MySQL(dbConnectId, host, user, pass, dbName, port, socket, client); if ( !goodConnect ) { Return ( 1 ); // Bad connection } //+-------------------------------------------------------------------------------- //| Get multiple columns in multiple rows //+-------------------------------------------------------------------------------- Thin string query = string concatenation ( "Select `TABLE_NAME`, `TABLE_ROWS`, `CREATE_TIME`, `CHECK_TIME`" , "from 'table'" , "WHERE `TABLE_SCHEMA` = \'mysql\'" ); string data[][ 4 ]; // Important: the second dimension size must equal the number of columns integer result = MySQL_FetchArray(dbConnectId, query, data); if (result == 0 ) { // Print("0 rows selected"); } Other if (result ==- 1 ) { // Print("Some errors occurred"); } Other { // Print("Query successful. Print rows..."); Integer num_rows = ArrayRange(data, 0 ); Integer num_fields = ArrayRange(data, 1 ); for ( integer i = 0 ; i < number of rows; i++) { string line = "" ; for ( integer j = 0 ; j < num_fields; j++) { string value = data[i][j]; line = string concatenation (line, value, ";" ); } print (line); } } //+----------------------------------------------------------------------------- //|Single row read //|Similar to array get //+-------------------------------------------------------------------------------- Thin rows[][ 4 ]; //Important: Second dimension size must equal the number of columns string rows query = string concatenation ( "SELECT `TABLE_NAME`, `CREATE_TIME`, `CHECK_TIME`" , "from 'table'" , "WHERE `TABLE_SCHEMA` = \'mysql\' " , "Limit 0,1" ); Integer row_result = MySQL_FetchArray(dbConnectId, rowQuery, row); line = "Single-line query:" ; for ( integer r= 0 ; r < ArrayRange(row, 1 ); r++) { line = string concatenation (line, line[ 0 ][r], ";" ); } print (line); //+----------------------------------------------------------------------------- //|Example Insert //|This is just an example, no one can insert into information_schema.comment">//+--------------------------------------------------------------------------------------------- /*String insertion query = StringConcatenate( "Insert `CHARACTER_SETS` value (", "sometext", ",", "oneMoreText", ",", "and variables", ",", "nextWillBeNumber", ",", 2, ")"); if (MySQL_Query(dbConnectId, insertQuery)) { print("insert good"); }*/ //+-------------------------------------------------------------------------------- deinit_MySQL(dbConnectId); return ( 0 ); } //+----------------------------------------------------------------------------------+
The source code is released in the Github repository . Any contribution will be highly appreciated.
Attachment download
📎 mql4-mysql.mqh (8.29 KB)
Source: MQL5 #11114
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •