Fossil SCM

Update the built-in SQLite to the latest trunk version, which perhaps restores the ability to compile Fossil using WindowsXP.

drh 2025-12-22 11:31 trunk
Commit 5f65ed513db93fb7c34d2ae007b63a2727a97403d7647817672e52eb94218eb8
+363 -167
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1581,13 +1581,15 @@
15811581
** (3) z[] does not looks like a numeric literal
15821582
*/
15831583
static int qrfRelaxable(Qrf *p, const char *z){
15841584
size_t i, n;
15851585
if( z[0]=='\'' || qrfSpace(z[0]) ) return 0;
1586
- if( z[0]==0 && (p->spec.zNull==0 || p->spec.zNull[0]==0) ) return 0;
1586
+ if( z[0]==0 ){
1587
+ return (p->spec.zNull!=0 && p->spec.zNull[0]!=0);
1588
+ }
15871589
n = strlen(z);
1588
- if( z[n-1]=='\'' || qrfSpace(z[n-1]) ) return 0;
1590
+ if( n==0 || z[n-1]=='\'' || qrfSpace(z[n-1]) ) return 0;
15891591
if( p->spec.zNull && strcmp(p->spec.zNull,z)==0 ) return 0;
15901592
i = (z[0]=='-' || z[0]=='+');
15911593
if( strcmp(z+i,"Inf")==0 ) return 0;
15921594
if( !qrfDigit(z[i]) ) return 1;
15931595
i++;
@@ -10180,15 +10182,22 @@
1018010182
}
1018110183
return pRe->zErr;
1018210184
}
1018310185
1018410186
/*
10185
-** Compute a reasonable limit on the length of the REGEXP NFA.
10187
+** The value of LIMIT_MAX_PATTERN_LENGTH.
1018610188
*/
1018710189
static int re_maxlen(sqlite3_context *context){
1018810190
sqlite3 *db = sqlite3_context_db_handle(context);
10189
- return 75 + sqlite3_limit(db, SQLITE_LIMIT_LIKE_PATTERN_LENGTH,-1)/2;
10191
+ return sqlite3_limit(db, SQLITE_LIMIT_LIKE_PATTERN_LENGTH,-1);
10192
+}
10193
+
10194
+/*
10195
+** Maximum NFA size given a maximum pattern length.
10196
+*/
10197
+static int re_maxnfa(int mxlen){
10198
+ return 75+mxlen/2;
1019010199
}
1019110200
1019210201
/*
1019310202
** Implementation of the regexp() SQL function. This function implements
1019410203
** the build-in REGEXP operator. The first argument to the function is the
@@ -10210,14 +10219,21 @@
1021010219
int setAux = 0; /* True to invoke sqlite3_set_auxdata() */
1021110220
1021210221
(void)argc; /* Unused */
1021310222
pRe = sqlite3_get_auxdata(context, 0);
1021410223
if( pRe==0 ){
10224
+ int mxLen = re_maxlen(context);
10225
+ int nPattern;
1021510226
zPattern = (const char*)sqlite3_value_text(argv[0]);
1021610227
if( zPattern==0 ) return;
10217
- zErr = re_compile(&pRe, zPattern, re_maxlen(context),
10218
- sqlite3_user_data(context)!=0);
10228
+ nPattern = sqlite3_value_bytes(argv[0]);
10229
+ if( nPattern>mxLen ){
10230
+ zErr = "REGEXP pattern too big";
10231
+ }else{
10232
+ zErr = re_compile(&pRe, zPattern, re_maxnfa(mxLen),
10233
+ sqlite3_user_data(context)!=0);
10234
+ }
1021910235
if( zErr ){
1022010236
re_free(pRe);
1022110237
sqlite3_result_error(context, zErr, -1);
1022210238
return;
1022310239
}
@@ -10279,11 +10295,11 @@
1027910295
"ATSTART",
1028010296
};
1028110297
1028210298
zPattern = (const char*)sqlite3_value_text(argv[0]);
1028310299
if( zPattern==0 ) return;
10284
- zErr = re_compile(&pRe, zPattern, re_maxlen(context),
10300
+ zErr = re_compile(&pRe, zPattern, re_maxnfa(re_maxlen(context)),
1028510301
sqlite3_user_data(context)!=0);
1028610302
if( zErr ){
1028710303
re_free(pRe);
1028810304
sqlite3_result_error(context, zErr, -1);
1028910305
return;
@@ -24178,11 +24194,10 @@
2417824194
** instance of the following structure.
2417924195
*/
2418024196
typedef struct ShellState ShellState;
2418124197
struct ShellState {
2418224198
sqlite3 *db; /* The database */
24183
- int iCompat; /* Compatibility date YYYYMMDD */
2418424199
u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
2418524200
u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
2418624201
u8 nEqpLevel; /* Depth of the EQP output graph */
2418724202
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
2418824203
u8 bSafeMode; /* True to prohibit unsafe operations */
@@ -24570,18 +24585,17 @@
2457024585
p->mode.mFlags = mFlags;
2457124586
}
2457224587
}
2457324588
2457424589
/*
24575
-** Set the mode to the default according to p->iCompat. It assumed
24576
-** that the mode has already been freed and zeroed prior to calling
24577
-** this routine.
24590
+** Set the mode to the default. It assumed that the mode has
24591
+** already been freed and zeroed prior to calling this routine.
2457824592
*/
2457924593
static void modeDefault(ShellState *p){
2458024594
p->mode.spec.iVersion = 1;
2458124595
p->mode.autoExplain = 1;
24582
- if( p->iCompat>=20251115 && (stdin_is_interactive || stdout_is_console) ){
24596
+ if( stdin_is_interactive || stdout_is_console ){
2458324597
modeChange(p, MODE_TTY);
2458424598
}else{
2458524599
modeChange(p, MODE_BATCH);
2458624600
}
2458724601
}
@@ -26604,12 +26618,12 @@
2660426618
".bail on|off Stop after hitting an error. Default OFF",
2660526619
#ifndef SQLITE_SHELL_FIDDLE
2660626620
".cd DIRECTORY Change the working directory to DIRECTORY",
2660726621
#endif
2660826622
".changes on|off Show number of rows changed by SQL",
26623
+ ".check OPTIONS ... Verify the results of a .testcase",
2660926624
#ifndef SQLITE_SHELL_FIDDLE
26610
- ".check GLOB Fail if output since .testcase does not match",
2661126625
".clone NEWDB Clone data into NEWDB from the existing database",
2661226626
#endif
2661326627
".connection [close] [#] Open or close an auxiliary database connection",
2661426628
".crlf ?on|off? Whether or not to use \\r\\n line endings",
2661526629
".databases List names and files of attached databases",
@@ -26785,13 +26799,11 @@
2678526799
" vmstep Show the virtual machine step count only",
2678626800
#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
2678726801
".system CMD ARGS... Run CMD ARGS... in a system shell",
2678826802
#endif
2678926803
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
26790
-#ifndef SQLITE_SHELL_FIDDLE
26791
- ",testcase NAME Begin redirecting output to 'testcase-out.txt'",
26792
-#endif
26804
+ ".testcase NAME Begin a test case.",
2679326805
",testctrl CMD ... Run various sqlite3_test_control() operations",
2679426806
" Run \".testctrl\" with no arguments for details",
2679526807
".timeout MS Try opening locked tables for MS milliseconds",
2679626808
".timer on|off Turn SQL timer on or off",
2679726809
#ifndef SQLITE_OMIT_TRACE
@@ -26930,23 +26942,17 @@
2693026942
" --bom Prepend a byte-order mark to the output\n"
2693126943
" -e Accumulate output in a temporary text file then\n"
2693226944
" launch a text editor when the redirection ends.\n"
2693326945
" --error-prefix X Use X as the left-margin prefix for error messages.\n"
2693426946
" Set to an empty string to restore the default.\n"
26935
-" --glob GLOB Raise an error if the memory buffer does not match\n"
26936
-" the GLOB pattern.\n"
26937
-" --keep Continue using the same \"memory\" buffer. Do not\n"
26938
-" reset it or delete it. Useful in combination with\n"
26939
-" --glob, --not-glob, and/or --verify.\n"
26940
-" ---notglob GLOB Raise an error if the memory buffer does not match\n"
26941
-" the GLOB pattern.\n"
26947
+" --keep Keep redirecting output to its current destination.\n"
26948
+" Use this option in combination with --show or\n"
26949
+" with --error-prefix when you do not want to stop\n"
26950
+" a current redirection.\n"
2694226951
" --plain Use plain text rather than HTML tables with -w\n"
26943
-" --show Write the memory buffer to the screen, for debugging.\n"
26944
-" --verify ENDMARK Read subsequent lines of text until the first line\n"
26945
-" that matches ENDMARK. Discard the ENDMARK. Compare\n"
26946
-" the text against the accumulated output in memory and\n"
26947
-" raise an error if there are any differences.\n"
26952
+" --show Show output text captured by .testcase or by\n"
26953
+" redirecting to \"memory\".\n"
2694826954
" -w Show the output in a web browser. Output is\n"
2694926955
" written into a temporary HTML file until the\n"
2695026956
" redirect ends, then the web browser is launched.\n"
2695126957
" Query results are shown as HTML tables, unless\n"
2695226958
" the --plain is used too.\n"
@@ -26970,10 +26976,40 @@
2697026976
" file in a web browser\n"
2697126977
" -x Show the output in a spreadsheet. Output is\n"
2697226978
" written to a temp file as CSV then the spreadsheet\n"
2697326979
" is launched when\n"
2697426980
},
26981
+ { ".check",
26982
+"USAGE: .check [OPTIONS] PATTERN\n"
26983
+"\n"
26984
+"Verify results of commands since the most recent .testcase command.\n"
26985
+"Restore output to the console, unless --keep is used.\n"
26986
+"\n"
26987
+"If PATTERN starts with \"<<ENDMARK\" then the actual pattern is taken from\n"
26988
+"subsequent lines of text up to the first line that begins with ENDMARK.\n"
26989
+"All pattern lines and the ENDMARK are discarded.\n"
26990
+"\n"
26991
+"Options:\n"
26992
+" --error-prefix TEXT Change error message prefix text to TEXT\n"
26993
+" --exact Do an exact comparison including leading and\n"
26994
+" trailing whitespace.\n"
26995
+" --glob Treat PATTERN as a GLOB\n"
26996
+" --keep Do not reset the testcase. More .check commands\n"
26997
+" will follow.\n"
26998
+" --notglob Output should not match PATTERN\n"
26999
+" --show Write testcase output to the screen, for debugging.\n"
27000
+ },
27001
+ { ".testcase",
27002
+"USAGE: .testcase [OPTIONS] NAME\n"
27003
+"\n"
27004
+"Start a new test case identified by NAME. All output\n"
27005
+"through the next \".check\" command is captured for comparison. See the\n"
27006
+"\".check\" commandn for additional informatioon.\n"
27007
+"\n"
27008
+"Options:\n"
27009
+" --error-prefix TEXT Change error message prefix text to TEXT\n"
27010
+ },
2697527011
};
2697627012
2697727013
/*
2697827014
** Return a pointer to usage text for zCmd, or NULL if none exists.
2697927015
*/
@@ -27193,10 +27229,56 @@
2719327229
if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0;
2719427230
}
2719527231
return 1;
2719627232
}
2719727233
#endif
27234
+
27235
+/*
27236
+** Return the size of the named file in bytes. Or return a negative
27237
+** number if the file does not exist.
27238
+*/
27239
+static sqlite3_int64 fileSize(const char *zFile){
27240
+#if defined(_WIN32) || defined(WIN32)
27241
+ struct _stat64 x;
27242
+ if( _stat64(zFile, &x)!=0 ) return -1;
27243
+ return (sqlite3_int64)x.st_size;
27244
+#else
27245
+ struct stat x;
27246
+ if( stat(zFile, &x)!=0 ) return -1;
27247
+ return (sqlite3_int64)x.st_size;
27248
+#endif
27249
+}
27250
+
27251
+/*
27252
+** Return true if zFile is an SQLite database.
27253
+**
27254
+** Algorithm:
27255
+** * If the file does not exist -> return false
27256
+** * If the size of the file is not a multiple of 512 -> return false
27257
+** * If sqlite3_open() fails -> return false
27258
+** * if sqlite3_prepare() or sqlite3_step() fails -> return false
27259
+** * Otherwise -> return true
27260
+*/
27261
+static int isDatabaseFile(const char *zFile, int openFlags){
27262
+ sqlite3 *db = 0;
27263
+ sqlite3_stmt *pStmt = 0;
27264
+ int rc;
27265
+ sqlite3_int64 sz = fileSize(zFile);
27266
+ if( sz<512 || (sz%512)!=0 ) return 0;
27267
+ if( sqlite3_open_v2(zFile, &db, openFlags, 0)==SQLITE_OK
27268
+ && sqlite3_prepare_v2(db,"SELECT count(*) FROM sqlite_schema",-1,&pStmt,0)
27269
+ ==SQLITE_OK
27270
+ && sqlite3_step(pStmt)==SQLITE_ROW
27271
+ ){
27272
+ rc = 1;
27273
+ }else{
27274
+ rc = 0;
27275
+ }
27276
+ sqlite3_finalize(pStmt);
27277
+ sqlite3_close(db);
27278
+ return rc;
27279
+}
2719827280
2719927281
/*
2720027282
** Try to deduce the type of file for zName based on its content. Return
2720127283
** one of the SHELL_OPEN_* constants.
2720227284
**
@@ -27206,24 +27288,16 @@
2720627288
** the type cannot be determined from content.
2720727289
*/
2720827290
int deduceDatabaseType(const char *zName, int dfltZip, int openFlags){
2720927291
FILE *f;
2721027292
size_t n;
27211
- sqlite3 *db = 0;
27212
- sqlite3_stmt *pStmt = 0;
2721327293
int rc = SHELL_OPEN_UNSPEC;
2721427294
char zBuf[100];
2721527295
if( access(zName,0)!=0 ) goto database_type_by_name;
27216
- if( sqlite3_open_v2(zName, &db, openFlags, 0)==SQLITE_OK
27217
- && sqlite3_prepare_v2(db,"SELECT count(*) FROM sqlite_schema",-1,&pStmt,0)
27218
- ==SQLITE_OK
27219
- && sqlite3_step(pStmt)==SQLITE_ROW
27220
- ){
27296
+ if( isDatabaseFile(zName, openFlags) ){
2722127297
rc = SHELL_OPEN_NORMAL;
2722227298
}
27223
- sqlite3_finalize(pStmt);
27224
- sqlite3_close(db);
2722527299
if( rc==SHELL_OPEN_NORMAL ) return SHELL_OPEN_NORMAL;
2722627300
f = sqlite3_fopen(zName, "rb");
2722727301
if( f==0 ) goto database_type_by_name;
2722827302
n = fread(zBuf, 16, 1, f);
2722927303
if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
@@ -27253,10 +27327,37 @@
2725327327
}else{
2725427328
rc = SHELL_OPEN_NORMAL;
2725527329
}
2725627330
return rc;
2725727331
}
27332
+
27333
+/*
27334
+** If the text in z[] is the name of a readable file and that file appears
27335
+** to contain SQL text and/or dot-commands, then return true. If z[] is
27336
+** not a file, or if the file is unreadable, or if the file is a database
27337
+** or anything else that is not SQL text and dot-commands, then return false.
27338
+**
27339
+** If the bLeaveUninit flag is set, then be sure to leave SQLite in an
27340
+** uninitialized state. This means invoking sqlite3_shutdown() after any
27341
+** SQLite API is used.
27342
+**
27343
+** Some amount of guesswork is involved in this decision.
27344
+*/
27345
+static int isScriptFile(const char *z, int bLeaveUninit){
27346
+ sqlite3_int64 sz = fileSize(z);
27347
+ if( sz<=0 ) return 0;
27348
+ if( (sz%512)==0 ){
27349
+ int rc = isDatabaseFile(z, SQLITE_OPEN_READONLY);
27350
+ if( bLeaveUninit ){
27351
+ sqlite3_shutdown();
27352
+ }
27353
+ if( rc ) return 0; /* Is a database */
27354
+ }
27355
+ if( sqlite3_strlike("%.sql",z,0)==0 ) return 1;
27356
+ if( sqlite3_strlike("%.txt",z,0)==0 ) return 1;
27357
+ return 0;
27358
+}
2725827359
2725927360
#ifndef SQLITE_OMIT_DESERIALIZE
2726027361
/*
2726127362
** Reconstruct an in-memory database using the output from the "dbtotxt"
2726227363
** program. Read content from the file in p->aAuxDb[].zDbFilename.
@@ -31328,23 +31429,17 @@
3132831429
** --bom Prepend a byte-order mark to the output
3132931430
** -e Accumulate output in a temporary text file then
3133031431
** launch a text editor when the redirection ends.
3133131432
** --error-prefix X Use X as the left-margin prefix for error messages.
3133231433
** Set to an empty string to restore the default.
31333
-** --glob GLOB Raise an error if the memory buffer does not match
31334
-** the GLOB pattern.
31335
-** --keep Continue using the same "memory" buffer. Do not
31336
-** reset it or delete it. Useful in combination with
31337
-** --glob, --not-glob, and/or --verify.
31338
-** ---notglob GLOB Raise an error if the memory buffer does not match
31339
-** the GLOB pattern.
31434
+** --keep Keep redirecting output to its current destination.
31435
+** Use this option in combination with --show or
31436
+** with --error-prefix when you do not want to stop
31437
+** a current redirection.
3134031438
** --plain Use plain text rather than HTML tables with -w
31341
-** --show Write the memory buffer to the screen, for debugging.
31342
-** --verify ENDMARK Read subsequent lines of text until the first line
31343
-** that matches ENDMARK. Discard the ENDMARK. Compare
31344
-** the text against the accumulated output in memory and
31345
-** raise an error if there are any differences.
31439
+** --show Show output text captured by .testcase or by
31440
+** redirecting to "memory".
3134631441
** -w Show the output in a web browser. Output is
3134731442
** written into a temporary HTML file until the
3134831443
** redirect ends, then the web browser is launched.
3134931444
** Query results are shown as HTML tables, unless
3135031445
** the --plain is used too.
@@ -31382,13 +31477,11 @@
3138231477
char *zFile = 0; /* The FILE argument */
3138331478
int i; /* Loop counter */
3138431479
int eMode = 0; /* 0: .outout/.once, 'x'=.excel, 'w'=.www */
3138531480
int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
3138631481
int bPlain = 0; /* --plain option */
31387
- int bKeep = 0; /* --keep option */
31388
- char *zCheck = 0; /* Argument to --glob, --notglob, --verify */
31389
- int eCheck = 0; /* 1: --glob, 2: --notglob, 3: --verify */
31482
+ int bKeep = 0; /* Keep redirecting */
3139031483
static const char *zBomUtf8 = "\357\273\277";
3139131484
const char *zBom = 0;
3139231485
char c = azArg[0][0];
3139331486
int n = strlen30(azArg[0]);
3139431487
@@ -31410,36 +31503,21 @@
3141031503
zBom = zBomUtf8;
3141131504
}else if( cli_strcmp(z,"-plain")==0 ){
3141231505
bPlain = 1;
3141331506
}else if( c=='o' && z[0]=='1' && z[1]!=0 && z[2]==0
3141431507
&& (z[1]=='x' || z[1]=='e' || z[1]=='w') ){
31415
- if( bKeep || eMode || eCheck ){
31508
+ if( bKeep || eMode ){
3141631509
dotCmdError(p, i, "incompatible with prior options",0);
3141731510
goto dotCmdOutput_error;
3141831511
}
3141931512
eMode = z[1];
31420
- }else if( cli_strcmp(z,"-keep")==0 ){
31421
- bKeep = 1;
3142231513
}else if( cli_strcmp(z,"-show")==0 ){
3142331514
if( cli_output_capture ){
3142431515
sqlite3_fprintf(stdout, "%s", sqlite3_str_value(cli_output_capture));
3142531516
}
31517
+ }else if( cli_strcmp(z,"-keep")==0 ){
3142631518
bKeep = 1;
31427
- }else if( cli_strcmp(z,"-glob")==0
31428
- || cli_strcmp(z,"-notglob")==0
31429
- || cli_strcmp(z,"-verify")==0
31430
- ){
31431
- if( eCheck || eMode ){
31432
- dotCmdError(p, i, "incompatible with prior options",0);
31433
- goto dotCmdOutput_error;
31434
- }
31435
- if( i+1>=nArg ){
31436
- dotCmdError(p, i, "missing argument", 0);
31437
- goto dotCmdOutput_error;
31438
- }
31439
- zCheck = azArg[++i];
31440
- eCheck = z[1]=='g' ? 1 : z[1]=='n' ? 2 : 3;
3144131519
}else if( optionMatch(z,"error-prefix") ){
3144231520
if( i+1>=nArg ){
3144331521
dotCmdError(p, i, "missing argument", 0);
3144431522
return 1;
3144531523
}
@@ -31450,11 +31528,11 @@
3145031528
dotCmdError(p, i, "unknown option", 0);
3145131529
sqlite3_free(zFile);
3145231530
return 1;
3145331531
}
3145431532
}else if( zFile==0 && eMode==0 ){
31455
- if( bKeep || eCheck ){
31533
+ if( bKeep ){
3145631534
dotCmdError(p, i, "incompatible with prior options",0);
3145731535
goto dotCmdOutput_error;
3145831536
}
3145931537
if( cli_strcmp(z, "memory")==0 && bOnce ){
3146031538
dotCmdError(p, 0, "cannot redirect to \"memory\"", 0);
@@ -31486,53 +31564,10 @@
3148631564
if( bOnce ){
3148731565
p->nPopOutput = 2;
3148831566
}else{
3148931567
p->nPopOutput = 0;
3149031568
}
31491
- if( eCheck ){
31492
- char *zTest;
31493
- if( cli_output_capture ){
31494
- zTest = sqlite3_str_value(cli_output_capture);
31495
- }else{
31496
- zTest = "";
31497
- }
31498
- p->nTestRun++;
31499
- if( eCheck==3 ){
31500
- int nCheck = strlen30(zCheck);
31501
- sqlite3_str *pPattern = sqlite3_str_new(p->db);
31502
- char *zPattern;
31503
- sqlite3_int64 iStart = p->lineno;
31504
- char zLine[2000];
31505
- while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
31506
- if( strchr(zLine,'\n') ) p->lineno++;
31507
- if( cli_strncmp(zCheck,zLine,nCheck)==0 ) break;
31508
- sqlite3_str_appendall(pPattern, zLine);
31509
- }
31510
- zPattern = sqlite3_str_finish(pPattern);
31511
- if( cli_strcmp(zPattern,zTest)!=0 ){
31512
- sqlite3_fprintf(stderr,
31513
- "%s:%lld: --verify does matches prior output\n",
31514
- p->zInFile, iStart);
31515
- p->nTestErr++;
31516
- }
31517
- sqlite3_free(zPattern);
31518
- }else{
31519
- char *zGlob = sqlite3_mprintf("*%s*", zCheck);
31520
- if( eCheck==1 && sqlite3_strglob(zGlob, zTest)!=0 ){
31521
- sqlite3_fprintf(stderr,
31522
- "%s:%lld: --glob \"%s\" does not match prior output\n",
31523
- p->zInFile, p->lineno, zCheck);
31524
- p->nTestErr++;
31525
- }else if( eCheck==2 && sqlite3_strglob(zGlob, zTest)==0 ){
31526
- sqlite3_fprintf(stderr,
31527
- "%s:%lld: --notglob \"%s\" matches prior output\n",
31528
- p->zInFile, p->lineno, zCheck);
31529
- p->nTestErr++;
31530
- }
31531
- sqlite3_free(zGlob);
31532
- }
31533
- }
3153431569
if( !bKeep ) output_reset(p);
3153531570
#ifndef SQLITE_NOHAVE_SYSTEM
3153631571
if( eMode=='e' || eMode=='x' || eMode=='w' ){
3153731572
p->doXdgOpen = 1;
3153831573
modePush(p);
@@ -31609,10 +31644,200 @@
3160931644
3161031645
dotCmdOutput_error:
3161131646
sqlite3_free(zFile);
3161231647
return 1;
3161331648
}
31649
+
31650
+/*
31651
+** DOT-COMMAND: .check
31652
+** USAGE: .check [OPTIONS] PATTERN
31653
+**
31654
+** Verify results of commands since the most recent .testcase command.
31655
+** Restore output to the console, unless --keep is used.
31656
+**
31657
+** If PATTERN starts with "<<ENDMARK" then the actual pattern is taken from
31658
+** subsequent lines of text up to the first line that begins with ENDMARK.
31659
+** All pattern lines and the ENDMARK are discarded.
31660
+**
31661
+** Options:
31662
+** --error-prefix TEXT Change error message prefix text to TEXT
31663
+** --exact Do an exact comparison including leading and
31664
+** trailing whitespace.
31665
+** --glob Treat PATTERN as a GLOB
31666
+** --keep Do not reset the testcase. More .check commands
31667
+** will follow.
31668
+** --notglob Output should not match PATTERN
31669
+** --show Write testcase output to the screen, for debugging.
31670
+*/
31671
+static int dotCmdCheck(ShellState *p){
31672
+ int nArg = p->dot.nArg; /* Number of arguments */
31673
+ char **azArg = p->dot.azArg; /* Text of the arguments */
31674
+ int i; /* Loop counter */
31675
+ int k; /* Result of pickStr() */
31676
+ char *zTest; /* Textcase result */
31677
+ int bKeep = 0; /* --keep option */
31678
+ char *zCheck = 0; /* PATTERN argument */
31679
+ char *zPattern = 0; /* Actual test pattern */
31680
+ int eCheck = 0; /* 1: --glob, 2: --notglob, 3: --exact */
31681
+ int isOk; /* True if results are OK */
31682
+ sqlite3_int64 iStart = p->lineno; /* Line number of .check statement */
31683
+
31684
+ if( p->zTestcase[0]==0 ){
31685
+ dotCmdError(p, 0, "no .testcase is active", 0);
31686
+ return 1;
31687
+ }
31688
+ for(i=1; i<nArg; i++){
31689
+ char *z = azArg[i];
31690
+ if( z[0]=='-' && z[1]=='-' && z[2]!=0 ) z++;
31691
+ if( cli_strcmp(z,"-keep")==0 ){
31692
+ bKeep = 1;
31693
+ }else if( cli_strcmp(z,"-show")==0 ){
31694
+ if( cli_output_capture ){
31695
+ sqlite3_fprintf(stdout, "%s", sqlite3_str_value(cli_output_capture));
31696
+ }
31697
+ bKeep = 1;
31698
+ }else if( z[0]=='-'
31699
+ && (k = pickStr(&z[1],0,"glob","notglob","exact",""))>=0
31700
+ ){
31701
+ if( eCheck && eCheck!=k+1 ){
31702
+ dotCmdError(p, i, "incompatible with prior options",0);
31703
+ return 1;
31704
+ }
31705
+ eCheck = k+1;
31706
+ }else if( zCheck ){
31707
+ dotCmdError(p, i, "unknown option", 0);
31708
+ return 1;
31709
+ }else{
31710
+ zCheck = azArg[i];
31711
+ }
31712
+ }
31713
+ if( zCheck==0 ){
31714
+ dotCmdError(p, 0, "no PATTERN specified", 0);
31715
+ return 1;
31716
+ }
31717
+ if( cli_output_capture ){
31718
+ zTest = sqlite3_str_value(cli_output_capture);
31719
+ shell_check_oom(zTest);
31720
+ }else{
31721
+ zTest = "";
31722
+ }
31723
+ p->nTestRun++;
31724
+ if( zCheck[0]=='<' && zCheck[1]=='<' && zCheck[2]!=0 ){
31725
+ int nCheck = strlen30(zCheck);
31726
+ sqlite3_str *pPattern = sqlite3_str_new(p->db);
31727
+ char zLine[2000];
31728
+ while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
31729
+ if( strchr(zLine,'\n') ) p->lineno++;
31730
+ if( cli_strncmp(&zCheck[2],zLine,nCheck-2)==0 ) break;
31731
+ sqlite3_str_appendall(pPattern, zLine);
31732
+ }
31733
+ zPattern = sqlite3_str_finish(pPattern);
31734
+ if( zPattern==0 ){
31735
+ zPattern = sqlite3_mprintf("");
31736
+ }
31737
+ }else{
31738
+ zPattern = zCheck;
31739
+ }
31740
+ shell_check_oom(zPattern);
31741
+ switch( eCheck ){
31742
+ case 1: {
31743
+ char *zGlob = sqlite3_mprintf("*%s*", zPattern);
31744
+ isOk = testcase_glob(zGlob, zTest)!=0;
31745
+ sqlite3_free(zGlob);
31746
+ break;
31747
+ }
31748
+ case 2: {
31749
+ char *zGlob = sqlite3_mprintf("*%s*", zPattern);
31750
+ isOk = testcase_glob(zGlob, zTest)==0;
31751
+ sqlite3_free(zGlob);
31752
+ break;
31753
+ }
31754
+ case 3: {
31755
+ isOk = cli_strcmp(zTest,zPattern)==0;
31756
+ break;
31757
+ }
31758
+ default: {
31759
+ /* Skip leading and trailing \n and \r on both pattern and test output */
31760
+ const char *z1 = zPattern;
31761
+ const char *z2 = zTest;
31762
+ size_t n1, n2;
31763
+ while( z1[0]=='\n' || z1[0]=='\r' ) z1++;
31764
+ n1 = strlen(z1);
31765
+ while( n1>0 && (z1[n1-1]=='\n' || z1[n1-1]=='\r') ) n1--;
31766
+ while( z2[0]=='\n' || z2[0]=='\r' ) z2++;
31767
+ n2 = strlen(z2);
31768
+ while( n2>0 && (z2[n2-1]=='\n' || z2[n2-1]=='\r') ) n2--;
31769
+ isOk = n1==n2 && memcmp(z1,z2,n1)==0;
31770
+ break;
31771
+ }
31772
+ }
31773
+ if( !isOk ){
31774
+ sqlite3_fprintf(stderr,
31775
+ "%s:%lld: .check failed for testcase %s\n",
31776
+ p->zInFile, iStart, p->zTestcase);
31777
+ p->nTestErr++;
31778
+ sqlite3_fprintf(stderr, "Expected: [%s]\n", zPattern);
31779
+ sqlite3_fprintf(stderr, "Got: [%s]\n", zTest);
31780
+ }
31781
+ if( zPattern!=zCheck ){
31782
+ sqlite3_free(zPattern);
31783
+ }
31784
+ if( !bKeep ){
31785
+ output_reset(p);
31786
+ p->zTestcase[0] = 0;
31787
+ }
31788
+ return 0;
31789
+}
31790
+
31791
+/*
31792
+** DOT-COMMAND: .testcase
31793
+** USAGE: .testcase [OPTIONS] NAME
31794
+**
31795
+** Start a new test case identified by NAME. All output
31796
+** through the next ".check" command is captured for comparison. See the
31797
+** ".check" commandn for additional informatioon.
31798
+**
31799
+** Options:
31800
+** --error-prefix TEXT Change error message prefix text to TEXT
31801
+*/
31802
+static int dotCmdTestcase(ShellState *p){
31803
+ int nArg = p->dot.nArg; /* Number of arguments */
31804
+ char **azArg = p->dot.azArg; /* Text of the arguments */
31805
+ int i; /* Loop counter */
31806
+ const char *zName = 0; /* Testcase name */
31807
+
31808
+ for(i=1; i<nArg; i++){
31809
+ char *z = azArg[i];
31810
+ if( z[0]=='-' && z[1]=='-' && z[2]!=0 ) z++;
31811
+ if( optionMatch(z,"error-prefix") ){
31812
+ if( i+1>=nArg ){
31813
+ dotCmdError(p, i, "missing argument", 0);
31814
+ return 1;
31815
+ }
31816
+ free(p->zErrPrefix);
31817
+ i++;
31818
+ p->zErrPrefix = azArg[i][0]==0 ? 0 : strdup(azArg[i]);
31819
+ }else if( zName ){
31820
+ dotCmdError(p, i, "unknown option", 0);
31821
+ return 1;
31822
+ }else{
31823
+ zName = azArg[i];
31824
+ }
31825
+ }
31826
+ output_reset(p);
31827
+ if( cli_output_capture ){
31828
+ sqlite3_str_free(cli_output_capture);
31829
+ }
31830
+ cli_output_capture = sqlite3_str_new(0);
31831
+ if( zName ){
31832
+ sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", zName);
31833
+ }else{
31834
+ sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s:%lld",
31835
+ p->zInFile, p->lineno);
31836
+ }
31837
+ return 0;
31838
+}
3161431839
3161531840
/*
3161631841
** Enlarge the space allocated in p->dot so that it can hold more
3161731842
** than nArg parsed command-line arguments.
3161831843
*/
@@ -31641,11 +31866,11 @@
3164131866
free(p->dot.zCopy);
3164231867
z = p->dot.zCopy = strdup(zLine);
3164331868
shell_check_oom(z);
3164431869
szLine = strlen(z);
3164531870
while( szLine>0 && IsSpace(z[szLine-1]) ) szLine--;
31646
- if( szLine>0 && z[szLine-1]==';' && p->iCompat>=20251115 ){
31871
+ if( szLine>0 && z[szLine-1]==';' ){
3164731872
szLine--;
3164831873
while( szLine>0 && IsSpace(z[szLine-1]) ) szLine--;
3164931874
}
3165031875
z[szLine] = 0;
3165131876
parseDotRealloc(p, 2);
@@ -31861,35 +32086,17 @@
3186132086
eputz("Usage: .changes on|off\n");
3186232087
rc = 1;
3186332088
}
3186432089
}else
3186532090
31866
-#ifndef SQLITE_SHELL_FIDDLE
3186732091
/* Cancel output redirection, if it is currently set (by .testcase)
3186832092
** Then read the content of the testcase-out.txt file and compare against
3186932093
** azArg[1]. If there are differences, report an error and exit.
3187032094
*/
3187132095
if( c=='c' && n>=3 && cli_strncmp(azArg[0], "check", n)==0 ){
31872
- char *zRes = 0;
31873
- output_reset(p);
31874
- if( nArg!=2 ){
31875
- eputz("Usage: .check GLOB-PATTERN\n");
31876
- rc = 2;
31877
- }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){
31878
- rc = 2;
31879
- }else if( testcase_glob(azArg[1],zRes)==0 ){
31880
- cli_printf(stderr,
31881
- "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
31882
- p->zTestcase, azArg[1], zRes);
31883
- rc = 1;
31884
- }else{
31885
- cli_printf(p->out, "testcase-%s ok\n", p->zTestcase);
31886
- p->nCheck++;
31887
- }
31888
- sqlite3_free(zRes);
32096
+ rc = dotCmdCheck(p);
3188932097
}else
31890
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
3189132098
3189232099
#ifndef SQLITE_SHELL_FIDDLE
3189332100
if( c=='c' && cli_strncmp(azArg[0], "clone", n)==0 ){
3189432101
failIfSafeMode(p, "cannot run .clone in safe mode");
3189532102
if( nArg==2 ){
@@ -32521,14 +32728,14 @@
3252132728
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
3252232729
goto meta_command_exit;
3252332730
}
3252432731
zSql = sqlite3_mprintf(
3252532732
"SELECT rootpage, 0 FROM sqlite_schema"
32526
- " WHERE name='%q' AND type='index'"
32733
+ " WHERE type='index' AND lower(name)=lower('%q')"
3252732734
"UNION ALL "
3252832735
"SELECT rootpage, 1 FROM sqlite_schema"
32529
- " WHERE name='%q' AND type='table'"
32736
+ " WHERE type='table' AND lower(name)=lower('%q')"
3253032737
" AND sql LIKE '%%without%%rowid%%'",
3253132738
azArg[1], azArg[1]
3253232739
);
3253332740
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3253432741
sqlite3_free(zSql);
@@ -32682,13 +32889,14 @@
3268232889
goto meta_command_exit;
3268332890
}
3268432891
if( nArg==3 ){
3268532892
sqlite3_limit(p->db, aLimit[iLimit].limitCode,
3268632893
(int)integerValue(azArg[2]));
32894
+ }else{
32895
+ cli_printf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName,
32896
+ sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
3268732897
}
32688
- cli_printf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName,
32689
- sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
3269032898
}
3269132899
}else
3269232900
3269332901
if( c=='l' && n>2 && cli_strncmp(azArg[0], "lint", n)==0 ){
3269432902
open_db(p, 0);
@@ -34017,25 +34225,15 @@
3401734225
sqlite3_str_free(pSql);
3401834226
modePop(p);
3401934227
if( rc ) return shellDatabaseError(p->db);
3402034228
}else
3402134229
34022
-#ifndef SQLITE_SHELL_FIDDLE
34023
- /* Begin redirecting output to the file "testcase-out.txt" */
34230
+ /* Set the p->zTestcase name and begin redirecting output into
34231
+ ** the cli_output_capture sqlite3_str */
3402434232
if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
34025
- output_reset(p);
34026
- p->out = output_file_open(p, "testcase-out.txt");
34027
- if( p->out==0 ){
34028
- eputz("Error: cannot open 'testcase-out.txt'\n");
34029
- }
34030
- if( nArg>=2 ){
34031
- sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
34032
- }else{
34033
- sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
34034
- }
34233
+ rc = dotCmdTestcase(p);
3403534234
}else
34036
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
3403734235
3403834236
#ifndef SQLITE_UNTESTABLE
3403934237
if( c=='t' && n>=8 && cli_strncmp(azArg[0], "testctrl", n)==0 ){
3404034238
static const struct {
3404134239
const char *zCtrlName; /* Name of a test-control option */
@@ -35351,11 +35549,10 @@
3535135549
" -bail stop after hitting an error\n"
3535235550
" -batch force batch I/O\n"
3535335551
" -box set output mode to 'box'\n"
3535435552
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
3535535553
" -column set output mode to 'column'\n"
35356
- " -compat YYYYMMDD set default options for date YYYYMMDD\n"
3535735554
" -csv set output mode to 'csv'\n"
3535835555
#if !defined(SQLITE_OMIT_DESERIALIZE)
3535935556
" -deserialize open the database using sqlite3_deserialize()\n"
3536035557
#endif
3536135558
" -echo print inputs before execution\n"
@@ -35435,15 +35632,10 @@
3543535632
/*
3543635633
** Initialize the state information in data
3543735634
*/
3543835635
static void main_init(ShellState *p) {
3543935636
memset(p, 0, sizeof(*p));
35440
-#if defined(COMPATIBILITY_DATE)
35441
- p->iCompat = COMPATIBILITY_DATE;
35442
-#else
35443
- p->iCompat = 20251116;
35444
-#endif
3544535637
p->pAuxDb = &p->aAuxDb[0];
3544635638
p->shellFlgs = SHFLG_Lookaside;
3544735639
sqlite3_config(SQLITE_CONFIG_LOG, shellLog, p);
3544835640
#if !defined(SQLITE_SHELL_FIDDLE)
3544935641
verify_uninitialized();
@@ -35637,11 +35829,11 @@
3563735829
SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
3563835830
warnInmemoryDb = 0;
3563935831
}
3564035832
#endif
3564135833
35642
- /* Do an initial pass through the command-line argument to locate
35834
+ /* Do an initial pass through the command-line arguments to locate
3564335835
** the name of the database file, the name of the initialization file,
3564435836
** the size of the alternative malloc heap, options affecting commands
3564535837
** or SQL run from the command line, and the first command to execute.
3564635838
*/
3564735839
#ifndef SQLITE_SHELL_FIDDLE
@@ -35649,11 +35841,11 @@
3564935841
#endif
3565035842
for(i=1; i<argc; i++){
3565135843
char *z;
3565235844
z = argv[i];
3565335845
if( z[0]!='-' || i>nOptsEnd ){
35654
- if( data.aAuxDb->zDbFilename==0 ){
35846
+ if( data.aAuxDb->zDbFilename==0 && !isScriptFile(z,1) ){
3565535847
data.aAuxDb->zDbFilename = z;
3565635848
}else{
3565735849
/* Excess arguments are interpreted as SQL (or dot-commands) and
3565835850
** mean that nothing is read from stdin */
3565935851
readStdin = 0;
@@ -35694,15 +35886,10 @@
3569435886
if( n<2 ){
3569535887
sqlite3_fprintf(stderr,"minimum --screenwidth is 2\n");
3569635888
exit(1);
3569735889
}
3569835890
stdout_tty_width = n;
35699
- }else if( cli_strcmp(z,"-compat")==0 ){
35700
- data.iCompat = atoi(cmdline_option_value(argc, argv, ++i));
35701
- modeFree(&data.mode);
35702
- memset(&data.mode, 0, sizeof(data.mode));
35703
- modeDefault(&data);
3570435891
}else if( cli_strcmp(z,"-utf8")==0 ){
3570535892
}else if( cli_strcmp(z,"-no-utf8")==0 ){
3570635893
}else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
3570735894
int val = 0;
3570835895
sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW, &val);
@@ -35889,11 +36076,11 @@
3588936076
** is given on the command line, look for a file named ~/.sqliterc and
3589036077
** try to process it.
3589136078
*/
3589236079
if( !noInit ) process_sqliterc(&data,zInitFile);
3589336080
35894
- /* Make a second pass through the command-line argument and set
36081
+ /* Make a second pass through the command-line arguments and set
3589536082
** options. This second pass is delayed until after the initialization
3589636083
** file is processed so that the command-line arguments will override
3589736084
** settings in the initialization file.
3589836085
*/
3589936086
for(i=1; i<argc; i++){
@@ -36015,12 +36202,10 @@
3601536202
stdin_is_interactive = 1;
3601636203
}else if( cli_strcmp(z,"-batch")==0 ){
3601736204
/* already handled */
3601836205
}else if( cli_strcmp(z,"-screenwidth")==0 ){
3601936206
i++;
36020
- }else if( cli_strcmp(z,"-compat")==0 ){
36021
- i++;
3602236207
}else if( cli_strcmp(z,"-utf8")==0 ){
3602336208
/* already handled */
3602436209
}else if( cli_strcmp(z,"-no-utf8")==0 ){
3602536210
/* already handled */
3602636211
}else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
@@ -36116,11 +36301,22 @@
3611636301
** command-line inputs, except for the argToSkip argument which contains
3611736302
** the database filename.
3611836303
*/
3611936304
for(i=0; i<nCmd; i++){
3612036305
echo_group_input(&data, azCmd[i]);
36121
- if( azCmd[i][0]=='.' ){
36306
+ if( isScriptFile(azCmd[i],0) ){
36307
+ FILE *inSaved = data.in;
36308
+ i64 savedLineno = data.lineno;
36309
+ int res = 1;
36310
+ if( (data.in = openChrSource(azCmd[i]))!=0 ){
36311
+ res = process_input(&data, azCmd[i]);
36312
+ fclose(data.in);
36313
+ }
36314
+ data.in = inSaved;
36315
+ data.lineno = savedLineno;
36316
+ if( res ) i = nCmd;
36317
+ }else if( azCmd[i][0]=='.' ){
3612236318
char *zErrCtx = malloc( 64 );
3612336319
shell_check_oom(zErrCtx);
3612436320
sqlite3_snprintf(64,zErrCtx,"argv[%i]:",aiCmd[i]);
3612536321
data.zInFile = "<cmdline>";
3612636322
data.zErrPrefix = zErrCtx;
3612736323
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1581,13 +1581,15 @@
1581 ** (3) z[] does not looks like a numeric literal
1582 */
1583 static int qrfRelaxable(Qrf *p, const char *z){
1584 size_t i, n;
1585 if( z[0]=='\'' || qrfSpace(z[0]) ) return 0;
1586 if( z[0]==0 && (p->spec.zNull==0 || p->spec.zNull[0]==0) ) return 0;
 
 
1587 n = strlen(z);
1588 if( z[n-1]=='\'' || qrfSpace(z[n-1]) ) return 0;
1589 if( p->spec.zNull && strcmp(p->spec.zNull,z)==0 ) return 0;
1590 i = (z[0]=='-' || z[0]=='+');
1591 if( strcmp(z+i,"Inf")==0 ) return 0;
1592 if( !qrfDigit(z[i]) ) return 1;
1593 i++;
@@ -10180,15 +10182,22 @@
10180 }
10181 return pRe->zErr;
10182 }
10183
10184 /*
10185 ** Compute a reasonable limit on the length of the REGEXP NFA.
10186 */
10187 static int re_maxlen(sqlite3_context *context){
10188 sqlite3 *db = sqlite3_context_db_handle(context);
10189 return 75 + sqlite3_limit(db, SQLITE_LIMIT_LIKE_PATTERN_LENGTH,-1)/2;
 
 
 
 
 
 
 
10190 }
10191
10192 /*
10193 ** Implementation of the regexp() SQL function. This function implements
10194 ** the build-in REGEXP operator. The first argument to the function is the
@@ -10210,14 +10219,21 @@
10210 int setAux = 0; /* True to invoke sqlite3_set_auxdata() */
10211
10212 (void)argc; /* Unused */
10213 pRe = sqlite3_get_auxdata(context, 0);
10214 if( pRe==0 ){
 
 
10215 zPattern = (const char*)sqlite3_value_text(argv[0]);
10216 if( zPattern==0 ) return;
10217 zErr = re_compile(&pRe, zPattern, re_maxlen(context),
10218 sqlite3_user_data(context)!=0);
 
 
 
 
 
10219 if( zErr ){
10220 re_free(pRe);
10221 sqlite3_result_error(context, zErr, -1);
10222 return;
10223 }
@@ -10279,11 +10295,11 @@
10279 "ATSTART",
10280 };
10281
10282 zPattern = (const char*)sqlite3_value_text(argv[0]);
10283 if( zPattern==0 ) return;
10284 zErr = re_compile(&pRe, zPattern, re_maxlen(context),
10285 sqlite3_user_data(context)!=0);
10286 if( zErr ){
10287 re_free(pRe);
10288 sqlite3_result_error(context, zErr, -1);
10289 return;
@@ -24178,11 +24194,10 @@
24178 ** instance of the following structure.
24179 */
24180 typedef struct ShellState ShellState;
24181 struct ShellState {
24182 sqlite3 *db; /* The database */
24183 int iCompat; /* Compatibility date YYYYMMDD */
24184 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
24185 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
24186 u8 nEqpLevel; /* Depth of the EQP output graph */
24187 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
24188 u8 bSafeMode; /* True to prohibit unsafe operations */
@@ -24570,18 +24585,17 @@
24570 p->mode.mFlags = mFlags;
24571 }
24572 }
24573
24574 /*
24575 ** Set the mode to the default according to p->iCompat. It assumed
24576 ** that the mode has already been freed and zeroed prior to calling
24577 ** this routine.
24578 */
24579 static void modeDefault(ShellState *p){
24580 p->mode.spec.iVersion = 1;
24581 p->mode.autoExplain = 1;
24582 if( p->iCompat>=20251115 && (stdin_is_interactive || stdout_is_console) ){
24583 modeChange(p, MODE_TTY);
24584 }else{
24585 modeChange(p, MODE_BATCH);
24586 }
24587 }
@@ -26604,12 +26618,12 @@
26604 ".bail on|off Stop after hitting an error. Default OFF",
26605 #ifndef SQLITE_SHELL_FIDDLE
26606 ".cd DIRECTORY Change the working directory to DIRECTORY",
26607 #endif
26608 ".changes on|off Show number of rows changed by SQL",
 
26609 #ifndef SQLITE_SHELL_FIDDLE
26610 ".check GLOB Fail if output since .testcase does not match",
26611 ".clone NEWDB Clone data into NEWDB from the existing database",
26612 #endif
26613 ".connection [close] [#] Open or close an auxiliary database connection",
26614 ".crlf ?on|off? Whether or not to use \\r\\n line endings",
26615 ".databases List names and files of attached databases",
@@ -26785,13 +26799,11 @@
26785 " vmstep Show the virtual machine step count only",
26786 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
26787 ".system CMD ARGS... Run CMD ARGS... in a system shell",
26788 #endif
26789 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
26790 #ifndef SQLITE_SHELL_FIDDLE
26791 ",testcase NAME Begin redirecting output to 'testcase-out.txt'",
26792 #endif
26793 ",testctrl CMD ... Run various sqlite3_test_control() operations",
26794 " Run \".testctrl\" with no arguments for details",
26795 ".timeout MS Try opening locked tables for MS milliseconds",
26796 ".timer on|off Turn SQL timer on or off",
26797 #ifndef SQLITE_OMIT_TRACE
@@ -26930,23 +26942,17 @@
26930 " --bom Prepend a byte-order mark to the output\n"
26931 " -e Accumulate output in a temporary text file then\n"
26932 " launch a text editor when the redirection ends.\n"
26933 " --error-prefix X Use X as the left-margin prefix for error messages.\n"
26934 " Set to an empty string to restore the default.\n"
26935 " --glob GLOB Raise an error if the memory buffer does not match\n"
26936 " the GLOB pattern.\n"
26937 " --keep Continue using the same \"memory\" buffer. Do not\n"
26938 " reset it or delete it. Useful in combination with\n"
26939 " --glob, --not-glob, and/or --verify.\n"
26940 " ---notglob GLOB Raise an error if the memory buffer does not match\n"
26941 " the GLOB pattern.\n"
26942 " --plain Use plain text rather than HTML tables with -w\n"
26943 " --show Write the memory buffer to the screen, for debugging.\n"
26944 " --verify ENDMARK Read subsequent lines of text until the first line\n"
26945 " that matches ENDMARK. Discard the ENDMARK. Compare\n"
26946 " the text against the accumulated output in memory and\n"
26947 " raise an error if there are any differences.\n"
26948 " -w Show the output in a web browser. Output is\n"
26949 " written into a temporary HTML file until the\n"
26950 " redirect ends, then the web browser is launched.\n"
26951 " Query results are shown as HTML tables, unless\n"
26952 " the --plain is used too.\n"
@@ -26970,10 +26976,40 @@
26970 " file in a web browser\n"
26971 " -x Show the output in a spreadsheet. Output is\n"
26972 " written to a temp file as CSV then the spreadsheet\n"
26973 " is launched when\n"
26974 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26975 };
26976
26977 /*
26978 ** Return a pointer to usage text for zCmd, or NULL if none exists.
26979 */
@@ -27193,10 +27229,56 @@
27193 if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0;
27194 }
27195 return 1;
27196 }
27197 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27198
27199 /*
27200 ** Try to deduce the type of file for zName based on its content. Return
27201 ** one of the SHELL_OPEN_* constants.
27202 **
@@ -27206,24 +27288,16 @@
27206 ** the type cannot be determined from content.
27207 */
27208 int deduceDatabaseType(const char *zName, int dfltZip, int openFlags){
27209 FILE *f;
27210 size_t n;
27211 sqlite3 *db = 0;
27212 sqlite3_stmt *pStmt = 0;
27213 int rc = SHELL_OPEN_UNSPEC;
27214 char zBuf[100];
27215 if( access(zName,0)!=0 ) goto database_type_by_name;
27216 if( sqlite3_open_v2(zName, &db, openFlags, 0)==SQLITE_OK
27217 && sqlite3_prepare_v2(db,"SELECT count(*) FROM sqlite_schema",-1,&pStmt,0)
27218 ==SQLITE_OK
27219 && sqlite3_step(pStmt)==SQLITE_ROW
27220 ){
27221 rc = SHELL_OPEN_NORMAL;
27222 }
27223 sqlite3_finalize(pStmt);
27224 sqlite3_close(db);
27225 if( rc==SHELL_OPEN_NORMAL ) return SHELL_OPEN_NORMAL;
27226 f = sqlite3_fopen(zName, "rb");
27227 if( f==0 ) goto database_type_by_name;
27228 n = fread(zBuf, 16, 1, f);
27229 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
@@ -27253,10 +27327,37 @@
27253 }else{
27254 rc = SHELL_OPEN_NORMAL;
27255 }
27256 return rc;
27257 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27258
27259 #ifndef SQLITE_OMIT_DESERIALIZE
27260 /*
27261 ** Reconstruct an in-memory database using the output from the "dbtotxt"
27262 ** program. Read content from the file in p->aAuxDb[].zDbFilename.
@@ -31328,23 +31429,17 @@
31328 ** --bom Prepend a byte-order mark to the output
31329 ** -e Accumulate output in a temporary text file then
31330 ** launch a text editor when the redirection ends.
31331 ** --error-prefix X Use X as the left-margin prefix for error messages.
31332 ** Set to an empty string to restore the default.
31333 ** --glob GLOB Raise an error if the memory buffer does not match
31334 ** the GLOB pattern.
31335 ** --keep Continue using the same "memory" buffer. Do not
31336 ** reset it or delete it. Useful in combination with
31337 ** --glob, --not-glob, and/or --verify.
31338 ** ---notglob GLOB Raise an error if the memory buffer does not match
31339 ** the GLOB pattern.
31340 ** --plain Use plain text rather than HTML tables with -w
31341 ** --show Write the memory buffer to the screen, for debugging.
31342 ** --verify ENDMARK Read subsequent lines of text until the first line
31343 ** that matches ENDMARK. Discard the ENDMARK. Compare
31344 ** the text against the accumulated output in memory and
31345 ** raise an error if there are any differences.
31346 ** -w Show the output in a web browser. Output is
31347 ** written into a temporary HTML file until the
31348 ** redirect ends, then the web browser is launched.
31349 ** Query results are shown as HTML tables, unless
31350 ** the --plain is used too.
@@ -31382,13 +31477,11 @@
31382 char *zFile = 0; /* The FILE argument */
31383 int i; /* Loop counter */
31384 int eMode = 0; /* 0: .outout/.once, 'x'=.excel, 'w'=.www */
31385 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
31386 int bPlain = 0; /* --plain option */
31387 int bKeep = 0; /* --keep option */
31388 char *zCheck = 0; /* Argument to --glob, --notglob, --verify */
31389 int eCheck = 0; /* 1: --glob, 2: --notglob, 3: --verify */
31390 static const char *zBomUtf8 = "\357\273\277";
31391 const char *zBom = 0;
31392 char c = azArg[0][0];
31393 int n = strlen30(azArg[0]);
31394
@@ -31410,36 +31503,21 @@
31410 zBom = zBomUtf8;
31411 }else if( cli_strcmp(z,"-plain")==0 ){
31412 bPlain = 1;
31413 }else if( c=='o' && z[0]=='1' && z[1]!=0 && z[2]==0
31414 && (z[1]=='x' || z[1]=='e' || z[1]=='w') ){
31415 if( bKeep || eMode || eCheck ){
31416 dotCmdError(p, i, "incompatible with prior options",0);
31417 goto dotCmdOutput_error;
31418 }
31419 eMode = z[1];
31420 }else if( cli_strcmp(z,"-keep")==0 ){
31421 bKeep = 1;
31422 }else if( cli_strcmp(z,"-show")==0 ){
31423 if( cli_output_capture ){
31424 sqlite3_fprintf(stdout, "%s", sqlite3_str_value(cli_output_capture));
31425 }
 
31426 bKeep = 1;
31427 }else if( cli_strcmp(z,"-glob")==0
31428 || cli_strcmp(z,"-notglob")==0
31429 || cli_strcmp(z,"-verify")==0
31430 ){
31431 if( eCheck || eMode ){
31432 dotCmdError(p, i, "incompatible with prior options",0);
31433 goto dotCmdOutput_error;
31434 }
31435 if( i+1>=nArg ){
31436 dotCmdError(p, i, "missing argument", 0);
31437 goto dotCmdOutput_error;
31438 }
31439 zCheck = azArg[++i];
31440 eCheck = z[1]=='g' ? 1 : z[1]=='n' ? 2 : 3;
31441 }else if( optionMatch(z,"error-prefix") ){
31442 if( i+1>=nArg ){
31443 dotCmdError(p, i, "missing argument", 0);
31444 return 1;
31445 }
@@ -31450,11 +31528,11 @@
31450 dotCmdError(p, i, "unknown option", 0);
31451 sqlite3_free(zFile);
31452 return 1;
31453 }
31454 }else if( zFile==0 && eMode==0 ){
31455 if( bKeep || eCheck ){
31456 dotCmdError(p, i, "incompatible with prior options",0);
31457 goto dotCmdOutput_error;
31458 }
31459 if( cli_strcmp(z, "memory")==0 && bOnce ){
31460 dotCmdError(p, 0, "cannot redirect to \"memory\"", 0);
@@ -31486,53 +31564,10 @@
31486 if( bOnce ){
31487 p->nPopOutput = 2;
31488 }else{
31489 p->nPopOutput = 0;
31490 }
31491 if( eCheck ){
31492 char *zTest;
31493 if( cli_output_capture ){
31494 zTest = sqlite3_str_value(cli_output_capture);
31495 }else{
31496 zTest = "";
31497 }
31498 p->nTestRun++;
31499 if( eCheck==3 ){
31500 int nCheck = strlen30(zCheck);
31501 sqlite3_str *pPattern = sqlite3_str_new(p->db);
31502 char *zPattern;
31503 sqlite3_int64 iStart = p->lineno;
31504 char zLine[2000];
31505 while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
31506 if( strchr(zLine,'\n') ) p->lineno++;
31507 if( cli_strncmp(zCheck,zLine,nCheck)==0 ) break;
31508 sqlite3_str_appendall(pPattern, zLine);
31509 }
31510 zPattern = sqlite3_str_finish(pPattern);
31511 if( cli_strcmp(zPattern,zTest)!=0 ){
31512 sqlite3_fprintf(stderr,
31513 "%s:%lld: --verify does matches prior output\n",
31514 p->zInFile, iStart);
31515 p->nTestErr++;
31516 }
31517 sqlite3_free(zPattern);
31518 }else{
31519 char *zGlob = sqlite3_mprintf("*%s*", zCheck);
31520 if( eCheck==1 && sqlite3_strglob(zGlob, zTest)!=0 ){
31521 sqlite3_fprintf(stderr,
31522 "%s:%lld: --glob \"%s\" does not match prior output\n",
31523 p->zInFile, p->lineno, zCheck);
31524 p->nTestErr++;
31525 }else if( eCheck==2 && sqlite3_strglob(zGlob, zTest)==0 ){
31526 sqlite3_fprintf(stderr,
31527 "%s:%lld: --notglob \"%s\" matches prior output\n",
31528 p->zInFile, p->lineno, zCheck);
31529 p->nTestErr++;
31530 }
31531 sqlite3_free(zGlob);
31532 }
31533 }
31534 if( !bKeep ) output_reset(p);
31535 #ifndef SQLITE_NOHAVE_SYSTEM
31536 if( eMode=='e' || eMode=='x' || eMode=='w' ){
31537 p->doXdgOpen = 1;
31538 modePush(p);
@@ -31609,10 +31644,200 @@
31609
31610 dotCmdOutput_error:
31611 sqlite3_free(zFile);
31612 return 1;
31613 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31614
31615 /*
31616 ** Enlarge the space allocated in p->dot so that it can hold more
31617 ** than nArg parsed command-line arguments.
31618 */
@@ -31641,11 +31866,11 @@
31641 free(p->dot.zCopy);
31642 z = p->dot.zCopy = strdup(zLine);
31643 shell_check_oom(z);
31644 szLine = strlen(z);
31645 while( szLine>0 && IsSpace(z[szLine-1]) ) szLine--;
31646 if( szLine>0 && z[szLine-1]==';' && p->iCompat>=20251115 ){
31647 szLine--;
31648 while( szLine>0 && IsSpace(z[szLine-1]) ) szLine--;
31649 }
31650 z[szLine] = 0;
31651 parseDotRealloc(p, 2);
@@ -31861,35 +32086,17 @@
31861 eputz("Usage: .changes on|off\n");
31862 rc = 1;
31863 }
31864 }else
31865
31866 #ifndef SQLITE_SHELL_FIDDLE
31867 /* Cancel output redirection, if it is currently set (by .testcase)
31868 ** Then read the content of the testcase-out.txt file and compare against
31869 ** azArg[1]. If there are differences, report an error and exit.
31870 */
31871 if( c=='c' && n>=3 && cli_strncmp(azArg[0], "check", n)==0 ){
31872 char *zRes = 0;
31873 output_reset(p);
31874 if( nArg!=2 ){
31875 eputz("Usage: .check GLOB-PATTERN\n");
31876 rc = 2;
31877 }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){
31878 rc = 2;
31879 }else if( testcase_glob(azArg[1],zRes)==0 ){
31880 cli_printf(stderr,
31881 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
31882 p->zTestcase, azArg[1], zRes);
31883 rc = 1;
31884 }else{
31885 cli_printf(p->out, "testcase-%s ok\n", p->zTestcase);
31886 p->nCheck++;
31887 }
31888 sqlite3_free(zRes);
31889 }else
31890 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
31891
31892 #ifndef SQLITE_SHELL_FIDDLE
31893 if( c=='c' && cli_strncmp(azArg[0], "clone", n)==0 ){
31894 failIfSafeMode(p, "cannot run .clone in safe mode");
31895 if( nArg==2 ){
@@ -32521,14 +32728,14 @@
32521 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
32522 goto meta_command_exit;
32523 }
32524 zSql = sqlite3_mprintf(
32525 "SELECT rootpage, 0 FROM sqlite_schema"
32526 " WHERE name='%q' AND type='index'"
32527 "UNION ALL "
32528 "SELECT rootpage, 1 FROM sqlite_schema"
32529 " WHERE name='%q' AND type='table'"
32530 " AND sql LIKE '%%without%%rowid%%'",
32531 azArg[1], azArg[1]
32532 );
32533 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
32534 sqlite3_free(zSql);
@@ -32682,13 +32889,14 @@
32682 goto meta_command_exit;
32683 }
32684 if( nArg==3 ){
32685 sqlite3_limit(p->db, aLimit[iLimit].limitCode,
32686 (int)integerValue(azArg[2]));
 
 
 
32687 }
32688 cli_printf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName,
32689 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
32690 }
32691 }else
32692
32693 if( c=='l' && n>2 && cli_strncmp(azArg[0], "lint", n)==0 ){
32694 open_db(p, 0);
@@ -34017,25 +34225,15 @@
34017 sqlite3_str_free(pSql);
34018 modePop(p);
34019 if( rc ) return shellDatabaseError(p->db);
34020 }else
34021
34022 #ifndef SQLITE_SHELL_FIDDLE
34023 /* Begin redirecting output to the file "testcase-out.txt" */
34024 if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
34025 output_reset(p);
34026 p->out = output_file_open(p, "testcase-out.txt");
34027 if( p->out==0 ){
34028 eputz("Error: cannot open 'testcase-out.txt'\n");
34029 }
34030 if( nArg>=2 ){
34031 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
34032 }else{
34033 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
34034 }
34035 }else
34036 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
34037
34038 #ifndef SQLITE_UNTESTABLE
34039 if( c=='t' && n>=8 && cli_strncmp(azArg[0], "testctrl", n)==0 ){
34040 static const struct {
34041 const char *zCtrlName; /* Name of a test-control option */
@@ -35351,11 +35549,10 @@
35351 " -bail stop after hitting an error\n"
35352 " -batch force batch I/O\n"
35353 " -box set output mode to 'box'\n"
35354 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
35355 " -column set output mode to 'column'\n"
35356 " -compat YYYYMMDD set default options for date YYYYMMDD\n"
35357 " -csv set output mode to 'csv'\n"
35358 #if !defined(SQLITE_OMIT_DESERIALIZE)
35359 " -deserialize open the database using sqlite3_deserialize()\n"
35360 #endif
35361 " -echo print inputs before execution\n"
@@ -35435,15 +35632,10 @@
35435 /*
35436 ** Initialize the state information in data
35437 */
35438 static void main_init(ShellState *p) {
35439 memset(p, 0, sizeof(*p));
35440 #if defined(COMPATIBILITY_DATE)
35441 p->iCompat = COMPATIBILITY_DATE;
35442 #else
35443 p->iCompat = 20251116;
35444 #endif
35445 p->pAuxDb = &p->aAuxDb[0];
35446 p->shellFlgs = SHFLG_Lookaside;
35447 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, p);
35448 #if !defined(SQLITE_SHELL_FIDDLE)
35449 verify_uninitialized();
@@ -35637,11 +35829,11 @@
35637 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
35638 warnInmemoryDb = 0;
35639 }
35640 #endif
35641
35642 /* Do an initial pass through the command-line argument to locate
35643 ** the name of the database file, the name of the initialization file,
35644 ** the size of the alternative malloc heap, options affecting commands
35645 ** or SQL run from the command line, and the first command to execute.
35646 */
35647 #ifndef SQLITE_SHELL_FIDDLE
@@ -35649,11 +35841,11 @@
35649 #endif
35650 for(i=1; i<argc; i++){
35651 char *z;
35652 z = argv[i];
35653 if( z[0]!='-' || i>nOptsEnd ){
35654 if( data.aAuxDb->zDbFilename==0 ){
35655 data.aAuxDb->zDbFilename = z;
35656 }else{
35657 /* Excess arguments are interpreted as SQL (or dot-commands) and
35658 ** mean that nothing is read from stdin */
35659 readStdin = 0;
@@ -35694,15 +35886,10 @@
35694 if( n<2 ){
35695 sqlite3_fprintf(stderr,"minimum --screenwidth is 2\n");
35696 exit(1);
35697 }
35698 stdout_tty_width = n;
35699 }else if( cli_strcmp(z,"-compat")==0 ){
35700 data.iCompat = atoi(cmdline_option_value(argc, argv, ++i));
35701 modeFree(&data.mode);
35702 memset(&data.mode, 0, sizeof(data.mode));
35703 modeDefault(&data);
35704 }else if( cli_strcmp(z,"-utf8")==0 ){
35705 }else if( cli_strcmp(z,"-no-utf8")==0 ){
35706 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
35707 int val = 0;
35708 sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW, &val);
@@ -35889,11 +36076,11 @@
35889 ** is given on the command line, look for a file named ~/.sqliterc and
35890 ** try to process it.
35891 */
35892 if( !noInit ) process_sqliterc(&data,zInitFile);
35893
35894 /* Make a second pass through the command-line argument and set
35895 ** options. This second pass is delayed until after the initialization
35896 ** file is processed so that the command-line arguments will override
35897 ** settings in the initialization file.
35898 */
35899 for(i=1; i<argc; i++){
@@ -36015,12 +36202,10 @@
36015 stdin_is_interactive = 1;
36016 }else if( cli_strcmp(z,"-batch")==0 ){
36017 /* already handled */
36018 }else if( cli_strcmp(z,"-screenwidth")==0 ){
36019 i++;
36020 }else if( cli_strcmp(z,"-compat")==0 ){
36021 i++;
36022 }else if( cli_strcmp(z,"-utf8")==0 ){
36023 /* already handled */
36024 }else if( cli_strcmp(z,"-no-utf8")==0 ){
36025 /* already handled */
36026 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
@@ -36116,11 +36301,22 @@
36116 ** command-line inputs, except for the argToSkip argument which contains
36117 ** the database filename.
36118 */
36119 for(i=0; i<nCmd; i++){
36120 echo_group_input(&data, azCmd[i]);
36121 if( azCmd[i][0]=='.' ){
 
 
 
 
 
 
 
 
 
 
 
36122 char *zErrCtx = malloc( 64 );
36123 shell_check_oom(zErrCtx);
36124 sqlite3_snprintf(64,zErrCtx,"argv[%i]:",aiCmd[i]);
36125 data.zInFile = "<cmdline>";
36126 data.zErrPrefix = zErrCtx;
36127
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1581,13 +1581,15 @@
1581 ** (3) z[] does not looks like a numeric literal
1582 */
1583 static int qrfRelaxable(Qrf *p, const char *z){
1584 size_t i, n;
1585 if( z[0]=='\'' || qrfSpace(z[0]) ) return 0;
1586 if( z[0]==0 ){
1587 return (p->spec.zNull!=0 && p->spec.zNull[0]!=0);
1588 }
1589 n = strlen(z);
1590 if( n==0 || z[n-1]=='\'' || qrfSpace(z[n-1]) ) return 0;
1591 if( p->spec.zNull && strcmp(p->spec.zNull,z)==0 ) return 0;
1592 i = (z[0]=='-' || z[0]=='+');
1593 if( strcmp(z+i,"Inf")==0 ) return 0;
1594 if( !qrfDigit(z[i]) ) return 1;
1595 i++;
@@ -10180,15 +10182,22 @@
10182 }
10183 return pRe->zErr;
10184 }
10185
10186 /*
10187 ** The value of LIMIT_MAX_PATTERN_LENGTH.
10188 */
10189 static int re_maxlen(sqlite3_context *context){
10190 sqlite3 *db = sqlite3_context_db_handle(context);
10191 return sqlite3_limit(db, SQLITE_LIMIT_LIKE_PATTERN_LENGTH,-1);
10192 }
10193
10194 /*
10195 ** Maximum NFA size given a maximum pattern length.
10196 */
10197 static int re_maxnfa(int mxlen){
10198 return 75+mxlen/2;
10199 }
10200
10201 /*
10202 ** Implementation of the regexp() SQL function. This function implements
10203 ** the build-in REGEXP operator. The first argument to the function is the
@@ -10210,14 +10219,21 @@
10219 int setAux = 0; /* True to invoke sqlite3_set_auxdata() */
10220
10221 (void)argc; /* Unused */
10222 pRe = sqlite3_get_auxdata(context, 0);
10223 if( pRe==0 ){
10224 int mxLen = re_maxlen(context);
10225 int nPattern;
10226 zPattern = (const char*)sqlite3_value_text(argv[0]);
10227 if( zPattern==0 ) return;
10228 nPattern = sqlite3_value_bytes(argv[0]);
10229 if( nPattern>mxLen ){
10230 zErr = "REGEXP pattern too big";
10231 }else{
10232 zErr = re_compile(&pRe, zPattern, re_maxnfa(mxLen),
10233 sqlite3_user_data(context)!=0);
10234 }
10235 if( zErr ){
10236 re_free(pRe);
10237 sqlite3_result_error(context, zErr, -1);
10238 return;
10239 }
@@ -10279,11 +10295,11 @@
10295 "ATSTART",
10296 };
10297
10298 zPattern = (const char*)sqlite3_value_text(argv[0]);
10299 if( zPattern==0 ) return;
10300 zErr = re_compile(&pRe, zPattern, re_maxnfa(re_maxlen(context)),
10301 sqlite3_user_data(context)!=0);
10302 if( zErr ){
10303 re_free(pRe);
10304 sqlite3_result_error(context, zErr, -1);
10305 return;
@@ -24178,11 +24194,10 @@
24194 ** instance of the following structure.
24195 */
24196 typedef struct ShellState ShellState;
24197 struct ShellState {
24198 sqlite3 *db; /* The database */
 
24199 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
24200 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
24201 u8 nEqpLevel; /* Depth of the EQP output graph */
24202 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
24203 u8 bSafeMode; /* True to prohibit unsafe operations */
@@ -24570,18 +24585,17 @@
24585 p->mode.mFlags = mFlags;
24586 }
24587 }
24588
24589 /*
24590 ** Set the mode to the default. It assumed that the mode has
24591 ** already been freed and zeroed prior to calling this routine.
 
24592 */
24593 static void modeDefault(ShellState *p){
24594 p->mode.spec.iVersion = 1;
24595 p->mode.autoExplain = 1;
24596 if( stdin_is_interactive || stdout_is_console ){
24597 modeChange(p, MODE_TTY);
24598 }else{
24599 modeChange(p, MODE_BATCH);
24600 }
24601 }
@@ -26604,12 +26618,12 @@
26618 ".bail on|off Stop after hitting an error. Default OFF",
26619 #ifndef SQLITE_SHELL_FIDDLE
26620 ".cd DIRECTORY Change the working directory to DIRECTORY",
26621 #endif
26622 ".changes on|off Show number of rows changed by SQL",
26623 ".check OPTIONS ... Verify the results of a .testcase",
26624 #ifndef SQLITE_SHELL_FIDDLE
 
26625 ".clone NEWDB Clone data into NEWDB from the existing database",
26626 #endif
26627 ".connection [close] [#] Open or close an auxiliary database connection",
26628 ".crlf ?on|off? Whether or not to use \\r\\n line endings",
26629 ".databases List names and files of attached databases",
@@ -26785,13 +26799,11 @@
26799 " vmstep Show the virtual machine step count only",
26800 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
26801 ".system CMD ARGS... Run CMD ARGS... in a system shell",
26802 #endif
26803 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
26804 ".testcase NAME Begin a test case.",
 
 
26805 ",testctrl CMD ... Run various sqlite3_test_control() operations",
26806 " Run \".testctrl\" with no arguments for details",
26807 ".timeout MS Try opening locked tables for MS milliseconds",
26808 ".timer on|off Turn SQL timer on or off",
26809 #ifndef SQLITE_OMIT_TRACE
@@ -26930,23 +26942,17 @@
26942 " --bom Prepend a byte-order mark to the output\n"
26943 " -e Accumulate output in a temporary text file then\n"
26944 " launch a text editor when the redirection ends.\n"
26945 " --error-prefix X Use X as the left-margin prefix for error messages.\n"
26946 " Set to an empty string to restore the default.\n"
26947 " --keep Keep redirecting output to its current destination.\n"
26948 " Use this option in combination with --show or\n"
26949 " with --error-prefix when you do not want to stop\n"
26950 " a current redirection.\n"
 
 
 
26951 " --plain Use plain text rather than HTML tables with -w\n"
26952 " --show Show output text captured by .testcase or by\n"
26953 " redirecting to \"memory\".\n"
 
 
 
26954 " -w Show the output in a web browser. Output is\n"
26955 " written into a temporary HTML file until the\n"
26956 " redirect ends, then the web browser is launched.\n"
26957 " Query results are shown as HTML tables, unless\n"
26958 " the --plain is used too.\n"
@@ -26970,10 +26976,40 @@
26976 " file in a web browser\n"
26977 " -x Show the output in a spreadsheet. Output is\n"
26978 " written to a temp file as CSV then the spreadsheet\n"
26979 " is launched when\n"
26980 },
26981 { ".check",
26982 "USAGE: .check [OPTIONS] PATTERN\n"
26983 "\n"
26984 "Verify results of commands since the most recent .testcase command.\n"
26985 "Restore output to the console, unless --keep is used.\n"
26986 "\n"
26987 "If PATTERN starts with \"<<ENDMARK\" then the actual pattern is taken from\n"
26988 "subsequent lines of text up to the first line that begins with ENDMARK.\n"
26989 "All pattern lines and the ENDMARK are discarded.\n"
26990 "\n"
26991 "Options:\n"
26992 " --error-prefix TEXT Change error message prefix text to TEXT\n"
26993 " --exact Do an exact comparison including leading and\n"
26994 " trailing whitespace.\n"
26995 " --glob Treat PATTERN as a GLOB\n"
26996 " --keep Do not reset the testcase. More .check commands\n"
26997 " will follow.\n"
26998 " --notglob Output should not match PATTERN\n"
26999 " --show Write testcase output to the screen, for debugging.\n"
27000 },
27001 { ".testcase",
27002 "USAGE: .testcase [OPTIONS] NAME\n"
27003 "\n"
27004 "Start a new test case identified by NAME. All output\n"
27005 "through the next \".check\" command is captured for comparison. See the\n"
27006 "\".check\" commandn for additional informatioon.\n"
27007 "\n"
27008 "Options:\n"
27009 " --error-prefix TEXT Change error message prefix text to TEXT\n"
27010 },
27011 };
27012
27013 /*
27014 ** Return a pointer to usage text for zCmd, or NULL if none exists.
27015 */
@@ -27193,10 +27229,56 @@
27229 if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0;
27230 }
27231 return 1;
27232 }
27233 #endif
27234
27235 /*
27236 ** Return the size of the named file in bytes. Or return a negative
27237 ** number if the file does not exist.
27238 */
27239 static sqlite3_int64 fileSize(const char *zFile){
27240 #if defined(_WIN32) || defined(WIN32)
27241 struct _stat64 x;
27242 if( _stat64(zFile, &x)!=0 ) return -1;
27243 return (sqlite3_int64)x.st_size;
27244 #else
27245 struct stat x;
27246 if( stat(zFile, &x)!=0 ) return -1;
27247 return (sqlite3_int64)x.st_size;
27248 #endif
27249 }
27250
27251 /*
27252 ** Return true if zFile is an SQLite database.
27253 **
27254 ** Algorithm:
27255 ** * If the file does not exist -> return false
27256 ** * If the size of the file is not a multiple of 512 -> return false
27257 ** * If sqlite3_open() fails -> return false
27258 ** * if sqlite3_prepare() or sqlite3_step() fails -> return false
27259 ** * Otherwise -> return true
27260 */
27261 static int isDatabaseFile(const char *zFile, int openFlags){
27262 sqlite3 *db = 0;
27263 sqlite3_stmt *pStmt = 0;
27264 int rc;
27265 sqlite3_int64 sz = fileSize(zFile);
27266 if( sz<512 || (sz%512)!=0 ) return 0;
27267 if( sqlite3_open_v2(zFile, &db, openFlags, 0)==SQLITE_OK
27268 && sqlite3_prepare_v2(db,"SELECT count(*) FROM sqlite_schema",-1,&pStmt,0)
27269 ==SQLITE_OK
27270 && sqlite3_step(pStmt)==SQLITE_ROW
27271 ){
27272 rc = 1;
27273 }else{
27274 rc = 0;
27275 }
27276 sqlite3_finalize(pStmt);
27277 sqlite3_close(db);
27278 return rc;
27279 }
27280
27281 /*
27282 ** Try to deduce the type of file for zName based on its content. Return
27283 ** one of the SHELL_OPEN_* constants.
27284 **
@@ -27206,24 +27288,16 @@
27288 ** the type cannot be determined from content.
27289 */
27290 int deduceDatabaseType(const char *zName, int dfltZip, int openFlags){
27291 FILE *f;
27292 size_t n;
 
 
27293 int rc = SHELL_OPEN_UNSPEC;
27294 char zBuf[100];
27295 if( access(zName,0)!=0 ) goto database_type_by_name;
27296 if( isDatabaseFile(zName, openFlags) ){
 
 
 
 
27297 rc = SHELL_OPEN_NORMAL;
27298 }
 
 
27299 if( rc==SHELL_OPEN_NORMAL ) return SHELL_OPEN_NORMAL;
27300 f = sqlite3_fopen(zName, "rb");
27301 if( f==0 ) goto database_type_by_name;
27302 n = fread(zBuf, 16, 1, f);
27303 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
@@ -27253,10 +27327,37 @@
27327 }else{
27328 rc = SHELL_OPEN_NORMAL;
27329 }
27330 return rc;
27331 }
27332
27333 /*
27334 ** If the text in z[] is the name of a readable file and that file appears
27335 ** to contain SQL text and/or dot-commands, then return true. If z[] is
27336 ** not a file, or if the file is unreadable, or if the file is a database
27337 ** or anything else that is not SQL text and dot-commands, then return false.
27338 **
27339 ** If the bLeaveUninit flag is set, then be sure to leave SQLite in an
27340 ** uninitialized state. This means invoking sqlite3_shutdown() after any
27341 ** SQLite API is used.
27342 **
27343 ** Some amount of guesswork is involved in this decision.
27344 */
27345 static int isScriptFile(const char *z, int bLeaveUninit){
27346 sqlite3_int64 sz = fileSize(z);
27347 if( sz<=0 ) return 0;
27348 if( (sz%512)==0 ){
27349 int rc = isDatabaseFile(z, SQLITE_OPEN_READONLY);
27350 if( bLeaveUninit ){
27351 sqlite3_shutdown();
27352 }
27353 if( rc ) return 0; /* Is a database */
27354 }
27355 if( sqlite3_strlike("%.sql",z,0)==0 ) return 1;
27356 if( sqlite3_strlike("%.txt",z,0)==0 ) return 1;
27357 return 0;
27358 }
27359
27360 #ifndef SQLITE_OMIT_DESERIALIZE
27361 /*
27362 ** Reconstruct an in-memory database using the output from the "dbtotxt"
27363 ** program. Read content from the file in p->aAuxDb[].zDbFilename.
@@ -31328,23 +31429,17 @@
31429 ** --bom Prepend a byte-order mark to the output
31430 ** -e Accumulate output in a temporary text file then
31431 ** launch a text editor when the redirection ends.
31432 ** --error-prefix X Use X as the left-margin prefix for error messages.
31433 ** Set to an empty string to restore the default.
31434 ** --keep Keep redirecting output to its current destination.
31435 ** Use this option in combination with --show or
31436 ** with --error-prefix when you do not want to stop
31437 ** a current redirection.
 
 
 
31438 ** --plain Use plain text rather than HTML tables with -w
31439 ** --show Show output text captured by .testcase or by
31440 ** redirecting to "memory".
 
 
 
31441 ** -w Show the output in a web browser. Output is
31442 ** written into a temporary HTML file until the
31443 ** redirect ends, then the web browser is launched.
31444 ** Query results are shown as HTML tables, unless
31445 ** the --plain is used too.
@@ -31382,13 +31477,11 @@
31477 char *zFile = 0; /* The FILE argument */
31478 int i; /* Loop counter */
31479 int eMode = 0; /* 0: .outout/.once, 'x'=.excel, 'w'=.www */
31480 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
31481 int bPlain = 0; /* --plain option */
31482 int bKeep = 0; /* Keep redirecting */
 
 
31483 static const char *zBomUtf8 = "\357\273\277";
31484 const char *zBom = 0;
31485 char c = azArg[0][0];
31486 int n = strlen30(azArg[0]);
31487
@@ -31410,36 +31503,21 @@
31503 zBom = zBomUtf8;
31504 }else if( cli_strcmp(z,"-plain")==0 ){
31505 bPlain = 1;
31506 }else if( c=='o' && z[0]=='1' && z[1]!=0 && z[2]==0
31507 && (z[1]=='x' || z[1]=='e' || z[1]=='w') ){
31508 if( bKeep || eMode ){
31509 dotCmdError(p, i, "incompatible with prior options",0);
31510 goto dotCmdOutput_error;
31511 }
31512 eMode = z[1];
 
 
31513 }else if( cli_strcmp(z,"-show")==0 ){
31514 if( cli_output_capture ){
31515 sqlite3_fprintf(stdout, "%s", sqlite3_str_value(cli_output_capture));
31516 }
31517 }else if( cli_strcmp(z,"-keep")==0 ){
31518 bKeep = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31519 }else if( optionMatch(z,"error-prefix") ){
31520 if( i+1>=nArg ){
31521 dotCmdError(p, i, "missing argument", 0);
31522 return 1;
31523 }
@@ -31450,11 +31528,11 @@
31528 dotCmdError(p, i, "unknown option", 0);
31529 sqlite3_free(zFile);
31530 return 1;
31531 }
31532 }else if( zFile==0 && eMode==0 ){
31533 if( bKeep ){
31534 dotCmdError(p, i, "incompatible with prior options",0);
31535 goto dotCmdOutput_error;
31536 }
31537 if( cli_strcmp(z, "memory")==0 && bOnce ){
31538 dotCmdError(p, 0, "cannot redirect to \"memory\"", 0);
@@ -31486,53 +31564,10 @@
31564 if( bOnce ){
31565 p->nPopOutput = 2;
31566 }else{
31567 p->nPopOutput = 0;
31568 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31569 if( !bKeep ) output_reset(p);
31570 #ifndef SQLITE_NOHAVE_SYSTEM
31571 if( eMode=='e' || eMode=='x' || eMode=='w' ){
31572 p->doXdgOpen = 1;
31573 modePush(p);
@@ -31609,10 +31644,200 @@
31644
31645 dotCmdOutput_error:
31646 sqlite3_free(zFile);
31647 return 1;
31648 }
31649
31650 /*
31651 ** DOT-COMMAND: .check
31652 ** USAGE: .check [OPTIONS] PATTERN
31653 **
31654 ** Verify results of commands since the most recent .testcase command.
31655 ** Restore output to the console, unless --keep is used.
31656 **
31657 ** If PATTERN starts with "<<ENDMARK" then the actual pattern is taken from
31658 ** subsequent lines of text up to the first line that begins with ENDMARK.
31659 ** All pattern lines and the ENDMARK are discarded.
31660 **
31661 ** Options:
31662 ** --error-prefix TEXT Change error message prefix text to TEXT
31663 ** --exact Do an exact comparison including leading and
31664 ** trailing whitespace.
31665 ** --glob Treat PATTERN as a GLOB
31666 ** --keep Do not reset the testcase. More .check commands
31667 ** will follow.
31668 ** --notglob Output should not match PATTERN
31669 ** --show Write testcase output to the screen, for debugging.
31670 */
31671 static int dotCmdCheck(ShellState *p){
31672 int nArg = p->dot.nArg; /* Number of arguments */
31673 char **azArg = p->dot.azArg; /* Text of the arguments */
31674 int i; /* Loop counter */
31675 int k; /* Result of pickStr() */
31676 char *zTest; /* Textcase result */
31677 int bKeep = 0; /* --keep option */
31678 char *zCheck = 0; /* PATTERN argument */
31679 char *zPattern = 0; /* Actual test pattern */
31680 int eCheck = 0; /* 1: --glob, 2: --notglob, 3: --exact */
31681 int isOk; /* True if results are OK */
31682 sqlite3_int64 iStart = p->lineno; /* Line number of .check statement */
31683
31684 if( p->zTestcase[0]==0 ){
31685 dotCmdError(p, 0, "no .testcase is active", 0);
31686 return 1;
31687 }
31688 for(i=1; i<nArg; i++){
31689 char *z = azArg[i];
31690 if( z[0]=='-' && z[1]=='-' && z[2]!=0 ) z++;
31691 if( cli_strcmp(z,"-keep")==0 ){
31692 bKeep = 1;
31693 }else if( cli_strcmp(z,"-show")==0 ){
31694 if( cli_output_capture ){
31695 sqlite3_fprintf(stdout, "%s", sqlite3_str_value(cli_output_capture));
31696 }
31697 bKeep = 1;
31698 }else if( z[0]=='-'
31699 && (k = pickStr(&z[1],0,"glob","notglob","exact",""))>=0
31700 ){
31701 if( eCheck && eCheck!=k+1 ){
31702 dotCmdError(p, i, "incompatible with prior options",0);
31703 return 1;
31704 }
31705 eCheck = k+1;
31706 }else if( zCheck ){
31707 dotCmdError(p, i, "unknown option", 0);
31708 return 1;
31709 }else{
31710 zCheck = azArg[i];
31711 }
31712 }
31713 if( zCheck==0 ){
31714 dotCmdError(p, 0, "no PATTERN specified", 0);
31715 return 1;
31716 }
31717 if( cli_output_capture ){
31718 zTest = sqlite3_str_value(cli_output_capture);
31719 shell_check_oom(zTest);
31720 }else{
31721 zTest = "";
31722 }
31723 p->nTestRun++;
31724 if( zCheck[0]=='<' && zCheck[1]=='<' && zCheck[2]!=0 ){
31725 int nCheck = strlen30(zCheck);
31726 sqlite3_str *pPattern = sqlite3_str_new(p->db);
31727 char zLine[2000];
31728 while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
31729 if( strchr(zLine,'\n') ) p->lineno++;
31730 if( cli_strncmp(&zCheck[2],zLine,nCheck-2)==0 ) break;
31731 sqlite3_str_appendall(pPattern, zLine);
31732 }
31733 zPattern = sqlite3_str_finish(pPattern);
31734 if( zPattern==0 ){
31735 zPattern = sqlite3_mprintf("");
31736 }
31737 }else{
31738 zPattern = zCheck;
31739 }
31740 shell_check_oom(zPattern);
31741 switch( eCheck ){
31742 case 1: {
31743 char *zGlob = sqlite3_mprintf("*%s*", zPattern);
31744 isOk = testcase_glob(zGlob, zTest)!=0;
31745 sqlite3_free(zGlob);
31746 break;
31747 }
31748 case 2: {
31749 char *zGlob = sqlite3_mprintf("*%s*", zPattern);
31750 isOk = testcase_glob(zGlob, zTest)==0;
31751 sqlite3_free(zGlob);
31752 break;
31753 }
31754 case 3: {
31755 isOk = cli_strcmp(zTest,zPattern)==0;
31756 break;
31757 }
31758 default: {
31759 /* Skip leading and trailing \n and \r on both pattern and test output */
31760 const char *z1 = zPattern;
31761 const char *z2 = zTest;
31762 size_t n1, n2;
31763 while( z1[0]=='\n' || z1[0]=='\r' ) z1++;
31764 n1 = strlen(z1);
31765 while( n1>0 && (z1[n1-1]=='\n' || z1[n1-1]=='\r') ) n1--;
31766 while( z2[0]=='\n' || z2[0]=='\r' ) z2++;
31767 n2 = strlen(z2);
31768 while( n2>0 && (z2[n2-1]=='\n' || z2[n2-1]=='\r') ) n2--;
31769 isOk = n1==n2 && memcmp(z1,z2,n1)==0;
31770 break;
31771 }
31772 }
31773 if( !isOk ){
31774 sqlite3_fprintf(stderr,
31775 "%s:%lld: .check failed for testcase %s\n",
31776 p->zInFile, iStart, p->zTestcase);
31777 p->nTestErr++;
31778 sqlite3_fprintf(stderr, "Expected: [%s]\n", zPattern);
31779 sqlite3_fprintf(stderr, "Got: [%s]\n", zTest);
31780 }
31781 if( zPattern!=zCheck ){
31782 sqlite3_free(zPattern);
31783 }
31784 if( !bKeep ){
31785 output_reset(p);
31786 p->zTestcase[0] = 0;
31787 }
31788 return 0;
31789 }
31790
31791 /*
31792 ** DOT-COMMAND: .testcase
31793 ** USAGE: .testcase [OPTIONS] NAME
31794 **
31795 ** Start a new test case identified by NAME. All output
31796 ** through the next ".check" command is captured for comparison. See the
31797 ** ".check" commandn for additional informatioon.
31798 **
31799 ** Options:
31800 ** --error-prefix TEXT Change error message prefix text to TEXT
31801 */
31802 static int dotCmdTestcase(ShellState *p){
31803 int nArg = p->dot.nArg; /* Number of arguments */
31804 char **azArg = p->dot.azArg; /* Text of the arguments */
31805 int i; /* Loop counter */
31806 const char *zName = 0; /* Testcase name */
31807
31808 for(i=1; i<nArg; i++){
31809 char *z = azArg[i];
31810 if( z[0]=='-' && z[1]=='-' && z[2]!=0 ) z++;
31811 if( optionMatch(z,"error-prefix") ){
31812 if( i+1>=nArg ){
31813 dotCmdError(p, i, "missing argument", 0);
31814 return 1;
31815 }
31816 free(p->zErrPrefix);
31817 i++;
31818 p->zErrPrefix = azArg[i][0]==0 ? 0 : strdup(azArg[i]);
31819 }else if( zName ){
31820 dotCmdError(p, i, "unknown option", 0);
31821 return 1;
31822 }else{
31823 zName = azArg[i];
31824 }
31825 }
31826 output_reset(p);
31827 if( cli_output_capture ){
31828 sqlite3_str_free(cli_output_capture);
31829 }
31830 cli_output_capture = sqlite3_str_new(0);
31831 if( zName ){
31832 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", zName);
31833 }else{
31834 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s:%lld",
31835 p->zInFile, p->lineno);
31836 }
31837 return 0;
31838 }
31839
31840 /*
31841 ** Enlarge the space allocated in p->dot so that it can hold more
31842 ** than nArg parsed command-line arguments.
31843 */
@@ -31641,11 +31866,11 @@
31866 free(p->dot.zCopy);
31867 z = p->dot.zCopy = strdup(zLine);
31868 shell_check_oom(z);
31869 szLine = strlen(z);
31870 while( szLine>0 && IsSpace(z[szLine-1]) ) szLine--;
31871 if( szLine>0 && z[szLine-1]==';' ){
31872 szLine--;
31873 while( szLine>0 && IsSpace(z[szLine-1]) ) szLine--;
31874 }
31875 z[szLine] = 0;
31876 parseDotRealloc(p, 2);
@@ -31861,35 +32086,17 @@
32086 eputz("Usage: .changes on|off\n");
32087 rc = 1;
32088 }
32089 }else
32090
 
