I can confirm to Vendomele that implementing a xBestIndex with a 'return
SQLITE_OK;' does work -- I did this myself a few weeks ago.
I do second Dominique's advice about checking the use of the various
'SQLITE_EXTENSION_INITx' macros. There's three of them. If it's not
already obvious, what it does is forward the calls of the sqlite functions
to the host application; you should /not/ link your extension with sqlite.c
(which I had done for a while until I understood).
In my case, my lib supports both static and dynamic linkage, and a bunch of
implementation files, so I wind up using all three of those macros. My
'main' module (which has the init function) is more-or-less like the
documentation; my 'implemenation' (where the actual extension functions,
virtual tables, etc) are, all start with this:
#ifndef SQLITE_CORE
#include "..\sqlite3\sqlite3ext.h"
extern "C" {
//declares extern the vtable of all the sqlite3 functions (for loadable
modules only)
SQLITE_EXTENSION_INIT3
}
#else
#include "../sqlite3/sqlite3.h"
#endif
I didn't find any doc on SQLITE_EXTENSION_INIT3, but it's easy to see it
just defines an extern to the c-style v-table declared in your 'main' module
via SQLITE_EXTENSION_INIT1, and initialized in your init function via
SQLITE-EXTENSION_INIT2.
Debugging advice: build the sqlite shell project in a debug configuration.
Use that as a test harness for your loadable extension, and then you can
step through the sqlite source and get a better handle on what is crashing.
I had to do this many many times. Also, I don't know what platform you're
developing on, and what tools you are using, but do use the
split-sqlite3c.tcl to split the amalgamation, so your debugger won't wig on
the huge number of source lines.
Barring all that, you might check your surrounding code. I myself found
some anomalies, such as:
* in the xCreate function, the doc states that 'The xCreate method need not
initialize the pModule, nRef, and zErrMsg fields...', however I found that
not to be the case. I set nRef = 0 (which is not used, but I do it anyway),
and critically important, zErrMsg = NULL;. That is intended to be a string
containing an error message allocated by a sqlite function
sqlite3_mprintf(), and if it is not null (like, if it is not initialized),
sqlite will eventually attempt to free it, and I experienced crashes when I
was initially developing because of that behaviour.
Good luck!
-dave
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Dominique Devienne
> Sent: Wednesday, September 10, 2014 7:14 AM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Error with xBestIndex
>
>
> On Wed, Sep 10, 2014 at 11:53 AM, vendomele <[email protected]> wrote:
>
> > I developed a loadable extension, but after the execution
> of the callback
> > "xBestIndex" there is a crash.
> >
> > So I made it simple for this callback by implementing only
> one line that
> > returns SQLITE_OK.
> >
> > The crash still persists.
> >
> > With a development tool, the crash occurred in an external
> instruction to
> > my
> > dll:
> > "dword ptr and [ebp- $ 04] $ 00"
> >
> > Anyone have an idea?
> >
>
> Can you run a simple user-defined-function from that loadable
> extension?
> That's a simpler use-case than trying to write a vtable impl.
>
> Did you use the macros mentioned by
> http://www.sqlite.org/loadext.html ?
>
> Those macros ensure that the loaded extension uses the same
> SQLite code
> than the host program (the .exe on Windows), which can have crashing
> consequences if not properly defined.
>
> Also, you must typically compile your extension with the same
> SQLite3 used
> to compile the host app. The API is mostly stable, but that's
> an obvious
> step to double-check in case of crashes like here. --DD
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users