Andrey
Andrey

Reputation: 98

SQLite extensions error, c to dll compiling

What is needed:

Compile the json1 extension for SQLite

What I did:

Reaserched the official extension page: https://sqlite.org/loadext.html

Downloaded the SQLite source code: https://www.sqlite.org/cgi/src/doc/trunk/README.md

Found 2 ways to compile a dll:

  1. cl windows command
  2. gcc linux command

For the cl command I installed Visual Studio and launched the vcvars32.bat file for the enviroment launch, then tried this command: cl ext/misc/json1.c sqlite3ext.h /link /dll. Docs: https://learn.microsoft.com/en-us/cpp/build/reference/compiler-command-line-syntax?view=vs-2019

However it didnt work and I got an error: fatal error C1083: sqlite3ext.h: No such file or directory. I have the sqlite3ext.h file and tried moving it arround but nothing worked.

Then I moved to the gcc command:

  1. I used the Ubuntu wsl
  2. Upadated Ubuntu
  3. Downloaded the source code (mensioned above)
  4. Installed the SQLite developer package (can't find it)
  5. Used this command: gcc -g -shared sqlite/ext/misc/json1.c -o json1.dll

Found the command on the SQLite extension page mensioned above

It didn't work and I got this long error message:

sqlite/ext/misc/json1.c: In function ‘jsonEachConnect’:
sqlite/ext/misc/json1.c:2099:29: error: ‘SQLITE_VTAB_INNOCUOUS’ undeclared (first use in this function); did you mean ‘SQLITE_STATIC’?
     sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
                             ^~~~~~~~~~~~~~~~~~~~~
                             SQLITE_STATIC
sqlite/ext/misc/json1.c:2099:29: note: each undeclared identifier is reported only once for each function it appears in
sqlite/ext/misc/json1.c: At top level:
sqlite/ext/misc/json1.c:2501:3: warning: excess elements in struct initializer
   0                          /* xShadowName */
   ^
sqlite/ext/misc/json1.c:2501:3: note: (near initialization for ‘jsonEachModule’)
sqlite/ext/misc/json1.c:2529:3: warning: excess elements in struct initializer
   0                          /* xShadowName */
   ^
sqlite/ext/misc/json1.c:2529:3: note: (near initialization for ‘jsonTreeModule’)
sqlite/ext/misc/json1.c: In function ‘sqlite3Json1Init’:
sqlite/ext/misc/json1.c:2594:8: error: ‘SQLITE_INNOCUOUS’ undeclared (first use in this function); did you mean ‘SQLITE_IGNORE’?
        SQLITE_INNOCUOUS;
        ^~~~~~~~~~~~~~~~
        SQLITE_IGNORE
sqlite/ext/misc/json1.c:2602:10: warning: implicit declaration of function ‘sqlite3_create_window_function’; did you mean ‘sqlite3_create_function’? [-Wimplicit-function-declaration]
     rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          sqlite3_create_function
sqlite/ext/misc/json1.c:2603:34: error: ‘SQLITE_SUBTYPE’ undeclared (first use in this function); did you mean ‘SQLITE_CANTOPEN’?
                                  SQLITE_SUBTYPE | enc, 0,
                                  ^~~~~~~~~~~~~~

ANY HELP WOULD BE GREATLY APPRECIATED!

Thanks!

Upvotes: 2

Views: 351

Answers (1)

Gabriel Maizo
Gabriel Maizo

Reputation: 111

I had this problem with the SQLite UUID extension using "better-sqlite", but that's something else. What I did was replace everything that said SQLITE_INNOCUOUS and SQLITE_DETERMINISTIC with SQLITE_IGNORE. And it worked, at least for this extension. Something like the following:

Before:

{
  int rc = SQLITE_OK;
  SQLITE_EXTENSION_INIT2(pApi);
  (void)pzErrMsg;  /* Unused parameter */
  rc = sqlite3_create_function(db, "uuid", 0, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
                               sqlite3UuidFunc, 0, 0);
  if( rc==SQLITE_OK ){
    rc = sqlite3_create_function(db, "uuid_str", 1, 
                       SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
                       0, sqlite3UuidStrFunc, 0, 0);
  }
  if( rc==SQLITE_OK ){
    rc = sqlite3_create_function(db, "uuid_blob", 1,
                       SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
                       0, sqlite3UuidBlobFunc, 0, 0);
  }
  return rc;
}

After:

{
  int rc = SQLITE_OK;
  SQLITE_EXTENSION_INIT2(pApi);
  (void)pzErrMsg; /* Unused parameter */
  rc = sqlite3_create_function(db, "uuid", 0, SQLITE_UTF8 | SQLITE_IGNORE, 0,
                               sqlite3UuidFunc, 0, 0);
  if (rc == SQLITE_OK)
  {
    rc = sqlite3_create_function(db, "uuid_str", 1,
                                 SQLITE_UTF8 | SQLITE_IGNORE | SQLITE_IGNORE,
                                 0, sqlite3UuidStrFunc, 0, 0);
  }
  if (rc == SQLITE_OK)
  {
    rc = sqlite3_create_function(db, "uuid_blob", 1,
                                 SQLITE_UTF8 | SQLITE_IGNORE | SQLITE_IGNORE,
                                 0, sqlite3UuidBlobFunc, 0, 0);
  }
  return rc;
}

Edit


I just had to declare this at the beginning of the code.

#define SQLITE_DETERMINISTIC    0x000000800
#define SQLITE_DIRECTONLY       0x000080000
#define SQLITE_SUBTYPE          0x000100000
#define SQLITE_INNOCUOUS        0x000200000

Upvotes: 1

Related Questions