Re: [sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
GOT IT. Well, I found my mistake that lead to all this. I'm sorry to have wasted your time. Here's what happened for those who struggle with similar issues... I originally opted to make sqlite3_module a member of my C++ "module" class. My C++ constructor was therefore assigning all the xFunctions to that module's members. Later, without realizing the impact, my implementation changed so my class derived sqlite3_module. However, I failed to switch the xFunc assignements to this->xFunc = foo; In the end, it was exactly as if I had never assigned anything to them. Thank you all very much! :) Simon On Fri, Oct 4, 2013 at 3:14 PM, Simonwrote: > The option was already on for my own stuff but not sqlite. However, I > just had to recompile libSqlite3 with debug option to get more details and > it's a bit scary... > > SQL query using sqlite3_exec() and stmt: create virtual table foo using > vtable_module1; > -Calling sqlite3_prepare_v2()... > -Calling sqlite3_step()... > staging.bin: sqlite3.c:103774: vtabCallConstructor: Assertion `xConstruct' > failed. > > What's that xConstruct?! I can't even grep that in the sqlite source > files! :( > > After having browsed around, I think it might actually be a macro > (somehow) which aliases either xCreate or xConnect depending on the > situation, but this is just a guess... and still, it doesn't really help. > I reviewed my xCreate and xConnect and they look fine at first glance... > > Thanks, > Simon > > > On Fri, Oct 4, 2013 at 2:26 PM, Richard Hipp wrote: > >> >> >> >> On Fri, Oct 4, 2013 at 2:22 PM, Simon wrote: >> >>> Hi Richard, >>> >>> That helped a lot and got me passed that point. However, I didn't go >>> very far from where I were... >>> >>> It now compiles fine, however the program segfaults within the >>> sqlite3_step() of the "create virtual table foo using vtable_module1;" >>> statement. >>> >>> Using valgrind, I get this interesting message: >>> >>> ==31748== Jump to the invalid address stated on the next line >>> ==31748== at 0x0: ??? >>> ==31748== by 0x5A0D119: vtabCallConstructor (in >>> /usr/lib64/libsqlite3.so.0.8.6) >>> ==31748== by 0x5A3D499: sqlite3VdbeExec (in >>> /usr/lib64/libsqlite3.so.0.8.6) >>> ==31748== by 0x5A3E969: sqlite3_step (in /usr/lib64/libsqlite3.so.0.8.6) >>> [...] >>> >>> This looks (to me) like one of the NULL function pointers in struct >>> sqlite3_module is being called. I added a valid xRename() function as I >>> had initially thought it was optionnal, but still not working. I then >>> tried creating a dummy function for every one of these pointers, but I get >>> the same result. I even tried changing the "create virtual..." statement >>> to include module params (which my module ignores) but again it didn't >>> change anything. >>> >>> Where should I look at next? >>> >>> >> Recompile with line-number information (-g is it?) so that you know >> exactly which line of code tried to jump to the NULL pointer. Then you'll >> know exactly which method you need to add. >> >> >> -- >> D. Richard Hipp >> d...@sqlite.org >> > > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
The option was already on for my own stuff but not sqlite. However, I just had to recompile libSqlite3 with debug option to get more details and it's a bit scary... SQL query using sqlite3_exec() and stmt: create virtual table foo using vtable_module1; -Calling sqlite3_prepare_v2()... -Calling sqlite3_step()... staging.bin: sqlite3.c:103774: vtabCallConstructor: Assertion `xConstruct' failed. What's that xConstruct?! I can't even grep that in the sqlite source files! :( After having browsed around, I think it might actually be a macro (somehow) which aliases either xCreate or xConnect depending on the situation, but this is just a guess... and still, it doesn't really help. I reviewed my xCreate and xConnect and they look fine at first glance... Thanks, Simon On Fri, Oct 4, 2013 at 2:26 PM, Richard Hippwrote: > > > > On Fri, Oct 4, 2013 at 2:22 PM, Simon wrote: > >> Hi Richard, >> >> That helped a lot and got me passed that point. However, I didn't go >> very far from where I were... >> >> It now compiles fine, however the program segfaults within the >> sqlite3_step() of the "create virtual table foo using vtable_module1;" >> statement. >> >> Using valgrind, I get this interesting message: >> >> ==31748== Jump to the invalid address stated on the next line >> ==31748== at 0x0: ??? >> ==31748== by 0x5A0D119: vtabCallConstructor (in >> /usr/lib64/libsqlite3.so.0.8.6) >> ==31748== by 0x5A3D499: sqlite3VdbeExec (in >> /usr/lib64/libsqlite3.so.0.8.6) >> ==31748== by 0x5A3E969: sqlite3_step (in /usr/lib64/libsqlite3.so.0.8.6) >> [...] >> >> This looks (to me) like one of the NULL function pointers in struct >> sqlite3_module is being called. I added a valid xRename() function as I >> had initially thought it was optionnal, but still not working. I then >> tried creating a dummy function for every one of these pointers, but I get >> the same result. I even tried changing the "create virtual..." statement >> to include module params (which my module ignores) but again it didn't >> change anything. >> >> Where should I look at next? >> >> > Recompile with line-number information (-g is it?) so that you know > exactly which line of code tried to jump to the NULL pointer. Then you'll > know exactly which method you need to add. > > > -- > D. Richard Hipp > d...@sqlite.org > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
On Fri, Oct 4, 2013 at 2:22 PM, Simonwrote: > Hi Richard, > > That helped a lot and got me passed that point. However, I didn't go very > far from where I were... > > It now compiles fine, however the program segfaults within the > sqlite3_step() of the "create virtual table foo using vtable_module1;" > statement. > > Using valgrind, I get this interesting message: > > ==31748== Jump to the invalid address stated on the next line > ==31748== at 0x0: ??? > ==31748== by 0x5A0D119: vtabCallConstructor (in > /usr/lib64/libsqlite3.so.0.8.6) > ==31748== by 0x5A3D499: sqlite3VdbeExec (in /usr/lib64/libsqlite3.so.0.8.6) > ==31748== by 0x5A3E969: sqlite3_step (in /usr/lib64/libsqlite3.so.0.8.6) > [...] > > This looks (to me) like one of the NULL function pointers in struct > sqlite3_module is being called. I added a valid xRename() function as I > had initially thought it was optionnal, but still not working. I then > tried creating a dummy function for every one of these pointers, but I get > the same result. I even tried changing the "create virtual..." statement > to include module params (which my module ignores) but again it didn't > change anything. > > Where should I look at next? > > Recompile with line-number information (-g is it?) so that you know exactly which line of code tried to jump to the NULL pointer. Then you'll know exactly which method you need to add. -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
Hi Richard, That helped a lot and got me passed that point. However, I didn't go very far from where I were... It now compiles fine, however the program segfaults within the sqlite3_step() of the "create virtual table foo using vtable_module1;" statement. Using valgrind, I get this interesting message: ==31748== Jump to the invalid address stated on the next line ==31748== at 0x0: ??? ==31748== by 0x5A0D119: vtabCallConstructor (in /usr/lib64/libsqlite3.so.0.8.6) ==31748== by 0x5A3D499: sqlite3VdbeExec (in /usr/lib64/libsqlite3.so.0.8.6) ==31748== by 0x5A3E969: sqlite3_step (in /usr/lib64/libsqlite3.so.0.8.6) [...] This looks (to me) like one of the NULL function pointers in struct sqlite3_module is being called. I added a valid xRename() function as I had initially thought it was optionnal, but still not working. I then tried creating a dummy function for every one of these pointers, but I get the same result. I even tried changing the "create virtual..." statement to include module params (which my module ignores) but again it didn't change anything. Where should I look at next? Thanks again for your help, Simon On Fri, Oct 4, 2013 at 10:54 AM, Richard Hippwrote: > > > > On Fri, Oct 4, 2013 at 10:07 AM, Simon wrote: > >> >> 3) I call sqlite3_create_module() with module name "vtable1" >> >> 4) I call sqlite3_declare_vtab() with this statement: "CREATE TABLE foo ( >> x >> integer, y integer );" >> > > > The application must never invoke sqlite3_declare_vtab(). The > sqlite3_declare_vtab() interface can only be called from within the xCreate > and xConnect methods of the virtual table implementation. If called from > any other context, sqlite3_declare_vtab() returns the error you describe. > > When you run "CREATE VIRTUAL TABLE name USING module;" the xCreate method > is called to create the new virtual table. The xCreate method needs to > tell the SQLite core what the schema for the virtual table is and it uses > sqlite3_declare_vtab() to do so. > > -- > D. Richard Hipp > d...@sqlite.org > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
On Fri, Oct 4, 2013 at 10:07 AM, Simonwrote: > > 3) I call sqlite3_create_module() with module name "vtable1" > > 4) I call sqlite3_declare_vtab() with this statement: "CREATE TABLE foo ( x > integer, y integer );" > The application must never invoke sqlite3_declare_vtab(). The sqlite3_declare_vtab() interface can only be called from within the xCreate and xConnect methods of the virtual table implementation. If called from any other context, sqlite3_declare_vtab() returns the error you describe. When you run "CREATE VIRTUAL TABLE name USING module;" the xCreate method is called to create the new virtual table. The xCreate method needs to tell the SQLite core what the schema for the virtual table is and it uses sqlite3_declare_vtab() to do so. -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
Simon, don't know what exactly wrong in your particular case, but I'd suggest setting debugger breakpoints everywhere in your x-handlers and notice the moment after which calls are ceased (or you get a error code). Max On Fri, Oct 4, 2013 at 6:07 PM, Simonwrote: > Hi there, > > I'm currently building my own virtual table implementation. I've built a > dummy vtable that returns the string "1" to all queries for all columns > but I'm having trouble getting started (getting a 'misuse' error). Can > someone help me get in the right direction? > > > > > > 1) I first create an sqlite3* object in ":memory:". This one works fine. > > 2) Allocate and init my derived sqlite3_module* object. > 2.1) Function pointers I use are Create,Destroy, Connect,Disconnect, > Open,Close, BestIndex,Filter, Next,Eof, Column,Rowid. > 2.2) NULL pointers for Update, Begin,Sync,Commit,Rollback, > FindFunction,Rename, Savepoint,Release,RollbackTo. > 2.3) *** ? *** Are there any other members not documented I'd need to init? > > 3) I call sqlite3_create_module() with module name "vtable1" > > 4) I call sqlite3_declare_vtab() with this statement: "CREATE TABLE foo ( x > integer, y integer );" > > --> That one fails with ERROR 21 (lib misuse). > > < > > > Did I forget a step? Do them in wrong order? Anything obvious seems wrong > to you? Where should I go to get more details and fix the issue? > My current implementation is rather complex and involves C++ and templates > a lot. Making a "small example" would be highly time-consuming, so I'd > prefer to avoid going that way if possible. > > Anyone can tell me where I'd find a simple functionnal vtable "hello > world"? The vtable documentation is great but is missing examples, imo. > Personnally, I think the vtable documentation page could benefit from one > example project throughout and develop it. Something like a basic CSV > vtable would probably help the masses a lot! :) > > Thanks for your help and time, > Simon > ___ > 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
[sqlite] Virtual Table: misuse error on sqlite3_declare_vtab()
Hi there, I'm currently building my own virtual table implementation. I've built a dummy vtable that returns the string "1" to all queries for all columns but I'm having trouble getting started (getting a 'misuse' error). Can someone help me get in the right direction? > 1) I first create an sqlite3* object in ":memory:". This one works fine. 2) Allocate and init my derived sqlite3_module* object. 2.1) Function pointers I use are Create,Destroy, Connect,Disconnect, Open,Close, BestIndex,Filter, Next,Eof, Column,Rowid. 2.2) NULL pointers for Update, Begin,Sync,Commit,Rollback, FindFunction,Rename, Savepoint,Release,RollbackTo. 2.3) *** ? *** Are there any other members not documented I'd need to init? 3) I call sqlite3_create_module() with module name "vtable1" 4) I call sqlite3_declare_vtab() with this statement: "CREATE TABLE foo ( x integer, y integer );" --> That one fails with ERROR 21 (lib misuse). < Did I forget a step? Do them in wrong order? Anything obvious seems wrong to you? Where should I go to get more details and fix the issue? My current implementation is rather complex and involves C++ and templates a lot. Making a "small example" would be highly time-consuming, so I'd prefer to avoid going that way if possible. Anyone can tell me where I'd find a simple functionnal vtable "hello world"? The vtable documentation is great but is missing examples, imo. Personnally, I think the vtable documentation page could benefit from one example project throughout and develop it. Something like a basic CSV vtable would probably help the masses a lot! :) Thanks for your help and time, Simon ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users