]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the test/testloadext.c loadable extension to test the ability to use
authordrh <>
Tue, 14 Oct 2025 17:50:55 +0000 (17:50 +0000)
committerdrh <>
Tue, 14 Oct 2025 17:50:55 +0000 (17:50 +0000)
the latest APIs using the loadable extension mechanism.

FossilOrigin-Name: a9bd7ed6f77c5e53f9130eac7eb999c662e9158fb229a462d29f18653284d6d0

manifest
manifest.uuid
test/testloadext.c [new file with mode: 0644]

index d3b09864a657291d0bdf304e6bf0796afc32e997..dfccbb0aec31016e10be7d8916ac02398bfca369 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\ssqlite3_db_status64()\sinterface\sand\sthe\nSQLITE_DBSTATUS_TEMPSTORE_SPILL\soption\sfor\suse\sin\sthat\sinterface.
-D 2025-10-14T17:09:06.733
+C Add\sthe\stest/testloadext.c\sloadable\sextension\sto\stest\sthe\sability\sto\suse\nthe\slatest\sAPIs\susing\sthe\sloadable\sextension\smechanism.
+D 2025-10-14T17:50:55.573
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -1692,6 +1692,7 @@ F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d163
 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637
 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc
 F test/tester.tcl 463ae33b8bf75ac77451df19bd65e7c415c2e9891227c7c9e657d0a2d8e1074a
+F test/testloadext.c 862b848783eaed9985fbce46c65cd214664376b549fae252b364d5d1ef350a27 w test/test-ext.c
 F test/testrunner.tcl 9da764507f6bc752961555c0beb58eb6584b9fb0f989342c7eaab3336380f560 x
 F test/testrunner_data.tcl c507a9afa911c03446ed90442ffd4a98aca02882c3d51bd1177c24795674def8
 F test/testrunner_estwork.tcl 7927a84327259a32854926f68a75292e33a61e7e052fdbfcb01f18696c99c724
@@ -2170,9 +2171,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 0f96eaeaa8c51c20f8d389bfd6d0d6371e8bb29ff7e8eaf3a0bcb35cb2b73338 2ebd7330312f3ee4674c343b7a19b703f1f89611a6846a0e2be39867f9895522
-R 121000212212aa3f111559e6bc700918
-T +closed 2ebd7330312f3ee4674c343b7a19b703f1f89611a6846a0e2be39867f9895522
+P 9f8739ddea6ec6d8890d0e8f6a0143773a008e4f96bd02a48d4bfebb3f9b72fe
+R 3bcf978653b0a415b88bad0bfdf06784
 U drh
-Z 182d0b439b0bbac3a39e1ec11f805251
+Z b8c7c6f6653660ab0ef54150557725dd
 # Remove this line to create a well-formed Fossil manifest.
index fd9f0e7ae811b191d3b0d416c29d63b54a5a12fa..c2f968c3ceded3c6b9d1f56ad3a3712b1352ef27 100644 (file)
@@ -1 +1 @@
-9f8739ddea6ec6d8890d0e8f6a0143773a008e4f96bd02a48d4bfebb3f9b72fe
+a9bd7ed6f77c5e53f9130eac7eb999c662e9158fb229a462d29f18653284d6d0
diff --git a/test/testloadext.c b/test/testloadext.c
new file mode 100644 (file)
index 0000000..94cd312
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+** 2025-10-14
+**
+** The author disclaims copyright to this source code.  In place of
+** a legal notice, here is a blessing:
+**
+**    May you do good and not evil.
+**    May you find forgiveness for yourself and forgive others.
+**    May you share freely, never taking more than you give.
+**
+******************************************************************************
+**
+** Test the ability of run-time extension loading to use the
+** very latest interfaces.
+**
+** Compile something like this:
+**
+** Linux:  gcc -g -fPIC shared testloadext.c -o testloadext.so
+**
+** Mac:    cc -g -fPIC -dynamiclib testloadext.c -o testloadext.dylib
+**
+** Win11:  cl testloadext.c -link -dll -out:testloadext.dll
+*/
+#include "sqlite3ext.h"
+SQLITE_EXTENSION_INIT1
+#include <assert.h>
+#include <string.h>
+
+/*
+** Implementation of the set_errmsg(CODE,MSG) SQL function.
+**
+** Raise an error that has numeric code CODE and text message MSG
+** using the sqlite3_set_errmsg() API.
+*/
+static void seterrmsgfunc(
+  sqlite3_context *context,
+  int argc,
+  sqlite3_value **argv
+){
+  sqlite3 *db;
+  char *zRes;
+  int rc;
+  assert( argc==2 );
+  db = sqlite3_context_db_handle(context);
+  rc = sqlite3_set_errmsg(db, 
+     sqlite3_value_int(argv[0]),
+     sqlite3_value_text(argv[1]));
+  zRes = sqlite3_mprintf("%d %d %s",
+              rc, sqlite3_errcode(db), sqlite3_errmsg(db));
+  sqlite3_result_text64(context, zRes, strlen(zRes),
+                        SQLITE_TRANSIENT, SQLITE_UTF8);
+  sqlite3_free(zRes);
+}
+
+/*
+** Implementation of the tempbuf_spill() SQL function.
+**
+** Return the value of SQLITE_DBSTATUS_TEMPBUF_SPILL.
+*/
+static void tempbuf_spill_func(
+  sqlite3_context *context,
+  int argc,
+  sqlite3_value **argv
+){
+  sqlite3 *db;
+  sqlite3_int64 iHi = 0, iCur = 0;
+  int rc;
+  int bReset;
+  assert( argc==1 );
+  bReset = sqlite3_value_int(argv[0]);
+  db = sqlite3_context_db_handle(context);
+  (void)sqlite3_db_status64(db, SQLITE_DBSTATUS_TEMPBUF_SPILL,
+                            &iCur, &iHi, bReset);
+  sqlite3_result_int64(context, iCur);
+}
+
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int sqlite3_testloadext_init(
+  sqlite3 *db, 
+  char **pzErrMsg, 
+  const sqlite3_api_routines *pApi
+){
+  int rc = SQLITE_OK;
+  SQLITE_EXTENSION_INIT2(pApi);
+  (void)pzErrMsg;  /* Unused parameter */
+  rc = sqlite3_create_function(db, "set_errmsg", 2,
+                   SQLITE_UTF8,
+                   0, seterrmsgfunc, 0, 0);
+  if( rc ) return rc;
+  rc = sqlite3_create_function(db, "tempbuf_spill", 1,
+                   SQLITE_UTF8,
+                   0, tempbuf_spill_func, 0, 0);
+  if( rc ) return rc;
+  return SQLITE_OK;
+}