32091 /* Cancel output redirection, if it is currently set (by .testcase)
32092 ** Then read the content of the testcase-out.txt file and compare against
32093 ** azArg[1]. If there are differences, report an error and exit.
32094 */
32095 if( c=='c' && n>=3 && cli_strncmp(azArg[0], "check", n)==0 ){
32096 rc = dotCmdCheck(p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32097 }else
 
32098
32099 #ifndef SQLITE_SHELL_FIDDLE
32100 if( c=='c' && cli_strncmp(azArg[0], "clone", n)==0 ){
32101 failIfSafeMode(p, "cannot run .clone in safe mode");
32102 if( nArg==2 ){
@@ -32521,14 +32728,14 @@
32728 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
32729 goto meta_command_exit;
32730 }
32731 zSql = sqlite3_mprintf(
32732 "SELECT rootpage, 0 FROM sqlite_schema"
32733 " WHERE type='index' AND lower(name)=lower('%q')"
32734 "UNION ALL "
32735 "SELECT rootpage, 1 FROM sqlite_schema"
32736 " WHERE type='table' AND lower(name)=lower('%q')"
32737 " AND sql LIKE '%%without%%rowid%%'",
32738 azArg[1], azArg[1]
32739 );
32740 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
32741 sqlite3_free(zSql);
@@ -32682,13 +32889,14 @@
32889 goto meta_command_exit;
32890 }
32891 if( nArg==3 ){
32892 sqlite3_limit(p->db, aLimit[iLimit].limitCode,
32893 (int)integerValue(azArg[2]));
32894 }else{
32895 cli_printf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName,
32896 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
32897 }
 
 
32898 }
32899 }else
32900
32901 if( c=='l' && n>2 && cli_strncmp(azArg[0], "lint", n)==0 ){
32902 open_db(p, 0);
@@ -34017,25 +34225,15 @@
34225 sqlite3_str_free(pSql);
34226 modePop(p);
34227 if( rc ) return shellDatabaseError(p->db);
34228 }else
34229
34230 /* Set the p->zTestcase name and begin redirecting output into
34231 ** the cli_output_capture sqlite3_str */
34232 if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
34233 rc = dotCmdTestcase(p);
 
 
 
 
 
 
 
 
 
