Defining a function that receives any struct (pointer to void?)

 

Hello people,

Basically, I'm trying to wrap the DatabaseReadBind function  https://www.mql5.com/en/docs/database/databasereadbind

But I can't figure out a way of defining a function (actually, instance method) that accepts as void &something (as DatabaseReadBind does).

Without wrapping, works fine:

    // stuff stuff
    int request = DatabasePrepare(DB.handle, sql);
    HiloStruct hiloStruct;

    while(DatabaseReadBind(request, hiloStruct)) {
    // stuff stuff


Wrapping in a method, breaks:

    SQLiteReadQuery * readQuery = new SQLiteReadQuery(sql);
    HiloStruct hiloStruct;
    while(readQuery.read(hiloStruct)) {


Errors:

class SQLiteReadQuery {
  // stuff stuff

  // 'void' - illegal use of 'void' type
  bool read(void &structInstance) {
    return DatabaseReadBind(this.request, structInstance);
  }
};
class SQLiteReadQuery {
  // stuff stuff

  // 'void' - illegal use of 'void' type
  bool read(void structInstance) {
    return DatabaseReadBind(this.request, structInstance);
  }
};
class SQLiteReadQuery {
  // stuff stuff

  bool read(void * structInstance) {
    return DatabaseReadBind(this.request, structInstance); // illegal type, structures only with simple type and/or string members are allowed
  }
};
class SQLiteReadQuery {
  // stuff stuff

  bool read(void * &structInstance) {
    return DatabaseReadBind(this.request, structInstance); // illegal type, structures only with simple type and/or string members are allowed
  }
};


Kinda unrelated but my intention is to wrap "error catching" code as on SQL errors the tester just say stuff like "database error, no such column: IND" with 0 hints on where to find it. Any help? What am I missing? Thanks, everybody!

Documentation on MQL5: Working with databases / DatabaseReadBind
Documentation on MQL5: Working with databases / DatabaseReadBind
  • www.mql5.com
DatabaseReadBind - Working with databases - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Pedro Bernardes:

Hello people,

Basically, I'm trying to wrap the DatabaseReadBind function  https://www.mql5.com/en/docs/database/databasereadbind

But I can't figure out a way of defining a function (actually, instance method) that accepts as void &something (as DatabaseReadBind does).

Without wrapping, works fine:


Wrapping in a method, breaks:


Errors:


Kinda unrelated but my intention is to wrap "error catching" code as on SQL errors the tester just say stuff like "database error, no such column: IND" with 0 hints on where to find it. Any help? What am I missing? Thanks, everybody!

You can't do that with struct in MQL.

Use template functions or classes.

 
Alain Verleyen #:

You can't do that with struct in MQL.

Use template functions or classes.

Hey Alain, thanks for your response.

If that is not possible, how 
DatabaseReadBind

does it? Is it an exception for it being native?

 
Pedro Bernardes #:
Hey Alain, thanks for your response.

If that is not possible, how 

does it? Is it an exception for it being native?

It's an MQL function coded in C++. We are coding in MQL, that's not the same.
 

Bummer,


thanks!