simple mysql wrapper

 

Hi All,

I wrote a small wrapper for fetching row and fields from MySQL.


source and compiled dll in attachment. Futher more a mqh for including the goodies :)

Files:
 

nice

thank you

p.s. you should post this to code library or articles

 

Well, it's still very basic... maybe later on :)


Russell

 

Thanks, that was the initial code I was using (or something like it)

But it gives lots of problems. MT can't handle MySQL rows or fields very well. Since they are C?? structures.

The wrapper translates these structures to the ones MT can handle (array of strings).

Therefor it is much more relyable; and it's easier to write MySQL queries.


btw. All original functions of libmysql are exported as well


Russell

 
Tnx, russell
 
Red.Line:
Tnx, russell
Russell:

Thanks, that was the initial code I was using (or something like it)

But it gives lots of problems. MT can't handle MySQL rows or fields very well. Since they are C?? structures.

The wrapper translates these structures to the ones MT can handle (array of strings).

Therefor it is much more relyable; and it's easier to write MySQL queries.


btw. All original functions of libmysql are exported as well


Russell

Russel or Red.Line,


if you read this, might you help me please regarding my problem? Thanks a lot! 'MySQL Read from Database'

 
awesome work, congrats.
 
abiank did you get the script to read from the database?
 

Hi JT2008,




#include <mysql.mqh>

int init(){
   Print(MT4_mysql_wrapper_version());
   MySQL_Init();
   getDB();
   return(0);
}

int deinit(){
   MySQL_DeInit();
   return(0);
}

void getDB(){ 
   //-------------v    set this to the number of fields you're selecting
   string lsData[][2];
   string lsQuery = "SELECT tableid,some_value FROM `mytable` INNER JOIN .... WHERE ... ORDER BY ...";
   MySQL_FetchArray(lsQuery, lsData); 
   for (int i = 0; i < ArrayRange(lsData,0); i++){
      for (int j = 0; j < ArrayRange(lsData,1); j++){
         Print(i+","+j+": "+lsData[i][j]);
      }
   }
}

hth


Russell

 
Well done, looks good. Are you going to provide instructions (or a makefile) on how to compile it from the source ? As I'm sure many people would like to be able to compile it rather than relying on the pre-built .dll I tried a simple command like: cl /LDd mysql_wrapper.cpp "C:\Program Files\MySQL\MySQL Server 5.0\lib\opt\libmysql.lib" but this generates a smaller .dll file than the one in the .zip file so maybe this excludes some functions.