34234 }else
 
34235
34236 #ifndef SQLITE_UNTESTABLE
34237 if( c=='t' && n>=8 && cli_strncmp(azArg[0], "testctrl", n)==0 ){
34238 static const struct {
34239 const char *zCtrlName; /* Name of a test-control option */
@@ -35351,11 +35549,10 @@
35549 " -bail stop after hitting an error\n"
35550 " -batch force batch I/O\n"
35551 " -box set output mode to 'box'\n"
35552 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
35553 " -column set output mode to 'column'\n"
 
35554 " -csv set output mode to 'csv'\n"
35555 #if !defined(SQLITE_OMIT_DESERIALIZE)
35556 " -deserialize open the database using sqlite3_deserialize()\n"
35557 #endif
35558 " -echo print inputs before execution\n"
@@ -35435,15 +35632,10 @@
35632 /*
35633 ** Initialize the state information in data
35634 */
35635 static void main_init(ShellState *p) {
35636 memset(p, 0, sizeof(*p));
 
 
 
 
 
35637 p->pAuxDb = &p->aAuxDb[0];
35638 p->shellFlgs = SHFLG_Lookaside;
35639 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, p);
35640 #if !defined(SQLITE_SHELL_FIDDLE)
35641 verify_uninitialized();
@@ -35637,11 +35829,11 @@
35829 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
35830 warnInmemoryDb = 0;
35831 }
35832 #endif
35833
35834 /* Do an initial pass through the command-line arguments to locate
35835 ** the name of the database file, the name of the initialization file,
35836 ** the size of the alternative malloc heap, options affecting commands
35837 ** or SQL run from the command line, and the first command to execute.
35838 */
35839 #ifndef SQLITE_SHELL_FIDDLE
@@ -35649,11 +35841,11 @@
35841 #endif
35842 for(i=1; i<argc; i++){
35843 char *z;
35844 z = argv[i];
35845 if( z[0]!='-' || i>nOptsEnd ){
35846 if( data.aAuxDb->zDbFilename==0 && !isScriptFile(z,1) ){
35847 data.aAuxDb->zDbFilename = z;
35848 }else{
35849 /* Excess arguments are interpreted as SQL (or dot-commands) and
35850 ** mean that nothing is read from stdin */
35851 readStdin = 0;
@@ -35694,15 +35886,10 @@
35886 if( n<2 ){
35887 sqlite3_fprintf(stderr,"minimum --screenwidth is 2\n");
35888 exit(1);
35889 }
35890 stdout_tty_width = n;
 
 
 
 
 
35891 }else if( cli_strcmp(z,"-utf8")==0 ){
35892 }else if( cli_strcmp(z,"-no-utf8")==0 ){
35893 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
35894 int val = 0;
35895 sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW, &val);
@@ -35889,11 +36076,11 @@
36076 ** is given on the command line, look for a file named ~/.sqliterc and
36077 ** try to process it.
36078 */
36079 if( !noInit ) process_sqliterc(&data,zInitFile);
36080
36081 /* Make a second pass through the command-line arguments and set
36082 ** options. This second pass is delayed until after the initialization
36083 ** file is processed so that the command-line arguments will override
36084 ** settings in the initialization file.
36085 */
36086 for(i=1; i<argc; i++){
@@ -36015,12 +36202,10 @@
36202 stdin_is_interactive = 1;
36203 }else if( cli_strcmp(z,"-batch")==0 ){
36204 /* already handled */
36205 }else if( cli_strcmp(z,"-screenwidth")==0 ){
36206 i++;
 
 
36207 }else if( cli_strcmp(z,"-utf8")==0 ){
36208 /* already handled */
36209 }else if( cli_strcmp(z,"-no-utf8")==0 ){
36210 /* already handled */
36211 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
@@ -36116,11 +36301,22 @@
36301 ** command-line inputs, except for the argToSkip argument which contains
36302 ** the database filename.
36303 */
36304 for(i=0; i<nCmd; i++){
36305 echo_group_input(&data, azCmd[i]);
36306 if( isScriptFile(azCmd[i],0) ){
36307 FILE *inSaved = data.in;
36308 i64 savedLineno = data.lineno;
36309 int res = 1;
36310 if( (data.in = openChrSource(azCmd[i]))!=0 ){
36311 res = process_input(&data, azCmd[i]);
36312 fclose(data.in);
36313 }
36314 data.in = inSaved;
36315 data.lineno = savedLineno;
36316 if( res ) i = nCmd;
36317 }else if( azCmd[i][0]=='.' ){
36318 char *zErrCtx = malloc( 64 );
36319 shell_check_oom(zErrCtx);
36320 sqlite3_snprintf(64,zErrCtx,"argv[%i]:",aiCmd[i]);
36321 data.zInFile = "<cmdline>";
36322 data.zErrPrefix = zErrCtx;
36323
+98 -92
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 01409738afc2c0d5bdaa248ffb508aa5f36a with changes in files:
21
+** eb2c020481dd591f459cf7191d18c2499aee with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.52.0"
471471
#define SQLITE_VERSION_NUMBER 3052000
472
-#define SQLITE_SOURCE_ID "2025-12-11 23:24:05 01409738afc2c0d5bdaa248ffb508aa5f36a66390f6b8e4834734529ee8ed2fa"
472
+#define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2025-12-11T23:24:05.667Z"
475
+#define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -7746,22 +7746,22 @@
77467746
** ^This interface loads an SQLite extension library from the named file.
77477747
**
77487748
** ^The sqlite3_load_extension() interface attempts to load an
77497749
** [SQLite extension] library contained in the file zFile. If
77507750
** the file cannot be loaded directly, attempts are made to load
7751
-** with various operating-system specific extensions added.
7751
+** with various operating-system specific filename extensions added.
77527752
** So for example, if "samplelib" cannot be loaded, then names like
77537753
** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
77547754
** be tried also.
77557755
**
77567756
** ^The entry point is zProc.
77577757
** ^(zProc may be 0, in which case SQLite will try to come up with an
77587758
** entry point name on its own. It first tries "sqlite3_extension_init".
7759
-** If that does not work, it constructs a name "sqlite3_X_init" where
7760
-** X consists of the lower-case equivalent of all ASCII alphabetic
7761
-** characters in the filename from the last "/" to the first following
7762
-** "." and omitting any initial "lib".)^
7759
+** If that does not work, it tries names of the form "sqlite3_X_init"
7760
+** where X consists of the lower-case equivalent of all ASCII alphabetic
7761
+** characters or all ASCII alphanumeric characters in the filename from
7762
+** the last "/" to the first following "." and omitting any initial "lib".)^
77637763
** ^The sqlite3_load_extension() interface returns
77647764
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
77657765
** ^If an error occurs and pzErrMsg is not 0, then the
77667766
** [sqlite3_load_extension()] interface shall attempt to
77677767
** fill *pzErrMsg with error message text stored in memory
@@ -48881,78 +48881,54 @@
4888148881
{ "WriteFile", (SYSCALL)WriteFile, 0 },
4888248882
4888348883
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
4888448884
LPOVERLAPPED))aSyscall[61].pCurrent)
4888548885
48886
- { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
48887
-
48888
-#define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
48889
- DWORD,DWORD))aSyscall[62].pCurrent)
48890
-
4889148886
/*
4889248887
** For WaitForSingleObject(), MSDN says:
4889348888
**
4889448889
** Minimum supported client: Windows XP [desktop apps | UWP apps]
4889548890
** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
4889648891
*/
4889748892
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
4889848893
4889948894
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
48900
- DWORD))aSyscall[63].pCurrent)
48895
+ DWORD))aSyscall[62].pCurrent)
4890148896
4890248897
#if !SQLITE_OS_WINCE
4890348898
{ "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
4890448899
#else
4890548900
{ "WaitForSingleObjectEx", (SYSCALL)0, 0 },
4890648901
#endif
4890748902
4890848903
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
48909
- BOOL))aSyscall[64].pCurrent)
48910
-
48911
- { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
48912
-
48913
-#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
48914
- PLARGE_INTEGER,DWORD))aSyscall[65].pCurrent)
48915
-
48916
- { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
48917
-
48918
-#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
48919
- FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
48920
-
48921
- { "CreateFile2", (SYSCALL)CreateFile2, 0 },
48922
-
48923
-#define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
48924
- LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[68].pCurrent)
48925
-
48926
- { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
48927
-
48928
-#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[70].pCurrent)
48904
+ BOOL))aSyscall[63].pCurrent)
4892948905
4893048906
{ "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
4893148907
4893248908
#define osGetNativeSystemInfo ((VOID(WINAPI*)( \
48933
- LPSYSTEM_INFO))aSyscall[71].pCurrent)
48909
+ LPSYSTEM_INFO))aSyscall[64].pCurrent)
4893448910
4893548911
#if defined(SQLITE_WIN32_HAS_ANSI)
4893648912
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
4893748913
#else
4893848914
{ "OutputDebugStringA", (SYSCALL)0, 0 },
4893948915
#endif
4894048916
48941
-#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[72].pCurrent)
48917
+#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[65].pCurrent)
4894248918
4894348919
#if defined(SQLITE_WIN32_HAS_WIDE)
4894448920
{ "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
4894548921
#else
4894648922
{ "OutputDebugStringW", (SYSCALL)0, 0 },
4894748923
#endif
4894848924
48949
-#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[73].pCurrent)
48925
+#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[66].pCurrent)
4895048926
4895148927
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
4895248928
48953
-#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
48929
+#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[67].pCurrent)
4895448930
4895548931
/*
4895648932
** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
4895748933
** is really just a macro that uses a compiler intrinsic (e.g. x64).
4895848934
** So do not try to make this is into a redefinable interface.
@@ -48963,38 +48939,38 @@
4896348939
#define osInterlockedCompareExchange InterlockedCompareExchange
4896448940
#else
4896548941
{ "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
4896648942
4896748943
#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
48968
- SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
48944
+ SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[68].pCurrent)
4896948945
#endif /* defined(InterlockedCompareExchange) */
4897048946
4897148947
#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
4897248948
{ "UuidCreate", (SYSCALL)UuidCreate, 0 },
4897348949
#else
4897448950
{ "UuidCreate", (SYSCALL)0, 0 },
4897548951
#endif
4897648952
48977
-#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent)
48953
+#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[69].pCurrent)
4897848954
4897948955
#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
4898048956
{ "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
4898148957
#else
4898248958
{ "UuidCreateSequential", (SYSCALL)0, 0 },
4898348959
#endif
4898448960
4898548961
#define osUuidCreateSequential \
48986
- ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
48962
+ ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[70].pCurrent)
4898748963
4898848964
#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
4898948965
{ "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
4899048966
#else
4899148967
{ "FlushViewOfFile", (SYSCALL)0, 0 },
4899248968
#endif
4899348969
4899448970
#define osFlushViewOfFile \
48995
- ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
48971
+ ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[71].pCurrent)
4899648972
4899748973
/*
4899848974
** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
4899948975
** to implement blocking locks with timeouts. MSDN says:
4900048976
**
@@ -49007,11 +48983,11 @@
4900748983
{ "CreateEvent", (SYSCALL)0, 0 },
4900848984
#endif
4900948985
4901048986
#define osCreateEvent ( \
4901148987
(HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49012
- aSyscall[80].pCurrent \
48988
+ aSyscall[72].pCurrent \
4901348989
)
4901448990
4901548991
/*
4901648992
** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
4901748993
** for the case where a timeout expires and a lock request must be
@@ -49024,68 +49000,68 @@
4902449000
{ "CancelIo", (SYSCALL)CancelIo, 0 },
4902549001
#else
4902649002
{ "CancelIo", (SYSCALL)0, 0 },
4902749003
#endif
4902849004
49029
-#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
49005
+#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[73].pCurrent)
4903049006
4903149007
#if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
4903249008
{ "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
4903349009
#else
4903449010
{ "GetModuleHandleW", (SYSCALL)0, 0 },
4903549011
#endif
4903649012
49037
-#define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[82].pCurrent)
49013
+#define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[74].pCurrent)
4903849014
4903949015
#ifndef _WIN32
4904049016
{ "getenv", (SYSCALL)getenv, 0 },
4904149017
#else
4904249018
{ "getenv", (SYSCALL)0, 0 },
4904349019
#endif
4904449020
49045
-#define osGetenv ((const char *(*)(const char *))aSyscall[83].pCurrent)
49021
+#define osGetenv ((const char *(*)(const char *))aSyscall[75].pCurrent)
4904649022
4904749023
#ifndef _WIN32
4904849024
{ "getcwd", (SYSCALL)getcwd, 0 },
4904949025
#else
4905049026
{ "getcwd", (SYSCALL)0, 0 },
4905149027
#endif
4905249028
49053
-#define osGetcwd ((char*(*)(char*,size_t))aSyscall[84].pCurrent)
49029
+#define osGetcwd ((char*(*)(char*,size_t))aSyscall[76].pCurrent)
4905449030
4905549031
#ifndef _WIN32
4905649032
{ "readlink", (SYSCALL)readlink, 0 },
4905749033
#else
4905849034
{ "readlink", (SYSCALL)0, 0 },
4905949035
#endif
4906049036
49061
-#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[85].pCurrent)
49037
+#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[77].pCurrent)
4906249038
4906349039
#ifndef _WIN32
4906449040
{ "lstat", (SYSCALL)lstat, 0 },
4906549041
#else
4906649042
{ "lstat", (SYSCALL)0, 0 },
4906749043
#endif
4906849044
49069
-#define osLstat ((int(*)(const char*,struct stat*))aSyscall[86].pCurrent)
49045
+#define osLstat ((int(*)(const char*,struct stat*))aSyscall[78].pCurrent)
4907049046
4907149047
#ifndef _WIN32
4907249048
{ "__errno", (SYSCALL)__errno, 0 },
4907349049
#else
4907449050
{ "__errno", (SYSCALL)0, 0 },
4907549051
#endif
4907649052
49077
-#define osErrno (*((int*(*)(void))aSyscall[87].pCurrent)())
49053
+#define osErrno (*((int*(*)(void))aSyscall[79].pCurrent)())
4907849054
4907949055
#ifndef _WIN32
4908049056
{ "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
4908149057
#else
4908249058
{ "cygwin_conv_path", (SYSCALL)0, 0 },
4908349059
#endif
4908449060
4908549061
#define osCygwin_conv_path ((size_t(*)(unsigned int, \
49086
- const void *, void *, size_t))aSyscall[88].pCurrent)
49062
+ const void *, void *, size_t))aSyscall[80].pCurrent)
4908749063
4908849064
}; /* End of the overrideable system calls */
4908949065
4909049066
/*
4909149067
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -54399,11 +54375,16 @@
5439954375
};
5440054376
#endif
5440154377
5440254378
/* Double-check that the aSyscall[] array has been constructed
5440354379
** correctly. See ticket [bb3a86e890c8e96ab] */
54404
- assert( ArraySize(aSyscall)==86 );
54380
+ assert( ArraySize(aSyscall)==81 );
54381
+ assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54382
+ assert( strcmp(aSyscall[20].zName,"GetFileAttributesA")==0 );
54383
+ assert( strcmp(aSyscall[40].zName,"HeapReAlloc")==0 );
54384
+ assert( strcmp(aSyscall[60].zName,"WideCharToMultiByte")==0 );
54385
+ assert( strcmp(aSyscall[80].zName,"cygwin_conv_path")==0 );
5440554386
5440654387
/* get memory map allocation granularity */
5440754388
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
5440854389
osGetSystemInfo(&winSysInfo);
5440954390
assert( winSysInfo.dwAllocationGranularity>0 );
@@ -110988,14 +110969,10 @@
110988110969
}
110989110970
}
110990110971
}
110991110972
#endif
110992110973
110993
- /* The ORDER BY and GROUP BY clauses may not refer to terms in
110994
- ** outer queries
110995
- */
110996
- sNC.pNext = 0;
110997110974
sNC.ncFlags |= NC_AllowAgg|NC_AllowWin;
110998110975
110999110976
/* If this is a converted compound query, move the ORDER BY clause from
111000110977
** the sub-query back to the parent query. At this point each term
111001110978
** within the ORDER BY clause has been transformed to an integer value.
@@ -142206,37 +142183,46 @@
142206142183
142207142184
/* If no entry point was specified and the default legacy
142208142185
** entry point name "sqlite3_extension_init" was not found, then
142209142186
** construct an entry point name "sqlite3_X_init" where the X is
142210142187
** replaced by the lowercase value of every ASCII alphabetic
142211
- ** character in the filename after the last "/" upto the first ".",
142212
- ** and eliding the first three characters if they are "lib".
142188
+ ** character in the filename after the last "/" up to the first ".",
142189
+ ** and skipping the first three characters if they are "lib".
142213142190
** Examples:
142214142191
**
142215142192
** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
142216142193
** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
142194
+ **
142195
+ ** If that still finds no entry point, repeat a second time but this
142196
+ ** time include both alphabetic and numeric characters up to the first
142197
+ ** ".". Example:
142198
+ **
142199
+ ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example5_init
142217142200
*/
142218142201
if( xInit==0 && zProc==0 ){
142219142202
int iFile, iEntry, c;
142220142203
int ncFile = sqlite3Strlen30(zFile);
142204
+ int cnt = 0;
142221142205
zAltEntry = sqlite3_malloc64(ncFile+30);
142222142206
if( zAltEntry==0 ){
142223142207
sqlite3OsDlClose(pVfs, handle);
142224142208
return SQLITE_NOMEM_BKPT;
142225142209
}
142226
- memcpy(zAltEntry, "sqlite3_", 8);
142227
- for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
142228
- iFile++;
142229
- if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
142230
- for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
142231
- if( sqlite3Isalpha(c) ){
142232
- zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
142233
- }
142234
- }
142235
- memcpy(zAltEntry+iEntry, "_init", 6);
142236
- zEntry = zAltEntry;
142237
- xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
142210
+ do{
142211
+ memcpy(zAltEntry, "sqlite3_", 8);
142212
+ for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
142213
+ iFile++;
142214
+ if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
142215
+ for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
142216
+ if( sqlite3Isalpha(c) || (cnt && sqlite3Isdigit(c)) ){
142217
+ zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
142218
+ }
142219
+ }
142220
+ memcpy(zAltEntry+iEntry, "_init", 6);
142221
+ zEntry = zAltEntry;
142222
+ xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
142223
+ }while( xInit==0 && (++cnt)<2 );
142238142224
}
142239142225
if( xInit==0 ){
142240142226
if( pzErrMsg ){
142241142227
nMsg += strlen(zEntry) + 300;
142242142228
*pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
@@ -154969,10 +154955,34 @@
154969154955
memset(&sCtx, 0, sizeof(sCtx));
154970154956
sCtx.pSrc = pSelect->pSrc;
154971154957
sqlite3WalkExprNN(&w, pSelect->pWhere);
154972154958
pSelect->selFlags &= ~SF_OnToWhere;
154973154959
}
154960
+
154961
+/*
154962
+** If p2 exists and p1 and p2 have the same number of terms, then change
154963
+** every term of p1 to have the same sort order as p2 and return true.
154964
+**
154965
+** If p2 is NULL or p1 and p2 are different lengths, then make no changes
154966
+** and return false.
154967
+**
154968
+** p1 must be non-NULL.
154969
+*/
154970
+static int sqlite3CopySortOrder(ExprList *p1, ExprList *p2){
154971
+ assert( p1 );
154972
+ if( p2 && p1->nExpr==p2->nExpr ){
154973
+ int ii;
154974
+ for(ii=0; ii<p1->nExpr; ii++){
154975
+ u8 sortFlags;
154976
+ sortFlags = p2->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
154977
+ p1->a[ii].fg.sortFlags = sortFlags;
154978
+ }
154979
+ return 1;
154980
+ }else{
154981
+ return 0;
154982
+ }
154983
+}
154974154984
154975154985
/*
154976154986
** Generate byte-code for the SELECT statement given in the p argument.
154977154987
**
154978154988
** The results are returned according to the SelectDest structure.
@@ -155622,11 +155632,12 @@
155622155632
** used for both the ORDER BY and DISTINCT processing. As originally
155623155633
** written the query must use a temp-table for at least one of the ORDER
155624155634
** BY and DISTINCT, and an index or separate temp-table for the other.
155625155635
*/
155626155636
if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
155627
- && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
155637
+ && sqlite3CopySortOrder(pEList, sSort.pOrderBy)
155638
+ && sqlite3ExprListCompare(pEList, sSort.pOrderBy, -1)==0
155628155639
&& OptimizationEnabled(db, SQLITE_GroupByOrder)
155629155640
#ifndef SQLITE_OMIT_WINDOWFUNC
155630155641
&& p->pWin==0
155631155642
#endif
155632155643
){
@@ -155836,25 +155847,14 @@
155836155847
** in the correct order. It also may not - the GROUP BY might use a
155837155848
** database index that causes rows to be grouped together as required
155838155849
** but not actually sorted. Either way, record the fact that the
155839155850
** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
155840155851
** variable. */
155841
- if( sSort.pOrderBy && pGroupBy->nExpr==sSort.pOrderBy->nExpr ){
155842
- int ii;
155843
- /* The GROUP BY processing doesn't care whether rows are delivered in
155844
- ** ASC or DESC order - only that each group is returned contiguously.
155845
- ** So set the ASC/DESC flags in the GROUP BY to match those in the
155846
- ** ORDER BY to maximize the chances of rows being delivered in an
155847
- ** order that makes the ORDER BY redundant. */
155848
- for(ii=0; ii<pGroupBy->nExpr; ii++){
155849
- u8 sortFlags;
155850
- sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
155851
- pGroupBy->a[ii].fg.sortFlags = sortFlags;
155852
- }
155853
- if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
155854
- orderByGrp = 1;
155855
- }
155852
+ if( sqlite3CopySortOrder(pGroupBy, sSort.pOrderBy)
155853
+ && sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0
155854
+ ){
155855
+ orderByGrp = 1;
155856155856
}
155857155857
}else{
155858155858
assert( 0==sqlite3LogEst(1) );
155859155859
p->nSelectRow = 0;
155860155860
}
@@ -156849,15 +156849,20 @@
156849156849
}
156850156850
goto trigger_cleanup;
156851156851
}
156852156852
}
156853156853
156854
+ /* NB: The SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES compile-time option is
156855
+ ** experimental and unsupported. Do not use it unless understand the
156856
+ ** implications and you cannot get by without this capability. */
156857
+#if !defined(SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES) /* Experimental */
156854156858
/* Do not create a trigger on a system table */
156855156859
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
156856156860
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
156857156861
goto trigger_cleanup;
156858156862
}
156863
+#endif
156859156864
156860156865
/* INSTEAD of triggers are only for views and views only support INSTEAD
156861156866
** of triggers.
156862156867
*/
156863156868
if( IsView(pTab) && tr_tm!=TK_INSTEAD ){
@@ -168744,15 +168749,18 @@
168744168749
168745168750
/* No matches cause a break out of the loop */
168746168751
break;
168747168752
}
168748168753
if( i==n ){
168754
+ int bSortByGroup = (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0;
168749168755
nOrderBy = n;
168750168756
if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) && !pSrc->fg.rowidUsed ){
168751
- eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
168757
+ eDistinct = 2 + bSortByGroup;
168752168758
}else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){
168753
- eDistinct = 1;
168759
+ eDistinct = 1 - bSortByGroup;
168760
+ }else if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
168761
+ eDistinct = 3;
168754168762
}
168755168763
}
168756168764
}
168757168765
168758168766
/* Allocate the sqlite3_index_info structure
@@ -172330,13 +172338,11 @@
172330172338
if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
172331172339
}else{
172332172340
pLoop = pLast;
172333172341
}
172334172342
if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
172335
- if( pLoop->u.vtab.isOrdered
172336
- && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
172337
- ){
172343
+ if( pLoop->u.vtab.isOrdered && pWInfo->pOrderBy==pOrderBy ){
172338172344
obSat = obDone;
172339172345
}else{
172340172346
/* No further ORDER BY terms may be matched. So this call should
172341172347
** return >=0, not -1. Clear isOrderDistinct to ensure it does so. */
172342172348
isOrderDistinct = 0;
@@ -261097,11 +261103,11 @@
261097261103
int nArg, /* Number of args */
261098261104
sqlite3_value **apUnused /* Function arguments */
261099261105
){
261100261106
assert( nArg==0 );
261101261107
UNUSED_PARAM2(nArg, apUnused);
261102
- sqlite3_result_text(pCtx, "fts5: 2025-12-11 18:16:39 e785a80e4100c368dca8d73cb662cff4d0fd76734fa0f3fa9b5754a380f7c746", -1, SQLITE_TRANSIENT);
261108
+ sqlite3_result_text(pCtx, "fts5: 2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8", -1, SQLITE_TRANSIENT);
261103261109
}
261104261110
261105261111
/*
261106261112
** Implementation of fts5_locale(LOCALE, TEXT) function.
261107261113
**
261108261114
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 01409738afc2c0d5bdaa248ffb508aa5f36a with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2025-12-11 23:24:05 01409738afc2c0d5bdaa248ffb508aa5f36a66390f6b8e4834734529ee8ed2fa"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-12-11T23:24:05.667Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -7746,22 +7746,22 @@
7746 ** ^This interface loads an SQLite extension library from the named file.
7747 **
7748 ** ^The sqlite3_load_extension() interface attempts to load an
7749 ** [SQLite extension] library contained in the file zFile. If
7750 ** the file cannot be loaded directly, attempts are made to load
7751 ** with various operating-system specific extensions added.
7752 ** So for example, if "samplelib" cannot be loaded, then names like
7753 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
7754 ** be tried also.
7755 **
7756 ** ^The entry point is zProc.
7757 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7758 ** entry point name on its own. It first tries "sqlite3_extension_init".
7759 ** If that does not work, it constructs a name "sqlite3_X_init" where
7760 ** X consists of the lower-case equivalent of all ASCII alphabetic
7761 ** characters in the filename from the last "/" to the first following
7762 ** "." and omitting any initial "lib".)^
7763 ** ^The sqlite3_load_extension() interface returns
7764 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7765 ** ^If an error occurs and pzErrMsg is not 0, then the
7766 ** [sqlite3_load_extension()] interface shall attempt to
7767 ** fill *pzErrMsg with error message text stored in memory
@@ -48881,78 +48881,54 @@
48881 { "WriteFile", (SYSCALL)WriteFile, 0 },
48882
48883 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
48884 LPOVERLAPPED))aSyscall[61].pCurrent)
48885
48886 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
48887
48888 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
48889 DWORD,DWORD))aSyscall[62].pCurrent)
48890
48891 /*
48892 ** For WaitForSingleObject(), MSDN says:
48893 **
48894 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
48895 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
48896 */
48897 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
48898
48899 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
48900 DWORD))aSyscall[63].pCurrent)
48901
48902 #if !SQLITE_OS_WINCE
48903 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
48904 #else
48905 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
48906 #endif
48907
48908 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
48909 BOOL))aSyscall[64].pCurrent)
48910
48911 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
48912
48913 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
48914 PLARGE_INTEGER,DWORD))aSyscall[65].pCurrent)
48915
48916 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
48917
48918 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
48919 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
48920
48921 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
48922
48923 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
48924 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[68].pCurrent)
48925
48926 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
48927
48928 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[70].pCurrent)
48929
48930 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
48931
48932 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
48933 LPSYSTEM_INFO))aSyscall[71].pCurrent)
48934
48935 #if defined(SQLITE_WIN32_HAS_ANSI)
48936 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
48937 #else
48938 { "OutputDebugStringA", (SYSCALL)0, 0 },
48939 #endif
48940
48941 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[72].pCurrent)
48942
48943 #if defined(SQLITE_WIN32_HAS_WIDE)
48944 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
48945 #else
48946 { "OutputDebugStringW", (SYSCALL)0, 0 },
48947 #endif
48948
48949 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[73].pCurrent)
48950
48951 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
48952
48953 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
48954
48955 /*
48956 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
48957 ** is really just a macro that uses a compiler intrinsic (e.g. x64).
48958 ** So do not try to make this is into a redefinable interface.
@@ -48963,38 +48939,38 @@
48963 #define osInterlockedCompareExchange InterlockedCompareExchange
48964 #else
48965 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
48966
48967 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
48968 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
48969 #endif /* defined(InterlockedCompareExchange) */
48970
48971 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
48972 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
48973 #else
48974 { "UuidCreate", (SYSCALL)0, 0 },
48975 #endif
48976
48977 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent)
48978
48979 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
48980 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
48981 #else
48982 { "UuidCreateSequential", (SYSCALL)0, 0 },
48983 #endif
48984
48985 #define osUuidCreateSequential \
48986 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
48987
48988 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
48989 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
48990 #else
48991 { "FlushViewOfFile", (SYSCALL)0, 0 },
48992 #endif
48993
48994 #define osFlushViewOfFile \
48995 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
48996
48997 /*
48998 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
48999 ** to implement blocking locks with timeouts. MSDN says:
49000 **
@@ -49007,11 +48983,11 @@
49007 { "CreateEvent", (SYSCALL)0, 0 },
49008 #endif
49009
49010 #define osCreateEvent ( \
49011 (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49012 aSyscall[80].pCurrent \
49013 )
49014
49015 /*
49016 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
49017 ** for the case where a timeout expires and a lock request must be
@@ -49024,68 +49000,68 @@
49024 { "CancelIo", (SYSCALL)CancelIo, 0 },
49025 #else
49026 { "CancelIo", (SYSCALL)0, 0 },
49027 #endif
49028
49029 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
49030
49031 #if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
49032 { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
49033 #else
49034 { "GetModuleHandleW", (SYSCALL)0, 0 },
49035 #endif
49036
49037 #define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[82].pCurrent)
49038
49039 #ifndef _WIN32
49040 { "getenv", (SYSCALL)getenv, 0 },
49041 #else
49042 { "getenv", (SYSCALL)0, 0 },
49043 #endif
49044
49045 #define osGetenv ((const char *(*)(const char *))aSyscall[83].pCurrent)
49046
49047 #ifndef _WIN32
49048 { "getcwd", (SYSCALL)getcwd, 0 },
49049 #else
49050 { "getcwd", (SYSCALL)0, 0 },
49051 #endif
49052
49053 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[84].pCurrent)
49054
49055 #ifndef _WIN32
49056 { "readlink", (SYSCALL)readlink, 0 },
49057 #else
49058 { "readlink", (SYSCALL)0, 0 },
49059 #endif
49060
49061 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[85].pCurrent)
49062
49063 #ifndef _WIN32
49064 { "lstat", (SYSCALL)lstat, 0 },
49065 #else
49066 { "lstat", (SYSCALL)0, 0 },
49067 #endif
49068
49069 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[86].pCurrent)
49070
49071 #ifndef _WIN32
49072 { "__errno", (SYSCALL)__errno, 0 },
49073 #else
49074 { "__errno", (SYSCALL)0, 0 },
49075 #endif
49076
49077 #define osErrno (*((int*(*)(void))aSyscall[87].pCurrent)())
49078
49079 #ifndef _WIN32
49080 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
49081 #else
49082 { "cygwin_conv_path", (SYSCALL)0, 0 },
49083 #endif
49084
49085 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49086 const void *, void *, size_t))aSyscall[88].pCurrent)
49087
49088 }; /* End of the overrideable system calls */
49089
49090 /*
49091 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -54399,11 +54375,16 @@
54399 };
54400 #endif
54401
54402 /* Double-check that the aSyscall[] array has been constructed
54403 ** correctly. See ticket [bb3a86e890c8e96ab] */
54404 assert( ArraySize(aSyscall)==86 );
 
 
 
 
 
