You can use sqlite3_auto_extension for this.
On 19 March 2017 at 11:35, R Smith <rsm...@rsweb.co.za> wrote: > > On 2017/03/19 11:05 AM, petern wrote: >> >> Taking DRH's remarks about learning tclsqlite for the efficient coding to >> heart, I discovered a big problem. >> >> Here is the simplest example from the docs and DRH presentation: >> >> TCLSH >> % db function myhex {format 0x%X}; >> % db eval {select myhex(10);} x {parray x}; >> x(*) = myhex(10) >> x(myhex(10)) = 0xA >> >> Now, on the same database with simultaneous connection eg: shell, odbc, >> etc: >> >> sqlite> select myhex(10); >> Run Time: real 0.000 user 0.000000 sys 0.000000 >> Error: no such function: myhex >> >> >> ----------------------------------------------------------------------------- >> Did I missing something in the docs? >> Is there a trick/pragma to make this work? >> >> Tclsqlite is extremely efficiently for extending sqlite but this facility >> is generally useless if the whole application must be ported to (or at >> least all db queries funneled through) TCLSH to use those easy to build >> extensions. What if the outer application can't be ported to TCL? > > > Adding a custom function (Whether done in your code using the API or using > TCL or whatever) makes that function belong to the connection, a function > cannot belong to the database or persist outside of the creating connection. > tclsqlite is a great way to code for examples or reproducible bugs or even > full DB maintenance scripts - but you can't use it together with your normal > program code from a different connection. I'm not sure if there exist any > way (or hack) to achieve this, maybe someone else knows, but what you tried > won't work. > > This is not a tclsqlite problem, if you open a connection from one of your > programs, add to it a custom function, and then open another connection to > the same DB from one of your other programs, the custom function will of > course NOT exist for the second connection - it's strictly a per-connection > thing, and the second connection must register its own custom function. > > There exist some add-ons for sqlite which introduce ways of creating custom > functions INSIDE the SQL via a query. Not sure if this will solve your > problem, if so ask again (or google) for links to them. > > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users