Thanks, Keith.

________________________________
From: Keith Medcalf <kmedc...@dessus.com>
Sent: Friday, December 6, 2019 05:34 PM
To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
Cc: Jose Isaias Cabrera <jic...@outlook.com>
Subject: RE: .expert disables loaded extensions


On Friday, 6 December, 2019 07:49. Jose Isaias Cabrera <jic...@outlook.com> 
wrote:

>please observe the following:
> 9:45:49.39>sqlite3
>SQLite version 3.30.0 2019-10-04 15:03:17
>Enter ".help" for usage hints.
>Connected to a transient in-memory database.
>Use ".open FILENAME" to reopen on a persistent database.
>sqlite> .load c:\\PMOProjects\\libsqlite3decimal sqlite3_decimal_init
>sqlite> select decStr('1.7654');
>1.7654
>sqlite> .expert
>sqlite> select decStr('1.7654');
>Error: no such function: decStr
>sqlite>
>
>This is kind of a drag because I use expert a lot for setting indexes
>when searches are slow.  Any thoughts?  Thanks.

Actually, .expert opens another connection, and that connection does not have 
any non-autoinit extensions loaded.  You can "fix" this by applying the 
following patch to decimal.c which adds a static to keep track of the fact that 
the module has been loaded, and then adds it to the autoinit list so that it is 
activated on all subsequent connections automatically.  This means that with 
this patch you only need to load the module once and it will automatically be 
active on all subsequently created connections ... you do not need to load it 
each time, only once per process.

Index: ext/private/decimal/decimal.c
==================================================================
--- ext/private/decimal/decimal.c
+++ ext/private/decimal/decimal.c
@@ -712,17 +712,18 @@

 #endif /* SQLITE_OMIT_VIRTUALTABLE */

 #pragma mark Public interface

+static int autoinit = 1;
+
 /**
  ** \brief Entry point of the SQLite3 Decimal extension.
  **/
 #ifdef _WIN32
 __declspec(dllexport)
 #endif
-
 int sqlite3_decimal_init(sqlite3* db, char** pzErrMsg, sqlite3_api_routines 
const* pApi) {

   (void)pzErrMsg;

   int rc = SQLITE_OK;
@@ -846,9 +847,10 @@
   if (rc == SQLITE_OK) {
     rc = sqlite3_create_module_v2(db, SQLITE_DECIMAL_PREFIX "Context",
                                   &decimalContextModule, decimalSharedContext, 
decimalContextDestroy);
   }
 #endif
-
-  return rc;
+  if (autoinit) sqlite3_auto_extension((void*)sqlite3_decimal_init);
+  autoinit = 0;
+  return rc == SQLITE_OK ? SQLITE_OK_LOAD_PERMANENTLY : rc;
 }

--
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to