Fossil SCM

Update the built-in SQLite to the latest 3.47.0 beta for testing.

drh 2024-10-12 11:10 trunk
Commit 753bf7d57a679e8ff5db5ddcc30fca74d4c8fea96fd37d3761edcd2e9bc123f6
3 files changed +200 -119 +108 -108 +1 -1
+200 -119
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -343,31 +343,25 @@
343343
#include <stdarg.h>
344344
#include <io.h>
345345
#include <fcntl.h>
346346
347347
/*
348
-** If the SQLITE_U8TEXT_ONLY option is defined, then only use
349
-** _O_U8TEXT, _O_WTEXT, and similar together with the UTF-16
350
-** interfaces to the Windows CRT. The use of ANSI-only routines
351
-** like fputs() and ANSI modes like _O_TEXT and _O_BINARY is
352
-** avoided.
353
-**
354
-** The downside of using SQLITE_U8TEXT_ONLY is that it becomes
355
-** impossible to output a bare newline character (0x0a) - that is,
356
-** a newline that is not preceded by a carriage return (0x0d).
357
-** And without that capability, sometimes the output will be slightly
358
-** incorrect, as extra 0x0d characters will have been inserted where
359
-** they do not belong.
360
-**
361
-** The SQLITE_U8TEXT_STDIO compile-time option is a compromise.
362
-** It always enables _O_WTEXT or similar for stdin, stdout, stderr,
363
-** but allows other streams to be _O_TEXT and/or O_BINARY. The
364
-** SQLITE_U8TEXT_STDIO option has the same downside as SQLITE_U8TEXT_ONLY
365
-** in that stray 0x0d characters might appear where they ought not, but
366
-** at least with this option those characters only appear on standard
367
-** I/O streams, and not on new streams that might be created by the
368
-** application using sqlite3_fopen() or sqlite3_popen().
348
+** If the SQLITE_U8TEXT_ONLY option is defined, then use O_U8TEXT
349
+** when appropriate on all output. (Sometimes use O_BINARY when
350
+** rendering ASCII text in cases where NL-to-CRLF expansion would
351
+** not be correct.)
352
+**
353
+** If the SQLITE_U8TEXT_STDIO option is defined, then use O_U8TEXT
354
+** when appropriate when writing to stdout or stderr. Use O_BINARY
355
+** or O_TEXT (depending on things like the .mode and the .crnl setting
356
+** in the CLI, or other context clues in other applications) for all
357
+** other output channels.
358
+**
359
+** The default behavior, if neither of the above is defined is to
360
+** use O_U8TEXT when writing to the Windows console (or anything
361
+** else for which _isatty() returns true) and to use O_BINARY or O_TEXT
362
+** for all other output channels.
369363
*/
370364
#if defined(SQLITE_U8TEXT_ONLY)
371365
# define UseWtextForOutput(fd) 1
372366
# define UseWtextForInput(fd) 1
373367
# define IsConsole(fd) _isatty(_fileno(fd))
@@ -378,10 +372,35 @@
378372
#else
379373
# define UseWtextForOutput(fd) _isatty(_fileno(fd))
380374
# define UseWtextForInput(fd) _isatty(_fileno(fd))
381375
# define IsConsole(fd) 1
382376
#endif
377
+
378
+/*
379
+** Global variables determine if simulated O_BINARY mode is to be
380
+** used for stdout or other, respectively. Simulated O_BINARY mode
381
+** means the mode is usually O_BINARY, but switches to O_U8TEXT for
382
+** unicode characters U+0080 or greater (any character that has a
383
+** multi-byte representation in UTF-8). This is the only way we
384
+** have found to render Unicode characters on a Windows console while
385
+** at the same time avoiding undesirable \n to \r\n translation.
386
+*/
387
+static int simBinaryStdout = 0;
388
+static int simBinaryOther = 0;
389
+
390
+
391
+/*
392
+** Determine if simulated binary mode should be used for output to fd
393
+*/
394
+static int UseBinaryWText(FILE *fd){
395
+ if( fd==stdout || fd==stderr ){
396
+ return simBinaryStdout;
397
+ }else{
398
+ return simBinaryOther;
399
+ }
400
+}
401
+
383402
384403
/*
385404
** Work-alike for the fopen() routine from the standard C library.
386405
*/
387406
FILE *sqlite3_fopen(const char *zFilename, const char *zMode){
@@ -400,10 +419,11 @@
400419
b2[sz2] = 0;
401420
fp = _wfopen(b1, b2);
402421
}
403422
free(b1);
404423
free(b2);
424
+ simBinaryOther = 0;
405425
return fp;
406426
}
407427
408428
409429
/*
@@ -454,32 +474,72 @@
454474
/* Reading from a file or other input source, just read bytes without
455475
** any translation. */
456476
return fgets(buf, sz, in);
457477
}
458478
}
479
+
480
+/*
481
+** Send ASCII text as O_BINARY. But for Unicode characters U+0080 and
482
+** greater, switch to O_U8TEXT.
483
+*/
484
+static void piecemealOutput(wchar_t *b1, int sz, FILE *out){
485
+ int i;
486
+ wchar_t c;
487
+ while( sz>0 ){
488
+ for(i=0; i<sz && b1[i]>=0x80; i++){}
489
+ if( i>0 ){
490
+ c = b1[i];
491
+ b1[i] = 0;
492
+ fflush(out);
493
+ _setmode(_fileno(out), _O_U8TEXT);
494
+ fputws(b1, out);
495
+ fflush(out);
496
+ b1 += i;
497
+ b1[0] = c;
498
+ sz -= i;
499
+ }else{
500
+ fflush(out);
501
+ _setmode(_fileno(out), _O_TEXT);
502
+ _setmode(_fileno(out), _O_BINARY);
503
+ fwrite(&b1[0], 1, 1, out);
504
+ for(i=1; i<sz && b1[i]<0x80; i++){
505
+ fwrite(&b1[i], 1, 1, out);
506
+ }
507
+ fflush(out);
508
+ _setmode(_fileno(out), _O_U8TEXT);
509
+ b1 += i;
510
+ sz -= i;
511
+ }
512
+ }
513
+}
459514
460515
/*
461516
** Work-alike for fputs() from the standard C library.
462517
*/
463518
int sqlite3_fputs(const char *z, FILE *out){
464
- if( UseWtextForOutput(out) ){
519
+ if( !UseWtextForOutput(out) ){
520
+ /* Writing to a file or other destination, just write bytes without
521
+ ** any translation. */
522
+ return fputs(z, out);
523
+ }else{
465524
/* When writing to the command-prompt in Windows, it is necessary
466
- ** to use _O_WTEXT input mode and write UTF-16 characters.
525
+ ** to use O_U8TEXT to render Unicode U+0080 and greater. Go ahead
526
+ ** use O_U8TEXT for everything in text mode.
467527
*/
468528
int sz = (int)strlen(z);
469529
wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) );
470530
if( b1==0 ) return 0;
471531
sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
472532
b1[sz] = 0;
473533
_setmode(_fileno(out), _O_U8TEXT);
474
- fputws(b1, out);
534
+ if( UseBinaryWText(out) ){
535
+ piecemealOutput(b1, sz, out);
536
+ }else{
537
+ fputws(b1, out);
538
+ }
475539
sqlite3_free(b1);
476540
return 0;
477
- }else{
478
- /* Writing to a file or other destination, just write bytes without
479
- ** any translation. */
480
- return fputs(z, out);
481541
}
482542
}
483543
484544
485545
/*
@@ -517,10 +577,14 @@
517577
*/
518578
void sqlite3_fsetmode(FILE *fp, int mode){
519579
if( !UseWtextForOutput(fp) ){
520580
fflush(fp);
521581
_setmode(_fileno(fp), mode);
582
+ }else if( fp==stdout || fp==stderr ){
583
+ simBinaryStdout = (mode==_O_BINARY);
584
+ }else{
585
+ simBinaryOther = (mode==_O_BINARY);
522586
}
523587
}
524588
525589
#endif /* defined(_WIN32) */
526590
@@ -6766,50 +6830,52 @@
67666830
aIdx[4] = i;
67676831
idxNum |= 0x40;
67686832
}
67696833
continue;
67706834
}
6771
- if( pConstraint->iColumn==SERIES_COLUMN_VALUE ){
6772
- switch( op ){
6773
- case SQLITE_INDEX_CONSTRAINT_EQ:
6774
- case SQLITE_INDEX_CONSTRAINT_IS: {
6775
- idxNum |= 0x0080;
6776
- idxNum &= ~0x3300;
6777
- aIdx[5] = i;
6778
- aIdx[6] = -1;
6779
- bStartSeen = 1;
6780
- break;
6781
- }
6782
- case SQLITE_INDEX_CONSTRAINT_GE: {
6783
- if( idxNum & 0x0080 ) break;
6784
- idxNum |= 0x0100;
6785
- idxNum &= ~0x0200;
6786
- aIdx[5] = i;
6787
- bStartSeen = 1;
6788
- break;
6789
- }
6790
- case SQLITE_INDEX_CONSTRAINT_GT: {
6791
- if( idxNum & 0x0080 ) break;
6792
- idxNum |= 0x0200;
6793
- idxNum &= ~0x0100;
6794
- aIdx[5] = i;
6795
- bStartSeen = 1;
6796
- break;
6797
- }
6798
- case SQLITE_INDEX_CONSTRAINT_LE: {
6799
- if( idxNum & 0x0080 ) break;
6800
- idxNum |= 0x1000;
6801
- idxNum &= ~0x2000;
6802
- aIdx[6] = i;
6803
- break;
6804
- }
6805
- case SQLITE_INDEX_CONSTRAINT_LT: {
6806
- if( idxNum & 0x0080 ) break;
6807
- idxNum |= 0x2000;
6808
- idxNum &= ~0x1000;
6809
- aIdx[6] = i;
6810
- break;
6835
+ if( pConstraint->iColumn<SERIES_COLUMN_START ){
6836
+ if( pConstraint->iColumn==SERIES_COLUMN_VALUE ){
6837
+ switch( op ){
6838
+ case SQLITE_INDEX_CONSTRAINT_EQ:
6839
+ case SQLITE_INDEX_CONSTRAINT_IS: {
6840
+ idxNum |= 0x0080;
6841
+ idxNum &= ~0x3300;
6842
+ aIdx[5] = i;
6843
+ aIdx[6] = -1;
6844
+ bStartSeen = 1;
6845
+ break;
6846
+ }
6847
+ case SQLITE_INDEX_CONSTRAINT_GE: {
6848
+ if( idxNum & 0x0080 ) break;
6849
+ idxNum |= 0x0100;
6850
+ idxNum &= ~0x0200;
6851
+ aIdx[5] = i;
6852
+ bStartSeen = 1;
6853
+ break;
6854
+ }
6855
+ case SQLITE_INDEX_CONSTRAINT_GT: {
6856
+ if( idxNum & 0x0080 ) break;
6857
+ idxNum |= 0x0200;
6858
+ idxNum &= ~0x0100;
6859
+ aIdx[5] = i;
6860
+ bStartSeen = 1;
6861
+ break;
6862
+ }
6863
+ case SQLITE_INDEX_CONSTRAINT_LE: {
6864
+ if( idxNum & 0x0080 ) break;
6865
+ idxNum |= 0x1000;
6866
+ idxNum &= ~0x2000;
6867
+ aIdx[6] = i;
6868
+ break;
6869
+ }
6870
+ case SQLITE_INDEX_CONSTRAINT_LT: {
6871
+ if( idxNum & 0x0080 ) break;
6872
+ idxNum |= 0x2000;
6873
+ idxNum &= ~0x1000;
6874
+ aIdx[6] = i;
6875
+ break;
6876
+ }
68116877
}
68126878
}
68136879
continue;
68146880
}
68156881
iCol = pConstraint->iColumn - SERIES_COLUMN_START;
@@ -21202,10 +21268,11 @@
2120221268
u8 nEqpLevel; /* Depth of the EQP output graph */
2120321269
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
2120421270
u8 bSafeMode; /* True to prohibit unsafe operations */
2120521271
u8 bSafeModePersist; /* The long-term value of bSafeMode */
2120621272
u8 eRestoreState; /* See comments above doAutoDetectRestore() */
21273
+ u8 crnlMode; /* Do NL-to-CRLF translations when enabled (maybe) */
2120721274
ColModeOpts cmOpts; /* Option values affecting columnar mode output */
2120821275
unsigned statsOn; /* True to display memory stats before each finalize */
2120921276
unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
2121021277
int inputNesting; /* Track nesting level of .read and other redirects */
2121121278
int outCount; /* Revert to stdout when reaching zero */
@@ -21382,17 +21449,11 @@
2138221449
#define SEP_Column "|"
2138321450
#define SEP_Row "\n"
2138421451
#define SEP_Tab "\t"
2138521452
#define SEP_Space " "
2138621453
#define SEP_Comma ","
21387
-#ifdef SQLITE_U8TEXT_ONLY
21388
- /* With the SQLITE_U8TEXT_ONLY option, the output will always be in
21389
- ** text mode. The \r will be inserted automatically. */
21390
-# define SEP_CrLf "\n"
21391
-#else
21392
-# define SEP_CrLf "\r\n"
21393
-#endif
21454
+#define SEP_CrLf "\n" /* Use ".crnl on" to get \r\n line endings */
2139421455
#define SEP_Unit "\x1F"
2139521456
#define SEP_Record "\x1E"
2139621457
2139721458
/*
2139821459
** Limit input nesting via .read or any other input redirect.
@@ -21604,10 +21665,23 @@
2160421665
p->mode = p->modePrior;
2160521666
p->shellFlgs = p->priorShFlgs;
2160621667
memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
2160721668
memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
2160821669
}
21670
+
21671
+/*
21672
+** Set output mode to text or binary for Windows.
21673
+*/
21674
+static void setCrnlMode(ShellState *p){
21675
+#ifdef _WIN32
21676
+ if( p->crnlMode ){
21677
+ sqlite3_fsetmode(p->out, _O_TEXT);
21678
+ }else{
21679
+ sqlite3_fsetmode(p->out, _O_BINARY);
21680
+ }
21681
+#endif
21682
+}
2160921683
2161021684
/*
2161121685
** Output the given string as a hex-encoded blob (eg. X'1234' )
2161221686
*/
2161321687
static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
@@ -21655,13 +21729,14 @@
2165521729
/*
2165621730
** Output the given string as a quoted string using SQL quoting conventions.
2165721731
**
2165821732
** See also: output_quoted_escaped_string()
2165921733
*/
21660
-static void output_quoted_string(FILE *out, const char *z){
21734
+static void output_quoted_string(ShellState *p, const char *z){
2166121735
int i;
2166221736
char c;
21737
+ FILE *out = p->out;
2166321738
sqlite3_fsetmode(out, _O_BINARY);
2166421739
if( z==0 ) return;
2166521740
for(i=0; (c = z[i])!=0 && c!='\''; i++){}
2166621741
if( c==0 ){
2166721742
sqlite3_fprintf(out, "'%s'",z);
@@ -21683,11 +21758,11 @@
2168321758
}
2168421759
z++;
2168521760
}
2168621761
sqlite3_fputs("'", out);
2168721762
}
21688
- sqlite3_fsetmode(out, _O_TEXT);
21763
+ setCrnlMode(p);
2168921764
}
2169021765
2169121766
/*
2169221767
** Output the given string as a quoted string using SQL quoting conventions.
2169321768
** Additionallly , escape the "\n" and "\r" characters so that they do not
@@ -21695,13 +21770,14 @@
2169521770
** systems.
2169621771
**
2169721772
** This is like output_quoted_string() but with the addition of the \r\n
2169821773
** escape mechanism.
2169921774
*/
21700
-static void output_quoted_escaped_string(FILE *out, const char *z){
21775
+static void output_quoted_escaped_string(ShellState *p, const char *z){
2170121776
int i;
2170221777
char c;
21778
+ FILE *out = p->out;
2170321779
sqlite3_fsetmode(out, _O_BINARY);
2170421780
for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
2170521781
if( c==0 ){
2170621782
sqlite3_fprintf(out, "'%s'",z);
2170721783
}else{
@@ -21750,11 +21826,11 @@
2175021826
}
2175121827
if( nNL ){
2175221828
sqlite3_fprintf(out, ",'%s',char(10))", zNL);
2175321829
}
2175421830
}
21755
- sqlite3_fsetmode(stdout, _O_TEXT);
21831
+ setCrnlMode(p);
2175621832
}
2175721833
2175821834
/*
2175921835
** Find earliest of chars within s specified in zAny.
2176021836
** With ns == ~0, is like strpbrk(s,zAny) and s must be 0-terminated.
@@ -22539,19 +22615,27 @@
2253922615
sqlite3_fsetmode(p->out, _O_BINARY);
2254022616
if( p->cnt++==0 && p->showHeader ){
2254122617
for(i=0; i<nArg; i++){
2254222618
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
2254322619
}
22544
- sqlite3_fputs(p->rowSeparator, p->out);
22620
+ if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){
22621
+ sqlite3_fputs("\r\n", p->out);
22622
+ }else{
22623
+ sqlite3_fputs(p->rowSeparator, p->out);
22624
+ }
2254522625
}
2254622626
if( nArg>0 ){
2254722627
for(i=0; i<nArg; i++){
2254822628
output_csv(p, azArg[i], i<nArg-1);
2254922629
}
22550
- sqlite3_fputs(p->rowSeparator, p->out);
22630
+ if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){
22631
+ sqlite3_fputs("\r\n", p->out);
22632
+ }else{
22633
+ sqlite3_fputs(p->rowSeparator, p->out);
22634
+ }
2255122635
}
22552
- sqlite3_fsetmode(p->out, _O_TEXT);
22636
+ setCrnlMode(p);
2255322637
break;
2255422638
}
2255522639
case MODE_Insert: {
2255622640
if( azArg==0 ) break;
2255722641
sqlite3_fprintf(p->out, "INSERT INTO %s",p->zDestTable);
@@ -22575,13 +22659,13 @@
2257522659
sqlite3_fputs(i>0 ? "," : " VALUES(", p->out);
2257622660
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2257722661
sqlite3_fputs("NULL", p->out);
2257822662
}else if( aiType && aiType[i]==SQLITE_TEXT ){
2257922663
if( ShellHasFlag(p, SHFLG_Newlines) ){
22580
- output_quoted_string(p->out, azArg[i]);
22664
+ output_quoted_string(p, azArg[i]);
2258122665
}else{
22582
- output_quoted_escaped_string(p->out, azArg[i]);
22666
+ output_quoted_escaped_string(p, azArg[i]);
2258322667
}
2258422668
}else if( aiType && aiType[i]==SQLITE_INTEGER ){
2258522669
sqlite3_fputs(azArg[i], p->out);
2258622670
}else if( aiType && aiType[i]==SQLITE_FLOAT ){
2258722671
char z[50];
@@ -22606,13 +22690,13 @@
2260622690
int nBlob = sqlite3_column_bytes(p->pStmt, i);
2260722691
output_hex_blob(p->out, pBlob, nBlob);
2260822692
}else if( isNumber(azArg[i], 0) ){
2260922693
sqlite3_fputs(azArg[i], p->out);
2261022694
}else if( ShellHasFlag(p, SHFLG_Newlines) ){
22611
- output_quoted_string(p->out, azArg[i]);
22695
+ output_quoted_string(p, azArg[i]);
2261222696
}else{
22613
- output_quoted_escaped_string(p->out, azArg[i]);
22697
+ output_quoted_escaped_string(p, azArg[i]);
2261422698
}
2261522699
}
2261622700
sqlite3_fputs(");\n", p->out);
2261722701
break;
2261822702
}
@@ -22661,21 +22745,21 @@
2266122745
case MODE_Quote: {
2266222746
if( azArg==0 ) break;
2266322747
if( p->cnt==0 && p->showHeader ){
2266422748
for(i=0; i<nArg; i++){
2266522749
if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
22666
- output_quoted_string(p->out, azCol[i]);
22750
+ output_quoted_string(p, azCol[i]);
2266722751
}
2266822752
sqlite3_fputs(p->rowSeparator, p->out);
2266922753
}
2267022754
p->cnt++;
2267122755
for(i=0; i<nArg; i++){
2267222756
if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
2267322757
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2267422758
sqlite3_fputs("NULL", p->out);
2267522759
}else if( aiType && aiType[i]==SQLITE_TEXT ){
22676
- output_quoted_string(p->out, azArg[i]);
22760
+ output_quoted_string(p, azArg[i]);
2267722761
}else if( aiType && aiType[i]==SQLITE_INTEGER ){
2267822762
sqlite3_fputs(azArg[i], p->out);
2267922763
}else if( aiType && aiType[i]==SQLITE_FLOAT ){
2268022764
char z[50];
2268122765
double r = sqlite3_column_double(p->pStmt, i);
@@ -22686,11 +22770,11 @@
2268622770
int nBlob = sqlite3_column_bytes(p->pStmt, i);
2268722771
output_hex_blob(p->out, pBlob, nBlob);
2268822772
}else if( isNumber(azArg[i], 0) ){
2268922773
sqlite3_fputs(azArg[i], p->out);
2269022774
}else{
22691
- output_quoted_string(p->out, azArg[i]);
22775
+ output_quoted_string(p, azArg[i]);
2269222776
}
2269322777
}
2269422778
sqlite3_fputs(p->rowSeparator, p->out);
2269522779
break;
2269622780
}
@@ -24690,14 +24774,11 @@
2469024774
#ifndef SQLITE_SHELL_FIDDLE
2469124775
".check GLOB Fail if output since .testcase does not match",
2469224776
".clone NEWDB Clone data into NEWDB from the existing database",
2469324777
#endif
2469424778
".connection [close] [#] Open or close an auxiliary database connection",
24695
-#if defined(_WIN32) && !defined(SQLITE_U8TEXT_ONLY) \
24696
- && !defined(SQLITE_U8TEXT_STDIO)
24697
- ".crnl on|off Translate \\n to \\r\\n. Default ON",
24698
-#endif /* _WIN32 && U8TEXT_ONLY && U8TEXT_STDIO */
24779
+ ".crnl on|off Translate \\n to \\r\\n sometimes. Default OFF",
2469924780
".databases List names and files of attached databases",
2470024781
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
2470124782
#if SQLITE_SHELL_HAVE_RECOVER
2470224783
".dbinfo ?DB? Show status information about the database",
2470324784
#endif
@@ -25692,20 +25773,20 @@
2569225773
/*
2569325774
** Try to open an output file. The names "stdout" and "stderr" are
2569425775
** recognized and do the right thing. NULL is returned if the output
2569525776
** filename is "off".
2569625777
*/
25697
-static FILE *output_file_open(const char *zFile, int bTextMode){
25778
+static FILE *output_file_open(const char *zFile){
2569825779
FILE *f;
2569925780
if( cli_strcmp(zFile,"stdout")==0 ){
2570025781
f = stdout;
2570125782
}else if( cli_strcmp(zFile, "stderr")==0 ){
2570225783
f = stderr;
2570325784
}else if( cli_strcmp(zFile, "off")==0 ){
2570425785
f = 0;
2570525786
}else{
25706
- f = sqlite3_fopen(zFile, bTextMode ? "w" : "wb");
25787
+ f = sqlite3_fopen(zFile, "w");
2570725788
if( f==0 ){
2570825789
sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile);
2570925790
}
2571025791
}
2571125792
return f;
@@ -26174,10 +26255,11 @@
2617426255
static void output_redir(ShellState *p, FILE *pfNew){
2617526256
if( p->out != stdout ){
2617626257
sqlite3_fputs("Output already redirected.\n", stderr);
2617726258
}else{
2617826259
p->out = pfNew;
26260
+ setCrnlMode(p);
2617926261
if( p->mode==MODE_Www ){
2618026262
sqlite3_fputs(
2618126263
"<!DOCTYPE html>\n"
2618226264
"<HTML><BODY><PRE>\n",
2618326265
p->out
@@ -26229,10 +26311,11 @@
2622926311
}
2623026312
#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
2623126313
}
2623226314
p->outfile[0] = 0;
2623326315
p->out = stdout;
26316
+ setCrnlMode(p);
2623426317
}
2623526318
#else
2623626319
# define output_redir(SS,pfO)
2623726320
# define output_reset(SS)
2623826321
#endif
@@ -28183,11 +28266,11 @@
2818328266
}
2818428267
}else
2818528268
2818628269
/* Undocumented. Legacy only. See "crnl" below */
2818728270
if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){
28188
- eputz("The \".binary\" command is deprecated. Use \".crnl\" instead.\n");
28271
+ eputz("The \".binary\" command is deprecated.\n");
2818928272
rc = 1;
2819028273
}else
2819128274
2819228275
/* The undocumented ".breakpoint" command causes a call to the no-op
2819328276
** routine named test_breakpoint().
@@ -28310,25 +28393,17 @@
2831028393
rc = 1;
2831128394
}
2831228395
}else
2831328396
2831428397
if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){
28315
-#if !defined(_WIN32) || defined(SQLITE_U8TEXT_ONLY) \
28316
- || defined(SQLITE_U8TEXT_STDIO)
28317
- sqlite3_fputs("The \".crnl\" command is disable in this build.\n", p->out);
28318
-#else
2831928398
if( nArg==2 ){
28320
- if( booleanValue(azArg[1]) ){
28321
- sqlite3_fsetmode(p->out, _O_TEXT);
28322
- }else{
28323
- sqlite3_fsetmode(p->out, _O_BINARY);
28324
- }
28325
- }else{
28326
- eputz("Usage: .crnl on|off\n");
28327
- rc = 1;
28328
- }
28329
-#endif
28399
+ p->crnlMode = booleanValue(azArg[1]);
28400
+ setCrnlMode(p);
28401
+ }else{
28402
+ sqlite3_fprintf(stderr, "crnl is currently %s\n",
28403
+ p->crnlMode ? "ON" : "OFF");
28404
+ }
2833028405
}else
2833128406
2833228407
if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){
2833328408
char **azName = 0;
2833428409
int nName = 0;
@@ -29404,11 +29479,11 @@
2940429479
" than \"on\" or \"off\"\n");
2940529480
zFile = "off";
2940629481
}
2940729482
output_file_close(p->pLog);
2940829483
if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout";
29409
- p->pLog = output_file_open(zFile, 0);
29484
+ p->pLog = output_file_open(zFile);
2941029485
}
2941129486
}else
2941229487
2941329488
if( c=='m' && cli_strncmp(azArg[0], "mode", n)==0 ){
2941429489
const char *zMode = 0;
@@ -29659,11 +29734,10 @@
2965929734
|| cli_strncmp(azArg[0], "once", n)==0))
2966029735
|| (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0)
2966129736
|| (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0)
2966229737
){
2966329738
char *zFile = 0;
29664
- int bTxtMode = 0;
2966529739
int i;
2966629740
int eMode = 0;
2966729741
int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
2966829742
int bPlain = 0; /* --plain option */
2966929743
static const char *zBomUtf8 = "\357\273\277";
@@ -29741,15 +29815,13 @@
2974129815
#endif
2974229816
}else if( eMode=='w' ){
2974329817
/* web-browser mode. */
2974429818
newTempFile(p, "html");
2974529819
if( !bPlain ) p->mode = MODE_Www;
29746
- bTxtMode = 1;
2974729820
}else{
2974829821
/* text editor mode */
2974929822
newTempFile(p, "txt");
29750
- bTxtMode = 1;
2975129823
}
2975229824
sqlite3_free(zFile);
2975329825
zFile = sqlite3_mprintf("%s", p->zTempFile);
2975429826
}
2975529827
#endif /* SQLITE_NOHAVE_SYSTEM */
@@ -29769,25 +29841,25 @@
2976929841
if( zBom ) sqlite3_fputs(zBom, pfPipe);
2977029842
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2977129843
}
2977229844
#endif
2977329845
}else{
29774
- FILE *pfFile = output_file_open(zFile, bTxtMode);
29846
+ FILE *pfFile = output_file_open(zFile);
2977529847
if( pfFile==0 ){
2977629848
if( cli_strcmp(zFile,"off")!=0 ){
2977729849
sqlite3_fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
2977829850
}
2977929851
rc = 1;
2978029852
} else {
2978129853
output_redir(p, pfFile);
29854
+ if( zBom ) sqlite3_fputs(zBom, pfFile);
2978229855
if( bPlain && eMode=='w' ){
2978329856
sqlite3_fputs(
2978429857
"<!DOCTYPE html>\n<BODY>\n<PLAINTEXT>\n",
2978529858
pfFile
2978629859
);
2978729860
}
29788
- if( zBom ) sqlite3_fputs(zBom, pfFile);
2978929861
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2979029862
}
2979129863
}
2979229864
sqlite3_free(zFile);
2979329865
}else
@@ -29980,11 +30052,10 @@
2998030052
}
2998130053
if( azArg[1][0]=='|' ){
2998230054
#ifdef SQLITE_OMIT_POPEN
2998330055
eputz("Error: pipes are not supported in this OS\n");
2998430056
rc = 1;
29985
- p->out = stdout;
2998630057
#else
2998730058
p->in = sqlite3_popen(azArg[1]+1, "r");
2998830059
if( p->in==0 ){
2998930060
sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
2999030061
rc = 1;
@@ -30967,11 +31038,11 @@
3096731038
3096831039
#ifndef SQLITE_SHELL_FIDDLE
3096931040
/* Begin redirecting output to the file "testcase-out.txt" */
3097031041
if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
3097131042
output_reset(p);
30972
- p->out = output_file_open("testcase-out.txt", 0);
31043
+ p->out = output_file_open("testcase-out.txt");
3097331044
if( p->out==0 ){
3097431045
eputz("Error: cannot open 'testcase-out.txt'\n");
3097531046
}
3097631047
if( nArg>=2 ){
3097731048
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -31471,11 +31542,11 @@
3147131542
rc = 1;
3147231543
goto meta_command_exit;
3147331544
}
3147431545
}else{
3147531546
output_file_close(p->traceOut);
31476
- p->traceOut = output_file_open(z, 0);
31547
+ p->traceOut = output_file_open(z);
3147731548
}
3147831549
}
3147931550
if( p->traceOut==0 ){
3148031551
sqlite3_trace_v2(p->db, 0, 0, 0);
3148131552
}else{
@@ -32361,10 +32432,20 @@
3236132432
#endif
3236232433
sqlite3_config(SQLITE_CONFIG_URI, 1);
3236332434
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
3236432435
sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
3236532436
sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
32437
+
32438
+ /* By default, come up in O_BINARY mode. That way, the default output is
32439
+ ** the same for Windows and non-Windows systems. Use the ".crnl on"
32440
+ ** command to change into O_TEXT mode to do automatic NL-to-CRLF
32441
+ ** conversions on output for Windows.
32442
+ **
32443
+ ** End-of-line marks on CVS output is CRLF when in .crnl is on and
32444
+ ** NL when .crnl is off.
32445
+ */
32446
+ data->crnlMode = 0;
3236632447
}
3236732448
3236832449
/*
3236932450
** Output text to the console in a font that attracts extra attention.
3237032451
*/
3237132452
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -343,31 +343,25 @@
343 #include <stdarg.h>
344 #include <io.h>
345 #include <fcntl.h>
346
347 /*
348 ** If the SQLITE_U8TEXT_ONLY option is defined, then only use
349 ** _O_U8TEXT, _O_WTEXT, and similar together with the UTF-16
350 ** interfaces to the Windows CRT. The use of ANSI-only routines
351 ** like fputs() and ANSI modes like _O_TEXT and _O_BINARY is
352 ** avoided.
353 **
354 ** The downside of using SQLITE_U8TEXT_ONLY is that it becomes
355 ** impossible to output a bare newline character (0x0a) - that is,
356 ** a newline that is not preceded by a carriage return (0x0d).
357 ** And without that capability, sometimes the output will be slightly
358 ** incorrect, as extra 0x0d characters will have been inserted where
359 ** they do not belong.
360 **
361 ** The SQLITE_U8TEXT_STDIO compile-time option is a compromise.
362 ** It always enables _O_WTEXT or similar for stdin, stdout, stderr,
363 ** but allows other streams to be _O_TEXT and/or O_BINARY. The
364 ** SQLITE_U8TEXT_STDIO option has the same downside as SQLITE_U8TEXT_ONLY
365 ** in that stray 0x0d characters might appear where they ought not, but
366 ** at least with this option those characters only appear on standard
367 ** I/O streams, and not on new streams that might be created by the
368 ** application using sqlite3_fopen() or sqlite3_popen().
369 */
370 #if defined(SQLITE_U8TEXT_ONLY)
371 # define UseWtextForOutput(fd) 1
372 # define UseWtextForInput(fd) 1
373 # define IsConsole(fd) _isatty(_fileno(fd))
@@ -378,10 +372,35 @@
378 #else
379 # define UseWtextForOutput(fd) _isatty(_fileno(fd))
380 # define UseWtextForInput(fd) _isatty(_fileno(fd))
381 # define IsConsole(fd) 1
382 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
384 /*
385 ** Work-alike for the fopen() routine from the standard C library.
386 */
387 FILE *sqlite3_fopen(const char *zFilename, const char *zMode){
@@ -400,10 +419,11 @@
400 b2[sz2] = 0;
401 fp = _wfopen(b1, b2);
402 }
403 free(b1);
404 free(b2);
 
