Libraries: MySQL for new MQL4 (tested in build 600) - page 4

 

Hi,

 

your script made so many connection in mysql.

maybe you can modify it

just open connection to database once, and insert to mysql while still connecting. 

 
naphill:

I worked it out after a long week of trying :)

Hi naphill,

I am also need to use it on 64 bit win7 platform. Can you share how to make it work on 64 bit ?

Thanks in advance ...

 
naphill:

I worked it out after a long week of trying :)

Hi Naphill,

Can you tell us, what must be changed to make it work for 64 bit platform ?

Thank you

 

Hi,

I got error "Access violation read to 0x00000019" , as i try to update the database. This happened exactly at reading the last row of Select query (i do select 20 rows). Below is the code ...

How to solve this ?

Thanks



#include <mql4-mysql.mqh>

string  host     = "localhost";
string  user     = "root";
string  pass     = "xxxxxxxx";
string  dbName   = "testdb";
string  tableName = "eurusd";

int     port     = 3306;
int     socket   = 0;
int     client   = 0;

int     dbConnectId = 0;
bool    goodConnect = false;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() {
    goodConnect = init_MySQL(dbConnectId, host, user, pass, dbName, port, socket, client);    
    if ( !goodConnect ) {
        return (1); // bad connect
    }
    else { // connection success ...
      // drop table if exists
      string dropQuery = StringConcatenate(
        "DROP TABLE IF EXISTS `", tableName ,"` )"
      ); 
      bool dropTableQuery = MySQL_Query(dbConnectId, dropQuery);
      if  (dropTableQuery == false) { // error drop table
         Print("Error drop table");
      }
      else {
         Print("Success drop table");
      }
      
      //------
      Sleep(1000);   // sleep 1 second      
      
      // create table if not exists, insert some data
      string createQuery = StringConcatenate(
        "CREATE TABLE IF NOT EXISTS `", tableName ,"` (`id` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT,`objName` VARCHAR(40),`tf` VARCHAR(5),`time1` VARCHAR(20) NULL default '0000-00-00 00:00:00',`prc1` double(9,5) NOT NULL default '0',`time2` VARCHAR(20) NULL default '0000-00-00 00:00:00',`prc2` double(9,5) NOT NULL default '0',`updown` int(2) NOT NULL default '-1',`finish` int(2) NOT NULL default '-1',`failed` int(2) NOT NULL default '-1',`init` int(2) NOT NULL default '-1',PRIMARY KEY (`id`) )"
      ); 
      bool createTableQuery = MySQL_Query(dbConnectId, createQuery);
      if  (createTableQuery == true) { // success create table
         Sleep(1000);   // sleep 1 second  
      
         //+-------------------------------------------------------------------+
         //| Insert some data to table                                         |
         //+-------------------------------------------------------------------+ 
         for (int n=0; n<30; n++) {  // insert 30 rows
            string setObjName = Symbol() + "_" + n;
            string insertQuery = StringConcatenate(
               "INSERT INTO `", tableName ,"` (`objName`,`tf`,`time1`,`prc1`,`time2`,`prc2`,`updown`,`finish`,`failed`,`init`) VALUES ('", setObjName ,"' , '", Period(), "' , '", TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) ,"' , '1.2345' , '2014-07-10 08:08:08' , '1.98765' , '1' , '0' , '0' , '0' )"
            );
            //--- 
            bool insertRes = MySQL_Query(dbConnectId, insertQuery);
            if (insertRes == false) {
               Print("Error insert data");
            }
            else {
               Print("Success insert data");
            }
         } // ende for
      
         //+-------------------------------------------------------------------+
         //| Fetch multiple columns in multiple rows                           |
         //+-------------------------------------------------------------------+ 
         Sleep(1000);   // sleep 1 second  
         string query = StringConcatenate(
            "SELECT * FROM `", tableName ,"` ORDER BY `id` ASC limit 20"
         );
         //---
         string data[][11];   // important: second dimension size must be equal to the number of columns
         int result = MySQL_FetchArray(dbConnectId, query, data);
         if ( result == 0 ) {
            Print("0 rows selected");
         } 
         else if ( result == -1 ) {
            Print("some error occured");
         } 
         else {
            Print("Query was successful. Printing rows...");
            //---
            int num_rows = ArrayRange(data, 0);
            int num_fields = ArrayRange(data, 1);
            for ( int i = 0; i < num_rows; i++) {
               string line = "";
               for ( int j = 0; j < num_fields; j++ ) {
                  if (j==0) { string theId            = data[i][j]; }
                  if (j==1) { string theObjName       = data[i][j]; }
                  if (j==2) { string theTF            = data[i][j]; }
                  if (j==3) { string theTime1         = data[i][j]; }
                  if (j==4) { string thePrc1          = data[i][j]; }
                  if (j==5) { string theTime2         = data[i][j]; }
                  if (j==6) { string thePrc2          = data[i][j]; }
                  if (j==7) { string theUpdown        = data[i][j]; }
                  if (j==8) { string theFinish        = data[i][j]; }
                  if (j==9) { string theFailed        = data[i][j]; }
                  if (j==10) { string theInit         = data[i][j]; }
                  //---
                  string value = data[i][j];
                  line = StringConcatenate(line, value, ";");               
               } // ende for
               
               Print("Line: #",i," with objName: ",theObjName," TF: ",theTF," time1: ",theTime1," Prc1: ",thePrc1," time2: ",theTime2," Prc2: ", thePrc2," Updown: ", theUpdown, " Finish: ",theFinish," Failed:",theFailed," Init:",theInit);
               Print(line);
            } // ende for
         } // ende else
         //--- 
         mysql_free_result (result);    
    
         //+-------------------------------------------------------------------+
         //| Update some data in table                                         |
         //+-------------------------------------------------------------------+ 
         Sleep(1000);   // sleep 1 second  
         string updateQuery = StringConcatenate(
            "UPDATE `", tableName ,"` SET `objName`= 'aloha' WHERE `id`>= '7' AND `id`<='15' "
         );
         //---
         bool updateRes = MySQL_Query(dbConnectId, updateQuery);
         if (updateRes == false) {
            Print("Error Update");
         }
         else {
            Print("Success Update");
         }
    
         //+-------------------------------------------------------------------+
         //|                                                                   |
         //+-------------------------------------------------------------------+
         Sleep(1000);   // sleep 1 second  
         string newquery = StringConcatenate(
            "SELECT * FROM `", tableName ,"` ORDER BY `id` limit 20"
         );
         //---
         string newdata[][11];   // important: second dimension size must be equal to the number of columns
         int newresult = MySQL_FetchArray(dbConnectId, newquery, newdata);
         if ( newresult == 0 ) {
            Print("0 rows selected");
         } 
         else if ( newresult == -1 ) {
            Print("some error occured");
         } 
         else {
            Print("Query was successful. Printing rows...");
            int new_num_rows = ArrayRange(newdata, 0);
            int new_num_fields = ArrayRange(newdata, 1);
            //---
            for ( i = 0; i < new_num_rows; i++) {
               string newline = "";
               for ( j = 0; j < new_num_fields; j++ ) {
                  if (j==0) { string newId            = newdata[i][j]; }
                  if (j==1) { string newObjName       = newdata[i][j]; }
                  if (j==2) { string newTF            = newdata[i][j]; }
                  if (j==3) { string newTime1         = newdata[i][j]; }
                  if (j==4) { string newPrc1          = newdata[i][j]; }
                  if (j==5) { string newTime2         = newdata[i][j]; }
                  if (j==6) { string newPrc2          = newdata[i][j]; }
                  if (j==7) { string newUpdown        = newdata[i][j]; }
                  if (j==8) { string newFinish        = newdata[i][j]; }
                  if (j==9) { string newFailed        = newdata[i][j]; }
                  if (j==10) { string newInit         = newdata[i][j]; }
                  //---
                  string newvalue = newdata[i][j];
                  newline = StringConcatenate(newline, newvalue, ";");
               }
               Print("New Line: #",i," with objName: ",newObjName," TF: ",newTF," time1: ",newTime1," Prc1: ",newPrc1," time2: ",newTime2," Prc2: ", newPrc2," Updown: ", newUpdown, " Finish: ",newFinish," Failed:",newFailed," Init:",newInit);
               Print(newline);
            } // ende for
         } // ende else
         //---
         mysql_free_result (newresult);
         
      } // ende if success create table

    } // ende else connection success ...
    //+-------------------------------------------------------------------
    deinit_MySQL(dbConnectId);
    return (0);
}
 