54405
54406 /* get memory map allocation granularity */
54407 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
54408 osGetSystemInfo(&winSysInfo);
54409 assert( winSysInfo.dwAllocationGranularity>0 );
@@ -110988,14 +110969,10 @@
110988 }
110989 }
110990 }
110991 #endif
110992
110993 /* The ORDER BY and GROUP BY clauses may not refer to terms in
110994 ** outer queries
110995 */
110996 sNC.pNext = 0;
110997 sNC.ncFlags |= NC_AllowAgg|NC_AllowWin;
110998
110999 /* If this is a converted compound query, move the ORDER BY clause from
111000 ** the sub-query back to the parent query. At this point each term
111001 ** within the ORDER BY clause has been transformed to an integer value.
@@ -142206,37 +142183,46 @@
142206
142207 /* If no entry point was specified and the default legacy
142208 ** entry point name "sqlite3_extension_init" was not found, then
142209 ** construct an entry point name "sqlite3_X_init" where the X is
142210 ** replaced by the lowercase value of every ASCII alphabetic
142211 ** character in the filename after the last "/" upto the first ".",
142212 ** and eliding the first three characters if they are "lib".
142213 ** Examples:
142214 **
142215 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
142216 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
 
 
 
 
 
 
142217 */
142218 if( xInit==0 && zProc==0 ){
142219 int iFile, iEntry, c;
142220 int ncFile = sqlite3Strlen30(zFile);
 
142221 zAltEntry = sqlite3_malloc64(ncFile+30);
142222 if( zAltEntry==0 ){
142223 sqlite3OsDlClose(pVfs, handle);
142224 return SQLITE_NOMEM_BKPT;
142225 }
142226 memcpy(zAltEntry, "sqlite3_", 8);
142227 for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
142228 iFile++;
142229 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
142230 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
142231 if( sqlite3Isalpha(c) ){
142232 zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
142233 }
142234 }
142235 memcpy(zAltEntry+iEntry, "_init", 6);
142236 zEntry = zAltEntry;
142237 xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
 
 
142238 }
142239 if( xInit==0 ){
142240 if( pzErrMsg ){
142241 nMsg += strlen(zEntry) + 300;
142242 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
@@ -154969,10 +154955,34 @@
154969 memset(&sCtx, 0, sizeof(sCtx));
154970 sCtx.pSrc = pSelect->pSrc;
154971 sqlite3WalkExprNN(&w, pSelect->pWhere);
154972 pSelect->selFlags &= ~SF_OnToWhere;
154973 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154974
154975 /*
154976 ** Generate byte-code for the SELECT statement given in the p argument.
154977 **
154978 ** The results are returned according to the SelectDest structure.
@@ -155622,11 +155632,12 @@
155622 ** used for both the ORDER BY and DISTINCT processing. As originally
155623 ** written the query must use a temp-table for at least one of the ORDER
155624 ** BY and DISTINCT, and an index or separate temp-table for the other.
155625 */
155626 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
155627 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
 
155628 && OptimizationEnabled(db, SQLITE_GroupByOrder)
155629 #ifndef SQLITE_OMIT_WINDOWFUNC
155630 && p->pWin==0
155631 #endif
155632 ){
@@ -155836,25 +155847,14 @@
155836 ** in the correct order. It also may not - the GROUP BY might use a
155837 ** database index that causes rows to be grouped together as required
155838 ** but not actually sorted. Either way, record the fact that the
155839 ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
155840 ** variable. */
155841 if( sSort.pOrderBy && pGroupBy->nExpr==sSort.pOrderBy->nExpr ){
155842 int ii;
155843 /* The GROUP BY processing doesn't care whether rows are delivered in
155844 ** ASC or DESC order - only that each group is returned contiguously.
155845 ** So set the ASC/DESC flags in the GROUP BY to match those in the
155846 ** ORDER BY to maximize the chances of rows being delivered in an
155847 ** order that makes the ORDER BY redundant. */
155848 for(ii=0; ii<pGroupBy->nExpr; ii++){
155849 u8 sortFlags;
155850 sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
155851 pGroupBy->a[ii].fg.sortFlags = sortFlags;
155852 }
155853 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
155854 orderByGrp = 1;
155855 }
155856 }
155857 }else{
155858 assert( 0==sqlite3LogEst(1) );
155859 p->nSelectRow = 0;
155860 }
@@ -156849,15 +156849,20 @@
156849 }
156850 goto trigger_cleanup;
156851 }
156852 }
156853
 
 
 
 
156854 /* Do not create a trigger on a system table */
156855 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
156856 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
156857 goto trigger_cleanup;
156858 }
 
