Hi,

sqlite3_open takes a Pointer-Pointer as 2nd argument:

int sqlite3_open(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);

This is what your compiler tries to tell you:

safecalls.c:152: warning: passing argument 2 of ‘sqlite3_open’ from 
incompatible pointer type

So, you have to declare your own function like this as well:

                int safe_sqlite3_open(char *tablename, sqlite3 **db)
                {
                   int retval;

                   retval = sqlite3_open(tablename, db);

                   if(retval != SQLITE_OK)
                      HandleError(retval, "sqlite3_open", "Can't open database: 
%s", sqlite3_errmsg(*db));

                   return retval;
                 }


And call it like this:

sqlite3 *MyDb;

safe_sqlite3_open("MyDatabaseFile.db3", &MyDb)


Martin

TW wrote:
>       I made a safe_sqlite3_open function like this:
>
>                 /* From sqlite.c --> query_and_populate function */
>               int safe_sqlite3_open(char *tablename, sqlite3 *db)
>               {
>                  int retval;
>
>                  retval = sqlite3_open(tablename, db);
>
>                  if(retval != SQLITE_OK)
>                             HandleError(retval, "sqlite3_open", "Can't open 
> database: %s", sqlite3_errmsg(db));
>
>                  return retval;
>                  }
>
>       In normal usage, I call the function like this:
>
>               /* From safecalls.c --> safe_sqlite3_open */
>               sqlite3 *db;
>
>               rc = safe_sqlite3_open(tablename, &db);
>
>       When I run make, though, I get these errors:
>
>               gcc -g -c cursedj.c -o cursedj.o 
>               gcc -g -c musicinfo.c -o musicinfo.o 
>               gcc -g -c sqlite.c -o sqlite.o
>               sqlite.c: In function ‘query_and_populate’:
>               sqlite.c:14: warning: passing argument 2 of ‘safe_sqlite3_open’ 
> from incompatible pointer type
>               gcc -g -c winmanip.c -o winmanip.o 
>               gcc -g -c output.c -o output.o 
>               gcc -g -c dhandler.c -o dhandler.o
>               gcc -g -c help.c -o help.o 
>               gcc -g -c file.c -o file.o
>               gcc -g -c safecalls.c -o safecalls.o
>               safecalls.c: In function ‘safe_sqlite3_open’:
>               safecalls.c:152: warning: passing argument 2 of ‘sqlite3_open’ 
> from incompatible pointer type
>               gcc -Wall -g -lm -lncurses -lsqlite3 -o cursedj cursedj.o 
> musicinfo.o sqlite.o winmanip.o \
>                       output.o dhandler.o help.o file.o safecalls.o
>
>       I know that they're just warnings, but, how can I pass the sqlite3 
> pointer to my safe function 
> without getting any errors?  I've tried making the function parameters "*&", 
> "&", passing the "address of" 
> to the function...all to no avail, except what I have now, but I get those 
> warnings, BUT, the code does 
> work and my program runs the way it is above.
>
>   
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to