SQLite User Forum

3.47 Extension functions added to CLI
Login

3.47 Extension functions added to CLI

(1) By Aask (AAsk1902) on 2024-10-23 06:42:40 [link] [source]

Is there a loadable extension for this or is it a compile option for the library?

(2) By Code Hz (codehz) on 2024-10-23 06:50:32 in reply to 1 [link] [source]

Just simply look at the page you gave and you can find a link point to the percentile extension, which provide all info you need

(3) By Aask (AAsk1902) on 2024-10-23 09:57:31 in reply to 2 [link] [source]

Need some help: I tried to compile percentile.c (using cl in the same way as I've successfully compiled other extensions) and hit an error:

percentile.c(497): error C2065: 'SQLITE_SELFORDER1': undeclared identifier

(4) By Richard Hipp (drh) on 2024-10-23 10:00:46 in reply to 3 [link] [source]

The 3.47.0 version of percentile.c requires a 3.47.0 version of the header file, sqlite3.h. You are trying to compile with an older version of sqlite3.h

(5.2) By Aask (AAsk1902) on 2024-10-23 11:01:22 edited from 5.1 in reply to 4 [link] [source]

I used sqlite3.h from version 3.47.0 and compiled without errors. However, on attempting to load the extension, I get:

SQLite version 3.47.0 2024-10-21 16:30:22
Enter ".help" for usage hints.
sqlite> .shell dir percentile.dll
 Volume in drive E is DATA
 Volume Serial Number is 84B8-2F69

 Directory of E:\SQLite32

23/10/2024  11:26           150,016 PERCENTILE.DLL
               1 File(s)        150,016 bytes
               0 Dir(s)  380,619,571,200 bytes free
sqlite> .load percentile.dll
Error: The specified procedure could not be found.

UPDATE

Just in case I did somethng wrong with Percentile.dll, I tried with another extension.

I had compiled CSV.c a long while ago. Using it in version 3.43.2, I encounter no issues:

SQLite version 3.43.2 2023-10-10 12:14:04
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .load 'E:\SQLite32\Extensions\CSV.dll'
sqlite>

However, I get the same error in subsequent versions:

SQLite version 3.44.2 2023-11-24 11:41:44 (UTF-16 console I/O)
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .load 'E:\SQLite32\Extensions\CSV.dll'
Error: The specified module could not be found.

Something changed after 3.43.2!

(6) By ddevienne on 2024-10-23 10:56:49 in reply to 5.1 [link] [source]

Drop the .dll suffix perhaps, see https://sqlite.org/cli.html#loading_extensions

Note that SQLite automatically adds the appropriate extension suffix (".dll" on windows, ".dylib" on Mac, ".so" on most other unixes) to the extension filename

(7) By Aask (AAsk1902) on 2024-10-23 11:03:42 in reply to 6 [link] [source]

Drop the .dll suffix perhaps,

Tried, but no change in response:

SQLite version 3.47.0 2024-10-21 16:30:22
Enter ".help" for usage hints.
sqlite> .load percentile
Error: The specified procedure could not be found.

(8.2) By ddevienne on 2024-10-23 11:09:23 edited from 8.1 in reply to 7 [link] [source]

Then the extension DLL is not in your PATH (use an absolute path as work-around, as doc mentions),
or the entry point (the function name looked up in the shared-lib) is not exported,
or not the default one expected (you can specify it explicitly to .load)

PS: You can use a tool like https://github.com/lucasg/Dependencies to see exports of your DLLs

(10) By Aask (AAsk1902) on 2024-10-23 11:15:53 in reply to 8.0 [link] [source]

Then the extension DLL is not in your PATH,

It is, as I took care to check: see

or the entry point (the function name looked up in the shared-lib) is not exported,

  1. How can I check?
  2. Does this require another step in compilation?

or not the default one expected (you can specify it explicitly to .load)

No change when I do that.

SQLite version 3.47.0 2024-10-21 16:30:22
Enter ".help" for usage hints.
sqlite> /* check percentile.dll */
sqlite> .shell dir /b percentile.dll
PERCENTILE.DLL
sqlite> /* It is in the path */
sqlite>  select load_extension('Percentile.DLL','sqlite3_percentile_init');
Runtime error: The specified procedure could not be found.

(9) By Richard Hipp (drh) on 2024-10-23 11:13:30 in reply to 5.2 [link] [source]

The CSV and percentile extensions are already compiled into the CLI. I think the errors you are seeing result from the loader getting confused by identical entry point names found in both the original executable and in the extension.

I think your best bet is to not try to load an extension that is already built in.

(11) By Aask (AAsk1902) on 2024-10-23 11:25:50 in reply to 9 [link] [source]

I think your best bet is to not try to load an extension that is already built in.

Fair enough.

I tried programmatically, in a prepare_v2 ... step ... finalize loop and I get this error:

no such function: median

which suggests that the extension was not loaded.

I tried this sql:

select load_extension('Percentile.DLL','sqlite3_percentile_init');select median(employeeid) from employees;

and this variation:

select load_extension('Percentile.DLL');select median(employeeid) from employees;

(13.3) By ddevienne on 2024-10-23 12:25:00 edited from 13.2 in reply to 9 [source]

After trying it locally, there's an issue on Windows in percentile.c.

Specifically, the line

#if defined(_WIN32) && !defined(SQLITE3_H) && !defined(SQLITE_STATIC_PERCENTILE)

prevents the __declspec(dllexport) from being compiled-in, so the extension entry-point is not exported.

By decomposing those 3 tests, it's the !defined(SQLITE3_H) that's failing.
So a side-effect somehow of the previous code and/or include does define it.

When I commented that one out, then the symbol was properly exported.

Looks like sqlite3ext.h loads sqlite3.h (see below), so normal that SQLITE3_H is later defined.
That's likely a mistake.

D:\oss\sqlite\3.47\sqlite-amalgamation-3470000>cl /showIncludes /nologo /LD percentile.c /Femy_percentile.dll
percentile.c
Note: including file: D:\oss\sqlite\3.47\sqlite-amalgamation-3470000\sqlite3ext.h
Note: including file:  D:\oss\sqlite\3.47\sqlite-amalgamation-3470000\sqlite3.h
...
percentile.c(126): fatal error C1189: #error:  HAS_SQLITE3_H

PS: that #error is mine and not in the original code of course.
PPS: That doesn't mean I can load the extension though! Richard is probably still right. But at least dumpbin /EXPORTS properly shows the entry point being exported.

(12) By Aask (AAsk1902) on 2024-10-23 11:42:48 in reply to 4 [link] [source]

Another change is that I now need elevated privileges to compile (previously, I was able to compile without elevated privileges).:

E:\SQLite32\Extensions\SOURCE\percentile.c : fatal error C1083: Cannot open compiler generated file: 'D:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x86\percentile.obj': Permission denied