From 2cd5db62dd82d38921c95b85f256b4e6c5877802 Mon Sep 17 00:00:00 2001 From: linan <953808323@qq.com> Date: Fri, 27 Jun 2025 11:27:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E8=AF=8D=E5=99=A8=E6=97=A0patch=20Sig?= =?UTF-8?q?ned-off-by:=20qianyong325=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shell.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/shell.c b/src/shell.c index 7fb190e..541a798 100644 --- a/src/shell.c +++ b/src/shell.c @@ -22133,6 +22133,8 @@ static void shellUSleepFunc( ** the database fails to open, print an error message and exit. */ static void open_db(ShellState *p, int openFlags){ + printf("open_db 1111\n"); + eputz("open_db 1111\n"); if( p->db==0 ){ const char *zDbFilename = p->pAuxDb->zDbFilename; if( p->openMode==SHELL_OPEN_UNSPEC ){ @@ -22189,6 +22191,36 @@ static void open_db(ShellState *p, int openFlags){ } sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); + // 添加启用扩展加载的配置项 + int enableLoadExtension = 1; + char *ErrMsg = 0; + int ret_icu; + ret_icu = sqlite3_db_config(p->db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, enableLoadExtension, &ErrMsg); + printf("sqlite3_db_config\n"); + eputz("sqlite3_db_config\n"); + if (ret_icu != SQLITE_OK) { + fprintf(stderr, "Failed to configure database: %s\n", ErrMsg ? ErrMsg : "Unknown error"); + eputf("Error: Failed to configure database: %s\n", ErrMsg ? ErrMsg : "Unknown error"); + if (ErrMsg) sqlite3_free(ErrMsg); + } + + if (access("libcustomtokenizer.z.so", F_OK) != 0) { + fprintf(stderr, "Extension file 'libcustomtokenizer.z.so' does not exist.\n"); + eputf("Error: Extension file 'libcustomtokenizer.z.so' does not exist.\n"); + exit(1); // Exit if the extension file does not exist + } + + // 加载自定义扩展 + ret_icu = sqlite3_load_extension(p->db, "libcustomtokenizer.z.so", NULL, &ErrMsg); + printf("sqlite3_load_extension\n"); + eputz("sqlite3_load_extension\n"); + if (ret_icu != SQLITE_OK) { + fprintf(stderr, "Failed to load extension: %s\n", ErrMsg ? ErrMsg : "Unknown error"); + eputf("Error: Failed to configure database: %s\n", ErrMsg ? ErrMsg : "Unknown error"); + if (ErrMsg) sqlite3_free(ErrMsg); + exit(1); // Exit if the extension cannot be loaded + } + /* Reflect the use or absence of --unsafe-testing invocation. */ { int testmode_on = ShellHasFlag(p,SHFLG_TestingMode); @@ -24775,6 +24807,8 @@ static int do_meta_command(char *zLine, ShellState *p){ goto meta_command_exit; } open_db(p, 0); + printf("open_db 222\n"); + eputz("open_db 222\n"); if( booleanValue(azArg[1]) ){ sqlite3_set_authorizer(p->db, shellAuth, p); }else if( p->bSafeModePersist ){ @@ -24847,6 +24881,8 @@ static int do_meta_command(char *zLine, ShellState *p){ 0, 0, 0); } open_db(p, 0); + printf("open_db 333\n"); + eputz("open_db 333\n"); pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb); if( pBackup==0 ){ eputf("Error: %s\n", sqlite3_errmsg(pDest)); @@ -25032,6 +25068,8 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_stmt *pStmt; int i; open_db(p, 0); + printf("open_db 444\n"); + eputz("open_db 444\n"); rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); if( rc ){ eputf("Error: %s\n", sqlite3_errmsg(p->db)); @@ -25089,6 +25127,8 @@ static int do_meta_command(char *zLine, ShellState *p){ }; int ii, v; open_db(p, 0); + printf("open_db 5555\n"); + eputz("open_db 5555\n"); for(ii=0; ii1 && cli_strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue; if( nArg>=3 ){ @@ -25178,6 +25218,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } open_db(p, 0); + printf("open_db 666\n"); + eputz("open_db 666\n"); if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ /* When playing back a "dump", the content might appear in an order @@ -25306,6 +25348,8 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; }else{ open_db(p, 0); + printf("open_db 7777\n"); + eputz("open_db 7777\n"); expertDotCommand(p, azArg, nArg); } }else @@ -25338,6 +25382,8 @@ static int do_meta_command(char *zLine, ShellState *p){ const char *zSchema = 0; open_db(p, 0); + printf("open_db 888\n"); + eputz("open_db 888\n"); zCmd = nArg>=2 ? azArg[1] : "help"; if( zCmd[0]=='-' @@ -25473,6 +25519,8 @@ static int do_meta_command(char *zLine, ShellState *p){ goto meta_command_exit; } open_db(p, 0); + printf("open_db 999\n"); + eputz("open_db 999\n"); rc = sqlite3_exec(p->db, "SELECT sql FROM" " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x" @@ -25598,6 +25646,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } seenInterrupt = 0; open_db(p, 0); + printf("open_db 101010\n"); + eputz("open_db 101010\n"); if( useOutputMode ){ /* If neither the --csv or --ascii options are specified, then set ** the column and row separator characters from the output mode. */ @@ -25854,6 +25904,8 @@ static int do_meta_command(char *zLine, ShellState *p){ goto meta_command_exit; } open_db(p, 0); + printf("open_db 111111111\n"); + eputz("open_db 111111111\n"); if( nArg==2 ){ sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1); goto meta_command_exit; @@ -25973,6 +26025,8 @@ static int do_meta_command(char *zLine, ShellState *p){ }; int i, n2; open_db(p, 0); + printf("open_db 12121212\n"); + eputz("open_db 12121212\n"); if( nArg==1 ){ for(i=0; i2 && cli_strncmp(azArg[0], "lint", n)==0 ){ open_db(p, 0); + printf("open_db 13131313\n"); + eputz("open_db 13131313\n"); lintDotCommand(p, azArg, nArg); }else @@ -26031,6 +26087,8 @@ static int do_meta_command(char *zLine, ShellState *p){ zFile = azArg[1]; zProc = nArg>=3 ? azArg[2] : 0; open_db(p, 0); + printf("open_db 14141414\n"); + eputz("open_db 1411414141\n"); rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg); if( rc!=SQLITE_OK ){ eputf("Error: %s\n", zErrMsg); @@ -26287,6 +26345,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } p->pAuxDb->zDbFilename = zNewFilename; open_db(p, OPEN_DB_KEEPALIVE); + printf("open_db 151515151\n"); + eputz("open_db 151515151\n"); if( p->db==0 ){ eputf("Error: cannot open '%s'\n", zNewFilename); sqlite3_free(zNewFilename); @@ -26298,6 +26358,8 @@ static int do_meta_command(char *zLine, ShellState *p){ /* As a fall-back open a TEMP database */ p->pAuxDb->zDbFilename = 0; open_db(p, 0); + printf("open_db 161616161\n"); + eputz("open_db 16161616161\n"); } }else @@ -26417,6 +26479,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='p' && n>=3 && cli_strncmp(azArg[0], "parameter", n)==0 ){ open_db(p,0); + printf("open_db 181818\n"); + eputz("open_db 181818\n"); if( nArg<=1 ) goto parameter_syntax_error; /* .parameter clear @@ -26570,6 +26634,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } } open_db(p, 0); + printf("open_db 19191919\n"); + eputz("open_db 191919\n"); sqlite3_progress_handler(p->db, nn, progress_handler, p); }else #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */ @@ -26653,6 +26719,8 @@ static int do_meta_command(char *zLine, ShellState *p){ return 1; } open_db(p, 0); + printf("open_db 20\n"); + eputz("open_db 20\n"); pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main"); if( pBackup==0 ){ eputf("Error: %s\n", sqlite3_errmsg(p->db)); @@ -26691,6 +26759,8 @@ static int do_meta_command(char *zLine, ShellState *p){ p->scanstatsOn = (u8)booleanValue(azArg[1]); } open_db(p, 0); + printf("open_db 21\n"); + eputz("open_db 21\n"); sqlite3_db_config( p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0 ); @@ -26719,6 +26789,8 @@ static int do_meta_command(char *zLine, ShellState *p){ int ii; open_db(p, 0); + printf("open_db 22\n"); + eputz("open_db 22\n"); memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.cMode = data.mode = MODE_Semi; @@ -27087,6 +27159,8 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_stmt *pStmt = 0; /* Query against the SELFTEST table */ open_db(p,0); + printf("open_db 23\n"); + eputz("open_db 23\n"); for(i=1; idb, "PRAGMA database_list", -1, &pStmt, 0); if( rc ){ sqlite3_finalize(pStmt); @@ -27630,6 +27708,8 @@ static int do_meta_command(char *zLine, ShellState *p){ const char *zCmd = 0; open_db(p, 0); + printf("open_db 26\n"); + eputz("open_db 26\n"); zCmd = nArg>=2 ? azArg[1] : "help"; /* The argument can optionally begin with "-" or "--" */ @@ -27840,6 +27920,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='t' && n>4 && cli_strncmp(azArg[0], "timeout", n)==0 ){ open_db(p, 0); + printf("open_db 27\n"); + eputz("open_db 27\n"); sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0); }else @@ -27861,6 +27943,8 @@ static int do_meta_command(char *zLine, ShellState *p){ int mType = 0; int jj; open_db(p, 0); + printf("open_db 28\n"); + eputz("open_db 28\n"); for(jj=1; jjflgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; BEGIN_TIMER; @@ -29089,6 +29175,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ */ if( access(data.pAuxDb->zDbFilename, 0)==0 ){ open_db(&data, 0); + printf("open_db 31\n"); + eputz("open_db 31\n"); } /* Process the initialization file if there is one. If no -init option @@ -29247,6 +29335,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( rc && bail_on_error ) return rc==2 ? 0 : rc; }else{ open_db(&data, 0); + printf("open_db 32\n"); + eputz("open_db 32\n"); rc = shell_exec(&data, z, &zErrMsg); if( zErrMsg!=0 ){ eputf("Error: %s\n", zErrMsg); @@ -29299,6 +29389,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ } }else{ open_db(&data, 0); + printf("open_db 34\n"); + eputz("open_db 34\n"); echo_group_input(&data, azCmd[i]); rc = shell_exec(&data, azCmd[i], &zErrMsg); if( zErrMsg || rc ){ -- Gitee