405 return fp;
406 }
407
408
409 /*
@@ -454,32 +474,72 @@
454 /* Reading from a file or other input source, just read bytes without
455 ** any translation. */
456 return fgets(buf, sz, in);
457 }
458 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
460 /*
461 ** Work-alike for fputs() from the standard C library.
462 */
463 int sqlite3_fputs(const char *z, FILE *out){
464 if( UseWtextForOutput(out) ){
 
 
 
 
465 /* When writing to the command-prompt in Windows, it is necessary
466 ** to use _O_WTEXT input mode and write UTF-16 characters.
 
467 */
468 int sz = (int)strlen(z);
469 wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) );
470 if( b1==0 ) return 0;
471 sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
472 b1[sz] = 0;
473 _setmode(_fileno(out), _O_U8TEXT);
474 fputws(b1, out);
 
 
 
 
475 sqlite3_free(b1);
476 return 0;
477 }else{
478 /* Writing to a file or other destination, just write bytes without
479 ** any translation. */
480 return fputs(z, out);
481 }
482 }
483
484
485 /*
@@ -517,10 +577,14 @@
517 */
518 void sqlite3_fsetmode(FILE *fp, int mode){
519 if( !UseWtextForOutput(fp) ){
520 fflush(fp);
521 _setmode(_fileno(fp), mode);
 
 
 
 
522 }
523 }
524
525 #endif /* defined(_WIN32) */
526
@@ -6766,50 +6830,52 @@
6766 aIdx[4] = i;
6767 idxNum |= 0x40;
6768 }
6769 continue;
6770 }
6771 if( pConstraint->iColumn==SERIES_COLUMN_VALUE ){
6772 switch( op ){
6773 case SQLITE_INDEX_CONSTRAINT_EQ:
6774 case SQLITE_INDEX_CONSTRAINT_IS: {
6775 idxNum |= 0x0080;
6776 idxNum &= ~0x3300;
6777 aIdx[5] = i;
6778 aIdx[6] = -1;
6779 bStartSeen = 1;
6780 break;
6781 }
6782 case SQLITE_INDEX_CONSTRAINT_GE: {
6783 if( idxNum & 0x0080 ) break;
6784 idxNum |= 0x0100;
6785 idxNum &= ~0x0200;
6786 aIdx[5] = i;
6787 bStartSeen = 1;
6788 break;
6789 }
6790 case SQLITE_INDEX_CONSTRAINT_GT: {
6791 if( idxNum & 0x0080 ) break;
6792 idxNum |= 0x0200;
6793 idxNum &= ~0x0100;
6794 aIdx[5] = i;
6795 bStartSeen = 1;
6796 break;
6797 }
6798 case SQLITE_INDEX_CONSTRAINT_LE: {
6799 if( idxNum & 0x0080 ) break;
6800 idxNum |= 0x1000;
6801 idxNum &= ~0x2000;
6802 aIdx[6] = i;
6803 break;
6804 }
6805 case SQLITE_INDEX_CONSTRAINT_LT: {
6806 if( idxNum & 0x0080 ) break;
6807 idxNum |= 0x2000;
6808 idxNum &= ~0x1000;
6809 aIdx[6] = i;
6810 break;
 
 
6811 }
6812 }
6813 continue;
6814 }
6815 iCol = pConstraint->iColumn - SERIES_COLUMN_START;
@@ -21202,10 +21268,11 @@
21202 u8 nEqpLevel; /* Depth of the EQP output graph */
21203 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
21204 u8 bSafeMode; /* True to prohibit unsafe operations */
21205 u8 bSafeModePersist; /* The long-term value of bSafeMode */
21206 u8 eRestoreState; /* See comments above doAutoDetectRestore() */
 
