I declare a struct and pass it as the 4th argument of sqlite3_exec(),
and define the 1st argument of callback function a pointer to this kind
of struct. while compiling, GCC give a warning like this:
        ae.c: In function ‘main’:
        ae.c:56: warning: passing argument 3 of ‘sqlite3_exec’ from
incompatible pointer type


however, the program runs well. What may causing the warning? what
should i do to get rid of this warning.

Thanks!

Here is an simple example:

#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>

typedef struct
{
        int x;
        int y;
}MyStruct;


static int callback(MyStruct *data, int argc, char **argv, char
**azColName){
   int i;
   printf ("%d, %d\n", data->x, data->y);

   for(i=0; i<argc; i++){
     printf("%s = %s\t", azColName[i], argv[i] ? argv[i] : "NULL");
   }
   printf("\n");
   return 0;
}

int main(int argc, char **argv){
   sqlite3 *db;
   char *zErrMsg = 0;
   int rc;
   MyStruct *data;
   data = (MyStruct *) malloc (sizeof (MyStruct));
   data->x = 1;
   data->y = 2;


   if( argc!=3 ){
     fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
     exit(1);
   }
   rc = sqlite3_open(argv[1], &db);
   if( rc != SQLITE_OK){
     fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
     sqlite3_close(db);
     exit(1);
   }
   rc = sqlite3_exec(db, argv[2], callback, data, &zErrMsg);
   if( rc!=SQLITE_OK ){
     fprintf(stderr, "SQL error: %s\n", zErrMsg);
        sqlite3_free(zErrMsg);
   }
   sqlite3_close(db);

   free (data);
   return 0;
}
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to