156859
156860 /* INSTEAD of triggers are only for views and views only support INSTEAD
156861 ** of triggers.
156862 */
156863 if( IsView(pTab) && tr_tm!=TK_INSTEAD ){
@@ -168744,15 +168749,18 @@
168744
168745 /* No matches cause a break out of the loop */
168746 break;
168747 }
168748 if( i==n ){
 
168749 nOrderBy = n;
168750 if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) && !pSrc->fg.rowidUsed ){
168751 eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
168752 }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){
168753 eDistinct = 1;
 
 
168754 }
168755 }
168756 }
168757
168758 /* Allocate the sqlite3_index_info structure
@@ -172330,13 +172338,11 @@
172330 if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
172331 }else{
172332 pLoop = pLast;
172333 }
172334 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
172335 if( pLoop->u.vtab.isOrdered
172336 && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
172337 ){
172338 obSat = obDone;
172339 }else{
172340 /* No further ORDER BY terms may be matched. So this call should
172341 ** return >=0, not -1. Clear isOrderDistinct to ensure it does so. */
172342 isOrderDistinct = 0;
@@ -261097,11 +261103,11 @@
261097 int nArg, /* Number of args */
261098 sqlite3_value **apUnused /* Function arguments */
261099 ){
261100 assert( nArg==0 );
261101 UNUSED_PARAM2(nArg, apUnused);
261102 sqlite3_result_text(pCtx, "fts5: 2025-12-11 18:16:39 e785a80e4100c368dca8d73cb662cff4d0fd76734fa0f3fa9b5754a380f7c746", -1, SQLITE_TRANSIENT);
261103 }
261104
261105 /*
261106 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261107 **
261108
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** eb2c020481dd591f459cf7191d18c2499aee with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -7746,22 +7746,22 @@
7746 ** ^This interface loads an SQLite extension library from the named file.
7747 **
7748 ** ^The sqlite3_load_extension() interface attempts to load an
7749 ** [SQLite extension] library contained in the file zFile. If
7750 ** the file cannot be loaded directly, attempts are made to load
7751 ** with various operating-system specific filename extensions added.
7752 ** So for example, if "samplelib" cannot be loaded, then names like
7753 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
7754 ** be tried also.
7755 **
7756 ** ^The entry point is zProc.
7757 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7758 ** entry point name on its own. It first tries "sqlite3_extension_init".
7759 ** If that does not work, it tries names of the form "sqlite3_X_init"
7760 ** where X consists of the lower-case equivalent of all ASCII alphabetic
7761 ** characters or all ASCII alphanumeric characters in the filename from
7762 ** the last "/" to the first following "." and omitting any initial "lib".)^
7763 ** ^The sqlite3_load_extension() interface returns
7764 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7765 ** ^If an error occurs and pzErrMsg is not 0, then the
7766 ** [sqlite3_load_extension()] interface shall attempt to
7767 ** fill *pzErrMsg with error message text stored in memory
@@ -48881,78 +48881,54 @@
48881 { "WriteFile", (SYSCALL)WriteFile, 0 },
48882
48883 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
48884 LPOVERLAPPED))aSyscall[61].pCurrent)
48885
 
 
 
 
 
48886 /*
48887 ** For WaitForSingleObject(), MSDN says:
48888 **
48889 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
48890 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
48891 */
48892 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
48893
48894 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
48895 DWORD))aSyscall[62].pCurrent)
48896
48897 #if !SQLITE_OS_WINCE
48898 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
48899 #else
48900 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
48901 #endif
48902
48903 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
48904 BOOL))aSyscall[63].pCurrent)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48905
48906 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
48907
48908 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
48909 LPSYSTEM_INFO))aSyscall[64].pCurrent)
48910
48911 #if defined(SQLITE_WIN32_HAS_ANSI)
48912 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
48913 #else
48914 { "OutputDebugStringA", (SYSCALL)0, 0 },
48915 #endif
48916
48917 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[65].pCurrent)
48918
48919 #if defined(SQLITE_WIN32_HAS_WIDE)
48920 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
48921 #else
48922 { "OutputDebugStringW", (SYSCALL)0, 0 },
48923 #endif
48924
48925 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[66].pCurrent)
48926
48927 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
48928
48929 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[67].pCurrent)
48930
48931 /*
48932 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
48933 ** is really just a macro that uses a compiler intrinsic (e.g. x64).
48934 ** So do not try to make this is into a redefinable interface.
@@ -48963,38 +48939,38 @@
48939 #define osInterlockedCompareExchange InterlockedCompareExchange
48940 #else
48941 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
48942
48943 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
48944 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[68].pCurrent)
48945 #endif /* defined(InterlockedCompareExchange) */
48946
48947 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
48948 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
48949 #else
48950 { "UuidCreate", (SYSCALL)0, 0 },
48951 #endif
48952
48953 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[69].pCurrent)
48954
48955 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
48956 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
48957 #else
48958 { "UuidCreateSequential", (SYSCALL)0, 0 },
48959 #endif
48960
48961 #define osUuidCreateSequential \
48962 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[70].pCurrent)
48963
48964 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
48965 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
48966 #else
48967 { "FlushViewOfFile", (SYSCALL)0, 0 },
48968 #endif
48969
48970 #define osFlushViewOfFile \
48971 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[71].pCurrent)
48972
48973 /*
48974 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
48975 ** to implement blocking locks with timeouts. MSDN says:
48976 **
@@ -49007,11 +48983,11 @@
48983 { "CreateEvent", (SYSCALL)0, 0 },
48984 #endif
48985
48986 #define osCreateEvent ( \
48987 (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
48988 aSyscall[72].pCurrent \
48989 )
48990
48991 /*
48992 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
48993 ** for the case where a timeout expires and a lock request must be
@@ -49024,68 +49000,68 @@
49000 { "CancelIo", (SYSCALL)CancelIo, 0 },
49001 #else
49002 { "CancelIo", (SYSCALL)0, 0 },
49003 #endif
49004
49005 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[73].pCurrent)
49006
49007 #if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
49008 { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
49009 #else
49010 { "GetModuleHandleW", (SYSCALL)0, 0 },
49011 #endif
49012
49013 #define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[74].pCurrent)
49014
49015 #ifndef _WIN32
49016 { "getenv", (SYSCALL)getenv, 0 },
49017 #else
49018 { "getenv", (SYSCALL)0, 0 },
49019 #endif
49020
49021 #define osGetenv ((const char *(*)(const char *))aSyscall[75].pCurrent)
49022
49023 #ifndef _WIN32
49024 { "getcwd", (SYSCALL)getcwd, 0 },
49025 #else
49026 { "getcwd", (SYSCALL)0, 0 },
49027 #endif
49028
49029 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[76].pCurrent)
49030
49031 #ifndef _WIN32
49032 { "readlink", (SYSCALL)readlink, 0 },
49033 #else
49034 { "readlink", (SYSCALL)0, 0 },
49035 #endif
49036
49037 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[77].pCurrent)
49038
49039 #ifndef _WIN32
49040 { "lstat", (SYSCALL)lstat, 0 },
49041 #else
49042 { "lstat", (SYSCALL)0, 0 },
49043 #endif
49044
49045 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[78].pCurrent)
49046
49047 #ifndef _WIN32
49048 { "__errno", (SYSCALL)__errno, 0 },
49049 #else
49050 { "__errno", (SYSCALL)0, 0 },
49051 #endif
49052
49053 #define osErrno (*((int*(*)(void))aSyscall[79].pCurrent)())
49054
49055 #ifndef _WIN32
49056 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
49057 #else
49058 { "cygwin_conv_path", (SYSCALL)0, 0 },
49059 #endif
49060
49061 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49062 const void *, void *, size_t))aSyscall[80].pCurrent)
49063
49064 }; /* End of the overrideable system calls */
49065
49066 /*
49067 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -54399,11 +54375,16 @@
54375 };
54376 #endif
54377
54378 /* Double-check that the aSyscall[] array has been constructed
54379 ** correctly. See ticket [bb3a86e890c8e96ab] */
54380 assert( ArraySize(aSyscall)==81 );
54381 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54382 assert( strcmp(aSyscall[20].zName,"GetFileAttributesA")==0 );
54383 assert( strcmp(aSyscall[40].zName,"HeapReAlloc")==0 );
54384 assert( strcmp(aSyscall[60].zName,"WideCharToMultiByte")==0 );
54385 assert( strcmp(aSyscall[80].zName,"cygwin_conv_path")==0 );
54386
54387 /* get memory map allocation granularity */
54388 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
54389 osGetSystemInfo(&winSysInfo);
54390 assert( winSysInfo.dwAllocationGranularity>0 );
@@ -110988,14 +110969,10 @@
110969 }
110970 }
110971 }
110972 #endif
110973
 
 
 
 
110974 sNC.ncFlags |= NC_AllowAgg|NC_AllowWin;
110975
110976 /* If this is a converted compound query, move the ORDER BY clause from
110977 ** the sub-query back to the parent query. At this point each term
110978 ** within the ORDER BY clause has been transformed to an integer value.
@@ -142206,37 +142183,46 @@
142183
142184 /* If no entry point was specified and the default legacy
142185 ** entry point name "sqlite3_extension_init" was not found, then
142186 ** construct an entry point name "sqlite3_X_init" where the X is
142187 ** replaced by the lowercase value of every ASCII alphabetic
142188 ** character in the filename after the last "/" up to the first ".",
142189 ** and skipping the first three characters if they are "lib".
142190 ** Examples:
142191 **
142192 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
142193 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
142194 **
142195 ** If that still finds no entry point, repeat a second time but this
142196 ** time include both alphabetic and numeric characters up to the first
142197 ** ".". Example:
142198 **
142199 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example5_init
142200 */
142201 if( xInit==0 && zProc==0 ){
142202 int iFile, iEntry, c;
142203 int ncFile = sqlite3Strlen30(zFile);
142204 int cnt = 0;
142205 zAltEntry = sqlite3_malloc64(ncFile+30);
142206 if( zAltEntry==0 ){
142207 sqlite3OsDlClose(pVfs, handle);
142208 return SQLITE_NOMEM_BKPT;
142209 }
142210 do{
142211 memcpy(zAltEntry, "sqlite3_", 8);
142212 for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
142213 iFile++;
142214 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
142215 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
142216 if( sqlite3Isalpha(c) || (cnt && sqlite3Isdigit(c)) ){
142217 zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
142218 }
142219 }
142220 memcpy(zAltEntry+iEntry, "_init", 6);
142221 zEntry = zAltEntry;
142222 xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
142223 }while( xInit==0 && (++cnt)<2 );
142224 }
142225 if( xInit==0 ){
142226 if( pzErrMsg ){
142227 nMsg += strlen(zEntry) + 300;
142228 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
@@ -154969,10 +154955,34 @@
154955 memset(&sCtx, 0, sizeof(sCtx));
154956 sCtx.pSrc = pSelect->pSrc;
154957 sqlite3WalkExprNN(&w, pSelect->pWhere);
154958 pSelect->selFlags &= ~SF_OnToWhere;
154959 }
154960
154961 /*
154962 ** If p2 exists and p1 and p2 have the same number of terms, then change
154963 ** every term of p1 to have the same sort order as p2 and return true.
154964 **
154965 ** If p2 is NULL or p1 and p2 are different lengths, then make no changes
154966 ** and return false.
154967 **
154968 ** p1 must be non-NULL.
154969 */
154970 static int sqlite3CopySortOrder(ExprList *p1, ExprList *p2){
154971 assert( p1 );
154972 if( p2 && p1->nExpr==p2->nExpr ){
154973 int ii;
154974 for(ii=0; ii<p1->nExpr; ii++){
154975 u8 sortFlags;
154976 sortFlags = p2->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
154977 p1->a[ii].fg.sortFlags = sortFlags;
154978 }
154979 return 1;
154980 }else{
154981 return 0;
154982 }
154983 }
154984
154985 /*
154986 ** Generate byte-code for the SELECT statement given in the p argument.
154987 **
154988 ** The results are returned according to the SelectDest structure.
@@ -155622,11 +155632,12 @@
155632 ** used for both the ORDER BY and DISTINCT processing. As originally
155633 ** written the query must use a temp-table for at least one of the ORDER
155634 ** BY and DISTINCT, and an index or separate temp-table for the other.
155635 */
155636 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
155637 && sqlite3CopySortOrder(pEList, sSort.pOrderBy)
155638 && sqlite3ExprListCompare(pEList, sSort.pOrderBy, -1)==0
155639 && OptimizationEnabled(db, SQLITE_GroupByOrder)
155640 #ifndef SQLITE_OMIT_WINDOWFUNC
155641 && p->pWin==0
155642 #endif
155643 ){
@@ -155836,25 +155847,14 @@
155847 ** in the correct order. It also may not - the GROUP BY might use a
155848 ** database index that causes rows to be grouped together as required
155849 ** but not actually sorted. Either way, record the fact that the
155850 ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
155851 ** variable. */
155852 if( sqlite3CopySortOrder(pGroupBy, sSort.pOrderBy)
155853 && sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0
155854 ){
155855 orderByGrp = 1;
 
 
 
 
 
 
 
 
 
 
 
155856 }
155857 }else{
155858 assert( 0==sqlite3LogEst(1) );
155859 p->nSelectRow = 0;
155860 }
@@ -156849,15 +156849,20 @@
156849 }
156850 goto trigger_cleanup;
156851 }
156852 }
156853
156854 /* NB: The SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES compile-time option is
156855 ** experimental and unsupported. Do not use it unless understand the
156856 ** implications and you cannot get by without this capability. */
156857 #if !defined(SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES) /* Experimental */
156858 /* Do not create a trigger on a system table */
156859 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
156860 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
156861 goto trigger_cleanup;
156862 }
156863 #endif
156864
156865 /* INSTEAD of triggers are only for views and views only support INSTEAD
156866 ** of triggers.
156867 */
156868 if( IsView(pTab) && tr_tm!=TK_INSTEAD ){
@@ -168744,15 +168749,18 @@
168749
168750 /* No matches cause a break out of the loop */
168751 break;
168752 }
168753 if( i==n ){
168754 int bSortByGroup = (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0;
168755 nOrderBy = n;
168756 if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) && !pSrc->fg.rowidUsed ){
168757 eDistinct = 2 + bSortByGroup;
168758 }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){
168759 eDistinct = 1 - bSortByGroup;
168760 }else if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
168761 eDistinct = 3;
168762 }
168763 }
168764 }
168765
168766 /* Allocate the sqlite3_index_info structure
@@ -172330,13 +172338,11 @@
172338 if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
172339 }else{
172340 pLoop = pLast;
172341 }
172342 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
172343 if( pLoop->u.vtab.isOrdered && pWInfo->pOrderBy==pOrderBy ){
 
 
172344 obSat = obDone;
172345 }else{
172346 /* No further ORDER BY terms may be matched. So this call should
172347 ** return >=0, not -1. Clear isOrderDistinct to ensure it does so. */
172348 isOrderDistinct = 0;
@@ -261097,11 +261103,11 @@
261103 int nArg, /* Number of args */
261104 sqlite3_value **apUnused /* Function arguments */
261105 ){
261106 assert( nArg==0 );
261107 UNUSED_PARAM2(nArg, apUnused);
261108 sqlite3_result_text(pCtx, "fts5: 2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8", -1, SQLITE_TRANSIENT);
261109 }
261110
261111 /*
261112 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261113 **
261114
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.52.0"
150150
#define SQLITE_VERSION_NUMBER 3052000
151
-#define SQLITE_SOURCE_ID "2025-12-11 23:24:05 01409738afc2c0d5bdaa248ffb508aa5f36a66390f6b8e4834734529ee8ed2fa"
151
+#define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2025-12-11T23:24:05.667Z"
154
+#define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -7425,22 +7425,22 @@
74257425
** ^This interface loads an SQLite extension library from the named file.
74267426
**
74277427
** ^The sqlite3_load_extension() interface attempts to load an
74287428
** [SQLite extension] library contained in the file zFile. If
74297429
** the file cannot be loaded directly, attempts are made to load
7430
-** with various operating-system specific extensions added.
7430
+** with various operating-system specific filename extensions added.
74317431
** So for example, if "samplelib" cannot be loaded, then names like
74327432
** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
74337433
** be tried also.
74347434
**
74357435
** ^The entry point is zProc.
74367436
** ^(zProc may be 0, in which case SQLite will try to come up with an
74377437
** entry point name on its own. It first tries "sqlite3_extension_init".
7438
-** If that does not work, it constructs a name "sqlite3_X_init" where
7439
-** X consists of the lower-case equivalent of all ASCII alphabetic
7440
-** characters in the filename from the last "/" to the first following
7441
-** "." and omitting any initial "lib".)^
7438
+** If that does not work, it tries names of the form "sqlite3_X_init"
7439
+** where X consists of the lower-case equivalent of all ASCII alphabetic
7440
+** characters or all ASCII alphanumeric characters in the filename from
7441
+** the last "/" to the first following "." and omitting any initial "lib".)^
74427442
** ^The sqlite3_load_extension() interface returns
74437443
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
74447444
** ^If an error occurs and pzErrMsg is not 0, then the
74457445
** [sqlite3_load_extension()] interface shall attempt to
74467446
** fill *pzErrMsg with error message text stored in memory
74477447
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2025-12-11 23:24:05 01409738afc2c0d5bdaa248ffb508aa5f36a66390f6b8e4834734529ee8ed2fa"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-12-11T23:24:05.667Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -7425,22 +7425,22 @@
7425 ** ^This interface loads an SQLite extension library from the named file.
7426 **
7427 ** ^The sqlite3_load_extension() interface attempts to load an
7428 ** [SQLite extension] library contained in the file zFile. If
7429 ** the file cannot be loaded directly, attempts are made to load
7430 ** with various operating-system specific extensions added.
7431 ** So for example, if "samplelib" cannot be loaded, then names like
7432 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
7433 ** be tried also.
7434 **
7435 ** ^The entry point is zProc.
7436 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7437 ** entry point name on its own. It first tries "sqlite3_extension_init".
7438 ** If that does not work, it constructs a name "sqlite3_X_init" where
7439 ** X consists of the lower-case equivalent of all ASCII alphabetic
7440 ** characters in the filename from the last "/" to the first following
7441 ** "." and omitting any initial "lib".)^
7442 ** ^The sqlite3_load_extension() interface returns
7443 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7444 ** ^If an error occurs and pzErrMsg is not 0, then the
7445 ** [sqlite3_load_extension()] interface shall attempt to
7446 ** fill *pzErrMsg with error message text stored in memory
7447
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -7425,22 +7425,22 @@
7425 ** ^This interface loads an SQLite extension library from the named file.
7426 **
7427 ** ^The sqlite3_load_extension() interface attempts to load an
7428 ** [SQLite extension] library contained in the file zFile. If
7429 ** the file cannot be loaded directly, attempts are made to load
7430 ** with various operating-system specific filename extensions added.
7431 ** So for example, if "samplelib" cannot be loaded, then names like
7432 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
7433 ** be tried also.
7434 **
7435 ** ^The entry point is zProc.
7436 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7437 ** entry point name on its own. It first tries "sqlite3_extension_init".
7438 ** If that does not work, it tries names of the form "sqlite3_X_init"
7439 ** where X consists of the lower-case equivalent of all ASCII alphabetic
7440 ** characters or all ASCII alphanumeric characters in the filename from
7441 ** the last "/" to the first following "." and omitting any initial "lib".)^
7442 ** ^The sqlite3_load_extension() interface returns
7443 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7444 ** ^If an error occurs and pzErrMsg is not 0, then the
7445 ** [sqlite3_load_extension()] interface shall attempt to
7446 ** fill *pzErrMsg with error message text stored in memory
7447

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button