21207 ColModeOpts cmOpts; /* Option values affecting columnar mode output */
21208 unsigned statsOn; /* True to display memory stats before each finalize */
21209 unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
21210 int inputNesting; /* Track nesting level of .read and other redirects */
21211 int outCount; /* Revert to stdout when reaching zero */
@@ -21382,17 +21449,11 @@
21382 #define SEP_Column "|"
21383 #define SEP_Row "\n"
21384 #define SEP_Tab "\t"
21385 #define SEP_Space " "
21386 #define SEP_Comma ","
21387 #ifdef SQLITE_U8TEXT_ONLY
21388 /* With the SQLITE_U8TEXT_ONLY option, the output will always be in
21389 ** text mode. The \r will be inserted automatically. */
21390 # define SEP_CrLf "\n"
21391 #else
21392 # define SEP_CrLf "\r\n"
21393 #endif
21394 #define SEP_Unit "\x1F"
21395 #define SEP_Record "\x1E"
21396
21397 /*
21398 ** Limit input nesting via .read or any other input redirect.
@@ -21604,10 +21665,23 @@
21604 p->mode = p->modePrior;
21605 p->shellFlgs = p->priorShFlgs;
21606 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
21607 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
21608 }
 
 
 
 
 
 
 
 
 
 
 
 
 
21609
21610 /*
21611 ** Output the given string as a hex-encoded blob (eg. X'1234' )
21612 */
21613 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
@@ -21655,13 +21729,14 @@
21655 /*
21656 ** Output the given string as a quoted string using SQL quoting conventions.
21657 **
21658 ** See also: output_quoted_escaped_string()
21659 */
21660 static void output_quoted_string(FILE *out, const char *z){
21661 int i;
21662 char c;
 
21663 sqlite3_fsetmode(out, _O_BINARY);
21664 if( z==0 ) return;
21665 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
21666 if( c==0 ){
21667 sqlite3_fprintf(out, "'%s'",z);
@@ -21683,11 +21758,11 @@
21683 }
21684 z++;
21685 }
21686 sqlite3_fputs("'", out);
21687 }
21688 sqlite3_fsetmode(out, _O_TEXT);
21689 }
21690
21691 /*
21692 ** Output the given string as a quoted string using SQL quoting conventions.
21693 ** Additionallly , escape the "\n" and "\r" characters so that they do not
@@ -21695,13 +21770,14 @@
21695 ** systems.
21696 **
21697 ** This is like output_quoted_string() but with the addition of the \r\n
21698 ** escape mechanism.
21699 */
21700 static void output_quoted_escaped_string(FILE *out, const char *z){
21701 int i;
21702 char c;
 
21703 sqlite3_fsetmode(out, _O_BINARY);
21704 for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
21705 if( c==0 ){
21706 sqlite3_fprintf(out, "'%s'",z);
21707 }else{
@@ -21750,11 +21826,11 @@
21750 }
21751 if( nNL ){
21752 sqlite3_fprintf(out, ",'%s',char(10))", zNL);
21753 }
21754 }
21755 sqlite3_fsetmode(stdout, _O_TEXT);
21756 }
21757
21758 /*
21759 ** Find earliest of chars within s specified in zAny.
21760 ** With ns == ~0, is like strpbrk(s,zAny) and s must be 0-terminated.
@@ -22539,19 +22615,27 @@
22539 sqlite3_fsetmode(p->out, _O_BINARY);
22540 if( p->cnt++==0 && p->showHeader ){
22541 for(i=0; i<nArg; i++){
22542 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
22543 }
22544 sqlite3_fputs(p->rowSeparator, p->out);
 
 
 
 
22545 }
22546 if( nArg>0 ){
22547 for(i=0; i<nArg; i++){
22548 output_csv(p, azArg[i], i<nArg-1);
22549 }
22550 sqlite3_fputs(p->rowSeparator, p->out);
 
 
 
 
22551 }
22552 sqlite3_fsetmode(p->out, _O_TEXT);
22553 break;
22554 }
22555 case MODE_Insert: {
22556 if( azArg==0 ) break;
22557 sqlite3_fprintf(p->out, "INSERT INTO %s",p->zDestTable);
@@ -22575,13 +22659,13 @@
22575 sqlite3_fputs(i>0 ? "," : " VALUES(", p->out);
22576 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
22577 sqlite3_fputs("NULL", p->out);
22578 }else if( aiType && aiType[i]==SQLITE_TEXT ){
22579 if( ShellHasFlag(p, SHFLG_Newlines) ){
22580 output_quoted_string(p->out, azArg[i]);
22581 }else{
22582 output_quoted_escaped_string(p->out, azArg[i]);
22583 }
22584 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
22585 sqlite3_fputs(azArg[i], p->out);
22586 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
22587 char z[50];
@@ -22606,13 +22690,13 @@
22606 int nBlob = sqlite3_column_bytes(p->pStmt, i);
22607 output_hex_blob(p->out, pBlob, nBlob);
22608 }else if( isNumber(azArg[i], 0) ){
22609 sqlite3_fputs(azArg[i], p->out);
22610 }else if( ShellHasFlag(p, SHFLG_Newlines) ){
22611 output_quoted_string(p->out, azArg[i]);
22612 }else{
22613 output_quoted_escaped_string(p->out, azArg[i]);
22614 }
22615 }
22616 sqlite3_fputs(");\n", p->out);
22617 break;
22618 }
@@ -22661,21 +22745,21 @@
22661 case MODE_Quote: {
22662 if( azArg==0 ) break;
22663 if( p->cnt==0 && p->showHeader ){
22664 for(i=0; i<nArg; i++){
22665 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
22666 output_quoted_string(p->out, azCol[i]);
22667 }
22668 sqlite3_fputs(p->rowSeparator, p->out);
22669 }
22670 p->cnt++;
22671 for(i=0; i<nArg; i++){
22672 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
22673 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
22674 sqlite3_fputs("NULL", p->out);
22675 }else if( aiType && aiType[i]==SQLITE_TEXT ){
22676 output_quoted_string(p->out, azArg[i]);
22677 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
22678 sqlite3_fputs(azArg[i], p->out);
22679 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
22680 char z[50];
22681 double r = sqlite3_column_double(p->pStmt, i);
@@ -22686,11 +22770,11 @@
22686 int nBlob = sqlite3_column_bytes(p->pStmt, i);
22687 output_hex_blob(p->out, pBlob, nBlob);
22688 }else if( isNumber(azArg[i], 0) ){
22689 sqlite3_fputs(azArg[i], p->out);
22690 }else{
22691 output_quoted_string(p->out, azArg[i]);
22692 }
22693 }
22694 sqlite3_fputs(p->rowSeparator, p->out);
22695 break;
22696 }
@@ -24690,14 +24774,11 @@
24690 #ifndef SQLITE_SHELL_FIDDLE
24691 ".check GLOB Fail if output since .testcase does not match",
24692 ".clone NEWDB Clone data into NEWDB from the existing database",
24693 #endif
24694 ".connection [close] [#] Open or close an auxiliary database connection",
24695 #if defined(_WIN32) && !defined(SQLITE_U8TEXT_ONLY) \
24696 && !defined(SQLITE_U8TEXT_STDIO)
24697 ".crnl on|off Translate \\n to \\r\\n. Default ON",
24698 #endif /* _WIN32 && U8TEXT_ONLY && U8TEXT_STDIO */
24699 ".databases List names and files of attached databases",
24700 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
24701 #if SQLITE_SHELL_HAVE_RECOVER
24702 ".dbinfo ?DB? Show status information about the database",
24703 #endif
@@ -25692,20 +25773,20 @@
25692 /*
25693 ** Try to open an output file. The names "stdout" and "stderr" are
25694 ** recognized and do the right thing. NULL is returned if the output
25695 ** filename is "off".
25696 */
25697 static FILE *output_file_open(const char *zFile, int bTextMode){
25698 FILE *f;
25699 if( cli_strcmp(zFile,"stdout")==0 ){
25700 f = stdout;
25701 }else if( cli_strcmp(zFile, "stderr")==0 ){
25702 f = stderr;
25703 }else if( cli_strcmp(zFile, "off")==0 ){
25704 f = 0;
25705 }else{
25706 f = sqlite3_fopen(zFile, bTextMode ? "w" : "wb");
25707 if( f==0 ){
25708 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile);
25709 }
25710 }
25711 return f;
@@ -26174,10 +26255,11 @@
26174 static void output_redir(ShellState *p, FILE *pfNew){
26175 if( p->out != stdout ){
26176 sqlite3_fputs("Output already redirected.\n", stderr);
26177 }else{
26178 p->out = pfNew;
 
26179 if( p->mode==MODE_Www ){
26180 sqlite3_fputs(
26181 "<!DOCTYPE html>\n"
26182 "<HTML><BODY><PRE>\n",
26183 p->out
@@ -26229,10 +26311,11 @@
26229 }
26230 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
26231 }
26232 p->outfile[0] = 0;
26233 p->out = stdout;
 
26234 }
26235 #else
26236 # define output_redir(SS,pfO)
26237 # define output_reset(SS)
26238 #endif
@@ -28183,11 +28266,11 @@
28183 }
28184 }else
28185
28186 /* Undocumented. Legacy only. See "crnl" below */
28187 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){
28188 eputz("The \".binary\" command is deprecated. Use \".crnl\" instead.\n");
28189 rc = 1;
28190 }else
28191
28192 /* The undocumented ".breakpoint" command causes a call to the no-op
28193 ** routine named test_breakpoint().
@@ -28310,25 +28393,17 @@
28310 rc = 1;
28311 }
28312 }else
28313
28314 if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){
28315 #if !defined(_WIN32) || defined(SQLITE_U8TEXT_ONLY) \
28316 || defined(SQLITE_U8TEXT_STDIO)
28317 sqlite3_fputs("The \".crnl\" command is disable in this build.\n", p->out);
28318 #else
28319 if( nArg==2 ){
28320 if( booleanValue(azArg[1]) ){
28321 sqlite3_fsetmode(p->out, _O_TEXT);
28322 }else{
28323 sqlite3_fsetmode(p->out, _O_BINARY);
28324 }
28325 }else{
28326 eputz("Usage: .crnl on|off\n");
28327 rc = 1;
28328 }
28329 #endif
28330 }else
28331
28332 if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){
28333 char **azName = 0;
28334 int nName = 0;
@@ -29404,11 +29479,11 @@
29404 " than \"on\" or \"off\"\n");
29405 zFile = "off";
29406 }
29407 output_file_close(p->pLog);
29408 if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout";
29409 p->pLog = output_file_open(zFile, 0);
29410 }
29411 }else
29412
29413 if( c=='m' && cli_strncmp(azArg[0], "mode", n)==0 ){
29414 const char *zMode = 0;
@@ -29659,11 +29734,10 @@
29659 || cli_strncmp(azArg[0], "once", n)==0))
29660 || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0)
29661 || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0)
29662 ){
29663 char *zFile = 0;
29664 int bTxtMode = 0;
29665 int i;
29666 int eMode = 0;
29667 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
29668 int bPlain = 0; /* --plain option */
29669 static const char *zBomUtf8 = "\357\273\277";
@@ -29741,15 +29815,13 @@
29741 #endif
29742 }else if( eMode=='w' ){
29743 /* web-browser mode. */
29744 newTempFile(p, "html");
29745 if( !bPlain ) p->mode = MODE_Www;
29746 bTxtMode = 1;
29747 }else{
29748 /* text editor mode */
29749 newTempFile(p, "txt");
29750 bTxtMode = 1;
29751 }
29752 sqlite3_free(zFile);
29753 zFile = sqlite3_mprintf("%s", p->zTempFile);
29754 }
29755 #endif /* SQLITE_NOHAVE_SYSTEM */
@@ -29769,25 +29841,25 @@
29769 if( zBom ) sqlite3_fputs(zBom, pfPipe);
29770 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
29771 }
29772 #endif
29773 }else{
29774 FILE *pfFile = output_file_open(zFile, bTxtMode);
29775 if( pfFile==0 ){
29776 if( cli_strcmp(zFile,"off")!=0 ){
29777 sqlite3_fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
29778 }
29779 rc = 1;
29780 } else {
29781 output_redir(p, pfFile);
 
29782 if( bPlain && eMode=='w' ){
29783 sqlite3_fputs(
29784 "<!DOCTYPE html>\n<BODY>\n<PLAINTEXT>\n",
29785 pfFile
29786 );
29787 }
29788 if( zBom ) sqlite3_fputs(zBom, pfFile);
29789 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
29790 }
29791 }
29792 sqlite3_free(zFile);
29793 }else
@@ -29980,11 +30052,10 @@
29980 }
29981 if( azArg[1][0]=='|' ){
29982 #ifdef SQLITE_OMIT_POPEN
29983 eputz("Error: pipes are not supported in this OS\n");
29984 rc = 1;
29985 p->out = stdout;
29986 #else
29987 p->in = sqlite3_popen(azArg[1]+1, "r");
29988 if( p->in==0 ){
29989 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
29990 rc = 1;
@@ -30967,11 +31038,11 @@
30967
30968 #ifndef SQLITE_SHELL_FIDDLE
30969 /* Begin redirecting output to the file "testcase-out.txt" */
30970 if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
30971 output_reset(p);
30972 p->out = output_file_open("testcase-out.txt", 0);
30973 if( p->out==0 ){
30974 eputz("Error: cannot open 'testcase-out.txt'\n");
30975 }
30976 if( nArg>=2 ){
30977 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -31471,11 +31542,11 @@
31471 rc = 1;
31472 goto meta_command_exit;
31473 }
31474 }else{
31475 output_file_close(p->traceOut);
31476 p->traceOut = output_file_open(z, 0);
31477 }
31478 }
31479 if( p->traceOut==0 ){
31480 sqlite3_trace_v2(p->db, 0, 0, 0);
31481 }else{
@@ -32361,10 +32432,20 @@
32361 #endif
32362 sqlite3_config(SQLITE_CONFIG_URI, 1);
32363 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
32364 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
32365 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
 
 
 
 
 
 
 
 
 
 
32366 }
32367
32368 /*
32369 ** Output text to the console in a font that attracts extra attention.
32370 */
32371
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -343,31 +343,25 @@
343 #include <stdarg.h>
344 #include <io.h>
345 #include <fcntl.h>
346
347 /*
348 ** If the SQLITE_U8TEXT_ONLY option is defined, then use O_U8TEXT
349 ** when appropriate on all output. (Sometimes use O_BINARY when
350 ** rendering ASCII text in cases where NL-to-CRLF expansion would
351 ** not be correct.)
352 **
353 ** If the SQLITE_U8TEXT_STDIO option is defined, then use O_U8TEXT
354 ** when appropriate when writing to stdout or stderr. Use O_BINARY
355 ** or O_TEXT (depending on things like the .mode and the .crnl setting
356 ** in the CLI, or other context clues in other applications) for all
357 ** other output channels.
358 **
359 ** The default behavior, if neither of the above is defined is to
360 ** use O_U8TEXT when writing to the Windows console (or anything
361 ** else for which _isatty() returns true) and to use O_BINARY or O_TEXT
362 ** for all other output channels.
 
 
 
 
 
 
363 */
364 #if defined(SQLITE_U8TEXT_ONLY)
365 # define UseWtextForOutput(fd) 1
366 # define UseWtextForInput(fd) 1
367 # define IsConsole(fd) _isatty(_fileno(fd))
@@ -378,10 +372,35 @@
372 #else
373 # define UseWtextForOutput(fd) _isatty(_fileno(fd))
374 # define UseWtextForInput(fd) _isatty(_fileno(fd))
375 # define IsConsole(fd) 1
376 #endif
377
378 /*
379 ** Global variables determine if simulated O_BINARY mode is to be
380 ** used for stdout or other, respectively. Simulated O_BINARY mode
381 ** means the mode is usually O_BINARY, but switches to O_U8TEXT for
382 ** unicode characters U+0080 or greater (any character that has a
383 ** multi-byte representation in UTF-8). This is the only way we
384 ** have found to render Unicode characters on a Windows console while
385 ** at the same time avoiding undesirable \n to \r\n translation.
386 */
387 static int simBinaryStdout = 0;
388 static int simBinaryOther = 0;
389
390
391 /*
392 ** Determine if simulated binary mode should be used for output to fd
393 */
394 static int UseBinaryWText(FILE *fd){
395 if( fd==stdout || fd==stderr ){
396 return simBinaryStdout;
397 }else{
398 return simBinaryOther;
399 }
400 }
401
402
403 /*
404 ** Work-alike for the fopen() routine from the standard C library.
405 */
406 FILE *sqlite3_fopen(const char *zFilename, const char *zMode){
@@ -400,10 +419,11 @@
419 b2[sz2] = 0;
420 fp = _wfopen(b1, b2);
421 }
422 free(b1);
423 free(b2);
424 simBinaryOther = 0;
425 return fp;
426 }
427
428
429 /*
@@ -454,32 +474,72 @@
474 /* Reading from a file or other input source, just read bytes without
475 ** any translation. */
476 return fgets(buf, sz, in);
477 }
478 }
479
480 /*
481 ** Send ASCII text as O_BINARY. But for Unicode characters U+0080 and
482 ** greater, switch to O_U8TEXT.
483 */
484 static void piecemealOutput(wchar_t *b1, int sz, FILE *out){
485 int i;
486 wchar_t c;
487 while( sz>0 ){
488 for(i=0; i<sz && b1[i]>=0x80; i++){}
489 if( i>0 ){
490 c = b1[i];
491 b1[i] = 0;
492 fflush(out);
493 _setmode(_fileno(out), _O_U8TEXT);
494 fputws(b1, out);
495 fflush(out);
496 b1 += i;
497 b1[0] = c;
498 sz -= i;
499 }else{
500 fflush(out);
501 _setmode(_fileno(out), _O_TEXT);
502 _setmode(_fileno(out), _O_BINARY);
503 fwrite(&b1[0], 1, 1, out);
504 for(i=1; i<sz && b1[i]<0x80; i++){
505 fwrite(&b1[i], 1, 1, out);
506 }
507 fflush(out);
508 _setmode(_fileno(out), _O_U8TEXT);
509 b1 += i;
510 sz -= i;
511 }
512 }
513 }
514
515 /*
516 ** Work-alike for fputs() from the standard C library.
517 */
518 int sqlite3_fputs(const char *z, FILE *out){
519 if( !UseWtextForOutput(out) ){
520 /* Writing to a file or other destination, just write bytes without
521 ** any translation. */
522 return fputs(z, out);
523 }else{
524 /* When writing to the command-prompt in Windows, it is necessary
525 ** to use O_U8TEXT to render Unicode U+0080 and greater. Go ahead
526 ** use O_U8TEXT for everything in text mode.
527 */
528 int sz = (int)strlen(z);
529 wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) );
530 if( b1==0 ) return 0;
531 sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
532 b1[sz] = 0;
533 _setmode(_fileno(out), _O_U8TEXT);
534 if( UseBinaryWText(out) ){
535 piecemealOutput(b1, sz, out);
536 }else{
537 fputws(b1, out);
538 }
539 sqlite3_free(b1);
540 return 0;
 
 
 
 
541 }
542 }
543
544
545 /*
@@ -517,10 +577,14 @@
577 */
578 void sqlite3_fsetmode(FILE *fp, int mode){
579 if( !UseWtextForOutput(fp) ){
580 fflush(fp);
581 _setmode(_fileno(fp), mode);
582 }else if( fp==stdout || fp==stderr ){
583 simBinaryStdout = (mode==_O_BINARY);
584 }else{
585 simBinaryOther = (mode==_O_BINARY);
586 }
587 }
588
589 #endif /* defined(_WIN32) */
590
@@ -6766,50 +6830,52 @@
6830 aIdx[4] = i;
6831 idxNum |= 0x40;
6832 }
6833 continue;
6834 }
6835 if( pConstraint->iColumn<SERIES_COLUMN_START ){
6836 if( pConstraint->iColumn==SERIES_COLUMN_VALUE ){
6837 switch( op ){
6838 case SQLITE_INDEX_CONSTRAINT_EQ:
6839 case SQLITE_INDEX_CONSTRAINT_IS: {
6840 idxNum |= 0x0080;
6841 idxNum &= ~0x3300;
6842 aIdx[5] = i;
6843 aIdx[6] = -1;
6844 bStartSeen = 1;
6845 break;
6846 }
6847 case SQLITE_INDEX_CONSTRAINT_GE: {
6848 if( idxNum & 0x0080 ) break;
6849 idxNum |= 0x0100;
6850 idxNum &= ~0x0200;
6851 aIdx[5] = i;
6852 bStartSeen = 1;
6853 break;
6854 }
6855 case SQLITE_INDEX_CONSTRAINT_GT: {
6856 if( idxNum & 0x0080 ) break;
6857 idxNum |= 0x0200;
6858 idxNum &= ~0x0100;
6859 aIdx[5] = i;
6860 bStartSeen = 1;
6861 break;
6862 }
6863 case SQLITE_INDEX_CONSTRAINT_LE: {
6864 if( idxNum & 0x0080 ) break;
6865 idxNum |= 0x1000;
6866 idxNum &= ~0x2000;
6867 aIdx[6] = i;
6868 break;
6869 }
6870 case SQLITE_INDEX_CONSTRAINT_LT: {
6871 if( idxNum & 0x0080 ) break;
6872 idxNum |= 0x2000;
6873 idxNum &= ~0x1000;
6874 aIdx[6] = i;
6875 break;
6876 }
6877 }
6878 }
6879 continue;
6880 }
6881 iCol = pConstraint->iColumn - SERIES_COLUMN_START;
@@ -21202,10 +21268,11 @@
21268 u8 nEqpLevel; /* Depth of the EQP output graph */
21269 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
21270 u8 bSafeMode; /* True to prohibit unsafe operations */
21271 u8 bSafeModePersist; /* The long-term value of bSafeMode */
21272 u8 eRestoreState; /* See comments above doAutoDetectRestore() */
21273 u8 crnlMode; /* Do NL-to-CRLF translations when enabled (maybe) */
21274 ColModeOpts cmOpts; /* Option values affecting columnar mode output */
21275 unsigned statsOn; /* True to display memory stats before each finalize */
21276 unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
21277 int inputNesting; /* Track nesting level of .read and other redirects */
21278 int outCount; /* Revert to stdout when reaching zero */
@@ -21382,17 +21449,11 @@
21449 #define SEP_Column "|"
21450 #define SEP_Row "\n"
21451 #define SEP_Tab "\t"
21452 #define SEP_Space " "
21453 #define SEP_Comma ","
21454 #define SEP_CrLf "\n" /* Use ".crnl on" to get \r\n line endings */
 
 
 
 
 
 
21455 #define SEP_Unit "\x1F"
21456 #define SEP_Record "\x1E"
21457
21458 /*
21459 ** Limit input nesting via .read or any other input redirect.
@@ -21604,10 +21665,23 @@
21665 p->mode = p->modePrior;
21666 p->shellFlgs = p->priorShFlgs;
21667 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
21668 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
21669 }
21670
21671 /*
21672 ** Set output mode to text or binary for Windows.
21673 */
21674 static void setCrnlMode(ShellState *p){
21675 #ifdef _WIN32
21676 if( p->crnlMode ){
21677 sqlite3_fsetmode(p->out, _O_TEXT);
21678 }else{
21679 sqlite3_fsetmode(p->out, _O_BINARY);
21680 }
21681 #endif
21682 }
21683
21684 /*
21685 ** Output the given string as a hex-encoded blob (eg. X'1234' )
21686 */
21687 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
@@ -21655,13 +21729,14 @@
21729 /*
21730 ** Output the given string as a quoted string using SQL quoting conventions.
21731 **
21732 ** See also: output_quoted_escaped_string()
21733 */
21734 static void output_quoted_string(ShellState *p, const char *z){
21735 int i;
21736 char c;
21737 FILE *out = p->out;
21738 sqlite3_fsetmode(out, _O_BINARY);
21739 if( z==0 ) return;
21740 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
21741 if( c==0 ){
21742 sqlite3_fprintf(out, "'%s'",z);
@@ -21683,11 +21758,11 @@
21758 }
21759 z++;
21760 }
21761 sqlite3_fputs("'", out);
21762 }
21763 setCrnlMode(p);
21764 }
21765
21766 /*
21767 ** Output the given string as a quoted string using SQL quoting conventions.
21768 ** Additionallly , escape the "\n" and "\r" characters so that they do not
@@ -21695,13 +21770,14 @@
21770 ** systems.
21771 **
21772 ** This is like output_quoted_string() but with the addition of the \r\n
21773 ** escape mechanism.
21774 */
21775 static void output_quoted_escaped_string(ShellState *p, const char *z){
21776 int i;
21777 char c;
21778 FILE *out = p->out;
21779 sqlite3_fsetmode(out, _O_BINARY);
21780 for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
21781 if( c==0 ){
21782 sqlite3_fprintf(out, "'%s'",z);
21783 }else{
@@ -21750,11 +21826,11 @@
21826 }
21827 if( nNL ){
21828 sqlite3_fprintf(out, ",'%s',char(10))", zNL);
21829 }
21830 }
21831 setCrnlMode(p);
21832 }
21833
21834 /*
21835 ** Find earliest of chars within s specified in zAny.
21836 ** With ns == ~0, is like strpbrk(s,zAny) and s must be 0-terminated.
@@ -22539,19 +22615,27 @@
22615 sqlite3_fsetmode(p->out, _O_BINARY);
22616 if( p->cnt++==0 && p->showHeader ){
22617 for(i=0; i<nArg; i++){
22618 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
22619 }
22620 if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){
22621 sqlite3_fputs("\r\n", p->out);
22622 }else{
22623 sqlite3_fputs(p->rowSeparator, p->out);
22624 }
22625 }
22626 if( nArg>0 ){
22627 for(i=0; i<nArg; i++){
22628 output_csv(p, azArg[i], i<nArg-1);
22629 }
22630 if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){
22631 sqlite3_fputs("\r\n", p->out);
22632 }else{
22633 sqlite3_fputs(p->rowSeparator, p->out);
22634 }
22635 }
22636 setCrnlMode(p);
22637 break;
22638 }
22639 case MODE_Insert: {
22640 if( azArg==0 ) break;
22641 sqlite3_fprintf(p->out, "INSERT INTO %s",p->zDestTable);
@@ -22575,13 +22659,13 @@
22659 sqlite3_fputs(i>0 ? "," : " VALUES(", p->out);
22660 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
22661 sqlite3_fputs("NULL", p->out);
22662 }else if( aiType && aiType[i]==SQLITE_TEXT ){
22663 if( ShellHasFlag(p, SHFLG_Newlines) ){
22664 output_quoted_string(p, azArg[i]);
22665 }else{
22666 output_quoted_escaped_string(p, azArg[i]);
22667 }
22668 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
22669 sqlite3_fputs(azArg[i], p->out);
22670 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
22671 char z[50];
@@ -22606,13 +22690,13 @@
22690 int nBlob = sqlite3_column_bytes(p->pStmt, i);
22691 output_hex_blob(p->out, pBlob, nBlob);
22692 }else if( isNumber(azArg[i], 0) ){
22693 sqlite3_fputs(azArg[i], p->out);
22694 }else if( ShellHasFlag(p, SHFLG_Newlines) ){
22695 output_quoted_string(p, azArg[i]);
22696 }else{
22697 output_quoted_escaped_string(p, azArg[i]);
22698 }
22699 }
22700 sqlite3_fputs(");\n", p->out);
22701 break;
22702 }
@@ -22661,21 +22745,21 @@
22745 case MODE_Quote: {
22746 if( azArg==0 ) break;
22747 if( p->cnt==0 && p->showHeader ){
22748 for(i=0; i<nArg; i++){
22749 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
22750 output_quoted_string(p, azCol[i]);
22751 }
22752 sqlite3_fputs(p->rowSeparator, p->out);
22753 }
22754 p->cnt++;
22755 for(i=0; i<nArg; i++){
22756 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
22757 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
22758 sqlite3_fputs("NULL", p->out);
22759 }else if( aiType && aiType[i]==SQLITE_TEXT ){
22760 output_quoted_string(p, azArg[i]);
22761 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
22762 sqlite3_fputs(azArg[i], p->out);
22763 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
22764 char z[50];
22765 double r = sqlite3_column_double(p->pStmt, i);
@@ -22686,11 +22770,11 @@
22770 int nBlob = sqlite3_column_bytes(p->pStmt, i);
22771 output_hex_blob(p->out, pBlob, nBlob);
22772 }else if( isNumber(azArg[i], 0) ){
22773 sqlite3_fputs(azArg[i], p->out);
22774 }else{
22775 output_quoted_string(p, azArg[i]);
22776 }
22777 }
22778 sqlite3_fputs(p->rowSeparator, p->out);
22779 break;
22780 }
@@ -24690,14 +24774,11 @@
24774 #ifndef SQLITE_SHELL_FIDDLE
24775 ".check GLOB Fail if output since .testcase does not match",
24776 ".clone NEWDB Clone data into NEWDB from the existing database",
24777 #endif
24778 ".connection [close] [#] Open or close an auxiliary database connection",
24779 ".crnl on|off Translate \\n to \\r\\n sometimes. Default OFF",
 
 
 
24780 ".databases List names and files of attached databases",
24781 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
24782 #if SQLITE_SHELL_HAVE_RECOVER
24783 ".dbinfo ?DB? Show status information about the database",
24784 #endif
@@ -25692,20 +25773,20 @@
25773 /*
25774 ** Try to open an output file. The names "stdout" and "stderr" are
25775 ** recognized and do the right thing. NULL is returned if the output
25776 ** filename is "off".
25777 */
25778 static FILE *output_file_open(const char *zFile){
25779 FILE *f;
25780 if( cli_strcmp(zFile,"stdout")==0 ){
25781 f = stdout;
25782 }else if( cli_strcmp(zFile, "stderr")==0 ){
25783 f = stderr;
25784 }else if( cli_strcmp(zFile, "off")==0 ){
25785 f = 0;
25786 }else{
25787 f = sqlite3_fopen(zFile, "w");
25788 if( f==0 ){
25789 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile);
25790 }
25791 }
25792 return f;
@@ -26174,10 +26255,11 @@
26255 static void output_redir(ShellState *p, FILE *pfNew){
26256 if( p->out != stdout ){
26257 sqlite3_fputs("Output already redirected.\n", stderr);
26258 }else{
26259 p->out = pfNew;
26260 setCrnlMode(p);
26261 if( p->mode==MODE_Www ){
26262 sqlite3_fputs(
26263 "<!DOCTYPE html>\n"
26264 "<HTML><BODY><PRE>\n",
26265 p->out
@@ -26229,10 +26311,11 @@
26311 }
26312 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
26313 }
26314 p->outfile[0] = 0;
26315 p->out = stdout;
26316 setCrnlMode(p);
26317 }
26318 #else
26319 # define output_redir(SS,pfO)
26320 # define output_reset(SS)
26321 #endif
@@ -28183,11 +28266,11 @@
28266 }
28267 }else
28268
28269 /* Undocumented. Legacy only. See "crnl" below */
28270 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){
28271 eputz("The \".binary\" command is deprecated.\n");
28272 rc = 1;
28273 }else
28274
28275 /* The undocumented ".breakpoint" command causes a call to the no-op
28276 ** routine named test_breakpoint().
@@ -28310,25 +28393,17 @@
28393 rc = 1;
28394 }
28395 }else
28396
28397 if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){
 
 
 
 
28398 if( nArg==2 ){
28399 p->crnlMode = booleanValue(azArg[1]);
28400 setCrnlMode(p);
28401 }else{
28402 sqlite3_fprintf(stderr, "crnl is currently %s\n",
28403 p->crnlMode ? "ON" : "OFF");
28404 }
 
 
 
 
28405 }else
28406
28407 if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){
28408 char **azName = 0;
28409 int nName = 0;
@@ -29404,11 +29479,11 @@
29479 " than \"on\" or \"off\"\n");
29480 zFile = "off";
29481 }
29482 output_file_close(p->pLog);
29483 if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout";
29484 p->pLog = output_file_open(zFile);
29485 }
29486 }else
29487
29488 if( c=='m' && cli_strncmp(azArg[0], "mode", n)==0 ){
29489 const char *zMode = 0;
@@ -29659,11 +29734,10 @@
29734 || cli_strncmp(azArg[0], "once", n)==0))
29735 || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0)
29736 || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0)
29737 ){
29738 char *zFile = 0;
 
29739 int i;
29740 int eMode = 0;
29741 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
29742 int bPlain = 0; /* --plain option */
29743 static const char *zBomUtf8 = "\357\273\277";
@@ -29741,15 +29815,13 @@
29815 #endif
29816 }else if( eMode=='w' ){
29817 /* web-browser mode. */
29818 newTempFile(p, "html");
29819 if( !bPlain ) p->mode = MODE_Www;
 
29820 }else{
29821 /* text editor mode */
29822 newTempFile(p, "txt");
 
29823 }
29824 sqlite3_free(zFile);
29825 zFile = sqlite3_mprintf("%s", p->zTempFile);
29826 }
29827 #endif /* SQLITE_NOHAVE_SYSTEM */
@@ -29769,25 +29841,25 @@
29841 if( zBom ) sqlite3_fputs(zBom, pfPipe);
29842 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
29843 }
29844 #endif
29845 }else{
29846 FILE *pfFile = output_file_open(zFile);
29847 if( pfFile==0 ){
29848 if( cli_strcmp(zFile,"off")!=0 ){
29849 sqlite3_fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
29850 }
29851 rc = 1;
29852 } else {
29853 output_redir(p, pfFile);
29854 if( zBom ) sqlite3_fputs(zBom, pfFile);
29855 if( bPlain && eMode=='w' ){
29856 sqlite3_fputs(
29857 "<!DOCTYPE html>\n<BODY>\n<PLAINTEXT>\n",
29858 pfFile
29859 );
29860 }
 
29861 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
29862 }
29863 }
29864 sqlite3_free(zFile);
29865 }else
@@ -29980,11 +30052,10 @@
30052 }
30053 if( azArg[1][0]=='|' ){
30054 #ifdef SQLITE_OMIT_POPEN
30055 eputz("Error: pipes are not supported in this OS\n");
30056 rc = 1;
 
30057 #else
30058 p->in = sqlite3_popen(azArg[1]+1, "r");
30059 if( p->in==0 ){
30060 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
30061 rc = 1;
@@ -30967,11 +31038,11 @@
31038
31039 #ifndef SQLITE_SHELL_FIDDLE
31040 /* Begin redirecting output to the file "testcase-out.txt" */
31041 if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
31042 output_reset(p);
31043 p->out = output_file_open("testcase-out.txt");
31044 if( p->out==0 ){
31045 eputz("Error: cannot open 'testcase-out.txt'\n");
31046 }
31047 if( nArg>=2 ){
31048 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -31471,11 +31542,11 @@
31542 rc = 1;
31543 goto meta_command_exit;
31544 }
31545 }else{
31546 output_file_close(p->traceOut);
31547 p->traceOut = output_file_open(z);
31548 }
31549 }
31550 if( p->traceOut==0 ){
31551 sqlite3_trace_v2(p->db, 0, 0, 0);
31552 }else{
@@ -32361,10 +32432,20 @@
32432 #endif
32433 sqlite3_config(SQLITE_CONFIG_URI, 1);
32434 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
32435 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
32436 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
32437
32438 /* By default, come up in O_BINARY mode. That way, the default output is
32439 ** the same for Windows and non-Windows systems. Use the ".crnl on"
32440 ** command to change into O_TEXT mode to do automatic NL-to-CRLF
32441 ** conversions on output for Windows.
32442 **
32443 ** End-of-line marks on CVS output is CRLF when in .crnl is on and
32444 ** NL when .crnl is off.
32445 */
32446 data->crnlMode = 0;
32447 }
32448
32449 /*
32450 ** Output text to the console in a font that attracts extra attention.
32451 */
32452
+108 -108
--- 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
-** 011fab70cb3d194b27742ebb236b05be5822.
21
+** 2db24c5364808008fa503f37ca8ccf5d135e.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -462,11 +462,11 @@
462462
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463463
** [sqlite_version()] and [sqlite_source_id()].
464464
*/
465465
#define SQLITE_VERSION "3.47.0"
466466
#define SQLITE_VERSION_NUMBER 3047000
467
-#define SQLITE_SOURCE_ID "2024-10-07 12:48:21 011fab70cb3d194b27742ebb236b05be582230567cf78e3e6cac6911de86922f"
467
+#define SQLITE_SOURCE_ID "2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470"
468468
469469
/*
470470
** CAPI3REF: Run-Time Library Version Numbers
471471
** KEYWORDS: sqlite3_version sqlite3_sourceid
472472
**
@@ -19230,11 +19230,11 @@
1923019230
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
1923119231
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
1923219232
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
1923319233
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
1923419234
#define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
19235
- /* 0x80000000 // Available */
19235
+#define EP_SubtArg 0x80000000 /* Is argument to SQLITE_SUBTYPE function */
1923619236
1923719237
/* The EP_Propagate mask is a set of properties that automatically propagate
1923819238
** upwards into parent nodes.
1923919239
*/
1924019240
#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
@@ -41011,58 +41011,33 @@
4101141011
** file by this or any other process. If such a lock is held, set *pResOut
4101241012
** to a non-zero value otherwise *pResOut is set to zero. The return value
4101341013
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
4101441014
*/
4101541015
static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){
41016
- int rc = SQLITE_OK;
41017
- int reserved = 0;
4101841016
unixFile *pFile = (unixFile*)id;
4101941017
4102041018
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
4102141019
4102241020
assert( pFile );
41023
-
41024
- /* Check if a thread in this process holds such a lock */
41025
- if( pFile->eFileLock>SHARED_LOCK ){
41026
- reserved = 1;
41027
- }
41028
-
41029
- /* Otherwise see if some other process holds it. */
41030
- if( !reserved ){
41031
- /* attempt to get the lock */
41032
- int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
41033
- if( !lrc ){
41034
- /* got the lock, unlock it */
41035
- lrc = robust_flock(pFile->h, LOCK_UN);
41036
- if ( lrc ) {
41037
- int tErrno = errno;
41038
- /* unlock failed with an error */
41039
- lrc = SQLITE_IOERR_UNLOCK;
41040
- storeLastErrno(pFile, tErrno);
41041
- rc = lrc;
41042
- }
41043
- } else {
41044
- int tErrno = errno;
41045
- reserved = 1;
41046
- /* someone else might have it reserved */
41047
- lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
41048
- if( IS_LOCK_ERROR(lrc) ){
41049
- storeLastErrno(pFile, tErrno);
41050
- rc = lrc;
41051
- }
41052
- }
41053
- }
41054
- OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
41055
-
41056
-#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
41057
- if( (rc & 0xff) == SQLITE_IOERR ){
41058
- rc = SQLITE_OK;
41059
- reserved=1;
41060
- }
41061
-#endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
41062
- *pResOut = reserved;
41063
- return rc;
41021
+ assert( pFile->eFileLock<=SHARED_LOCK );
41022
+
41023
+ /* The flock VFS only ever takes exclusive locks (see function flockLock).
41024
+ ** Therefore, if this connection is holding any lock at all, no other
41025
+ ** connection may be holding a RESERVED lock. So set *pResOut to 0
41026
+ ** in this case.
41027
+ **
41028
+ ** Or, this connection may be holding no lock. In that case, set *pResOut to
41029
+ ** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the
41030
+ ** db in order to roll the hot journal back. If there is another connection
41031
+ ** holding a lock, that attempt will fail and an SQLITE_BUSY returned to
41032
+ ** the user. With other VFS, we try to avoid this, in order to allow a reader
41033
+ ** to proceed while a writer is preparing its transaction. But that won't
41034
+ ** work with the flock VFS - as it always takes EXCLUSIVE locks - so it is
41035
+ ** not a problem in this case. */
41036
+ *pResOut = 0;
41037
+
41038
+ return SQLITE_OK;
4106441039
}
4106541040
4106641041
/*
4106741042
** Lock the file with the lock specified by parameter eFileLock - one
4106841043
** of the following:
@@ -108215,10 +108190,28 @@
108215108190
pExpr->op = TK_NULL;
108216108191
return WRC_Prune;
108217108192
}
108218108193
}
108219108194
#endif
108195
+
108196
+ /* If the function may call sqlite3_value_subtype(), then set the
108197
+ ** EP_SubtArg flag on all of its argument expressions. This prevents
108198
+ ** where.c from replacing the expression with a value read from an
108199
+ ** index on the same expression, which will not have the correct
108200
+ ** subtype. Also set the flag if the function expression itself is
108201
+ ** an EP_SubtArg expression. In this case subtypes are required as
108202
+ ** the function may return a value with a subtype back to its
108203
+ ** caller using sqlite3_result_value(). */
108204
+ if( (pDef->funcFlags & SQLITE_SUBTYPE)
108205
+ || ExprHasProperty(pExpr, EP_SubtArg)
108206
+ ){
108207
+ int ii;
108208
+ for(ii=0; ii<n; ii++){
108209
+ ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg);
108210
+ }
108211
+ }
108212
+
108220108213
if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
108221108214
/* For the purposes of the EP_ConstFunc flag, date and time
108222108215
** functions and other functions that change slowly are considered
108223108216
** constant because they are constant for the duration of one query.
108224108217
** This allows them to be factored out of inner loops. */
@@ -113888,10 +113881,63 @@
113888113881
}
113889113882
#endif /* !defined(SQLITE_UNTESTABLE) */
113890113883
}
113891113884
return target;
113892113885
}
113886
+
113887
+/*
113888
+** Expression Node callback for sqlite3ExprCanReturnSubtype().
113889
+**
113890
+** Only a function call is able to return a subtype. So if the node
113891
+** is not a function call, return WRC_Prune immediately.
113892
+**
113893
+** A function call is able to return a subtype if it has the
113894
+** SQLITE_RESULT_SUBTYPE property.
113895
+**
113896
+** Assume that every function is able to pass-through a subtype from
113897
+** one of its argument (using sqlite3_result_value()). Most functions
113898
+** are not this way, but we don't have a mechanism to distinguish those
113899
+** that are from those that are not, so assume they all work this way.
113900
+** That means that if one of its arguments is another function and that
113901
+** other function is able to return a subtype, then this function is
113902
+** able to return a subtype.
113903
+*/
113904
+static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
113905
+ int n;
113906
+ FuncDef *pDef;
113907
+ sqlite3 *db;
113908
+ if( pExpr->op!=TK_FUNCTION ){
113909
+ return WRC_Prune;
113910
+ }
113911
+ assert( ExprUseXList(pExpr) );
113912
+ db = pWalker->pParse->db;
113913
+ n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
113914
+ pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
113915
+ if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
113916
+ pWalker->eCode = 1;
113917
+ return WRC_Prune;
113918
+ }
113919
+ return WRC_Continue;
113920
+}
113921
+
113922
+/*
113923
+** Return TRUE if expression pExpr is able to return a subtype.
113924
+**
113925
+** A TRUE return does not guarantee that a subtype will be returned.
113926
+** It only indicates that a subtype return is possible. False positives
113927
+** are acceptable as they only disable an optimization. False negatives,
113928
+** on the other hand, can lead to incorrect answers.
113929
+*/
113930
+static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
113931
+ Walker w;
113932
+ memset(&w, 0, sizeof(w));
113933
+ w.pParse = pParse;
113934
+ w.xExprCallback = exprNodeCanReturnSubtype;
113935
+ sqlite3WalkExpr(&w, pExpr);
113936
+ return w.eCode;
113937
+}
113938
+
113893113939
113894113940
/*
113895113941
** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
113896113942
** If it is, then resolve the expression by reading from the index and
113897113943
** return the register into which the value has been read. If pExpr is
@@ -113921,10 +113967,21 @@
113921113967
){
113922113968
/* Affinity mismatch on a generated column */
113923113969
continue;
113924113970
}
113925113971
113972
+
113973
+ /* Functions that might set a subtype should not be replaced by the
113974
+ ** value taken from an expression index if they are themselves an
113975
+ ** argument to another scalar function or aggregate.
113976
+ ** https://sqlite.org/forum/forumpost/68d284c86b082c3e */
113977
+ if( ExprHasProperty(pExpr, EP_SubtArg)
113978
+ && sqlite3ExprCanReturnSubtype(pParse, pExpr)
113979
+ ){
113980
+ continue;
113981
+ }
113982
+
113926113983
v = pParse->pVdbe;
113927113984
assert( v!=0 );
113928113985
if( p->bMaybeNullRow ){
113929113986
/* If the index is on a NULL row due to an outer join, then we
113930113987
** cannot extract the value from the index. The value must be
@@ -131918,11 +131975,12 @@
131918131975
FUNCTION(max, -1, 1, 1, minmaxFunc ),
131919131976
FUNCTION(max, 0, 1, 1, 0 ),
131920131977
WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
131921131978
SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
131922131979
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
131923
- FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF),
131980
+ FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
131981
+ SQLITE_FUNC_TYPEOF|SQLITE_SUBTYPE),
131924131982
FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
131925131983
FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN),
131926131984
FUNCTION(instr, 2, 0, 0, instrFunc ),
131927131985
FUNCTION(printf, -1, 0, 0, printfFunc ),
131928131986
FUNCTION(format, -1, 0, 0, printfFunc ),
@@ -132024,11 +132082,11 @@
132024132082
MFUNCTION(atanh, 1, atanh, math1Func ),
132025132083
#endif
132026132084
MFUNCTION(sqrt, 1, sqrt, math1Func ),
132027132085
MFUNCTION(radians, 1, degToRad, math1Func ),
132028132086
MFUNCTION(degrees, 1, radToDeg, math1Func ),
132029
- FUNCTION(pi, 0, 0, 0, piFunc ),
132087
+ MFUNCTION(pi, 0, 0, piFunc ),
132030132088
#endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
132031132089
FUNCTION(sign, 1, 0, 0, signFunc ),
132032132090
INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
132033132091
INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
132034132092
};
@@ -161397,11 +161455,11 @@
161397161455
** this code, but the database engine itself might be processing
161398161456
** content using a different encoding. */
161399161457
cnt = 0;
161400161458
while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
161401161459
cnt++;
161402
- if( c==wc[3] && z[cnt]!=0 ){
161460
+ if( c==wc[3] && z[cnt]>0 && z[cnt]<0x80 ){
161403161461
cnt++;
161404161462
}else if( c>=0x80 ){
161405161463
const u8 *z2 = z+cnt-1;
161406161464
if( sqlite3Utf8Read(&z2)==0xfffd || ENC(db)==SQLITE_UTF16LE ){
161407161465
cnt--;
@@ -169376,62 +169434,10 @@
169376169434
nSearch += pLoop->nOut;
169377169435
if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta;
169378169436
}
169379169437
}
169380169438
169381
-/*
169382
-** Expression Node callback for sqlite3ExprCanReturnSubtype().
169383
-**
169384
-** Only a function call is able to return a subtype. So if the node
169385
-** is not a function call, return WRC_Prune immediately.
169386
-**
169387
-** A function call is able to return a subtype if it has the
169388
-** SQLITE_RESULT_SUBTYPE property.
169389
-**
169390
-** Assume that every function is able to pass-through a subtype from
169391
-** one of its argument (using sqlite3_result_value()). Most functions
169392
-** are not this way, but we don't have a mechanism to distinguish those
169393
-** that are from those that are not, so assume they all work this way.
169394
-** That means that if one of its arguments is another function and that
169395
-** other function is able to return a subtype, then this function is
169396
-** able to return a subtype.
169397
-*/
169398
-static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
169399
- int n;
169400
- FuncDef *pDef;
169401
- sqlite3 *db;
169402
- if( pExpr->op!=TK_FUNCTION ){
169403
- return WRC_Prune;
169404
- }
169405
- assert( ExprUseXList(pExpr) );
169406
- db = pWalker->pParse->db;
169407
- n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
169408
- pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
169409
- if( pDef==0 || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
169410
- pWalker->eCode = 1;
169411
- return WRC_Prune;
169412
- }
169413
- return WRC_Continue;
169414
-}
169415
-
169416
-/*
169417
-** Return TRUE if expression pExpr is able to return a subtype.
169418
-**
169419
-** A TRUE return does not guarantee that a subtype will be returned.
169420
-** It only indicates that a subtype return is possible. False positives
169421
-** are acceptable as they only disable an optimization. False negatives,
169422
-** on the other hand, can lead to incorrect answers.
169423
-*/
169424
-static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
169425
- Walker w;
169426
- memset(&w, 0, sizeof(w));
169427
- w.pParse = pParse;
169428
- w.xExprCallback = exprNodeCanReturnSubtype;
169429
- sqlite3WalkExpr(&w, pExpr);
169430
- return w.eCode;
169431
-}
169432
-
169433169439
/*
169434169440
** The index pIdx is used by a query and contains one or more expressions.
169435169441
** In other words pIdx is an index on an expression. iIdxCur is the cursor
169436169442
** number for the index and iDataCur is the cursor number for the corresponding
169437169443
** table.
@@ -169461,16 +169467,10 @@
169461169467
pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]);
169462169468
}else{
169463169469
continue;
169464169470
}
169465169471
if( sqlite3ExprIsConstant(0,pExpr) ) continue;
169466
- if( pExpr->op==TK_FUNCTION && sqlite3ExprCanReturnSubtype(pParse,pExpr) ){
169467
- /* Functions that might set a subtype should not be replaced by the
169468
- ** value taken from an expression index since the index omits the
169469
- ** subtype. https://sqlite.org/forum/forumpost/68d284c86b082c3e */
169470
- continue;
169471
- }
169472169472
p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
169473169473
if( p==0 ) break;
169474169474
p->pIENext = pParse->pIdxEpr;
169475169475
#ifdef WHERETRACE_ENABLED
169476169476
if( sqlite3WhereTrace & 0x200 ){
@@ -254849,11 +254849,11 @@
254849254849
int nArg, /* Number of args */
254850254850
sqlite3_value **apUnused /* Function arguments */
254851254851
){
254852254852
assert( nArg==0 );
254853254853
UNUSED_PARAM2(nArg, apUnused);
254854
- sqlite3_result_text(pCtx, "fts5: 2024-10-07 12:48:21 011fab70cb3d194b27742ebb236b05be582230567cf78e3e6cac6911de86922f", -1, SQLITE_TRANSIENT);
254854
+ sqlite3_result_text(pCtx, "fts5: 2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470", -1, SQLITE_TRANSIENT);
254855254855
}
254856254856
254857254857
/*
254858254858
** Implementation of fts5_locale(LOCALE, TEXT) function.
254859254859
**
254860254860
--- 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 ** 011fab70cb3d194b27742ebb236b05be5822.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -462,11 +462,11 @@
462 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463 ** [sqlite_version()] and [sqlite_source_id()].
464 */
465 #define SQLITE_VERSION "3.47.0"
466 #define SQLITE_VERSION_NUMBER 3047000
467 #define SQLITE_SOURCE_ID "2024-10-07 12:48:21 011fab70cb3d194b27742ebb236b05be582230567cf78e3e6cac6911de86922f"
468
469 /*
470 ** CAPI3REF: Run-Time Library Version Numbers
471 ** KEYWORDS: sqlite3_version sqlite3_sourceid
472 **
@@ -19230,11 +19230,11 @@
19230 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
19231 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
19232 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
19233 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
19234 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
19235 /* 0x80000000 // Available */
19236
19237 /* The EP_Propagate mask is a set of properties that automatically propagate
19238 ** upwards into parent nodes.
19239 */
19240 #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
@@ -41011,58 +41011,33 @@
41011 ** file by this or any other process. If such a lock is held, set *pResOut
41012 ** to a non-zero value otherwise *pResOut is set to zero. The return value
41013 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
41014 */
41015 static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){
41016 int rc = SQLITE_OK;
41017 int reserved = 0;
41018 unixFile *pFile = (unixFile*)id;
41019
41020 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
41021
41022 assert( pFile );
41023
41024 /* Check if a thread in this process holds such a lock */
41025 if( pFile->eFileLock>SHARED_LOCK ){
41026 reserved = 1;
41027 }
41028
41029 /* Otherwise see if some other process holds it. */
41030 if( !reserved ){
41031 /* attempt to get the lock */
41032 int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
41033 if( !lrc ){
41034 /* got the lock, unlock it */
41035 lrc = robust_flock(pFile->h, LOCK_UN);
41036 if ( lrc ) {
41037 int tErrno = errno;
41038 /* unlock failed with an error */
41039 lrc = SQLITE_IOERR_UNLOCK;
41040 storeLastErrno(pFile, tErrno);
41041 rc = lrc;
41042 }
41043 } else {
41044 int tErrno = errno;
41045 reserved = 1;
41046 /* someone else might have it reserved */
41047 lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
41048 if( IS_LOCK_ERROR(lrc) ){
41049 storeLastErrno(pFile, tErrno);
41050 rc = lrc;
41051 }
41052 }
41053 }
41054 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
41055
41056 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
41057 if( (rc & 0xff) == SQLITE_IOERR ){
41058 rc = SQLITE_OK;
41059 reserved=1;
41060 }
41061 #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
41062 *pResOut = reserved;
41063 return rc;
41064 }
41065
41066 /*
41067 ** Lock the file with the lock specified by parameter eFileLock - one
41068 ** of the following:
@@ -108215,10 +108190,28 @@
108215 pExpr->op = TK_NULL;
108216 return WRC_Prune;
108217 }
108218 }
108219 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108220 if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
108221 /* For the purposes of the EP_ConstFunc flag, date and time
108222 ** functions and other functions that change slowly are considered
108223 ** constant because they are constant for the duration of one query.
108224 ** This allows them to be factored out of inner loops. */
@@ -113888,10 +113881,63 @@
113888 }
113889 #endif /* !defined(SQLITE_UNTESTABLE) */
113890 }
113891 return target;
113892 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113893
113894 /*
113895 ** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
113896 ** If it is, then resolve the expression by reading from the index and
113897 ** return the register into which the value has been read. If pExpr is
@@ -113921,10 +113967,21 @@
113921 ){
113922 /* Affinity mismatch on a generated column */
113923 continue;
113924 }
113925
 
 
 
 
 
 
 
 
 
 
 
113926 v = pParse->pVdbe;
113927 assert( v!=0 );
113928 if( p->bMaybeNullRow ){
113929 /* If the index is on a NULL row due to an outer join, then we
113930 ** cannot extract the value from the index. The value must be
@@ -131918,11 +131975,12 @@
131918 FUNCTION(max, -1, 1, 1, minmaxFunc ),
131919 FUNCTION(max, 0, 1, 1, 0 ),
131920 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
131921 SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
131922 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
131923 FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF),
 
131924 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
131925 FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN),
131926 FUNCTION(instr, 2, 0, 0, instrFunc ),
131927 FUNCTION(printf, -1, 0, 0, printfFunc ),
131928 FUNCTION(format, -1, 0, 0, printfFunc ),
@@ -132024,11 +132082,11 @@
132024 MFUNCTION(atanh, 1, atanh, math1Func ),
132025 #endif
132026 MFUNCTION(sqrt, 1, sqrt, math1Func ),
132027 MFUNCTION(radians, 1, degToRad, math1Func ),
132028 MFUNCTION(degrees, 1, radToDeg, math1Func ),
132029 FUNCTION(pi, 0, 0, 0, piFunc ),
132030 #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
132031 FUNCTION(sign, 1, 0, 0, signFunc ),
132032 INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
132033 INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
132034 };
@@ -161397,11 +161455,11 @@
161397 ** this code, but the database engine itself might be processing
161398 ** content using a different encoding. */
161399 cnt = 0;
161400 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
161401 cnt++;
161402 if( c==wc[3] && z[cnt]!=0 ){
161403 cnt++;
161404 }else if( c>=0x80 ){
161405 const u8 *z2 = z+cnt-1;
161406 if( sqlite3Utf8Read(&z2)==0xfffd || ENC(db)==SQLITE_UTF16LE ){
161407 cnt--;
@@ -169376,62 +169434,10 @@
169376 nSearch += pLoop->nOut;
169377 if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta;
169378 }
169379 }
169380
169381 /*
169382 ** Expression Node callback for sqlite3ExprCanReturnSubtype().
169383 **
169384 ** Only a function call is able to return a subtype. So if the node
169385 ** is not a function call, return WRC_Prune immediately.
169386 **
169387 ** A function call is able to return a subtype if it has the
169388 ** SQLITE_RESULT_SUBTYPE property.
169389 **
169390 ** Assume that every function is able to pass-through a subtype from
169391 ** one of its argument (using sqlite3_result_value()). Most functions
169392 ** are not this way, but we don't have a mechanism to distinguish those
169393 ** that are from those that are not, so assume they all work this way.
169394 ** That means that if one of its arguments is another function and that
169395 ** other function is able to return a subtype, then this function is
169396 ** able to return a subtype.
169397 */
169398 static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
169399 int n;
169400 FuncDef *pDef;
169401 sqlite3 *db;
169402 if( pExpr->op!=TK_FUNCTION ){
169403 return WRC_Prune;
169404 }
169405 assert( ExprUseXList(pExpr) );
169406 db = pWalker->pParse->db;
169407 n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
169408 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
169409 if( pDef==0 || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
169410 pWalker->eCode = 1;
169411 return WRC_Prune;
169412 }
169413 return WRC_Continue;
169414 }
169415
169416 /*
169417 ** Return TRUE if expression pExpr is able to return a subtype.
169418 **
169419 ** A TRUE return does not guarantee that a subtype will be returned.
169420 ** It only indicates that a subtype return is possible. False positives
169421 ** are acceptable as they only disable an optimization. False negatives,
169422 ** on the other hand, can lead to incorrect answers.
169423 */
169424 static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
169425 Walker w;
169426 memset(&w, 0, sizeof(w));
169427 w.pParse = pParse;
169428 w.xExprCallback = exprNodeCanReturnSubtype;
169429 sqlite3WalkExpr(&w, pExpr);
169430 return w.eCode;
169431 }
169432
169433 /*
169434 ** The index pIdx is used by a query and contains one or more expressions.
169435 ** In other words pIdx is an index on an expression. iIdxCur is the cursor
169436 ** number for the index and iDataCur is the cursor number for the corresponding
169437 ** table.
@@ -169461,16 +169467,10 @@
169461 pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]);
169462 }else{
169463 continue;
169464 }
169465 if( sqlite3ExprIsConstant(0,pExpr) ) continue;
169466 if( pExpr->op==TK_FUNCTION && sqlite3ExprCanReturnSubtype(pParse,pExpr) ){
169467 /* Functions that might set a subtype should not be replaced by the
169468 ** value taken from an expression index since the index omits the
169469 ** subtype. https://sqlite.org/forum/forumpost/68d284c86b082c3e */
169470 continue;
169471 }
169472 p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
169473 if( p==0 ) break;
169474 p->pIENext = pParse->pIdxEpr;
169475 #ifdef WHERETRACE_ENABLED
169476 if( sqlite3WhereTrace & 0x200 ){
@@ -254849,11 +254849,11 @@
254849 int nArg, /* Number of args */
254850 sqlite3_value **apUnused /* Function arguments */
254851 ){
254852 assert( nArg==0 );
254853 UNUSED_PARAM2(nArg, apUnused);
254854 sqlite3_result_text(pCtx, "fts5: 2024-10-07 12:48:21 011fab70cb3d194b27742ebb236b05be582230567cf78e3e6cac6911de86922f", -1, SQLITE_TRANSIENT);
254855 }
254856
254857 /*
254858 ** Implementation of fts5_locale(LOCALE, TEXT) function.
254859 **
254860
--- 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 ** 2db24c5364808008fa503f37ca8ccf5d135e.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -462,11 +462,11 @@
462 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463 ** [sqlite_version()] and [sqlite_source_id()].
464 */
465 #define SQLITE_VERSION "3.47.0"
466 #define SQLITE_VERSION_NUMBER 3047000
467 #define SQLITE_SOURCE_ID "2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470"
468
469 /*
470 ** CAPI3REF: Run-Time Library Version Numbers
471 ** KEYWORDS: sqlite3_version sqlite3_sourceid
472 **
@@ -19230,11 +19230,11 @@
19230 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
19231 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
19232 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
19233 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
19234 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
19235 #define EP_SubtArg 0x80000000 /* Is argument to SQLITE_SUBTYPE function */
19236
19237 /* The EP_Propagate mask is a set of properties that automatically propagate
19238 ** upwards into parent nodes.
19239 */
19240 #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
@@ -41011,58 +41011,33 @@
41011 ** file by this or any other process. If such a lock is held, set *pResOut
41012 ** to a non-zero value otherwise *pResOut is set to zero. The return value
41013 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
41014 */
41015 static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){
 
 
41016 unixFile *pFile = (unixFile*)id;
41017
41018 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
41019
41020 assert( pFile );
41021 assert( pFile->eFileLock<=SHARED_LOCK );
41022
41023 /* The flock VFS only ever takes exclusive locks (see function flockLock).
41024 ** Therefore, if this connection is holding any lock at all, no other
41025 ** connection may be holding a RESERVED lock. So set *pResOut to 0
41026 ** in this case.
41027 **
41028 ** Or, this connection may be holding no lock. In that case, set *pResOut to
41029 ** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the
41030 ** db in order to roll the hot journal back. If there is another connection
41031 ** holding a lock, that attempt will fail and an SQLITE_BUSY returned to
41032 ** the user. With other VFS, we try to avoid this, in order to allow a reader
41033 ** to proceed while a writer is preparing its transaction. But that won't
41034 ** work with the flock VFS - as it always takes EXCLUSIVE locks - so it is
41035 ** not a problem in this case. */
41036 *pResOut = 0;
41037
41038 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41039 }
41040
41041 /*
41042 ** Lock the file with the lock specified by parameter eFileLock - one
41043 ** of the following:
@@ -108215,10 +108190,28 @@
108190 pExpr->op = TK_NULL;
108191 return WRC_Prune;
108192 }
108193 }
108194 #endif
108195
108196 /* If the function may call sqlite3_value_subtype(), then set the
108197 ** EP_SubtArg flag on all of its argument expressions. This prevents
108198 ** where.c from replacing the expression with a value read from an
108199 ** index on the same expression, which will not have the correct
108200 ** subtype. Also set the flag if the function expression itself is
108201 ** an EP_SubtArg expression. In this case subtypes are required as
108202 ** the function may return a value with a subtype back to its
108203 ** caller using sqlite3_result_value(). */
108204 if( (pDef->funcFlags & SQLITE_SUBTYPE)
108205 || ExprHasProperty(pExpr, EP_SubtArg)
108206 ){
108207 int ii;
108208 for(ii=0; ii<n; ii++){
108209 ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg);
108210 }
108211 }
108212
108213 if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
108214 /* For the purposes of the EP_ConstFunc flag, date and time
108215 ** functions and other functions that change slowly are considered
108216 ** constant because they are constant for the duration of one query.
108217 ** This allows them to be factored out of inner loops. */
@@ -113888,10 +113881,63 @@
113881 }
113882 #endif /* !defined(SQLITE_UNTESTABLE) */
113883 }
113884 return target;
113885 }
113886
113887 /*
113888 ** Expression Node callback for sqlite3ExprCanReturnSubtype().
113889 **
113890 ** Only a function call is able to return a subtype. So if the node
113891 ** is not a function call, return WRC_Prune immediately.
113892 **
113893 ** A function call is able to return a subtype if it has the
113894 ** SQLITE_RESULT_SUBTYPE property.
113895 **
113896 ** Assume that every function is able to pass-through a subtype from
113897 ** one of its argument (using sqlite3_result_value()). Most functions
113898 ** are not this way, but we don't have a mechanism to distinguish those
113899 ** that are from those that are not, so assume they all work this way.
113900 ** That means that if one of its arguments is another function and that
113901 ** other function is able to return a subtype, then this function is
113902 ** able to return a subtype.
113903 */
113904 static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
113905 int n;
113906 FuncDef *pDef;
113907 sqlite3 *db;
113908 if( pExpr->op!=TK_FUNCTION ){
113909 return WRC_Prune;
113910 }
113911 assert( ExprUseXList(pExpr) );
113912 db = pWalker->pParse->db;
113913 n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
113914 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
113915 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
113916 pWalker->eCode = 1;
113917 return WRC_Prune;
113918 }
113919 return WRC_Continue;
113920 }
113921
113922 /*
113923 ** Return TRUE if expression pExpr is able to return a subtype.
113924 **
113925 ** A TRUE return does not guarantee that a subtype will be returned.
113926 ** It only indicates that a subtype return is possible. False positives
113927 ** are acceptable as they only disable an optimization. False negatives,
113928 ** on the other hand, can lead to incorrect answers.
113929 */
113930 static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
113931 Walker w;
113932 memset(&w, 0, sizeof(w));
113933 w.pParse = pParse;
113934 w.xExprCallback = exprNodeCanReturnSubtype;
113935 sqlite3WalkExpr(&w, pExpr);
113936 return w.eCode;
113937 }
113938
113939
113940 /*
113941 ** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
113942 ** If it is, then resolve the expression by reading from the index and
113943 ** return the register into which the value has been read. If pExpr is
@@ -113921,10 +113967,21 @@
113967 ){
113968 /* Affinity mismatch on a generated column */
113969 continue;
113970 }
113971
113972
113973 /* Functions that might set a subtype should not be replaced by the
113974 ** value taken from an expression index if they are themselves an
113975 ** argument to another scalar function or aggregate.
113976 ** https://sqlite.org/forum/forumpost/68d284c86b082c3e */
113977 if( ExprHasProperty(pExpr, EP_SubtArg)
113978 && sqlite3ExprCanReturnSubtype(pParse, pExpr)
113979 ){
113980 continue;
113981 }
113982
113983 v = pParse->pVdbe;
113984 assert( v!=0 );
113985 if( p->bMaybeNullRow ){
113986 /* If the index is on a NULL row due to an outer join, then we
113987 ** cannot extract the value from the index. The value must be
@@ -131918,11 +131975,12 @@
131975 FUNCTION(max, -1, 1, 1, minmaxFunc ),
131976 FUNCTION(max, 0, 1, 1, 0 ),
131977 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
131978 SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
131979 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
131980 FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
131981 SQLITE_FUNC_TYPEOF|SQLITE_SUBTYPE),
131982 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
131983 FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN),
131984 FUNCTION(instr, 2, 0, 0, instrFunc ),
131985 FUNCTION(printf, -1, 0, 0, printfFunc ),
131986 FUNCTION(format, -1, 0, 0, printfFunc ),
@@ -132024,11 +132082,11 @@
132082 MFUNCTION(atanh, 1, atanh, math1Func ),
132083 #endif
132084 MFUNCTION(sqrt, 1, sqrt, math1Func ),
132085 MFUNCTION(radians, 1, degToRad, math1Func ),
132086 MFUNCTION(degrees, 1, radToDeg, math1Func ),
132087 MFUNCTION(pi, 0, 0, piFunc ),
132088 #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
132089 FUNCTION(sign, 1, 0, 0, signFunc ),
132090 INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
132091 INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
132092 };
@@ -161397,11 +161455,11 @@
161455 ** this code, but the database engine itself might be processing
161456 ** content using a different encoding. */
161457 cnt = 0;
161458 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
161459 cnt++;
161460 if( c==wc[3] && z[cnt]>0 && z[cnt]<0x80 ){
161461 cnt++;
161462 }else if( c>=0x80 ){
161463 const u8 *z2 = z+cnt-1;
161464 if( sqlite3Utf8Read(&z2)==0xfffd || ENC(db)==SQLITE_UTF16LE ){
161465 cnt--;
@@ -169376,62 +169434,10 @@
169434 nSearch += pLoop->nOut;
169435 if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta;
169436 }
169437 }
169438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169439 /*
169440 ** The index pIdx is used by a query and contains one or more expressions.
169441 ** In other words pIdx is an index on an expression. iIdxCur is the cursor
169442 ** number for the index and iDataCur is the cursor number for the corresponding
169443 ** table.
@@ -169461,16 +169467,10 @@
169467 pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]);
169468 }else{
169469 continue;
169470 }
169471 if( sqlite3ExprIsConstant(0,pExpr) ) continue;
 
 
 
 
 
 
169472 p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
169473 if( p==0 ) break;
169474 p->pIENext = pParse->pIdxEpr;
169475 #ifdef WHERETRACE_ENABLED
169476 if( sqlite3WhereTrace & 0x200 ){
@@ -254849,11 +254849,11 @@
254849 int nArg, /* Number of args */
254850 sqlite3_value **apUnused /* Function arguments */
254851 ){
254852 assert( nArg==0 );
254853 UNUSED_PARAM2(nArg, apUnused);
254854 sqlite3_result_text(pCtx, "fts5: 2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470", -1, SQLITE_TRANSIENT);
254855 }
254856
254857 /*
254858 ** Implementation of fts5_locale(LOCALE, TEXT) function.
254859 **
254860
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.47.0"
150150
#define SQLITE_VERSION_NUMBER 3047000
151
-#define SQLITE_SOURCE_ID "2024-10-07 12:48:21 011fab70cb3d194b27742ebb236b05be582230567cf78e3e6cac6911de86922f"
151
+#define SQLITE_SOURCE_ID "2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.47.0"
150 #define SQLITE_VERSION_NUMBER 3047000
151 #define SQLITE_SOURCE_ID "2024-10-07 12:48:21 011fab70cb3d194b27742ebb236b05be582230567cf78e3e6cac6911de86922f"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.47.0"
150 #define SQLITE_VERSION_NUMBER 3047000
151 #define SQLITE_SOURCE_ID "2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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