satindergrewal / lightning

c-lightning — a Lightning Network implementation in C
Other
0 stars 2 forks source link

wallet/invoices.c compilation errors #3

Closed satindergrewal closed 3 years ago

satindergrewal commented 3 years ago

On compiling I get the following errors:

wallet/invoices.c:691:9: error: implicit declaration of function 'db_prepare' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        stmt = db_prepare(invoices->db,
               ^
wallet/invoices.c:691:7: error: incompatible integer to pointer conversion assigning to 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *') from 'int' [-Werror,-Wint-conversion]
        stmt = db_prepare(invoices->db,
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
make: *** [wallet/invoices.o] Error 1

I changed the db_prepare to sqlite3_prepare_v2 and now getting different errors:

cc wallet/invoices.c
wallet/invoices.c:691:28: error: incompatible pointer types passing 'struct db *' to parameter of type 'sqlite3 *' (aka 'struct sqlite3 *') [-Werror,-Wincompatible-pointer-types]
        stmt = sqlite3_prepare_v2(invoices->db, "SELECT count(*) FROM invoices;", -1, &stmt, NULL);
                                  ^~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sqlite3.h:4057:12: note: passing argument to parameter 'db' here
  sqlite3 *db,            /* Database handle */
           ^
wallet/invoices.c:691:7: error: incompatible integer to pointer conversion assigning to 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *') from 'int' [-Werror,-Wint-conversion]
        stmt = sqlite3_prepare_v2(invoices->db, "SELECT count(*) FROM invoices;", -1, &stmt, NULL);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
make: *** [wallet/invoices.o] Error 1

invoices->db is of type db, but the statement wants sqlite3 type. tried using db and sqlite3 type changes but couldn't find way to get past these errors.

I actually tried changing the type to db:

struct db_stmt *stmt;
stmt = db_prepare_v2(invoices->db, SQL(SELECT count(*) "
                           "  FROM invoices;"));

and the db related errors went away. then the errors pointed to int num_cols = sqlite3_column_count(stmt); and I don't find sqlite3_column_count equivalent in db_common.h or other files...

satindergrewal commented 3 years ago

Issue resolved by these 2 git commits: https://github.com/satindergrewal/lightning/commit/9be57e98dbc61a595cf2c915aca64fdd8b7c4a5d, https://github.com/satindergrewal/lightning/commit/6fb0135ddb7f14f54d071c608937ab4038af80c5

Thanks @jl777 for hints and pushing a little bit. 😃