Hi,

some times i got another error : "Access violation read to 0x7DD08507 in  'msvcrt.dll'  ".

What does it mean ?

Thanks

 

I get the access violation problem too

2014.08.01 14:18:37.914    Access violation read to 0x000003B8 in '\AppData\Roaming\MetaQuotes\Terminal\BB190E062770E27C3E79391AB0D1A117\MQL4\Libraries\libmysql.dll'

on build 670

tried 5 different libmysql.dll including the latest one 6.1.5.0

Connecting works fine, the violation occurrs as soon as mysql_query is called in the mqh

I would greatly appreciate any pointers as to how to fix this


thanks

Mick

 
jackprobe:

Hi Naphill,

Can you tell us, what must be changed to make it work for 64 bit platform ?

Thank you

Could you be more specific about issues you experience in 64 bit platform? I tried it in Win 7 and it worked fine.
 
mql4_comments:

Sometimes access violation happens with libmysql.dll ((

and "mysql_errno: 2006; mysql_error: MySQL server has gone away" after that EA can't connect to db. Only reload...

Hi All!

I solved it this problem (MYSQL server has gone away):

If the connect return an error, I closed the connection, and reopen it:

 

if(!VanKapcsolat)
   {
      if(egyszer == 1) 
      {
         VanKapcsolat = ConnToSql();
         egyszer++;
      }
      if(egyszer == 0) 
      {
         deinit_MySQL(db_ConnectId);
         Print("DB kapcsolat vége.");
         egyszer++;
         if(db_socket < 25) db_socket++;
         else db_socket = 0;
         if(db_client < 15) db_client++;
         else db_client = 0;
         if(db_ConnectId < 30) db_ConnectId++;
         else db_ConnectId = 0;
      }
   }
   if(lastc < Time[0]) // számlaadatok frissítése gyertyánként 1×
   {
      if(VanKapcsolat)
      {
         SajatSzamlaAdatok();
         lastc = Time[0];
         egyszer = 0;
      }
   }

else if(result2 == -1)  // ha a lekérdezés sql hiba miatt sikertelen
   {
      if(errstr != "") errstr = errstr + soremeles + "  Adatbázis hiba a számlákhoz tartozó kötések lekérdezésénél!";
      else errstr = "  Adatbázis hiba a számlákhoz tartozó kötések lekérdezésénél!";
      hiba = -1;
      if(PrintToLog) Print("Adatbázis hiba a számlákhoz tartozó kötések lekérdezésénél!");
      VanKapcsolat = false;
   }

 

this library is extremely unstable,

its much appreciated that we are working on it but for the sake of investing money with it unfortunately its unacceptable.

I cant add the EA to the chart multiple times without having to do a reboot, with the memory errors, what is the real problem around this access violation error? 

 

 


 
Hi friends, I have a question for you:
Gold is the data I wanted to start the year 1970 almost all the Czech mt4 brokers but I did not succeed in this data I receive the data from most brokers to year1992 help



Reason: