Fossil SCM

Update the built-in SQLite to the latest trunk version for testing, and especially testing of the enhancements to the CLI.

drh 2025-12-30 13:18 trunk
Commit b9ecacf4a1623baee8470990b5a68f1626e2ea6b7a19c6b6cfc852783a4f21cd
3 files changed +236 -140 +75 -24 +21 -4
+236 -140
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -35,11 +35,11 @@
3535
** ext/recover/sqlite3recover.h
3636
** src/shell.c.in
3737
**
3838
** To modify this program, get a copy of the canonical SQLite source tree,
3939
** edit the src/shell.c.in file and/or some of the other files that are
40
-** listed above, then rerun the rerun "make shell.c".
40
+** listed above, then rerun the command "make shell.c".
4141
*/
4242
/************************* Begin src/shell.c.in ******************/
4343
/*
4444
** 2001 September 15
4545
**
@@ -49,11 +49,11 @@
4949
** May you do good and not evil.
5050
** May you find forgiveness for yourself and forgive others.
5151
** May you share freely, never taking more than you give.
5252
**
5353
*************************************************************************
54
-** This file contains code to implement the "sqlite" command line
54
+** This file contains code to implement the "sqlite3" command line
5555
** utility for accessing SQLite databases.
5656
*/
5757
#if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
5858
/* This needs to come before any includes for MSVC compiler */
5959
#define _CRT_SECURE_NO_WARNINGS
@@ -4070,10 +4070,18 @@
40704070
#define PROMPT_LEN_MAX 128
40714071
/* First line prompt. default: "sqlite> " */
40724072
static char mainPrompt[PROMPT_LEN_MAX];
40734073
/* Continuation prompt. default: " ...> " */
40744074
static char continuePrompt[PROMPT_LEN_MAX];
4075
+
4076
+/*
4077
+** Write I/O traces to the following stream.
4078
+*/
4079
+#ifdef SQLITE_ENABLE_IOTRACE
4080
+static FILE *iotrace = 0;
4081
+#endif
4082
+
40754083
40764084
/* This is variant of the standard-library strncpy() routine with the
40774085
** one change that the destination string is always zero-terminated, even
40784086
** if there is no zero-terminator in the first n-1 characters of the source
40794087
** string.
@@ -4190,17 +4198,10 @@
41904198
*/
41914199
static void shell_check_oom(const void *p){
41924200
if( p==0 ) shell_out_of_memory();
41934201
}
41944202
4195
-/*
4196
-** Write I/O traces to the following stream.
4197
-*/
4198
-#ifdef SQLITE_ENABLE_IOTRACE
4199
-static FILE *iotrace = 0;
4200
-#endif
4201
-
42024203
/*
42034204
** This routine works like printf in that its first argument is a
42044205
** format string and subsequent arguments are values to be substituted
42054206
** in place of % fields. The result of formatting this string
42064207
** is written to iotrace.
@@ -8351,13 +8352,13 @@
83518352
}else if( e<-10000 ){
83528353
e = -10000;
83538354
}
83548355
83558356
if( m<0 ){
8357
+ if( m<(-9223372036854775807LL) ) return;
83568358
isNeg = 1;
83578359
m = -m;
8358
- if( m<0 ) return;
83598360
}else if( m==0 && e>-1000 && e<1000 ){
83608361
sqlite3_result_double(context, 0.0);
83618362
return;
83628363
}
83638364
while( (m>>32)&0xffe00000 ){
@@ -26848,19 +26849,31 @@
2684826849
"USAGE: .import [OPTIONS] FILE TABLE\n"
2684926850
"\n"
2685026851
"Import CSV or similar text from FILE into TABLE. If TABLE does\n"
2685126852
"not exist, it is created using the first row of FILE as the column\n"
2685226853
"names. If FILE begins with \"|\" then it is a command that is run\n"
26853
-"and the output from the command is used as the input data.\n"
26854
+"and the output from the command is used as the input data. If\n"
26855
+"FILE begins with \"<<\" followed by a label, then content is read from\n"
26856
+"the script until the first line that matches the label.\n"
26857
+"\n"
26858
+"The content of FILE is interpreted using RFC-4180 (\"CSV\") quoting\n"
26859
+"rules unless the current mode is \"ascii\" or \"tabs\" or unless one\n"
26860
+"the --ascii option is used.\n"
2685426861
"\n"
26855
-"FILE is assumed to be in a CSV format, unless the current mode\n"
26856
-"is \"ascii\" or \"tabs\" or unless one of the options below specify\n"
26857
-"an alternative.\n"
26862
+"The column and row separators must be single ASCII characters. If\n"
26863
+"multiple characters or a Unicode character are specified for the\n"
26864
+"separators, then only the first byte of the separator is used. Except,\n"
26865
+"if the row separator is \\n and the mode is not --ascii, then \\r\\n is\n"
26866
+"understood as a row separator too.\n"
2685826867
"\n"
2685926868
"Options:\n"
26860
-" --ascii Use \\037 and \\036 as column and row separators on input\n"
26869
+" --ascii Do not use RFC-4180 quoting. Use \\037 and \\036\n"
26870
+" as column and row separators on input, unless other\n"
26871
+" delimiters are specified using --colsep and/or --rowsep\n"
26872
+" --colsep CHAR Use CHAR as the column separator.\n"
2686126873
" --csv Input is standard RFC-4180 CSV.\n"
26874
+" --rowsep CHAR Use CHAR as the row separator.\n"
2686226875
" --schema S When creating TABLE, put it in schema S\n"
2686326876
" --skip N Ignore the first N rows of input\n"
2686426877
" -v Verbose mode\n"
2686526878
},
2686626879
{ ".mode",
@@ -26987,11 +27000,10 @@
2698727000
"If PATTERN starts with \"<<ENDMARK\" then the actual pattern is taken from\n"
2698827001
"subsequent lines of text up to the first line that begins with ENDMARK.\n"
2698927002
"All pattern lines and the ENDMARK are discarded.\n"
2699027003
"\n"
2699127004
"Options:\n"
26992
-" --error-prefix TEXT Change error message prefix text to TEXT\n"
2699327005
" --exact Do an exact comparison including leading and\n"
2699427006
" trailing whitespace.\n"
2699527007
" --glob Treat PATTERN as a GLOB\n"
2699627008
" --keep Do not reset the testcase. More .check commands\n"
2699727009
" will follow.\n"
@@ -28000,11 +28012,13 @@
2800028012
typedef struct ImportCtx ImportCtx;
2800128013
struct ImportCtx {
2800228014
const char *zFile; /* Name of the input file */
2800328015
FILE *in; /* Read the CSV text from this input stream */
2800428016
int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close in */
28017
+ char *zIn; /* Input text */
2800528018
char *z; /* Accumulated text for a field */
28019
+ i64 nUsed; /* Bytes of zIn[] used so far */
2800628020
i64 n; /* Number of bytes in z */
2800728021
i64 nAlloc; /* Space allocated for z[] */
2800828022
int nLine; /* Current line number */
2800928023
int nRow; /* Number of rows imported */
2801028024
int nErr; /* Number of errors encountered */
@@ -28020,13 +28034,32 @@
2802028034
p->xCloser(p->in);
2802128035
p->in = 0;
2802228036
}
2802328037
sqlite3_free(p->z);
2802428038
p->z = 0;
28039
+ if( p->zIn ){
28040
+ sqlite3_free(p->zIn);
28041
+ p->zIn = 0;
28042
+ }
2802528043
}
2802628044
28027
-/* Append a single byte to z[] */
28045
+/* Read a single character of the .import input text. Return EOF
28046
+** at end-of-file.
28047
+*/
28048
+static int import_getc(ImportCtx *p){
28049
+ if( p->in ){
28050
+ return fgetc(p->in);
28051
+ }else if( p->zIn && p->zIn[p->nUsed]!=0 ){
28052
+ return p->zIn[p->nUsed++];
28053
+ }else{
28054
+ return EOF;
28055
+ }
28056
+}
28057
+
28058
+/* Append a single byte to the field value begin constructed
28059
+** in the p->z[] buffer
28060
+*/
2802828061
static void import_append_char(ImportCtx *p, int c){
2802928062
if( p->n+1>=p->nAlloc ){
2803028063
p->nAlloc += p->nAlloc + 100;
2803128064
p->z = sqlite3_realloc64(p->z, p->nAlloc);
2803228065
shell_check_oom(p->z);
@@ -28038,12 +28071,12 @@
2803828071
** with the option of having a separator other than ",".
2803928072
**
2804028073
** + Input comes from p->in.
2804128074
** + Store results in p->z of length p->n. Space to hold p->z comes
2804228075
** from sqlite3_malloc64().
28043
-** + Use p->cSep as the column separator. The default is ",".
28044
-** + Use p->rSep as the row separator. The default is "\n".
28076
+** + Use p->cColSep as the column separator. The default is ",".
28077
+** + Use p->cRowSep as the row separator. The default is "\n".
2804528078
** + Keep track of the line number in p->nLine.
2804628079
** + Store the character that terminates the field in p->cTerm. Store
2804728080
** EOF on end-of-file.
2804828081
** + Report syntax errors on stderr
2804928082
*/
@@ -28050,11 +28083,11 @@
2805028083
static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){
2805128084
int c;
2805228085
int cSep = (u8)p->cColSep;
2805328086
int rSep = (u8)p->cRowSep;
2805428087
p->n = 0;
28055
- c = fgetc(p->in);
28088
+ c = import_getc(p);
2805628089
if( c==EOF || seenInterrupt ){
2805728090
p->cTerm = EOF;
2805828091
return 0;
2805928092
}
2806028093
if( c=='"' ){
@@ -28061,11 +28094,11 @@
2806128094
int pc, ppc;
2806228095
int startLine = p->nLine;
2806328096
int cQuote = c;
2806428097
pc = ppc = 0;
2806528098
while( 1 ){
28066
- c = fgetc(p->in);
28099
+ c = import_getc(p);
2806728100
if( c==rSep ) p->nLine++;
2806828101
if( c==cQuote ){
2806928102
if( pc==cQuote ){
2807028103
pc = 0;
2807128104
continue;
@@ -28097,24 +28130,24 @@
2809728130
}else{
2809828131
/* If this is the first field being parsed and it begins with the
2809928132
** UTF-8 BOM (0xEF BB BF) then skip the BOM */
2810028133
if( (c&0xff)==0xef && p->bNotFirst==0 ){
2810128134
import_append_char(p, c);
28102
- c = fgetc(p->in);
28135
+ c = import_getc(p);
2810328136
if( (c&0xff)==0xbb ){
2810428137
import_append_char(p, c);
28105
- c = fgetc(p->in);
28138
+ c = import_getc(p);
2810628139
if( (c&0xff)==0xbf ){
2810728140
p->bNotFirst = 1;
2810828141
p->n = 0;
2810928142
return csv_read_one_field(p);
2811028143
}
2811128144
}
2811228145
}
2811328146
while( c!=EOF && c!=cSep && c!=rSep ){
2811428147
import_append_char(p, c);
28115
- c = fgetc(p->in);
28148
+ c = import_getc(p);
2811628149
}
2811728150
if( c==rSep ){
2811828151
p->nLine++;
2811928152
if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
2812028153
}
@@ -28128,12 +28161,12 @@
2812828161
/* Read a single field of ASCII delimited text.
2812928162
**
2813028163
** + Input comes from p->in.
2813128164
** + Store results in p->z of length p->n. Space to hold p->z comes
2813228165
** from sqlite3_malloc64().
28133
-** + Use p->cSep as the column separator. The default is "\x1F".
28134
-** + Use p->rSep as the row separator. The default is "\x1E".
28166
+** + Use p->cColSep as the column separator. The default is "\x1F".
28167
+** + Use p->cRowSep as the row separator. The default is "\x1E".
2813528168
** + Keep track of the row number in p->nLine.
2813628169
** + Store the character that terminates the field in p->cTerm. Store
2813728170
** EOF on end-of-file.
2813828171
** + Report syntax errors on stderr
2813928172
*/
@@ -28140,18 +28173,18 @@
2814028173
static char *SQLITE_CDECL ascii_read_one_field(ImportCtx *p){
2814128174
int c;
2814228175
int cSep = (u8)p->cColSep;
2814328176
int rSep = (u8)p->cRowSep;
2814428177
p->n = 0;
28145
- c = fgetc(p->in);
28178
+ c = import_getc(p);
2814628179
if( c==EOF || seenInterrupt ){
2814728180
p->cTerm = EOF;
2814828181
return 0;
2814928182
}
2815028183
while( c!=EOF && c!=cSep && c!=rSep ){
2815128184
import_append_char(p, c);
28152
- c = fgetc(p->in);
28185
+ c = import_getc(p);
2815328186
}
2815428187
if( c==rSep ){
2815528188
p->nLine++;
2815628189
}
2815728190
p->cTerm = c;
@@ -30452,19 +30485,31 @@
3045230485
** USAGE: .import [OPTIONS] FILE TABLE
3045330486
**
3045430487
** Import CSV or similar text from FILE into TABLE. If TABLE does
3045530488
** not exist, it is created using the first row of FILE as the column
3045630489
** names. If FILE begins with "|" then it is a command that is run
30457
-** and the output from the command is used as the input data.
30490
+** and the output from the command is used as the input data. If
30491
+** FILE begins with "<<" followed by a label, then content is read from
30492
+** the script until the first line that matches the label.
30493
+**
30494
+** The content of FILE is interpreted using RFC-4180 ("CSV") quoting
30495
+** rules unless the current mode is "ascii" or "tabs" or unless one
30496
+** the --ascii option is used.
3045830497
**
30459
-** FILE is assumed to be in a CSV format, unless the current mode
30460
-** is "ascii" or "tabs" or unless one of the options below specify
30461
-** an alternative.
30498
+** The column and row separators must be single ASCII characters. If
30499
+** multiple characters or a Unicode character are specified for the
30500
+** separators, then only the first byte of the separator is used. Except,
30501
+** if the row separator is \n and the mode is not --ascii, then \r\n is
30502
+** understood as a row separator too.
3046230503
**
3046330504
** Options:
30464
-** --ascii Use \037 and \036 as column and row separators on input
30505
+** --ascii Do not use RFC-4180 quoting. Use \037 and \036
30506
+** as column and row separators on input, unless other
30507
+** delimiters are specified using --colsep and/or --rowsep
30508
+** --colsep CHAR Use CHAR as the column separator.
3046530509
** --csv Input is standard RFC-4180 CSV.
30510
+** --rowsep CHAR Use CHAR as the row separator.
3046630511
** --schema S When creating TABLE, put it in schema S
3046730512
** --skip N Ignore the first N rows of input
3046830513
** -v Verbose mode
3046930514
*/
3047030515
static int dotCmdImport(ShellState *p){
@@ -30476,17 +30521,16 @@
3047630521
sqlite3_stmt *pStmt = NULL; /* A statement */
3047730522
int nCol; /* Number of columns in the table */
3047830523
i64 nByte; /* Number of bytes in an SQL string */
3047930524
int i, j; /* Loop counters */
3048030525
int needCommit; /* True to COMMIT or ROLLBACK at end */
30481
- int nSep; /* Number of bytes in spec.zColumnSep */
3048230526
char *zSql = 0; /* An SQL statement */
3048330527
ImportCtx sCtx; /* Reader context */
3048430528
char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
3048530529
int eVerbose = 0; /* Larger for more console output */
3048630530
i64 nSkip = 0; /* Initial lines to skip */
30487
- int useOutputMode = 1; /* Use output mode to determine separators */
30531
+ i64 iLineOffset = 0; /* Offset to the first line of input */
3048830532
char *zCreate = 0; /* CREATE TABLE statement text */
3048930533
int rc; /* Result code */
3049030534
3049130535
failIfSafeMode(p, "cannot run .import in safe mode");
3049230536
memset(&sCtx, 0, sizeof(sCtx));
@@ -30512,70 +30556,67 @@
3051230556
}else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
3051330557
zSchema = azArg[++i];
3051430558
}else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
3051530559
nSkip = integerValue(azArg[++i]);
3051630560
}else if( cli_strcmp(z,"-ascii")==0 ){
30517
- sCtx.cColSep = SEP_Unit[0];
30518
- sCtx.cRowSep = SEP_Record[0];
30561
+ if( sCtx.cColSep==0 ) sCtx.cColSep = SEP_Unit[0];
30562
+ if( sCtx.cRowSep==0 ) sCtx.cRowSep = SEP_Record[0];
3051930563
xRead = ascii_read_one_field;
30520
- useOutputMode = 0;
3052130564
}else if( cli_strcmp(z,"-csv")==0 ){
30522
- sCtx.cColSep = ',';
30523
- sCtx.cRowSep = '\n';
30565
+ if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
30566
+ if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
3052430567
xRead = csv_read_one_field;
30525
- useOutputMode = 0;
30568
+ }else if( cli_strcmp(z,"-colsep")==0 ){
30569
+ if( i==nArg-1 ){
30570
+ dotCmdError(p, i, "missing argument", 0);
30571
+ return 1;
30572
+ }
30573
+ i++;
30574
+ sCtx.cColSep = azArg[i][0];
30575
+ }else if( cli_strcmp(z,"-rowsep")==0 ){
30576
+ if( i==nArg-1 ){
30577
+ dotCmdError(p, i, "missing argument", 0);
30578
+ return 1;
30579
+ }
30580
+ i++;
30581
+ sCtx.cRowSep = azArg[i][0];
3052630582
}else{
3052730583
dotCmdError(p, i, "unknown option", 0);
3052830584
return 1;
3052930585
}
3053030586
}
3053130587
if( zTable==0 ){
30532
- cli_printf(p->out, "ERROR: missing %s argument\n",
30588
+ dotCmdError(p, nArg, 0, "Missing %s argument\n",
3053330589
zFile==0 ? "FILE" : "TABLE");
3053430590
return 1;
3053530591
}
3053630592
seenInterrupt = 0;
3053730593
open_db(p, 0);
30538
- if( useOutputMode ){
30539
- /* If neither the --csv or --ascii options are specified, then set
30540
- ** the column and row separator characters from the output mode. */
30541
- if( p->mode.spec.zColumnSep==0 ){
30542
- modeSetStr(&p->mode.spec.zColumnSep, ",");
30543
- nSep = 1;
30544
- }else if( (nSep = strlen30(p->mode.spec.zColumnSep))==0 ){
30545
- eputz("Error: non-null column separator required for import\n");
30546
- return 1;
30547
- }
30548
- if( nSep>1 ){
30549
- eputz("Error: multi-character column separators not allowed"
30550
- " for import\n");
30551
- return 1;
30552
- }
30553
- if( p->mode.spec.zRowSep==0 ){
30554
- modeSetStr(&p->mode.spec.zRowSep, "\n");
30555
- nSep = 1;
30556
- }else if( (nSep = strlen30(p->mode.spec.zRowSep))==0 ){
30557
- eputz("Error: non-null row separator required for import\n");
30558
- return 1;
30559
- }
30560
- if( nSep==2 && p->mode.eMode==MODE_Csv
30561
- && cli_strcmp(p->mode.spec.zRowSep,SEP_CrLf)==0
30562
- ){
30563
- /* When importing CSV (only), if the row separator is set to the
30564
- ** default output row separator, change it to the default input
30565
- ** row separator. This avoids having to maintain different input
30566
- ** and output row separators. */
30567
- modeSetStr(&p->mode.spec.zRowSep, SEP_Row);
30568
- nSep = strlen30(p->mode.spec.zRowSep);
30569
- }
30570
- if( nSep>1 ){
30571
- eputz("Error: multi-character row separators not allowed"
30572
- " for import\n");
30573
- return 1;
30574
- }
30575
- sCtx.cColSep = (u8)p->mode.spec.zColumnSep[0];
30576
- sCtx.cRowSep = (u8)p->mode.spec.zRowSep[0];
30594
+ if( sCtx.cColSep==0 ){
30595
+ if( p->mode.spec.zColumnSep && p->mode.spec.zColumnSep[0]!=0 ){
30596
+ sCtx.cColSep = p->mode.spec.zColumnSep[0];
30597
+ }else{
30598
+ sCtx.cColSep = ',';
30599
+ }
30600
+ }
30601
+ if( (sCtx.cColSep & 0x80)!=0 ){
30602
+ eputz("Error: .import column separator must be ASCII\n");
30603
+ return 1;
30604
+ }
30605
+ if( sCtx.cRowSep==0 ){
30606
+ if( p->mode.spec.zRowSep && p->mode.spec.zRowSep[0]!=0 ){
30607
+ sCtx.cRowSep = p->mode.spec.zRowSep[0];
30608
+ }else{
30609
+ sCtx.cRowSep = '\n';
30610
+ }
30611
+ }
30612
+ if( sCtx.cRowSep=='\r' && xRead!=ascii_read_one_field ){
30613
+ sCtx.cRowSep = '\n';
30614
+ }
30615
+ if( (sCtx.cRowSep & 0x80)!=0 ){
30616
+ eputz("Error: .import row separator must be ASCII\n");
30617
+ return 1;
3057730618
}
3057830619
sCtx.zFile = zFile;
3057930620
sCtx.nLine = 1;
3058030621
if( sCtx.zFile[0]=='|' ){
3058130622
#ifdef SQLITE_OMIT_POPEN
@@ -30584,19 +30625,58 @@
3058430625
#else
3058530626
sCtx.in = sqlite3_popen(sCtx.zFile+1, "r");
3058630627
sCtx.zFile = "<pipe>";
3058730628
sCtx.xCloser = pclose;
3058830629
#endif
30630
+ }else if( sCtx.zFile[0]=='<' && sCtx.zFile[1]=='<' && sCtx.zFile[2]!=0 ){
30631
+ /* Input text comes from subsequent lines of script until the zFile
30632
+ ** delimiter */
30633
+ int nEndMark = strlen30(zFile)-2;
30634
+ char *zEndMark = &zFile[2];
30635
+ sqlite3_str *pContent = sqlite3_str_new(p->db);
30636
+ int ckEnd = 1;
30637
+ i64 iStart = p->lineno;
30638
+ char zLine[2000];
30639
+ sCtx.zFile = p->zInFile;
30640
+ sCtx.nLine = p->lineno+1;
30641
+ iLineOffset = p->lineno;
30642
+ while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
30643
+ if( ckEnd && cli_strncmp(zLine,zEndMark,nEndMark)==0 ){
30644
+ ckEnd = 2;
30645
+ if( strchr(zLine,'\n') ) p->lineno++;
30646
+ break;
30647
+ }
30648
+ if( strchr(zLine,'\n') ){
30649
+ p->lineno++;
30650
+ ckEnd = 1;
30651
+ }else{
30652
+ ckEnd = 0;
30653
+ }
30654
+ sqlite3_str_appendall(pContent, zLine);
30655
+ }
30656
+ sCtx.zIn = sqlite3_str_finish(pContent);
30657
+ if( sCtx.zIn==0 ){
30658
+ sCtx.zIn = sqlite3_mprintf("");
30659
+ }
30660
+ if( ckEnd<2 ){
30661
+ i64 savedLn = p->lineno;
30662
+ p->lineno = iStart;
30663
+ dotCmdError(p, 0, 0,"Content terminator \"%s\" not found.",zEndMark);
30664
+ p->lineno = savedLn;
30665
+ import_cleanup(&sCtx);
30666
+ return 1;
30667
+ }
3058930668
}else{
3059030669
sCtx.in = sqlite3_fopen(sCtx.zFile, "rb");
3059130670
sCtx.xCloser = fclose;
3059230671
}
30593
- if( sCtx.in==0 ){
30594
- cli_printf(stderr,"Error: cannot open \"%s\"\n", zFile);
30672
+ if( sCtx.in==0 && sCtx.zIn==0 ){
30673
+ dotCmdError(p, 0, 0, "cannot open \"%s\"", zFile);
30674
+ import_cleanup(&sCtx);
3059530675
return 1;
3059630676
}
30597
- if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
30677
+ if( eVerbose>=1 ){
3059830678
char zSep[2];
3059930679
zSep[1] = 0;
3060030680
zSep[0] = sCtx.cColSep;
3060130681
cli_puts("Column separator ", p->out);
3060230682
output_c_string(p->out, zSep);
@@ -30749,10 +30829,14 @@
3074930829
if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){
3075030830
z = "";
3075130831
}
3075230832
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
3075330833
if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
30834
+ if( i==0 && (strcmp(z,"\n")==0 || strcmp(z,"\r\n")==0) ){
30835
+ /* Ignore trailing \n or \r\n when some other row separator */
30836
+ break;
30837
+ }
3075430838
cli_printf(stderr,"%s:%d: expected %d columns but found %d"
3075530839
" - filling the rest with NULL\n",
3075630840
sCtx.zFile, startLine, nCol, i+1);
3075730841
i += 2;
3075830842
while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
@@ -30772,10 +30856,11 @@
3077230856
rc = sqlite3_reset(pStmt);
3077330857
if( rc!=SQLITE_OK ){
3077430858
cli_printf(stderr,"%s:%d: INSERT failed: %s\n",
3077530859
sCtx.zFile, startLine, sqlite3_errmsg(p->db));
3077630860
sCtx.nErr++;
30861
+ if( bail_on_error ) break;
3077730862
}else{
3077830863
sCtx.nRow++;
3077930864
}
3078030865
}
3078130866
}while( sCtx.cTerm!=EOF );
@@ -30784,13 +30869,13 @@
3078430869
sqlite3_finalize(pStmt);
3078530870
if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
3078630871
if( eVerbose>0 ){
3078730872
cli_printf(p->out,
3078830873
"Added %d rows with %d errors using %d lines of input\n",
30789
- sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
30874
+ sCtx.nRow, sCtx.nErr, sCtx.nLine-1-iLineOffset);
3079030875
}
30791
- return 0;
30876
+ return sCtx.nErr ? 1 : 0;
3079230877
}
3079330878
3079430879
3079530880
/*
3079630881
** This function computes what to show the user about the configured
@@ -31657,11 +31742,10 @@
3165731742
** If PATTERN starts with "<<ENDMARK" then the actual pattern is taken from
3165831743
** subsequent lines of text up to the first line that begins with ENDMARK.
3165931744
** All pattern lines and the ENDMARK are discarded.
3166031745
**
3166131746
** Options:
31662
-** --error-prefix TEXT Change error message prefix text to TEXT
3166331747
** --exact Do an exact comparison including leading and
3166431748
** trailing whitespace.
3166531749
** --glob Treat PATTERN as a GLOB
3166631750
** --keep Do not reset the testcase. More .check commands
3166731751
** will follow.
@@ -31712,11 +31796,11 @@
3171231796
}
3171331797
if( zCheck==0 ){
3171431798
dotCmdError(p, 0, "no PATTERN specified", 0);
3171531799
return 1;
3171631800
}
31717
- if( cli_output_capture ){
31801
+ if( cli_output_capture && sqlite3_str_length(cli_output_capture) ){
3171831802
zTest = sqlite3_str_value(cli_output_capture);
3171931803
shell_check_oom(zTest);
3172031804
}else{
3172131805
zTest = "";
3172231806
}
@@ -33450,12 +33534,11 @@
3345033534
" rootpage integer,\n"
3345133535
" sql text\n"
3345233536
");\n", zName);
3345333537
}
3345433538
}
33455
- rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
33456
- -1, &pStmt, 0);
33539
+ rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
3345733540
if( rc ){
3345833541
shellDatabaseError(p->db);
3345933542
sqlite3_finalize(pStmt);
3346033543
3346133544
rc = 1;
@@ -33463,11 +33546,11 @@
3346333546
}
3346433547
pSql = sqlite3_str_new(p->db);
3346533548
sqlite3_str_appendf(pSql, "SELECT sql FROM", 0);
3346633549
iSchema = 0;
3346733550
while( sqlite3_step(pStmt)==SQLITE_ROW ){
33468
- const char *zDb = (const char*)sqlite3_column_text(pStmt, 0);
33551
+ const char *zDb = (const char*)sqlite3_column_text(pStmt, 1);
3346933552
char zScNum[30];
3347033553
sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
3347133554
sqlite3_str_appendall(pSql, zDiv);
3347233555
zDiv = " UNION ALL ";
3347333556
if( sqlite3_stricmp(zDb, "main")==0 ){
@@ -33483,11 +33566,12 @@
3348333566
" AS sql, type, tbl_name, name, rowid, %d AS snum, %Q as sname",
3348433567
++iSchema, zDb);
3348533568
sqlite3_str_appendf(pSql," FROM \"%w\".sqlite_schema", zDb);
3348633569
}
3348733570
sqlite3_finalize(pStmt);
33488
-#ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
33571
+#if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS) \
33572
+ && !defined(SQLITE_OMIT_VIRTUALTABLE)
3348933573
if( zName ){
3349033574
sqlite3_str_appendall(pSql,
3349133575
" UNION ALL SELECT shell_module_schema(name),"
3349233576
" 'table', name, name, name, 9e+99, 'main' FROM pragma_module_list");
3349333577
}
@@ -35690,29 +35774,65 @@
3569035774
cli_puts(z, p->out);
3569135775
fflush(p->out);
3569235776
return 1;
3569335777
}
3569435778
35695
-#ifndef SQLITE_SHELL_IS_UTF8
35696
-# if (defined(_WIN32) || defined(WIN32)) \
35697
- && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
35698
-# define SQLITE_SHELL_IS_UTF8 (0)
35699
-# else
35700
-# define SQLITE_SHELL_IS_UTF8 (1)
35701
-# endif
35702
-#endif
35703
-
35779
+/* Alternative name to the entry point for Fiddle */
3570435780
#ifdef SQLITE_SHELL_FIDDLE
3570535781
# define main fiddle_main
3570635782
#endif
3570735783
35708
-#if SQLITE_SHELL_IS_UTF8
35709
-int SQLITE_CDECL main(int argc, char **argv){
35710
-#else
35784
+/* Use the wmain() entry point on Windows. Translate arguments to
35785
+** UTF8, then invoke the traditional main() entry point which is
35786
+** renamed using a #define to utf8_main() .
35787
+*/
35788
+#if defined(_WIN32) && !defined(main)
35789
+# define main utf8_main /* Rename entry point to utf_main() */
35790
+int SQLITE_CDECL utf8_main(int,char**); /* Forward declaration */
3571135791
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
35712
- char **argv;
35713
-#endif
35792
+ int rc, i;
35793
+ char **argv = malloc( sizeof(char*) * (argc+1) );
35794
+ char **orig = argv;
35795
+ if( argv==0 ){
35796
+ fprintf(stderr, "malloc failed\n");
35797
+ exit(1);
35798
+ }
35799
+ for(i=0; i<argc; i++){
35800
+ int nByte = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, 0, 0, 0, 0);
35801
+ if( nByte==0 ){
35802
+ argv[i] = 0;
35803
+ }else{
35804
+ argv[i] = malloc( nByte );
35805
+ if( argv[i]==0 ){
35806
+ fprintf(stderr, "malloc failed\n");
35807
+ exit(1);
35808
+ }
35809
+ nByte = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i],nByte,0,0);
35810
+ if( nByte==0 ){
35811
+ free(argv[i]);
35812
+ argv[i] = 0;
35813
+ }
35814
+ }
35815
+ }
35816
+ argv[argc] = 0;
35817
+ rc = utf8_main(argc, argv);
35818
+ for(i=0; i<argc; i++) free(orig[i]);
35819
+ free(argv);
35820
+ return rc;
35821
+}
35822
+#endif /* WIN32 */
35823
+
35824
+/*
35825
+** This is the main entry point for the process. Everything starts here.
35826
+**
35827
+** The "main" identifier may have been #defined to something else:
35828
+**
35829
+** utf8_main On Windows
35830
+** fiddle_main In Fiddle
35831
+** sqlite3_shell Other projects that use shell.c as a subroutine
35832
+*/
35833
+int SQLITE_CDECL main(int argc, char **argv){
3571435834
#ifdef SQLITE_DEBUG
3571535835
sqlite3_int64 mem_main_enter = 0;
3571635836
#endif
3571735837
char *zErrMsg = 0;
3571835838
#ifdef SQLITE_SHELL_FIDDLE
@@ -35730,14 +35850,10 @@
3573035850
int nOptsEnd = argc;
3573135851
int bEnableVfstrace = 0;
3573235852
char **azCmd = 0;
3573335853
int *aiCmd = 0;
3573435854
const char *zVfs = 0; /* Value of -vfs command-line option */
35735
-#if !SQLITE_SHELL_IS_UTF8
35736
- char **argvToFree = 0;
35737
- int argcToFree = 0;
35738
-#endif
3573935855
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
3574035856
3574135857
#ifdef SQLITE_SHELL_FIDDLE
3574235858
stdin_is_interactive = 0;
3574335859
stdout_is_console = 1;
@@ -35788,36 +35904,10 @@
3578835904
exit(1);
3578935905
}
3579035906
#endif
3579135907
main_init(&data);
3579235908
35793
- /* On Windows, we must translate command-line arguments into UTF-8.
35794
- ** The SQLite memory allocator subsystem has to be enabled in order to
35795
- ** do this. But we want to run an sqlite3_shutdown() afterwards so that
35796
- ** subsequent sqlite3_config() calls will work. So copy all results into
35797
- ** memory that does not come from the SQLite memory allocator.
35798
- */
35799
-#if !SQLITE_SHELL_IS_UTF8
35800
- sqlite3_initialize();
35801
- argvToFree = malloc(sizeof(argv[0])*argc*2);
35802
- shell_check_oom(argvToFree);
35803
- argcToFree = argc;
35804
- argv = argvToFree + argc;
35805
- for(i=0; i<argc; i++){
35806
- char *z = sqlite3_win32_unicode_to_utf8(wargv[i]);
35807
- i64 n;
35808
- shell_check_oom(z);
35809
- n = strlen(z);
35810
- argv[i] = malloc( n+1 );
35811
- shell_check_oom(argv[i]);
35812
- memcpy(argv[i], z, n+1);
35813
- argvToFree[i] = argv[i];
35814
- sqlite3_free(z);
35815
- }
35816
- sqlite3_shutdown();
35817
-#endif
35818
-
3581935909
assert( argc>=1 && argv && argv[0] );
3582035910
Argv0 = argv[0];
3582135911
3582235912
#ifdef SQLITE_SHELL_DBNAME_PROC
3582335913
{
@@ -36009,10 +36099,20 @@
3600936099
}else if( cli_strcmp(z,"-safe")==0 ){
3601036100
/* no-op - catch this on the second pass */
3601136101
}else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
3601236102
/* skip over the argument */
3601336103
i++;
36104
+ }else if( cli_strcmp(z,"-test-argv")==0 ){
36105
+ /* Undocumented test option. Print the values in argv[] and exit.
36106
+ ** Use this to verify that any translation of the argv[], for example
36107
+ ** on Windows that receives wargv[] from the OS and must convert
36108
+ ** to UTF8 prior to calling this routine. */
36109
+ int kk;
36110
+ for(kk=0; kk<argc; kk++){
36111
+ sqlite3_fprintf(stdout,"argv[%d] = \"%s\"\n", kk, argv[kk]);
36112
+ }
36113
+ return 0;
3601436114
}
3601536115
}
3601636116
#ifndef SQLITE_SHELL_FIDDLE
3601736117
if( !bEnableVfstrace ) verify_uninitialized();
3601836118
#endif
@@ -36427,14 +36527,10 @@
3642736527
}
3642836528
find_home_dir(1);
3642936529
output_reset(&data);
3643036530
data.doXdgOpen = 0;
3643136531
clearTempFile(&data);
36432
-#if !SQLITE_SHELL_IS_UTF8
36433
- for(i=0; i<argcToFree; i++) free(argvToFree[i]);
36434
- free(argvToFree);
36435
-#endif
3643636532
modeFree(&data.mode);
3643736533
if( data.nSavedModes ){
3643836534
int ii;
3643936535
for(ii=0; ii<data.nSavedModes; ii++){
3644036536
modeFree(&data.aSavedModes[ii].mode);
3644136537
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -35,11 +35,11 @@
35 ** ext/recover/sqlite3recover.h
36 ** src/shell.c.in
37 **
38 ** To modify this program, get a copy of the canonical SQLite source tree,
39 ** edit the src/shell.c.in file and/or some of the other files that are
40 ** listed above, then rerun the rerun "make shell.c".
41 */
42 /************************* Begin src/shell.c.in ******************/
43 /*
44 ** 2001 September 15
45 **
@@ -49,11 +49,11 @@
49 ** May you do good and not evil.
50 ** May you find forgiveness for yourself and forgive others.
51 ** May you share freely, never taking more than you give.
52 **
53 *************************************************************************
54 ** This file contains code to implement the "sqlite" command line
55 ** utility for accessing SQLite databases.
56 */
57 #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
58 /* This needs to come before any includes for MSVC compiler */
59 #define _CRT_SECURE_NO_WARNINGS
@@ -4070,10 +4070,18 @@
4070 #define PROMPT_LEN_MAX 128
4071 /* First line prompt. default: "sqlite> " */
4072 static char mainPrompt[PROMPT_LEN_MAX];
4073 /* Continuation prompt. default: " ...> " */
4074 static char continuePrompt[PROMPT_LEN_MAX];
 
 
 
 
 
 
 
 
4075
4076 /* This is variant of the standard-library strncpy() routine with the
4077 ** one change that the destination string is always zero-terminated, even
4078 ** if there is no zero-terminator in the first n-1 characters of the source
4079 ** string.
@@ -4190,17 +4198,10 @@
4190 */
4191 static void shell_check_oom(const void *p){
4192 if( p==0 ) shell_out_of_memory();
4193 }
4194
4195 /*
4196 ** Write I/O traces to the following stream.
4197 */
4198 #ifdef SQLITE_ENABLE_IOTRACE
4199 static FILE *iotrace = 0;
4200 #endif
4201
4202 /*
4203 ** This routine works like printf in that its first argument is a
4204 ** format string and subsequent arguments are values to be substituted
4205 ** in place of % fields. The result of formatting this string
4206 ** is written to iotrace.
@@ -8351,13 +8352,13 @@
8351 }else if( e<-10000 ){
8352 e = -10000;
8353 }
8354
8355 if( m<0 ){
 
8356 isNeg = 1;
8357 m = -m;
8358 if( m<0 ) return;
8359 }else if( m==0 && e>-1000 && e<1000 ){
8360 sqlite3_result_double(context, 0.0);
8361 return;
8362 }
8363 while( (m>>32)&0xffe00000 ){
@@ -26848,19 +26849,31 @@
26848 "USAGE: .import [OPTIONS] FILE TABLE\n"
26849 "\n"
26850 "Import CSV or similar text from FILE into TABLE. If TABLE does\n"
26851 "not exist, it is created using the first row of FILE as the column\n"
26852 "names. If FILE begins with \"|\" then it is a command that is run\n"
26853 "and the output from the command is used as the input data.\n"
 
 
 
 
 
 
26854 "\n"
26855 "FILE is assumed to be in a CSV format, unless the current mode\n"
26856 "is \"ascii\" or \"tabs\" or unless one of the options below specify\n"
26857 "an alternative.\n"
 
 
26858 "\n"
26859 "Options:\n"
26860 " --ascii Use \\037 and \\036 as column and row separators on input\n"
 
 
 
26861 " --csv Input is standard RFC-4180 CSV.\n"
 
26862 " --schema S When creating TABLE, put it in schema S\n"
26863 " --skip N Ignore the first N rows of input\n"
26864 " -v Verbose mode\n"
26865 },
26866 { ".mode",
@@ -26987,11 +27000,10 @@
26987 "If PATTERN starts with \"<<ENDMARK\" then the actual pattern is taken from\n"
26988 "subsequent lines of text up to the first line that begins with ENDMARK.\n"
26989 "All pattern lines and the ENDMARK are discarded.\n"
26990 "\n"
26991 "Options:\n"
26992 " --error-prefix TEXT Change error message prefix text to TEXT\n"
26993 " --exact Do an exact comparison including leading and\n"
26994 " trailing whitespace.\n"
26995 " --glob Treat PATTERN as a GLOB\n"
26996 " --keep Do not reset the testcase. More .check commands\n"
26997 " will follow.\n"
@@ -28000,11 +28012,13 @@
28000 typedef struct ImportCtx ImportCtx;
28001 struct ImportCtx {
28002 const char *zFile; /* Name of the input file */
28003 FILE *in; /* Read the CSV text from this input stream */
28004 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close in */
 
28005 char *z; /* Accumulated text for a field */
 
28006 i64 n; /* Number of bytes in z */
28007 i64 nAlloc; /* Space allocated for z[] */
28008 int nLine; /* Current line number */
28009 int nRow; /* Number of rows imported */
28010 int nErr; /* Number of errors encountered */
@@ -28020,13 +28034,32 @@
28020 p->xCloser(p->in);
28021 p->in = 0;
28022 }
28023 sqlite3_free(p->z);
28024 p->z = 0;
 
 
 
 
28025 }
28026
28027 /* Append a single byte to z[] */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28028 static void import_append_char(ImportCtx *p, int c){
28029 if( p->n+1>=p->nAlloc ){
28030 p->nAlloc += p->nAlloc + 100;
28031 p->z = sqlite3_realloc64(p->z, p->nAlloc);
28032 shell_check_oom(p->z);
@@ -28038,12 +28071,12 @@
28038 ** with the option of having a separator other than ",".
28039 **
28040 ** + Input comes from p->in.
28041 ** + Store results in p->z of length p->n. Space to hold p->z comes
28042 ** from sqlite3_malloc64().
28043 ** + Use p->cSep as the column separator. The default is ",".
28044 ** + Use p->rSep as the row separator. The default is "\n".
28045 ** + Keep track of the line number in p->nLine.
28046 ** + Store the character that terminates the field in p->cTerm. Store
28047 ** EOF on end-of-file.
28048 ** + Report syntax errors on stderr
28049 */
@@ -28050,11 +28083,11 @@
28050 static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){
28051 int c;
28052 int cSep = (u8)p->cColSep;
28053 int rSep = (u8)p->cRowSep;
28054 p->n = 0;
28055 c = fgetc(p->in);
28056 if( c==EOF || seenInterrupt ){
28057 p->cTerm = EOF;
28058 return 0;
28059 }
28060 if( c=='"' ){
@@ -28061,11 +28094,11 @@
28061 int pc, ppc;
28062 int startLine = p->nLine;
28063 int cQuote = c;
28064 pc = ppc = 0;
28065 while( 1 ){
28066 c = fgetc(p->in);
28067 if( c==rSep ) p->nLine++;
28068 if( c==cQuote ){
28069 if( pc==cQuote ){
28070 pc = 0;
28071 continue;
@@ -28097,24 +28130,24 @@
28097 }else{
28098 /* If this is the first field being parsed and it begins with the
28099 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */
28100 if( (c&0xff)==0xef && p->bNotFirst==0 ){
28101 import_append_char(p, c);
28102 c = fgetc(p->in);
28103 if( (c&0xff)==0xbb ){
28104 import_append_char(p, c);
28105 c = fgetc(p->in);
28106 if( (c&0xff)==0xbf ){
28107 p->bNotFirst = 1;
28108 p->n = 0;
28109 return csv_read_one_field(p);
28110 }
28111 }
28112 }
28113 while( c!=EOF && c!=cSep && c!=rSep ){
28114 import_append_char(p, c);
28115 c = fgetc(p->in);
28116 }
28117 if( c==rSep ){
28118 p->nLine++;
28119 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
28120 }
@@ -28128,12 +28161,12 @@
28128 /* Read a single field of ASCII delimited text.
28129 **
28130 ** + Input comes from p->in.
28131 ** + Store results in p->z of length p->n. Space to hold p->z comes
28132 ** from sqlite3_malloc64().
28133 ** + Use p->cSep as the column separator. The default is "\x1F".
28134 ** + Use p->rSep as the row separator. The default is "\x1E".
28135 ** + Keep track of the row number in p->nLine.
28136 ** + Store the character that terminates the field in p->cTerm. Store
28137 ** EOF on end-of-file.
28138 ** + Report syntax errors on stderr
28139 */
@@ -28140,18 +28173,18 @@
28140 static char *SQLITE_CDECL ascii_read_one_field(ImportCtx *p){
28141 int c;
28142 int cSep = (u8)p->cColSep;
28143 int rSep = (u8)p->cRowSep;
28144 p->n = 0;
28145 c = fgetc(p->in);
28146 if( c==EOF || seenInterrupt ){
28147 p->cTerm = EOF;
28148 return 0;
28149 }
28150 while( c!=EOF && c!=cSep && c!=rSep ){
28151 import_append_char(p, c);
28152 c = fgetc(p->in);
28153 }
28154 if( c==rSep ){
28155 p->nLine++;
28156 }
28157 p->cTerm = c;
@@ -30452,19 +30485,31 @@
30452 ** USAGE: .import [OPTIONS] FILE TABLE
30453 **
30454 ** Import CSV or similar text from FILE into TABLE. If TABLE does
30455 ** not exist, it is created using the first row of FILE as the column
30456 ** names. If FILE begins with "|" then it is a command that is run
30457 ** and the output from the command is used as the input data.
 
 
 
 
 
 
30458 **
30459 ** FILE is assumed to be in a CSV format, unless the current mode
30460 ** is "ascii" or "tabs" or unless one of the options below specify
30461 ** an alternative.
 
 
30462 **
30463 ** Options:
30464 ** --ascii Use \037 and \036 as column and row separators on input
 
 
 
30465 ** --csv Input is standard RFC-4180 CSV.
 
30466 ** --schema S When creating TABLE, put it in schema S
30467 ** --skip N Ignore the first N rows of input
30468 ** -v Verbose mode
30469 */
30470 static int dotCmdImport(ShellState *p){
@@ -30476,17 +30521,16 @@
30476 sqlite3_stmt *pStmt = NULL; /* A statement */
30477 int nCol; /* Number of columns in the table */
30478 i64 nByte; /* Number of bytes in an SQL string */
30479 int i, j; /* Loop counters */
30480 int needCommit; /* True to COMMIT or ROLLBACK at end */
30481 int nSep; /* Number of bytes in spec.zColumnSep */
30482 char *zSql = 0; /* An SQL statement */
30483 ImportCtx sCtx; /* Reader context */
30484 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
30485 int eVerbose = 0; /* Larger for more console output */
30486 i64 nSkip = 0; /* Initial lines to skip */
30487 int useOutputMode = 1; /* Use output mode to determine separators */
30488 char *zCreate = 0; /* CREATE TABLE statement text */
30489 int rc; /* Result code */
30490
30491 failIfSafeMode(p, "cannot run .import in safe mode");
30492 memset(&sCtx, 0, sizeof(sCtx));
@@ -30512,70 +30556,67 @@
30512 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
30513 zSchema = azArg[++i];
30514 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
30515 nSkip = integerValue(azArg[++i]);
30516 }else if( cli_strcmp(z,"-ascii")==0 ){
30517 sCtx.cColSep = SEP_Unit[0];
30518 sCtx.cRowSep = SEP_Record[0];
30519 xRead = ascii_read_one_field;
30520 useOutputMode = 0;
30521 }else if( cli_strcmp(z,"-csv")==0 ){
30522 sCtx.cColSep = ',';
30523 sCtx.cRowSep = '\n';
30524 xRead = csv_read_one_field;
30525 useOutputMode = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
30526 }else{
30527 dotCmdError(p, i, "unknown option", 0);
30528 return 1;
30529 }
30530 }
30531 if( zTable==0 ){
30532 cli_printf(p->out, "ERROR: missing %s argument\n",
30533 zFile==0 ? "FILE" : "TABLE");
30534 return 1;
30535 }
30536 seenInterrupt = 0;
30537 open_db(p, 0);
30538 if( useOutputMode ){
30539 /* If neither the --csv or --ascii options are specified, then set
30540 ** the column and row separator characters from the output mode. */
30541 if( p->mode.spec.zColumnSep==0 ){
30542 modeSetStr(&p->mode.spec.zColumnSep, ",");
30543 nSep = 1;
30544 }else if( (nSep = strlen30(p->mode.spec.zColumnSep))==0 ){
30545 eputz("Error: non-null column separator required for import\n");
30546 return 1;
30547 }
30548 if( nSep>1 ){
30549 eputz("Error: multi-character column separators not allowed"
30550 " for import\n");
30551 return 1;
30552 }
30553 if( p->mode.spec.zRowSep==0 ){
30554 modeSetStr(&p->mode.spec.zRowSep, "\n");
30555 nSep = 1;
30556 }else if( (nSep = strlen30(p->mode.spec.zRowSep))==0 ){
30557 eputz("Error: non-null row separator required for import\n");
30558 return 1;
30559 }
30560 if( nSep==2 && p->mode.eMode==MODE_Csv
30561 && cli_strcmp(p->mode.spec.zRowSep,SEP_CrLf)==0
30562 ){
30563 /* When importing CSV (only), if the row separator is set to the
30564 ** default output row separator, change it to the default input
30565 ** row separator. This avoids having to maintain different input
30566 ** and output row separators. */
30567 modeSetStr(&p->mode.spec.zRowSep, SEP_Row);
30568 nSep = strlen30(p->mode.spec.zRowSep);
30569 }
30570 if( nSep>1 ){
30571 eputz("Error: multi-character row separators not allowed"
30572 " for import\n");
30573 return 1;
30574 }
30575 sCtx.cColSep = (u8)p->mode.spec.zColumnSep[0];
30576 sCtx.cRowSep = (u8)p->mode.spec.zRowSep[0];
30577 }
30578 sCtx.zFile = zFile;
30579 sCtx.nLine = 1;
30580 if( sCtx.zFile[0]=='|' ){
30581 #ifdef SQLITE_OMIT_POPEN
@@ -30584,19 +30625,58 @@
30584 #else
30585 sCtx.in = sqlite3_popen(sCtx.zFile+1, "r");
30586 sCtx.zFile = "<pipe>";
30587 sCtx.xCloser = pclose;
30588 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30589 }else{
30590 sCtx.in = sqlite3_fopen(sCtx.zFile, "rb");
30591 sCtx.xCloser = fclose;
30592 }
30593 if( sCtx.in==0 ){
30594 cli_printf(stderr,"Error: cannot open \"%s\"\n", zFile);
 
30595 return 1;
30596 }
30597 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
30598 char zSep[2];
30599 zSep[1] = 0;
30600 zSep[0] = sCtx.cColSep;
30601 cli_puts("Column separator ", p->out);
30602 output_c_string(p->out, zSep);
@@ -30749,10 +30829,14 @@
30749 if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){
30750 z = "";
30751 }
30752 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
30753 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
 
 
 
 
30754 cli_printf(stderr,"%s:%d: expected %d columns but found %d"
30755 " - filling the rest with NULL\n",
30756 sCtx.zFile, startLine, nCol, i+1);
30757 i += 2;
30758 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
@@ -30772,10 +30856,11 @@
30772 rc = sqlite3_reset(pStmt);
30773 if( rc!=SQLITE_OK ){
30774 cli_printf(stderr,"%s:%d: INSERT failed: %s\n",
30775 sCtx.zFile, startLine, sqlite3_errmsg(p->db));
30776 sCtx.nErr++;
 
30777 }else{
30778 sCtx.nRow++;
30779 }
30780 }
30781 }while( sCtx.cTerm!=EOF );
@@ -30784,13 +30869,13 @@
30784 sqlite3_finalize(pStmt);
30785 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
30786 if( eVerbose>0 ){
30787 cli_printf(p->out,
30788 "Added %d rows with %d errors using %d lines of input\n",
30789 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
30790 }
30791 return 0;
30792 }
30793
30794
30795 /*
30796 ** This function computes what to show the user about the configured
@@ -31657,11 +31742,10 @@
31657 ** If PATTERN starts with "<<ENDMARK" then the actual pattern is taken from
31658 ** subsequent lines of text up to the first line that begins with ENDMARK.
31659 ** All pattern lines and the ENDMARK are discarded.
31660 **
31661 ** Options:
31662 ** --error-prefix TEXT Change error message prefix text to TEXT
31663 ** --exact Do an exact comparison including leading and
31664 ** trailing whitespace.
31665 ** --glob Treat PATTERN as a GLOB
31666 ** --keep Do not reset the testcase. More .check commands
31667 ** will follow.
@@ -31712,11 +31796,11 @@
31712 }
31713 if( zCheck==0 ){
31714 dotCmdError(p, 0, "no PATTERN specified", 0);
31715 return 1;
31716 }
31717 if( cli_output_capture ){
31718 zTest = sqlite3_str_value(cli_output_capture);
31719 shell_check_oom(zTest);
31720 }else{
31721 zTest = "";
31722 }
@@ -33450,12 +33534,11 @@
33450 " rootpage integer,\n"
33451 " sql text\n"
33452 ");\n", zName);
33453 }
33454 }
33455 rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
33456 -1, &pStmt, 0);
33457 if( rc ){
33458 shellDatabaseError(p->db);
33459 sqlite3_finalize(pStmt);
33460
33461 rc = 1;
@@ -33463,11 +33546,11 @@
33463 }
33464 pSql = sqlite3_str_new(p->db);
33465 sqlite3_str_appendf(pSql, "SELECT sql FROM", 0);
33466 iSchema = 0;
33467 while( sqlite3_step(pStmt)==SQLITE_ROW ){
33468 const char *zDb = (const char*)sqlite3_column_text(pStmt, 0);
33469 char zScNum[30];
33470 sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
33471 sqlite3_str_appendall(pSql, zDiv);
33472 zDiv = " UNION ALL ";
33473 if( sqlite3_stricmp(zDb, "main")==0 ){
@@ -33483,11 +33566,12 @@
33483 " AS sql, type, tbl_name, name, rowid, %d AS snum, %Q as sname",
33484 ++iSchema, zDb);
33485 sqlite3_str_appendf(pSql," FROM \"%w\".sqlite_schema", zDb);
33486 }
33487 sqlite3_finalize(pStmt);
33488 #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
 
33489 if( zName ){
33490 sqlite3_str_appendall(pSql,
33491 " UNION ALL SELECT shell_module_schema(name),"
33492 " 'table', name, name, name, 9e+99, 'main' FROM pragma_module_list");
33493 }
@@ -35690,29 +35774,65 @@
35690 cli_puts(z, p->out);
35691 fflush(p->out);
35692 return 1;
35693 }
35694
35695 #ifndef SQLITE_SHELL_IS_UTF8
35696 # if (defined(_WIN32) || defined(WIN32)) \
35697 && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
35698 # define SQLITE_SHELL_IS_UTF8 (0)
35699 # else
35700 # define SQLITE_SHELL_IS_UTF8 (1)
35701 # endif
35702 #endif
35703
35704 #ifdef SQLITE_SHELL_FIDDLE
35705 # define main fiddle_main
35706 #endif
35707
35708 #if SQLITE_SHELL_IS_UTF8
35709 int SQLITE_CDECL main(int argc, char **argv){
35710 #else
 
 
 
 
35711 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
35712 char **argv;
35713 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35714 #ifdef SQLITE_DEBUG
35715 sqlite3_int64 mem_main_enter = 0;
35716 #endif
35717 char *zErrMsg = 0;
35718 #ifdef SQLITE_SHELL_FIDDLE
@@ -35730,14 +35850,10 @@
35730 int nOptsEnd = argc;
35731 int bEnableVfstrace = 0;
35732 char **azCmd = 0;
35733 int *aiCmd = 0;
35734 const char *zVfs = 0; /* Value of -vfs command-line option */
35735 #if !SQLITE_SHELL_IS_UTF8
35736 char **argvToFree = 0;
35737 int argcToFree = 0;
35738 #endif
35739 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
35740
35741 #ifdef SQLITE_SHELL_FIDDLE
35742 stdin_is_interactive = 0;
35743 stdout_is_console = 1;
@@ -35788,36 +35904,10 @@
35788 exit(1);
35789 }
35790 #endif
35791 main_init(&data);
35792
35793 /* On Windows, we must translate command-line arguments into UTF-8.
35794 ** The SQLite memory allocator subsystem has to be enabled in order to
35795 ** do this. But we want to run an sqlite3_shutdown() afterwards so that
35796 ** subsequent sqlite3_config() calls will work. So copy all results into
35797 ** memory that does not come from the SQLite memory allocator.
35798 */
35799 #if !SQLITE_SHELL_IS_UTF8
35800 sqlite3_initialize();
35801 argvToFree = malloc(sizeof(argv[0])*argc*2);
35802 shell_check_oom(argvToFree);
35803 argcToFree = argc;
35804 argv = argvToFree + argc;
35805 for(i=0; i<argc; i++){
35806 char *z = sqlite3_win32_unicode_to_utf8(wargv[i]);
35807 i64 n;
35808 shell_check_oom(z);
35809 n = strlen(z);
35810 argv[i] = malloc( n+1 );
35811 shell_check_oom(argv[i]);
35812 memcpy(argv[i], z, n+1);
35813 argvToFree[i] = argv[i];
35814 sqlite3_free(z);
35815 }
35816 sqlite3_shutdown();
35817 #endif
35818
35819 assert( argc>=1 && argv && argv[0] );
35820 Argv0 = argv[0];
35821
35822 #ifdef SQLITE_SHELL_DBNAME_PROC
35823 {
@@ -36009,10 +36099,20 @@
36009 }else if( cli_strcmp(z,"-safe")==0 ){
36010 /* no-op - catch this on the second pass */
36011 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
36012 /* skip over the argument */
36013 i++;
 
 
 
 
 
 
 
 
 
 
36014 }
36015 }
36016 #ifndef SQLITE_SHELL_FIDDLE
36017 if( !bEnableVfstrace ) verify_uninitialized();
36018 #endif
@@ -36427,14 +36527,10 @@
36427 }
36428 find_home_dir(1);
36429 output_reset(&data);
36430 data.doXdgOpen = 0;
36431 clearTempFile(&data);
36432 #if !SQLITE_SHELL_IS_UTF8
36433 for(i=0; i<argcToFree; i++) free(argvToFree[i]);
36434 free(argvToFree);
36435 #endif
36436 modeFree(&data.mode);
36437 if( data.nSavedModes ){
36438 int ii;
36439 for(ii=0; ii<data.nSavedModes; ii++){
36440 modeFree(&data.aSavedModes[ii].mode);
36441
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -35,11 +35,11 @@
35 ** ext/recover/sqlite3recover.h
36 ** src/shell.c.in
37 **
38 ** To modify this program, get a copy of the canonical SQLite source tree,
39 ** edit the src/shell.c.in file and/or some of the other files that are
40 ** listed above, then rerun the command "make shell.c".
41 */
42 /************************* Begin src/shell.c.in ******************/
43 /*
44 ** 2001 September 15
45 **
@@ -49,11 +49,11 @@
49 ** May you do good and not evil.
50 ** May you find forgiveness for yourself and forgive others.
51 ** May you share freely, never taking more than you give.
52 **
53 *************************************************************************
54 ** This file contains code to implement the "sqlite3" command line
55 ** utility for accessing SQLite databases.
56 */
57 #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
58 /* This needs to come before any includes for MSVC compiler */
59 #define _CRT_SECURE_NO_WARNINGS
@@ -4070,10 +4070,18 @@
4070 #define PROMPT_LEN_MAX 128
4071 /* First line prompt. default: "sqlite> " */
4072 static char mainPrompt[PROMPT_LEN_MAX];
4073 /* Continuation prompt. default: " ...> " */
4074 static char continuePrompt[PROMPT_LEN_MAX];
4075
4076 /*
4077 ** Write I/O traces to the following stream.
4078 */
4079 #ifdef SQLITE_ENABLE_IOTRACE
4080 static FILE *iotrace = 0;
4081 #endif
4082
4083
4084 /* This is variant of the standard-library strncpy() routine with the
4085 ** one change that the destination string is always zero-terminated, even
4086 ** if there is no zero-terminator in the first n-1 characters of the source
4087 ** string.
@@ -4190,17 +4198,10 @@
4198 */
4199 static void shell_check_oom(const void *p){
4200 if( p==0 ) shell_out_of_memory();
4201 }
4202
 
 
 
 
 
 
 
4203 /*
4204 ** This routine works like printf in that its first argument is a
4205 ** format string and subsequent arguments are values to be substituted
4206 ** in place of % fields. The result of formatting this string
4207 ** is written to iotrace.
@@ -8351,13 +8352,13 @@
8352 }else if( e<-10000 ){
8353 e = -10000;
8354 }
8355
8356 if( m<0 ){
8357 if( m<(-9223372036854775807LL) ) return;
8358 isNeg = 1;
8359 m = -m;
 
8360 }else if( m==0 && e>-1000 && e<1000 ){
8361 sqlite3_result_double(context, 0.0);
8362 return;
8363 }
8364 while( (m>>32)&0xffe00000 ){
@@ -26848,19 +26849,31 @@
26849 "USAGE: .import [OPTIONS] FILE TABLE\n"
26850 "\n"
26851 "Import CSV or similar text from FILE into TABLE. If TABLE does\n"
26852 "not exist, it is created using the first row of FILE as the column\n"
26853 "names. If FILE begins with \"|\" then it is a command that is run\n"
26854 "and the output from the command is used as the input data. If\n"
26855 "FILE begins with \"<<\" followed by a label, then content is read from\n"
26856 "the script until the first line that matches the label.\n"
26857 "\n"
26858 "The content of FILE is interpreted using RFC-4180 (\"CSV\") quoting\n"
26859 "rules unless the current mode is \"ascii\" or \"tabs\" or unless one\n"
26860 "the --ascii option is used.\n"
26861 "\n"
26862 "The column and row separators must be single ASCII characters. If\n"
26863 "multiple characters or a Unicode character are specified for the\n"
26864 "separators, then only the first byte of the separator is used. Except,\n"
26865 "if the row separator is \\n and the mode is not --ascii, then \\r\\n is\n"
26866 "understood as a row separator too.\n"
26867 "\n"
26868 "Options:\n"
26869 " --ascii Do not use RFC-4180 quoting. Use \\037 and \\036\n"
26870 " as column and row separators on input, unless other\n"
26871 " delimiters are specified using --colsep and/or --rowsep\n"
26872 " --colsep CHAR Use CHAR as the column separator.\n"
26873 " --csv Input is standard RFC-4180 CSV.\n"
26874 " --rowsep CHAR Use CHAR as the row separator.\n"
26875 " --schema S When creating TABLE, put it in schema S\n"
26876 " --skip N Ignore the first N rows of input\n"
26877 " -v Verbose mode\n"
26878 },
26879 { ".mode",
@@ -26987,11 +27000,10 @@
27000 "If PATTERN starts with \"<<ENDMARK\" then the actual pattern is taken from\n"
27001 "subsequent lines of text up to the first line that begins with ENDMARK.\n"
27002 "All pattern lines and the ENDMARK are discarded.\n"
27003 "\n"
27004 "Options:\n"
 
27005 " --exact Do an exact comparison including leading and\n"
27006 " trailing whitespace.\n"
27007 " --glob Treat PATTERN as a GLOB\n"
27008 " --keep Do not reset the testcase. More .check commands\n"
27009 " will follow.\n"
@@ -28000,11 +28012,13 @@
28012 typedef struct ImportCtx ImportCtx;
28013 struct ImportCtx {
28014 const char *zFile; /* Name of the input file */
28015 FILE *in; /* Read the CSV text from this input stream */
28016 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close in */
28017 char *zIn; /* Input text */
28018 char *z; /* Accumulated text for a field */
28019 i64 nUsed; /* Bytes of zIn[] used so far */
28020 i64 n; /* Number of bytes in z */
28021 i64 nAlloc; /* Space allocated for z[] */
28022 int nLine; /* Current line number */
28023 int nRow; /* Number of rows imported */
28024 int nErr; /* Number of errors encountered */
@@ -28020,13 +28034,32 @@
28034 p->xCloser(p->in);
28035 p->in = 0;
28036 }
28037 sqlite3_free(p->z);
28038 p->z = 0;
28039 if( p->zIn ){
28040 sqlite3_free(p->zIn);
28041 p->zIn = 0;
28042 }
28043 }
28044
28045 /* Read a single character of the .import input text. Return EOF
28046 ** at end-of-file.
28047 */
28048 static int import_getc(ImportCtx *p){
28049 if( p->in ){
28050 return fgetc(p->in);
28051 }else if( p->zIn && p->zIn[p->nUsed]!=0 ){
28052 return p->zIn[p->nUsed++];
28053 }else{
28054 return EOF;
28055 }
28056 }
28057
28058 /* Append a single byte to the field value begin constructed
28059 ** in the p->z[] buffer
28060 */
28061 static void import_append_char(ImportCtx *p, int c){
28062 if( p->n+1>=p->nAlloc ){
28063 p->nAlloc += p->nAlloc + 100;
28064 p->z = sqlite3_realloc64(p->z, p->nAlloc);
28065 shell_check_oom(p->z);
@@ -28038,12 +28071,12 @@
28071 ** with the option of having a separator other than ",".
28072 **
28073 ** + Input comes from p->in.
28074 ** + Store results in p->z of length p->n. Space to hold p->z comes
28075 ** from sqlite3_malloc64().
28076 ** + Use p->cColSep as the column separator. The default is ",".
28077 ** + Use p->cRowSep as the row separator. The default is "\n".
28078 ** + Keep track of the line number in p->nLine.
28079 ** + Store the character that terminates the field in p->cTerm. Store
28080 ** EOF on end-of-file.
28081 ** + Report syntax errors on stderr
28082 */
@@ -28050,11 +28083,11 @@
28083 static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){
28084 int c;
28085 int cSep = (u8)p->cColSep;
28086 int rSep = (u8)p->cRowSep;
28087 p->n = 0;
28088 c = import_getc(p);
28089 if( c==EOF || seenInterrupt ){
28090 p->cTerm = EOF;
28091 return 0;
28092 }
28093 if( c=='"' ){
@@ -28061,11 +28094,11 @@
28094 int pc, ppc;
28095 int startLine = p->nLine;
28096 int cQuote = c;
28097 pc = ppc = 0;
28098 while( 1 ){
28099 c = import_getc(p);
28100 if( c==rSep ) p->nLine++;
28101 if( c==cQuote ){
28102 if( pc==cQuote ){
28103 pc = 0;
28104 continue;
@@ -28097,24 +28130,24 @@
28130 }else{
28131 /* If this is the first field being parsed and it begins with the
28132 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */
28133 if( (c&0xff)==0xef && p->bNotFirst==0 ){
28134 import_append_char(p, c);
28135 c = import_getc(p);
28136 if( (c&0xff)==0xbb ){
28137 import_append_char(p, c);
28138 c = import_getc(p);
28139 if( (c&0xff)==0xbf ){
28140 p->bNotFirst = 1;
28141 p->n = 0;
28142 return csv_read_one_field(p);
28143 }
28144 }
28145 }
28146 while( c!=EOF && c!=cSep && c!=rSep ){
28147 import_append_char(p, c);
28148 c = import_getc(p);
28149 }
28150 if( c==rSep ){
28151 p->nLine++;
28152 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
28153 }
@@ -28128,12 +28161,12 @@
28161 /* Read a single field of ASCII delimited text.
28162 **
28163 ** + Input comes from p->in.
28164 ** + Store results in p->z of length p->n. Space to hold p->z comes
28165 ** from sqlite3_malloc64().
28166 ** + Use p->cColSep as the column separator. The default is "\x1F".
28167 ** + Use p->cRowSep as the row separator. The default is "\x1E".
28168 ** + Keep track of the row number in p->nLine.
28169 ** + Store the character that terminates the field in p->cTerm. Store
28170 ** EOF on end-of-file.
28171 ** + Report syntax errors on stderr
28172 */
@@ -28140,18 +28173,18 @@
28173 static char *SQLITE_CDECL ascii_read_one_field(ImportCtx *p){
28174 int c;
28175 int cSep = (u8)p->cColSep;
28176 int rSep = (u8)p->cRowSep;
28177 p->n = 0;
28178 c = import_getc(p);
28179 if( c==EOF || seenInterrupt ){
28180 p->cTerm = EOF;
28181 return 0;
28182 }
28183 while( c!=EOF && c!=cSep && c!=rSep ){
28184 import_append_char(p, c);
28185 c = import_getc(p);
28186 }
28187 if( c==rSep ){
28188 p->nLine++;
28189 }
28190 p->cTerm = c;
@@ -30452,19 +30485,31 @@
30485 ** USAGE: .import [OPTIONS] FILE TABLE
30486 **
30487 ** Import CSV or similar text from FILE into TABLE. If TABLE does
30488 ** not exist, it is created using the first row of FILE as the column
30489 ** names. If FILE begins with "|" then it is a command that is run
30490 ** and the output from the command is used as the input data. If
30491 ** FILE begins with "<<" followed by a label, then content is read from
30492 ** the script until the first line that matches the label.
30493 **
30494 ** The content of FILE is interpreted using RFC-4180 ("CSV") quoting
30495 ** rules unless the current mode is "ascii" or "tabs" or unless one
30496 ** the --ascii option is used.
30497 **
30498 ** The column and row separators must be single ASCII characters. If
30499 ** multiple characters or a Unicode character are specified for the
30500 ** separators, then only the first byte of the separator is used. Except,
30501 ** if the row separator is \n and the mode is not --ascii, then \r\n is
30502 ** understood as a row separator too.
30503 **
30504 ** Options:
30505 ** --ascii Do not use RFC-4180 quoting. Use \037 and \036
30506 ** as column and row separators on input, unless other
30507 ** delimiters are specified using --colsep and/or --rowsep
30508 ** --colsep CHAR Use CHAR as the column separator.
30509 ** --csv Input is standard RFC-4180 CSV.
30510 ** --rowsep CHAR Use CHAR as the row separator.
30511 ** --schema S When creating TABLE, put it in schema S
30512 ** --skip N Ignore the first N rows of input
30513 ** -v Verbose mode
30514 */
30515 static int dotCmdImport(ShellState *p){
@@ -30476,17 +30521,16 @@
30521 sqlite3_stmt *pStmt = NULL; /* A statement */
30522 int nCol; /* Number of columns in the table */
30523 i64 nByte; /* Number of bytes in an SQL string */
30524 int i, j; /* Loop counters */
30525 int needCommit; /* True to COMMIT or ROLLBACK at end */
 
30526 char *zSql = 0; /* An SQL statement */
30527 ImportCtx sCtx; /* Reader context */
30528 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
30529 int eVerbose = 0; /* Larger for more console output */
30530 i64 nSkip = 0; /* Initial lines to skip */
30531 i64 iLineOffset = 0; /* Offset to the first line of input */
30532 char *zCreate = 0; /* CREATE TABLE statement text */
30533 int rc; /* Result code */
30534
30535 failIfSafeMode(p, "cannot run .import in safe mode");
30536 memset(&sCtx, 0, sizeof(sCtx));
@@ -30512,70 +30556,67 @@
30556 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
30557 zSchema = azArg[++i];
30558 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
30559 nSkip = integerValue(azArg[++i]);
30560 }else if( cli_strcmp(z,"-ascii")==0 ){
30561 if( sCtx.cColSep==0 ) sCtx.cColSep = SEP_Unit[0];
30562 if( sCtx.cRowSep==0 ) sCtx.cRowSep = SEP_Record[0];
30563 xRead = ascii_read_one_field;
 
30564 }else if( cli_strcmp(z,"-csv")==0 ){
30565 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
30566 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
30567 xRead = csv_read_one_field;
30568 }else if( cli_strcmp(z,"-colsep")==0 ){
30569 if( i==nArg-1 ){
30570 dotCmdError(p, i, "missing argument", 0);
30571 return 1;
30572 }
30573 i++;
30574 sCtx.cColSep = azArg[i][0];
30575 }else if( cli_strcmp(z,"-rowsep")==0 ){
30576 if( i==nArg-1 ){
30577 dotCmdError(p, i, "missing argument", 0);
30578 return 1;
30579 }
30580 i++;
30581 sCtx.cRowSep = azArg[i][0];
30582 }else{
30583 dotCmdError(p, i, "unknown option", 0);
30584 return 1;
30585 }
30586 }
30587 if( zTable==0 ){
30588 dotCmdError(p, nArg, 0, "Missing %s argument\n",
30589 zFile==0 ? "FILE" : "TABLE");
30590 return 1;
30591 }
30592 seenInterrupt = 0;
30593 open_db(p, 0);
30594 if( sCtx.cColSep==0 ){
30595 if( p->mode.spec.zColumnSep && p->mode.spec.zColumnSep[0]!=0 ){
30596 sCtx.cColSep = p->mode.spec.zColumnSep[0];
30597 }else{
30598 sCtx.cColSep = ',';
30599 }
30600 }
30601 if( (sCtx.cColSep & 0x80)!=0 ){
30602 eputz("Error: .import column separator must be ASCII\n");
30603 return 1;
30604 }
30605 if( sCtx.cRowSep==0 ){
30606 if( p->mode.spec.zRowSep && p->mode.spec.zRowSep[0]!=0 ){
30607 sCtx.cRowSep = p->mode.spec.zRowSep[0];
30608 }else{
30609 sCtx.cRowSep = '\n';
30610 }
30611 }
30612 if( sCtx.cRowSep=='\r' && xRead!=ascii_read_one_field ){
30613 sCtx.cRowSep = '\n';
30614 }
30615 if( (sCtx.cRowSep & 0x80)!=0 ){
30616 eputz("Error: .import row separator must be ASCII\n");
30617 return 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30618 }
30619 sCtx.zFile = zFile;
30620 sCtx.nLine = 1;
30621 if( sCtx.zFile[0]=='|' ){
30622 #ifdef SQLITE_OMIT_POPEN
@@ -30584,19 +30625,58 @@
30625 #else
30626 sCtx.in = sqlite3_popen(sCtx.zFile+1, "r");
30627 sCtx.zFile = "<pipe>";
30628 sCtx.xCloser = pclose;
30629 #endif
30630 }else if( sCtx.zFile[0]=='<' && sCtx.zFile[1]=='<' && sCtx.zFile[2]!=0 ){
30631 /* Input text comes from subsequent lines of script until the zFile
30632 ** delimiter */
30633 int nEndMark = strlen30(zFile)-2;
30634 char *zEndMark = &zFile[2];
30635 sqlite3_str *pContent = sqlite3_str_new(p->db);
30636 int ckEnd = 1;
30637 i64 iStart = p->lineno;
30638 char zLine[2000];
30639 sCtx.zFile = p->zInFile;
30640 sCtx.nLine = p->lineno+1;
30641 iLineOffset = p->lineno;
30642 while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
30643 if( ckEnd && cli_strncmp(zLine,zEndMark,nEndMark)==0 ){
30644 ckEnd = 2;
30645 if( strchr(zLine,'\n') ) p->lineno++;
30646 break;
30647 }
30648 if( strchr(zLine,'\n') ){
30649 p->lineno++;
30650 ckEnd = 1;
30651 }else{
30652 ckEnd = 0;
30653 }
30654 sqlite3_str_appendall(pContent, zLine);
30655 }
30656 sCtx.zIn = sqlite3_str_finish(pContent);
30657 if( sCtx.zIn==0 ){
30658 sCtx.zIn = sqlite3_mprintf("");
30659 }
30660 if( ckEnd<2 ){
30661 i64 savedLn = p->lineno;
30662 p->lineno = iStart;
30663 dotCmdError(p, 0, 0,"Content terminator \"%s\" not found.",zEndMark);
30664 p->lineno = savedLn;
30665 import_cleanup(&sCtx);
30666 return 1;
30667 }
30668 }else{
30669 sCtx.in = sqlite3_fopen(sCtx.zFile, "rb");
30670 sCtx.xCloser = fclose;
30671 }
30672 if( sCtx.in==0 && sCtx.zIn==0 ){
30673 dotCmdError(p, 0, 0, "cannot open \"%s\"", zFile);
30674 import_cleanup(&sCtx);
30675 return 1;
30676 }
30677 if( eVerbose>=1 ){
30678 char zSep[2];
30679 zSep[1] = 0;
30680 zSep[0] = sCtx.cColSep;
30681 cli_puts("Column separator ", p->out);
30682 output_c_string(p->out, zSep);
@@ -30749,10 +30829,14 @@
30829 if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){
30830 z = "";
30831 }
30832 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
30833 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
30834 if( i==0 && (strcmp(z,"\n")==0 || strcmp(z,"\r\n")==0) ){
30835 /* Ignore trailing \n or \r\n when some other row separator */
30836 break;
30837 }
30838 cli_printf(stderr,"%s:%d: expected %d columns but found %d"
30839 " - filling the rest with NULL\n",
30840 sCtx.zFile, startLine, nCol, i+1);
30841 i += 2;
30842 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
@@ -30772,10 +30856,11 @@
30856 rc = sqlite3_reset(pStmt);
30857 if( rc!=SQLITE_OK ){
30858 cli_printf(stderr,"%s:%d: INSERT failed: %s\n",
30859 sCtx.zFile, startLine, sqlite3_errmsg(p->db));
30860 sCtx.nErr++;
30861 if( bail_on_error ) break;
30862 }else{
30863 sCtx.nRow++;
30864 }
30865 }
30866 }while( sCtx.cTerm!=EOF );
@@ -30784,13 +30869,13 @@
30869 sqlite3_finalize(pStmt);
30870 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
30871 if( eVerbose>0 ){
30872 cli_printf(p->out,
30873 "Added %d rows with %d errors using %d lines of input\n",
30874 sCtx.nRow, sCtx.nErr, sCtx.nLine-1-iLineOffset);
30875 }
30876 return sCtx.nErr ? 1 : 0;
30877 }
30878
30879
30880 /*
30881 ** This function computes what to show the user about the configured
@@ -31657,11 +31742,10 @@
31742 ** If PATTERN starts with "<<ENDMARK" then the actual pattern is taken from
31743 ** subsequent lines of text up to the first line that begins with ENDMARK.
31744 ** All pattern lines and the ENDMARK are discarded.
31745 **
31746 ** Options:
 
31747 ** --exact Do an exact comparison including leading and
31748 ** trailing whitespace.
31749 ** --glob Treat PATTERN as a GLOB
31750 ** --keep Do not reset the testcase. More .check commands
31751 ** will follow.
@@ -31712,11 +31796,11 @@
31796 }
31797 if( zCheck==0 ){
31798 dotCmdError(p, 0, "no PATTERN specified", 0);
31799 return 1;
31800 }
31801 if( cli_output_capture && sqlite3_str_length(cli_output_capture) ){
31802 zTest = sqlite3_str_value(cli_output_capture);
31803 shell_check_oom(zTest);
31804 }else{
31805 zTest = "";
31806 }
@@ -33450,12 +33534,11 @@
33534 " rootpage integer,\n"
33535 " sql text\n"
33536 ");\n", zName);
33537 }
33538 }
33539 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
 
33540 if( rc ){
33541 shellDatabaseError(p->db);
33542 sqlite3_finalize(pStmt);
33543
33544 rc = 1;
@@ -33463,11 +33546,11 @@
33546 }
33547 pSql = sqlite3_str_new(p->db);
33548 sqlite3_str_appendf(pSql, "SELECT sql FROM", 0);
33549 iSchema = 0;
33550 while( sqlite3_step(pStmt)==SQLITE_ROW ){
33551 const char *zDb = (const char*)sqlite3_column_text(pStmt, 1);
33552 char zScNum[30];
33553 sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
33554 sqlite3_str_appendall(pSql, zDiv);
33555 zDiv = " UNION ALL ";
33556 if( sqlite3_stricmp(zDb, "main")==0 ){
@@ -33483,11 +33566,12 @@
33566 " AS sql, type, tbl_name, name, rowid, %d AS snum, %Q as sname",
33567 ++iSchema, zDb);
33568 sqlite3_str_appendf(pSql," FROM \"%w\".sqlite_schema", zDb);
33569 }
33570 sqlite3_finalize(pStmt);
33571 #if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS) \
33572 && !defined(SQLITE_OMIT_VIRTUALTABLE)
33573 if( zName ){
33574 sqlite3_str_appendall(pSql,
33575 " UNION ALL SELECT shell_module_schema(name),"
33576 " 'table', name, name, name, 9e+99, 'main' FROM pragma_module_list");
33577 }
@@ -35690,29 +35774,65 @@
35774 cli_puts(z, p->out);
35775 fflush(p->out);
35776 return 1;
35777 }
35778
35779 /* Alternative name to the entry point for Fiddle */
 
 
 
 
 
 
 
 
35780 #ifdef SQLITE_SHELL_FIDDLE
35781 # define main fiddle_main
35782 #endif
35783
35784 /* Use the wmain() entry point on Windows. Translate arguments to
35785 ** UTF8, then invoke the traditional main() entry point which is
35786 ** renamed using a #define to utf8_main() .
35787 */
35788 #if defined(_WIN32) && !defined(main)
35789 # define main utf8_main /* Rename entry point to utf_main() */
35790 int SQLITE_CDECL utf8_main(int,char**); /* Forward declaration */
35791 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
35792 int rc, i;
35793 char **argv = malloc( sizeof(char*) * (argc+1) );
35794 char **orig = argv;
35795 if( argv==0 ){
35796 fprintf(stderr, "malloc failed\n");
35797 exit(1);
35798 }
35799 for(i=0; i<argc; i++){
35800 int nByte = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, 0, 0, 0, 0);
35801 if( nByte==0 ){
35802 argv[i] = 0;
35803 }else{
35804 argv[i] = malloc( nByte );
35805 if( argv[i]==0 ){
35806 fprintf(stderr, "malloc failed\n");
35807 exit(1);
35808 }
35809 nByte = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i],nByte,0,0);
35810 if( nByte==0 ){
35811 free(argv[i]);
35812 argv[i] = 0;
35813 }
35814 }
35815 }
35816 argv[argc] = 0;
35817 rc = utf8_main(argc, argv);
35818 for(i=0; i<argc; i++) free(orig[i]);
35819 free(argv);
35820 return rc;
35821 }
35822 #endif /* WIN32 */
35823
35824 /*
35825 ** This is the main entry point for the process. Everything starts here.
35826 **
35827 ** The "main" identifier may have been #defined to something else:
35828 **
35829 ** utf8_main On Windows
35830 ** fiddle_main In Fiddle
35831 ** sqlite3_shell Other projects that use shell.c as a subroutine
35832 */
35833 int SQLITE_CDECL main(int argc, char **argv){
35834 #ifdef SQLITE_DEBUG
35835 sqlite3_int64 mem_main_enter = 0;
35836 #endif
35837 char *zErrMsg = 0;
35838 #ifdef SQLITE_SHELL_FIDDLE
@@ -35730,14 +35850,10 @@
35850 int nOptsEnd = argc;
35851 int bEnableVfstrace = 0;
35852 char **azCmd = 0;
35853 int *aiCmd = 0;
35854 const char *zVfs = 0; /* Value of -vfs command-line option */
 
 
 
 
35855 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
35856
35857 #ifdef SQLITE_SHELL_FIDDLE
35858 stdin_is_interactive = 0;
35859 stdout_is_console = 1;
@@ -35788,36 +35904,10 @@
35904 exit(1);
35905 }
35906 #endif
35907 main_init(&data);
35908
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35909 assert( argc>=1 && argv && argv[0] );
35910 Argv0 = argv[0];
35911
35912 #ifdef SQLITE_SHELL_DBNAME_PROC
35913 {
@@ -36009,10 +36099,20 @@
36099 }else if( cli_strcmp(z,"-safe")==0 ){
36100 /* no-op - catch this on the second pass */
36101 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
36102 /* skip over the argument */
36103 i++;
36104 }else if( cli_strcmp(z,"-test-argv")==0 ){
36105 /* Undocumented test option. Print the values in argv[] and exit.
36106 ** Use this to verify that any translation of the argv[], for example
36107 ** on Windows that receives wargv[] from the OS and must convert
36108 ** to UTF8 prior to calling this routine. */
36109 int kk;
36110 for(kk=0; kk<argc; kk++){
36111 sqlite3_fprintf(stdout,"argv[%d] = \"%s\"\n", kk, argv[kk]);
36112 }
36113 return 0;
36114 }
36115 }
36116 #ifndef SQLITE_SHELL_FIDDLE
36117 if( !bEnableVfstrace ) verify_uninitialized();
36118 #endif
@@ -36427,14 +36527,10 @@
36527 }
36528 find_home_dir(1);
36529 output_reset(&data);
36530 data.doXdgOpen = 0;
36531 clearTempFile(&data);
 
 
 
 
36532 modeFree(&data.mode);
36533 if( data.nSavedModes ){
36534 int ii;
36535 for(ii=0; ii<data.nSavedModes; ii++){
36536 modeFree(&data.aSavedModes[ii].mode);
36537
+75 -24
--- 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
-** eb2c020481dd591f459cf7191d18c2499aee with changes in files:
21
+** 39e15ce3d6c42b13d0c1164a161e7b5d5d83 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.52.0"
471471
#define SQLITE_VERSION_NUMBER 3052000
472
-#define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
472
+#define SQLITE_SOURCE_ID "2025-12-30 13:10:10 39e15ce3d6c42b13d0c1164a161e7b5d5d8382050c2729961733ddef695c9116"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
475
+#define SQLITE_SCM_DATETIME "2025-12-30T13:10:10.143Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -4752,16 +4752,32 @@
47524752
** compiles to see if some SQL syntax is well-formed, without generating
47534753
** messages on the global error log when it is not. If the test compile
47544754
** fails, the sqlite3_prepare_v3() call returns the same error indications
47554755
** with or without this flag; it just omits the call to [sqlite3_log()] that
47564756
** logs the error.
4757
+**
4758
+** [[SQLITE_PREPARE_FROM_DDL]] <dt>SQLITE_PREPARE_FROM_DDL</dt>
4759
+** <dd>The SQLITE_PREPARE_FROM_DDL flag causes the SQL compiler to behave as if
4760
+** the SQL statement is part of a database schema. This makes a difference
4761
+** when the [SQLITE_DBCONFIG_TRUSTED_SCHEMA] option is set to off.
4762
+** When this option is used and SQLITE_DBCONFIG_TRUSTED_SCHEMA is off,
4763
+** SQL functions may not be called unless they are tagged with
4764
+** [SQLITE_INNOCUOUS] and virtual tables may not be used unless tagged
4765
+** with [SQLITE_VTAB_INNOCUOUS]. Use the SQLITE_PREPARE_FROM_DDL option
4766
+** when preparing SQL that is derived from parts of the database
4767
+** schema. In particular, virtual table implementations that
4768
+** run SQL statements based on the arguments to their CREATE VIRTUAL
4769
+** TABLE statement should use [sqlite3_prepare_v3()] and set the
4770
+** SQLITE_PREPARE_FROM_DLL flag to prevent bypass of the
4771
+** [SQLITE_DBCONFIG_TRUSTED_SCHEMA] security checks.
47574772
** </dl>
47584773
*/
47594774
#define SQLITE_PREPARE_PERSISTENT 0x01
47604775
#define SQLITE_PREPARE_NORMALIZE 0x02
47614776
#define SQLITE_PREPARE_NO_VTAB 0x04
47624777
#define SQLITE_PREPARE_DONT_LOG 0x10
4778
+#define SQLITE_PREPARE_FROM_DDL 0x20
47634779
47644780
/*
47654781
** CAPI3REF: Compiling An SQL Statement
47664782
** KEYWORDS: {SQL statement compiler}
47674783
** METHOD: sqlite3
@@ -4771,12 +4787,13 @@
47714787
** program using one of these routines. Or, in other words, these routines
47724788
** are constructors for the [prepared statement] object.
47734789
**
47744790
** The preferred routine to use is [sqlite3_prepare_v2()]. The
47754791
** [sqlite3_prepare()] interface is legacy and should be avoided.
4776
-** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4777
-** for special purposes.
4792
+** [sqlite3_prepare_v3()] has an extra
4793
+** [SQLITE_PREPARE_FROM_DDL|"prepFlags" option] that is some times
4794
+** needed for special purpose or to pass along security restrictions.
47784795
**
47794796
** The use of the UTF-8 interfaces is preferred, as SQLite currently
47804797
** does all parsing using UTF-8. The UTF-16 interfaces are provided
47814798
** as a convenience. The UTF-16 interfaces work by converting the
47824799
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
@@ -17529,11 +17546,11 @@
1752917546
1753017547
/*
1753117548
** Additional non-public SQLITE_PREPARE_* flags
1753217549
*/
1753317550
#define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
17534
-#define SQLITE_PREPARE_MASK 0x1f /* Mask of public flags */
17551
+#define SQLITE_PREPARE_MASK 0x3f /* Mask of public flags */
1753517552
1753617553
/*
1753717554
** Prototypes for the VDBE interface. See comments on the implementation
1753817555
** for a description of what each of these routines does.
1753917556
*/
@@ -53635,10 +53652,11 @@
5363553652
attr = INVALID_FILE_ATTRIBUTES;
5363653653
}else{
5363753654
attr = sAttrData.dwFileAttributes;
5363853655
}
5363953656
}else{
53657
+ if( noRetry ) lastErrno = osGetLastError();
5364053658
winLogIoerr(cnt, __LINE__);
5364153659
if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
5364253660
sqlite3_free(zConverted);
5364353661
return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
5364453662
zFilename);
@@ -112552,11 +112570,13 @@
112552112570
const Expr *pExpr, /* The function invocation */
112553112571
const FuncDef *pDef /* The function being invoked */
112554112572
){
112555112573
assert( !IN_RENAME_OBJECT );
112556112574
assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
112557
- if( ExprHasProperty(pExpr, EP_FromDDL) ){
112575
+ if( ExprHasProperty(pExpr, EP_FromDDL)
112576
+ || pParse->prepFlags & SQLITE_PREPARE_FROM_DDL
112577
+ ){
112558112578
if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
112559112579
|| (pParse->db->flags & SQLITE_TrustedSchema)==0
112560112580
){
112561112581
/* Functions prohibited in triggers and views if:
112562112582
** (1) tagged with SQLITE_DIRECTONLY
@@ -131378,11 +131398,11 @@
131378131398
** * Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
131379131399
** virtual tables
131380131400
** * Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
131381131401
** virtual tables if PRAGMA trusted_schema=ON.
131382131402
*/
131383
- if( pParse->pToplevel!=0
131403
+ if( (pParse->pToplevel!=0 || (pParse->prepFlags & SQLITE_PREPARE_FROM_DDL))
131384131404
&& pTab->u.vtab.p->eVtabRisk >
131385131405
((pParse->db->flags & SQLITE_TrustedSchema)!=0)
131386131406
){
131387131407
sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
131388131408
pTab->zName);
@@ -153534,11 +153554,11 @@
153534153554
}
153535153555
sqlite3SrcItemAttachSubquery(pParse, pFrom, pTab->u.view.pSelect, 1);
153536153556
}
153537153557
#ifndef SQLITE_OMIT_VIRTUALTABLE
153538153558
else if( ALWAYS(IsVirtual(pTab))
153539
- && pFrom->fg.fromDDL
153559
+ && (pFrom->fg.fromDDL || (pParse->prepFlags & SQLITE_PREPARE_FROM_DDL))
153540153560
&& ALWAYS(pTab->u.vtab.p!=0)
153541153561
&& pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
153542153562
){
153543153563
sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
153544153564
pTab->zName);
@@ -173679,10 +173699,11 @@
173679173699
pWInfo->revMask = (m1 & pWInfo->revMask) | ((pWInfo->revMask>>1) & ~m1);
173680173700
notReady &= ~pLoop->maskSelf;
173681173701
for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
173682173702
if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
173683173703
pTerm->wtFlags |= TERM_CODED;
173704
+ pTerm->prereqAll = 0;
173684173705
}
173685173706
}
173686173707
if( i!=pWInfo->nLevel-1 ){
173687173708
int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel);
173688173709
memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte);
@@ -184829,11 +184850,11 @@
184829184850
for(i=1; sqlite3Isdigit(z[i]); i++){}
184830184851
return i;
184831184852
}
184832184853
case CC_DOLLAR:
184833184854
case CC_VARALPHA: {
184834
- int n = 0;
184855
+ i64 n = 0;
184835184856
testcase( z[0]=='$' ); testcase( z[0]=='@' );
184836184857
testcase( z[0]==':' ); testcase( z[0]=='#' );
184837184858
*tokenType = TK_VARIABLE;
184838184859
for(i=1; (c=z[i])!=0; i++){
184839184860
if( IdChar(c) ){
@@ -192298,10 +192319,19 @@
192298192319
SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
192299192320
192300192321
#define fts3GetVarint32(p, piVal) ( \
192301192322
(*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
192302192323
)
192324
+
192325
+SQLITE_PRIVATE int sqlite3Fts3PrepareStmt(
192326
+ Fts3Table *p, /* Prepare for this connection */
192327
+ const char *zSql, /* SQL to prepare */
192328
+ int bPersist, /* True to set SQLITE_PREPARE_PERSISTENT */
192329
+ int bAllowVtab, /* True to omit SQLITE_PREPARE_NO_VTAB */
192330
+ sqlite3_stmt **pp /* OUT: Prepared statement */
192331
+);
192332
+
192303192333
192304192334
/* fts3.c */
192305192335
SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
192306192336
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
192307192337
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
@@ -193906,13 +193936,11 @@
193906193936
p->pSeekStmt = 0;
193907193937
}else{
193908193938
zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
193909193939
if( !zSql ) return SQLITE_NOMEM;
193910193940
p->bLock++;
193911
- rc = sqlite3_prepare_v3(
193912
- p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
193913
- );
193941
+ rc = sqlite3Fts3PrepareStmt(p, zSql, 1, 1, &pCsr->pStmt);
193914193942
p->bLock--;
193915193943
sqlite3_free(zSql);
193916193944
}
193917193945
if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
193918193946
}
@@ -195483,13 +195511,11 @@
195483195511
p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
195484195512
);
195485195513
}
195486195514
if( zSql ){
195487195515
p->bLock++;
195488
- rc = sqlite3_prepare_v3(
195489
- p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
195490
- );
195516
+ rc = sqlite3Fts3PrepareStmt(p, zSql, 1, 1, &pCsr->pStmt);
195491195517
p->bLock--;
195492195518
sqlite3_free(zSql);
195493195519
}else{
195494195520
rc = SQLITE_NOMEM;
195495195521
}
@@ -196108,10 +196134,11 @@
196108196134
int rc = SQLITE_OK;
196109196135
int bOk = 0;
196110196136
196111196137
UNUSED_PARAMETER(isQuick);
196112196138
rc = sqlite3Fts3IntegrityCheck(p, &bOk);
196139
+ assert( pVtab->zErrMsg==0 || rc!=SQLITE_OK );
196113196140
assert( rc!=SQLITE_CORRUPT_VTAB );
196114196141
if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
196115196142
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
196116196143
" FTS%d table %s.%s: %s",
196117196144
p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
@@ -202719,10 +202746,28 @@
202719202746
#define SQL_SELECT_MXLEVEL 36
202720202747
202721202748
#define SQL_SELECT_LEVEL_RANGE2 37
202722202749
#define SQL_UPDATE_LEVEL_IDX 38
202723202750
#define SQL_UPDATE_LEVEL 39
202751
+
202752
+/*
202753
+** Wrapper around sqlite3_prepare_v3() to ensure that SQLITE_PREPARE_FROM_DDL
202754
+** is always set.
202755
+*/
202756
+SQLITE_PRIVATE int sqlite3Fts3PrepareStmt(
202757
+ Fts3Table *p, /* Prepare for this connection */
202758
+ const char *zSql, /* SQL to prepare */
202759
+ int bPersist, /* True to set SQLITE_PREPARE_PERSISTENT */
202760
+ int bAllowVtab, /* True to omit SQLITE_PREPARE_NO_VTAB */
202761
+ sqlite3_stmt **pp /* OUT: Prepared statement */
202762
+){
202763
+ int f = SQLITE_PREPARE_FROM_DDL
202764
+ |((bAllowVtab==0) ? SQLITE_PREPARE_NO_VTAB : 0)
202765
+ |(bPersist ? SQLITE_PREPARE_PERSISTENT : 0);
202766
+
202767
+ return sqlite3_prepare_v3(p->db, zSql, -1, f, pp, NULL);
202768
+}
202724202769
202725202770
/*
202726202771
** This function is used to obtain an SQLite prepared statement handle
202727202772
** for the statement identified by the second argument. If successful,
202728202773
** *pp is set to the requested statement handle and SQLITE_OK returned.
@@ -202845,24 +202890,24 @@
202845202890
assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
202846202891
assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
202847202892
202848202893
pStmt = p->aStmt[eStmt];
202849202894
if( !pStmt ){
202850
- int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
202895
+ int bAllowVtab = 0;
202851202896
char *zSql;
202852202897
if( eStmt==SQL_CONTENT_INSERT ){
202853202898
zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName, p->zWriteExprlist);
202854202899
}else if( eStmt==SQL_SELECT_CONTENT_BY_ROWID ){
202855
- f &= ~SQLITE_PREPARE_NO_VTAB;
202900
+ bAllowVtab = 1;
202856202901
zSql = sqlite3_mprintf(azSql[eStmt], p->zReadExprlist);
202857202902
}else{
202858202903
zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName);
202859202904
}
202860202905
if( !zSql ){
202861202906
rc = SQLITE_NOMEM;
202862202907
}else{
202863
- rc = sqlite3_prepare_v3(p->db, zSql, -1, f, &pStmt, NULL);
202908
+ rc = sqlite3Fts3PrepareStmt(p, zSql, 1, bAllowVtab, &pStmt);
202864202909
sqlite3_free(zSql);
202865202910
assert( rc==SQLITE_OK || pStmt==0 );
202866202911
p->aStmt[eStmt] = pStmt;
202867202912
}
202868202913
}
@@ -206025,11 +206070,11 @@
206025206070
/* Compose and prepare an SQL statement to loop through the content table */
206026206071
char *zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
206027206072
if( !zSql ){
206028206073
rc = SQLITE_NOMEM;
206029206074
}else{
206030
- rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
206075
+ rc = sqlite3Fts3PrepareStmt(p, zSql, 0, 1, &pStmt);
206031206076
sqlite3_free(zSql);
206032206077
}
206033206078
206034206079
if( rc==SQLITE_OK ){
206035206080
sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
@@ -207778,11 +207823,11 @@
207778207823
207779207824
zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
207780207825
if( !zSql ){
207781207826
rc = SQLITE_NOMEM;
207782207827
}else{
207783
- rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
207828
+ rc = sqlite3Fts3PrepareStmt(p, zSql, 0, 1, &pStmt);
207784207829
sqlite3_free(zSql);
207785207830
}
207786207831
207787207832
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
207788207833
i64 iDocid = sqlite3_column_int64(pStmt, 0);
@@ -239313,11 +239358,17 @@
239313239358
# define FLEXARRAY
239314239359
#else
239315239360
# define FLEXARRAY 1
239316239361
#endif
239317239362
239318
-#endif
239363
+#endif /* SQLITE_AMALGAMATION */
239364
+
239365
+/*
239366
+** Constants for the largest and smallest possible 32-bit signed integers.
239367
+*/
239368
+# define LARGEST_INT32 ((int)(0x7fffffff))
239369
+# define SMALLEST_INT32 ((int)((-1) - LARGEST_INT32))
239319239370
239320239371
/* Truncate very long tokens to this many bytes. Hard limit is
239321239372
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
239322239373
** field that occurs at the start of each leaf page (see fts5_index.c). */
239323239374
#define FTS5_MAX_TOKEN_SIZE 32768
@@ -253895,11 +253946,11 @@
253895253946
if( nMerge<0 ){
253896253947
Fts5Structure *pNew = fts5IndexOptimizeStruct(p, pStruct);
253897253948
fts5StructureRelease(pStruct);
253898253949
pStruct = pNew;
253899253950
nMin = 1;
253900
- nMerge = nMerge*-1;
253951
+ nMerge = (nMerge==SMALLEST_INT32 ? LARGEST_INT32 : (nMerge*-1));
253901253952
}
253902253953
if( pStruct && pStruct->nLevel ){
253903253954
if( fts5IndexMerge(p, &pStruct, nMerge, nMin) ){
253904253955
fts5StructureWrite(p, pStruct);
253905253956
}
@@ -261103,11 +261154,11 @@
261103261154
int nArg, /* Number of args */
261104261155
sqlite3_value **apUnused /* Function arguments */
261105261156
){
261106261157
assert( nArg==0 );
261107261158
UNUSED_PARAM2(nArg, apUnused);
261108
- sqlite3_result_text(pCtx, "fts5: 2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8", -1, SQLITE_TRANSIENT);
261159
+ sqlite3_result_text(pCtx, "fts5: 2025-12-30 11:36:23 52738908b04848b93d54431def37ffaa9723043270ff8ba1e2fa59ab0040afc5", -1, SQLITE_TRANSIENT);
261109261160
}
261110261161
261111261162
/*
261112261163
** Implementation of fts5_locale(LOCALE, TEXT) function.
261113261164
**
261114261165
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** eb2c020481dd591f459cf7191d18c2499aee with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4752,16 +4752,32 @@
4752 ** compiles to see if some SQL syntax is well-formed, without generating
4753 ** messages on the global error log when it is not. If the test compile
4754 ** fails, the sqlite3_prepare_v3() call returns the same error indications
4755 ** with or without this flag; it just omits the call to [sqlite3_log()] that
4756 ** logs the error.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4757 ** </dl>
4758 */
4759 #define SQLITE_PREPARE_PERSISTENT 0x01
4760 #define SQLITE_PREPARE_NORMALIZE 0x02
4761 #define SQLITE_PREPARE_NO_VTAB 0x04
4762 #define SQLITE_PREPARE_DONT_LOG 0x10
 
4763
4764 /*
4765 ** CAPI3REF: Compiling An SQL Statement
4766 ** KEYWORDS: {SQL statement compiler}
4767 ** METHOD: sqlite3
@@ -4771,12 +4787,13 @@
4771 ** program using one of these routines. Or, in other words, these routines
4772 ** are constructors for the [prepared statement] object.
4773 **
4774 ** The preferred routine to use is [sqlite3_prepare_v2()]. The
4775 ** [sqlite3_prepare()] interface is legacy and should be avoided.
4776 ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4777 ** for special purposes.
 
4778 **
4779 ** The use of the UTF-8 interfaces is preferred, as SQLite currently
4780 ** does all parsing using UTF-8. The UTF-16 interfaces are provided
4781 ** as a convenience. The UTF-16 interfaces work by converting the
4782 ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
@@ -17529,11 +17546,11 @@
17529
17530 /*
17531 ** Additional non-public SQLITE_PREPARE_* flags
17532 */
17533 #define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
17534 #define SQLITE_PREPARE_MASK 0x1f /* Mask of public flags */
17535
17536 /*
17537 ** Prototypes for the VDBE interface. See comments on the implementation
17538 ** for a description of what each of these routines does.
17539 */
@@ -53635,10 +53652,11 @@
53635 attr = INVALID_FILE_ATTRIBUTES;
53636 }else{
53637 attr = sAttrData.dwFileAttributes;
53638 }
53639 }else{
 
53640 winLogIoerr(cnt, __LINE__);
53641 if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
53642 sqlite3_free(zConverted);
53643 return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
53644 zFilename);
@@ -112552,11 +112570,13 @@
112552 const Expr *pExpr, /* The function invocation */
112553 const FuncDef *pDef /* The function being invoked */
112554 ){
112555 assert( !IN_RENAME_OBJECT );
112556 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
112557 if( ExprHasProperty(pExpr, EP_FromDDL) ){
 
 
112558 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
112559 || (pParse->db->flags & SQLITE_TrustedSchema)==0
112560 ){
112561 /* Functions prohibited in triggers and views if:
112562 ** (1) tagged with SQLITE_DIRECTONLY
@@ -131378,11 +131398,11 @@
131378 ** * Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
131379 ** virtual tables
131380 ** * Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
131381 ** virtual tables if PRAGMA trusted_schema=ON.
131382 */
131383 if( pParse->pToplevel!=0
131384 && pTab->u.vtab.p->eVtabRisk >
131385 ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
131386 ){
131387 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
131388 pTab->zName);
@@ -153534,11 +153554,11 @@
153534 }
153535 sqlite3SrcItemAttachSubquery(pParse, pFrom, pTab->u.view.pSelect, 1);
153536 }
153537 #ifndef SQLITE_OMIT_VIRTUALTABLE
153538 else if( ALWAYS(IsVirtual(pTab))
153539 && pFrom->fg.fromDDL
153540 && ALWAYS(pTab->u.vtab.p!=0)
153541 && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
153542 ){
153543 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
153544 pTab->zName);
@@ -173679,10 +173699,11 @@
173679 pWInfo->revMask = (m1 & pWInfo->revMask) | ((pWInfo->revMask>>1) & ~m1);
173680 notReady &= ~pLoop->maskSelf;
173681 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
173682 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
173683 pTerm->wtFlags |= TERM_CODED;
 
173684 }
173685 }
173686 if( i!=pWInfo->nLevel-1 ){
173687 int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel);
173688 memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte);
@@ -184829,11 +184850,11 @@
184829 for(i=1; sqlite3Isdigit(z[i]); i++){}
184830 return i;
184831 }
184832 case CC_DOLLAR:
184833 case CC_VARALPHA: {
184834 int n = 0;
184835 testcase( z[0]=='$' ); testcase( z[0]=='@' );
184836 testcase( z[0]==':' ); testcase( z[0]=='#' );
184837 *tokenType = TK_VARIABLE;
184838 for(i=1; (c=z[i])!=0; i++){
184839 if( IdChar(c) ){
@@ -192298,10 +192319,19 @@
192298 SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
192299
192300 #define fts3GetVarint32(p, piVal) ( \
192301 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
192302 )
 
 
 
 
 
 
 
 
 
192303
192304 /* fts3.c */
192305 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
192306 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
192307 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
@@ -193906,13 +193936,11 @@
193906 p->pSeekStmt = 0;
193907 }else{
193908 zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
193909 if( !zSql ) return SQLITE_NOMEM;
193910 p->bLock++;
193911 rc = sqlite3_prepare_v3(
193912 p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
193913 );
193914 p->bLock--;
193915 sqlite3_free(zSql);
193916 }
193917 if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
193918 }
@@ -195483,13 +195511,11 @@
195483 p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
195484 );
195485 }
195486 if( zSql ){
195487 p->bLock++;
195488 rc = sqlite3_prepare_v3(
195489 p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
195490 );
195491 p->bLock--;
195492 sqlite3_free(zSql);
195493 }else{
195494 rc = SQLITE_NOMEM;
195495 }
@@ -196108,10 +196134,11 @@
196108 int rc = SQLITE_OK;
196109 int bOk = 0;
196110
196111 UNUSED_PARAMETER(isQuick);
196112 rc = sqlite3Fts3IntegrityCheck(p, &bOk);
 
196113 assert( rc!=SQLITE_CORRUPT_VTAB );
196114 if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
196115 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
196116 " FTS%d table %s.%s: %s",
196117 p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
@@ -202719,10 +202746,28 @@
202719 #define SQL_SELECT_MXLEVEL 36
202720
202721 #define SQL_SELECT_LEVEL_RANGE2 37
202722 #define SQL_UPDATE_LEVEL_IDX 38
202723 #define SQL_UPDATE_LEVEL 39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202724
202725 /*
202726 ** This function is used to obtain an SQLite prepared statement handle
202727 ** for the statement identified by the second argument. If successful,
202728 ** *pp is set to the requested statement handle and SQLITE_OK returned.
@@ -202845,24 +202890,24 @@
202845 assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
202846 assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
202847
202848 pStmt = p->aStmt[eStmt];
202849 if( !pStmt ){
202850 int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
202851 char *zSql;
202852 if( eStmt==SQL_CONTENT_INSERT ){
202853 zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName, p->zWriteExprlist);
202854 }else if( eStmt==SQL_SELECT_CONTENT_BY_ROWID ){
202855 f &= ~SQLITE_PREPARE_NO_VTAB;
202856 zSql = sqlite3_mprintf(azSql[eStmt], p->zReadExprlist);
202857 }else{
202858 zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName);
202859 }
202860 if( !zSql ){
202861 rc = SQLITE_NOMEM;
202862 }else{
202863 rc = sqlite3_prepare_v3(p->db, zSql, -1, f, &pStmt, NULL);
202864 sqlite3_free(zSql);
202865 assert( rc==SQLITE_OK || pStmt==0 );
202866 p->aStmt[eStmt] = pStmt;
202867 }
202868 }
@@ -206025,11 +206070,11 @@
206025 /* Compose and prepare an SQL statement to loop through the content table */
206026 char *zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
206027 if( !zSql ){
206028 rc = SQLITE_NOMEM;
206029 }else{
206030 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
206031 sqlite3_free(zSql);
206032 }
206033
206034 if( rc==SQLITE_OK ){
206035 sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
@@ -207778,11 +207823,11 @@
207778
207779 zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
207780 if( !zSql ){
207781 rc = SQLITE_NOMEM;
207782 }else{
207783 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
207784 sqlite3_free(zSql);
207785 }
207786
207787 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
207788 i64 iDocid = sqlite3_column_int64(pStmt, 0);
@@ -239313,11 +239358,17 @@
239313 # define FLEXARRAY
239314 #else
239315 # define FLEXARRAY 1
239316 #endif
239317
239318 #endif
 
 
 
 
 
 
239319
239320 /* Truncate very long tokens to this many bytes. Hard limit is
239321 ** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
239322 ** field that occurs at the start of each leaf page (see fts5_index.c). */
239323 #define FTS5_MAX_TOKEN_SIZE 32768
@@ -253895,11 +253946,11 @@
253895 if( nMerge<0 ){
253896 Fts5Structure *pNew = fts5IndexOptimizeStruct(p, pStruct);
253897 fts5StructureRelease(pStruct);
253898 pStruct = pNew;
253899 nMin = 1;
253900 nMerge = nMerge*-1;
253901 }
253902 if( pStruct && pStruct->nLevel ){
253903 if( fts5IndexMerge(p, &pStruct, nMerge, nMin) ){
253904 fts5StructureWrite(p, pStruct);
253905 }
@@ -261103,11 +261154,11 @@
261103 int nArg, /* Number of args */
261104 sqlite3_value **apUnused /* Function arguments */
261105 ){
261106 assert( nArg==0 );
261107 UNUSED_PARAM2(nArg, apUnused);
261108 sqlite3_result_text(pCtx, "fts5: 2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8", -1, SQLITE_TRANSIENT);
261109 }
261110
261111 /*
261112 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261113 **
261114
--- extsrc/sqlite3.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 ** 39e15ce3d6c42b13d0c1164a161e7b5d5d83 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2025-12-30 13:10:10 39e15ce3d6c42b13d0c1164a161e7b5d5d8382050c2729961733ddef695c9116"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-12-30T13:10:10.143Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4752,16 +4752,32 @@
4752 ** compiles to see if some SQL syntax is well-formed, without generating
4753 ** messages on the global error log when it is not. If the test compile
4754 ** fails, the sqlite3_prepare_v3() call returns the same error indications
4755 ** with or without this flag; it just omits the call to [sqlite3_log()] that
4756 ** logs the error.
4757 **
4758 ** [[SQLITE_PREPARE_FROM_DDL]] <dt>SQLITE_PREPARE_FROM_DDL</dt>
4759 ** <dd>The SQLITE_PREPARE_FROM_DDL flag causes the SQL compiler to behave as if
4760 ** the SQL statement is part of a database schema. This makes a difference
4761 ** when the [SQLITE_DBCONFIG_TRUSTED_SCHEMA] option is set to off.
4762 ** When this option is used and SQLITE_DBCONFIG_TRUSTED_SCHEMA is off,
4763 ** SQL functions may not be called unless they are tagged with
4764 ** [SQLITE_INNOCUOUS] and virtual tables may not be used unless tagged
4765 ** with [SQLITE_VTAB_INNOCUOUS]. Use the SQLITE_PREPARE_FROM_DDL option
4766 ** when preparing SQL that is derived from parts of the database
4767 ** schema. In particular, virtual table implementations that
4768 ** run SQL statements based on the arguments to their CREATE VIRTUAL
4769 ** TABLE statement should use [sqlite3_prepare_v3()] and set the
4770 ** SQLITE_PREPARE_FROM_DLL flag to prevent bypass of the
4771 ** [SQLITE_DBCONFIG_TRUSTED_SCHEMA] security checks.
4772 ** </dl>
4773 */
4774 #define SQLITE_PREPARE_PERSISTENT 0x01
4775 #define SQLITE_PREPARE_NORMALIZE 0x02
4776 #define SQLITE_PREPARE_NO_VTAB 0x04
4777 #define SQLITE_PREPARE_DONT_LOG 0x10
4778 #define SQLITE_PREPARE_FROM_DDL 0x20
4779
4780 /*
4781 ** CAPI3REF: Compiling An SQL Statement
4782 ** KEYWORDS: {SQL statement compiler}
4783 ** METHOD: sqlite3
@@ -4771,12 +4787,13 @@
4787 ** program using one of these routines. Or, in other words, these routines
4788 ** are constructors for the [prepared statement] object.
4789 **
4790 ** The preferred routine to use is [sqlite3_prepare_v2()]. The
4791 ** [sqlite3_prepare()] interface is legacy and should be avoided.
4792 ** [sqlite3_prepare_v3()] has an extra
4793 ** [SQLITE_PREPARE_FROM_DDL|"prepFlags" option] that is some times
4794 ** needed for special purpose or to pass along security restrictions.
4795 **
4796 ** The use of the UTF-8 interfaces is preferred, as SQLite currently
4797 ** does all parsing using UTF-8. The UTF-16 interfaces are provided
4798 ** as a convenience. The UTF-16 interfaces work by converting the
4799 ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
@@ -17529,11 +17546,11 @@
17546
17547 /*
17548 ** Additional non-public SQLITE_PREPARE_* flags
17549 */
17550 #define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
17551 #define SQLITE_PREPARE_MASK 0x3f /* Mask of public flags */
17552
17553 /*
17554 ** Prototypes for the VDBE interface. See comments on the implementation
17555 ** for a description of what each of these routines does.
17556 */
@@ -53635,10 +53652,11 @@
53652 attr = INVALID_FILE_ATTRIBUTES;
53653 }else{
53654 attr = sAttrData.dwFileAttributes;
53655 }
53656 }else{
53657 if( noRetry ) lastErrno = osGetLastError();
53658 winLogIoerr(cnt, __LINE__);
53659 if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
53660 sqlite3_free(zConverted);
53661 return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
53662 zFilename);
@@ -112552,11 +112570,13 @@
112570 const Expr *pExpr, /* The function invocation */
112571 const FuncDef *pDef /* The function being invoked */
112572 ){
112573 assert( !IN_RENAME_OBJECT );
112574 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
112575 if( ExprHasProperty(pExpr, EP_FromDDL)
112576 || pParse->prepFlags & SQLITE_PREPARE_FROM_DDL
112577 ){
112578 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
112579 || (pParse->db->flags & SQLITE_TrustedSchema)==0
112580 ){
112581 /* Functions prohibited in triggers and views if:
112582 ** (1) tagged with SQLITE_DIRECTONLY
@@ -131378,11 +131398,11 @@
131398 ** * Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
131399 ** virtual tables
131400 ** * Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
131401 ** virtual tables if PRAGMA trusted_schema=ON.
131402 */
131403 if( (pParse->pToplevel!=0 || (pParse->prepFlags & SQLITE_PREPARE_FROM_DDL))
131404 && pTab->u.vtab.p->eVtabRisk >
131405 ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
131406 ){
131407 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
131408 pTab->zName);
@@ -153534,11 +153554,11 @@
153554 }
153555 sqlite3SrcItemAttachSubquery(pParse, pFrom, pTab->u.view.pSelect, 1);
153556 }
153557 #ifndef SQLITE_OMIT_VIRTUALTABLE
153558 else if( ALWAYS(IsVirtual(pTab))
153559 && (pFrom->fg.fromDDL || (pParse->prepFlags & SQLITE_PREPARE_FROM_DDL))
153560 && ALWAYS(pTab->u.vtab.p!=0)
153561 && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
153562 ){
153563 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
153564 pTab->zName);
@@ -173679,10 +173699,11 @@
173699 pWInfo->revMask = (m1 & pWInfo->revMask) | ((pWInfo->revMask>>1) & ~m1);
173700 notReady &= ~pLoop->maskSelf;
173701 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
173702 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
173703 pTerm->wtFlags |= TERM_CODED;
173704 pTerm->prereqAll = 0;
173705 }
173706 }
173707 if( i!=pWInfo->nLevel-1 ){
173708 int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel);
173709 memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte);
@@ -184829,11 +184850,11 @@
184850 for(i=1; sqlite3Isdigit(z[i]); i++){}
184851 return i;
184852 }
184853 case CC_DOLLAR:
184854 case CC_VARALPHA: {
184855 i64 n = 0;
184856 testcase( z[0]=='$' ); testcase( z[0]=='@' );
184857 testcase( z[0]==':' ); testcase( z[0]=='#' );
184858 *tokenType = TK_VARIABLE;
184859 for(i=1; (c=z[i])!=0; i++){
184860 if( IdChar(c) ){
@@ -192298,10 +192319,19 @@
192319 SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
192320
192321 #define fts3GetVarint32(p, piVal) ( \
192322 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
192323 )
192324
192325 SQLITE_PRIVATE int sqlite3Fts3PrepareStmt(
192326 Fts3Table *p, /* Prepare for this connection */
192327 const char *zSql, /* SQL to prepare */
192328 int bPersist, /* True to set SQLITE_PREPARE_PERSISTENT */
192329 int bAllowVtab, /* True to omit SQLITE_PREPARE_NO_VTAB */
192330 sqlite3_stmt **pp /* OUT: Prepared statement */
192331 );
192332
192333
192334 /* fts3.c */
192335 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
192336 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
192337 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
@@ -193906,13 +193936,11 @@
193936 p->pSeekStmt = 0;
193937 }else{
193938 zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
193939 if( !zSql ) return SQLITE_NOMEM;
193940 p->bLock++;
193941 rc = sqlite3Fts3PrepareStmt(p, zSql, 1, 1, &pCsr->pStmt);
 
 
193942 p->bLock--;
193943 sqlite3_free(zSql);
193944 }
193945 if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
193946 }
@@ -195483,13 +195511,11 @@
195511 p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
195512 );
195513 }
195514 if( zSql ){
195515 p->bLock++;
195516 rc = sqlite3Fts3PrepareStmt(p, zSql, 1, 1, &pCsr->pStmt);
 
 
195517 p->bLock--;
195518 sqlite3_free(zSql);
195519 }else{
195520 rc = SQLITE_NOMEM;
195521 }
@@ -196108,10 +196134,11 @@
196134 int rc = SQLITE_OK;
196135 int bOk = 0;
196136
196137 UNUSED_PARAMETER(isQuick);
196138 rc = sqlite3Fts3IntegrityCheck(p, &bOk);
196139 assert( pVtab->zErrMsg==0 || rc!=SQLITE_OK );
196140 assert( rc!=SQLITE_CORRUPT_VTAB );
196141 if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
196142 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
196143 " FTS%d table %s.%s: %s",
196144 p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
@@ -202719,10 +202746,28 @@
202746 #define SQL_SELECT_MXLEVEL 36
202747
202748 #define SQL_SELECT_LEVEL_RANGE2 37
202749 #define SQL_UPDATE_LEVEL_IDX 38
202750 #define SQL_UPDATE_LEVEL 39
202751
202752 /*
202753 ** Wrapper around sqlite3_prepare_v3() to ensure that SQLITE_PREPARE_FROM_DDL
202754 ** is always set.
202755 */
202756 SQLITE_PRIVATE int sqlite3Fts3PrepareStmt(
202757 Fts3Table *p, /* Prepare for this connection */
202758 const char *zSql, /* SQL to prepare */
202759 int bPersist, /* True to set SQLITE_PREPARE_PERSISTENT */
202760 int bAllowVtab, /* True to omit SQLITE_PREPARE_NO_VTAB */
202761 sqlite3_stmt **pp /* OUT: Prepared statement */
202762 ){
202763 int f = SQLITE_PREPARE_FROM_DDL
202764 |((bAllowVtab==0) ? SQLITE_PREPARE_NO_VTAB : 0)
202765 |(bPersist ? SQLITE_PREPARE_PERSISTENT : 0);
202766
202767 return sqlite3_prepare_v3(p->db, zSql, -1, f, pp, NULL);
202768 }
202769
202770 /*
202771 ** This function is used to obtain an SQLite prepared statement handle
202772 ** for the statement identified by the second argument. If successful,
202773 ** *pp is set to the requested statement handle and SQLITE_OK returned.
@@ -202845,24 +202890,24 @@
202890 assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
202891 assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
202892
202893 pStmt = p->aStmt[eStmt];
202894 if( !pStmt ){
202895 int bAllowVtab = 0;
202896 char *zSql;
202897 if( eStmt==SQL_CONTENT_INSERT ){
202898 zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName, p->zWriteExprlist);
202899 }else if( eStmt==SQL_SELECT_CONTENT_BY_ROWID ){
202900 bAllowVtab = 1;
202901 zSql = sqlite3_mprintf(azSql[eStmt], p->zReadExprlist);
202902 }else{
202903 zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName);
202904 }
202905 if( !zSql ){
202906 rc = SQLITE_NOMEM;
202907 }else{
202908 rc = sqlite3Fts3PrepareStmt(p, zSql, 1, bAllowVtab, &pStmt);
202909 sqlite3_free(zSql);
202910 assert( rc==SQLITE_OK || pStmt==0 );
202911 p->aStmt[eStmt] = pStmt;
202912 }
202913 }
@@ -206025,11 +206070,11 @@
206070 /* Compose and prepare an SQL statement to loop through the content table */
206071 char *zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
206072 if( !zSql ){
206073 rc = SQLITE_NOMEM;
206074 }else{
206075 rc = sqlite3Fts3PrepareStmt(p, zSql, 0, 1, &pStmt);
206076 sqlite3_free(zSql);
206077 }
206078
206079 if( rc==SQLITE_OK ){
206080 sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
@@ -207778,11 +207823,11 @@
207823
207824 zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
207825 if( !zSql ){
207826 rc = SQLITE_NOMEM;
207827 }else{
207828 rc = sqlite3Fts3PrepareStmt(p, zSql, 0, 1, &pStmt);
207829 sqlite3_free(zSql);
207830 }
207831
207832 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
207833 i64 iDocid = sqlite3_column_int64(pStmt, 0);
@@ -239313,11 +239358,17 @@
239358 # define FLEXARRAY
239359 #else
239360 # define FLEXARRAY 1
239361 #endif
239362
239363 #endif /* SQLITE_AMALGAMATION */
239364
239365 /*
239366 ** Constants for the largest and smallest possible 32-bit signed integers.
239367 */
239368 # define LARGEST_INT32 ((int)(0x7fffffff))
239369 # define SMALLEST_INT32 ((int)((-1) - LARGEST_INT32))
239370
239371 /* Truncate very long tokens to this many bytes. Hard limit is
239372 ** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
239373 ** field that occurs at the start of each leaf page (see fts5_index.c). */
239374 #define FTS5_MAX_TOKEN_SIZE 32768
@@ -253895,11 +253946,11 @@
253946 if( nMerge<0 ){
253947 Fts5Structure *pNew = fts5IndexOptimizeStruct(p, pStruct);
253948 fts5StructureRelease(pStruct);
253949 pStruct = pNew;
253950 nMin = 1;
253951 nMerge = (nMerge==SMALLEST_INT32 ? LARGEST_INT32 : (nMerge*-1));
253952 }
253953 if( pStruct && pStruct->nLevel ){
253954 if( fts5IndexMerge(p, &pStruct, nMerge, nMin) ){
253955 fts5StructureWrite(p, pStruct);
253956 }
@@ -261103,11 +261154,11 @@
261154 int nArg, /* Number of args */
261155 sqlite3_value **apUnused /* Function arguments */
261156 ){
261157 assert( nArg==0 );
261158 UNUSED_PARAM2(nArg, apUnused);
261159 sqlite3_result_text(pCtx, "fts5: 2025-12-30 11:36:23 52738908b04848b93d54431def37ffaa9723043270ff8ba1e2fa59ab0040afc5", -1, SQLITE_TRANSIENT);
261160 }
261161
261162 /*
261163 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261164 **
261165
+21 -4
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.52.0"
150150
#define SQLITE_VERSION_NUMBER 3052000
151
-#define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
151
+#define SQLITE_SOURCE_ID "2025-12-30 13:10:10 39e15ce3d6c42b13d0c1164a161e7b5d5d8382050c2729961733ddef695c9116"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
154
+#define SQLITE_SCM_DATETIME "2025-12-30T13:10:10.143Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4431,16 +4431,32 @@
44314431
** compiles to see if some SQL syntax is well-formed, without generating
44324432
** messages on the global error log when it is not. If the test compile
44334433
** fails, the sqlite3_prepare_v3() call returns the same error indications
44344434
** with or without this flag; it just omits the call to [sqlite3_log()] that
44354435
** logs the error.
4436
+**
4437
+** [[SQLITE_PREPARE_FROM_DDL]] <dt>SQLITE_PREPARE_FROM_DDL</dt>
4438
+** <dd>The SQLITE_PREPARE_FROM_DDL flag causes the SQL compiler to behave as if
4439
+** the SQL statement is part of a database schema. This makes a difference
4440
+** when the [SQLITE_DBCONFIG_TRUSTED_SCHEMA] option is set to off.
4441
+** When this option is used and SQLITE_DBCONFIG_TRUSTED_SCHEMA is off,
4442
+** SQL functions may not be called unless they are tagged with
4443
+** [SQLITE_INNOCUOUS] and virtual tables may not be used unless tagged
4444
+** with [SQLITE_VTAB_INNOCUOUS]. Use the SQLITE_PREPARE_FROM_DDL option
4445
+** when preparing SQL that is derived from parts of the database
4446
+** schema. In particular, virtual table implementations that
4447
+** run SQL statements based on the arguments to their CREATE VIRTUAL
4448
+** TABLE statement should use [sqlite3_prepare_v3()] and set the
4449
+** SQLITE_PREPARE_FROM_DLL flag to prevent bypass of the
4450
+** [SQLITE_DBCONFIG_TRUSTED_SCHEMA] security checks.
44364451
** </dl>
44374452
*/
44384453
#define SQLITE_PREPARE_PERSISTENT 0x01
44394454
#define SQLITE_PREPARE_NORMALIZE 0x02
44404455
#define SQLITE_PREPARE_NO_VTAB 0x04
44414456
#define SQLITE_PREPARE_DONT_LOG 0x10
4457
+#define SQLITE_PREPARE_FROM_DDL 0x20
44424458
44434459
/*
44444460
** CAPI3REF: Compiling An SQL Statement
44454461
** KEYWORDS: {SQL statement compiler}
44464462
** METHOD: sqlite3
@@ -4450,12 +4466,13 @@
44504466
** program using one of these routines. Or, in other words, these routines
44514467
** are constructors for the [prepared statement] object.
44524468
**
44534469
** The preferred routine to use is [sqlite3_prepare_v2()]. The
44544470
** [sqlite3_prepare()] interface is legacy and should be avoided.
4455
-** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4456
-** for special purposes.
4471
+** [sqlite3_prepare_v3()] has an extra
4472
+** [SQLITE_PREPARE_FROM_DDL|"prepFlags" option] that is some times
4473
+** needed for special purpose or to pass along security restrictions.
44574474
**
44584475
** The use of the UTF-8 interfaces is preferred, as SQLite currently
44594476
** does all parsing using UTF-8. The UTF-16 interfaces are provided
44604477
** as a convenience. The UTF-16 interfaces work by converting the
44614478
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
44624479
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2025-12-22 11:28:16 eb2c020481dd591f459cf7191d18c2499aeec210fc3fc27bb35e5abc0d9cb6d8"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-12-22T11:28:16.789Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4431,16 +4431,32 @@
4431 ** compiles to see if some SQL syntax is well-formed, without generating
4432 ** messages on the global error log when it is not. If the test compile
4433 ** fails, the sqlite3_prepare_v3() call returns the same error indications
4434 ** with or without this flag; it just omits the call to [sqlite3_log()] that
4435 ** logs the error.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4436 ** </dl>
4437 */
4438 #define SQLITE_PREPARE_PERSISTENT 0x01
4439 #define SQLITE_PREPARE_NORMALIZE 0x02
4440 #define SQLITE_PREPARE_NO_VTAB 0x04
4441 #define SQLITE_PREPARE_DONT_LOG 0x10
 
4442
4443 /*
4444 ** CAPI3REF: Compiling An SQL Statement
4445 ** KEYWORDS: {SQL statement compiler}
4446 ** METHOD: sqlite3
@@ -4450,12 +4466,13 @@
4450 ** program using one of these routines. Or, in other words, these routines
4451 ** are constructors for the [prepared statement] object.
4452 **
4453 ** The preferred routine to use is [sqlite3_prepare_v2()]. The
4454 ** [sqlite3_prepare()] interface is legacy and should be avoided.
4455 ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4456 ** for special purposes.
 
4457 **
4458 ** The use of the UTF-8 interfaces is preferred, as SQLite currently
4459 ** does all parsing using UTF-8. The UTF-16 interfaces are provided
4460 ** as a convenience. The UTF-16 interfaces work by converting the
4461 ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
4462
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2025-12-30 13:10:10 39e15ce3d6c42b13d0c1164a161e7b5d5d8382050c2729961733ddef695c9116"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-12-30T13:10:10.143Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4431,16 +4431,32 @@
4431 ** compiles to see if some SQL syntax is well-formed, without generating
4432 ** messages on the global error log when it is not. If the test compile
4433 ** fails, the sqlite3_prepare_v3() call returns the same error indications
4434 ** with or without this flag; it just omits the call to [sqlite3_log()] that
4435 ** logs the error.
4436 **
4437 ** [[SQLITE_PREPARE_FROM_DDL]] <dt>SQLITE_PREPARE_FROM_DDL</dt>
4438 ** <dd>The SQLITE_PREPARE_FROM_DDL flag causes the SQL compiler to behave as if
4439 ** the SQL statement is part of a database schema. This makes a difference
4440 ** when the [SQLITE_DBCONFIG_TRUSTED_SCHEMA] option is set to off.
4441 ** When this option is used and SQLITE_DBCONFIG_TRUSTED_SCHEMA is off,
4442 ** SQL functions may not be called unless they are tagged with
4443 ** [SQLITE_INNOCUOUS] and virtual tables may not be used unless tagged
4444 ** with [SQLITE_VTAB_INNOCUOUS]. Use the SQLITE_PREPARE_FROM_DDL option
4445 ** when preparing SQL that is derived from parts of the database
4446 ** schema. In particular, virtual table implementations that
4447 ** run SQL statements based on the arguments to their CREATE VIRTUAL
4448 ** TABLE statement should use [sqlite3_prepare_v3()] and set the
4449 ** SQLITE_PREPARE_FROM_DLL flag to prevent bypass of the
4450 ** [SQLITE_DBCONFIG_TRUSTED_SCHEMA] security checks.
4451 ** </dl>
4452 */
4453 #define SQLITE_PREPARE_PERSISTENT 0x01
4454 #define SQLITE_PREPARE_NORMALIZE 0x02
4455 #define SQLITE_PREPARE_NO_VTAB 0x04
4456 #define SQLITE_PREPARE_DONT_LOG 0x10
4457 #define SQLITE_PREPARE_FROM_DDL 0x20
4458
4459 /*
4460 ** CAPI3REF: Compiling An SQL Statement
4461 ** KEYWORDS: {SQL statement compiler}
4462 ** METHOD: sqlite3
@@ -4450,12 +4466,13 @@
4466 ** program using one of these routines. Or, in other words, these routines
4467 ** are constructors for the [prepared statement] object.
4468 **
4469 ** The preferred routine to use is [sqlite3_prepare_v2()]. The
4470 ** [sqlite3_prepare()] interface is legacy and should be avoided.
4471 ** [sqlite3_prepare_v3()] has an extra
4472 ** [SQLITE_PREPARE_FROM_DDL|"prepFlags" option] that is some times
4473 ** needed for special purpose or to pass along security restrictions.
4474 **
4475 ** The use of the UTF-8 interfaces is preferred, as SQLite currently
4476 ** does all parsing using UTF-8. The UTF-16 interfaces are provided
4477 ** as a convenience. The UTF-16 interfaces work by converting the
4478 ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
4479

Keyboard Shortcuts

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