Would someone, please, show me an example (several actual, successive
lines of code) in C (or C++) showing a proper use of
sqlite3_auto_extension()? I have searched the web looking for examples, but
there are none that I can tell. I have also, to the best of my understanding,
readhttp://www.sqlite.org/c3ref/auto_extension.html numerous times and I have
had no success. I am trying to use SQLite with extensionfunctions.c, but
extensionfunctions.c lacks a function called "xEntryPoint()". I do not know if
I am actually supposed to pass a pointer to a function called "xEntryPoint()"
or not. I am leaning toward 'no' and in reality I would think "xEntryPoint()"
is merely to represent some function found in extensionfunctions.c.
Below is code I have tried:
if (sqlite3Database)
sqlite3_close(sqlite3Database);
iCommandResult = sqlite3_open(":memory:",);
bContinue = (iCommandResult == 0);
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"CREATE TABLE data_table
(DataID INT, RandomData INT, V_In INT);",
,
0,
);
... Some Code to Fill the sqlite3Database in memory with data
bContinue = (iCommandResult == 0);
}
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT DataID, RandomData,
V_In FROM data_table",
,
this,
);
}
if (sqlite3Database)
{
iCommandResult = sqlite3_auto_extension(0);
if (iCommandResult == 0)
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT
STDEV(RandomData) AS RandomData_STDEV, V_In FROM data_table GROUP BY V_In",
,
this,
);
}
Since I cannot find a function called "xEntryPoint()", I tried zero as an
argument to sqlite3_auto_extension(). Not surprisingly, that did not work.
Here is some more code I tried ('adapted' from the commented out help section
at the top of extensionfunctions.c):
if (sqlite3Database)
sqlite3_close(sqlite3Database);
iCommandResult = sqlite3_open(":memory:",);
iCommandResult = sqlite3_enable_load_extension(sqlite3Database, 1);
bContinue = (iCommandResult == 0);
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"CREATE TABLE data_table
(DataID INT, RandomData INT, V_In INT);",
,
0,
);
... Some Code to Fill the sqlite3Database in memory with data
bContinue = (iCommandResult == 0);
}
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT DataID, RandomData,
V_In FROM data_table",
,
this,
);
}
if (sqlite3Database)
{
iCommandResult = sqlite3_load_extension(sqlite3Database, 0, 0,
ppcLoadExtErrorMessage);
if (iCommandResult == 0)
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT
STDEV(RandomData) AS RandomData_STDEV, V_In FROM data_table GROUP BY V_In",
,
this,
);
}
After executing sqlite3_load_extension, iCommandResult was set to SQLITE_ERROR
(exactly what I expected), but ppcLoadExtErrorMessage was NULL, so I could not
tell what the error was about.
Usage instructions from top of extensionfunctions.c:
Usage instructions for applications calling the sqlite3 API functions:
In your application, call sqlite3_enable_load_extension(db,1) to
allow loading external libraries. Then load the library
libsqlitefunctions
using sqlite3_load_extension; the third argument should be 0.
See http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions.
Select statements may now use these functions, as in