1From 153903e64e45fa243d4da21563e8c52a6440c42a Mon Sep 17 00:00:00 2001 2From: MartinChoo <214582617@qq.com> 3Date: Wed, 23 Jul 2025 17:47:31 +0800 4Subject: [PATCH 10/12] EnableExtensionLoading-LoadCustomTokenizer 5 6--- 7 src/shell.c | 32 ++++++++++++++++++++++++++++++++ 8 1 file changed, 32 insertions(+) 9 10diff --git a/src/shell.c b/src/shell.c 11index c1948b1..cedf118 100644 12--- a/src/shell.c 13+++ b/src/shell.c 14@@ -118,6 +118,7 @@ typedef unsigned short int u16; 15 #include <stdio.h> 16 #include <assert.h> 17 #include <math.h> 18+#include <sys/time.h> 19 #include "sqlite3.h" 20 #include "sqlite3sym.h" 21 typedef sqlite3_int64 i64; 22@@ -22190,6 +22191,32 @@ static void open_db(ShellState *p, int openFlags){ 23 } 24 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); 25 26+ int enableLoadExtension = 1; 27+ char *ErrMsg = 0; 28+ int ret_icu = SQLITE_OK; 29+ const char *extension_path = "/system/lib64/platformsdk/libcustomtokenizer.z.so"; 30+ 31+ if (access(extension_path, F_OK) == 0) { 32+ // 启用扩展加载配置 33+ ret_icu = sqlite3_db_config(p->db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, enableLoadExtension, &ErrMsg); 34+ if (ret_icu != SQLITE_OK) { 35+ eputf("ERROR: Failed to configure database for extension loading: %s\n", ErrMsg ? ErrMsg : "Unknown error"); 36+ if (ErrMsg) sqlite3_free(ErrMsg); 37+ return; 38+ } 39+ 40+ // 加载自定义扩展 41+ ret_icu = sqlite3_load_extension(p->db, extension_path, NULL, &ErrMsg); 42+ if (ret_icu != SQLITE_OK) { 43+ eputf("ERROR: Failed to load extension from: %s. Message: %s\n", extension_path, ErrMsg ? ErrMsg : "Unknown error"); 44+ if (ErrMsg) sqlite3_free(ErrMsg); 45+ return; 46+ } 47+ 48+ } else { 49+ eputf("ERROR: Extension file (%s) does NOT exist. Extension will not be loaded.\n", extension_path); 50+ } 51+ 52 /* Reflect the use or absence of --unsafe-testing invocation. */ 53 { 54 int testmode_on = ShellHasFlag(p,SHFLG_TestingMode); 55@@ -28238,6 +28265,8 @@ static int line_is_complete(char *zSql, int nSql){ 56 static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ 57 int rc; 58 char *zErrMsg = 0; 59+ struct timeval start, end; 60+ gettimeofday(&start, NULL); 61 62 open_db(p, 0); 63 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql); 64@@ -28245,6 +28274,9 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ 65 BEGIN_TIMER; 66 rc = shell_exec(p, zSql, &zErrMsg); 67 END_TIMER; 68+ gettimeofday(&end, NULL); 69+ long long elapsed_us = (end.tv_sec - start.tv_sec) * 1000000LL + (end.tv_usec - start.tv_usec); 70+ eputf("cost: %lld us\n", elapsed_us); 71 if( rc || zErrMsg ){ 72 char zPrefix[100]; 73 const char *zErrorTail; 74-- 752.47.0.windows.2 76 77