www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - dlang how to use sqlite3

reply "kaspars" <djkraukscis gmail.com> writes:
Hello everyone !
i m trying to use sqlite3  but fails
Can anybody  help me fix the errors



import core.stdc.stdio, std.string, etc.c.sqlite3;
pragma(lib, "sqlite3");


// Version 1
int DoTheCallback(void* NotUsed, int numCols ,char[][]
results,char[][] columnNames)
    {
    writef("number of colomns: ", columnNames, "\n");
    return 0;
    };

// Version 2
extern(C) int myCallback(void *a_parm, int argc, char **argv,
char **column)
{
      return 0;
}


int main()
{
     sqlite3* db;
     int code;

     char*** pazResult;
     int* pnRow;
     int* pnColumn;
     char** pzErrmsg;


     code = sqlite3_open("triphone.db", &db);
     if(SQLITE_OK != code)
     {
        printf("DB create error: %s\n", sqlite3_errmsg(db));
        return 1;
     }
     printf("DB open!\n");


     // Version 1
     sqlite3_exec(db,"SELECT * FROM
triphones",myCallback,null,null);


    // Version 2
     sqlite3_exec(db,"SELECT * FROM
triphones",cast(sqlite3_callback)&DoTheCallback,null,null);


     printf("%s \n",pzErrmsg);

     sqlite3_close(db);
     printf("DB closed.\n");

     return 0;
}

The Question is how  to use sqlite3
Above Versions not working


Version 1 return
not callable using argument types ()

Versin 2 return
number of colomns: number of colomns: number of colomns: number
of colomns:
but empty array
Oct 01 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Tuesday, 1 October 2013 at 09:11:32 UTC, kaspars wrote:
     // Version 1
     sqlite3_exec(db,"SELECT * FROM
 triphones",myCallback,null,null);
should be sqlite3_exec(db,"SELECT * FROM triphones",&myCallback,null,null); otherwise you're actually doing a parenthesis-less call to myCallback instead of passing it's address, hence the error message.
Oct 01 2013
parent "kaspars" <djkraukscis gmail.com> writes:
On Tuesday, 1 October 2013 at 09:17:12 UTC, John Colvin wrote:
 On Tuesday, 1 October 2013 at 09:11:32 UTC, kaspars wrote:
    // Version 1
    sqlite3_exec(db,"SELECT * FROM
 triphones",myCallback,null,null);
should be sqlite3_exec(db,"SELECT * FROM triphones",&myCallback,null,null); otherwise you're actually doing a parenthesis-less call to myCallback instead of passing it's address, hence the error message.
Thank you ,It work !!
Oct 01 2013