Re: [sqlite] Error with xBestIndex
Yep, same one as me, glad the info helped. I think I may file a bug on that. Delphi, I do remember that, and have had rare occasion to use it, though I've never linked c obj in (or are you using sqlite as a dll?). Good luck on the rest of you implementation! -dave > -Original Message- > From: sqlite-users-boun...@sqlite.org > [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of vendomele > Sent: Wednesday, September 10, 2014 10:01 AM > To: sqlite-users@sqlite.org > Subject: Re: [sqlite] Error with xBestIndex > > > Thanks a lot Dave > > The problem came from SQLite3_vtab's attributte: zErrMsg. > > It was not initialized to null. > > Now I have more crashes, I can continue the development of > the loadable > extension. > > For your information, I develop in Delphi, it is not too difficult to > transcribe C in Delphi > > > > -- > View this message in context: > http://sqlite.1065341.n5.nabble.com/Error-with-xBestIndex-tp77 808p77820.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error with xBestIndex
Thanks a lot Dave The problem came from SQLite3_vtab's attributte: zErrMsg. It was not initialized to null. Now I have more crashes, I can continue the development of the loadable extension. For your information, I develop in Delphi, it is not too difficult to transcribe C in Delphi -- View this message in context: http://sqlite.1065341.n5.nabble.com/Error-with-xBestIndex-tp77808p77820.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error with xBestIndex
Hi Dominique, Yes I started by creating a user defined function, I followed the example of the "half" function we can find everywhere on the Internet and it works My loadable extension manages to create a virtual table when I send the "CREATE VIRTUAL TABLE x USING ..." SQL command, I can see the newly created table, but the queries "SELECT ..." with or without "WHERE" do not work. -- View this message in context: http://sqlite.1065341.n5.nabble.com/Error-with-xBestIndex-tp77808p77819.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error with xBestIndex
Hi Dominique, Yes I started by creating a user defined function, I followed the example of the "half" function we can find everywhere on the Internet and it works My loadable extension manages to create a virtual table when I send the "CREATE VIRTUAL TABLE x USING ..." SQL command, I can see the newly created table, but the queries "SELECT ..." with or without "WHERE" do not work. -- View this message in context: http://sqlite.1065341.n5.nabble.com/Error-with-xBestIndex-tp77808p77815.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error with xBestIndex
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: sqlite-users-boun...@sqlite.org > [mailto:sqlite-users-boun...@sqlite.org] 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 <fve...@gmail.com> 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 > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error with xBestIndex
On Wed, Sep 10, 2014 at 11:53 AM, vendomelewrote: > 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 sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users