Fossil SCM

Merge from trunk

george 2022-02-10 00:29 search-terms-highlighting merge
Commit 2b5f9b211cf5e0a01ee72c5ba9ed0e3172a5e1a462b6874046e52ff36553064b
+360 -61
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12143,10 +12143,19 @@
1214312143
EQPGraphRow *pRow; /* Linked list of all rows of the EQP output */
1214412144
EQPGraphRow *pLast; /* Last element of the pRow list */
1214512145
char zPrefix[100]; /* Graph prefix */
1214612146
};
1214712147
12148
+/* Parameters affecting columnar mode result display (defaulting together) */
12149
+typedef struct ColModeOpts {
12150
+ int iWrap; /* In columnar modes, wrap lines reaching this limit */
12151
+ u8 bQuote; /* Quote results for .mode box and table */
12152
+ u8 bWordWrap; /* In columnar modes, wrap at word boundaries */
12153
+} ColModeOpts;
12154
+#define ColModeOpts_default { 60, 0, 0 }
12155
+#define ColModeOpts_default_qbox { 60, 1, 0 }
12156
+
1214812157
/*
1214912158
** State information about the database connection is contained in an
1215012159
** instance of the following structure.
1215112160
*/
1215212161
typedef struct ShellState ShellState;
@@ -12161,12 +12170,14 @@
1216112170
u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
1216212171
u8 nEqpLevel; /* Depth of the EQP output graph */
1216312172
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
1216412173
u8 bSafeMode; /* True to prohibit unsafe operations */
1216512174
u8 bSafeModePersist; /* The long-term value of bSafeMode */
12175
+ ColModeOpts cmOpts; /* Option values affecting columnar mode output */
1216612176
unsigned statsOn; /* True to display memory stats before each finalize */
1216712177
unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
12178
+ int inputNesting; /* Track nesting level of .read and other redirects */
1216812179
int outCount; /* Revert to stdout when reaching zero */
1216912180
int cnt; /* Number of records displayed so far */
1217012181
int lineno; /* Line number of last line read from in */
1217112182
int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
1217212183
FILE *in; /* Read commands from this stream */
@@ -12327,10 +12338,16 @@
1232712338
#define SEP_Comma ","
1232812339
#define SEP_CrLf "\r\n"
1232912340
#define SEP_Unit "\x1F"
1233012341
#define SEP_Record "\x1E"
1233112342
12343
+/*
12344
+** Limit input nesting via .read or any other input redirect.
12345
+** It's not too expensive, so a generous allowance can be made.
12346
+*/
12347
+#define MAX_INPUT_NESTING 25
12348
+
1233212349
/*
1233312350
** A callback for the sqlite3_log() interface.
1233412351
*/
1233512352
static void shellLog(void *pArg, int iErrCode, const char *zMsg){
1233612353
ShellState *p = (ShellState*)pArg;
@@ -14234,11 +14251,138 @@
1423414251
utf8_printf(p->out, "%s", zSep3);
1423514252
}
1423614253
fputs("\n", p->out);
1423714254
}
1423814255
14256
+/*
14257
+** z[] is a line of text that is to be displayed the .mode box or table or
14258
+** similar tabular formats. z[] might contain control characters such
14259
+** as \n, \t, \f, or \r.
14260
+**
14261
+** Compute characters to display on the first line of z[]. Stop at the
14262
+** first \r, \n, or \f. Expand \t into spaces. Return a copy (obtained
14263
+** from malloc()) of that first line, which caller should free sometime.
14264
+** Write anything to display on the next line into *pzTail. If this is
14265
+** the last line, write a NULL into *pzTail. (*pzTail is not allocated.)
14266
+*/
14267
+static char *translateForDisplayAndDup(
14268
+ const unsigned char *z, /* Input text to be transformed */
14269
+ const unsigned char **pzTail, /* OUT: Tail of the input for next line */
14270
+ int mxWidth, /* Max width. 0 means no limit */
14271
+ u8 bWordWrap /* If true, avoid breaking mid-word */
14272
+){
14273
+ int i; /* Input bytes consumed */
14274
+ int j; /* Output bytes generated */
14275
+ int k; /* Input bytes to be displayed */
14276
+ int n; /* Output column number */
14277
+ unsigned char *zOut; /* Output text */
1423914278
14279
+ if( z==0 ){
14280
+ *pzTail = 0;
14281
+ return 0;
14282
+ }
14283
+ if( mxWidth<0 ) mxWidth = -mxWidth;
14284
+ if( mxWidth==0 ) mxWidth = 1000000;
14285
+ i = j = n = 0;
14286
+ while( n<mxWidth ){
14287
+ if( z[i]>=' ' ){
14288
+ n++;
14289
+ do{ i++; j++; }while( (z[i]&0xc0)==0x80 );
14290
+ continue;
14291
+ }
14292
+ if( z[i]=='\t' ){
14293
+ do{
14294
+ n++;
14295
+ j++;
14296
+ }while( (n&7)!=0 && n<mxWidth );
14297
+ i++;
14298
+ continue;
14299
+ }
14300
+ break;
14301
+ }
14302
+ if( n>=mxWidth && bWordWrap ){
14303
+ /* Perhaps try to back up to a better place to break the line */
14304
+ for(k=i; k>i/2; k--){
14305
+ if( isspace(z[k-1]) ) break;
14306
+ }
14307
+ if( k<=i/2 ){
14308
+ for(k=i; k>i/2; k--){
14309
+ if( isalnum(z[k-1])!=isalnum(z[k]) && (z[k]&0xc0)!=0x80 ) break;
14310
+ }
14311
+ }
14312
+ if( k<=i/2 ){
14313
+ k = i;
14314
+ }else{
14315
+ i = k;
14316
+ while( z[i]==' ' ) i++;
14317
+ }
14318
+ }else{
14319
+ k = i;
14320
+ }
14321
+ if( n>=mxWidth && z[i]>=' ' ){
14322
+ *pzTail = &z[i];
14323
+ }else if( z[i]=='\r' && z[i+1]=='\n' ){
14324
+ *pzTail = z[i+2] ? &z[i+2] : 0;
14325
+ }else if( z[i]==0 || z[i+1]==0 ){
14326
+ *pzTail = 0;
14327
+ }else{
14328
+ *pzTail = &z[i+1];
14329
+ }
14330
+ zOut = malloc( j+1 );
14331
+ shell_check_oom(zOut);
14332
+ i = j = n = 0;
14333
+ while( i<k ){
14334
+ if( z[i]>=' ' ){
14335
+ n++;
14336
+ do{ zOut[j++] = z[i++]; }while( (z[i]&0xc0)==0x80 );
14337
+ continue;
14338
+ }
14339
+ if( z[i]=='\t' ){
14340
+ do{
14341
+ n++;
14342
+ zOut[j++] = ' ';
14343
+ }while( (n&7)!=0 && n<mxWidth );
14344
+ i++;
14345
+ continue;
14346
+ }
14347
+ break;
14348
+ }
14349
+ zOut[j] = 0;
14350
+ return (char*)zOut;
14351
+}
14352
+
14353
+/* Extract the value of the i-th current column for pStmt as an SQL literal
14354
+** value. Memory is obtained from sqlite3_malloc64() and must be freed by
14355
+** the caller.
14356
+*/
14357
+static char *quoted_column(sqlite3_stmt *pStmt, int i){
14358
+ switch( sqlite3_column_type(pStmt, i) ){
14359
+ case SQLITE_NULL: {
14360
+ return sqlite3_mprintf("NULL");
14361
+ }
14362
+ case SQLITE_INTEGER:
14363
+ case SQLITE_FLOAT: {
14364
+ return sqlite3_mprintf("%s",sqlite3_column_text(pStmt,i));
14365
+ }
14366
+ case SQLITE_TEXT: {
14367
+ return sqlite3_mprintf("%Q",sqlite3_column_text(pStmt,i));
14368
+ }
14369
+ case SQLITE_BLOB: {
14370
+ int j;
14371
+ sqlite3_str *pStr = sqlite3_str_new(0);
14372
+ const unsigned char *a = sqlite3_column_blob(pStmt,i);
14373
+ int n = sqlite3_column_bytes(pStmt,i);
14374
+ sqlite3_str_append(pStr, "x'", 2);
14375
+ for(j=0; j<n; j++){
14376
+ sqlite3_str_appendf(pStr, "%02x", a[j]);
14377
+ }
14378
+ sqlite3_str_append(pStr, "'", 1);
14379
+ return sqlite3_str_finish(pStr);
14380
+ }
14381
+ }
14382
+ return 0; /* Not reached */
14383
+}
1424014384
1424114385
/*
1424214386
** Run a prepared statement and output the result in one of the
1424314387
** table-oriented formats: MODE_Column, MODE_Markdown, MODE_Table,
1424414388
** or MODE_Box.
@@ -14254,39 +14398,41 @@
1425414398
){
1425514399
sqlite3_int64 nRow = 0;
1425614400
int nColumn = 0;
1425714401
char **azData = 0;
1425814402
sqlite3_int64 nAlloc = 0;
14403
+ char *abRowDiv = 0;
14404
+ const unsigned char *uz;
1425914405
const char *z;
14406
+ char **azQuoted = 0;
1426014407
int rc;
1426114408
sqlite3_int64 i, nData;
1426214409
int j, nTotal, w, n;
1426314410
const char *colSep = 0;
1426414411
const char *rowSep = 0;
14412
+ const unsigned char **azNextLine = 0;
14413
+ int bNextLine = 0;
14414
+ int bMultiLineRowExists = 0;
14415
+ int bw = p->cmOpts.bWordWrap;
1426514416
1426614417
rc = sqlite3_step(pStmt);
1426714418
if( rc!=SQLITE_ROW ) return;
1426814419
nColumn = sqlite3_column_count(pStmt);
1426914420
nAlloc = nColumn*4;
1427014421
if( nAlloc<=0 ) nAlloc = 1;
1427114422
azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
1427214423
shell_check_oom(azData);
14273
- for(i=0; i<nColumn; i++){
14274
- azData[i] = strdup(sqlite3_column_name(pStmt,i));
14275
- }
14276
- do{
14277
- if( (nRow+2)*nColumn >= nAlloc ){
14278
- nAlloc *= 2;
14279
- azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
14280
- shell_check_oom(azData);
14281
- }
14282
- nRow++;
14283
- for(i=0; i<nColumn; i++){
14284
- z = (const char*)sqlite3_column_text(pStmt,i);
14285
- azData[nRow*nColumn + i] = z ? strdup(z) : 0;
14286
- }
14287
- }while( sqlite3_step(pStmt)==SQLITE_ROW );
14424
+ azNextLine = sqlite3_malloc64( nColumn*sizeof(char*) );
14425
+ shell_check_oom((void*)azNextLine);
14426
+ memset((void*)azNextLine, 0, nColumn*sizeof(char*) );
14427
+ if( p->cmOpts.bQuote ){
14428
+ azQuoted = sqlite3_malloc64( nColumn*sizeof(char*) );
14429
+ shell_check_oom(azQuoted);
14430
+ memset(azQuoted, 0, nColumn*sizeof(char*) );
14431
+ }
14432
+ abRowDiv = sqlite3_malloc64( nAlloc/nColumn );
14433
+ shell_check_oom(abRowDiv);
1428814434
if( nColumn>p->nWidth ){
1428914435
p->colWidth = realloc(p->colWidth, (nColumn+1)*2*sizeof(int));
1429014436
shell_check_oom(p->colWidth);
1429114437
for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
1429214438
p->nWidth = nColumn;
@@ -14296,10 +14442,56 @@
1429614442
for(i=0; i<nColumn; i++){
1429714443
w = p->colWidth[i];
1429814444
if( w<0 ) w = -w;
1429914445
p->actualWidth[i] = w;
1430014446
}
14447
+ for(i=0; i<nColumn; i++){
14448
+ const unsigned char *zNotUsed;
14449
+ int wx = p->colWidth[i];
14450
+ if( wx==0 ){
14451
+ wx = p->cmOpts.iWrap;
14452
+ }
14453
+ if( wx<0 ) wx = -wx;
14454
+ uz = (const unsigned char*)sqlite3_column_name(pStmt,i);
14455
+ azData[i] = translateForDisplayAndDup(uz, &zNotUsed, wx, bw);
14456
+ }
14457
+ do{
14458
+ int useNextLine = bNextLine;
14459
+ bNextLine = 0;
14460
+ if( (nRow+2)*nColumn >= nAlloc ){
14461
+ nAlloc *= 2;
14462
+ azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
14463
+ shell_check_oom(azData);
14464
+ abRowDiv = sqlite3_realloc64(abRowDiv, nAlloc/nColumn);
14465
+ shell_check_oom(abRowDiv);
14466
+ }
14467
+ abRowDiv[nRow] = 1;
14468
+ nRow++;
14469
+ for(i=0; i<nColumn; i++){
14470
+ int wx = p->colWidth[i];
14471
+ if( wx==0 ){
14472
+ wx = p->cmOpts.iWrap;
14473
+ }
14474
+ if( wx<0 ) wx = -wx;
14475
+ if( useNextLine ){
14476
+ uz = azNextLine[i];
14477
+ }else if( p->cmOpts.bQuote ){
14478
+ sqlite3_free(azQuoted[i]);
14479
+ azQuoted[i] = quoted_column(pStmt,i);
14480
+ uz = (const unsigned char*)azQuoted[i];
14481
+ }else{
14482
+ uz = (const unsigned char*)sqlite3_column_text(pStmt,i);
14483
+ }
14484
+ azData[nRow*nColumn + i]
14485
+ = translateForDisplayAndDup(uz, &azNextLine[i], wx, bw);
14486
+ if( azNextLine[i] ){
14487
+ bNextLine = 1;
14488
+ abRowDiv[nRow-1] = 0;
14489
+ bMultiLineRowExists = 1;
14490
+ }
14491
+ }
14492
+ }while( bNextLine || sqlite3_step(pStmt)==SQLITE_ROW );
1430114493
nTotal = nColumn*(nRow+1);
1430214494
for(i=0; i<nTotal; i++){
1430314495
z = azData[i];
1430414496
if( z==0 ) z = p->nullValue;
1430514497
n = strlenChar(z);
@@ -14378,10 +14570,19 @@
1437814570
w = p->actualWidth[j];
1437914571
if( p->colWidth[j]<0 ) w = -w;
1438014572
utf8_width_print(p->out, w, z);
1438114573
if( j==nColumn-1 ){
1438214574
utf8_printf(p->out, "%s", rowSep);
14575
+ if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1<nTotal ){
14576
+ if( p->cMode==MODE_Table ){
14577
+ print_row_separator(p, nColumn, "+");
14578
+ }else if( p->cMode==MODE_Box ){
14579
+ print_box_row_separator(p, nColumn, BOX_123, BOX_1234, BOX_134);
14580
+ }else if( p->cMode==MODE_Column ){
14581
+ raw_printf(p->out, "\n");
14582
+ }
14583
+ }
1438314584
j = -1;
1438414585
if( seenInterrupt ) goto columnar_end;
1438514586
}else{
1438614587
utf8_printf(p->out, "%s", colSep);
1438714588
}
@@ -14396,10 +14597,16 @@
1439614597
utf8_printf(p->out, "Interrupt\n");
1439714598
}
1439814599
nData = (nRow+1)*nColumn;
1439914600
for(i=0; i<nData; i++) free(azData[i]);
1440014601
sqlite3_free(azData);
14602
+ sqlite3_free((void*)azNextLine);
14603
+ sqlite3_free(abRowDiv);
14604
+ if( azQuoted ){
14605
+ for(i=0; i<nColumn; i++) sqlite3_free(azQuoted[i]);
14606
+ sqlite3_free(azQuoted);
14607
+ }
1440114608
}
1440214609
1440314610
/*
1440414611
** Run a prepared statement
1440514612
*/
@@ -15147,10 +15354,11 @@
1514715354
".import FILE TABLE Import data from FILE into TABLE",
1514815355
" Options:",
1514915356
" --ascii Use \\037 and \\036 as column and row separators",
1515015357
" --csv Use , and \\n as column and row separators",
1515115358
" --skip N Skip the first N rows of input",
15359
+ " --schema S Target table to be S.TABLE",
1515215360
" -v \"Verbose\" - increase auxiliary output",
1515315361
" Notes:",
1515415362
" * If TABLE does not exist, it is created. The first row of input",
1515515363
" determines the column names.",
1515615364
" * If neither --csv or --ascii are used, the input mode is derived",
@@ -15172,27 +15380,35 @@
1517215380
" fkey-indexes Find missing foreign key indexes",
1517315381
#ifndef SQLITE_OMIT_LOAD_EXTENSION
1517415382
".load FILE ?ENTRY? Load an extension library",
1517515383
#endif
1517615384
".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15177
- ".mode MODE ?TABLE? Set output mode",
15385
+ ".mode MODE ?OPTIONS? Set output mode",
1517815386
" MODE is one of:",
15179
- " ascii Columns/rows delimited by 0x1F and 0x1E",
15180
- " box Tables using unicode box-drawing characters",
15181
- " csv Comma-separated values",
15182
- " column Output in columns. (See .width)",
15183
- " html HTML <table> code",
15184
- " insert SQL insert statements for TABLE",
15185
- " json Results in a JSON array",
15186
- " line One value per line",
15187
- " list Values delimited by \"|\"",
15188
- " markdown Markdown table format",
15189
- " quote Escape answers as for SQL",
15190
- " table ASCII-art table",
15191
- " tabs Tab-separated values",
15192
- " tcl TCL list elements",
15193
- ".nonce STRING Disable safe mode for one command if the nonce matches",
15387
+ " ascii Columns/rows delimited by 0x1F and 0x1E",
15388
+ " box Tables using unicode box-drawing characters",
15389
+ " csv Comma-separated values",
15390
+ " column Output in columns. (See .width)",
15391
+ " html HTML <table> code",
15392
+ " insert SQL insert statements for TABLE",
15393
+ " json Results in a JSON array",
15394
+ " line One value per line",
15395
+ " list Values delimited by \"|\"",
15396
+ " markdown Markdown table format",
15397
+ " qbox Shorthand for \"box --width 60 --quote\"",
15398
+ " quote Escape answers as for SQL",
15399
+ " table ASCII-art table",
15400
+ " tabs Tab-separated values",
15401
+ " tcl TCL list elements",
15402
+ " OPTIONS: (for columnar modes or insert mode):",
15403
+ " --wrap N Wrap output lines to no longer than N characters",
15404
+ " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15405
+ " --ww Shorthand for \"--wordwrap 1\"",
15406
+ " --quote Quote output text as SQL literals",
15407
+ " --noquote Do not quote output text",
15408
+ " TABLE The name of SQL table used for \"insert\" mode",
15409
+ ".nonce STRING Suspend safe mode for one command if nonce matches",
1519415410
".nullvalue STRING Use STRING in place of NULL values",
1519515411
".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
1519615412
" If FILE begins with '|' then open as a pipe",
1519715413
" --bom Put a UTF8 byte-order mark at the beginning",
1519815414
" -e Send output to the system text editor",
@@ -19459,10 +19675,11 @@
1945919675
}
1946019676
}else
1946119677
1946219678
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
1946319679
char *zTable = 0; /* Insert data into this table */
19680
+ char *zSchema = "main"; /* within this schema */
1946419681
char *zFile = 0; /* Name of file to extra content from */
1946519682
sqlite3_stmt *pStmt = NULL; /* A statement */
1946619683
int nCol; /* Number of columns in the table */
1946719684
int nByte; /* Number of bytes in an SQL string */
1946819685
int i, j; /* Loop counters */
@@ -19501,10 +19718,12 @@
1950119718
rc = 1;
1950219719
goto meta_command_exit;
1950319720
}
1950419721
}else if( strcmp(z,"-v")==0 ){
1950519722
eVerbose++;
19723
+ }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
19724
+ zSchema = azArg[++i];
1950619725
}else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
1950719726
nSkip = integerValue(azArg[++i]);
1950819727
}else if( strcmp(z,"-ascii")==0 ){
1950919728
sCtx.cColSep = SEP_Unit[0];
1951019729
sCtx.cRowSep = SEP_Record[0];
@@ -19592,10 +19811,11 @@
1959219811
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
1959319812
rc = 1;
1959419813
import_cleanup(&sCtx);
1959519814
goto meta_command_exit;
1959619815
}
19816
+ /* Below, resources must be freed before exit. */
1959719817
if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
1959819818
char zSep[2];
1959919819
zSep[1] = 0;
1960019820
zSep[0] = sCtx.cColSep;
1960119821
utf8_printf(p->out, "Column separator ");
@@ -19606,20 +19826,21 @@
1960619826
utf8_printf(p->out, "\n");
1960719827
}
1960819828
while( (nSkip--)>0 ){
1960919829
while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
1961019830
}
19611
- zSql = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
19831
+ zSql = sqlite3_mprintf("SELECT * FROM \"%w\".\"%w\"", zSchema, zTable);
1961219832
if( zSql==0 ){
1961319833
import_cleanup(&sCtx);
1961419834
shell_out_of_memory();
1961519835
}
1961619836
nByte = strlen30(zSql);
1961719837
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1961819838
import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
1961919839
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19620
- char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\"", zTable);
19840
+ char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
19841
+ zSchema, zTable);
1962119842
char cSep = '(';
1962219843
while( xRead(&sCtx) ){
1962319844
zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
1962419845
cSep = ',';
1962519846
if( sCtx.cTerm!=sCtx.cColSep ) break;
@@ -19634,18 +19855,18 @@
1963419855
zCreate = sqlite3_mprintf("%z\n)", zCreate);
1963519856
if( eVerbose>=1 ){
1963619857
utf8_printf(p->out, "%s\n", zCreate);
1963719858
}
1963819859
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
19639
- sqlite3_free(zCreate);
1964019860
if( rc ){
19641
- utf8_printf(stderr, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
19642
- sqlite3_errmsg(p->db));
19861
+ utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db));
19862
+ sqlite3_free(zCreate);
1964319863
import_cleanup(&sCtx);
1964419864
rc = 1;
1964519865
goto meta_command_exit;
1964619866
}
19867
+ sqlite3_free(zCreate);
1964719868
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1964819869
}
1964919870
sqlite3_free(zSql);
1965019871
if( rc ){
1965119872
if (pStmt) sqlite3_finalize(pStmt);
@@ -19661,11 +19882,12 @@
1966119882
zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
1966219883
if( zSql==0 ){
1966319884
import_cleanup(&sCtx);
1966419885
shell_out_of_memory();
1966519886
}
19666
- sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
19887
+ sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?",
19888
+ zSchema, zTable);
1966719889
j = strlen30(zSql);
1966819890
for(i=1; i<nCol; i++){
1966919891
zSql[j++] = ',';
1967019892
zSql[j++] = '?';
1967119893
}
@@ -19962,68 +20184,127 @@
1996220184
p->pLog = output_file_open(zFile, 0);
1996320185
}
1996420186
}else
1996520187
1996620188
if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
19967
- const char *zMode = nArg>=2 ? azArg[1] : "";
19968
- int n2 = strlen30(zMode);
19969
- int c2 = zMode[0];
19970
- if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
20189
+ const char *zMode = 0;
20190
+ const char *zTabname = 0;
20191
+ int i, n2;
20192
+ ColModeOpts cmOpts = ColModeOpts_default;
20193
+ for(i=1; i<nArg; i++){
20194
+ const char *z = azArg[i];
20195
+ if( optionMatch(z,"wrap") && i+1<nArg ){
20196
+ cmOpts.iWrap = integerValue(azArg[++i]);
20197
+ }else if( optionMatch(z,"ww") ){
20198
+ cmOpts.bWordWrap = 1;
20199
+ }else if( optionMatch(z,"wordwrap") && i+1<nArg ){
20200
+ cmOpts.bWordWrap = (u8)booleanValue(azArg[++i]);
20201
+ }else if( optionMatch(z,"quote") ){
20202
+ cmOpts.bQuote = 1;
20203
+ }else if( optionMatch(z,"noquote") ){
20204
+ cmOpts.bQuote = 0;
20205
+ }else if( zMode==0 ){
20206
+ zMode = z;
20207
+ /* Apply defaults for qbox pseudo-mods. If that
20208
+ * overwrites already-set values, user was informed of this.
20209
+ */
20210
+ if( strcmp(z, "qbox")==0 ){
20211
+ ColModeOpts cmo = ColModeOpts_default_qbox;
20212
+ zMode = "box";
20213
+ cmOpts = cmo;
20214
+ }
20215
+ }else if( zTabname==0 ){
20216
+ zTabname = z;
20217
+ }else if( z[0]=='-' ){
20218
+ utf8_printf(stderr, "unknown option: %s\n", z);
20219
+ utf8_printf(stderr, "options:\n"
20220
+ " --noquote\n"
20221
+ " --quote\n"
20222
+ " --wordwrap on/off\n"
20223
+ " --wrap N\n"
20224
+ " --ww\n");
20225
+ rc = 1;
20226
+ goto meta_command_exit;
20227
+ }else{
20228
+ utf8_printf(stderr, "extra argument: \"%s\"\n", z);
20229
+ rc = 1;
20230
+ goto meta_command_exit;
20231
+ }
20232
+ }
20233
+ if( zMode==0 ){
20234
+ if( p->mode==MODE_Column
20235
+ || (p->mode>=MODE_Markdown && p->mode<=MODE_Box)
20236
+ ){
20237
+ raw_printf
20238
+ (p->out,
20239
+ "current output mode: %s --wrap %d --wordwrap %s --%squote\n",
20240
+ modeDescr[p->mode], p->cmOpts.iWrap,
20241
+ p->cmOpts.bWordWrap ? "on" : "off",
20242
+ p->cmOpts.bQuote ? "" : "no");
20243
+ }else{
20244
+ raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]);
20245
+ }
20246
+ zMode = modeDescr[p->mode];
20247
+ }
20248
+ n2 = strlen30(zMode);
20249
+ if( strncmp(zMode,"lines",n2)==0 ){
1997120250
p->mode = MODE_Line;
1997220251
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19973
- }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
20252
+ }else if( strncmp(zMode,"columns",n2)==0 ){
1997420253
p->mode = MODE_Column;
1997520254
if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){
1997620255
p->showHeader = 1;
1997720256
}
1997820257
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19979
- }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
20258
+ p->cmOpts = cmOpts;
20259
+ }else if( strncmp(zMode,"list",n2)==0 ){
1998020260
p->mode = MODE_List;
1998120261
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
1998220262
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19983
- }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
20263
+ }else if( strncmp(zMode,"html",n2)==0 ){
1998420264
p->mode = MODE_Html;
19985
- }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
20265
+ }else if( strncmp(zMode,"tcl",n2)==0 ){
1998620266
p->mode = MODE_Tcl;
1998720267
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
1998820268
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19989
- }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
20269
+ }else if( strncmp(zMode,"csv",n2)==0 ){
1999020270
p->mode = MODE_Csv;
1999120271
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
1999220272
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
19993
- }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
20273
+ }else if( strncmp(zMode,"tabs",n2)==0 ){
1999420274
p->mode = MODE_List;
1999520275
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
19996
- }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
20276
+ }else if( strncmp(zMode,"insert",n2)==0 ){
1999720277
p->mode = MODE_Insert;
19998
- set_table_name(p, nArg>=3 ? azArg[2] : "table");
19999
- }else if( c2=='q' && strncmp(azArg[1],"quote",n2)==0 ){
20278
+ set_table_name(p, zTabname ? zTabname : "table");
20279
+ }else if( strncmp(zMode,"quote",n2)==0 ){
2000020280
p->mode = MODE_Quote;
2000120281
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
2000220282
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20003
- }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
20283
+ }else if( strncmp(zMode,"ascii",n2)==0 ){
2000420284
p->mode = MODE_Ascii;
2000520285
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
2000620286
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
20007
- }else if( c2=='m' && strncmp(azArg[1],"markdown",n2)==0 ){
20287
+ }else if( strncmp(zMode,"markdown",n2)==0 ){
2000820288
p->mode = MODE_Markdown;
20009
- }else if( c2=='t' && strncmp(azArg[1],"table",n2)==0 ){
20289
+ p->cmOpts = cmOpts;
20290
+ }else if( strncmp(zMode,"table",n2)==0 ){
2001020291
p->mode = MODE_Table;
20011
- }else if( c2=='b' && strncmp(azArg[1],"box",n2)==0 ){
20292
+ p->cmOpts = cmOpts;
20293
+ }else if( strncmp(zMode,"box",n2)==0 ){
2001220294
p->mode = MODE_Box;
20013
- }else if( c2=='c' && strncmp(azArg[1],"count",n2)==0 ){
20295
+ p->cmOpts = cmOpts;
20296
+ }else if( strncmp(zMode,"count",n2)==0 ){
2001420297
p->mode = MODE_Count;
20015
- }else if( c2=='o' && strncmp(azArg[1],"off",n2)==0 ){
20298
+ }else if( strncmp(zMode,"off",n2)==0 ){
2001620299
p->mode = MODE_Off;
20017
- }else if( c2=='j' && strncmp(azArg[1],"json",n2)==0 ){
20300
+ }else if( strncmp(zMode,"json",n2)==0 ){
2001820301
p->mode = MODE_Json;
20019
- }else if( nArg==1 ){
20020
- raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]);
2002120302
}else{
2002220303
raw_printf(stderr, "Error: mode should be one of: "
2002320304
"ascii box column csv html insert json line list markdown "
20024
- "quote table tabs tcl\n");
20305
+ "qbox quote table tabs tcl\n");
2002520306
rc = 1;
2002620307
}
2002720308
p->cMode = p->mode;
2002820309
}else
2002920310
@@ -21167,11 +21448,21 @@
2116721448
azBool[ShellHasFlag(p, SHFLG_Echo)]);
2116821449
utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
2116921450
utf8_printf(p->out, "%12.12s: %s\n","explain",
2117021451
p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
2117121452
utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
21172
- utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
21453
+ if( p->mode==MODE_Column
21454
+ || (p->mode>=MODE_Markdown && p->mode<=MODE_Box)
21455
+ ){
21456
+ utf8_printf
21457
+ (p->out, "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode",
21458
+ modeDescr[p->mode], p->cmOpts.iWrap,
21459
+ p->cmOpts.bWordWrap ? "on" : "off",
21460
+ p->cmOpts.bQuote ? "" : "no");
21461
+ }else{
21462
+ utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
21463
+ }
2117321464
utf8_printf(p->out, "%12.12s: ", "nullvalue");
2117421465
output_c_string(p->out, p->nullValue);
2117521466
raw_printf(p->out, "\n");
2117621467
utf8_printf(p->out,"%12.12s: %s\n","output",
2117721468
strlen30(p->outfile) ? p->outfile : "stdout");
@@ -22010,10 +22301,17 @@
2201022301
int rc; /* Error code */
2201122302
int errCnt = 0; /* Number of errors seen */
2201222303
int startline = 0; /* Line number for start of current input */
2201322304
QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
2201422305
22306
+ if( p->inputNesting==MAX_INPUT_NESTING ){
22307
+ /* This will be more informative in a later version. */
22308
+ utf8_printf(stderr,"Input nesting limit (%d) reached at line %d."
22309
+ " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
22310
+ return 1;
22311
+ }
22312
+ ++p->inputNesting;
2201522313
p->lineno = 0;
2201622314
while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
2201722315
fflush(p->out);
2201822316
zLine = one_input_line(p->in, zLine, nSql>0);
2201922317
if( zLine==0 ){
@@ -22092,10 +22390,11 @@
2209222390
if( nSql && QSS_PLAINDARK(qss) ){
2209322391
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2209422392
}
2209522393
free(zSql);
2209622394
free(zLine);
22395
+ --p->inputNesting;
2209722396
return errCnt>0;
2209822397
}
2209922398
2210022399
/*
2210122400
** Return a pathname which is the user's home directory. A
2210222401
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12143,10 +12143,19 @@
12143 EQPGraphRow *pRow; /* Linked list of all rows of the EQP output */
12144 EQPGraphRow *pLast; /* Last element of the pRow list */
12145 char zPrefix[100]; /* Graph prefix */
12146 };
12147
 
 
 
 
 
 
 
 
 
12148 /*
12149 ** State information about the database connection is contained in an
12150 ** instance of the following structure.
12151 */
12152 typedef struct ShellState ShellState;
@@ -12161,12 +12170,14 @@
12161 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
12162 u8 nEqpLevel; /* Depth of the EQP output graph */
12163 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
12164 u8 bSafeMode; /* True to prohibit unsafe operations */
12165 u8 bSafeModePersist; /* The long-term value of bSafeMode */
 
12166 unsigned statsOn; /* True to display memory stats before each finalize */
12167 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
 
12168 int outCount; /* Revert to stdout when reaching zero */
12169 int cnt; /* Number of records displayed so far */
12170 int lineno; /* Line number of last line read from in */
12171 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
12172 FILE *in; /* Read commands from this stream */
@@ -12327,10 +12338,16 @@
12327 #define SEP_Comma ","
12328 #define SEP_CrLf "\r\n"
12329 #define SEP_Unit "\x1F"
12330 #define SEP_Record "\x1E"
12331
 
 
 
 
 
 
12332 /*
12333 ** A callback for the sqlite3_log() interface.
12334 */
12335 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
12336 ShellState *p = (ShellState*)pArg;
@@ -14234,11 +14251,138 @@
14234 utf8_printf(p->out, "%s", zSep3);
14235 }
14236 fputs("\n", p->out);
14237 }
14238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14240
14241 /*
14242 ** Run a prepared statement and output the result in one of the
14243 ** table-oriented formats: MODE_Column, MODE_Markdown, MODE_Table,
14244 ** or MODE_Box.
@@ -14254,39 +14398,41 @@
14254 ){
14255 sqlite3_int64 nRow = 0;
14256 int nColumn = 0;
14257 char **azData = 0;
14258 sqlite3_int64 nAlloc = 0;
 
 
14259 const char *z;
 
14260 int rc;
14261 sqlite3_int64 i, nData;
14262 int j, nTotal, w, n;
14263 const char *colSep = 0;
14264 const char *rowSep = 0;
 
 
 
 
14265
14266 rc = sqlite3_step(pStmt);
14267 if( rc!=SQLITE_ROW ) return;
14268 nColumn = sqlite3_column_count(pStmt);
14269 nAlloc = nColumn*4;
14270 if( nAlloc<=0 ) nAlloc = 1;
14271 azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
14272 shell_check_oom(azData);
14273 for(i=0; i<nColumn; i++){
14274 azData[i] = strdup(sqlite3_column_name(pStmt,i));
14275 }
14276 do{
14277 if( (nRow+2)*nColumn >= nAlloc ){
14278 nAlloc *= 2;
14279 azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
14280 shell_check_oom(azData);
14281 }
14282 nRow++;
14283 for(i=0; i<nColumn; i++){
14284 z = (const char*)sqlite3_column_text(pStmt,i);
14285 azData[nRow*nColumn + i] = z ? strdup(z) : 0;
14286 }
14287 }while( sqlite3_step(pStmt)==SQLITE_ROW );
14288 if( nColumn>p->nWidth ){
14289 p->colWidth = realloc(p->colWidth, (nColumn+1)*2*sizeof(int));
14290 shell_check_oom(p->colWidth);
14291 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
14292 p->nWidth = nColumn;
@@ -14296,10 +14442,56 @@
14296 for(i=0; i<nColumn; i++){
14297 w = p->colWidth[i];
14298 if( w<0 ) w = -w;
14299 p->actualWidth[i] = w;
14300 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14301 nTotal = nColumn*(nRow+1);
14302 for(i=0; i<nTotal; i++){
14303 z = azData[i];
14304 if( z==0 ) z = p->nullValue;
14305 n = strlenChar(z);
@@ -14378,10 +14570,19 @@
14378 w = p->actualWidth[j];
14379 if( p->colWidth[j]<0 ) w = -w;
14380 utf8_width_print(p->out, w, z);
14381 if( j==nColumn-1 ){
14382 utf8_printf(p->out, "%s", rowSep);
 
 
 
 
 
 
 
 
 
14383 j = -1;
14384 if( seenInterrupt ) goto columnar_end;
14385 }else{
14386 utf8_printf(p->out, "%s", colSep);
14387 }
@@ -14396,10 +14597,16 @@
14396 utf8_printf(p->out, "Interrupt\n");
14397 }
14398 nData = (nRow+1)*nColumn;
14399 for(i=0; i<nData; i++) free(azData[i]);
14400 sqlite3_free(azData);
 
 
 
 
 
 
14401 }
14402
14403 /*
14404 ** Run a prepared statement
14405 */
@@ -15147,10 +15354,11 @@
15147 ".import FILE TABLE Import data from FILE into TABLE",
15148 " Options:",
15149 " --ascii Use \\037 and \\036 as column and row separators",
15150 " --csv Use , and \\n as column and row separators",
15151 " --skip N Skip the first N rows of input",
 
15152 " -v \"Verbose\" - increase auxiliary output",
15153 " Notes:",
15154 " * If TABLE does not exist, it is created. The first row of input",
15155 " determines the column names.",
15156 " * If neither --csv or --ascii are used, the input mode is derived",
@@ -15172,27 +15380,35 @@
15172 " fkey-indexes Find missing foreign key indexes",
15173 #ifndef SQLITE_OMIT_LOAD_EXTENSION
15174 ".load FILE ?ENTRY? Load an extension library",
15175 #endif
15176 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15177 ".mode MODE ?TABLE? Set output mode",
15178 " MODE is one of:",
15179 " ascii Columns/rows delimited by 0x1F and 0x1E",
15180 " box Tables using unicode box-drawing characters",
15181 " csv Comma-separated values",
15182 " column Output in columns. (See .width)",
15183 " html HTML <table> code",
15184 " insert SQL insert statements for TABLE",
15185 " json Results in a JSON array",
15186 " line One value per line",
15187 " list Values delimited by \"|\"",
15188 " markdown Markdown table format",
15189 " quote Escape answers as for SQL",
15190 " table ASCII-art table",
15191 " tabs Tab-separated values",
15192 " tcl TCL list elements",
15193 ".nonce STRING Disable safe mode for one command if the nonce matches",
 
 
 
 
 
 
 
 
15194 ".nullvalue STRING Use STRING in place of NULL values",
15195 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15196 " If FILE begins with '|' then open as a pipe",
15197 " --bom Put a UTF8 byte-order mark at the beginning",
15198 " -e Send output to the system text editor",
@@ -19459,10 +19675,11 @@
19459 }
19460 }else
19461
19462 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
19463 char *zTable = 0; /* Insert data into this table */
 
19464 char *zFile = 0; /* Name of file to extra content from */
19465 sqlite3_stmt *pStmt = NULL; /* A statement */
19466 int nCol; /* Number of columns in the table */
19467 int nByte; /* Number of bytes in an SQL string */
19468 int i, j; /* Loop counters */
@@ -19501,10 +19718,12 @@
19501 rc = 1;
19502 goto meta_command_exit;
19503 }
19504 }else if( strcmp(z,"-v")==0 ){
19505 eVerbose++;
 
 
19506 }else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
19507 nSkip = integerValue(azArg[++i]);
19508 }else if( strcmp(z,"-ascii")==0 ){
19509 sCtx.cColSep = SEP_Unit[0];
19510 sCtx.cRowSep = SEP_Record[0];
@@ -19592,10 +19811,11 @@
19592 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
19593 rc = 1;
19594 import_cleanup(&sCtx);
19595 goto meta_command_exit;
19596 }
 
19597 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
19598 char zSep[2];
19599 zSep[1] = 0;
19600 zSep[0] = sCtx.cColSep;
19601 utf8_printf(p->out, "Column separator ");
@@ -19606,20 +19826,21 @@
19606 utf8_printf(p->out, "\n");
19607 }
19608 while( (nSkip--)>0 ){
19609 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
19610 }
19611 zSql = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
19612 if( zSql==0 ){
19613 import_cleanup(&sCtx);
19614 shell_out_of_memory();
19615 }
19616 nByte = strlen30(zSql);
19617 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19618 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
19619 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19620 char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\"", zTable);
 
19621 char cSep = '(';
19622 while( xRead(&sCtx) ){
19623 zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
19624 cSep = ',';
19625 if( sCtx.cTerm!=sCtx.cColSep ) break;
@@ -19634,18 +19855,18 @@
19634 zCreate = sqlite3_mprintf("%z\n)", zCreate);
19635 if( eVerbose>=1 ){
19636 utf8_printf(p->out, "%s\n", zCreate);
19637 }
19638 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
19639 sqlite3_free(zCreate);
19640 if( rc ){
19641 utf8_printf(stderr, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
19642 sqlite3_errmsg(p->db));
19643 import_cleanup(&sCtx);
19644 rc = 1;
19645 goto meta_command_exit;
19646 }
 
19647 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19648 }
19649 sqlite3_free(zSql);
19650 if( rc ){
19651 if (pStmt) sqlite3_finalize(pStmt);
@@ -19661,11 +19882,12 @@
19661 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
19662 if( zSql==0 ){
19663 import_cleanup(&sCtx);
19664 shell_out_of_memory();
19665 }
19666 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
 
19667 j = strlen30(zSql);
19668 for(i=1; i<nCol; i++){
19669 zSql[j++] = ',';
19670 zSql[j++] = '?';
19671 }
@@ -19962,68 +20184,127 @@
19962 p->pLog = output_file_open(zFile, 0);
19963 }
19964 }else
19965
19966 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
19967 const char *zMode = nArg>=2 ? azArg[1] : "";
19968 int n2 = strlen30(zMode);
19969 int c2 = zMode[0];
19970 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19971 p->mode = MODE_Line;
19972 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19973 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
19974 p->mode = MODE_Column;
19975 if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){
19976 p->showHeader = 1;
19977 }
19978 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19979 }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
 
19980 p->mode = MODE_List;
19981 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
19982 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19983 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
19984 p->mode = MODE_Html;
19985 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
19986 p->mode = MODE_Tcl;
19987 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
19988 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
19989 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
19990 p->mode = MODE_Csv;
19991 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
19992 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
19993 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
19994 p->mode = MODE_List;
19995 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
19996 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
19997 p->mode = MODE_Insert;
19998 set_table_name(p, nArg>=3 ? azArg[2] : "table");
19999 }else if( c2=='q' && strncmp(azArg[1],"quote",n2)==0 ){
20000 p->mode = MODE_Quote;
20001 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
20002 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20003 }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
20004 p->mode = MODE_Ascii;
20005 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
20006 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
20007 }else if( c2=='m' && strncmp(azArg[1],"markdown",n2)==0 ){
20008 p->mode = MODE_Markdown;
20009 }else if( c2=='t' && strncmp(azArg[1],"table",n2)==0 ){
 
20010 p->mode = MODE_Table;
20011 }else if( c2=='b' && strncmp(azArg[1],"box",n2)==0 ){
 
20012 p->mode = MODE_Box;
20013 }else if( c2=='c' && strncmp(azArg[1],"count",n2)==0 ){
 
20014 p->mode = MODE_Count;
20015 }else if( c2=='o' && strncmp(azArg[1],"off",n2)==0 ){
20016 p->mode = MODE_Off;
20017 }else if( c2=='j' && strncmp(azArg[1],"json",n2)==0 ){
20018 p->mode = MODE_Json;
20019 }else if( nArg==1 ){
20020 raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]);
20021 }else{
20022 raw_printf(stderr, "Error: mode should be one of: "
20023 "ascii box column csv html insert json line list markdown "
20024 "quote table tabs tcl\n");
20025 rc = 1;
20026 }
20027 p->cMode = p->mode;
20028 }else
20029
@@ -21167,11 +21448,21 @@
21167 azBool[ShellHasFlag(p, SHFLG_Echo)]);
21168 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
21169 utf8_printf(p->out, "%12.12s: %s\n","explain",
21170 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
21171 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
21172 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
 
 
 
 
 
 
 
 
 
 
21173 utf8_printf(p->out, "%12.12s: ", "nullvalue");
21174 output_c_string(p->out, p->nullValue);
21175 raw_printf(p->out, "\n");
21176 utf8_printf(p->out,"%12.12s: %s\n","output",
21177 strlen30(p->outfile) ? p->outfile : "stdout");
@@ -22010,10 +22301,17 @@
22010 int rc; /* Error code */
22011 int errCnt = 0; /* Number of errors seen */
22012 int startline = 0; /* Line number for start of current input */
22013 QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
22014
 
 
 
 
 
 
 
22015 p->lineno = 0;
22016 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
22017 fflush(p->out);
22018 zLine = one_input_line(p->in, zLine, nSql>0);
22019 if( zLine==0 ){
@@ -22092,10 +22390,11 @@
22092 if( nSql && QSS_PLAINDARK(qss) ){
22093 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22094 }
22095 free(zSql);
22096 free(zLine);
 
22097 return errCnt>0;
22098 }
22099
22100 /*
22101 ** Return a pathname which is the user's home directory. A
22102
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12143,10 +12143,19 @@
12143 EQPGraphRow *pRow; /* Linked list of all rows of the EQP output */
12144 EQPGraphRow *pLast; /* Last element of the pRow list */
12145 char zPrefix[100]; /* Graph prefix */
12146 };
12147
12148 /* Parameters affecting columnar mode result display (defaulting together) */
12149 typedef struct ColModeOpts {
12150 int iWrap; /* In columnar modes, wrap lines reaching this limit */
12151 u8 bQuote; /* Quote results for .mode box and table */
12152 u8 bWordWrap; /* In columnar modes, wrap at word boundaries */
12153 } ColModeOpts;
12154 #define ColModeOpts_default { 60, 0, 0 }
12155 #define ColModeOpts_default_qbox { 60, 1, 0 }
12156
12157 /*
12158 ** State information about the database connection is contained in an
12159 ** instance of the following structure.
12160 */
12161 typedef struct ShellState ShellState;
@@ -12161,12 +12170,14 @@
12170 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
12171 u8 nEqpLevel; /* Depth of the EQP output graph */
12172 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
12173 u8 bSafeMode; /* True to prohibit unsafe operations */
12174 u8 bSafeModePersist; /* The long-term value of bSafeMode */
12175 ColModeOpts cmOpts; /* Option values affecting columnar mode output */
12176 unsigned statsOn; /* True to display memory stats before each finalize */
12177 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
12178 int inputNesting; /* Track nesting level of .read and other redirects */
12179 int outCount; /* Revert to stdout when reaching zero */
12180 int cnt; /* Number of records displayed so far */
12181 int lineno; /* Line number of last line read from in */
12182 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
12183 FILE *in; /* Read commands from this stream */
@@ -12327,10 +12338,16 @@
12338 #define SEP_Comma ","
12339 #define SEP_CrLf "\r\n"
12340 #define SEP_Unit "\x1F"
12341 #define SEP_Record "\x1E"
12342
12343 /*
12344 ** Limit input nesting via .read or any other input redirect.
12345 ** It's not too expensive, so a generous allowance can be made.
12346 */
12347 #define MAX_INPUT_NESTING 25
12348
12349 /*
12350 ** A callback for the sqlite3_log() interface.
12351 */
12352 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
12353 ShellState *p = (ShellState*)pArg;
@@ -14234,11 +14251,138 @@
14251 utf8_printf(p->out, "%s", zSep3);
14252 }
14253 fputs("\n", p->out);
14254 }
14255
14256 /*
14257 ** z[] is a line of text that is to be displayed the .mode box or table or
14258 ** similar tabular formats. z[] might contain control characters such
14259 ** as \n, \t, \f, or \r.
14260 **
14261 ** Compute characters to display on the first line of z[]. Stop at the
14262 ** first \r, \n, or \f. Expand \t into spaces. Return a copy (obtained
14263 ** from malloc()) of that first line, which caller should free sometime.
14264 ** Write anything to display on the next line into *pzTail. If this is
14265 ** the last line, write a NULL into *pzTail. (*pzTail is not allocated.)
14266 */
14267 static char *translateForDisplayAndDup(
14268 const unsigned char *z, /* Input text to be transformed */
14269 const unsigned char **pzTail, /* OUT: Tail of the input for next line */
14270 int mxWidth, /* Max width. 0 means no limit */
14271 u8 bWordWrap /* If true, avoid breaking mid-word */
14272 ){
14273 int i; /* Input bytes consumed */
14274 int j; /* Output bytes generated */
14275 int k; /* Input bytes to be displayed */
14276 int n; /* Output column number */
14277 unsigned char *zOut; /* Output text */
14278
14279 if( z==0 ){
14280 *pzTail = 0;
14281 return 0;
14282 }
14283 if( mxWidth<0 ) mxWidth = -mxWidth;
14284 if( mxWidth==0 ) mxWidth = 1000000;
14285 i = j = n = 0;
14286 while( n<mxWidth ){
14287 if( z[i]>=' ' ){
14288 n++;
14289 do{ i++; j++; }while( (z[i]&0xc0)==0x80 );
14290 continue;
14291 }
14292 if( z[i]=='\t' ){
14293 do{
14294 n++;
14295 j++;
14296 }while( (n&7)!=0 && n<mxWidth );
14297 i++;
14298 continue;
14299 }
14300 break;
14301 }
14302 if( n>=mxWidth && bWordWrap ){
14303 /* Perhaps try to back up to a better place to break the line */
14304 for(k=i; k>i/2; k--){
14305 if( isspace(z[k-1]) ) break;
14306 }
14307 if( k<=i/2 ){
14308 for(k=i; k>i/2; k--){
14309 if( isalnum(z[k-1])!=isalnum(z[k]) && (z[k]&0xc0)!=0x80 ) break;
14310 }
14311 }
14312 if( k<=i/2 ){
14313 k = i;
14314 }else{
14315 i = k;
14316 while( z[i]==' ' ) i++;
14317 }
14318 }else{
14319 k = i;
14320 }
14321 if( n>=mxWidth && z[i]>=' ' ){
14322 *pzTail = &z[i];
14323 }else if( z[i]=='\r' && z[i+1]=='\n' ){
14324 *pzTail = z[i+2] ? &z[i+2] : 0;
14325 }else if( z[i]==0 || z[i+1]==0 ){
14326 *pzTail = 0;
14327 }else{
14328 *pzTail = &z[i+1];
14329 }
14330 zOut = malloc( j+1 );
14331 shell_check_oom(zOut);
14332 i = j = n = 0;
14333 while( i<k ){
14334 if( z[i]>=' ' ){
14335 n++;
14336 do{ zOut[j++] = z[i++]; }while( (z[i]&0xc0)==0x80 );
14337 continue;
14338 }
14339 if( z[i]=='\t' ){
14340 do{
14341 n++;
14342 zOut[j++] = ' ';
14343 }while( (n&7)!=0 && n<mxWidth );
14344 i++;
14345 continue;
14346 }
14347 break;
14348 }
14349 zOut[j] = 0;
14350 return (char*)zOut;
14351 }
14352
14353 /* Extract the value of the i-th current column for pStmt as an SQL literal
14354 ** value. Memory is obtained from sqlite3_malloc64() and must be freed by
14355 ** the caller.
14356 */
14357 static char *quoted_column(sqlite3_stmt *pStmt, int i){
14358 switch( sqlite3_column_type(pStmt, i) ){
14359 case SQLITE_NULL: {
14360 return sqlite3_mprintf("NULL");
14361 }
14362 case SQLITE_INTEGER:
14363 case SQLITE_FLOAT: {
14364 return sqlite3_mprintf("%s",sqlite3_column_text(pStmt,i));
14365 }
14366 case SQLITE_TEXT: {
14367 return sqlite3_mprintf("%Q",sqlite3_column_text(pStmt,i));
14368 }
14369 case SQLITE_BLOB: {
14370 int j;
14371 sqlite3_str *pStr = sqlite3_str_new(0);
14372 const unsigned char *a = sqlite3_column_blob(pStmt,i);
14373 int n = sqlite3_column_bytes(pStmt,i);
14374 sqlite3_str_append(pStr, "x'", 2);
14375 for(j=0; j<n; j++){
14376 sqlite3_str_appendf(pStr, "%02x", a[j]);
14377 }
14378 sqlite3_str_append(pStr, "'", 1);
14379 return sqlite3_str_finish(pStr);
14380 }
14381 }
14382 return 0; /* Not reached */
14383 }
14384
14385 /*
14386 ** Run a prepared statement and output the result in one of the
14387 ** table-oriented formats: MODE_Column, MODE_Markdown, MODE_Table,
14388 ** or MODE_Box.
@@ -14254,39 +14398,41 @@
14398 ){
14399 sqlite3_int64 nRow = 0;
14400 int nColumn = 0;
14401 char **azData = 0;
14402 sqlite3_int64 nAlloc = 0;
14403 char *abRowDiv = 0;
14404 const unsigned char *uz;
14405 const char *z;
14406 char **azQuoted = 0;
14407 int rc;
14408 sqlite3_int64 i, nData;
14409 int j, nTotal, w, n;
14410 const char *colSep = 0;
14411 const char *rowSep = 0;
14412 const unsigned char **azNextLine = 0;
14413 int bNextLine = 0;
14414 int bMultiLineRowExists = 0;
14415 int bw = p->cmOpts.bWordWrap;
14416
14417 rc = sqlite3_step(pStmt);
14418 if( rc!=SQLITE_ROW ) return;
14419 nColumn = sqlite3_column_count(pStmt);
14420 nAlloc = nColumn*4;
14421 if( nAlloc<=0 ) nAlloc = 1;
14422 azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
14423 shell_check_oom(azData);
14424 azNextLine = sqlite3_malloc64( nColumn*sizeof(char*) );
14425 shell_check_oom((void*)azNextLine);
14426 memset((void*)azNextLine, 0, nColumn*sizeof(char*) );
14427 if( p->cmOpts.bQuote ){
14428 azQuoted = sqlite3_malloc64( nColumn*sizeof(char*) );
14429 shell_check_oom(azQuoted);
14430 memset(azQuoted, 0, nColumn*sizeof(char*) );
14431 }
14432 abRowDiv = sqlite3_malloc64( nAlloc/nColumn );
14433 shell_check_oom(abRowDiv);
 
 
 
 
 
14434 if( nColumn>p->nWidth ){
14435 p->colWidth = realloc(p->colWidth, (nColumn+1)*2*sizeof(int));
14436 shell_check_oom(p->colWidth);
14437 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
14438 p->nWidth = nColumn;
@@ -14296,10 +14442,56 @@
14442 for(i=0; i<nColumn; i++){
14443 w = p->colWidth[i];
14444 if( w<0 ) w = -w;
14445 p->actualWidth[i] = w;
14446 }
14447 for(i=0; i<nColumn; i++){
14448 const unsigned char *zNotUsed;
14449 int wx = p->colWidth[i];
14450 if( wx==0 ){
14451 wx = p->cmOpts.iWrap;
14452 }
14453 if( wx<0 ) wx = -wx;
14454 uz = (const unsigned char*)sqlite3_column_name(pStmt,i);
14455 azData[i] = translateForDisplayAndDup(uz, &zNotUsed, wx, bw);
14456 }
14457 do{
14458 int useNextLine = bNextLine;
14459 bNextLine = 0;
14460 if( (nRow+2)*nColumn >= nAlloc ){
14461 nAlloc *= 2;
14462 azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
14463 shell_check_oom(azData);
14464 abRowDiv = sqlite3_realloc64(abRowDiv, nAlloc/nColumn);
14465 shell_check_oom(abRowDiv);
14466 }
14467 abRowDiv[nRow] = 1;
14468 nRow++;
14469 for(i=0; i<nColumn; i++){
14470 int wx = p->colWidth[i];
14471 if( wx==0 ){
14472 wx = p->cmOpts.iWrap;
14473 }
14474 if( wx<0 ) wx = -wx;
14475 if( useNextLine ){
14476 uz = azNextLine[i];
14477 }else if( p->cmOpts.bQuote ){
14478 sqlite3_free(azQuoted[i]);
14479 azQuoted[i] = quoted_column(pStmt,i);
14480 uz = (const unsigned char*)azQuoted[i];
14481 }else{
14482 uz = (const unsigned char*)sqlite3_column_text(pStmt,i);
14483 }
14484 azData[nRow*nColumn + i]
14485 = translateForDisplayAndDup(uz, &azNextLine[i], wx, bw);
14486 if( azNextLine[i] ){
14487 bNextLine = 1;
14488 abRowDiv[nRow-1] = 0;
14489 bMultiLineRowExists = 1;
14490 }
14491 }
14492 }while( bNextLine || sqlite3_step(pStmt)==SQLITE_ROW );
14493 nTotal = nColumn*(nRow+1);
14494 for(i=0; i<nTotal; i++){
14495 z = azData[i];
14496 if( z==0 ) z = p->nullValue;
14497 n = strlenChar(z);
@@ -14378,10 +14570,19 @@
14570 w = p->actualWidth[j];
14571 if( p->colWidth[j]<0 ) w = -w;
14572 utf8_width_print(p->out, w, z);
14573 if( j==nColumn-1 ){
14574 utf8_printf(p->out, "%s", rowSep);
14575 if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1<nTotal ){
14576 if( p->cMode==MODE_Table ){
14577 print_row_separator(p, nColumn, "+");
14578 }else if( p->cMode==MODE_Box ){
14579 print_box_row_separator(p, nColumn, BOX_123, BOX_1234, BOX_134);
14580 }else if( p->cMode==MODE_Column ){
14581 raw_printf(p->out, "\n");
14582 }
14583 }
14584 j = -1;
14585 if( seenInterrupt ) goto columnar_end;
14586 }else{
14587 utf8_printf(p->out, "%s", colSep);
14588 }
@@ -14396,10 +14597,16 @@
14597 utf8_printf(p->out, "Interrupt\n");
14598 }
14599 nData = (nRow+1)*nColumn;
14600 for(i=0; i<nData; i++) free(azData[i]);
14601 sqlite3_free(azData);
14602 sqlite3_free((void*)azNextLine);
14603 sqlite3_free(abRowDiv);
14604 if( azQuoted ){
14605 for(i=0; i<nColumn; i++) sqlite3_free(azQuoted[i]);
14606 sqlite3_free(azQuoted);
14607 }
14608 }
14609
14610 /*
14611 ** Run a prepared statement
14612 */
@@ -15147,10 +15354,11 @@
15354 ".import FILE TABLE Import data from FILE into TABLE",
15355 " Options:",
15356 " --ascii Use \\037 and \\036 as column and row separators",
15357 " --csv Use , and \\n as column and row separators",
15358 " --skip N Skip the first N rows of input",
15359 " --schema S Target table to be S.TABLE",
15360 " -v \"Verbose\" - increase auxiliary output",
15361 " Notes:",
15362 " * If TABLE does not exist, it is created. The first row of input",
15363 " determines the column names.",
15364 " * If neither --csv or --ascii are used, the input mode is derived",
@@ -15172,27 +15380,35 @@
15380 " fkey-indexes Find missing foreign key indexes",
15381 #ifndef SQLITE_OMIT_LOAD_EXTENSION
15382 ".load FILE ?ENTRY? Load an extension library",
15383 #endif
15384 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15385 ".mode MODE ?OPTIONS? Set output mode",
15386 " MODE is one of:",
15387 " ascii Columns/rows delimited by 0x1F and 0x1E",
15388 " box Tables using unicode box-drawing characters",
15389 " csv Comma-separated values",
15390 " column Output in columns. (See .width)",
15391 " html HTML <table> code",
15392 " insert SQL insert statements for TABLE",
15393 " json Results in a JSON array",
15394 " line One value per line",
15395 " list Values delimited by \"|\"",
15396 " markdown Markdown table format",
15397 " qbox Shorthand for \"box --width 60 --quote\"",
15398 " quote Escape answers as for SQL",
15399 " table ASCII-art table",
15400 " tabs Tab-separated values",
15401 " tcl TCL list elements",
15402 " OPTIONS: (for columnar modes or insert mode):",
15403 " --wrap N Wrap output lines to no longer than N characters",
15404 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15405 " --ww Shorthand for \"--wordwrap 1\"",
15406 " --quote Quote output text as SQL literals",
15407 " --noquote Do not quote output text",
15408 " TABLE The name of SQL table used for \"insert\" mode",
15409 ".nonce STRING Suspend safe mode for one command if nonce matches",
15410 ".nullvalue STRING Use STRING in place of NULL values",
15411 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15412 " If FILE begins with '|' then open as a pipe",
15413 " --bom Put a UTF8 byte-order mark at the beginning",
15414 " -e Send output to the system text editor",
@@ -19459,10 +19675,11 @@
19675 }
19676 }else
19677
19678 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
19679 char *zTable = 0; /* Insert data into this table */
19680 char *zSchema = "main"; /* within this schema */
19681 char *zFile = 0; /* Name of file to extra content from */
19682 sqlite3_stmt *pStmt = NULL; /* A statement */
19683 int nCol; /* Number of columns in the table */
19684 int nByte; /* Number of bytes in an SQL string */
19685 int i, j; /* Loop counters */
@@ -19501,10 +19718,12 @@
19718 rc = 1;
19719 goto meta_command_exit;
19720 }
19721 }else if( strcmp(z,"-v")==0 ){
19722 eVerbose++;
19723 }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
19724 zSchema = azArg[++i];
19725 }else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
19726 nSkip = integerValue(azArg[++i]);
19727 }else if( strcmp(z,"-ascii")==0 ){
19728 sCtx.cColSep = SEP_Unit[0];
19729 sCtx.cRowSep = SEP_Record[0];
@@ -19592,10 +19811,11 @@
19811 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
19812 rc = 1;
19813 import_cleanup(&sCtx);
19814 goto meta_command_exit;
19815 }
19816 /* Below, resources must be freed before exit. */
19817 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
19818 char zSep[2];
19819 zSep[1] = 0;
19820 zSep[0] = sCtx.cColSep;
19821 utf8_printf(p->out, "Column separator ");
@@ -19606,20 +19826,21 @@
19826 utf8_printf(p->out, "\n");
19827 }
19828 while( (nSkip--)>0 ){
19829 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
19830 }
19831 zSql = sqlite3_mprintf("SELECT * FROM \"%w\".\"%w\"", zSchema, zTable);
19832 if( zSql==0 ){
19833 import_cleanup(&sCtx);
19834 shell_out_of_memory();
19835 }
19836 nByte = strlen30(zSql);
19837 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19838 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
19839 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19840 char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
19841 zSchema, zTable);
19842 char cSep = '(';
19843 while( xRead(&sCtx) ){
19844 zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
19845 cSep = ',';
19846 if( sCtx.cTerm!=sCtx.cColSep ) break;
@@ -19634,18 +19855,18 @@
19855 zCreate = sqlite3_mprintf("%z\n)", zCreate);
19856 if( eVerbose>=1 ){
19857 utf8_printf(p->out, "%s\n", zCreate);
19858 }
19859 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
 
19860 if( rc ){
19861 utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db));
19862 sqlite3_free(zCreate);
19863 import_cleanup(&sCtx);
19864 rc = 1;
19865 goto meta_command_exit;
19866 }
19867 sqlite3_free(zCreate);
19868 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19869 }
19870 sqlite3_free(zSql);
19871 if( rc ){
19872 if (pStmt) sqlite3_finalize(pStmt);
@@ -19661,11 +19882,12 @@
19882 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
19883 if( zSql==0 ){
19884 import_cleanup(&sCtx);
19885 shell_out_of_memory();
19886 }
19887 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?",
19888 zSchema, zTable);
19889 j = strlen30(zSql);
19890 for(i=1; i<nCol; i++){
19891 zSql[j++] = ',';
19892 zSql[j++] = '?';
19893 }
@@ -19962,68 +20184,127 @@
20184 p->pLog = output_file_open(zFile, 0);
20185 }
20186 }else
20187
20188 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
20189 const char *zMode = 0;
20190 const char *zTabname = 0;
20191 int i, n2;
20192 ColModeOpts cmOpts = ColModeOpts_default;
20193 for(i=1; i<nArg; i++){
20194 const char *z = azArg[i];
20195 if( optionMatch(z,"wrap") && i+1<nArg ){
20196 cmOpts.iWrap = integerValue(azArg[++i]);
20197 }else if( optionMatch(z,"ww") ){
20198 cmOpts.bWordWrap = 1;
20199 }else if( optionMatch(z,"wordwrap") && i+1<nArg ){
20200 cmOpts.bWordWrap = (u8)booleanValue(azArg[++i]);
20201 }else if( optionMatch(z,"quote") ){
20202 cmOpts.bQuote = 1;
20203 }else if( optionMatch(z,"noquote") ){
20204 cmOpts.bQuote = 0;
20205 }else if( zMode==0 ){
20206 zMode = z;
20207 /* Apply defaults for qbox pseudo-mods. If that
20208 * overwrites already-set values, user was informed of this.
20209 */
20210 if( strcmp(z, "qbox")==0 ){
20211 ColModeOpts cmo = ColModeOpts_default_qbox;
20212 zMode = "box";
20213 cmOpts = cmo;
20214 }
20215 }else if( zTabname==0 ){
20216 zTabname = z;
20217 }else if( z[0]=='-' ){
20218 utf8_printf(stderr, "unknown option: %s\n", z);
20219 utf8_printf(stderr, "options:\n"
20220 " --noquote\n"
20221 " --quote\n"
20222 " --wordwrap on/off\n"
20223 " --wrap N\n"
20224 " --ww\n");
20225 rc = 1;
20226 goto meta_command_exit;
20227 }else{
20228 utf8_printf(stderr, "extra argument: \"%s\"\n", z);
20229 rc = 1;
20230 goto meta_command_exit;
20231 }
20232 }
20233 if( zMode==0 ){
20234 if( p->mode==MODE_Column
20235 || (p->mode>=MODE_Markdown && p->mode<=MODE_Box)
20236 ){
20237 raw_printf
20238 (p->out,
20239 "current output mode: %s --wrap %d --wordwrap %s --%squote\n",
20240 modeDescr[p->mode], p->cmOpts.iWrap,
20241 p->cmOpts.bWordWrap ? "on" : "off",
20242 p->cmOpts.bQuote ? "" : "no");
20243 }else{
20244 raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]);
20245 }
20246 zMode = modeDescr[p->mode];
20247 }
20248 n2 = strlen30(zMode);
20249 if( strncmp(zMode,"lines",n2)==0 ){
20250 p->mode = MODE_Line;
20251 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20252 }else if( strncmp(zMode,"columns",n2)==0 ){
20253 p->mode = MODE_Column;
20254 if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){
20255 p->showHeader = 1;
20256 }
20257 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20258 p->cmOpts = cmOpts;
20259 }else if( strncmp(zMode,"list",n2)==0 ){
20260 p->mode = MODE_List;
20261 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
20262 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20263 }else if( strncmp(zMode,"html",n2)==0 ){
20264 p->mode = MODE_Html;
20265 }else if( strncmp(zMode,"tcl",n2)==0 ){
20266 p->mode = MODE_Tcl;
20267 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
20268 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20269 }else if( strncmp(zMode,"csv",n2)==0 ){
20270 p->mode = MODE_Csv;
20271 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
20272 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
20273 }else if( strncmp(zMode,"tabs",n2)==0 ){
20274 p->mode = MODE_List;
20275 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
20276 }else if( strncmp(zMode,"insert",n2)==0 ){
20277 p->mode = MODE_Insert;
20278 set_table_name(p, zTabname ? zTabname : "table");
20279 }else if( strncmp(zMode,"quote",n2)==0 ){
20280 p->mode = MODE_Quote;
20281 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
20282 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
20283 }else if( strncmp(zMode,"ascii",n2)==0 ){
20284 p->mode = MODE_Ascii;
20285 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
20286 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
20287 }else if( strncmp(zMode,"markdown",n2)==0 ){
20288 p->mode = MODE_Markdown;
20289 p->cmOpts = cmOpts;
20290 }else if( strncmp(zMode,"table",n2)==0 ){
20291 p->mode = MODE_Table;
20292 p->cmOpts = cmOpts;
20293 }else if( strncmp(zMode,"box",n2)==0 ){
20294 p->mode = MODE_Box;
20295 p->cmOpts = cmOpts;
20296 }else if( strncmp(zMode,"count",n2)==0 ){
20297 p->mode = MODE_Count;
20298 }else if( strncmp(zMode,"off",n2)==0 ){
20299 p->mode = MODE_Off;
20300 }else if( strncmp(zMode,"json",n2)==0 ){
20301 p->mode = MODE_Json;
 
 
20302 }else{
20303 raw_printf(stderr, "Error: mode should be one of: "
20304 "ascii box column csv html insert json line list markdown "
20305 "qbox quote table tabs tcl\n");
20306 rc = 1;
20307 }
20308 p->cMode = p->mode;
20309 }else
20310
@@ -21167,11 +21448,21 @@
21448 azBool[ShellHasFlag(p, SHFLG_Echo)]);
21449 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
21450 utf8_printf(p->out, "%12.12s: %s\n","explain",
21451 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
21452 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
21453 if( p->mode==MODE_Column
21454 || (p->mode>=MODE_Markdown && p->mode<=MODE_Box)
21455 ){
21456 utf8_printf
21457 (p->out, "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode",
21458 modeDescr[p->mode], p->cmOpts.iWrap,
21459 p->cmOpts.bWordWrap ? "on" : "off",
21460 p->cmOpts.bQuote ? "" : "no");
21461 }else{
21462 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
21463 }
21464 utf8_printf(p->out, "%12.12s: ", "nullvalue");
21465 output_c_string(p->out, p->nullValue);
21466 raw_printf(p->out, "\n");
21467 utf8_printf(p->out,"%12.12s: %s\n","output",
21468 strlen30(p->outfile) ? p->outfile : "stdout");
@@ -22010,10 +22301,17 @@
22301 int rc; /* Error code */
22302 int errCnt = 0; /* Number of errors seen */
22303 int startline = 0; /* Line number for start of current input */
22304 QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
22305
22306 if( p->inputNesting==MAX_INPUT_NESTING ){
22307 /* This will be more informative in a later version. */
22308 utf8_printf(stderr,"Input nesting limit (%d) reached at line %d."
22309 " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
22310 return 1;
22311 }
22312 ++p->inputNesting;
22313 p->lineno = 0;
22314 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
22315 fflush(p->out);
22316 zLine = one_input_line(p->in, zLine, nSql>0);
22317 if( zLine==0 ){
@@ -22092,10 +22390,11 @@
22390 if( nSql && QSS_PLAINDARK(qss) ){
22391 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22392 }
22393 free(zSql);
22394 free(zLine);
22395 --p->inputNesting;
22396 return errCnt>0;
22397 }
22398
22399 /*
22400 ** Return a pathname which is the user's home directory. A
22401
+1016 -231
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.38.0"
456456
#define SQLITE_VERSION_NUMBER 3038000
457
-#define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
457
+#define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -4656,10 +4656,12 @@
46564656
** still make the distinction between protected and unprotected
46574657
** sqlite3_value objects even when not strictly required.
46584658
**
46594659
** ^The sqlite3_value objects that are passed as parameters into the
46604660
** implementation of [application-defined SQL functions] are protected.
4661
+** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4662
+** are protected.
46614663
** ^The sqlite3_value object returned by
46624664
** [sqlite3_column_value()] is unprotected.
46634665
** Unprotected sqlite3_value objects may only be used as arguments
46644666
** to [sqlite3_result_value()], [sqlite3_bind_value()], and
46654667
** [sqlite3_value_dup()].
@@ -7435,28 +7437,60 @@
74357437
/*
74367438
** CAPI3REF: Virtual Table Constraint Operator Codes
74377439
**
74387440
** These macros define the allowed values for the
74397441
** [sqlite3_index_info].aConstraint[].op field. Each value represents
7440
-** an operator that is part of a constraint term in the wHERE clause of
7442
+** an operator that is part of a constraint term in the WHERE clause of
74417443
** a query that uses a [virtual table].
7444
+**
7445
+** ^The left-hand operand of the operator is given by the corresponding
7446
+** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
7447
+** operand is the rowid.
7448
+** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
7449
+** operators have no left-hand operand, and so for those operators the
7450
+** corresponding aConstraint[].iColumn is meaningless and should not be
7451
+** used.
7452
+**
7453
+** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
7454
+** value 255 are reserved to represent functions that are overloaded
7455
+** by the [xFindFunction|xFindFunction method] of the virtual table
7456
+** implementation.
7457
+**
7458
+** The right-hand operands for each constraint might be accessible using
7459
+** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
7460
+** operand is only available if it appears as a single constant literal
7461
+** in the input SQL. If the right-hand operand is another column or an
7462
+** expression (even a constant expression) or a parameter, then the
7463
+** sqlite3_vtab_rhs_value() probably will not be able to extract it.
7464
+** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
7465
+** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
7466
+** and hence calls to sqlite3_vtab_rhs_value() for those operators will
7467
+** always return SQLITE_NOTFOUND.
7468
+**
7469
+** The collating sequence to be used for comparison can be found using
7470
+** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7471
+** tables, the collating sequence of constraints does not matter (for example
7472
+** because the constraints are numeric) and so the sqlite3_vtab_collation()
7473
+** interface is no commonly needed.
74427474
*/
7443
-#define SQLITE_INDEX_CONSTRAINT_EQ 2
7444
-#define SQLITE_INDEX_CONSTRAINT_GT 4
7445
-#define SQLITE_INDEX_CONSTRAINT_LE 8
7446
-#define SQLITE_INDEX_CONSTRAINT_LT 16
7447
-#define SQLITE_INDEX_CONSTRAINT_GE 32
7448
-#define SQLITE_INDEX_CONSTRAINT_MATCH 64
7449
-#define SQLITE_INDEX_CONSTRAINT_LIKE 65
7450
-#define SQLITE_INDEX_CONSTRAINT_GLOB 66
7451
-#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7452
-#define SQLITE_INDEX_CONSTRAINT_NE 68
7453
-#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7454
-#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7455
-#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7456
-#define SQLITE_INDEX_CONSTRAINT_IS 72
7457
-#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
7475
+#define SQLITE_INDEX_CONSTRAINT_EQ 2
7476
+#define SQLITE_INDEX_CONSTRAINT_GT 4
7477
+#define SQLITE_INDEX_CONSTRAINT_LE 8
7478
+#define SQLITE_INDEX_CONSTRAINT_LT 16
7479
+#define SQLITE_INDEX_CONSTRAINT_GE 32
7480
+#define SQLITE_INDEX_CONSTRAINT_MATCH 64
7481
+#define SQLITE_INDEX_CONSTRAINT_LIKE 65
7482
+#define SQLITE_INDEX_CONSTRAINT_GLOB 66
7483
+#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7484
+#define SQLITE_INDEX_CONSTRAINT_NE 68
7485
+#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7486
+#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7487
+#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7488
+#define SQLITE_INDEX_CONSTRAINT_IS 72
7489
+#define SQLITE_INDEX_CONSTRAINT_LIMIT 73
7490
+#define SQLITE_INDEX_CONSTRAINT_OFFSET 74
7491
+#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
74587492
74597493
/*
74607494
** CAPI3REF: Register A Virtual Table Implementation
74617495
** METHOD: sqlite3
74627496
**
@@ -9775,25 +9809,26 @@
97759809
*/
97769810
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
97779811
97789812
/*
97799813
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9814
+** METHOD: sqlite3_index_info
97809815
**
97819816
** This function may only be called from within a call to the [xBestIndex]
97829817
** method of a [virtual table]. This function returns a pointer to a string
97839818
** that is the name of the appropriate collation sequence to use for text
97849819
** comparisons on the constraint identified by its arguments.
97859820
**
9786
-** The first argument must be the pointer to the sqlite3_index_info object
9821
+** The first argument must be the pointer to the [sqlite3_index_info] object
97879822
** that is the first parameter to the xBestIndex() method. The second argument
97889823
** must be an index into the aConstraint[] array belonging to the
97899824
** sqlite3_index_info structure passed to xBestIndex.
97909825
**
97919826
** Important:
97929827
** The first parameter must be the same pointer that is passed into the
97939828
** xBestMethod() method. The first parameter may not be a pointer to a
9794
-** different sqlite3_index_info object, even an exact copy.
9829
+** different [sqlite3_index_info] object, even an exact copy.
97959830
**
97969831
** The return value is computed as follows:
97979832
**
97989833
** <ol>
97999834
** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9807,10 +9842,240 @@
98079842
** <li><p> Otherwise, "BINARY" is returned.
98089843
** </ol>
98099844
*/
98109845
SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
98119846
9847
+/*
9848
+** CAPI3REF: Determine if a virtual table query is DISTINCT
9849
+** METHOD: sqlite3_index_info
9850
+**
9851
+** This API may only be used from within an [xBestIndex|xBestIndex method]
9852
+** of a [virtual table] implementation. The result of calling this
9853
+** interface from outside of xBestIndex() is undefined and probably harmful.
9854
+**
9855
+** ^The sqlite3_vtab_distinct() interface returns an integer that is
9856
+** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9857
+** gives the virtual table additional information about how the query
9858
+** planner wants the output to be ordered. As long as the virtual table
9859
+** can meet the ordering requirements of the query planner, it may set
9860
+** the "orderByConsumed" flag.
9861
+**
9862
+** <ol><li value="0"><p>
9863
+** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9864
+** that the query planner needs the virtual table to return all rows in the
9865
+** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9866
+** [sqlite3_index_info] object. This is the default expectation. If the
9867
+** virtual table outputs all rows in sorted order, then it is always safe for
9868
+** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9869
+** the return value from sqlite3_vtab_distinct().
9870
+** <li value="1"><p>
9871
+** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9872
+** that the query planner does not need the rows to be returned in sorted order
9873
+** as long as all rows with the same values in all columns identified by the
9874
+** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9875
+** is doing a GROUP BY.
9876
+** <li value="2"><p>
9877
+** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9878
+** that the query planner does not need the rows returned in any particular
9879
+** order, as long as rows with the same values in all "aOrderBy" columns
9880
+** are adjacent.)^ ^(Furthermore, only a single row for each particular
9881
+** combination of values in the columns identified by the "aOrderBy" field
9882
+** needs to be returned.)^ ^It is always ok for two or more rows with the same
9883
+** values in all "aOrderBy" columns to be returned, as long as all such rows
9884
+** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9885
+** that have the same value for all columns identified by "aOrderBy".
9886
+** ^However omitting the extra rows is optional.
9887
+** This mode is used for a DISTINCT query.
9888
+** </ol>
9889
+**
9890
+** ^For the purposes of comparing virtual table output values to see if the
9891
+** values are same value for sorting purposes, two NULL values are considered
9892
+** to be the same. In other words, the comparison operator is "IS"
9893
+** (or "IS NOT DISTINCT FROM") and not "==".
9894
+**
9895
+** If a virtual table implementation is unable to meet the requirements
9896
+** specified above, then it must not set the "orderByConsumed" flag in the
9897
+** [sqlite3_index_info] object or an incorrect answer may result.
9898
+**
9899
+** ^A virtual table implementation is always free to return rows in any order
9900
+** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9901
+** the "orderByConsumed" flag is unset, the query planner will add extra
9902
+** [bytecode] to ensure that the final results returned by the SQL query are
9903
+** ordered correctly. The use of the "orderByConsumed" flag and the
9904
+** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9905
+** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9906
+** flag might help queries against a virtual table to run faster. Being
9907
+** overly aggressive and setting the "orderByConsumed" flag when it is not
9908
+** valid to do so, on the other hand, might cause SQLite to return incorrect
9909
+** results.
9910
+*/
9911
+SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9912
+
9913
+/*
9914
+** CAPI3REF: Identify and handle IN constraints in xBestIndex
9915
+**
9916
+** This interface may only be used from within an
9917
+** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9918
+** The result of invoking this interface from any other context is
9919
+** undefined and probably harmful.
9920
+**
9921
+** ^(A constraint on a virtual table of the form
9922
+** "[IN operator|column IN (...)]" is
9923
+** communicated to the xBestIndex method as a
9924
+** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9925
+** this constraint, it must set the corresponding
9926
+** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9927
+** the usual mode of handling IN operators, SQLite generates [bytecode]
9928
+** that invokes the [xFilter|xFilter() method] once for each value
9929
+** on the right-hand side of the IN operator.)^ Thus the virtual table
9930
+** only sees a single value from the right-hand side of the IN operator
9931
+** at a time.
9932
+**
9933
+** In some cases, however, it would be advantageous for the virtual
9934
+** table to see all values on the right-hand of the IN operator all at
9935
+** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9936
+**
9937
+** <ol>
9938
+** <li><p>
9939
+** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9940
+** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9941
+** is an [IN operator] that can be processed all at once. ^In other words,
9942
+** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9943
+** by which the virtual table can ask SQLite if all-at-once processing
9944
+** of the IN operator is even possible.
9945
+**
9946
+** <li><p>
9947
+** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9948
+** to SQLite that the virtual table does or does not want to process
9949
+** the IN operator all-at-once, respectively. ^Thus when the third
9950
+** parameter (F) is non-negative, this interface is the mechanism by
9951
+** which the virtual table tells SQLite how it wants to process the
9952
+** IN operator.
9953
+** </ol>
9954
+**
9955
+** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9956
+** within the same xBestIndex method call. ^For any given P,N pair,
9957
+** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9958
+** within the same xBestIndex call. ^If the interface returns true
9959
+** (non-zero), that means that the constraint is an IN operator
9960
+** that can be processed all-at-once. ^If the constraint is not an IN
9961
+** operator or cannot be processed all-at-once, then the interface returns
9962
+** false.
9963
+**
9964
+** ^(All-at-once processing of the IN operator is selected if both of the
9965
+** following conditions are met:
9966
+**
9967
+** <ol>
9968
+** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9969
+** integer. This is how the virtual table tells SQLite that it wants to
9970
+** use the N-th constraint.
9971
+**
9972
+** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9973
+** non-negative had F>=1.
9974
+** </ol>)^
9975
+**
9976
+** ^If either or both of the conditions above are false, then SQLite uses
9977
+** the traditional one-at-a-time processing strategy for the IN constraint.
9978
+** ^If both conditions are true, then the argvIndex-th parameter to the
9979
+** xFilter method will be an [sqlite3_value] that appears to be NULL,
9980
+** but which can be passed to [sqlite3_vtab_in_first()] and
9981
+** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9982
+** of the IN constraint.
9983
+*/
9984
+SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9985
+
9986
+/*
9987
+** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9988
+**
9989
+** These interfaces are only useful from within the
9990
+** [xFilter|xFilter() method] of a [virtual table] implementation.
9991
+** The result of invoking these interfaces from any other context
9992
+** is undefined and probably harmful.
9993
+**
9994
+** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9995
+** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9996
+** xFilter method which invokes these routines, and specifically
9997
+** a parameter that was previously selected for all-at-once IN constraint
9998
+** processing use the [sqlite3_vtab_in()] interface in the
9999
+** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10000
+** an xFilter argument that was selected for all-at-once IN constraint
10001
+** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
10002
+** exhibit some other undefined or harmful behavior.
10003
+**
10004
+** ^(Use these routines to access all values on the right-hand side
10005
+** of the IN constraint using code like the following:
10006
+**
10007
+** <blockquote><pre>
10008
+** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
10009
+** &nbsp; rc==SQLITE_OK && pVal
10010
+** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
10011
+** &nbsp; ){
10012
+** &nbsp; // do something with pVal
10013
+** &nbsp; }
10014
+** &nbsp; if( rc!=SQLITE_OK ){
10015
+** &nbsp; // an error has occurred
10016
+** &nbsp; }
10017
+** </pre></blockquote>)^
10018
+**
10019
+** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
10020
+** routines return SQLITE_OK and set *P to point to the first or next value
10021
+** on the RHS of the IN constraint. ^If there are no more values on the
10022
+** right hand side of the IN constraint, then *P is set to NULL and these
10023
+** routines return [SQLITE_DONE]. ^The return value might be
10024
+** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
10025
+**
10026
+** The *ppOut values returned by these routines are only valid until the
10027
+** next call to either of these routines or until the end of the xFilter
10028
+** method from which these routines were called. If the virtual table
10029
+** implementation needs to retain the *ppOut values for longer, it must make
10030
+** copies. The *ppOut values are [protected sqlite3_value|protected].
10031
+*/
10032
+SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
10033
+SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
10034
+
10035
+/*
10036
+** CAPI3REF: Constraint values in xBestIndex()
10037
+** METHOD: sqlite3_index_info
10038
+**
10039
+** This API may only be used from within the [xBestIndex|xBestIndex method]
10040
+** of a [virtual table] implementation. The result of calling this interface
10041
+** from outside of an xBestIndex method are undefined and probably harmful.
10042
+**
10043
+** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
10044
+** the [xBestIndex] method of a [virtual table] implementation, with P being
10045
+** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
10046
+** J being a 0-based index into P->aConstraint[], then this routine
10047
+** attempts to set *V to the value of the right-hand operand of
10048
+** that constraint if the right-hand operand is known. ^If the
10049
+** right-hand operand is not known, then *V is set to a NULL pointer.
10050
+** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10051
+** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
10052
+** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10053
+** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10054
+** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
10055
+** something goes wrong.
10056
+**
10057
+** The sqlite3_vtab_rhs_value() interface is usually only successful if
10058
+** the right-hand operand of a constraint is a literal value in the original
10059
+** SQL statement. If the right-hand operand is an expression or a reference
10060
+** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
10061
+** will probably return [SQLITE_NOTFOUND].
10062
+**
10063
+** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
10064
+** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
10065
+** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
10066
+**
10067
+** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
10068
+** and remains valid for the duration of the xBestIndex method call.
10069
+** ^When xBestIndex returns, the sqlite3_value object returned by
10070
+** sqlite3_vtab_rhs_value() is automatically deallocated.
10071
+**
10072
+** The "_rhs_" in the name of this routine is an appreviation for
10073
+** "Right-Hand Side".
10074
+*/
10075
+SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
10076
+
981210077
/*
981310078
** CAPI3REF: Conflict resolution modes
981410079
** KEYWORDS: {conflict resolution mode}
981510080
**
981610081
** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -14374,14 +14639,15 @@
1437414639
#define BMS ((int)(sizeof(Bitmask)*8))
1437514640
1437614641
/*
1437714642
** A bit in a Bitmask
1437814643
*/
14379
-#define MASKBIT(n) (((Bitmask)1)<<(n))
14380
-#define MASKBIT64(n) (((u64)1)<<(n))
14381
-#define MASKBIT32(n) (((unsigned int)1)<<(n))
14382
-#define ALLBITS ((Bitmask)-1)
14644
+#define MASKBIT(n) (((Bitmask)1)<<(n))
14645
+#define MASKBIT64(n) (((u64)1)<<(n))
14646
+#define MASKBIT32(n) (((unsigned int)1)<<(n))
14647
+#define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
14648
+#define ALLBITS ((Bitmask)-1)
1438314649
1438414650
/* A VList object records a mapping between parameters/variables/wildcards
1438514651
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
1438614652
** variable number associated with that parameter. See the format description
1438714653
** on the sqlite3VListAdd() routine for more information. A VList is really
@@ -15403,21 +15669,22 @@
1540315669
#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
1540415670
#define OP_VBegin 169
1540515671
#define OP_VCreate 170
1540615672
#define OP_VDestroy 171
1540715673
#define OP_VOpen 172
15408
-#define OP_VColumn 173 /* synopsis: r[P3]=vcolumn(P2) */
15409
-#define OP_VRename 174
15410
-#define OP_Pagecount 175
15411
-#define OP_MaxPgcnt 176
15412
-#define OP_FilterAdd 177 /* synopsis: filter(P1) += key(P3@P4) */
15413
-#define OP_Trace 178
15414
-#define OP_CursorHint 179
15415
-#define OP_ReleaseReg 180 /* synopsis: release r[P1@P2] mask P3 */
15416
-#define OP_Noop 181
15417
-#define OP_Explain 182
15418
-#define OP_Abortable 183
15674
+#define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */
15675
+#define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */
15676
+#define OP_VRename 175
15677
+#define OP_Pagecount 176
15678
+#define OP_MaxPgcnt 177
15679
+#define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */
15680
+#define OP_Trace 179
15681
+#define OP_CursorHint 180
15682
+#define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */
15683
+#define OP_Noop 182
15684
+#define OP_Explain 183
15685
+#define OP_Abortable 184
1541915686
1542015687
/* Properties such as "out2" or "jump" that are specified in
1542115688
** comments following the "case" for each opcode in the vdbe.c
1542215689
** are encoded into bitvectors as follows:
1542315690
*/
@@ -15447,13 +15714,13 @@
1544715714
/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
1544815715
/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
1544915716
/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
1545015717
/* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
1545115718
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15452
-/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15453
-/* 176 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15454
-}
15719
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\
15720
+/* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15721
+/* 184 */ 0x00,}
1545515722
1545615723
/* The resolve3P2Values() routine is able to run faster if it knows
1545715724
** the value of the largest JUMP opcode. The smaller the maximum
1545815725
** JUMP opcode the better, so the mkopcodeh.tcl script that
1545915726
** generated this include file strives to group all JUMP opcodes
@@ -18576,10 +18843,11 @@
1857618843
** initialized as they will be set before being used. The boundary is
1857718844
** determined by offsetof(Parse,aTempReg).
1857818845
**************************************************************************/
1857918846
1858018847
int aTempReg[8]; /* Holding area for temporary registers */
18848
+ Parse *pOuterParse; /* Outer Parse object when nested */
1858118849
Token sNameToken; /* Token with unqualified schema object name */
1858218850
1858318851
/************************************************************************
1858418852
** Above is constant between recursions. Below is reset before and after
1858518853
** each recursion. The boundary between these two regions is determined
@@ -18626,11 +18894,12 @@
1862618894
#define PARSE_MODE_UNMAP 3
1862718895
1862818896
/*
1862918897
** Sizes and pointers of various parts of the Parse object.
1863018898
*/
18631
-#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
18899
+#define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg))
18900
+#define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/
1863218901
#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
1863318902
#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
1863418903
#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
1863518904
1863618905
/*
@@ -19566,11 +19835,12 @@
1956619835
#endif
1956719836
SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe*,int,const char*);
1956819837
SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
1956919838
SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,
1957019839
Upsert*);
19571
-SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
19840
+SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,
19841
+ ExprList*,Select*,u16,int);
1957219842
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
1957319843
SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
1957419844
SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
1957519845
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
1957619846
SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*);
@@ -19966,11 +20236,11 @@
1996620236
void (*)(sqlite3_context*),
1996720237
void (*)(sqlite3_context*,int,sqlite3_value **),
1996820238
FuncDestructor *pDestructor
1996920239
);
1997020240
SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
19971
-SQLITE_PRIVATE void sqlite3OomFault(sqlite3*);
20241
+SQLITE_PRIVATE void *sqlite3OomFault(sqlite3*);
1997220242
SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
1997320243
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1997420244
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1997520245
1997620246
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
@@ -20087,11 +20357,12 @@
2008720357
SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
2008820358
SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
2008920359
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
2009020360
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
2009120361
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20092
-SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
20362
+SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*);
20363
+SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*);
2009320364
SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
2009420365
#ifdef SQLITE_ENABLE_NORMALIZE
2009520366
SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
2009620367
#endif
2009720368
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
@@ -20520,10 +20791,18 @@
2052020791
2052120792
#endif /* !defined(_OS_COMMON_H_) */
2052220793
2052320794
/************** End of os_common.h *******************************************/
2052420795
/************** Begin file ctime.c *******************************************/
20796
+/* DO NOT EDIT!
20797
+** This file is automatically generated by the script in the canonical
20798
+** SQLite source tree at tool/mkctimec.tcl.
20799
+**
20800
+** To modify this header, edit any of the various lists in that script
20801
+** which specify categories of generated conditionals in this file.
20802
+*/
20803
+
2052520804
/*
2052620805
** 2010 February 23
2052720806
**
2052820807
** The author disclaims copyright to this source code. In place of
2052920808
** a legal notice, here is a blessing:
@@ -20568,13 +20847,10 @@
2056820847
** only a handful of compile-time options, so most times this array is usually
2056920848
** rather short and uses little memory space.
2057020849
*/
2057120850
static const char * const sqlite3azCompileOpt[] = {
2057220851
20573
-/*
20574
-** BEGIN CODE GENERATED BY tool/mkctime.tcl
20575
-*/
2057620852
#ifdef SQLITE_32BIT_ROWID
2057720853
"32BIT_ROWID",
2057820854
#endif
2057920855
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
2058020856
"4_BYTE_ALIGNED_MALLOC",
@@ -20701,13 +20977,10 @@
2070120977
"DISABLE_FTS4_DEFERRED",
2070220978
#endif
2070320979
#ifdef SQLITE_DISABLE_INTRINSIC
2070420980
"DISABLE_INTRINSIC",
2070520981
#endif
20706
-#ifdef SQLITE_DISABLE_JSON
20707
- "DISABLE_JSON",
20708
-#endif
2070920982
#ifdef SQLITE_DISABLE_LFS
2071020983
"DISABLE_LFS",
2071120984
#endif
2071220985
#ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
2071320986
"DISABLE_PAGECACHE_OVERFLOW_STATS",
@@ -21104,10 +21377,13 @@
2110421377
#ifdef SQLITE_OMIT_INTEGRITY_CHECK
2110521378
"OMIT_INTEGRITY_CHECK",
2110621379
#endif
2110721380
#ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
2110821381
"OMIT_INTROSPECTION_PRAGMAS",
21382
+#endif
21383
+#ifdef SQLITE_OMIT_JSON
21384
+ "OMIT_JSON",
2110921385
#endif
2111021386
#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
2111121387
"OMIT_LIKE_OPTIMIZATION",
2111221388
#endif
2111321389
#ifdef SQLITE_OMIT_LOAD_EXTENSION
@@ -21293,14 +21569,12 @@
2129321569
"WIN32_MALLOC",
2129421570
#endif
2129521571
#ifdef SQLITE_ZERO_MALLOC
2129621572
"ZERO_MALLOC",
2129721573
#endif
21298
-/*
21299
-** END CODE GENERATED BY tool/mkctime.tcl
21300
-*/
21301
-};
21574
+
21575
+} ;
2130221576
2130321577
SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
2130421578
*pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
2130521579
return (const char**)sqlite3azCompileOpt;
2130621580
}
@@ -22214,10 +22488,28 @@
2221422488
i64 iKey2; /* Second key value passed to hook */
2221522489
Mem *aNew; /* Array of new.* values */
2221622490
Table *pTab; /* Schema object being upated */
2221722491
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
2221822492
};
22493
+
22494
+/*
22495
+** An instance of this object is used to pass an vector of values into
22496
+** OP_VFilter, the xFilter method of a virtual table. The vector is the
22497
+** set of values on the right-hand side of an IN constraint.
22498
+**
22499
+** The value as passed into xFilter is an sqlite3_value with a "pointer"
22500
+** type, such as is generated by sqlite3_result_pointer() and read by
22501
+** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null
22502
+** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces
22503
+** know how to use this object to step through all the values in the
22504
+** right operand of the IN constraint.
22505
+*/
22506
+typedef struct ValueList ValueList;
22507
+struct ValueList {
22508
+ BtCursor *pCsr; /* An ephemeral table holding all values */
22509
+ sqlite3_value *pOut; /* Register to hold each decoded output value */
22510
+};
2221922511
2222022512
/*
2222122513
** Function prototypes
2222222514
*/
2222322515
SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
@@ -23406,11 +23698,12 @@
2340623698
*/
2340723699
static int parseModifier(
2340823700
sqlite3_context *pCtx, /* Function context */
2340923701
const char *z, /* The text of the modifier */
2341023702
int n, /* Length of zMod in bytes */
23411
- DateTime *p /* The date/time value to be modified */
23703
+ DateTime *p, /* The date/time value to be modified */
23704
+ int idx /* Parameter index of the modifier */
2341223705
){
2341323706
int rc = 1;
2341423707
double r;
2341523708
switch(sqlite3UpperToLower[(u8)z[0]] ){
2341623709
case 'a': {
@@ -23419,10 +23712,11 @@
2341923712
**
2342023713
** If rawS is available, then interpret as a julian day number, or
2342123714
** a unix timestamp, depending on its magnitude.
2342223715
*/
2342323716
if( sqlite3_stricmp(z, "auto")==0 ){
23717
+ if( idx>1 ) return 1; /* IMP: R-33611-57934 */
2342423718
if( !p->rawS || p->validJD ){
2342523719
rc = 0;
2342623720
p->rawS = 0;
2342723721
}else if( p->s>=-210866760000 && p->s<=253402300799 ){
2342823722
r = p->s*1000.0 + 210866760000000.0;
@@ -23443,10 +23737,11 @@
2344323737
** is not the first modifier, or if the prior argument is not a numeric
2344423738
** value in the allowed range of julian day numbers understood by
2344523739
** SQLite (0..5373484.5) then the result will be NULL.
2344623740
*/
2344723741
if( sqlite3_stricmp(z, "julianday")==0 ){
23742
+ if( idx>1 ) return 1; /* IMP: R-31176-64601 */
2344823743
if( p->validJD && p->rawS ){
2344923744
rc = 0;
2345023745
p->rawS = 0;
2345123746
}
2345223747
}
@@ -23473,10 +23768,11 @@
2347323768
**
2347423769
** Treat the current value of p->s as the number of
2347523770
** seconds since 1970. Convert to a real julian day number.
2347623771
*/
2347723772
if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
23773
+ if( idx>1 ) return 1; /* IMP: R-49255-55373 */
2347823774
r = p->s*1000.0 + 210866760000000.0;
2347923775
if( r>=0.0 && r<464269060800000.0 ){
2348023776
clearYMD_HMS_TZ(p);
2348123777
p->iJD = (sqlite3_int64)(r + 0.5);
2348223778
p->validJD = 1;
@@ -23686,11 +23982,11 @@
2368623982
}
2368723983
}
2368823984
for(i=1; i<argc; i++){
2368923985
z = sqlite3_value_text(argv[i]);
2369023986
n = sqlite3_value_bytes(argv[i]);
23691
- if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
23987
+ if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1;
2369223988
}
2369323989
computeJD(p);
2369423990
if( p->isError || !validJulianDay(p->iJD) ) return 1;
2369523991
return 0;
2369623992
}
@@ -28956,22 +29252,31 @@
2895629252
/*
2895729253
** Call this routine to record the fact that an OOM (out-of-memory) error
2895829254
** has happened. This routine will set db->mallocFailed, and also
2895929255
** temporarily disable the lookaside memory allocator and interrupt
2896029256
** any running VDBEs.
29257
+**
29258
+** Always return a NULL pointer so that this routine can be invoked using
29259
+**
29260
+** return sqlite3OomFault(db);
29261
+**
29262
+** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
29263
+** common case where no OOM occurs.
2896129264
*/
28962
-SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
29265
+SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
2896329266
if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
2896429267
db->mallocFailed = 1;
2896529268
if( db->nVdbeExec>0 ){
2896629269
AtomicStore(&db->u1.isInterrupted, 1);
2896729270
}
2896829271
DisableLookaside;
2896929272
if( db->pParse ){
29273
+ sqlite3ErrorMsg(db->pParse, "out of memory");
2897029274
db->pParse->rc = SQLITE_NOMEM_BKPT;
2897129275
}
2897229276
}
29277
+ return 0;
2897329278
}
2897429279
2897529280
/*
2897629281
** This routine reactivates the memory allocator and clears the
2897729282
** db->mallocFailed flag as necessary.
@@ -32356,17 +32661,23 @@
3235632661
*/
3235732662
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
3235832663
char *zMsg;
3235932664
va_list ap;
3236032665
sqlite3 *db = pParse->db;
32666
+ assert( db!=0 );
32667
+ assert( db->pParse==pParse );
3236132668
db->errByteOffset = -2;
3236232669
va_start(ap, zFormat);
3236332670
zMsg = sqlite3VMPrintf(db, zFormat, ap);
3236432671
va_end(ap);
3236532672
if( db->errByteOffset<-1 ) db->errByteOffset = -1;
3236632673
if( db->suppressErr ){
3236732674
sqlite3DbFree(db, zMsg);
32675
+ if( db->mallocFailed ){
32676
+ pParse->nErr++;
32677
+ pParse->rc = SQLITE_NOMEM;
32678
+ }
3236832679
}else{
3236932680
pParse->nErr++;
3237032681
sqlite3DbFree(db, pParse->zErrMsg);
3237132682
pParse->zErrMsg = zMsg;
3237232683
pParse->rc = SQLITE_ERROR;
@@ -34334,21 +34645,22 @@
3433434645
/* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
3433534646
/* 169 */ "VBegin" OpHelp(""),
3433634647
/* 170 */ "VCreate" OpHelp(""),
3433734648
/* 171 */ "VDestroy" OpHelp(""),
3433834649
/* 172 */ "VOpen" OpHelp(""),
34339
- /* 173 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34340
- /* 174 */ "VRename" OpHelp(""),
34341
- /* 175 */ "Pagecount" OpHelp(""),
34342
- /* 176 */ "MaxPgcnt" OpHelp(""),
34343
- /* 177 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34344
- /* 178 */ "Trace" OpHelp(""),
34345
- /* 179 */ "CursorHint" OpHelp(""),
34346
- /* 180 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34347
- /* 181 */ "Noop" OpHelp(""),
34348
- /* 182 */ "Explain" OpHelp(""),
34349
- /* 183 */ "Abortable" OpHelp(""),
34650
+ /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
34651
+ /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34652
+ /* 175 */ "VRename" OpHelp(""),
34653
+ /* 176 */ "Pagecount" OpHelp(""),
34654
+ /* 177 */ "MaxPgcnt" OpHelp(""),
34655
+ /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34656
+ /* 179 */ "Trace" OpHelp(""),
34657
+ /* 180 */ "CursorHint" OpHelp(""),
34658
+ /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34659
+ /* 182 */ "Noop" OpHelp(""),
34660
+ /* 183 */ "Explain" OpHelp(""),
34661
+ /* 184 */ "Abortable" OpHelp(""),
3435034662
};
3435134663
return azName[i];
3435234664
}
3435334665
#endif
3435434666
@@ -56722,12 +57034,11 @@
5672257034
** Once this function has been called, the transaction must either be
5672357035
** rolled back or committed. It is not safe to call this function and
5672457036
** then continue writing to the database.
5672557037
*/
5672657038
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56727
- assert( pPager->dbSize>=nPage || CORRUPT_DB );
56728
- testcase( pPager->dbSize<nPage );
57039
+ assert( pPager->dbSize>=nPage );
5672957040
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
5673057041
pPager->dbSize = nPage;
5673157042
5673257043
/* At one point the code here called assertTruncateConstraint() to
5673357044
** ensure that all pages being truncated away by this operation are,
@@ -63102,11 +63413,13 @@
6310263413
rc = WAL_RETRY;
6310363414
goto begin_unreliable_shm_out;
6310463415
}
6310563416
6310663417
/* Allocate a buffer to read frames into */
63107
- szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
63418
+ assert( (pWal->szPage & (pWal->szPage-1))==0 );
63419
+ assert( pWal->szPage>=512 && pWal->szPage<=65536 );
63420
+ szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
6310863421
aFrame = (u8 *)sqlite3_malloc64(szFrame);
6310963422
if( aFrame==0 ){
6311063423
rc = SQLITE_NOMEM_BKPT;
6311163424
goto begin_unreliable_shm_out;
6311263425
}
@@ -63116,11 +63429,11 @@
6311663429
** wal file since the heap-memory wal-index was created. If so, the
6311763430
** heap-memory wal-index is discarded and WAL_RETRY returned to
6311863431
** the caller. */
6311963432
aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
6312063433
aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
63121
- for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage);
63434
+ for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->szPage);
6312263435
iOffset+szFrame<=szWal;
6312363436
iOffset+=szFrame
6312463437
){
6312563438
u32 pgno; /* Database page number for frame */
6312663439
u32 nTruncate; /* dbsize field from frame header */
@@ -68934,13 +69247,17 @@
6893469247
freeTempSpace(pBt);
6893569248
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
6893669249
pageSize-usableSize);
6893769250
return rc;
6893869251
}
68939
- if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
68940
- rc = SQLITE_CORRUPT_BKPT;
68941
- goto page1_init_failed;
69252
+ if( nPage>nPageFile ){
69253
+ if( sqlite3WritableSchema(pBt->db)==0 ){
69254
+ rc = SQLITE_CORRUPT_BKPT;
69255
+ goto page1_init_failed;
69256
+ }else{
69257
+ nPage = nPageFile;
69258
+ }
6894269259
}
6894369260
/* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
6894469261
** be less than 480. In other words, if the page size is 512, then the
6894569262
** reserved space size cannot exceed 32. */
6894669263
if( usableSize<480 ){
@@ -76691,18 +77008,17 @@
7669177008
int i = sqlite3FindDbName(pDb, zDb);
7669277009
7669377010
if( i==1 ){
7669477011
Parse sParse;
7669577012
int rc = 0;
76696
- memset(&sParse, 0, sizeof(sParse));
76697
- sParse.db = pDb;
77013
+ sqlite3ParseObjectInit(&sParse,pDb);
7669877014
if( sqlite3OpenTempDatabase(&sParse) ){
7669977015
sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
7670077016
rc = SQLITE_ERROR;
7670177017
}
7670277018
sqlite3DbFree(pErrorDb, sParse.zErrMsg);
76703
- sqlite3ParserReset(&sParse);
77019
+ sqlite3ParseObjectReset(&sParse);
7670477020
if( rc ){
7670577021
return 0;
7670677022
}
7670777023
}
7670877024
@@ -78910,15 +79226,11 @@
7891079226
const char *zNeg = "";
7891179227
int rc = SQLITE_OK;
7891279228
7891379229
assert( pExpr!=0 );
7891479230
while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
78915
-#if defined(SQLITE_ENABLE_STAT4)
7891679231
if( op==TK_REGISTER ) op = pExpr->op2;
78917
-#else
78918
- if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
78919
-#endif
7892079232
7892179233
/* Compressed expressions only appear when parsing the DEFAULT clause
7892279234
** on a table column definition, and hence only when pCtx==0. This
7892379235
** check ensures that an EP_TokenOnly expression is never passed down
7892479236
** into valueFromFunction(). */
@@ -80707,12 +81019,11 @@
8070781019
** makes the code easier to read during debugging. None of this happens
8070881020
** in a production build.
8070981021
*/
8071081022
static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
8071181023
assert( p->nOp>0 || p->aOp==0 );
80712
- assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
80713
- || p->pParse->nErr>0 );
81024
+ assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
8071481025
if( p->nOp ){
8071581026
assert( p->aOp );
8071681027
sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
8071781028
p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
8071881029
}
@@ -85436,10 +85747,74 @@
8543685747
*/
8543785748
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
8543885749
assert( p );
8543985750
return sqlite3_value_nochange(p->pOut);
8544085751
}
85752
+
85753
+/*
85754
+** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
85755
+** sqlite3_vtab_in_next() (if bNext!=0).
85756
+*/
85757
+static int valueFromValueList(
85758
+ sqlite3_value *pVal, /* Pointer to the ValueList object */
85759
+ sqlite3_value **ppOut, /* Store the next value from the list here */
85760
+ int bNext /* 1 for _next(). 0 for _first() */
85761
+){
85762
+ int rc;
85763
+ ValueList *pRhs;
85764
+
85765
+ *ppOut = 0;
85766
+ if( pVal==0 ) return SQLITE_MISUSE;
85767
+ pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList");
85768
+ if( pRhs==0 ) return SQLITE_MISUSE;
85769
+ if( bNext ){
85770
+ rc = sqlite3BtreeNext(pRhs->pCsr, 0);
85771
+ }else{
85772
+ int dummy = 0;
85773
+ rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy);
85774
+ assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) );
85775
+ if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE;
85776
+ }
85777
+ if( rc==SQLITE_OK ){
85778
+ u32 sz; /* Size of current row in bytes */
85779
+ Mem sMem; /* Raw content of current row */
85780
+ memset(&sMem, 0, sizeof(sMem));
85781
+ sz = sqlite3BtreePayloadSize(pRhs->pCsr);
85782
+ rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem);
85783
+ if( rc==SQLITE_OK ){
85784
+ u8 *zBuf = (u8*)sMem.z;
85785
+ u32 iSerial;
85786
+ sqlite3_value *pOut = pRhs->pOut;
85787
+ int iOff = 1 + getVarint32(&zBuf[1], iSerial);
85788
+ sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut);
85789
+ pOut->enc = ENC(pOut->db);
85790
+ if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
85791
+ rc = SQLITE_NOMEM;
85792
+ }else{
85793
+ *ppOut = pOut;
85794
+ }
85795
+ }
85796
+ sqlite3VdbeMemRelease(&sMem);
85797
+ }
85798
+ return rc;
85799
+}
85800
+
85801
+/*
85802
+** Set the iterator value pVal to point to the first value in the set.
85803
+** Set (*ppOut) to point to this value before returning.
85804
+*/
85805
+SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){
85806
+ return valueFromValueList(pVal, ppOut, 0);
85807
+}
85808
+
85809
+/*
85810
+** Set the iterator value pVal to point to the next value in the set.
85811
+** Set (*ppOut) to point to this value before returning.
85812
+*/
85813
+SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){
85814
+ return valueFromValueList(pVal, ppOut, 1);
85815
+}
8544185816
8544285817
/*
8544385818
** Return the current time for a statement. If the current time
8544485819
** is requested more than once within the same run of a single prepared
8544585820
** statement, the exact same time is returned for each invocation regardless
@@ -87537,11 +87912,10 @@
8753787912
*/
8753887913
static u64 filterHash(const Mem *aMem, const Op *pOp){
8753987914
int i, mx;
8754087915
u64 h = 0;
8754187916
87542
- i = pOp->p3;
8754387917
assert( pOp->p4type==P4_INT32 );
8754487918
for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
8754587919
const Mem *p = &aMem[i];
8754687920
if( p->flags & (MEM_Int|MEM_IntReal) ){
8754787921
h += p->u.i;
@@ -89020,11 +89394,11 @@
8902089394
testcase( pIn1->flags & MEM_Real );
8902189395
testcase( pIn1->flags & MEM_IntReal );
8902289396
sqlite3VdbeMemStringify(pIn1, encoding, 1);
8902389397
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
8902489398
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
89025
- if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
89399
+ if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
8902689400
}
8902789401
if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
8902889402
testcase( pIn3->flags & MEM_Int );
8902989403
testcase( pIn3->flags & MEM_Real );
8903089404
testcase( pIn3->flags & MEM_IntReal );
@@ -89846,10 +90220,12 @@
8984690220
case COLTYPE_TEXT: {
8984790221
if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
8984890222
break;
8984990223
}
8985090224
case COLTYPE_REAL: {
90225
+ testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
90226
+ testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
8985190227
if( pIn1->flags & MEM_Int ){
8985290228
/* When applying REAL affinity, if the result is still an MEM_Int
8985390229
** that will fit in 6 bytes, then change the type to MEM_IntReal
8985490230
** so that we keep the high-resolution integer value but know that
8985590231
** the type really wants to be REAL. */
@@ -89863,11 +90239,11 @@
8986390239
}else{
8986490240
pIn1->u.r = (double)pIn1->u.i;
8986590241
pIn1->flags |= MEM_Real;
8986690242
pIn1->flags &= ~MEM_Int;
8986790243
}
89868
- }else if( (pIn1->flags & MEM_Real)==0 ){
90244
+ }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
8986990245
goto vdbe_type_error;
8987090246
}
8987190247
break;
8987290248
}
8987390249
default: {
@@ -94592,10 +94968,38 @@
9459294968
goto no_mem;
9459394969
}
9459494970
break;
9459594971
}
9459694972
#endif /* SQLITE_OMIT_VIRTUALTABLE */
94973
+
94974
+#ifndef SQLITE_OMIT_VIRTUALTABLE
94975
+/* Opcode: VInitIn P1 P2 P3 * *
94976
+** Synopsis: r[P2]=ValueList(P1,P3)
94977
+**
94978
+** Set register P2 to be a pointer to a ValueList object for cursor P1
94979
+** with cache register P3 and output register P3+1. This ValueList object
94980
+** can be used as the first argument to sqlite3_vtab_in_first() and
94981
+** sqlite3_vtab_in_next() to extract all of the values stored in the P1
94982
+** cursor. Register P3 is used to hold the values returned by
94983
+** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
94984
+*/
94985
+case OP_VInitIn: { /* out2 */
94986
+ VdbeCursor *pC; /* The cursor containing the RHS values */
94987
+ ValueList *pRhs; /* New ValueList object to put in reg[P2] */
94988
+
94989
+ pC = p->apCsr[pOp->p1];
94990
+ pRhs = sqlite3_malloc64( sizeof(*pRhs) );
94991
+ if( pRhs==0 ) goto no_mem;
94992
+ pRhs->pCsr = pC->uc.pCursor;
94993
+ pRhs->pOut = &aMem[pOp->p3];
94994
+ pOut = out2Prerelease(p, pOp);
94995
+ pOut->flags = MEM_Null;
94996
+ sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free);
94997
+ break;
94998
+}
94999
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
95000
+
9459795001
9459895002
#ifndef SQLITE_OMIT_VIRTUALTABLE
9459995003
/* Opcode: VFilter P1 P2 P3 P4 *
9460095004
** Synopsis: iplan=r[P3] zplan='P4'
9460195005
**
@@ -95579,14 +95983,13 @@
9557995983
wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
9558095984
9558195985
sqlite3_mutex_enter(db->mutex);
9558295986
9558395987
pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
95584
- do {
95585
- memset(&sParse, 0, sizeof(Parse));
95988
+ while(1){
95989
+ sqlite3ParseObjectInit(&sParse,db);
9558695990
if( !pBlob ) goto blob_open_out;
95587
- sParse.db = db;
9558895991
sqlite3DbFree(db, zErr);
9558995992
zErr = 0;
9559095993
9559195994
sqlite3BtreeEnterAll(db);
9559295995
pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
@@ -95759,11 +96162,13 @@
9575996162
sqlite3BtreeLeaveAll(db);
9576096163
if( db->mallocFailed ){
9576196164
goto blob_open_out;
9576296165
}
9576396166
rc = blobSeekToRow(pBlob, iRow, &zErr);
95764
- } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
96167
+ if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break;
96168
+ sqlite3ParseObjectReset(&sParse);
96169
+ }
9576596170
9576696171
blob_open_out:
9576796172
if( rc==SQLITE_OK && db->mallocFailed==0 ){
9576896173
*ppBlob = (sqlite3_blob *)pBlob;
9576996174
}else{
@@ -95770,11 +96175,11 @@
9577096175
if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
9577196176
sqlite3DbFree(db, pBlob);
9577296177
}
9577396178
sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
9577496179
sqlite3DbFree(db, zErr);
95775
- sqlite3ParserReset(&sParse);
96180
+ sqlite3ParseObjectReset(&sParse);
9577696181
rc = sqlite3ApiExit(db, rc);
9577796182
sqlite3_mutex_leave(db->mutex);
9577896183
return rc;
9577996184
}
9578096185
@@ -100835,11 +101240,11 @@
100835101240
&& (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
100836101241
){
100837101242
/* Internal-use-only functions are disallowed unless the
100838101243
** SQL is being compiled using sqlite3NestedParse() or
100839101244
** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
100840
- ** used to activate internal functionsn for testing purposes */
101245
+ ** used to activate internal functions for testing purposes */
100841101246
no_such_func = 1;
100842101247
pDef = 0;
100843101248
}else
100844101249
if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
100845101250
&& !IN_RENAME_OBJECT
@@ -101054,11 +101459,12 @@
101054101459
sqlite3ErrorMsg(pParse, "row value misused");
101055101460
}
101056101461
break;
101057101462
}
101058101463
}
101059
- return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
101464
+ assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
101465
+ return pParse->nErr ? WRC_Abort : WRC_Continue;
101060101466
}
101061101467
101062101468
/*
101063101469
** pEList is a list of expressions which are really the result set of the
101064101470
** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
@@ -101468,11 +101874,11 @@
101468101874
** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
101469101875
** this routine in the correct order.
101470101876
*/
101471101877
if( (p->selFlags & SF_Expanded)==0 ){
101472101878
sqlite3SelectPrep(pParse, p, pOuterNC);
101473
- return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
101879
+ return pParse->nErr ? WRC_Abort : WRC_Prune;
101474101880
}
101475101881
101476101882
isCompound = p->pPrior!=0;
101477101883
nCompound = 0;
101478101884
pLeftmost = p;
@@ -101516,11 +101922,12 @@
101516101922
const char *zSavedContext = pParse->zAuthContext;
101517101923
101518101924
if( pItem->zName ) pParse->zAuthContext = pItem->zName;
101519101925
sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
101520101926
pParse->zAuthContext = zSavedContext;
101521
- if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
101927
+ if( pParse->nErr ) return WRC_Abort;
101928
+ assert( db->mallocFailed==0 );
101522101929
101523101930
/* If the number of references to the outer context changed when
101524101931
** expressions in the sub-select were resolved, the sub-select
101525101932
** is correlated. It is not required to check the refcount on any
101526101933
** but the innermost outer context object, as lookupName() increments
@@ -104696,12 +105103,11 @@
104696105103
Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
104697105104
Expr *pRhs = pEList->a[i].pExpr;
104698105105
CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
104699105106
int j;
104700105107
104701
- assert( pReq!=0 || pRhs->iColumn==XN_ROWID
104702
- || pParse->nErr || db->mallocFailed );
105108
+ assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr );
104703105109
for(j=0; j<nExpr; j++){
104704105110
if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
104705105111
assert( pIdx->azColl[j] );
104706105112
if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
104707105113
continue;
@@ -105173,14 +105579,12 @@
105173105579
pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
105174105580
pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
105175105581
}
105176105582
pSel->iLimit = 0;
105177105583
if( sqlite3Select(pParse, pSel, &dest) ){
105178
- if( pParse->nErr ){
105179
- pExpr->op2 = pExpr->op;
105180
- pExpr->op = TK_ERROR;
105181
- }
105584
+ pExpr->op2 = pExpr->op;
105585
+ pExpr->op = TK_ERROR;
105182105586
return 0;
105183105587
}
105184105588
pExpr->iTable = rReg = dest.iSDParm;
105185105589
ExprSetVVAProperty(pExpr, EP_NoReduce);
105186105590
if( addrOnce ){
@@ -105393,14 +105797,13 @@
105393105797
if( destIfNull==destIfFalse ){
105394105798
destStep2 = destIfFalse;
105395105799
}else{
105396105800
destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105397105801
}
105398
- if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105399105802
for(i=0; i<nVector; i++){
105400105803
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105401
- if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
105804
+ if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105402105805
if( sqlite3ExprCanBeNull(p) ){
105403105806
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
105404105807
VdbeCoverage(v);
105405105808
}
105406105809
}
@@ -108571,11 +108974,13 @@
108571108974
sqlite3 *db; /* The database connection; */
108572108975
Vdbe *v; /* The prepared statement under construction */
108573108976
int r1; /* Temporary registers */
108574108977
108575108978
db = pParse->db;
108576
- if( pParse->nErr || db->mallocFailed ) return;
108979
+ assert( db->pParse==pParse );
108980
+ if( pParse->nErr ) return;
108981
+ assert( db->mallocFailed==0 );
108577108982
pNew = pParse->pNewTable;
108578108983
assert( pNew );
108579108984
108580108985
assert( sqlite3BtreeHoldsAllMutexes(db) );
108581108986
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -108697,11 +109102,11 @@
108697109102
sqlite3NestedParse(pParse,
108698109103
"SELECT CASE WHEN quick_check GLOB 'CHECK*'"
108699109104
" THEN raise(ABORT,'CHECK constraint failed')"
108700109105
" ELSE raise(ABORT,'NOT NULL constraint failed')"
108701109106
" END"
108702
- " FROM pragma_quick_check(\"%w\",\"%w\")"
109107
+ " FROM pragma_quick_check(%Q,%Q)"
108703109108
" WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
108704109109
zTab, zDb
108705109110
);
108706109111
}
108707109112
}
@@ -108982,11 +109387,13 @@
108982109387
**
108983109388
** Technically, as x no longer points into a valid object or to the byte
108984109389
** following a valid object, it may not be used in comparison operations.
108985109390
*/
108986109391
static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
108987
- if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){
109392
+ assert( pParse==pParse->db->pParse );
109393
+ assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
109394
+ if( pParse->nErr==0 ){
108988109395
const RenameToken *p;
108989109396
u8 i = 0;
108990109397
for(p=pParse->pRename; p; p=p->pNext){
108991109398
if( p->p ){
108992109399
assert( p->p!=pPtr );
@@ -109379,11 +109786,11 @@
109379109786
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
109380109787
109381109788
/* Parse the SQL statement passed as the first argument. If no error
109382109789
** occurs and the parse does not result in a new table, index or
109383109790
** trigger object, the database must be corrupt. */
109384
- memset(p, 0, sizeof(Parse));
109791
+ sqlite3ParseObjectInit(p, db);
109385109792
p->eParseMode = PARSE_MODE_RENAME;
109386109793
p->db = db;
109387109794
p->nQueryLoop = 1;
109388109795
rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM;
109389109796
if( db->mallocFailed ) rc = SQLITE_NOMEM;
@@ -109664,11 +110071,11 @@
109664110071
sqlite3FreeIndex(db, pIdx);
109665110072
}
109666110073
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
109667110074
sqlite3DbFree(db, pParse->zErrMsg);
109668110075
renameTokenFree(db, pParse->pRename);
109669
- sqlite3ParserReset(pParse);
110076
+ sqlite3ParseObjectReset(pParse);
109670110077
}
109671110078
109672110079
/*
109673110080
** SQL function:
109674110081
**
@@ -110378,10 +110785,16 @@
110378110785
110379110786
/* Edit the sqlite_schema table */
110380110787
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110381110788
assert( iDb>=0 );
110382110789
zDb = db->aDb[iDb].zDbSName;
110790
+#ifndef SQLITE_OMIT_AUTHORIZATION
110791
+ /* Invoke the authorization callback. */
110792
+ if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){
110793
+ goto exit_drop_column;
110794
+ }
110795
+#endif
110383110796
renameTestSchema(pParse, zDb, iDb==1, "", 0);
110384110797
renameFixQuotes(pParse, zDb, iDb==1);
110385110798
sqlite3NestedParse(pParse,
110386110799
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
110387110800
"sql = sqlite_drop_column(%d, sql, %d) "
@@ -112765,11 +113178,11 @@
112765113178
){
112766113179
goto attach_end;
112767113180
}
112768113181
112769113182
#ifndef SQLITE_OMIT_AUTHORIZATION
112770
- if( pAuthArg ){
113183
+ if( ALWAYS(pAuthArg) ){
112771113184
char *zAuthArg;
112772113185
if( pAuthArg->op==TK_STRING ){
112773113186
assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112774113187
zAuthArg = pAuthArg->u.zToken;
112775113188
}else{
@@ -113426,15 +113839,17 @@
113426113839
sqlite3 *db;
113427113840
Vdbe *v;
113428113841
113429113842
assert( pParse->pToplevel==0 );
113430113843
db = pParse->db;
113844
+ assert( db->pParse==pParse );
113431113845
if( pParse->nested ) return;
113432
- if( db->mallocFailed || pParse->nErr ){
113433
- if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
113846
+ if( pParse->nErr ){
113847
+ if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM;
113434113848
return;
113435113849
}
113850
+ assert( db->mallocFailed==0 );
113436113851
113437113852
/* Begin by generating some termination code at the end of the
113438113853
** vdbe program
113439113854
*/
113440113855
v = pParse->pVdbe;
@@ -113563,11 +113978,13 @@
113563113978
}
113564113979
}
113565113980
113566113981
/* Get the VDBE program ready for execution
113567113982
*/
113568
- if( v && pParse->nErr==0 && !db->mallocFailed ){
113983
+ assert( v!=0 || pParse->nErr );
113984
+ assert( db->mallocFailed==0 || pParse->nErr );
113985
+ if( pParse->nErr==0 ){
113569113986
/* A minimum of one cursor is required if autoincrement is used
113570113987
* See ticket [a696379c1f08866] */
113571113988
assert( pParse->pAinc==0 || pParse->nTab>0 );
113572113989
sqlite3VdbeMakeReady(v, pParse);
113573113990
pParse->rc = SQLITE_DONE;
@@ -115667,14 +116084,15 @@
115667116084
pList->a[0].sortFlags = pParse->iPkSortOrder;
115668116085
assert( pParse->pNewTable==pTab );
115669116086
pTab->iPKey = -1;
115670116087
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
115671116088
SQLITE_IDXTYPE_PRIMARYKEY);
115672
- if( db->mallocFailed || pParse->nErr ){
116089
+ if( pParse->nErr ){
115673116090
pTab->tabFlags &= ~TF_WithoutRowid;
115674116091
return;
115675116092
}
116093
+ assert( db->mallocFailed==0 );
115676116094
pPk = sqlite3PrimaryKeyIndex(pTab);
115677116095
assert( pPk->nKeyCol==1 );
115678116096
}else{
115679116097
pPk = sqlite3PrimaryKeyIndex(pTab);
115680116098
assert( pPk!=0 );
@@ -116411,14 +116829,14 @@
116411116829
** normally holds CHECK constraints on an ordinary table, but for
116412116830
** a VIEW it holds the list of column names.
116413116831
*/
116414116832
sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
116415116833
&pTable->nCol, &pTable->aCol);
116416
- if( db->mallocFailed==0
116417
- && pParse->nErr==0
116834
+ if( pParse->nErr==0
116418116835
&& pTable->nCol==pSel->pEList->nExpr
116419116836
){
116837
+ assert( db->mallocFailed==0 );
116420116838
sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
116421116839
SQLITE_AFF_NONE);
116422116840
}
116423116841
}else{
116424116842
/* CREATE VIEW name AS... without an argument list. Construct
@@ -117033,11 +117451,11 @@
117033117451
tnum = (Pgno)memRootPage;
117034117452
}else{
117035117453
tnum = pIndex->tnum;
117036117454
}
117037117455
pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
117038
- assert( pKey!=0 || db->mallocFailed || pParse->nErr );
117456
+ assert( pKey!=0 || pParse->nErr );
117039117457
117040117458
/* Open the sorter cursor if we are to use one. */
117041117459
iSorter = pParse->nTab++;
117042117460
sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
117043117461
sqlite3KeyInfoRef(pKey), P4_KEYINFO);
@@ -117197,13 +117615,15 @@
117197117615
int nExtra = 0; /* Space allocated for zExtra[] */
117198117616
int nExtraCol; /* Number of extra columns needed */
117199117617
char *zExtra = 0; /* Extra space after the Index object */
117200117618
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
117201117619
117202
- if( db->mallocFailed || pParse->nErr>0 ){
117620
+ assert( db->pParse==pParse );
117621
+ if( pParse->nErr ){
117203117622
goto exit_create_index;
117204117623
}
117624
+ assert( db->mallocFailed==0 );
117205117625
if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
117206117626
goto exit_create_index;
117207117627
}
117208117628
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117209117629
goto exit_create_index;
@@ -117263,11 +117683,10 @@
117263117683
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117264117684
}
117265117685
pDb = &db->aDb[iDb];
117266117686
117267117687
assert( pTab!=0 );
117268
- assert( pParse->nErr==0 );
117269117688
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
117270117689
&& db->init.busy==0
117271117690
&& pTblName!=0
117272117691
#if SQLITE_USER_AUTHENTICATION
117273117692
&& sqlite3UserAuthTable(pTab->zName)==0
@@ -117827,14 +118246,14 @@
117827118246
Index *pIndex;
117828118247
Vdbe *v;
117829118248
sqlite3 *db = pParse->db;
117830118249
int iDb;
117831118250
117832
- assert( pParse->nErr==0 ); /* Never called with prior errors */
117833118251
if( db->mallocFailed ){
117834118252
goto exit_drop_index;
117835118253
}
118254
+ assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
117836118255
assert( pName->nSrc==1 );
117837118256
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117838118257
goto exit_drop_index;
117839118258
}
117840118259
pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
@@ -119746,13 +120165,15 @@
119746120165
Trigger *pTrigger; /* List of table triggers, if required */
119747120166
#endif
119748120167
119749120168
memset(&sContext, 0, sizeof(sContext));
119750120169
db = pParse->db;
119751
- if( pParse->nErr || db->mallocFailed ){
120170
+ assert( db->pParse==pParse );
120171
+ if( pParse->nErr ){
119752120172
goto delete_from_cleanup;
119753120173
}
120174
+ assert( db->mallocFailed==0 );
119754120175
assert( pTabList->nSrc==1 );
119755120176
119756120177
119757120178
/* Locate the table which we want to delete. This table has to be
119758120179
** put in an SrcList structure because some of the subroutines we
@@ -119929,11 +120350,11 @@
119929120350
**
119930120351
** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values.
119931120352
** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
119932120353
** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
119933120354
*/
119934
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1);
120355
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
119935120356
if( pWInfo==0 ) goto delete_from_cleanup;
119936120357
eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
119937120358
assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
119938120359
assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
119939120360
if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
@@ -120542,10 +120963,11 @@
120542120963
static void subtypeFunc(
120543120964
sqlite3_context *context,
120544120965
int argc,
120545120966
sqlite3_value **argv
120546120967
){
120968
+ UNUSED_PARAMETER(argc);
120547120969
sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
120548120970
}
120549120971
120550120972
/*
120551120973
** Implementation of the length() function
@@ -123472,11 +123894,11 @@
123472123894
123473123895
/* Create VDBE to loop through the entries in pSrc that match the WHERE
123474123896
** clause. For each row found, increment either the deferred or immediate
123475123897
** foreign key constraint counter. */
123476123898
if( pParse->nErr==0 ){
123477
- pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
123899
+ pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
123478123900
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
123479123901
if( pWInfo ){
123480123902
sqlite3WhereEnd(pWInfo);
123481123903
}
123482123904
}
@@ -125014,13 +125436,15 @@
125014125436
Trigger *pTrigger; /* List of triggers on pTab, if required */
125015125437
int tmask; /* Mask of trigger times */
125016125438
#endif
125017125439
125018125440
db = pParse->db;
125019
- if( pParse->nErr || db->mallocFailed ){
125441
+ assert( db->pParse==pParse );
125442
+ if( pParse->nErr ){
125020125443
goto insert_cleanup;
125021125444
}
125445
+ assert( db->mallocFailed==0 );
125022125446
dest.iSDParm = 0; /* Suppress a harmless compiler warning */
125023125447
125024125448
/* If the Select object is really just a simple VALUES() list with a
125025125449
** single row (the common case) then keep that one row of values
125026125450
** and discard the other (unused) parts of the pSelect object
@@ -125192,11 +125616,13 @@
125192125616
sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
125193125617
dest.iSdst = bIdListInOrder ? regData : 0;
125194125618
dest.nSdst = pTab->nCol;
125195125619
rc = sqlite3Select(pParse, pSelect, &dest);
125196125620
regFromSelect = dest.iSdst;
125197
- if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
125621
+ assert( db->pParse==pParse );
125622
+ if( rc || pParse->nErr ) goto insert_cleanup;
125623
+ assert( db->mallocFailed==0 );
125198125624
sqlite3VdbeEndCoroutine(v, regYield);
125199125625
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
125200125626
assert( pSelect->pEList );
125201125627
nColumn = pSelect->pEList->nExpr;
125202125628
@@ -127937,10 +128363,15 @@
127937128363
int (*autovacuum_pages)(sqlite3*,
127938128364
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
127939128365
void*, void(*)(void*));
127940128366
/* Version 3.38.0 and later */
127941128367
int (*error_offset)(sqlite3*);
128368
+ int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128369
+ int (*vtab_distinct)(sqlite3_index_info*);
128370
+ int (*vtab_in)(sqlite3_index_info*,int,int);
128371
+ int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128372
+ int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
127942128373
};
127943128374
127944128375
/*
127945128376
** This is the function signature used for all extension entry points. It
127946128377
** is also defined in the file "loadext.c".
@@ -128250,10 +128681,15 @@
128250128681
#define sqlite3_total_changes64 sqlite3_api->total_changes64
128251128682
/* Version 3.37.0 and later */
128252128683
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128253128684
/* Version 3.38.0 and later */
128254128685
#define sqlite3_error_offset sqlite3_api->error_offset
128686
+#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128687
+#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
128688
+#define sqlite3_vtab_in sqlite3_api->vtab_in
128689
+#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
128690
+#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
128255128691
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128256128692
128257128693
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128258128694
/* This case when the file really is being compiled as a loadable
128259128695
** extension */
@@ -128741,10 +129177,15 @@
128741129177
sqlite3_total_changes64,
128742129178
/* Version 3.37.0 and later */
128743129179
sqlite3_autovacuum_pages,
128744129180
/* Version 3.38.0 and later */
128745129181
sqlite3_error_offset,
129182
+ sqlite3_vtab_rhs_value,
129183
+ sqlite3_vtab_distinct,
129184
+ sqlite3_vtab_in,
129185
+ sqlite3_vtab_in_first,
129186
+ sqlite3_vtab_in_next
128746129187
};
128747129188
128748129189
/* True if x is the directory separator character
128749129190
*/
128750129191
#if SQLITE_OS_WIN
@@ -131042,10 +131483,14 @@
131042131483
sqlite3_stmt *pDummy = 0;
131043131484
(void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
131044131485
(void)sqlite3_finalize(pDummy);
131045131486
sqlite3DbFree(db, zSql);
131046131487
}
131488
+ if( db->mallocFailed ){
131489
+ sqlite3ErrorMsg(db->pParse, "out of memory");
131490
+ db->pParse->rc = SQLITE_NOMEM_BKPT;
131491
+ }
131047131492
pHash = &db->aDb[ii].pSchema->tblHash;
131048131493
break;
131049131494
}
131050131495
}
131051131496
}
@@ -133078,12 +133523,14 @@
133078133523
}
133079133524
133080133525
/*
133081133526
** Free all memory allocations in the pParse object
133082133527
*/
133083
-SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
133528
+SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse *pParse){
133084133529
sqlite3 *db = pParse->db;
133530
+ assert( db!=0 );
133531
+ assert( db->pParse==pParse );
133085133532
assert( pParse->nested==0 );
133086133533
#ifndef SQLITE_OMIT_SHARED_CACHE
133087133534
sqlite3DbFree(db, pParse->aTableLock);
133088133535
#endif
133089133536
while( pParse->pCleanup ){
@@ -133094,15 +133541,16 @@
133094133541
}
133095133542
sqlite3DbFree(db, pParse->aLabel);
133096133543
if( pParse->pConstExpr ){
133097133544
sqlite3ExprListDelete(db, pParse->pConstExpr);
133098133545
}
133099
- if( db ){
133100
- assert( db->lookaside.bDisable >= pParse->disableLookaside );
133101
- db->lookaside.bDisable -= pParse->disableLookaside;
133102
- db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133103
- }
133546
+ assert( db->lookaside.bDisable >= pParse->disableLookaside );
133547
+ db->lookaside.bDisable -= pParse->disableLookaside;
133548
+ db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133549
+ assert( pParse->db->pParse==pParse );
133550
+ db->pParse = pParse->pOuterParse;
133551
+ pParse->db = 0;
133104133552
pParse->disableLookaside = 0;
133105133553
}
133106133554
133107133555
/*
133108133556
** Add a new cleanup operation to a Parser. The cleanup should happen when
@@ -133111,11 +133559,11 @@
133111133559
**
133112133560
** Use this mechanism for uncommon cleanups. There is a higher setup
133113133561
** cost for this mechansim (an extra malloc), so it should not be used
133114133562
** for common cleanups that happen on most calls. But for less
133115133563
** common cleanups, we save a single NULL-pointer comparison in
133116
-** sqlite3ParserReset(), which reduces the total CPU cycle count.
133564
+** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
133117133565
**
133118133566
** If a memory allocation error occurs, then the cleanup happens immediately.
133119133567
** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
133120133568
** pParse->earlyCleanup flag is set in that case. Calling code show verify
133121133569
** that test cases exist for which this happens, to guard against possible
@@ -133150,10 +133598,29 @@
133150133598
pParse->earlyCleanup = 1;
133151133599
#endif
133152133600
}
133153133601
return pPtr;
133154133602
}
133603
+
133604
+/*
133605
+** Turn bulk memory into a valid Parse object and link that Parse object
133606
+** into database connection db.
133607
+**
133608
+** Call sqlite3ParseObjectReset() to undo this operation.
133609
+**
133610
+** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which
133611
+** is generated by Lemon.
133612
+*/
133613
+SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){
133614
+ memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
133615
+ memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
133616
+ assert( db->pParse!=pParse );
133617
+ pParse->pOuterParse = db->pParse;
133618
+ db->pParse = pParse;
133619
+ pParse->db = db;
133620
+ if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
133621
+}
133155133622
133156133623
/*
133157133624
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133158133625
*/
133159133626
static int sqlite3Prepare(
@@ -133167,15 +133634,19 @@
133167133634
){
133168133635
int rc = SQLITE_OK; /* Result code */
133169133636
int i; /* Loop counter */
133170133637
Parse sParse; /* Parsing context */
133171133638
133172
- memset(&sParse, 0, PARSE_HDR_SZ);
133639
+ /* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
133640
+ memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
133173133641
memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
133642
+ sParse.pOuterParse = db->pParse;
133643
+ db->pParse = &sParse;
133644
+ sParse.db = db;
133174133645
sParse.pReprepare = pReprepare;
133175133646
assert( ppStmt && *ppStmt==0 );
133176
- /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
133647
+ if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory");
133177133648
assert( sqlite3_mutex_held(db->mutex) );
133178133649
133179133650
/* For a long-term use prepared statement avoid the use of
133180133651
** lookaside memory.
133181133652
*/
@@ -133224,11 +133695,10 @@
133224133695
}
133225133696
}
133226133697
133227133698
sqlite3VtabUnlockList(db);
133228133699
133229
- sParse.db = db;
133230133700
if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
133231133701
char *zSqlCopy;
133232133702
int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
133233133703
testcase( nBytes==mxLen );
133234133704
testcase( nBytes==mxLen+1 );
@@ -133291,11 +133761,11 @@
133291133761
sqlite3DbFree(db, pT);
133292133762
}
133293133763
133294133764
end_prepare:
133295133765
133296
- sqlite3ParserReset(&sParse);
133766
+ sqlite3ParseObjectReset(&sParse);
133297133767
return rc;
133298133768
}
133299133769
static int sqlite3LockAndPrepare(
133300133770
sqlite3 *db, /* Database handle. */
133301133771
const char *zSql, /* UTF-8 encoded SQL statement. */
@@ -134946,11 +135416,11 @@
134946135416
p->enc = ENC(db);
134947135417
p->db = db;
134948135418
p->nRef = 1;
134949135419
memset(&p[1], 0, nExtra);
134950135420
}else{
134951
- sqlite3OomFault(db);
135421
+ return (KeyInfo*)sqlite3OomFault(db);
134952135422
}
134953135423
return p;
134954135424
}
134955135425
134956135426
/*
@@ -135117,10 +135587,13 @@
135117135587
}
135118135588
#endif
135119135589
135120135590
iTab = pSort->iECursor;
135121135591
if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
135592
+ if( eDest==SRT_Mem && p->iOffset ){
135593
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
135594
+ }
135122135595
regRowid = 0;
135123135596
regRow = pDest->iSdst;
135124135597
}else{
135125135598
regRowid = sqlite3GetTempReg(pParse);
135126135599
if( eDest==SRT_EphemTab || eDest==SRT_Table ){
@@ -136975,10 +137448,11 @@
136975137448
}else{
136976137449
pSplit = p;
136977137450
for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
136978137451
}
136979137452
pPrior = pSplit->pPrior;
137453
+ assert( pPrior!=0 );
136980137454
pSplit->pPrior = 0;
136981137455
pPrior->pNext = 0;
136982137456
assert( p->pOrderBy == pOrderBy );
136983137457
assert( pOrderBy!=0 || db->mallocFailed );
136984137458
pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
@@ -139126,11 +139600,12 @@
139126139600
}
139127139601
}
139128139602
139129139603
/* Process NATURAL keywords, and ON and USING clauses of joins.
139130139604
*/
139131
- if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
139605
+ assert( db->mallocFailed==0 || pParse->nErr!=0 );
139606
+ if( pParse->nErr || sqliteProcessJoin(pParse, p) ){
139132139607
return WRC_Abort;
139133139608
}
139134139609
139135139610
/* For every "*" that occurs in the column list, insert the names of
139136139611
** all columns in all tables. And for every TABLE.* insert the names
@@ -139423,16 +139898,17 @@
139423139898
Parse *pParse, /* The parser context */
139424139899
Select *p, /* The SELECT statement being coded. */
139425139900
NameContext *pOuterNC /* Name context for container */
139426139901
){
139427139902
assert( p!=0 || pParse->db->mallocFailed );
139903
+ assert( pParse->db->pParse==pParse );
139428139904
if( pParse->db->mallocFailed ) return;
139429139905
if( p->selFlags & SF_HasTypeInfo ) return;
139430139906
sqlite3SelectExpand(pParse, p);
139431
- if( pParse->nErr || pParse->db->mallocFailed ) return;
139907
+ if( pParse->nErr ) return;
139432139908
sqlite3ResolveSelectNames(pParse, p, pOuterNC);
139433
- if( pParse->nErr || pParse->db->mallocFailed ) return;
139909
+ if( pParse->nErr ) return;
139434139910
sqlite3SelectAddTypeInfo(pParse, p);
139435139911
}
139436139912
139437139913
/*
139438139914
** Reset the aggregate accumulator.
@@ -139445,12 +139921,14 @@
139445139921
static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
139446139922
Vdbe *v = pParse->pVdbe;
139447139923
int i;
139448139924
struct AggInfo_func *pFunc;
139449139925
int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
139926
+ assert( pParse->db->pParse==pParse );
139927
+ assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
139450139928
if( nReg==0 ) return;
139451
- if( pParse->nErr || pParse->db->mallocFailed ) return;
139929
+ if( pParse->nErr ) return;
139452139930
#ifdef SQLITE_DEBUG
139453139931
/* Verify that all AggInfo registers are within the range specified by
139454139932
** AggInfo.mnReg..AggInfo.mxReg */
139455139933
assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
139456139934
for(i=0; i<pAggInfo->nColumn; i++){
@@ -139869,14 +140347,16 @@
139869140347
sqlite3 *db; /* The database connection */
139870140348
ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
139871140349
u8 minMaxFlag; /* Flag for min/max queries */
139872140350
139873140351
db = pParse->db;
140352
+ assert( pParse==db->pParse );
139874140353
v = sqlite3GetVdbe(pParse);
139875
- if( p==0 || db->mallocFailed || pParse->nErr ){
140354
+ if( p==0 || pParse->nErr ){
139876140355
return 1;
139877140356
}
140357
+ assert( db->mallocFailed==0 );
139878140358
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
139879140359
#if SELECTTRACE_ENABLED
139880140360
SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
139881140361
if( sqlite3SelectTrace & 0x100 ){
139882140362
sqlite3TreeViewSelect(0, p, 0);
@@ -139907,13 +140387,14 @@
139907140387
}
139908140388
p->selFlags &= ~SF_Distinct;
139909140389
p->selFlags |= SF_NoopOrderBy;
139910140390
}
139911140391
sqlite3SelectPrep(pParse, p, 0);
139912
- if( pParse->nErr || db->mallocFailed ){
140392
+ if( pParse->nErr ){
139913140393
goto select_end;
139914140394
}
140395
+ assert( db->mallocFailed==0 );
139915140396
assert( p->pEList!=0 );
139916140397
#if SELECTTRACE_ENABLED
139917140398
if( sqlite3SelectTrace & 0x104 ){
139918140399
SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
139919140400
sqlite3TreeViewSelect(0, p, 0);
@@ -139953,11 +140434,11 @@
139953140434
sqlite3GenerateColumnNames(pParse, p);
139954140435
}
139955140436
139956140437
#ifndef SQLITE_OMIT_WINDOWFUNC
139957140438
if( sqlite3WindowRewrite(pParse, p) ){
139958
- assert( db->mallocFailed || pParse->nErr>0 );
140439
+ assert( pParse->nErr );
139959140440
goto select_end;
139960140441
}
139961140442
#if SELECTTRACE_ENABLED
139962140443
if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
139963140444
SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -140429,11 +140910,11 @@
140429140910
140430140911
140431140912
/* Begin the database scan. */
140432140913
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140433140914
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
140434
- p->pEList, wctrlFlags, p->nSelectRow);
140915
+ p->pEList, p, wctrlFlags, p->nSelectRow);
140435140916
if( pWInfo==0 ) goto select_end;
140436140917
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
140437140918
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
140438140919
}
140439140920
if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
@@ -140693,11 +141174,11 @@
140693141174
** in the right order to begin with.
140694141175
*/
140695141176
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
140696141177
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140697141178
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
140698
- WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
141179
+ 0, (WHERE_GROUPBY|(orderByGrp ? WHERE_SORTBYGROUP : 0)|distFlag), 0
140699141180
);
140700141181
if( pWInfo==0 ){
140701141182
sqlite3ExprListDelete(db, pDistinct);
140702141183
goto select_end;
140703141184
}
@@ -140991,11 +141472,11 @@
140991141472
assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
140992141473
assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
140993141474
140994141475
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140995141476
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
140996
- pDistinct, minMaxFlag|distFlag, 0);
141477
+ pDistinct, 0, minMaxFlag|distFlag, 0);
140997141478
if( pWInfo==0 ){
140998141479
goto select_end;
140999141480
}
141000141481
SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
141001141482
eDist = sqlite3WhereIsDistinct(pWInfo);
@@ -141048,11 +141529,11 @@
141048141529
/* Control jumps to here if an error is encountered above, or upon
141049141530
** successful coding of the SELECT.
141050141531
*/
141051141532
select_end:
141052141533
assert( db->mallocFailed==0 || db->mallocFailed==1 );
141053
- pParse->nErr += db->mallocFailed;
141534
+ assert( db->mallocFailed==0 || pParse->nErr!=0 );
141054141535
sqlite3ExprListDelete(db, pMinMaxOrderBy);
141055141536
#ifdef SQLITE_DEBUG
141056141537
if( pAggInfo && !db->mallocFailed ){
141057141538
for(i=0; i<pAggInfo->nColumn; i++){
141058141539
Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -142200,10 +142681,11 @@
142200142681
Select sSelect;
142201142682
SrcList sFrom;
142202142683
142203142684
assert( v!=0 );
142204142685
assert( pParse->bReturning );
142686
+ assert( db->pParse==pParse );
142205142687
pReturning = pParse->u1.pReturning;
142206142688
assert( pTrigger == &(pReturning->retTrig) );
142207142689
memset(&sSelect, 0, sizeof(sSelect));
142208142690
memset(&sFrom, 0, sizeof(sFrom));
142209142691
sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
@@ -142210,11 +142692,12 @@
142210142692
sSelect.pSrc = &sFrom;
142211142693
sFrom.nSrc = 1;
142212142694
sFrom.a[0].pTab = pTab;
142213142695
sFrom.a[0].iCursor = -1;
142214142696
sqlite3SelectPrep(pParse, &sSelect, 0);
142215
- if( db->mallocFailed==0 && pParse->nErr==0 ){
142697
+ if( pParse->nErr==0 ){
142698
+ assert( db->mallocFailed==0 );
142216142699
sqlite3GenerateColumnNames(pParse, &sSelect);
142217142700
}
142218142701
sqlite3ExprListDelete(db, sSelect.pEList);
142219142702
pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142220142703
if( !db->mallocFailed ){
@@ -142228,11 +142711,11 @@
142228142711
sNC.uNC.iBaseReg = regIn;
142229142712
sNC.ncFlags = NC_UBaseReg;
142230142713
pParse->eTriggerOp = pTrigger->op;
142231142714
pParse->pTriggerTab = pTab;
142232142715
if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142233
- && !db->mallocFailed
142716
+ && ALWAYS(!db->mallocFailed)
142234142717
){
142235142718
int i;
142236142719
int nCol = pNew->nExpr;
142237142720
int reg = pParse->nMem+1;
142238142721
pParse->nMem += nCol+2;
@@ -142392,12 +142875,12 @@
142392142875
TriggerPrg *pPrg; /* Value to return */
142393142876
Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
142394142877
Vdbe *v; /* Temporary VM */
142395142878
NameContext sNC; /* Name context for sub-vdbe */
142396142879
SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
142397
- Parse *pSubParse; /* Parse context for sub-vdbe */
142398142880
int iEndTrigger = 0; /* Label to jump to if WHEN is false */
142881
+ Parse sSubParse; /* Parse context for sub-vdbe */
142399142882
142400142883
assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
142401142884
assert( pTop->pVdbe );
142402142885
142403142886
/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
@@ -142415,23 +142898,21 @@
142415142898
pPrg->aColmask[0] = 0xffffffff;
142416142899
pPrg->aColmask[1] = 0xffffffff;
142417142900
142418142901
/* Allocate and populate a new Parse context to use for coding the
142419142902
** trigger sub-program. */
142420
- pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
142421
- if( !pSubParse ) return 0;
142903
+ sqlite3ParseObjectInit(&sSubParse, db);
142422142904
memset(&sNC, 0, sizeof(sNC));
142423
- sNC.pParse = pSubParse;
142424
- pSubParse->db = db;
142425
- pSubParse->pTriggerTab = pTab;
142426
- pSubParse->pToplevel = pTop;
142427
- pSubParse->zAuthContext = pTrigger->zName;
142428
- pSubParse->eTriggerOp = pTrigger->op;
142429
- pSubParse->nQueryLoop = pParse->nQueryLoop;
142430
- pSubParse->disableVtab = pParse->disableVtab;
142431
-
142432
- v = sqlite3GetVdbe(pSubParse);
142905
+ sNC.pParse = &sSubParse;
142906
+ sSubParse.pTriggerTab = pTab;
142907
+ sSubParse.pToplevel = pTop;
142908
+ sSubParse.zAuthContext = pTrigger->zName;
142909
+ sSubParse.eTriggerOp = pTrigger->op;
142910
+ sSubParse.nQueryLoop = pParse->nQueryLoop;
142911
+ sSubParse.disableVtab = pParse->disableVtab;
142912
+
142913
+ v = sqlite3GetVdbe(&sSubParse);
142433142914
if( v ){
142434142915
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
142435142916
pTrigger->zName, onErrorText(orconf),
142436142917
(pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
142437142918
(pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
@@ -142453,42 +142934,43 @@
142453142934
if( pTrigger->pWhen ){
142454142935
pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
142455142936
if( db->mallocFailed==0
142456142937
&& SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
142457142938
){
142458
- iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
142459
- sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142939
+ iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse);
142940
+ sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142460142941
}
142461142942
sqlite3ExprDelete(db, pWhen);
142462142943
}
142463142944
142464142945
/* Code the trigger program into the sub-vdbe. */
142465
- codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);
142946
+ codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf);
142466142947
142467142948
/* Insert an OP_Halt at the end of the sub-program. */
142468142949
if( iEndTrigger ){
142469142950
sqlite3VdbeResolveLabel(v, iEndTrigger);
142470142951
}
142471142952
sqlite3VdbeAddOp0(v, OP_Halt);
142472142953
VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
142954
+ transferParseError(pParse, &sSubParse);
142473142955
142474
- transferParseError(pParse, pSubParse);
142475
- if( db->mallocFailed==0 && pParse->nErr==0 ){
142956
+ if( pParse->nErr==0 ){
142957
+ assert( db->mallocFailed==0 );
142476142958
pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
142477142959
}
142478
- pProgram->nMem = pSubParse->nMem;
142479
- pProgram->nCsr = pSubParse->nTab;
142960
+ pProgram->nMem = sSubParse.nMem;
142961
+ pProgram->nCsr = sSubParse.nTab;
142480142962
pProgram->token = (void *)pTrigger;
142481
- pPrg->aColmask[0] = pSubParse->oldmask;
142482
- pPrg->aColmask[1] = pSubParse->newmask;
142963
+ pPrg->aColmask[0] = sSubParse.oldmask;
142964
+ pPrg->aColmask[1] = sSubParse.newmask;
142483142965
sqlite3VdbeDelete(v);
142966
+ }else{
142967
+ transferParseError(pParse, &sSubParse);
142484142968
}
142485142969
142486
- assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
142487
- sqlite3ParserReset(pSubParse);
142488
- sqlite3StackFree(db, pSubParse);
142489
-
142970
+ assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg );
142971
+ sqlite3ParseObjectReset(&sSubParse);
142490142972
return pPrg;
142491142973
}
142492142974
142493142975
/*
142494142976
** Return a pointer to a TriggerPrg object containing the sub-program for
@@ -142539,11 +143021,11 @@
142539143021
int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
142540143022
){
142541143023
Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
142542143024
TriggerPrg *pPrg;
142543143025
pPrg = getRowTrigger(pParse, p, pTab, orconf);
142544
- assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
143026
+ assert( pPrg || pParse->nErr );
142545143027
142546143028
/* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
142547143029
** is a pointer to the sub-vdbe containing the trigger program. */
142548143030
if( pPrg ){
142549143031
int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
@@ -143057,13 +143539,15 @@
143057143539
int regRowSet = 0; /* Rowset of rows to be updated */
143058143540
int regKey = 0; /* composite PRIMARY KEY value */
143059143541
143060143542
memset(&sContext, 0, sizeof(sContext));
143061143543
db = pParse->db;
143062
- if( pParse->nErr || db->mallocFailed ){
143544
+ assert( db->pParse==pParse );
143545
+ if( pParse->nErr ){
143063143546
goto update_cleanup;
143064143547
}
143548
+ assert( db->mallocFailed==0 );
143065143549
143066143550
/* Locate the table which we want to update.
143067143551
*/
143068143552
pTab = sqlite3SrcListLookup(pParse, pTabList);
143069143553
if( pTab==0 ) goto update_cleanup;
@@ -143431,11 +143915,11 @@
143431143915
** or index, causing a single-pass approach to malfunction. */
143432143916
flags = WHERE_ONEPASS_DESIRED;
143433143917
if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
143434143918
flags |= WHERE_ONEPASS_MULTIROW;
143435143919
}
143436
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
143920
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
143437143921
if( pWInfo==0 ) goto update_cleanup;
143438143922
143439143923
/* A one-pass strategy that might update more than one row may not
143440143924
** be used if any column of the index used for the scan is being
143441143925
** updated. Otherwise, if there is an index on "b", statements like
@@ -143953,11 +144437,13 @@
143953144437
}else{
143954144438
regRec = ++pParse->nMem;
143955144439
regRowid = ++pParse->nMem;
143956144440
143957144441
/* Start scanning the virtual table */
143958
- pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0);
144442
+ pWInfo = sqlite3WhereBegin(
144443
+ pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0
144444
+ );
143959144445
if( pWInfo==0 ) return;
143960144446
143961144447
/* Populate the argument registers. */
143962144448
for(i=0; i<pTab->nCol; i++){
143963144449
assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
@@ -145598,13 +146084,12 @@
145598146084
return SQLITE_MISUSE_BKPT;
145599146085
}
145600146086
pTab = pCtx->pTab;
145601146087
assert( IsVirtual(pTab) );
145602146088
145603
- memset(&sParse, 0, sizeof(sParse));
146089
+ sqlite3ParseObjectInit(&sParse, db);
145604146090
sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
145605
- sParse.db = db;
145606146091
/* We should never be able to reach this point while loading the
145607146092
** schema. Nevertheless, defend against that (turn off db->init.busy)
145608146093
** in case a bug arises. */
145609146094
assert( db->init.busy==0 );
145610146095
initBusy = db->init.busy;
@@ -145654,11 +146139,11 @@
145654146139
145655146140
if( sParse.pVdbe ){
145656146141
sqlite3VdbeFinalize(sParse.pVdbe);
145657146142
}
145658146143
sqlite3DeleteTable(db, sParse.pNewTable);
145659
- sqlite3ParserReset(&sParse);
146144
+ sqlite3ParseObjectReset(&sParse);
145660146145
db->init.busy = initBusy;
145661146146
145662146147
assert( (rc&0xff)==rc );
145663146148
rc = sqlite3ApiExit(db, rc);
145664146149
sqlite3_mutex_leave(db->mutex);
@@ -146265,14 +146750,16 @@
146265146750
u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
146266146751
Index *pIndex; /* Index used, or NULL */
146267146752
} btree;
146268146753
struct { /* Information for virtual tables */
146269146754
int idxNum; /* Index number */
146270
- u8 needFree; /* True if sqlite3_free(idxStr) is needed */
146755
+ u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
146756
+ u32 bOmitOffset : 1; /* True to let virtual table handle offset */
146271146757
i8 isOrdered; /* True if satisfies ORDER BY */
146272146758
u16 omitMask; /* Terms that may be omitted */
146273146759
char *idxStr; /* Index identifier string */
146760
+ u32 mHandleIn; /* Terms to handle as IN(...) instead of == */
146274146761
} vtab;
146275146762
} u;
146276146763
u32 wsFlags; /* WHERE_* flags describing the plan */
146277146764
u16 nLTerm; /* Number of entries in aLTerm[] */
146278146765
u16 nSkip; /* Number of NULL aLTerm[] entries */
@@ -146425,10 +146912,11 @@
146425146912
#ifdef SQLITE_ENABLE_STAT4
146426146913
# define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
146427146914
#else
146428146915
# define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
146429146916
#endif
146917
+#define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
146430146918
146431146919
/*
146432146920
** An instance of the WhereScan object is used as an iterator for locating
146433146921
** terms in the WHERE clause that are useful to the query planner.
146434146922
*/
@@ -146528,11 +147016,10 @@
146528147016
** to construct WhereLoop objects for a particular query.
146529147017
*/
146530147018
struct WhereLoopBuilder {
146531147019
WhereInfo *pWInfo; /* Information about this WHERE */
146532147020
WhereClause *pWC; /* WHERE clause terms */
146533
- ExprList *pOrderBy; /* ORDER BY clause */
146534147021
WhereLoop *pNew; /* Template WhereLoop */
146535147022
WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
146536147023
#ifdef SQLITE_ENABLE_STAT4
146537147024
UnpackedRecord *pRec; /* Probe for stat4 (if required) */
146538147025
int nRecValid; /* Number of valid fields currently in pRec */
@@ -146596,10 +147083,13 @@
146596147083
Parse *pParse; /* Parsing and code generating context */
146597147084
SrcList *pTabList; /* List of tables in the join */
146598147085
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
146599147086
ExprList *pResultSet; /* Result set of the query */
146600147087
Expr *pWhere; /* The complete WHERE clause */
147088
+#ifndef SQLITE_OMIT_VIRTUALTABLE
147089
+ Select *pLimit; /* Used to access LIMIT expr/registers for vtabs */
147090
+#endif
146601147091
int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
146602147092
int iContinue; /* Jump here to continue with next record */
146603147093
int iBreak; /* Jump here to break out of the loop */
146604147094
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
146605147095
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -146681,10 +147171,11 @@
146681147171
146682147172
/* whereexpr.c: */
146683147173
SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
146684147174
SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
146685147175
SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
147176
+SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause*, Select*);
146686147177
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
146687147178
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
146688147179
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
146689147180
SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
146690147181
SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
@@ -146751,10 +147242,11 @@
146751147242
#define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
146752147243
#define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
146753147244
#define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
146754147245
#define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
146755147246
#define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
147247
+#define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
146756147248
146757147249
#endif /* !defined(SQLITE_WHEREINT_H) */
146758147250
146759147251
/************** End of whereInt.h ********************************************/
146760147252
/************** Continuing where we left off in wherecode.c ******************/
@@ -147561,10 +148053,13 @@
147561148053
regBase = r1;
147562148054
}else{
147563148055
sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
147564148056
}
147565148057
}
148058
+ }
148059
+ for(j=nSkip; j<nEq; j++){
148060
+ pTerm = pLoop->aLTerm[j];
147566148061
if( pTerm->eOperator & WO_IN ){
147567148062
if( pTerm->pExpr->flags & EP_xIsSelect ){
147568148063
/* No affinity ever needs to be (or should be) applied to a value
147569148064
** from the RHS of an "? IN (SELECT ...)" expression. The
147570148065
** sqlite3FindInIndex() routine has already ensured that the
@@ -147575,11 +148070,12 @@
147575148070
Expr *pRight = pTerm->pExpr->pRight;
147576148071
if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
147577148072
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
147578148073
VdbeCoverage(v);
147579148074
}
147580
- if( pParse->db->mallocFailed==0 && pParse->nErr==0 ){
148075
+ if( pParse->nErr==0 ){
148076
+ assert( pParse->db->mallocFailed==0 );
147581148077
if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
147582148078
zAff[j] = SQLITE_AFF_BLOB;
147583148079
}
147584148080
if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
147585148081
zAff[j] = SQLITE_AFF_BLOB;
@@ -148265,15 +148761,31 @@
148265148761
for(j=0; j<nConstraint; j++){
148266148762
int iTarget = iReg+j+2;
148267148763
pTerm = pLoop->aLTerm[j];
148268148764
if( NEVER(pTerm==0) ) continue;
148269148765
if( pTerm->eOperator & WO_IN ){
148270
- codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148271
- addrNotFound = pLevel->addrNxt;
148766
+ if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
148767
+ int iTab = pParse->nTab++;
148768
+ int iCache = ++pParse->nMem;
148769
+ sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab);
148770
+ sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
148771
+ }else{
148772
+ codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148773
+ addrNotFound = pLevel->addrNxt;
148774
+ }
148272148775
}else{
148273148776
Expr *pRight = pTerm->pExpr->pRight;
148274148777
codeExprOrVector(pParse, pRight, iTarget, 1);
148778
+ if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET
148779
+ && pLoop->u.vtab.bOmitOffset
148780
+ ){
148781
+ assert( pTerm->eOperator==WO_AUX );
148782
+ assert( pWInfo->pLimit!=0 );
148783
+ assert( pWInfo->pLimit->iOffset>0 );
148784
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pLimit->iOffset);
148785
+ VdbeComment((v,"Zero OFFSET counter"));
148786
+ }
148275148787
}
148276148788
}
148277148789
sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
148278148790
sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
148279148791
sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
@@ -148292,17 +148804,23 @@
148292148804
iIn = pLevel->u.in.nIn;
148293148805
}else{
148294148806
iIn = 0;
148295148807
}
148296148808
for(j=nConstraint-1; j>=0; j--){
148809
+ int bIn; /* True to generate byte code to loop over RHS IN values */
148297148810
pTerm = pLoop->aLTerm[j];
148298
- if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
148811
+ if( (pTerm->eOperator & WO_IN)!=0
148812
+ && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
148813
+ ){
148814
+ bIn = 1;
148815
+ }else{
148816
+ bIn = 0;
148817
+ }
148818
+ if( bIn ) iIn--;
148299148819
if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
148300148820
disableTerm(pLevel, pTerm);
148301
- }else if( (pTerm->eOperator & WO_IN)!=0
148302
- && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1
148303
- ){
148821
+ }else if( bIn && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){
148304148822
Expr *pCompare; /* The comparison operator */
148305148823
Expr *pRight; /* RHS of the comparison */
148306148824
VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
148307148825
148308148826
/* Reload the constraint value into reg[iReg+j+2]. The same value
@@ -149028,11 +149546,11 @@
149028149546
regRowid = ++pParse->nMem;
149029149547
}
149030149548
iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
149031149549
149032149550
/* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
149033
- ** Then for every term xN, evaluate as the subexpression: xN AND z
149551
+ ** Then for every term xN, evaluate as the subexpression: xN AND y
149034149552
** That way, terms in y that are factored into the disjunction will
149035149553
** be picked up by the recursive calls to sqlite3WhereBegin() below.
149036149554
**
149037149555
** Actually, each subexpression is converted to "xN AND w" where w is
149038149556
** the "interesting" terms of z - terms that did not originate in the
@@ -149040,19 +149558,28 @@
149040149558
** indices.
149041149559
**
149042149560
** This optimization also only applies if the (x1 OR x2 OR ...) term
149043149561
** is not contained in the ON clause of a LEFT JOIN.
149044149562
** See ticket http://www.sqlite.org/src/info/f2369304e4
149563
+ **
149564
+ ** 2022-02-04: Do not push down slices of a row-value comparison.
149565
+ ** In other words, "w" or "y" may not be a slice of a vector. Otherwise,
149566
+ ** the initialization of the right-hand operand of the vector comparison
149567
+ ** might not occur, or might occur only in an OR branch that is not
149568
+ ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
149045149569
*/
149046149570
if( pWC->nTerm>1 ){
149047149571
int iTerm;
149048149572
for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
149049149573
Expr *pExpr = pWC->a[iTerm].pExpr;
149050149574
if( &pWC->a[iTerm] == pTerm ) continue;
149051149575
testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
149052149576
testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
149053
- if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
149577
+ testcase( pWC->a[iTerm].wtFlags & TERM_SLICE );
149578
+ if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
149579
+ continue;
149580
+ }
149054149581
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
149055149582
testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
149056149583
pExpr = sqlite3ExprDup(db, pExpr, 0);
149057149584
pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
149058149585
}
@@ -149091,13 +149618,13 @@
149091149618
pOrExpr = pAndExpr;
149092149619
}
149093149620
/* Loop through table entries that match term pOrTerm. */
149094149621
ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
149095149622
WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
149096
- pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
149623
+ pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0,
149097149624
WHERE_OR_SUBCLAUSE, iCovCur);
149098
- assert( pSubWInfo || pParse->nErr || db->mallocFailed );
149625
+ assert( pSubWInfo || pParse->nErr );
149099149626
if( pSubWInfo ){
149100149627
WhereLoop *pSubLoop;
149101149628
int addrExplain = sqlite3WhereExplainOneScan(
149102149629
pParse, pOrTab, &pSubWInfo->a[0], 0
149103149630
);
@@ -149831,11 +150358,11 @@
149831150358
void *pNotUsed;
149832150359
pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
149833150360
assert( pVtab!=0 );
149834150361
assert( pVtab->pModule!=0 );
149835150362
assert( !ExprHasProperty(pExpr, EP_IntValue) );
149836
- pMod = (sqlite3_module *)pVtab->pModule;
150363
+ pMod = (sqlite3_module *)pVtab->pModule;
149837150364
if( pMod->xFindFunction!=0 ){
149838150365
i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
149839150366
if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
149840150367
*peOp2 = i;
149841150368
*ppRight = pList->a[1].pExpr;
@@ -150788,11 +151315,14 @@
150788151315
** new terms for each component comparison - "a = ?" and "b = ?". The
150789151316
** new terms completely replace the original vector comparison, which is
150790151317
** no longer used.
150791151318
**
150792151319
** This is only required if at least one side of the comparison operation
150793
- ** is not a sub-select. */
151320
+ ** is not a sub-select.
151321
+ **
151322
+ ** tag-20220128a
151323
+ */
150794151324
if( (pExpr->op==TK_EQ || pExpr->op==TK_IS)
150795151325
&& (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1
150796151326
&& sqlite3ExprVectorSize(pExpr->pRight)==nLeft
150797151327
&& ( (pExpr->pLeft->flags & EP_xIsSelect)==0
150798151328
|| (pExpr->pRight->flags & EP_xIsSelect)==0)
@@ -150805,11 +151335,11 @@
150805151335
Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft);
150806151336
Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft);
150807151337
150808151338
pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
150809151339
transferJoinMarkings(pNew, pExpr);
150810
- idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
151340
+ idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
150811151341
exprAnalyze(pSrc, pWC, idxNew);
150812151342
}
150813151343
pTerm = &pWC->a[idxTerm];
150814151344
pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
150815151345
pTerm->eOperator = 0;
@@ -150930,10 +151460,117 @@
150930151460
}else{
150931151461
sqlite3WhereSplit(pWC, pE2->pLeft, op);
150932151462
sqlite3WhereSplit(pWC, pE2->pRight, op);
150933151463
}
150934151464
}
151465
+
151466
+/*
151467
+** Add either a LIMIT (if eMatchOp==SQLITE_INDEX_CONSTRAINT_LIMIT) or
151468
+** OFFSET (if eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET) term to the
151469
+** where-clause passed as the first argument. The value for the term
151470
+** is found in register iReg.
151471
+**
151472
+** In the common case where the value is a simple integer
151473
+** (example: "LIMIT 5 OFFSET 10") then the expression codes as a
151474
+** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value().
151475
+** If not, then it codes as a TK_REGISTER expression.
151476
+*/
151477
+void whereAddLimitExpr(
151478
+ WhereClause *pWC, /* Add the constraint to this WHERE clause */
151479
+ int iReg, /* Register that will hold value of the limit/offset */
151480
+ Expr *pExpr, /* Expression that defines the limit/offset */
151481
+ int iCsr, /* Cursor to which the constraint applies */
151482
+ int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */
151483
+){
151484
+ Parse *pParse = pWC->pWInfo->pParse;
151485
+ sqlite3 *db = pParse->db;
151486
+ Expr *pNew;
151487
+ int iVal = 0;
151488
+
151489
+ if( sqlite3ExprIsInteger(pExpr, &iVal) && iVal>=0 ){
151490
+ Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0);
151491
+ if( pVal==0 ) return;
151492
+ ExprSetProperty(pVal, EP_IntValue);
151493
+ pVal->u.iValue = iVal;
151494
+ pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
151495
+ }else{
151496
+ Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0);
151497
+ if( pVal==0 ) return;
151498
+ pVal->iTable = iReg;
151499
+ pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
151500
+ }
151501
+ if( pNew ){
151502
+ WhereTerm *pTerm;
151503
+ int idx;
151504
+ idx = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_VIRTUAL);
151505
+ pTerm = &pWC->a[idx];
151506
+ pTerm->leftCursor = iCsr;
151507
+ pTerm->eOperator = WO_AUX;
151508
+ pTerm->eMatchOp = eMatchOp;
151509
+ }
151510
+}
151511
+
151512
+/*
151513
+** Possibly add terms corresponding to the LIMIT and OFFSET clauses of the
151514
+** SELECT statement passed as the second argument. These terms are only
151515
+** added if:
151516
+**
151517
+** 1. The SELECT statement has a LIMIT clause, and
151518
+** 2. The SELECT statement is not an aggregate or DISTINCT query, and
151519
+** 3. The SELECT statement has exactly one object in its from clause, and
151520
+** that object is a virtual table, and
151521
+** 4. There are no terms in the WHERE clause that will not be passed
151522
+** to the virtual table xBestIndex method.
151523
+** 5. The ORDER BY clause, if any, will be made available to the xBestIndex
151524
+** method.
151525
+**
151526
+** LIMIT and OFFSET terms are ignored by most of the planner code. They
151527
+** exist only so that they may be passed to the xBestIndex method of the
151528
+** single virtual table in the FROM clause of the SELECT.
151529
+*/
151530
+SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){
151531
+ assert( p==0 || (p->pGroupBy==0 && (p->selFlags & SF_Aggregate)==0) );
151532
+ if( (p && p->pLimit) /* 1 */
151533
+ && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */
151534
+ && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */
151535
+ ){
151536
+ ExprList *pOrderBy = p->pOrderBy;
151537
+ int iCsr = p->pSrc->a[0].iCursor;
151538
+ int ii;
151539
+
151540
+ /* Check condition (4). Return early if it is not met. */
151541
+ for(ii=0; ii<pWC->nTerm; ii++){
151542
+ if( pWC->a[ii].wtFlags & TERM_CODED ){
151543
+ /* This term is a vector operation that has been decomposed into
151544
+ ** other, subsequent terms. It can be ignored. See tag-20220128a */
151545
+ assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
151546
+ assert( pWC->a[ii].eOperator==0 );
151547
+ continue;
151548
+ }
151549
+ if( pWC->a[ii].leftCursor!=iCsr ) return;
151550
+ }
151551
+
151552
+ /* Check condition (5). Return early if it is not met. */
151553
+ if( pOrderBy ){
151554
+ for(ii=0; ii<pOrderBy->nExpr; ii++){
151555
+ Expr *pExpr = pOrderBy->a[ii].pExpr;
151556
+ if( pExpr->op!=TK_COLUMN ) return;
151557
+ if( pExpr->iTable!=iCsr ) return;
151558
+ if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
151559
+ }
151560
+ }
151561
+
151562
+ /* All conditions are met. Add the terms to the where-clause object. */
151563
+ assert( p->pLimit->op==TK_LIMIT );
151564
+ whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft,
151565
+ iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT);
151566
+ if( p->iOffset>0 ){
151567
+ whereAddLimitExpr(pWC, p->iOffset, p->pLimit->pRight,
151568
+ iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET);
151569
+ }
151570
+ }
151571
+}
150935151572
150936151573
/*
150937151574
** Initialize a preallocated WhereClause structure.
150938151575
*/
150939151576
SQLITE_PRIVATE void sqlite3WhereClauseInit(
@@ -150966,10 +151603,11 @@
150966151603
for(i=pWC->nBase; i<pWC->nTerm; i++){
150967151604
assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 );
150968151605
}
150969151606
#endif
150970151607
while(1){
151608
+ assert( a->eMatchOp==0 || a->eOperator==WO_AUX );
150971151609
if( a->wtFlags & TERM_DYNAMIC ){
150972151610
sqlite3ExprDelete(db, a->pExpr);
150973151611
}
150974151612
if( a->wtFlags & (TERM_ORINFO|TERM_ANDINFO) ){
150975151613
if( a->wtFlags & TERM_ORINFO ){
@@ -151123,10 +151761,11 @@
151123151761
if( pColRef==0 ) return;
151124151762
pColRef->iTable = pItem->iCursor;
151125151763
pColRef->iColumn = k++;
151126151764
assert( ExprUseYTab(pColRef) );
151127151765
pColRef->y.pTab = pTab;
151766
+ pItem->colUsed |= sqlite3ExprColUsed(pColRef);
151128151767
pRhs = sqlite3PExpr(pParse, TK_UPLUS,
151129151768
sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
151130151769
pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
151131151770
if( pItem->fg.jointype & JT_LEFT ){
151132151771
sqlite3SetJoinExpr(pTerm, pItem->iCursor);
@@ -151167,12 +151806,18 @@
151167151806
** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
151168151807
** agree on the structure, all will be well.
151169151808
*/
151170151809
typedef struct HiddenIndexInfo HiddenIndexInfo;
151171151810
struct HiddenIndexInfo {
151172
- WhereClause *pWC; /* The Where clause being analyzed */
151173
- Parse *pParse; /* The parsing context */
151811
+ WhereClause *pWC; /* The Where clause being analyzed */
151812
+ Parse *pParse; /* The parsing context */
151813
+ int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
151814
+ u32 mIn; /* Mask of terms that are <col> IN (...) */
151815
+ u32 mHandleIn; /* Terms that vtab will handle as <col> IN (...) */
151816
+ sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151817
+ ** because extra space is allocated to hold up
151818
+ ** to nTerm such values */
151174151819
};
151175151820
151176151821
/* Forward declaration of methods */
151177151822
static int whereLoopResize(sqlite3*, WhereLoop*, int);
151178151823
@@ -152232,31 +152877,33 @@
152232152877
152233152878
#ifndef SQLITE_OMIT_VIRTUALTABLE
152234152879
/*
152235152880
** Allocate and populate an sqlite3_index_info structure. It is the
152236152881
** responsibility of the caller to eventually release the structure
152237
-** by passing the pointer returned by this function to sqlite3_free().
152882
+** by passing the pointer returned by this function to freeIndexInfo().
152238152883
*/
152239152884
static sqlite3_index_info *allocateIndexInfo(
152240
- Parse *pParse, /* The parsing context */
152885
+ WhereInfo *pWInfo, /* The WHERE clause */
152241152886
WhereClause *pWC, /* The WHERE clause being analyzed */
152242152887
Bitmask mUnusable, /* Ignore terms with these prereqs */
152243152888
SrcItem *pSrc, /* The FROM clause term that is the vtab */
152244
- ExprList *pOrderBy, /* The ORDER BY clause */
152245152889
u16 *pmNoOmit /* Mask of terms not to omit */
152246152890
){
152247152891
int i, j;
152248152892
int nTerm;
152893
+ Parse *pParse = pWInfo->pParse;
152249152894
struct sqlite3_index_constraint *pIdxCons;
152250152895
struct sqlite3_index_orderby *pIdxOrderBy;
152251152896
struct sqlite3_index_constraint_usage *pUsage;
152252152897
struct HiddenIndexInfo *pHidden;
152253152898
WhereTerm *pTerm;
152254152899
int nOrderBy;
152255152900
sqlite3_index_info *pIdxInfo;
152256152901
u16 mNoOmit = 0;
152257152902
const Table *pTab;
152903
+ int eDistinct = 0;
152904
+ ExprList *pOrderBy = pWInfo->pOrderBy;
152258152905
152259152906
assert( pSrc!=0 );
152260152907
pTab = pSrc->pTab;
152261152908
assert( pTab!=0 );
152262152909
assert( IsVirtual(pTab) );
@@ -152274,10 +152921,11 @@
152274152921
testcase( pTerm->eOperator & WO_ISNULL );
152275152922
testcase( pTerm->eOperator & WO_IS );
152276152923
testcase( pTerm->eOperator & WO_ALL );
152277152924
if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
152278152925
if( pTerm->wtFlags & TERM_VNULL ) continue;
152926
+
152279152927
assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152280152928
assert( pTerm->u.x.leftColumn>=XN_ROWID );
152281152929
assert( pTerm->u.x.leftColumn<pTab->nCol );
152282152930
152283152931
/* tag-20191211-002: WHERE-clause constraints are not useful to the
@@ -152335,40 +152983,49 @@
152335152983
}
152336152984
152337152985
/* No matches cause a break out of the loop */
152338152986
break;
152339152987
}
152340
- if( i==n){
152988
+ if( i==n ){
152341152989
nOrderBy = n;
152990
+ if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152991
+ eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152992
+ }
152342152993
}
152343152994
}
152344152995
152345152996
/* Allocate the sqlite3_index_info structure
152346152997
*/
152347152998
pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
152348152999
+ (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
152349
- + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
153000
+ + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden)
153001
+ + sizeof(sqlite3_value*)*nTerm );
152350153002
if( pIdxInfo==0 ){
152351153003
sqlite3ErrorMsg(pParse, "out of memory");
152352153004
return 0;
152353153005
}
152354153006
pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
152355
- pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
153007
+ pIdxCons = (struct sqlite3_index_constraint*)&pHidden->aRhs[nTerm];
152356153008
pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
152357153009
pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
152358153010
pIdxInfo->aConstraint = pIdxCons;
152359153011
pIdxInfo->aOrderBy = pIdxOrderBy;
152360153012
pIdxInfo->aConstraintUsage = pUsage;
152361153013
pHidden->pWC = pWC;
152362153014
pHidden->pParse = pParse;
153015
+ pHidden->eDistinct = eDistinct;
153016
+ pHidden->mIn = 0;
152363153017
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152364153018
u16 op;
152365153019
if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152366153020
pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152367153021
pIdxCons[j].iTermOffset = i;
152368153022
op = pTerm->eOperator & WO_ALL;
152369
- if( op==WO_IN ) op = WO_EQ;
153023
+ if( op==WO_IN ){
153024
+ pHidden->mIn |= SMASKBIT32(j);
153025
+ op = WO_EQ;
153026
+ }
152370153027
if( op==WO_AUX ){
152371153028
pIdxCons[j].op = pTerm->eMatchOp;
152372153029
}else if( op & (WO_ISNULL|WO_IS) ){
152373153030
if( op==WO_ISNULL ){
152374153031
pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
@@ -152414,10 +153071,28 @@
152414153071
pIdxInfo->nOrderBy = j;
152415153072
152416153073
*pmNoOmit = mNoOmit;
152417153074
return pIdxInfo;
152418153075
}
153076
+
153077
+/*
153078
+** Free an sqlite3_index_info structure allocated by allocateIndexInfo()
153079
+** and possibly modified by xBestIndex methods.
153080
+*/
153081
+static void freeIndexInfo(sqlite3 *db, sqlite3_index_info *pIdxInfo){
153082
+ HiddenIndexInfo *pHidden;
153083
+ int i;
153084
+ assert( pIdxInfo!=0 );
153085
+ pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
153086
+ assert( pHidden->pParse!=0 );
153087
+ assert( pHidden->pParse->db==db );
153088
+ for(i=0; i<pIdxInfo->nConstraint; i++){
153089
+ sqlite3ValueFree(pHidden->aRhs[i]); /* IMP: R-14553-25174 */
153090
+ pHidden->aRhs[i] = 0;
153091
+ }
153092
+ sqlite3DbFree(db, pIdxInfo);
153093
+}
152419153094
152420153095
/*
152421153096
** The table object reference passed as the second argument to this function
152422153097
** must represent a virtual table. This function invokes the xBestIndex()
152423153098
** method of the virtual table with the sqlite3_index_info object that
@@ -152436,11 +153111,13 @@
152436153111
static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
152437153112
sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
152438153113
int rc;
152439153114
152440153115
whereTraceIndexInfoInputs(p);
153116
+ pParse->db->nSchemaLock++;
152441153117
rc = pVtab->pModule->xBestIndex(pVtab, p);
153118
+ pParse->db->nSchemaLock--;
152442153119
whereTraceIndexInfoOutputs(p);
152443153120
152444153121
if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
152445153122
if( rc==SQLITE_NOMEM ){
152446153123
sqlite3OomFault(pParse->db);
@@ -154566,10 +155243,19 @@
154566155243
}
154567155244
return rc;
154568155245
}
154569155246
154570155247
#ifndef SQLITE_OMIT_VIRTUALTABLE
155248
+
155249
+/*
155250
+** Return true if pTerm is a virtual table LIMIT or OFFSET term.
155251
+*/
155252
+static int isLimitTerm(WhereTerm *pTerm){
155253
+ assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 );
155254
+ return pTerm->eMatchOp>=SQLITE_INDEX_CONSTRAINT_LIMIT
155255
+ && pTerm->eMatchOp<=SQLITE_INDEX_CONSTRAINT_OFFSET;
155256
+}
154571155257
154572155258
/*
154573155259
** Argument pIdxInfo is already populated with all constraints that may
154574155260
** be used by the virtual table identified by pBuilder->pNew->iTab. This
154575155261
** function marks a subset of those constraints usable, invokes the
@@ -154594,13 +155280,15 @@
154594155280
Bitmask mPrereq, /* Mask of tables that must be used. */
154595155281
Bitmask mUsable, /* Mask of usable tables */
154596155282
u16 mExclude, /* Exclude terms using these operators */
154597155283
sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */
154598155284
u16 mNoOmit, /* Do not omit these constraints */
154599
- int *pbIn /* OUT: True if plan uses an IN(...) op */
155285
+ int *pbIn, /* OUT: True if plan uses an IN(...) op */
155286
+ int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */
154600155287
){
154601155288
WhereClause *pWC = pBuilder->pWC;
155289
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
154602155290
struct sqlite3_index_constraint *pIdxCons;
154603155291
struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
154604155292
int i;
154605155293
int mxTerm;
154606155294
int rc = SQLITE_OK;
@@ -154619,10 +155307,11 @@
154619155307
for(i=0; i<nConstraint; i++, pIdxCons++){
154620155308
WhereTerm *pTerm = &pWC->a[pIdxCons->iTermOffset];
154621155309
pIdxCons->usable = 0;
154622155310
if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight
154623155311
&& (pTerm->eOperator & mExclude)==0
155312
+ && (pbRetryLimit || !isLimitTerm(pTerm))
154624155313
){
154625155314
pIdxCons->usable = 1;
154626155315
}
154627155316
}
154628155317
@@ -154634,10 +155323,11 @@
154634155323
pIdxInfo->orderByConsumed = 0;
154635155324
pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
154636155325
pIdxInfo->estimatedRows = 25;
154637155326
pIdxInfo->idxFlags = 0;
154638155327
pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
155328
+ pHidden->mHandleIn = 0;
154639155329
154640155330
/* Invoke the virtual table xBestIndex() method */
154641155331
rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
154642155332
if( rc ){
154643155333
if( rc==SQLITE_CONSTRAINT ){
@@ -154651,12 +155341,12 @@
154651155341
return rc;
154652155342
}
154653155343
154654155344
mxTerm = -1;
154655155345
assert( pNew->nLSlot>=nConstraint );
154656
- for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
154657
- pNew->u.vtab.omitMask = 0;
155346
+ memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint );
155347
+ memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab));
154658155348
pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
154659155349
for(i=0; i<nConstraint; i++, pIdxCons++){
154660155350
int iTerm;
154661155351
if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
154662155352
WhereTerm *pTerm;
@@ -154686,21 +155376,41 @@
154686155376
testcase( i!=iTerm );
154687155377
pNew->u.vtab.omitMask |= 1<<iTerm;
154688155378
}else{
154689155379
testcase( i!=iTerm );
154690155380
}
155381
+ if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){
155382
+ pNew->u.vtab.bOmitOffset = 1;
155383
+ }
154691155384
}
154692
- if( (pTerm->eOperator & WO_IN)!=0 ){
155385
+ if( SMASKBIT32(i) & pHidden->mHandleIn ){
155386
+ pNew->u.vtab.mHandleIn |= MASKBIT32(iTerm);
155387
+ }else if( (pTerm->eOperator & WO_IN)!=0 ){
154693155388
/* A virtual table that is constrained by an IN clause may not
154694155389
** consume the ORDER BY clause because (1) the order of IN terms
154695155390
** is not necessarily related to the order of output terms and
154696155391
** (2) Multiple outputs from a single IN value will not merge
154697155392
** together. */
154698155393
pIdxInfo->orderByConsumed = 0;
154699155394
pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
154700155395
*pbIn = 1; assert( (mExclude & WO_IN)==0 );
154701155396
}
155397
+
155398
+ if( isLimitTerm(pTerm) && *pbIn ){
155399
+ /* If there is an IN(...) term handled as an == (separate call to
155400
+ ** xFilter for each value on the RHS of the IN) and a LIMIT or
155401
+ ** OFFSET term handled as well, the plan is unusable. Set output
155402
+ ** variable *pbRetryLimit to true to tell the caller to retry with
155403
+ ** LIMIT and OFFSET disabled. */
155404
+ if( pIdxInfo->needToFreeIdxStr ){
155405
+ sqlite3_free(pIdxInfo->idxStr);
155406
+ pIdxInfo->idxStr = 0;
155407
+ pIdxInfo->needToFreeIdxStr = 0;
155408
+ }
155409
+ *pbRetryLimit = 1;
155410
+ return SQLITE_OK;
155411
+ }
154702155412
}
154703155413
}
154704155414
154705155415
pNew->nLTerm = mxTerm+1;
154706155416
for(i=0; i<=mxTerm; i++){
@@ -154769,10 +155479,77 @@
154769155479
}
154770155480
zRet = (pC ? pC->zName : sqlite3StrBINARY);
154771155481
}
154772155482
return zRet;
154773155483
}
155484
+
155485
+/*
155486
+** Return true if constraint iCons is really an IN(...) constraint, or
155487
+** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
155488
+** or clear (if bHandle==0) the flag to handle it using an iterator.
155489
+*/
155490
+SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *pIdxInfo, int iCons, int bHandle){
155491
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155492
+ u32 m = SMASKBIT32(iCons);
155493
+ if( m & pHidden->mIn ){
155494
+ if( bHandle==0 ){
155495
+ pHidden->mHandleIn &= ~m;
155496
+ }else if( bHandle>0 ){
155497
+ pHidden->mHandleIn |= m;
155498
+ }
155499
+ return 1;
155500
+ }
155501
+ return 0;
155502
+}
155503
+
155504
+/*
155505
+** This interface is callable from within the xBestIndex callback only.
155506
+**
155507
+** If possible, set (*ppVal) to point to an object containing the value
155508
+** on the right-hand-side of constraint iCons.
155509
+*/
155510
+SQLITE_API int sqlite3_vtab_rhs_value(
155511
+ sqlite3_index_info *pIdxInfo, /* Copy of first argument to xBestIndex */
155512
+ int iCons, /* Constraint for which RHS is wanted */
155513
+ sqlite3_value **ppVal /* Write value extracted here */
155514
+){
155515
+ HiddenIndexInfo *pH = (HiddenIndexInfo*)&pIdxInfo[1];
155516
+ sqlite3_value *pVal = 0;
155517
+ int rc = SQLITE_OK;
155518
+ if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
155519
+ rc = SQLITE_MISUSE; /* EV: R-30545-25046 */
155520
+ }else{
155521
+ if( pH->aRhs[iCons]==0 ){
155522
+ WhereTerm *pTerm = &pH->pWC->a[pIdxInfo->aConstraint[iCons].iTermOffset];
155523
+ rc = sqlite3ValueFromExpr(
155524
+ pH->pParse->db, pTerm->pExpr->pRight, ENC(pH->pParse->db),
155525
+ SQLITE_AFF_BLOB, &pH->aRhs[iCons]
155526
+ );
155527
+ testcase( rc!=SQLITE_OK );
155528
+ }
155529
+ pVal = pH->aRhs[iCons];
155530
+ }
155531
+ *ppVal = pVal;
155532
+
155533
+ if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
155534
+ rc = SQLITE_NOTFOUND; /* IMP: R-36424-56542 */
155535
+ }
155536
+
155537
+ return rc;
155538
+}
155539
+
155540
+
155541
+/*
155542
+** Return true if ORDER BY clause may be handled as DISTINCT.
155543
+*/
155544
+SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155545
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155546
+ assert( pHidden->eDistinct==0
155547
+ || pHidden->eDistinct==1
155548
+ || pHidden->eDistinct==2 );
155549
+ return pHidden->eDistinct;
155550
+}
154774155551
154775155552
/*
154776155553
** Add all WhereLoop objects for a table of the join identified by
154777155554
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
154778155555
**
@@ -154811,35 +155588,43 @@
154811155588
int nConstraint; /* Number of constraints in p */
154812155589
int bIn; /* True if plan uses IN(...) operator */
154813155590
WhereLoop *pNew;
154814155591
Bitmask mBest; /* Tables used by best possible plan */
154815155592
u16 mNoOmit;
155593
+ int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */
154816155594
154817155595
assert( (mPrereq & mUnusable)==0 );
154818155596
pWInfo = pBuilder->pWInfo;
154819155597
pParse = pWInfo->pParse;
154820155598
pWC = pBuilder->pWC;
154821155599
pNew = pBuilder->pNew;
154822155600
pSrc = &pWInfo->pTabList->a[pNew->iTab];
154823155601
assert( IsVirtual(pSrc->pTab) );
154824
- p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy,
154825
- &mNoOmit);
155602
+ p = allocateIndexInfo(pWInfo, pWC, mUnusable, pSrc, &mNoOmit);
154826155603
if( p==0 ) return SQLITE_NOMEM_BKPT;
154827155604
pNew->rSetup = 0;
154828155605
pNew->wsFlags = WHERE_VIRTUALTABLE;
154829155606
pNew->nLTerm = 0;
154830155607
pNew->u.vtab.needFree = 0;
154831155608
nConstraint = p->nConstraint;
154832155609
if( whereLoopResize(pParse->db, pNew, nConstraint) ){
154833
- sqlite3DbFree(pParse->db, p);
155610
+ freeIndexInfo(pParse->db, p);
154834155611
return SQLITE_NOMEM_BKPT;
154835155612
}
154836155613
154837155614
/* First call xBestIndex() with all constraints usable. */
154838155615
WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
154839155616
WHERETRACE(0x40, (" VirtualOne: all usable\n"));
154840
- rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
155617
+ rc = whereLoopAddVirtualOne(
155618
+ pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry
155619
+ );
155620
+ if( bRetry ){
155621
+ assert( rc==SQLITE_OK );
155622
+ rc = whereLoopAddVirtualOne(
155623
+ pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0
155624
+ );
155625
+ }
154841155626
154842155627
/* If the call to xBestIndex() with all terms enabled produced a plan
154843155628
** that does not require any source tables (IOW: a plan with mBest==0)
154844155629
** and does not use an IN(...) operator, then there is no point in making
154845155630
** any further calls to xBestIndex() since they will all return the same
@@ -154853,11 +155638,11 @@
154853155638
/* If the plan produced by the earlier call uses an IN(...) term, call
154854155639
** xBestIndex again, this time with IN(...) terms disabled. */
154855155640
if( bIn ){
154856155641
WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n"));
154857155642
rc = whereLoopAddVirtualOne(
154858
- pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn);
155643
+ pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0);
154859155644
assert( bIn==0 );
154860155645
mBestNoIn = pNew->prereq & ~mPrereq;
154861155646
if( mBestNoIn==0 ){
154862155647
seenZero = 1;
154863155648
seenZeroNoIN = 1;
@@ -154880,11 +155665,11 @@
154880155665
if( mNext==ALLBITS ) break;
154881155666
if( mNext==mBest || mNext==mBestNoIn ) continue;
154882155667
WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
154883155668
(sqlite3_uint64)mPrev, (sqlite3_uint64)mNext));
154884155669
rc = whereLoopAddVirtualOne(
154885
- pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn);
155670
+ pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0);
154886155671
if( pNew->prereq==mPrereq ){
154887155672
seenZero = 1;
154888155673
if( bIn==0 ) seenZeroNoIN = 1;
154889155674
}
154890155675
}
@@ -154893,26 +155678,26 @@
154893155678
** that requires no source tables at all (i.e. one guaranteed to be
154894155679
** usable), make a call here with all source tables disabled */
154895155680
if( rc==SQLITE_OK && seenZero==0 ){
154896155681
WHERETRACE(0x40, (" VirtualOne: all disabled\n"));
154897155682
rc = whereLoopAddVirtualOne(
154898
- pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn);
155683
+ pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0);
154899155684
if( bIn==0 ) seenZeroNoIN = 1;
154900155685
}
154901155686
154902155687
/* If the calls to xBestIndex() have so far failed to find a plan
154903155688
** that requires no source tables at all and does not use an IN(...)
154904155689
** operator, make a final call to obtain one here. */
154905155690
if( rc==SQLITE_OK && seenZeroNoIN==0 ){
154906155691
WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n"));
154907155692
rc = whereLoopAddVirtualOne(
154908
- pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
155693
+ pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0);
154909155694
}
154910155695
}
154911155696
154912155697
if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
154913
- sqlite3DbFreeNN(pParse->db, p);
155698
+ freeIndexInfo(pParse->db, p);
154914155699
WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
154915155700
return rc;
154916155701
}
154917155702
#endif /* SQLITE_OMIT_VIRTUALTABLE */
154918155703
@@ -154952,11 +155737,10 @@
154952155737
WhereTerm *pOrTerm;
154953155738
int once = 1;
154954155739
int i, j;
154955155740
154956155741
sSubBuild = *pBuilder;
154957
- sSubBuild.pOrderBy = 0;
154958155742
sSubBuild.pOrSet = &sCur;
154959155743
154960155744
WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
154961155745
for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
154962155746
if( (pOrTerm->eOperator & WO_AND)!=0 ){
@@ -156310,10 +157094,11 @@
156310157094
Parse *pParse, /* The parser context */
156311157095
SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
156312157096
Expr *pWhere, /* The WHERE clause */
156313157097
ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
156314157098
ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */
157099
+ Select *pLimit, /* Use this LIMIT/OFFSET clause, if any */
156315157100
u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
156316157101
int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
156317157102
** If WHERE_USE_LIMIT, then the limit amount */
156318157103
){
156319157104
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
@@ -156344,11 +157129,10 @@
156344157129
memset(&sWLB, 0, sizeof(sWLB));
156345157130
156346157131
/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
156347157132
testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
156348157133
if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
156349
- sWLB.pOrderBy = pOrderBy;
156350157134
156351157135
/* The number of tables in the FROM clause is limited by the number of
156352157136
** bits in a Bitmask
156353157137
*/
156354157138
testcase( pTabList->nSrc==BMS );
@@ -156387,10 +157171,13 @@
156387157171
pWInfo->nLevel = nTabList;
156388157172
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
156389157173
pWInfo->wctrlFlags = wctrlFlags;
156390157174
pWInfo->iLimit = iAuxArg;
156391157175
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
157176
+#ifndef SQLITE_OMIT_VIRTUALTABLE
157177
+ pWInfo->pLimit = pLimit;
157178
+#endif
156392157179
memset(&pWInfo->nOBSat, 0,
156393157180
offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
156394157181
memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
156395157182
assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
156396157183
pMaskSet = &pWInfo->sMaskSet;
@@ -156455,10 +157242,11 @@
156455157242
#endif
156456157243
}
156457157244
156458157245
/* Analyze all of the subexpressions. */
156459157246
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
157247
+ sqlite3WhereAddLimit(&pWInfo->sWC, pLimit);
156460157248
if( db->mallocFailed ) goto whereBeginError;
156461157249
156462157250
/* Special case: WHERE terms that do not refer to any tables in the join
156463157251
** (constant expressions). Evaluate each such term, and jump over all the
156464157252
** generated code if the result is not true.
@@ -156554,13 +157342,14 @@
156554157342
}
156555157343
}
156556157344
if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
156557157345
pWInfo->revMask = ALLBITS;
156558157346
}
156559
- if( pParse->nErr || db->mallocFailed ){
157347
+ if( pParse->nErr ){
156560157348
goto whereBeginError;
156561157349
}
157350
+ assert( db->mallocFailed==0 );
156562157351
#ifdef WHERETRACE_ENABLED
156563157352
if( sqlite3WhereTrace ){
156564157353
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
156565157354
if( pWInfo->nOBSat>0 ){
156566157355
sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
@@ -156700,10 +157489,11 @@
156700157489
testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 );
156701157490
testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS );
156702157491
if( pWInfo->eOnePass==ONEPASS_OFF
156703157492
&& pTab->nCol<BMS
156704157493
&& (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
157494
+ && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0
156705157495
){
156706157496
/* If we know that only a prefix of the record will be used,
156707157497
** it is advantageous to reduce the "column count" field in
156708157498
** the P4 operand of the OP_OpenRead/Write opcode. */
156709157499
Bitmask b = pTabItem->colUsed;
@@ -158264,16 +159054,11 @@
158264159054
** there could still be references to that table embedded in the
158265159055
** result-set or ORDER BY clause of the SELECT statement p. */
158266159056
sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab);
158267159057
}
158268159058
158269
- if( rc ){
158270
- if( pParse->nErr==0 ){
158271
- assert( pParse->db->mallocFailed );
158272
- sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM);
158273
- }
158274
- }
159059
+ assert( rc==SQLITE_OK || pParse->nErr!=0 );
158275159060
return rc;
158276159061
}
158277159062
158278159063
/*
158279159064
** Unlink the Window object from the Select to which it is attached,
@@ -193955,12 +194740,12 @@
193955194740
sqlite3_result_error_nomem(ctx);
193956194741
goto jsonSetDone;
193957194742
}else if( x.nErr ){
193958194743
goto jsonSetDone;
193959194744
}else if( pNode && (bApnd || bIsSet) ){
193960
- testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
193961
- assert( pNode->eU!=3 || pNode->eU!=5 );
194745
+ testcase( pNode->eU!=0 && pNode->eU!=1 );
194746
+ assert( pNode->eU!=3 && pNode->eU!=5 );
193962194747
VVA( pNode->eU = 4 );
193963194748
pNode->jnFlags |= (u8)JNODE_REPLACE;
193964194749
pNode->u.iReplace = i + 1;
193965194750
}
193966194751
}
@@ -194737,11 +195522,11 @@
194737195522
sqlite3_module *pModule;
194738195523
} aMod[] = {
194739195524
{ "json_each", &jsonEachModule },
194740195525
{ "json_tree", &jsonTreeModule },
194741195526
};
194742
- int i;
195527
+ unsigned int i;
194743195528
for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
194744195529
rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
194745195530
}
194746195531
return rc;
194747195532
}
@@ -233334,11 +234119,11 @@
233334234119
int nArg, /* Number of args */
233335234120
sqlite3_value **apUnused /* Function arguments */
233336234121
){
233337234122
assert( nArg==0 );
233338234123
UNUSED_PARAM2(nArg, apUnused);
233339
- sqlite3_result_text(pCtx, "fts5: 2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec", -1, SQLITE_TRANSIENT);
234124
+ sqlite3_result_text(pCtx, "fts5: 2022-01-25 16:28:57 6e4154d414afe2562b488149b10c175d1f15bd1d5060ee479d5ae9386a2e277e", -1, SQLITE_TRANSIENT);
233340234125
}
233341234126
233342234127
/*
233343234128
** Return true if zName is the extension on one of the shadow tables used
233344234129
** by this module.
233345234130
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -4656,10 +4656,12 @@
4656 ** still make the distinction between protected and unprotected
4657 ** sqlite3_value objects even when not strictly required.
4658 **
4659 ** ^The sqlite3_value objects that are passed as parameters into the
4660 ** implementation of [application-defined SQL functions] are protected.
 
 
4661 ** ^The sqlite3_value object returned by
4662 ** [sqlite3_column_value()] is unprotected.
4663 ** Unprotected sqlite3_value objects may only be used as arguments
4664 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4665 ** [sqlite3_value_dup()].
@@ -7435,28 +7437,60 @@
7435 /*
7436 ** CAPI3REF: Virtual Table Constraint Operator Codes
7437 **
7438 ** These macros define the allowed values for the
7439 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7440 ** an operator that is part of a constraint term in the wHERE clause of
7441 ** a query that uses a [virtual table].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7442 */
7443 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7444 #define SQLITE_INDEX_CONSTRAINT_GT 4
7445 #define SQLITE_INDEX_CONSTRAINT_LE 8
7446 #define SQLITE_INDEX_CONSTRAINT_LT 16
7447 #define SQLITE_INDEX_CONSTRAINT_GE 32
7448 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
7449 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
7450 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
7451 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7452 #define SQLITE_INDEX_CONSTRAINT_NE 68
7453 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7454 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7455 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7456 #define SQLITE_INDEX_CONSTRAINT_IS 72
7457 #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
 
 
7458
7459 /*
7460 ** CAPI3REF: Register A Virtual Table Implementation
7461 ** METHOD: sqlite3
7462 **
@@ -9775,25 +9809,26 @@
9775 */
9776 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9777
9778 /*
9779 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
 
9780 **
9781 ** This function may only be called from within a call to the [xBestIndex]
9782 ** method of a [virtual table]. This function returns a pointer to a string
9783 ** that is the name of the appropriate collation sequence to use for text
9784 ** comparisons on the constraint identified by its arguments.
9785 **
9786 ** The first argument must be the pointer to the sqlite3_index_info object
9787 ** that is the first parameter to the xBestIndex() method. The second argument
9788 ** must be an index into the aConstraint[] array belonging to the
9789 ** sqlite3_index_info structure passed to xBestIndex.
9790 **
9791 ** Important:
9792 ** The first parameter must be the same pointer that is passed into the
9793 ** xBestMethod() method. The first parameter may not be a pointer to a
9794 ** different sqlite3_index_info object, even an exact copy.
9795 **
9796 ** The return value is computed as follows:
9797 **
9798 ** <ol>
9799 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9807,10 +9842,240 @@
9807 ** <li><p> Otherwise, "BINARY" is returned.
9808 ** </ol>
9809 */
9810 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9812 /*
9813 ** CAPI3REF: Conflict resolution modes
9814 ** KEYWORDS: {conflict resolution mode}
9815 **
9816 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -14374,14 +14639,15 @@
14374 #define BMS ((int)(sizeof(Bitmask)*8))
14375
14376 /*
14377 ** A bit in a Bitmask
14378 */
14379 #define MASKBIT(n) (((Bitmask)1)<<(n))
14380 #define MASKBIT64(n) (((u64)1)<<(n))
14381 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14382 #define ALLBITS ((Bitmask)-1)
 
14383
14384 /* A VList object records a mapping between parameters/variables/wildcards
14385 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
14386 ** variable number associated with that parameter. See the format description
14387 ** on the sqlite3VListAdd() routine for more information. A VList is really
@@ -15403,21 +15669,22 @@
15403 #define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
15404 #define OP_VBegin 169
15405 #define OP_VCreate 170
15406 #define OP_VDestroy 171
15407 #define OP_VOpen 172
15408 #define OP_VColumn 173 /* synopsis: r[P3]=vcolumn(P2) */
15409 #define OP_VRename 174
15410 #define OP_Pagecount 175
15411 #define OP_MaxPgcnt 176
15412 #define OP_FilterAdd 177 /* synopsis: filter(P1) += key(P3@P4) */
15413 #define OP_Trace 178
15414 #define OP_CursorHint 179
15415 #define OP_ReleaseReg 180 /* synopsis: release r[P1@P2] mask P3 */
15416 #define OP_Noop 181
15417 #define OP_Explain 182
15418 #define OP_Abortable 183
 
15419
15420 /* Properties such as "out2" or "jump" that are specified in
15421 ** comments following the "case" for each opcode in the vdbe.c
15422 ** are encoded into bitvectors as follows:
15423 */
@@ -15447,13 +15714,13 @@
15447 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15448 /* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
15449 /* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15450 /* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
15451 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15452 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15453 /* 176 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15454 }
15455
15456 /* The resolve3P2Values() routine is able to run faster if it knows
15457 ** the value of the largest JUMP opcode. The smaller the maximum
15458 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15459 ** generated this include file strives to group all JUMP opcodes
@@ -18576,10 +18843,11 @@
18576 ** initialized as they will be set before being used. The boundary is
18577 ** determined by offsetof(Parse,aTempReg).
18578 **************************************************************************/
18579
18580 int aTempReg[8]; /* Holding area for temporary registers */
 
18581 Token sNameToken; /* Token with unqualified schema object name */
18582
18583 /************************************************************************
18584 ** Above is constant between recursions. Below is reset before and after
18585 ** each recursion. The boundary between these two regions is determined
@@ -18626,11 +18894,12 @@
18626 #define PARSE_MODE_UNMAP 3
18627
18628 /*
18629 ** Sizes and pointers of various parts of the Parse object.
18630 */
18631 #define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
 
18632 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
18633 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
18634 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
18635
18636 /*
@@ -19566,11 +19835,12 @@
19566 #endif
19567 SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe*,int,const char*);
19568 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
19569 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,
19570 Upsert*);
19571 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
 
19572 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
19573 SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
19574 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
19575 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
19576 SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*);
@@ -19966,11 +20236,11 @@
19966 void (*)(sqlite3_context*),
19967 void (*)(sqlite3_context*,int,sqlite3_value **),
19968 FuncDestructor *pDestructor
19969 );
19970 SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
19971 SQLITE_PRIVATE void sqlite3OomFault(sqlite3*);
19972 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
19973 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
19974 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
19975
19976 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
@@ -20087,11 +20357,12 @@
20087 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
20088 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
20089 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20090 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
20091 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20092 SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
 
20093 SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
20094 #ifdef SQLITE_ENABLE_NORMALIZE
20095 SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
20096 #endif
20097 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
@@ -20520,10 +20791,18 @@
20520
20521 #endif /* !defined(_OS_COMMON_H_) */
20522
20523 /************** End of os_common.h *******************************************/
20524 /************** Begin file ctime.c *******************************************/
 
 
 
 
 
 
 
 
20525 /*
20526 ** 2010 February 23
20527 **
20528 ** The author disclaims copyright to this source code. In place of
20529 ** a legal notice, here is a blessing:
@@ -20568,13 +20847,10 @@
20568 ** only a handful of compile-time options, so most times this array is usually
20569 ** rather short and uses little memory space.
20570 */
20571 static const char * const sqlite3azCompileOpt[] = {
20572
20573 /*
20574 ** BEGIN CODE GENERATED BY tool/mkctime.tcl
20575 */
20576 #ifdef SQLITE_32BIT_ROWID
20577 "32BIT_ROWID",
20578 #endif
20579 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
20580 "4_BYTE_ALIGNED_MALLOC",
@@ -20701,13 +20977,10 @@
20701 "DISABLE_FTS4_DEFERRED",
20702 #endif
20703 #ifdef SQLITE_DISABLE_INTRINSIC
20704 "DISABLE_INTRINSIC",
20705 #endif
20706 #ifdef SQLITE_DISABLE_JSON
20707 "DISABLE_JSON",
20708 #endif
20709 #ifdef SQLITE_DISABLE_LFS
20710 "DISABLE_LFS",
20711 #endif
20712 #ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
20713 "DISABLE_PAGECACHE_OVERFLOW_STATS",
@@ -21104,10 +21377,13 @@
21104 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
21105 "OMIT_INTEGRITY_CHECK",
21106 #endif
21107 #ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
21108 "OMIT_INTROSPECTION_PRAGMAS",
 
 
 
21109 #endif
21110 #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
21111 "OMIT_LIKE_OPTIMIZATION",
21112 #endif
21113 #ifdef SQLITE_OMIT_LOAD_EXTENSION
@@ -21293,14 +21569,12 @@
21293 "WIN32_MALLOC",
21294 #endif
21295 #ifdef SQLITE_ZERO_MALLOC
21296 "ZERO_MALLOC",
21297 #endif
21298 /*
21299 ** END CODE GENERATED BY tool/mkctime.tcl
21300 */
21301 };
21302
21303 SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
21304 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
21305 return (const char**)sqlite3azCompileOpt;
21306 }
@@ -22214,10 +22488,28 @@
22214 i64 iKey2; /* Second key value passed to hook */
22215 Mem *aNew; /* Array of new.* values */
22216 Table *pTab; /* Schema object being upated */
22217 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
22218 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22219
22220 /*
22221 ** Function prototypes
22222 */
22223 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
@@ -23406,11 +23698,12 @@
23406 */
23407 static int parseModifier(
23408 sqlite3_context *pCtx, /* Function context */
23409 const char *z, /* The text of the modifier */
23410 int n, /* Length of zMod in bytes */
23411 DateTime *p /* The date/time value to be modified */
 
23412 ){
23413 int rc = 1;
23414 double r;
23415 switch(sqlite3UpperToLower[(u8)z[0]] ){
23416 case 'a': {
@@ -23419,10 +23712,11 @@
23419 **
23420 ** If rawS is available, then interpret as a julian day number, or
23421 ** a unix timestamp, depending on its magnitude.
23422 */
23423 if( sqlite3_stricmp(z, "auto")==0 ){
 
23424 if( !p->rawS || p->validJD ){
23425 rc = 0;
23426 p->rawS = 0;
23427 }else if( p->s>=-210866760000 && p->s<=253402300799 ){
23428 r = p->s*1000.0 + 210866760000000.0;
@@ -23443,10 +23737,11 @@
23443 ** is not the first modifier, or if the prior argument is not a numeric
23444 ** value in the allowed range of julian day numbers understood by
23445 ** SQLite (0..5373484.5) then the result will be NULL.
23446 */
23447 if( sqlite3_stricmp(z, "julianday")==0 ){
 
23448 if( p->validJD && p->rawS ){
23449 rc = 0;
23450 p->rawS = 0;
23451 }
23452 }
@@ -23473,10 +23768,11 @@
23473 **
23474 ** Treat the current value of p->s as the number of
23475 ** seconds since 1970. Convert to a real julian day number.
23476 */
23477 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
 
23478 r = p->s*1000.0 + 210866760000000.0;
23479 if( r>=0.0 && r<464269060800000.0 ){
23480 clearYMD_HMS_TZ(p);
23481 p->iJD = (sqlite3_int64)(r + 0.5);
23482 p->validJD = 1;
@@ -23686,11 +23982,11 @@
23686 }
23687 }
23688 for(i=1; i<argc; i++){
23689 z = sqlite3_value_text(argv[i]);
23690 n = sqlite3_value_bytes(argv[i]);
23691 if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
23692 }
23693 computeJD(p);
23694 if( p->isError || !validJulianDay(p->iJD) ) return 1;
23695 return 0;
23696 }
@@ -28956,22 +29252,31 @@
28956 /*
28957 ** Call this routine to record the fact that an OOM (out-of-memory) error
28958 ** has happened. This routine will set db->mallocFailed, and also
28959 ** temporarily disable the lookaside memory allocator and interrupt
28960 ** any running VDBEs.
 
 
 
 
 
 
 
28961 */
28962 SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
28963 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
28964 db->mallocFailed = 1;
28965 if( db->nVdbeExec>0 ){
28966 AtomicStore(&db->u1.isInterrupted, 1);
28967 }
28968 DisableLookaside;
28969 if( db->pParse ){
 
28970 db->pParse->rc = SQLITE_NOMEM_BKPT;
28971 }
28972 }
 
28973 }
28974
28975 /*
28976 ** This routine reactivates the memory allocator and clears the
28977 ** db->mallocFailed flag as necessary.
@@ -32356,17 +32661,23 @@
32356 */
32357 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
32358 char *zMsg;
32359 va_list ap;
32360 sqlite3 *db = pParse->db;
 
 
32361 db->errByteOffset = -2;
32362 va_start(ap, zFormat);
32363 zMsg = sqlite3VMPrintf(db, zFormat, ap);
32364 va_end(ap);
32365 if( db->errByteOffset<-1 ) db->errByteOffset = -1;
32366 if( db->suppressErr ){
32367 sqlite3DbFree(db, zMsg);
 
 
 
 
32368 }else{
32369 pParse->nErr++;
32370 sqlite3DbFree(db, pParse->zErrMsg);
32371 pParse->zErrMsg = zMsg;
32372 pParse->rc = SQLITE_ERROR;
@@ -34334,21 +34645,22 @@
34334 /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
34335 /* 169 */ "VBegin" OpHelp(""),
34336 /* 170 */ "VCreate" OpHelp(""),
34337 /* 171 */ "VDestroy" OpHelp(""),
34338 /* 172 */ "VOpen" OpHelp(""),
34339 /* 173 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34340 /* 174 */ "VRename" OpHelp(""),
34341 /* 175 */ "Pagecount" OpHelp(""),
34342 /* 176 */ "MaxPgcnt" OpHelp(""),
34343 /* 177 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34344 /* 178 */ "Trace" OpHelp(""),
34345 /* 179 */ "CursorHint" OpHelp(""),
34346 /* 180 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34347 /* 181 */ "Noop" OpHelp(""),
34348 /* 182 */ "Explain" OpHelp(""),
34349 /* 183 */ "Abortable" OpHelp(""),
 
34350 };
34351 return azName[i];
34352 }
34353 #endif
34354
@@ -56722,12 +57034,11 @@
56722 ** Once this function has been called, the transaction must either be
56723 ** rolled back or committed. It is not safe to call this function and
56724 ** then continue writing to the database.
56725 */
56726 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56727 assert( pPager->dbSize>=nPage || CORRUPT_DB );
56728 testcase( pPager->dbSize<nPage );
56729 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
56730 pPager->dbSize = nPage;
56731
56732 /* At one point the code here called assertTruncateConstraint() to
56733 ** ensure that all pages being truncated away by this operation are,
@@ -63102,11 +63413,13 @@
63102 rc = WAL_RETRY;
63103 goto begin_unreliable_shm_out;
63104 }
63105
63106 /* Allocate a buffer to read frames into */
63107 szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
 
 
63108 aFrame = (u8 *)sqlite3_malloc64(szFrame);
63109 if( aFrame==0 ){
63110 rc = SQLITE_NOMEM_BKPT;
63111 goto begin_unreliable_shm_out;
63112 }
@@ -63116,11 +63429,11 @@
63116 ** wal file since the heap-memory wal-index was created. If so, the
63117 ** heap-memory wal-index is discarded and WAL_RETRY returned to
63118 ** the caller. */
63119 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
63120 aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
63121 for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage);
63122 iOffset+szFrame<=szWal;
63123 iOffset+=szFrame
63124 ){
63125 u32 pgno; /* Database page number for frame */
63126 u32 nTruncate; /* dbsize field from frame header */
@@ -68934,13 +69247,17 @@
68934 freeTempSpace(pBt);
68935 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
68936 pageSize-usableSize);
68937 return rc;
68938 }
68939 if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
68940 rc = SQLITE_CORRUPT_BKPT;
68941 goto page1_init_failed;
 
 
 
 
68942 }
68943 /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
68944 ** be less than 480. In other words, if the page size is 512, then the
68945 ** reserved space size cannot exceed 32. */
68946 if( usableSize<480 ){
@@ -76691,18 +77008,17 @@
76691 int i = sqlite3FindDbName(pDb, zDb);
76692
76693 if( i==1 ){
76694 Parse sParse;
76695 int rc = 0;
76696 memset(&sParse, 0, sizeof(sParse));
76697 sParse.db = pDb;
76698 if( sqlite3OpenTempDatabase(&sParse) ){
76699 sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
76700 rc = SQLITE_ERROR;
76701 }
76702 sqlite3DbFree(pErrorDb, sParse.zErrMsg);
76703 sqlite3ParserReset(&sParse);
76704 if( rc ){
76705 return 0;
76706 }
76707 }
76708
@@ -78910,15 +79226,11 @@
78910 const char *zNeg = "";
78911 int rc = SQLITE_OK;
78912
78913 assert( pExpr!=0 );
78914 while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
78915 #if defined(SQLITE_ENABLE_STAT4)
78916 if( op==TK_REGISTER ) op = pExpr->op2;
78917 #else
78918 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
78919 #endif
78920
78921 /* Compressed expressions only appear when parsing the DEFAULT clause
78922 ** on a table column definition, and hence only when pCtx==0. This
78923 ** check ensures that an EP_TokenOnly expression is never passed down
78924 ** into valueFromFunction(). */
@@ -80707,12 +81019,11 @@
80707 ** makes the code easier to read during debugging. None of this happens
80708 ** in a production build.
80709 */
80710 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
80711 assert( p->nOp>0 || p->aOp==0 );
80712 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
80713 || p->pParse->nErr>0 );
80714 if( p->nOp ){
80715 assert( p->aOp );
80716 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
80717 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
80718 }
@@ -85436,10 +85747,74 @@
85436 */
85437 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
85438 assert( p );
85439 return sqlite3_value_nochange(p->pOut);
85440 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85441
85442 /*
85443 ** Return the current time for a statement. If the current time
85444 ** is requested more than once within the same run of a single prepared
85445 ** statement, the exact same time is returned for each invocation regardless
@@ -87537,11 +87912,10 @@
87537 */
87538 static u64 filterHash(const Mem *aMem, const Op *pOp){
87539 int i, mx;
87540 u64 h = 0;
87541
87542 i = pOp->p3;
87543 assert( pOp->p4type==P4_INT32 );
87544 for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
87545 const Mem *p = &aMem[i];
87546 if( p->flags & (MEM_Int|MEM_IntReal) ){
87547 h += p->u.i;
@@ -89020,11 +89394,11 @@
89020 testcase( pIn1->flags & MEM_Real );
89021 testcase( pIn1->flags & MEM_IntReal );
89022 sqlite3VdbeMemStringify(pIn1, encoding, 1);
89023 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
89024 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
89025 if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
89026 }
89027 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
89028 testcase( pIn3->flags & MEM_Int );
89029 testcase( pIn3->flags & MEM_Real );
89030 testcase( pIn3->flags & MEM_IntReal );
@@ -89846,10 +90220,12 @@
89846 case COLTYPE_TEXT: {
89847 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
89848 break;
89849 }
89850 case COLTYPE_REAL: {
 
 
89851 if( pIn1->flags & MEM_Int ){
89852 /* When applying REAL affinity, if the result is still an MEM_Int
89853 ** that will fit in 6 bytes, then change the type to MEM_IntReal
89854 ** so that we keep the high-resolution integer value but know that
89855 ** the type really wants to be REAL. */
@@ -89863,11 +90239,11 @@
89863 }else{
89864 pIn1->u.r = (double)pIn1->u.i;
89865 pIn1->flags |= MEM_Real;
89866 pIn1->flags &= ~MEM_Int;
89867 }
89868 }else if( (pIn1->flags & MEM_Real)==0 ){
89869 goto vdbe_type_error;
89870 }
89871 break;
89872 }
89873 default: {
@@ -94592,10 +94968,38 @@
94592 goto no_mem;
94593 }
94594 break;
94595 }
94596 #endif /* SQLITE_OMIT_VIRTUALTABLE */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94597
94598 #ifndef SQLITE_OMIT_VIRTUALTABLE
94599 /* Opcode: VFilter P1 P2 P3 P4 *
94600 ** Synopsis: iplan=r[P3] zplan='P4'
94601 **
@@ -95579,14 +95983,13 @@
95579 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
95580
95581 sqlite3_mutex_enter(db->mutex);
95582
95583 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
95584 do {
95585 memset(&sParse, 0, sizeof(Parse));
95586 if( !pBlob ) goto blob_open_out;
95587 sParse.db = db;
95588 sqlite3DbFree(db, zErr);
95589 zErr = 0;
95590
95591 sqlite3BtreeEnterAll(db);
95592 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
@@ -95759,11 +96162,13 @@
95759 sqlite3BtreeLeaveAll(db);
95760 if( db->mallocFailed ){
95761 goto blob_open_out;
95762 }
95763 rc = blobSeekToRow(pBlob, iRow, &zErr);
95764 } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
 
 
95765
95766 blob_open_out:
95767 if( rc==SQLITE_OK && db->mallocFailed==0 ){
95768 *ppBlob = (sqlite3_blob *)pBlob;
95769 }else{
@@ -95770,11 +96175,11 @@
95770 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
95771 sqlite3DbFree(db, pBlob);
95772 }
95773 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
95774 sqlite3DbFree(db, zErr);
95775 sqlite3ParserReset(&sParse);
95776 rc = sqlite3ApiExit(db, rc);
95777 sqlite3_mutex_leave(db->mutex);
95778 return rc;
95779 }
95780
@@ -100835,11 +101240,11 @@
100835 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
100836 ){
100837 /* Internal-use-only functions are disallowed unless the
100838 ** SQL is being compiled using sqlite3NestedParse() or
100839 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
100840 ** used to activate internal functionsn for testing purposes */
100841 no_such_func = 1;
100842 pDef = 0;
100843 }else
100844 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
100845 && !IN_RENAME_OBJECT
@@ -101054,11 +101459,12 @@
101054 sqlite3ErrorMsg(pParse, "row value misused");
101055 }
101056 break;
101057 }
101058 }
101059 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
 
101060 }
101061
101062 /*
101063 ** pEList is a list of expressions which are really the result set of the
101064 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
@@ -101468,11 +101874,11 @@
101468 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
101469 ** this routine in the correct order.
101470 */
101471 if( (p->selFlags & SF_Expanded)==0 ){
101472 sqlite3SelectPrep(pParse, p, pOuterNC);
101473 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
101474 }
101475
101476 isCompound = p->pPrior!=0;
101477 nCompound = 0;
101478 pLeftmost = p;
@@ -101516,11 +101922,12 @@
101516 const char *zSavedContext = pParse->zAuthContext;
101517
101518 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
101519 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
101520 pParse->zAuthContext = zSavedContext;
101521 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
 
101522
101523 /* If the number of references to the outer context changed when
101524 ** expressions in the sub-select were resolved, the sub-select
101525 ** is correlated. It is not required to check the refcount on any
101526 ** but the innermost outer context object, as lookupName() increments
@@ -104696,12 +105103,11 @@
104696 Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
104697 Expr *pRhs = pEList->a[i].pExpr;
104698 CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
104699 int j;
104700
104701 assert( pReq!=0 || pRhs->iColumn==XN_ROWID
104702 || pParse->nErr || db->mallocFailed );
104703 for(j=0; j<nExpr; j++){
104704 if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
104705 assert( pIdx->azColl[j] );
104706 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
104707 continue;
@@ -105173,14 +105579,12 @@
105173 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
105174 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
105175 }
105176 pSel->iLimit = 0;
105177 if( sqlite3Select(pParse, pSel, &dest) ){
105178 if( pParse->nErr ){
105179 pExpr->op2 = pExpr->op;
105180 pExpr->op = TK_ERROR;
105181 }
105182 return 0;
105183 }
105184 pExpr->iTable = rReg = dest.iSDParm;
105185 ExprSetVVAProperty(pExpr, EP_NoReduce);
105186 if( addrOnce ){
@@ -105393,14 +105797,13 @@
105393 if( destIfNull==destIfFalse ){
105394 destStep2 = destIfFalse;
105395 }else{
105396 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105397 }
105398 if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105399 for(i=0; i<nVector; i++){
105400 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105401 if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
105402 if( sqlite3ExprCanBeNull(p) ){
105403 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
105404 VdbeCoverage(v);
105405 }
105406 }
@@ -108571,11 +108974,13 @@
108571 sqlite3 *db; /* The database connection; */
108572 Vdbe *v; /* The prepared statement under construction */
108573 int r1; /* Temporary registers */
108574
108575 db = pParse->db;
108576 if( pParse->nErr || db->mallocFailed ) return;
 
 
108577 pNew = pParse->pNewTable;
108578 assert( pNew );
108579
108580 assert( sqlite3BtreeHoldsAllMutexes(db) );
108581 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -108697,11 +109102,11 @@
108697 sqlite3NestedParse(pParse,
108698 "SELECT CASE WHEN quick_check GLOB 'CHECK*'"
108699 " THEN raise(ABORT,'CHECK constraint failed')"
108700 " ELSE raise(ABORT,'NOT NULL constraint failed')"
108701 " END"
108702 " FROM pragma_quick_check(\"%w\",\"%w\")"
108703 " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
108704 zTab, zDb
108705 );
108706 }
108707 }
@@ -108982,11 +109387,13 @@
108982 **
108983 ** Technically, as x no longer points into a valid object or to the byte
108984 ** following a valid object, it may not be used in comparison operations.
108985 */
108986 static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
108987 if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){
 
 
108988 const RenameToken *p;
108989 u8 i = 0;
108990 for(p=pParse->pRename; p; p=p->pNext){
108991 if( p->p ){
108992 assert( p->p!=pPtr );
@@ -109379,11 +109786,11 @@
109379 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
109380
109381 /* Parse the SQL statement passed as the first argument. If no error
109382 ** occurs and the parse does not result in a new table, index or
109383 ** trigger object, the database must be corrupt. */
109384 memset(p, 0, sizeof(Parse));
109385 p->eParseMode = PARSE_MODE_RENAME;
109386 p->db = db;
109387 p->nQueryLoop = 1;
109388 rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM;
109389 if( db->mallocFailed ) rc = SQLITE_NOMEM;
@@ -109664,11 +110071,11 @@
109664 sqlite3FreeIndex(db, pIdx);
109665 }
109666 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
109667 sqlite3DbFree(db, pParse->zErrMsg);
109668 renameTokenFree(db, pParse->pRename);
109669 sqlite3ParserReset(pParse);
109670 }
109671
109672 /*
109673 ** SQL function:
109674 **
@@ -110378,10 +110785,16 @@
110378
110379 /* Edit the sqlite_schema table */
110380 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110381 assert( iDb>=0 );
110382 zDb = db->aDb[iDb].zDbSName;
 
 
 
 
 
 
110383 renameTestSchema(pParse, zDb, iDb==1, "", 0);
110384 renameFixQuotes(pParse, zDb, iDb==1);
110385 sqlite3NestedParse(pParse,
110386 "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
110387 "sql = sqlite_drop_column(%d, sql, %d) "
@@ -112765,11 +113178,11 @@
112765 ){
112766 goto attach_end;
112767 }
112768
112769 #ifndef SQLITE_OMIT_AUTHORIZATION
112770 if( pAuthArg ){
112771 char *zAuthArg;
112772 if( pAuthArg->op==TK_STRING ){
112773 assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112774 zAuthArg = pAuthArg->u.zToken;
112775 }else{
@@ -113426,15 +113839,17 @@
113426 sqlite3 *db;
113427 Vdbe *v;
113428
113429 assert( pParse->pToplevel==0 );
113430 db = pParse->db;
 
113431 if( pParse->nested ) return;
113432 if( db->mallocFailed || pParse->nErr ){
113433 if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
113434 return;
113435 }
 
113436
113437 /* Begin by generating some termination code at the end of the
113438 ** vdbe program
113439 */
113440 v = pParse->pVdbe;
@@ -113563,11 +113978,13 @@
113563 }
113564 }
113565
113566 /* Get the VDBE program ready for execution
113567 */
113568 if( v && pParse->nErr==0 && !db->mallocFailed ){
 
 
113569 /* A minimum of one cursor is required if autoincrement is used
113570 * See ticket [a696379c1f08866] */
113571 assert( pParse->pAinc==0 || pParse->nTab>0 );
113572 sqlite3VdbeMakeReady(v, pParse);
113573 pParse->rc = SQLITE_DONE;
@@ -115667,14 +116084,15 @@
115667 pList->a[0].sortFlags = pParse->iPkSortOrder;
115668 assert( pParse->pNewTable==pTab );
115669 pTab->iPKey = -1;
115670 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
115671 SQLITE_IDXTYPE_PRIMARYKEY);
115672 if( db->mallocFailed || pParse->nErr ){
115673 pTab->tabFlags &= ~TF_WithoutRowid;
115674 return;
115675 }
 
115676 pPk = sqlite3PrimaryKeyIndex(pTab);
115677 assert( pPk->nKeyCol==1 );
115678 }else{
115679 pPk = sqlite3PrimaryKeyIndex(pTab);
115680 assert( pPk!=0 );
@@ -116411,14 +116829,14 @@
116411 ** normally holds CHECK constraints on an ordinary table, but for
116412 ** a VIEW it holds the list of column names.
116413 */
116414 sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
116415 &pTable->nCol, &pTable->aCol);
116416 if( db->mallocFailed==0
116417 && pParse->nErr==0
116418 && pTable->nCol==pSel->pEList->nExpr
116419 ){
 
116420 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
116421 SQLITE_AFF_NONE);
116422 }
116423 }else{
116424 /* CREATE VIEW name AS... without an argument list. Construct
@@ -117033,11 +117451,11 @@
117033 tnum = (Pgno)memRootPage;
117034 }else{
117035 tnum = pIndex->tnum;
117036 }
117037 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
117038 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
117039
117040 /* Open the sorter cursor if we are to use one. */
117041 iSorter = pParse->nTab++;
117042 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
117043 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
@@ -117197,13 +117615,15 @@
117197 int nExtra = 0; /* Space allocated for zExtra[] */
117198 int nExtraCol; /* Number of extra columns needed */
117199 char *zExtra = 0; /* Extra space after the Index object */
117200 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
117201
117202 if( db->mallocFailed || pParse->nErr>0 ){
 
117203 goto exit_create_index;
117204 }
 
117205 if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
117206 goto exit_create_index;
117207 }
117208 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117209 goto exit_create_index;
@@ -117263,11 +117683,10 @@
117263 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117264 }
117265 pDb = &db->aDb[iDb];
117266
117267 assert( pTab!=0 );
117268 assert( pParse->nErr==0 );
117269 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
117270 && db->init.busy==0
117271 && pTblName!=0
117272 #if SQLITE_USER_AUTHENTICATION
117273 && sqlite3UserAuthTable(pTab->zName)==0
@@ -117827,14 +118246,14 @@
117827 Index *pIndex;
117828 Vdbe *v;
117829 sqlite3 *db = pParse->db;
117830 int iDb;
117831
117832 assert( pParse->nErr==0 ); /* Never called with prior errors */
117833 if( db->mallocFailed ){
117834 goto exit_drop_index;
117835 }
 
117836 assert( pName->nSrc==1 );
117837 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117838 goto exit_drop_index;
117839 }
117840 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
@@ -119746,13 +120165,15 @@
119746 Trigger *pTrigger; /* List of table triggers, if required */
119747 #endif
119748
119749 memset(&sContext, 0, sizeof(sContext));
119750 db = pParse->db;
119751 if( pParse->nErr || db->mallocFailed ){
 
119752 goto delete_from_cleanup;
119753 }
 
119754 assert( pTabList->nSrc==1 );
119755
119756
119757 /* Locate the table which we want to delete. This table has to be
119758 ** put in an SrcList structure because some of the subroutines we
@@ -119929,11 +120350,11 @@
119929 **
119930 ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values.
119931 ** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
119932 ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
119933 */
119934 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1);
119935 if( pWInfo==0 ) goto delete_from_cleanup;
119936 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
119937 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
119938 assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
119939 if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
@@ -120542,10 +120963,11 @@
120542 static void subtypeFunc(
120543 sqlite3_context *context,
120544 int argc,
120545 sqlite3_value **argv
120546 ){
 
120547 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
120548 }
120549
120550 /*
120551 ** Implementation of the length() function
@@ -123472,11 +123894,11 @@
123472
123473 /* Create VDBE to loop through the entries in pSrc that match the WHERE
123474 ** clause. For each row found, increment either the deferred or immediate
123475 ** foreign key constraint counter. */
123476 if( pParse->nErr==0 ){
123477 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
123478 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
123479 if( pWInfo ){
123480 sqlite3WhereEnd(pWInfo);
123481 }
123482 }
@@ -125014,13 +125436,15 @@
125014 Trigger *pTrigger; /* List of triggers on pTab, if required */
125015 int tmask; /* Mask of trigger times */
125016 #endif
125017
125018 db = pParse->db;
125019 if( pParse->nErr || db->mallocFailed ){
 
125020 goto insert_cleanup;
125021 }
 
125022 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
125023
125024 /* If the Select object is really just a simple VALUES() list with a
125025 ** single row (the common case) then keep that one row of values
125026 ** and discard the other (unused) parts of the pSelect object
@@ -125192,11 +125616,13 @@
125192 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
125193 dest.iSdst = bIdListInOrder ? regData : 0;
125194 dest.nSdst = pTab->nCol;
125195 rc = sqlite3Select(pParse, pSelect, &dest);
125196 regFromSelect = dest.iSdst;
125197 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
 
 
125198 sqlite3VdbeEndCoroutine(v, regYield);
125199 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
125200 assert( pSelect->pEList );
125201 nColumn = pSelect->pEList->nExpr;
125202
@@ -127937,10 +128363,15 @@
127937 int (*autovacuum_pages)(sqlite3*,
127938 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
127939 void*, void(*)(void*));
127940 /* Version 3.38.0 and later */
127941 int (*error_offset)(sqlite3*);
 
 
 
 
 
127942 };
127943
127944 /*
127945 ** This is the function signature used for all extension entry points. It
127946 ** is also defined in the file "loadext.c".
@@ -128250,10 +128681,15 @@
128250 #define sqlite3_total_changes64 sqlite3_api->total_changes64
128251 /* Version 3.37.0 and later */
128252 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128253 /* Version 3.38.0 and later */
128254 #define sqlite3_error_offset sqlite3_api->error_offset
 
 
 
 
 
128255 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128256
128257 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128258 /* This case when the file really is being compiled as a loadable
128259 ** extension */
@@ -128741,10 +129177,15 @@
128741 sqlite3_total_changes64,
128742 /* Version 3.37.0 and later */
128743 sqlite3_autovacuum_pages,
128744 /* Version 3.38.0 and later */
128745 sqlite3_error_offset,
 
 
 
 
 
128746 };
128747
128748 /* True if x is the directory separator character
128749 */
128750 #if SQLITE_OS_WIN
@@ -131042,10 +131483,14 @@
131042 sqlite3_stmt *pDummy = 0;
131043 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
131044 (void)sqlite3_finalize(pDummy);
131045 sqlite3DbFree(db, zSql);
131046 }
 
 
 
 
131047 pHash = &db->aDb[ii].pSchema->tblHash;
131048 break;
131049 }
131050 }
131051 }
@@ -133078,12 +133523,14 @@
133078 }
133079
133080 /*
133081 ** Free all memory allocations in the pParse object
133082 */
133083 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
133084 sqlite3 *db = pParse->db;
 
 
133085 assert( pParse->nested==0 );
133086 #ifndef SQLITE_OMIT_SHARED_CACHE
133087 sqlite3DbFree(db, pParse->aTableLock);
133088 #endif
133089 while( pParse->pCleanup ){
@@ -133094,15 +133541,16 @@
133094 }
133095 sqlite3DbFree(db, pParse->aLabel);
133096 if( pParse->pConstExpr ){
133097 sqlite3ExprListDelete(db, pParse->pConstExpr);
133098 }
133099 if( db ){
133100 assert( db->lookaside.bDisable >= pParse->disableLookaside );
133101 db->lookaside.bDisable -= pParse->disableLookaside;
133102 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133103 }
 
133104 pParse->disableLookaside = 0;
133105 }
133106
133107 /*
133108 ** Add a new cleanup operation to a Parser. The cleanup should happen when
@@ -133111,11 +133559,11 @@
133111 **
133112 ** Use this mechanism for uncommon cleanups. There is a higher setup
133113 ** cost for this mechansim (an extra malloc), so it should not be used
133114 ** for common cleanups that happen on most calls. But for less
133115 ** common cleanups, we save a single NULL-pointer comparison in
133116 ** sqlite3ParserReset(), which reduces the total CPU cycle count.
133117 **
133118 ** If a memory allocation error occurs, then the cleanup happens immediately.
133119 ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
133120 ** pParse->earlyCleanup flag is set in that case. Calling code show verify
133121 ** that test cases exist for which this happens, to guard against possible
@@ -133150,10 +133598,29 @@
133150 pParse->earlyCleanup = 1;
133151 #endif
133152 }
133153 return pPtr;
133154 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133155
133156 /*
133157 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133158 */
133159 static int sqlite3Prepare(
@@ -133167,15 +133634,19 @@
133167 ){
133168 int rc = SQLITE_OK; /* Result code */
133169 int i; /* Loop counter */
133170 Parse sParse; /* Parsing context */
133171
133172 memset(&sParse, 0, PARSE_HDR_SZ);
 
133173 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
 
 
 
133174 sParse.pReprepare = pReprepare;
133175 assert( ppStmt && *ppStmt==0 );
133176 /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
133177 assert( sqlite3_mutex_held(db->mutex) );
133178
133179 /* For a long-term use prepared statement avoid the use of
133180 ** lookaside memory.
133181 */
@@ -133224,11 +133695,10 @@
133224 }
133225 }
133226
133227 sqlite3VtabUnlockList(db);
133228
133229 sParse.db = db;
133230 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
133231 char *zSqlCopy;
133232 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
133233 testcase( nBytes==mxLen );
133234 testcase( nBytes==mxLen+1 );
@@ -133291,11 +133761,11 @@
133291 sqlite3DbFree(db, pT);
133292 }
133293
133294 end_prepare:
133295
133296 sqlite3ParserReset(&sParse);
133297 return rc;
133298 }
133299 static int sqlite3LockAndPrepare(
133300 sqlite3 *db, /* Database handle. */
133301 const char *zSql, /* UTF-8 encoded SQL statement. */
@@ -134946,11 +135416,11 @@
134946 p->enc = ENC(db);
134947 p->db = db;
134948 p->nRef = 1;
134949 memset(&p[1], 0, nExtra);
134950 }else{
134951 sqlite3OomFault(db);
134952 }
134953 return p;
134954 }
134955
134956 /*
@@ -135117,10 +135587,13 @@
135117 }
135118 #endif
135119
135120 iTab = pSort->iECursor;
135121 if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
 
 
 
135122 regRowid = 0;
135123 regRow = pDest->iSdst;
135124 }else{
135125 regRowid = sqlite3GetTempReg(pParse);
135126 if( eDest==SRT_EphemTab || eDest==SRT_Table ){
@@ -136975,10 +137448,11 @@
136975 }else{
136976 pSplit = p;
136977 for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
136978 }
136979 pPrior = pSplit->pPrior;
 
136980 pSplit->pPrior = 0;
136981 pPrior->pNext = 0;
136982 assert( p->pOrderBy == pOrderBy );
136983 assert( pOrderBy!=0 || db->mallocFailed );
136984 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
@@ -139126,11 +139600,12 @@
139126 }
139127 }
139128
139129 /* Process NATURAL keywords, and ON and USING clauses of joins.
139130 */
139131 if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
 
139132 return WRC_Abort;
139133 }
139134
139135 /* For every "*" that occurs in the column list, insert the names of
139136 ** all columns in all tables. And for every TABLE.* insert the names
@@ -139423,16 +139898,17 @@
139423 Parse *pParse, /* The parser context */
139424 Select *p, /* The SELECT statement being coded. */
139425 NameContext *pOuterNC /* Name context for container */
139426 ){
139427 assert( p!=0 || pParse->db->mallocFailed );
 
139428 if( pParse->db->mallocFailed ) return;
139429 if( p->selFlags & SF_HasTypeInfo ) return;
139430 sqlite3SelectExpand(pParse, p);
139431 if( pParse->nErr || pParse->db->mallocFailed ) return;
139432 sqlite3ResolveSelectNames(pParse, p, pOuterNC);
139433 if( pParse->nErr || pParse->db->mallocFailed ) return;
139434 sqlite3SelectAddTypeInfo(pParse, p);
139435 }
139436
139437 /*
139438 ** Reset the aggregate accumulator.
@@ -139445,12 +139921,14 @@
139445 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
139446 Vdbe *v = pParse->pVdbe;
139447 int i;
139448 struct AggInfo_func *pFunc;
139449 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
 
 
139450 if( nReg==0 ) return;
139451 if( pParse->nErr || pParse->db->mallocFailed ) return;
139452 #ifdef SQLITE_DEBUG
139453 /* Verify that all AggInfo registers are within the range specified by
139454 ** AggInfo.mnReg..AggInfo.mxReg */
139455 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
139456 for(i=0; i<pAggInfo->nColumn; i++){
@@ -139869,14 +140347,16 @@
139869 sqlite3 *db; /* The database connection */
139870 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
139871 u8 minMaxFlag; /* Flag for min/max queries */
139872
139873 db = pParse->db;
 
139874 v = sqlite3GetVdbe(pParse);
139875 if( p==0 || db->mallocFailed || pParse->nErr ){
139876 return 1;
139877 }
 
139878 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
139879 #if SELECTTRACE_ENABLED
139880 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
139881 if( sqlite3SelectTrace & 0x100 ){
139882 sqlite3TreeViewSelect(0, p, 0);
@@ -139907,13 +140387,14 @@
139907 }
139908 p->selFlags &= ~SF_Distinct;
139909 p->selFlags |= SF_NoopOrderBy;
139910 }
139911 sqlite3SelectPrep(pParse, p, 0);
139912 if( pParse->nErr || db->mallocFailed ){
139913 goto select_end;
139914 }
 
139915 assert( p->pEList!=0 );
139916 #if SELECTTRACE_ENABLED
139917 if( sqlite3SelectTrace & 0x104 ){
139918 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
139919 sqlite3TreeViewSelect(0, p, 0);
@@ -139953,11 +140434,11 @@
139953 sqlite3GenerateColumnNames(pParse, p);
139954 }
139955
139956 #ifndef SQLITE_OMIT_WINDOWFUNC
139957 if( sqlite3WindowRewrite(pParse, p) ){
139958 assert( db->mallocFailed || pParse->nErr>0 );
139959 goto select_end;
139960 }
139961 #if SELECTTRACE_ENABLED
139962 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
139963 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -140429,11 +140910,11 @@
140429
140430
140431 /* Begin the database scan. */
140432 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140433 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
140434 p->pEList, wctrlFlags, p->nSelectRow);
140435 if( pWInfo==0 ) goto select_end;
140436 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
140437 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
140438 }
140439 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
@@ -140693,11 +141174,11 @@
140693 ** in the right order to begin with.
140694 */
140695 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
140696 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140697 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
140698 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
140699 );
140700 if( pWInfo==0 ){
140701 sqlite3ExprListDelete(db, pDistinct);
140702 goto select_end;
140703 }
@@ -140991,11 +141472,11 @@
140991 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
140992 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
140993
140994 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140995 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
140996 pDistinct, minMaxFlag|distFlag, 0);
140997 if( pWInfo==0 ){
140998 goto select_end;
140999 }
141000 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
141001 eDist = sqlite3WhereIsDistinct(pWInfo);
@@ -141048,11 +141529,11 @@
141048 /* Control jumps to here if an error is encountered above, or upon
141049 ** successful coding of the SELECT.
141050 */
141051 select_end:
141052 assert( db->mallocFailed==0 || db->mallocFailed==1 );
141053 pParse->nErr += db->mallocFailed;
141054 sqlite3ExprListDelete(db, pMinMaxOrderBy);
141055 #ifdef SQLITE_DEBUG
141056 if( pAggInfo && !db->mallocFailed ){
141057 for(i=0; i<pAggInfo->nColumn; i++){
141058 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -142200,10 +142681,11 @@
142200 Select sSelect;
142201 SrcList sFrom;
142202
142203 assert( v!=0 );
142204 assert( pParse->bReturning );
 
142205 pReturning = pParse->u1.pReturning;
142206 assert( pTrigger == &(pReturning->retTrig) );
142207 memset(&sSelect, 0, sizeof(sSelect));
142208 memset(&sFrom, 0, sizeof(sFrom));
142209 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
@@ -142210,11 +142692,12 @@
142210 sSelect.pSrc = &sFrom;
142211 sFrom.nSrc = 1;
142212 sFrom.a[0].pTab = pTab;
142213 sFrom.a[0].iCursor = -1;
142214 sqlite3SelectPrep(pParse, &sSelect, 0);
142215 if( db->mallocFailed==0 && pParse->nErr==0 ){
 
142216 sqlite3GenerateColumnNames(pParse, &sSelect);
142217 }
142218 sqlite3ExprListDelete(db, sSelect.pEList);
142219 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142220 if( !db->mallocFailed ){
@@ -142228,11 +142711,11 @@
142228 sNC.uNC.iBaseReg = regIn;
142229 sNC.ncFlags = NC_UBaseReg;
142230 pParse->eTriggerOp = pTrigger->op;
142231 pParse->pTriggerTab = pTab;
142232 if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142233 && !db->mallocFailed
142234 ){
142235 int i;
142236 int nCol = pNew->nExpr;
142237 int reg = pParse->nMem+1;
142238 pParse->nMem += nCol+2;
@@ -142392,12 +142875,12 @@
142392 TriggerPrg *pPrg; /* Value to return */
142393 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
142394 Vdbe *v; /* Temporary VM */
142395 NameContext sNC; /* Name context for sub-vdbe */
142396 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
142397 Parse *pSubParse; /* Parse context for sub-vdbe */
142398 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
 
142399
142400 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
142401 assert( pTop->pVdbe );
142402
142403 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
@@ -142415,23 +142898,21 @@
142415 pPrg->aColmask[0] = 0xffffffff;
142416 pPrg->aColmask[1] = 0xffffffff;
142417
142418 /* Allocate and populate a new Parse context to use for coding the
142419 ** trigger sub-program. */
142420 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
142421 if( !pSubParse ) return 0;
142422 memset(&sNC, 0, sizeof(sNC));
142423 sNC.pParse = pSubParse;
142424 pSubParse->db = db;
142425 pSubParse->pTriggerTab = pTab;
142426 pSubParse->pToplevel = pTop;
142427 pSubParse->zAuthContext = pTrigger->zName;
142428 pSubParse->eTriggerOp = pTrigger->op;
142429 pSubParse->nQueryLoop = pParse->nQueryLoop;
142430 pSubParse->disableVtab = pParse->disableVtab;
142431
142432 v = sqlite3GetVdbe(pSubParse);
142433 if( v ){
142434 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
142435 pTrigger->zName, onErrorText(orconf),
142436 (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
142437 (pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
@@ -142453,42 +142934,43 @@
142453 if( pTrigger->pWhen ){
142454 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
142455 if( db->mallocFailed==0
142456 && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
142457 ){
142458 iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
142459 sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142460 }
142461 sqlite3ExprDelete(db, pWhen);
142462 }
142463
142464 /* Code the trigger program into the sub-vdbe. */
142465 codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);
142466
142467 /* Insert an OP_Halt at the end of the sub-program. */
142468 if( iEndTrigger ){
142469 sqlite3VdbeResolveLabel(v, iEndTrigger);
142470 }
142471 sqlite3VdbeAddOp0(v, OP_Halt);
142472 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
 
142473
142474 transferParseError(pParse, pSubParse);
142475 if( db->mallocFailed==0 && pParse->nErr==0 ){
142476 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
142477 }
142478 pProgram->nMem = pSubParse->nMem;
142479 pProgram->nCsr = pSubParse->nTab;
142480 pProgram->token = (void *)pTrigger;
142481 pPrg->aColmask[0] = pSubParse->oldmask;
142482 pPrg->aColmask[1] = pSubParse->newmask;
142483 sqlite3VdbeDelete(v);
 
 
142484 }
142485
142486 assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
142487 sqlite3ParserReset(pSubParse);
142488 sqlite3StackFree(db, pSubParse);
142489
142490 return pPrg;
142491 }
142492
142493 /*
142494 ** Return a pointer to a TriggerPrg object containing the sub-program for
@@ -142539,11 +143021,11 @@
142539 int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
142540 ){
142541 Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
142542 TriggerPrg *pPrg;
142543 pPrg = getRowTrigger(pParse, p, pTab, orconf);
142544 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
142545
142546 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
142547 ** is a pointer to the sub-vdbe containing the trigger program. */
142548 if( pPrg ){
142549 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
@@ -143057,13 +143539,15 @@
143057 int regRowSet = 0; /* Rowset of rows to be updated */
143058 int regKey = 0; /* composite PRIMARY KEY value */
143059
143060 memset(&sContext, 0, sizeof(sContext));
143061 db = pParse->db;
143062 if( pParse->nErr || db->mallocFailed ){
 
143063 goto update_cleanup;
143064 }
 
143065
143066 /* Locate the table which we want to update.
143067 */
143068 pTab = sqlite3SrcListLookup(pParse, pTabList);
143069 if( pTab==0 ) goto update_cleanup;
@@ -143431,11 +143915,11 @@
143431 ** or index, causing a single-pass approach to malfunction. */
143432 flags = WHERE_ONEPASS_DESIRED;
143433 if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
143434 flags |= WHERE_ONEPASS_MULTIROW;
143435 }
143436 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
143437 if( pWInfo==0 ) goto update_cleanup;
143438
143439 /* A one-pass strategy that might update more than one row may not
143440 ** be used if any column of the index used for the scan is being
143441 ** updated. Otherwise, if there is an index on "b", statements like
@@ -143953,11 +144437,13 @@
143953 }else{
143954 regRec = ++pParse->nMem;
143955 regRowid = ++pParse->nMem;
143956
143957 /* Start scanning the virtual table */
143958 pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0);
 
 
143959 if( pWInfo==0 ) return;
143960
143961 /* Populate the argument registers. */
143962 for(i=0; i<pTab->nCol; i++){
143963 assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
@@ -145598,13 +146084,12 @@
145598 return SQLITE_MISUSE_BKPT;
145599 }
145600 pTab = pCtx->pTab;
145601 assert( IsVirtual(pTab) );
145602
145603 memset(&sParse, 0, sizeof(sParse));
145604 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
145605 sParse.db = db;
145606 /* We should never be able to reach this point while loading the
145607 ** schema. Nevertheless, defend against that (turn off db->init.busy)
145608 ** in case a bug arises. */
145609 assert( db->init.busy==0 );
145610 initBusy = db->init.busy;
@@ -145654,11 +146139,11 @@
145654
145655 if( sParse.pVdbe ){
145656 sqlite3VdbeFinalize(sParse.pVdbe);
145657 }
145658 sqlite3DeleteTable(db, sParse.pNewTable);
145659 sqlite3ParserReset(&sParse);
145660 db->init.busy = initBusy;
145661
145662 assert( (rc&0xff)==rc );
145663 rc = sqlite3ApiExit(db, rc);
145664 sqlite3_mutex_leave(db->mutex);
@@ -146265,14 +146750,16 @@
146265 u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
146266 Index *pIndex; /* Index used, or NULL */
146267 } btree;
146268 struct { /* Information for virtual tables */
146269 int idxNum; /* Index number */
146270 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
 
146271 i8 isOrdered; /* True if satisfies ORDER BY */
146272 u16 omitMask; /* Terms that may be omitted */
146273 char *idxStr; /* Index identifier string */
 
146274 } vtab;
146275 } u;
146276 u32 wsFlags; /* WHERE_* flags describing the plan */
146277 u16 nLTerm; /* Number of entries in aLTerm[] */
146278 u16 nSkip; /* Number of NULL aLTerm[] entries */
@@ -146425,10 +146912,11 @@
146425 #ifdef SQLITE_ENABLE_STAT4
146426 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
146427 #else
146428 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
146429 #endif
 
146430
146431 /*
146432 ** An instance of the WhereScan object is used as an iterator for locating
146433 ** terms in the WHERE clause that are useful to the query planner.
146434 */
@@ -146528,11 +147016,10 @@
146528 ** to construct WhereLoop objects for a particular query.
146529 */
146530 struct WhereLoopBuilder {
146531 WhereInfo *pWInfo; /* Information about this WHERE */
146532 WhereClause *pWC; /* WHERE clause terms */
146533 ExprList *pOrderBy; /* ORDER BY clause */
146534 WhereLoop *pNew; /* Template WhereLoop */
146535 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
146536 #ifdef SQLITE_ENABLE_STAT4
146537 UnpackedRecord *pRec; /* Probe for stat4 (if required) */
146538 int nRecValid; /* Number of valid fields currently in pRec */
@@ -146596,10 +147083,13 @@
146596 Parse *pParse; /* Parsing and code generating context */
146597 SrcList *pTabList; /* List of tables in the join */
146598 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
146599 ExprList *pResultSet; /* Result set of the query */
146600 Expr *pWhere; /* The complete WHERE clause */
 
 
 
146601 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
146602 int iContinue; /* Jump here to continue with next record */
146603 int iBreak; /* Jump here to break out of the loop */
146604 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
146605 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -146681,10 +147171,11 @@
146681
146682 /* whereexpr.c: */
146683 SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
146684 SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
146685 SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
 
146686 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
146687 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
146688 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
146689 SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
146690 SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
@@ -146751,10 +147242,11 @@
146751 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
146752 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
146753 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
146754 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
146755 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
 
146756
146757 #endif /* !defined(SQLITE_WHEREINT_H) */
146758
146759 /************** End of whereInt.h ********************************************/
146760 /************** Continuing where we left off in wherecode.c ******************/
@@ -147561,10 +148053,13 @@
147561 regBase = r1;
147562 }else{
147563 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
147564 }
147565 }
 
 
 
147566 if( pTerm->eOperator & WO_IN ){
147567 if( pTerm->pExpr->flags & EP_xIsSelect ){
147568 /* No affinity ever needs to be (or should be) applied to a value
147569 ** from the RHS of an "? IN (SELECT ...)" expression. The
147570 ** sqlite3FindInIndex() routine has already ensured that the
@@ -147575,11 +148070,12 @@
147575 Expr *pRight = pTerm->pExpr->pRight;
147576 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
147577 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
147578 VdbeCoverage(v);
147579 }
147580 if( pParse->db->mallocFailed==0 && pParse->nErr==0 ){
 
147581 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
147582 zAff[j] = SQLITE_AFF_BLOB;
147583 }
147584 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
147585 zAff[j] = SQLITE_AFF_BLOB;
@@ -148265,15 +148761,31 @@
148265 for(j=0; j<nConstraint; j++){
148266 int iTarget = iReg+j+2;
148267 pTerm = pLoop->aLTerm[j];
148268 if( NEVER(pTerm==0) ) continue;
148269 if( pTerm->eOperator & WO_IN ){
148270 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148271 addrNotFound = pLevel->addrNxt;
 
 
 
 
 
 
 
148272 }else{
148273 Expr *pRight = pTerm->pExpr->pRight;
148274 codeExprOrVector(pParse, pRight, iTarget, 1);
 
 
 
 
 
 
 
 
 
148275 }
148276 }
148277 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
148278 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
148279 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
@@ -148292,17 +148804,23 @@
148292 iIn = pLevel->u.in.nIn;
148293 }else{
148294 iIn = 0;
148295 }
148296 for(j=nConstraint-1; j>=0; j--){
 
148297 pTerm = pLoop->aLTerm[j];
148298 if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
 
 
 
 
 
 
 
148299 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
148300 disableTerm(pLevel, pTerm);
148301 }else if( (pTerm->eOperator & WO_IN)!=0
148302 && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1
148303 ){
148304 Expr *pCompare; /* The comparison operator */
148305 Expr *pRight; /* RHS of the comparison */
148306 VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
148307
148308 /* Reload the constraint value into reg[iReg+j+2]. The same value
@@ -149028,11 +149546,11 @@
149028 regRowid = ++pParse->nMem;
149029 }
149030 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
149031
149032 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
149033 ** Then for every term xN, evaluate as the subexpression: xN AND z
149034 ** That way, terms in y that are factored into the disjunction will
149035 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
149036 **
149037 ** Actually, each subexpression is converted to "xN AND w" where w is
149038 ** the "interesting" terms of z - terms that did not originate in the
@@ -149040,19 +149558,28 @@
149040 ** indices.
149041 **
149042 ** This optimization also only applies if the (x1 OR x2 OR ...) term
149043 ** is not contained in the ON clause of a LEFT JOIN.
149044 ** See ticket http://www.sqlite.org/src/info/f2369304e4
 
 
 
 
 
 
149045 */
149046 if( pWC->nTerm>1 ){
149047 int iTerm;
149048 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
149049 Expr *pExpr = pWC->a[iTerm].pExpr;
149050 if( &pWC->a[iTerm] == pTerm ) continue;
149051 testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
149052 testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
149053 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
 
 
 
149054 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
149055 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
149056 pExpr = sqlite3ExprDup(db, pExpr, 0);
149057 pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
149058 }
@@ -149091,13 +149618,13 @@
149091 pOrExpr = pAndExpr;
149092 }
149093 /* Loop through table entries that match term pOrTerm. */
149094 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
149095 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
149096 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
149097 WHERE_OR_SUBCLAUSE, iCovCur);
149098 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
149099 if( pSubWInfo ){
149100 WhereLoop *pSubLoop;
149101 int addrExplain = sqlite3WhereExplainOneScan(
149102 pParse, pOrTab, &pSubWInfo->a[0], 0
149103 );
@@ -149831,11 +150358,11 @@
149831 void *pNotUsed;
149832 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
149833 assert( pVtab!=0 );
149834 assert( pVtab->pModule!=0 );
149835 assert( !ExprHasProperty(pExpr, EP_IntValue) );
149836 pMod = (sqlite3_module *)pVtab->pModule;
149837 if( pMod->xFindFunction!=0 ){
149838 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
149839 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
149840 *peOp2 = i;
149841 *ppRight = pList->a[1].pExpr;
@@ -150788,11 +151315,14 @@
150788 ** new terms for each component comparison - "a = ?" and "b = ?". The
150789 ** new terms completely replace the original vector comparison, which is
150790 ** no longer used.
150791 **
150792 ** This is only required if at least one side of the comparison operation
150793 ** is not a sub-select. */
 
 
 
150794 if( (pExpr->op==TK_EQ || pExpr->op==TK_IS)
150795 && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1
150796 && sqlite3ExprVectorSize(pExpr->pRight)==nLeft
150797 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
150798 || (pExpr->pRight->flags & EP_xIsSelect)==0)
@@ -150805,11 +151335,11 @@
150805 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft);
150806 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft);
150807
150808 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
150809 transferJoinMarkings(pNew, pExpr);
150810 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
150811 exprAnalyze(pSrc, pWC, idxNew);
150812 }
150813 pTerm = &pWC->a[idxTerm];
150814 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
150815 pTerm->eOperator = 0;
@@ -150930,10 +151460,117 @@
150930 }else{
150931 sqlite3WhereSplit(pWC, pE2->pLeft, op);
150932 sqlite3WhereSplit(pWC, pE2->pRight, op);
150933 }
150934 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150935
150936 /*
150937 ** Initialize a preallocated WhereClause structure.
150938 */
150939 SQLITE_PRIVATE void sqlite3WhereClauseInit(
@@ -150966,10 +151603,11 @@
150966 for(i=pWC->nBase; i<pWC->nTerm; i++){
150967 assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 );
150968 }
150969 #endif
150970 while(1){
 
150971 if( a->wtFlags & TERM_DYNAMIC ){
150972 sqlite3ExprDelete(db, a->pExpr);
150973 }
150974 if( a->wtFlags & (TERM_ORINFO|TERM_ANDINFO) ){
150975 if( a->wtFlags & TERM_ORINFO ){
@@ -151123,10 +151761,11 @@
151123 if( pColRef==0 ) return;
151124 pColRef->iTable = pItem->iCursor;
151125 pColRef->iColumn = k++;
151126 assert( ExprUseYTab(pColRef) );
151127 pColRef->y.pTab = pTab;
 
151128 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
151129 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
151130 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
151131 if( pItem->fg.jointype & JT_LEFT ){
151132 sqlite3SetJoinExpr(pTerm, pItem->iCursor);
@@ -151167,12 +151806,18 @@
151167 ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
151168 ** agree on the structure, all will be well.
151169 */
151170 typedef struct HiddenIndexInfo HiddenIndexInfo;
151171 struct HiddenIndexInfo {
151172 WhereClause *pWC; /* The Where clause being analyzed */
151173 Parse *pParse; /* The parsing context */
 
 
 
 
 
 
151174 };
151175
151176 /* Forward declaration of methods */
151177 static int whereLoopResize(sqlite3*, WhereLoop*, int);
151178
@@ -152232,31 +152877,33 @@
152232
152233 #ifndef SQLITE_OMIT_VIRTUALTABLE
152234 /*
152235 ** Allocate and populate an sqlite3_index_info structure. It is the
152236 ** responsibility of the caller to eventually release the structure
152237 ** by passing the pointer returned by this function to sqlite3_free().
152238 */
152239 static sqlite3_index_info *allocateIndexInfo(
152240 Parse *pParse, /* The parsing context */
152241 WhereClause *pWC, /* The WHERE clause being analyzed */
152242 Bitmask mUnusable, /* Ignore terms with these prereqs */
152243 SrcItem *pSrc, /* The FROM clause term that is the vtab */
152244 ExprList *pOrderBy, /* The ORDER BY clause */
152245 u16 *pmNoOmit /* Mask of terms not to omit */
152246 ){
152247 int i, j;
152248 int nTerm;
 
152249 struct sqlite3_index_constraint *pIdxCons;
152250 struct sqlite3_index_orderby *pIdxOrderBy;
152251 struct sqlite3_index_constraint_usage *pUsage;
152252 struct HiddenIndexInfo *pHidden;
152253 WhereTerm *pTerm;
152254 int nOrderBy;
152255 sqlite3_index_info *pIdxInfo;
152256 u16 mNoOmit = 0;
152257 const Table *pTab;
 
 
152258
152259 assert( pSrc!=0 );
152260 pTab = pSrc->pTab;
152261 assert( pTab!=0 );
152262 assert( IsVirtual(pTab) );
@@ -152274,10 +152921,11 @@
152274 testcase( pTerm->eOperator & WO_ISNULL );
152275 testcase( pTerm->eOperator & WO_IS );
152276 testcase( pTerm->eOperator & WO_ALL );
152277 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
152278 if( pTerm->wtFlags & TERM_VNULL ) continue;
 
152279 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152280 assert( pTerm->u.x.leftColumn>=XN_ROWID );
152281 assert( pTerm->u.x.leftColumn<pTab->nCol );
152282
152283 /* tag-20191211-002: WHERE-clause constraints are not useful to the
@@ -152335,40 +152983,49 @@
152335 }
152336
152337 /* No matches cause a break out of the loop */
152338 break;
152339 }
152340 if( i==n){
152341 nOrderBy = n;
 
 
 
152342 }
152343 }
152344
152345 /* Allocate the sqlite3_index_info structure
152346 */
152347 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
152348 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
152349 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
 
152350 if( pIdxInfo==0 ){
152351 sqlite3ErrorMsg(pParse, "out of memory");
152352 return 0;
152353 }
152354 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
152355 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
152356 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
152357 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
152358 pIdxInfo->aConstraint = pIdxCons;
152359 pIdxInfo->aOrderBy = pIdxOrderBy;
152360 pIdxInfo->aConstraintUsage = pUsage;
152361 pHidden->pWC = pWC;
152362 pHidden->pParse = pParse;
 
 
152363 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152364 u16 op;
152365 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152366 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152367 pIdxCons[j].iTermOffset = i;
152368 op = pTerm->eOperator & WO_ALL;
152369 if( op==WO_IN ) op = WO_EQ;
 
 
 
152370 if( op==WO_AUX ){
152371 pIdxCons[j].op = pTerm->eMatchOp;
152372 }else if( op & (WO_ISNULL|WO_IS) ){
152373 if( op==WO_ISNULL ){
152374 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
@@ -152414,10 +153071,28 @@
152414 pIdxInfo->nOrderBy = j;
152415
152416 *pmNoOmit = mNoOmit;
152417 return pIdxInfo;
152418 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152419
152420 /*
152421 ** The table object reference passed as the second argument to this function
152422 ** must represent a virtual table. This function invokes the xBestIndex()
152423 ** method of the virtual table with the sqlite3_index_info object that
@@ -152436,11 +153111,13 @@
152436 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
152437 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
152438 int rc;
152439
152440 whereTraceIndexInfoInputs(p);
 
152441 rc = pVtab->pModule->xBestIndex(pVtab, p);
 
152442 whereTraceIndexInfoOutputs(p);
152443
152444 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
152445 if( rc==SQLITE_NOMEM ){
152446 sqlite3OomFault(pParse->db);
@@ -154566,10 +155243,19 @@
154566 }
154567 return rc;
154568 }
154569
154570 #ifndef SQLITE_OMIT_VIRTUALTABLE
 
 
 
 
 
 
 
 
 
154571
154572 /*
154573 ** Argument pIdxInfo is already populated with all constraints that may
154574 ** be used by the virtual table identified by pBuilder->pNew->iTab. This
154575 ** function marks a subset of those constraints usable, invokes the
@@ -154594,13 +155280,15 @@
154594 Bitmask mPrereq, /* Mask of tables that must be used. */
154595 Bitmask mUsable, /* Mask of usable tables */
154596 u16 mExclude, /* Exclude terms using these operators */
154597 sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */
154598 u16 mNoOmit, /* Do not omit these constraints */
154599 int *pbIn /* OUT: True if plan uses an IN(...) op */
 
154600 ){
154601 WhereClause *pWC = pBuilder->pWC;
 
154602 struct sqlite3_index_constraint *pIdxCons;
154603 struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
154604 int i;
154605 int mxTerm;
154606 int rc = SQLITE_OK;
@@ -154619,10 +155307,11 @@
154619 for(i=0; i<nConstraint; i++, pIdxCons++){
154620 WhereTerm *pTerm = &pWC->a[pIdxCons->iTermOffset];
154621 pIdxCons->usable = 0;
154622 if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight
154623 && (pTerm->eOperator & mExclude)==0
 
154624 ){
154625 pIdxCons->usable = 1;
154626 }
154627 }
154628
@@ -154634,10 +155323,11 @@
154634 pIdxInfo->orderByConsumed = 0;
154635 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
154636 pIdxInfo->estimatedRows = 25;
154637 pIdxInfo->idxFlags = 0;
154638 pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
 
154639
154640 /* Invoke the virtual table xBestIndex() method */
154641 rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
154642 if( rc ){
154643 if( rc==SQLITE_CONSTRAINT ){
@@ -154651,12 +155341,12 @@
154651 return rc;
154652 }
154653
154654 mxTerm = -1;
154655 assert( pNew->nLSlot>=nConstraint );
154656 for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
154657 pNew->u.vtab.omitMask = 0;
154658 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
154659 for(i=0; i<nConstraint; i++, pIdxCons++){
154660 int iTerm;
154661 if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
154662 WhereTerm *pTerm;
@@ -154686,21 +155376,41 @@
154686 testcase( i!=iTerm );
154687 pNew->u.vtab.omitMask |= 1<<iTerm;
154688 }else{
154689 testcase( i!=iTerm );
154690 }
 
 
 
154691 }
154692 if( (pTerm->eOperator & WO_IN)!=0 ){
 
 
154693 /* A virtual table that is constrained by an IN clause may not
154694 ** consume the ORDER BY clause because (1) the order of IN terms
154695 ** is not necessarily related to the order of output terms and
154696 ** (2) Multiple outputs from a single IN value will not merge
154697 ** together. */
154698 pIdxInfo->orderByConsumed = 0;
154699 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
154700 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
154701 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154702 }
154703 }
154704
154705 pNew->nLTerm = mxTerm+1;
154706 for(i=0; i<=mxTerm; i++){
@@ -154769,10 +155479,77 @@
154769 }
154770 zRet = (pC ? pC->zName : sqlite3StrBINARY);
154771 }
154772 return zRet;
154773 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154774
154775 /*
154776 ** Add all WhereLoop objects for a table of the join identified by
154777 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
154778 **
@@ -154811,35 +155588,43 @@
154811 int nConstraint; /* Number of constraints in p */
154812 int bIn; /* True if plan uses IN(...) operator */
154813 WhereLoop *pNew;
154814 Bitmask mBest; /* Tables used by best possible plan */
154815 u16 mNoOmit;
 
154816
154817 assert( (mPrereq & mUnusable)==0 );
154818 pWInfo = pBuilder->pWInfo;
154819 pParse = pWInfo->pParse;
154820 pWC = pBuilder->pWC;
154821 pNew = pBuilder->pNew;
154822 pSrc = &pWInfo->pTabList->a[pNew->iTab];
154823 assert( IsVirtual(pSrc->pTab) );
154824 p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy,
154825 &mNoOmit);
154826 if( p==0 ) return SQLITE_NOMEM_BKPT;
154827 pNew->rSetup = 0;
154828 pNew->wsFlags = WHERE_VIRTUALTABLE;
154829 pNew->nLTerm = 0;
154830 pNew->u.vtab.needFree = 0;
154831 nConstraint = p->nConstraint;
154832 if( whereLoopResize(pParse->db, pNew, nConstraint) ){
154833 sqlite3DbFree(pParse->db, p);
154834 return SQLITE_NOMEM_BKPT;
154835 }
154836
154837 /* First call xBestIndex() with all constraints usable. */
154838 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
154839 WHERETRACE(0x40, (" VirtualOne: all usable\n"));
154840 rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
 
 
 
 
 
 
 
 
154841
154842 /* If the call to xBestIndex() with all terms enabled produced a plan
154843 ** that does not require any source tables (IOW: a plan with mBest==0)
154844 ** and does not use an IN(...) operator, then there is no point in making
154845 ** any further calls to xBestIndex() since they will all return the same
@@ -154853,11 +155638,11 @@
154853 /* If the plan produced by the earlier call uses an IN(...) term, call
154854 ** xBestIndex again, this time with IN(...) terms disabled. */
154855 if( bIn ){
154856 WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n"));
154857 rc = whereLoopAddVirtualOne(
154858 pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn);
154859 assert( bIn==0 );
154860 mBestNoIn = pNew->prereq & ~mPrereq;
154861 if( mBestNoIn==0 ){
154862 seenZero = 1;
154863 seenZeroNoIN = 1;
@@ -154880,11 +155665,11 @@
154880 if( mNext==ALLBITS ) break;
154881 if( mNext==mBest || mNext==mBestNoIn ) continue;
154882 WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
154883 (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext));
154884 rc = whereLoopAddVirtualOne(
154885 pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn);
154886 if( pNew->prereq==mPrereq ){
154887 seenZero = 1;
154888 if( bIn==0 ) seenZeroNoIN = 1;
154889 }
154890 }
@@ -154893,26 +155678,26 @@
154893 ** that requires no source tables at all (i.e. one guaranteed to be
154894 ** usable), make a call here with all source tables disabled */
154895 if( rc==SQLITE_OK && seenZero==0 ){
154896 WHERETRACE(0x40, (" VirtualOne: all disabled\n"));
154897 rc = whereLoopAddVirtualOne(
154898 pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn);
154899 if( bIn==0 ) seenZeroNoIN = 1;
154900 }
154901
154902 /* If the calls to xBestIndex() have so far failed to find a plan
154903 ** that requires no source tables at all and does not use an IN(...)
154904 ** operator, make a final call to obtain one here. */
154905 if( rc==SQLITE_OK && seenZeroNoIN==0 ){
154906 WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n"));
154907 rc = whereLoopAddVirtualOne(
154908 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
154909 }
154910 }
154911
154912 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
154913 sqlite3DbFreeNN(pParse->db, p);
154914 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
154915 return rc;
154916 }
154917 #endif /* SQLITE_OMIT_VIRTUALTABLE */
154918
@@ -154952,11 +155737,10 @@
154952 WhereTerm *pOrTerm;
154953 int once = 1;
154954 int i, j;
154955
154956 sSubBuild = *pBuilder;
154957 sSubBuild.pOrderBy = 0;
154958 sSubBuild.pOrSet = &sCur;
154959
154960 WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
154961 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
154962 if( (pOrTerm->eOperator & WO_AND)!=0 ){
@@ -156310,10 +157094,11 @@
156310 Parse *pParse, /* The parser context */
156311 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
156312 Expr *pWhere, /* The WHERE clause */
156313 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
156314 ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */
 
156315 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
156316 int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
156317 ** If WHERE_USE_LIMIT, then the limit amount */
156318 ){
156319 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
@@ -156344,11 +157129,10 @@
156344 memset(&sWLB, 0, sizeof(sWLB));
156345
156346 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
156347 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
156348 if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
156349 sWLB.pOrderBy = pOrderBy;
156350
156351 /* The number of tables in the FROM clause is limited by the number of
156352 ** bits in a Bitmask
156353 */
156354 testcase( pTabList->nSrc==BMS );
@@ -156387,10 +157171,13 @@
156387 pWInfo->nLevel = nTabList;
156388 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
156389 pWInfo->wctrlFlags = wctrlFlags;
156390 pWInfo->iLimit = iAuxArg;
156391 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
 
 
 
156392 memset(&pWInfo->nOBSat, 0,
156393 offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
156394 memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
156395 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
156396 pMaskSet = &pWInfo->sMaskSet;
@@ -156455,10 +157242,11 @@
156455 #endif
156456 }
156457
156458 /* Analyze all of the subexpressions. */
156459 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
 
156460 if( db->mallocFailed ) goto whereBeginError;
156461
156462 /* Special case: WHERE terms that do not refer to any tables in the join
156463 ** (constant expressions). Evaluate each such term, and jump over all the
156464 ** generated code if the result is not true.
@@ -156554,13 +157342,14 @@
156554 }
156555 }
156556 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
156557 pWInfo->revMask = ALLBITS;
156558 }
156559 if( pParse->nErr || db->mallocFailed ){
156560 goto whereBeginError;
156561 }
 
156562 #ifdef WHERETRACE_ENABLED
156563 if( sqlite3WhereTrace ){
156564 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
156565 if( pWInfo->nOBSat>0 ){
156566 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
@@ -156700,10 +157489,11 @@
156700 testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 );
156701 testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS );
156702 if( pWInfo->eOnePass==ONEPASS_OFF
156703 && pTab->nCol<BMS
156704 && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
 
156705 ){
156706 /* If we know that only a prefix of the record will be used,
156707 ** it is advantageous to reduce the "column count" field in
156708 ** the P4 operand of the OP_OpenRead/Write opcode. */
156709 Bitmask b = pTabItem->colUsed;
@@ -158264,16 +159054,11 @@
158264 ** there could still be references to that table embedded in the
158265 ** result-set or ORDER BY clause of the SELECT statement p. */
158266 sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab);
158267 }
158268
158269 if( rc ){
158270 if( pParse->nErr==0 ){
158271 assert( pParse->db->mallocFailed );
158272 sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM);
158273 }
158274 }
158275 return rc;
158276 }
158277
158278 /*
158279 ** Unlink the Window object from the Select to which it is attached,
@@ -193955,12 +194740,12 @@
193955 sqlite3_result_error_nomem(ctx);
193956 goto jsonSetDone;
193957 }else if( x.nErr ){
193958 goto jsonSetDone;
193959 }else if( pNode && (bApnd || bIsSet) ){
193960 testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
193961 assert( pNode->eU!=3 || pNode->eU!=5 );
193962 VVA( pNode->eU = 4 );
193963 pNode->jnFlags |= (u8)JNODE_REPLACE;
193964 pNode->u.iReplace = i + 1;
193965 }
193966 }
@@ -194737,11 +195522,11 @@
194737 sqlite3_module *pModule;
194738 } aMod[] = {
194739 { "json_each", &jsonEachModule },
194740 { "json_tree", &jsonTreeModule },
194741 };
194742 int i;
194743 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
194744 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
194745 }
194746 return rc;
194747 }
@@ -233334,11 +234119,11 @@
233334 int nArg, /* Number of args */
233335 sqlite3_value **apUnused /* Function arguments */
233336 ){
233337 assert( nArg==0 );
233338 UNUSED_PARAM2(nArg, apUnused);
233339 sqlite3_result_text(pCtx, "fts5: 2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec", -1, SQLITE_TRANSIENT);
233340 }
233341
233342 /*
233343 ** Return true if zName is the extension on one of the shadow tables used
233344 ** by this module.
233345
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -4656,10 +4656,12 @@
4656 ** still make the distinction between protected and unprotected
4657 ** sqlite3_value objects even when not strictly required.
4658 **
4659 ** ^The sqlite3_value objects that are passed as parameters into the
4660 ** implementation of [application-defined SQL functions] are protected.
4661 ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4662 ** are protected.
4663 ** ^The sqlite3_value object returned by
4664 ** [sqlite3_column_value()] is unprotected.
4665 ** Unprotected sqlite3_value objects may only be used as arguments
4666 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4667 ** [sqlite3_value_dup()].
@@ -7435,28 +7437,60 @@
7437 /*
7438 ** CAPI3REF: Virtual Table Constraint Operator Codes
7439 **
7440 ** These macros define the allowed values for the
7441 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7442 ** an operator that is part of a constraint term in the WHERE clause of
7443 ** a query that uses a [virtual table].
7444 **
7445 ** ^The left-hand operand of the operator is given by the corresponding
7446 ** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
7447 ** operand is the rowid.
7448 ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
7449 ** operators have no left-hand operand, and so for those operators the
7450 ** corresponding aConstraint[].iColumn is meaningless and should not be
7451 ** used.
7452 **
7453 ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
7454 ** value 255 are reserved to represent functions that are overloaded
7455 ** by the [xFindFunction|xFindFunction method] of the virtual table
7456 ** implementation.
7457 **
7458 ** The right-hand operands for each constraint might be accessible using
7459 ** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
7460 ** operand is only available if it appears as a single constant literal
7461 ** in the input SQL. If the right-hand operand is another column or an
7462 ** expression (even a constant expression) or a parameter, then the
7463 ** sqlite3_vtab_rhs_value() probably will not be able to extract it.
7464 ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
7465 ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
7466 ** and hence calls to sqlite3_vtab_rhs_value() for those operators will
7467 ** always return SQLITE_NOTFOUND.
7468 **
7469 ** The collating sequence to be used for comparison can be found using
7470 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7471 ** tables, the collating sequence of constraints does not matter (for example
7472 ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7473 ** interface is no commonly needed.
7474 */
7475 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7476 #define SQLITE_INDEX_CONSTRAINT_GT 4
7477 #define SQLITE_INDEX_CONSTRAINT_LE 8
7478 #define SQLITE_INDEX_CONSTRAINT_LT 16
7479 #define SQLITE_INDEX_CONSTRAINT_GE 32
7480 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
7481 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
7482 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
7483 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7484 #define SQLITE_INDEX_CONSTRAINT_NE 68
7485 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7486 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7487 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7488 #define SQLITE_INDEX_CONSTRAINT_IS 72
7489 #define SQLITE_INDEX_CONSTRAINT_LIMIT 73
7490 #define SQLITE_INDEX_CONSTRAINT_OFFSET 74
7491 #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
7492
7493 /*
7494 ** CAPI3REF: Register A Virtual Table Implementation
7495 ** METHOD: sqlite3
7496 **
@@ -9775,25 +9809,26 @@
9809 */
9810 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9811
9812 /*
9813 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9814 ** METHOD: sqlite3_index_info
9815 **
9816 ** This function may only be called from within a call to the [xBestIndex]
9817 ** method of a [virtual table]. This function returns a pointer to a string
9818 ** that is the name of the appropriate collation sequence to use for text
9819 ** comparisons on the constraint identified by its arguments.
9820 **
9821 ** The first argument must be the pointer to the [sqlite3_index_info] object
9822 ** that is the first parameter to the xBestIndex() method. The second argument
9823 ** must be an index into the aConstraint[] array belonging to the
9824 ** sqlite3_index_info structure passed to xBestIndex.
9825 **
9826 ** Important:
9827 ** The first parameter must be the same pointer that is passed into the
9828 ** xBestMethod() method. The first parameter may not be a pointer to a
9829 ** different [sqlite3_index_info] object, even an exact copy.
9830 **
9831 ** The return value is computed as follows:
9832 **
9833 ** <ol>
9834 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9807,10 +9842,240 @@
9842 ** <li><p> Otherwise, "BINARY" is returned.
9843 ** </ol>
9844 */
9845 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9846
9847 /*
9848 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9849 ** METHOD: sqlite3_index_info
9850 **
9851 ** This API may only be used from within an [xBestIndex|xBestIndex method]
9852 ** of a [virtual table] implementation. The result of calling this
9853 ** interface from outside of xBestIndex() is undefined and probably harmful.
9854 **
9855 ** ^The sqlite3_vtab_distinct() interface returns an integer that is
9856 ** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9857 ** gives the virtual table additional information about how the query
9858 ** planner wants the output to be ordered. As long as the virtual table
9859 ** can meet the ordering requirements of the query planner, it may set
9860 ** the "orderByConsumed" flag.
9861 **
9862 ** <ol><li value="0"><p>
9863 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9864 ** that the query planner needs the virtual table to return all rows in the
9865 ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9866 ** [sqlite3_index_info] object. This is the default expectation. If the
9867 ** virtual table outputs all rows in sorted order, then it is always safe for
9868 ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9869 ** the return value from sqlite3_vtab_distinct().
9870 ** <li value="1"><p>
9871 ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9872 ** that the query planner does not need the rows to be returned in sorted order
9873 ** as long as all rows with the same values in all columns identified by the
9874 ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9875 ** is doing a GROUP BY.
9876 ** <li value="2"><p>
9877 ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9878 ** that the query planner does not need the rows returned in any particular
9879 ** order, as long as rows with the same values in all "aOrderBy" columns
9880 ** are adjacent.)^ ^(Furthermore, only a single row for each particular
9881 ** combination of values in the columns identified by the "aOrderBy" field
9882 ** needs to be returned.)^ ^It is always ok for two or more rows with the same
9883 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9884 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9885 ** that have the same value for all columns identified by "aOrderBy".
9886 ** ^However omitting the extra rows is optional.
9887 ** This mode is used for a DISTINCT query.
9888 ** </ol>
9889 **
9890 ** ^For the purposes of comparing virtual table output values to see if the
9891 ** values are same value for sorting purposes, two NULL values are considered
9892 ** to be the same. In other words, the comparison operator is "IS"
9893 ** (or "IS NOT DISTINCT FROM") and not "==".
9894 **
9895 ** If a virtual table implementation is unable to meet the requirements
9896 ** specified above, then it must not set the "orderByConsumed" flag in the
9897 ** [sqlite3_index_info] object or an incorrect answer may result.
9898 **
9899 ** ^A virtual table implementation is always free to return rows in any order
9900 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9901 ** the "orderByConsumed" flag is unset, the query planner will add extra
9902 ** [bytecode] to ensure that the final results returned by the SQL query are
9903 ** ordered correctly. The use of the "orderByConsumed" flag and the
9904 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9905 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9906 ** flag might help queries against a virtual table to run faster. Being
9907 ** overly aggressive and setting the "orderByConsumed" flag when it is not
9908 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9909 ** results.
9910 */
9911 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9912
9913 /*
9914 ** CAPI3REF: Identify and handle IN constraints in xBestIndex
9915 **
9916 ** This interface may only be used from within an
9917 ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9918 ** The result of invoking this interface from any other context is
9919 ** undefined and probably harmful.
9920 **
9921 ** ^(A constraint on a virtual table of the form
9922 ** "[IN operator|column IN (...)]" is
9923 ** communicated to the xBestIndex method as a
9924 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9925 ** this constraint, it must set the corresponding
9926 ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9927 ** the usual mode of handling IN operators, SQLite generates [bytecode]
9928 ** that invokes the [xFilter|xFilter() method] once for each value
9929 ** on the right-hand side of the IN operator.)^ Thus the virtual table
9930 ** only sees a single value from the right-hand side of the IN operator
9931 ** at a time.
9932 **
9933 ** In some cases, however, it would be advantageous for the virtual
9934 ** table to see all values on the right-hand of the IN operator all at
9935 ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9936 **
9937 ** <ol>
9938 ** <li><p>
9939 ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9940 ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9941 ** is an [IN operator] that can be processed all at once. ^In other words,
9942 ** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9943 ** by which the virtual table can ask SQLite if all-at-once processing
9944 ** of the IN operator is even possible.
9945 **
9946 ** <li><p>
9947 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9948 ** to SQLite that the virtual table does or does not want to process
9949 ** the IN operator all-at-once, respectively. ^Thus when the third
9950 ** parameter (F) is non-negative, this interface is the mechanism by
9951 ** which the virtual table tells SQLite how it wants to process the
9952 ** IN operator.
9953 ** </ol>
9954 **
9955 ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9956 ** within the same xBestIndex method call. ^For any given P,N pair,
9957 ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9958 ** within the same xBestIndex call. ^If the interface returns true
9959 ** (non-zero), that means that the constraint is an IN operator
9960 ** that can be processed all-at-once. ^If the constraint is not an IN
9961 ** operator or cannot be processed all-at-once, then the interface returns
9962 ** false.
9963 **
9964 ** ^(All-at-once processing of the IN operator is selected if both of the
9965 ** following conditions are met:
9966 **
9967 ** <ol>
9968 ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9969 ** integer. This is how the virtual table tells SQLite that it wants to
9970 ** use the N-th constraint.
9971 **
9972 ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9973 ** non-negative had F>=1.
9974 ** </ol>)^
9975 **
9976 ** ^If either or both of the conditions above are false, then SQLite uses
9977 ** the traditional one-at-a-time processing strategy for the IN constraint.
9978 ** ^If both conditions are true, then the argvIndex-th parameter to the
9979 ** xFilter method will be an [sqlite3_value] that appears to be NULL,
9980 ** but which can be passed to [sqlite3_vtab_in_first()] and
9981 ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9982 ** of the IN constraint.
9983 */
9984 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9985
9986 /*
9987 ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9988 **
9989 ** These interfaces are only useful from within the
9990 ** [xFilter|xFilter() method] of a [virtual table] implementation.
9991 ** The result of invoking these interfaces from any other context
9992 ** is undefined and probably harmful.
9993 **
9994 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9995 ** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9996 ** xFilter method which invokes these routines, and specifically
9997 ** a parameter that was previously selected for all-at-once IN constraint
9998 ** processing use the [sqlite3_vtab_in()] interface in the
9999 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10000 ** an xFilter argument that was selected for all-at-once IN constraint
10001 ** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
10002 ** exhibit some other undefined or harmful behavior.
10003 **
10004 ** ^(Use these routines to access all values on the right-hand side
10005 ** of the IN constraint using code like the following:
10006 **
10007 ** <blockquote><pre>
10008 ** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
10009 ** &nbsp; rc==SQLITE_OK && pVal
10010 ** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
10011 ** &nbsp; ){
10012 ** &nbsp; // do something with pVal
10013 ** &nbsp; }
10014 ** &nbsp; if( rc!=SQLITE_OK ){
10015 ** &nbsp; // an error has occurred
10016 ** &nbsp; }
10017 ** </pre></blockquote>)^
10018 **
10019 ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
10020 ** routines return SQLITE_OK and set *P to point to the first or next value
10021 ** on the RHS of the IN constraint. ^If there are no more values on the
10022 ** right hand side of the IN constraint, then *P is set to NULL and these
10023 ** routines return [SQLITE_DONE]. ^The return value might be
10024 ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
10025 **
10026 ** The *ppOut values returned by these routines are only valid until the
10027 ** next call to either of these routines or until the end of the xFilter
10028 ** method from which these routines were called. If the virtual table
10029 ** implementation needs to retain the *ppOut values for longer, it must make
10030 ** copies. The *ppOut values are [protected sqlite3_value|protected].
10031 */
10032 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
10033 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
10034
10035 /*
10036 ** CAPI3REF: Constraint values in xBestIndex()
10037 ** METHOD: sqlite3_index_info
10038 **
10039 ** This API may only be used from within the [xBestIndex|xBestIndex method]
10040 ** of a [virtual table] implementation. The result of calling this interface
10041 ** from outside of an xBestIndex method are undefined and probably harmful.
10042 **
10043 ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
10044 ** the [xBestIndex] method of a [virtual table] implementation, with P being
10045 ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
10046 ** J being a 0-based index into P->aConstraint[], then this routine
10047 ** attempts to set *V to the value of the right-hand operand of
10048 ** that constraint if the right-hand operand is known. ^If the
10049 ** right-hand operand is not known, then *V is set to a NULL pointer.
10050 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10051 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
10052 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10053 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10054 ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
10055 ** something goes wrong.
10056 **
10057 ** The sqlite3_vtab_rhs_value() interface is usually only successful if
10058 ** the right-hand operand of a constraint is a literal value in the original
10059 ** SQL statement. If the right-hand operand is an expression or a reference
10060 ** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
10061 ** will probably return [SQLITE_NOTFOUND].
10062 **
10063 ** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
10064 ** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
10065 ** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
10066 **
10067 ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
10068 ** and remains valid for the duration of the xBestIndex method call.
10069 ** ^When xBestIndex returns, the sqlite3_value object returned by
10070 ** sqlite3_vtab_rhs_value() is automatically deallocated.
10071 **
10072 ** The "_rhs_" in the name of this routine is an appreviation for
10073 ** "Right-Hand Side".
10074 */
10075 SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
10076
10077 /*
10078 ** CAPI3REF: Conflict resolution modes
10079 ** KEYWORDS: {conflict resolution mode}
10080 **
10081 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -14374,14 +14639,15 @@
14639 #define BMS ((int)(sizeof(Bitmask)*8))
14640
14641 /*
14642 ** A bit in a Bitmask
14643 */
14644 #define MASKBIT(n) (((Bitmask)1)<<(n))
14645 #define MASKBIT64(n) (((u64)1)<<(n))
14646 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14647 #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
14648 #define ALLBITS ((Bitmask)-1)
14649
14650 /* A VList object records a mapping between parameters/variables/wildcards
14651 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
14652 ** variable number associated with that parameter. See the format description
14653 ** on the sqlite3VListAdd() routine for more information. A VList is really
@@ -15403,21 +15669,22 @@
15669 #define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
15670 #define OP_VBegin 169
15671 #define OP_VCreate 170
15672 #define OP_VDestroy 171
15673 #define OP_VOpen 172
15674 #define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */
15675 #define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */
15676 #define OP_VRename 175
15677 #define OP_Pagecount 176
15678 #define OP_MaxPgcnt 177
15679 #define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */
15680 #define OP_Trace 179
15681 #define OP_CursorHint 180
15682 #define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */
15683 #define OP_Noop 182
15684 #define OP_Explain 183
15685 #define OP_Abortable 184
15686
15687 /* Properties such as "out2" or "jump" that are specified in
15688 ** comments following the "case" for each opcode in the vdbe.c
15689 ** are encoded into bitvectors as follows:
15690 */
@@ -15447,13 +15714,13 @@
15714 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15715 /* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
15716 /* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15717 /* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
15718 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15719 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\
15720 /* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15721 /* 184 */ 0x00,}
15722
15723 /* The resolve3P2Values() routine is able to run faster if it knows
15724 ** the value of the largest JUMP opcode. The smaller the maximum
15725 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15726 ** generated this include file strives to group all JUMP opcodes
@@ -18576,10 +18843,11 @@
18843 ** initialized as they will be set before being used. The boundary is
18844 ** determined by offsetof(Parse,aTempReg).
18845 **************************************************************************/
18846
18847 int aTempReg[8]; /* Holding area for temporary registers */
18848 Parse *pOuterParse; /* Outer Parse object when nested */
18849 Token sNameToken; /* Token with unqualified schema object name */
18850
18851 /************************************************************************
18852 ** Above is constant between recursions. Below is reset before and after
18853 ** each recursion. The boundary between these two regions is determined
@@ -18626,11 +18894,12 @@
18894 #define PARSE_MODE_UNMAP 3
18895
18896 /*
18897 ** Sizes and pointers of various parts of the Parse object.
18898 */
18899 #define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg))
18900 #define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/
18901 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
18902 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
18903 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
18904
18905 /*
@@ -19566,11 +19835,12 @@
19835 #endif
19836 SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe*,int,const char*);
19837 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
19838 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,
19839 Upsert*);
19840 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,
19841 ExprList*,Select*,u16,int);
19842 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
19843 SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
19844 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
19845 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
19846 SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*);
@@ -19966,11 +20236,11 @@
20236 void (*)(sqlite3_context*),
20237 void (*)(sqlite3_context*,int,sqlite3_value **),
20238 FuncDestructor *pDestructor
20239 );
20240 SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
20241 SQLITE_PRIVATE void *sqlite3OomFault(sqlite3*);
20242 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
20243 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
20244 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
20245
20246 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
@@ -20087,11 +20357,12 @@
20357 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
20358 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
20359 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20360 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
20361 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20362 SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*);
20363 SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*);
20364 SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
20365 #ifdef SQLITE_ENABLE_NORMALIZE
20366 SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
20367 #endif
20368 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
@@ -20520,10 +20791,18 @@
20791
20792 #endif /* !defined(_OS_COMMON_H_) */
20793
20794 /************** End of os_common.h *******************************************/
20795 /************** Begin file ctime.c *******************************************/
20796 /* DO NOT EDIT!
20797 ** This file is automatically generated by the script in the canonical
20798 ** SQLite source tree at tool/mkctimec.tcl.
20799 **
20800 ** To modify this header, edit any of the various lists in that script
20801 ** which specify categories of generated conditionals in this file.
20802 */
20803
20804 /*
20805 ** 2010 February 23
20806 **
20807 ** The author disclaims copyright to this source code. In place of
20808 ** a legal notice, here is a blessing:
@@ -20568,13 +20847,10 @@
20847 ** only a handful of compile-time options, so most times this array is usually
20848 ** rather short and uses little memory space.
20849 */
20850 static const char * const sqlite3azCompileOpt[] = {
20851
 
 
 
20852 #ifdef SQLITE_32BIT_ROWID
20853 "32BIT_ROWID",
20854 #endif
20855 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
20856 "4_BYTE_ALIGNED_MALLOC",
@@ -20701,13 +20977,10 @@
20977 "DISABLE_FTS4_DEFERRED",
20978 #endif
20979 #ifdef SQLITE_DISABLE_INTRINSIC
20980 "DISABLE_INTRINSIC",
20981 #endif
 
 
 
20982 #ifdef SQLITE_DISABLE_LFS
20983 "DISABLE_LFS",
20984 #endif
20985 #ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
20986 "DISABLE_PAGECACHE_OVERFLOW_STATS",
@@ -21104,10 +21377,13 @@
21377 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
21378 "OMIT_INTEGRITY_CHECK",
21379 #endif
21380 #ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
21381 "OMIT_INTROSPECTION_PRAGMAS",
21382 #endif
21383 #ifdef SQLITE_OMIT_JSON
21384 "OMIT_JSON",
21385 #endif
21386 #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
21387 "OMIT_LIKE_OPTIMIZATION",
21388 #endif
21389 #ifdef SQLITE_OMIT_LOAD_EXTENSION
@@ -21293,14 +21569,12 @@
21569 "WIN32_MALLOC",
21570 #endif
21571 #ifdef SQLITE_ZERO_MALLOC
21572 "ZERO_MALLOC",
21573 #endif
21574
21575 } ;
 
 
21576
21577 SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
21578 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
21579 return (const char**)sqlite3azCompileOpt;
21580 }
@@ -22214,10 +22488,28 @@
22488 i64 iKey2; /* Second key value passed to hook */
22489 Mem *aNew; /* Array of new.* values */
22490 Table *pTab; /* Schema object being upated */
22491 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
22492 };
22493
22494 /*
22495 ** An instance of this object is used to pass an vector of values into
22496 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
22497 ** set of values on the right-hand side of an IN constraint.
22498 **
22499 ** The value as passed into xFilter is an sqlite3_value with a "pointer"
22500 ** type, such as is generated by sqlite3_result_pointer() and read by
22501 ** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null
22502 ** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces
22503 ** know how to use this object to step through all the values in the
22504 ** right operand of the IN constraint.
22505 */
22506 typedef struct ValueList ValueList;
22507 struct ValueList {
22508 BtCursor *pCsr; /* An ephemeral table holding all values */
22509 sqlite3_value *pOut; /* Register to hold each decoded output value */
22510 };
22511
22512 /*
22513 ** Function prototypes
22514 */
22515 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
@@ -23406,11 +23698,12 @@
23698 */
23699 static int parseModifier(
23700 sqlite3_context *pCtx, /* Function context */
23701 const char *z, /* The text of the modifier */
23702 int n, /* Length of zMod in bytes */
23703 DateTime *p, /* The date/time value to be modified */
23704 int idx /* Parameter index of the modifier */
23705 ){
23706 int rc = 1;
23707 double r;
23708 switch(sqlite3UpperToLower[(u8)z[0]] ){
23709 case 'a': {
@@ -23419,10 +23712,11 @@
23712 **
23713 ** If rawS is available, then interpret as a julian day number, or
23714 ** a unix timestamp, depending on its magnitude.
23715 */
23716 if( sqlite3_stricmp(z, "auto")==0 ){
23717 if( idx>1 ) return 1; /* IMP: R-33611-57934 */
23718 if( !p->rawS || p->validJD ){
23719 rc = 0;
23720 p->rawS = 0;
23721 }else if( p->s>=-210866760000 && p->s<=253402300799 ){
23722 r = p->s*1000.0 + 210866760000000.0;
@@ -23443,10 +23737,11 @@
23737 ** is not the first modifier, or if the prior argument is not a numeric
23738 ** value in the allowed range of julian day numbers understood by
23739 ** SQLite (0..5373484.5) then the result will be NULL.
23740 */
23741 if( sqlite3_stricmp(z, "julianday")==0 ){
23742 if( idx>1 ) return 1; /* IMP: R-31176-64601 */
23743 if( p->validJD && p->rawS ){
23744 rc = 0;
23745 p->rawS = 0;
23746 }
23747 }
@@ -23473,10 +23768,11 @@
23768 **
23769 ** Treat the current value of p->s as the number of
23770 ** seconds since 1970. Convert to a real julian day number.
23771 */
23772 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
23773 if( idx>1 ) return 1; /* IMP: R-49255-55373 */
23774 r = p->s*1000.0 + 210866760000000.0;
23775 if( r>=0.0 && r<464269060800000.0 ){
23776 clearYMD_HMS_TZ(p);
23777 p->iJD = (sqlite3_int64)(r + 0.5);
23778 p->validJD = 1;
@@ -23686,11 +23982,11 @@
23982 }
23983 }
23984 for(i=1; i<argc; i++){
23985 z = sqlite3_value_text(argv[i]);
23986 n = sqlite3_value_bytes(argv[i]);
23987 if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1;
23988 }
23989 computeJD(p);
23990 if( p->isError || !validJulianDay(p->iJD) ) return 1;
23991 return 0;
23992 }
@@ -28956,22 +29252,31 @@
29252 /*
29253 ** Call this routine to record the fact that an OOM (out-of-memory) error
29254 ** has happened. This routine will set db->mallocFailed, and also
29255 ** temporarily disable the lookaside memory allocator and interrupt
29256 ** any running VDBEs.
29257 **
29258 ** Always return a NULL pointer so that this routine can be invoked using
29259 **
29260 ** return sqlite3OomFault(db);
29261 **
29262 ** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
29263 ** common case where no OOM occurs.
29264 */
29265 SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
29266 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
29267 db->mallocFailed = 1;
29268 if( db->nVdbeExec>0 ){
29269 AtomicStore(&db->u1.isInterrupted, 1);
29270 }
29271 DisableLookaside;
29272 if( db->pParse ){
29273 sqlite3ErrorMsg(db->pParse, "out of memory");
29274 db->pParse->rc = SQLITE_NOMEM_BKPT;
29275 }
29276 }
29277 return 0;
29278 }
29279
29280 /*
29281 ** This routine reactivates the memory allocator and clears the
29282 ** db->mallocFailed flag as necessary.
@@ -32356,17 +32661,23 @@
32661 */
32662 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
32663 char *zMsg;
32664 va_list ap;
32665 sqlite3 *db = pParse->db;
32666 assert( db!=0 );
32667 assert( db->pParse==pParse );
32668 db->errByteOffset = -2;
32669 va_start(ap, zFormat);
32670 zMsg = sqlite3VMPrintf(db, zFormat, ap);
32671 va_end(ap);
32672 if( db->errByteOffset<-1 ) db->errByteOffset = -1;
32673 if( db->suppressErr ){
32674 sqlite3DbFree(db, zMsg);
32675 if( db->mallocFailed ){
32676 pParse->nErr++;
32677 pParse->rc = SQLITE_NOMEM;
32678 }
32679 }else{
32680 pParse->nErr++;
32681 sqlite3DbFree(db, pParse->zErrMsg);
32682 pParse->zErrMsg = zMsg;
32683 pParse->rc = SQLITE_ERROR;
@@ -34334,21 +34645,22 @@
34645 /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
34646 /* 169 */ "VBegin" OpHelp(""),
34647 /* 170 */ "VCreate" OpHelp(""),
34648 /* 171 */ "VDestroy" OpHelp(""),
34649 /* 172 */ "VOpen" OpHelp(""),
34650 /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
34651 /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34652 /* 175 */ "VRename" OpHelp(""),
34653 /* 176 */ "Pagecount" OpHelp(""),
34654 /* 177 */ "MaxPgcnt" OpHelp(""),
34655 /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34656 /* 179 */ "Trace" OpHelp(""),
34657 /* 180 */ "CursorHint" OpHelp(""),
34658 /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34659 /* 182 */ "Noop" OpHelp(""),
34660 /* 183 */ "Explain" OpHelp(""),
34661 /* 184 */ "Abortable" OpHelp(""),
34662 };
34663 return azName[i];
34664 }
34665 #endif
34666
@@ -56722,12 +57034,11 @@
57034 ** Once this function has been called, the transaction must either be
57035 ** rolled back or committed. It is not safe to call this function and
57036 ** then continue writing to the database.
57037 */
57038 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
57039 assert( pPager->dbSize>=nPage );
 
57040 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
57041 pPager->dbSize = nPage;
57042
57043 /* At one point the code here called assertTruncateConstraint() to
57044 ** ensure that all pages being truncated away by this operation are,
@@ -63102,11 +63413,13 @@
63413 rc = WAL_RETRY;
63414 goto begin_unreliable_shm_out;
63415 }
63416
63417 /* Allocate a buffer to read frames into */
63418 assert( (pWal->szPage & (pWal->szPage-1))==0 );
63419 assert( pWal->szPage>=512 && pWal->szPage<=65536 );
63420 szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
63421 aFrame = (u8 *)sqlite3_malloc64(szFrame);
63422 if( aFrame==0 ){
63423 rc = SQLITE_NOMEM_BKPT;
63424 goto begin_unreliable_shm_out;
63425 }
@@ -63116,11 +63429,11 @@
63429 ** wal file since the heap-memory wal-index was created. If so, the
63430 ** heap-memory wal-index is discarded and WAL_RETRY returned to
63431 ** the caller. */
63432 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
63433 aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
63434 for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->szPage);
63435 iOffset+szFrame<=szWal;
63436 iOffset+=szFrame
63437 ){
63438 u32 pgno; /* Database page number for frame */
63439 u32 nTruncate; /* dbsize field from frame header */
@@ -68934,13 +69247,17 @@
69247 freeTempSpace(pBt);
69248 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
69249 pageSize-usableSize);
69250 return rc;
69251 }
69252 if( nPage>nPageFile ){
69253 if( sqlite3WritableSchema(pBt->db)==0 ){
69254 rc = SQLITE_CORRUPT_BKPT;
69255 goto page1_init_failed;
69256 }else{
69257 nPage = nPageFile;
69258 }
69259 }
69260 /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
69261 ** be less than 480. In other words, if the page size is 512, then the
69262 ** reserved space size cannot exceed 32. */
69263 if( usableSize<480 ){
@@ -76691,18 +77008,17 @@
77008 int i = sqlite3FindDbName(pDb, zDb);
77009
77010 if( i==1 ){
77011 Parse sParse;
77012 int rc = 0;
77013 sqlite3ParseObjectInit(&sParse,pDb);
 
77014 if( sqlite3OpenTempDatabase(&sParse) ){
77015 sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
77016 rc = SQLITE_ERROR;
77017 }
77018 sqlite3DbFree(pErrorDb, sParse.zErrMsg);
77019 sqlite3ParseObjectReset(&sParse);
77020 if( rc ){
77021 return 0;
77022 }
77023 }
77024
@@ -78910,15 +79226,11 @@
79226 const char *zNeg = "";
79227 int rc = SQLITE_OK;
79228
79229 assert( pExpr!=0 );
79230 while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
 
79231 if( op==TK_REGISTER ) op = pExpr->op2;
 
 
 
79232
79233 /* Compressed expressions only appear when parsing the DEFAULT clause
79234 ** on a table column definition, and hence only when pCtx==0. This
79235 ** check ensures that an EP_TokenOnly expression is never passed down
79236 ** into valueFromFunction(). */
@@ -80707,12 +81019,11 @@
81019 ** makes the code easier to read during debugging. None of this happens
81020 ** in a production build.
81021 */
81022 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
81023 assert( p->nOp>0 || p->aOp==0 );
81024 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
 
81025 if( p->nOp ){
81026 assert( p->aOp );
81027 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
81028 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
81029 }
@@ -85436,10 +85747,74 @@
85747 */
85748 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
85749 assert( p );
85750 return sqlite3_value_nochange(p->pOut);
85751 }
85752
85753 /*
85754 ** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
85755 ** sqlite3_vtab_in_next() (if bNext!=0).
85756 */
85757 static int valueFromValueList(
85758 sqlite3_value *pVal, /* Pointer to the ValueList object */
85759 sqlite3_value **ppOut, /* Store the next value from the list here */
85760 int bNext /* 1 for _next(). 0 for _first() */
85761 ){
85762 int rc;
85763 ValueList *pRhs;
85764
85765 *ppOut = 0;
85766 if( pVal==0 ) return SQLITE_MISUSE;
85767 pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList");
85768 if( pRhs==0 ) return SQLITE_MISUSE;
85769 if( bNext ){
85770 rc = sqlite3BtreeNext(pRhs->pCsr, 0);
85771 }else{
85772 int dummy = 0;
85773 rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy);
85774 assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) );
85775 if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE;
85776 }
85777 if( rc==SQLITE_OK ){
85778 u32 sz; /* Size of current row in bytes */
85779 Mem sMem; /* Raw content of current row */
85780 memset(&sMem, 0, sizeof(sMem));
85781 sz = sqlite3BtreePayloadSize(pRhs->pCsr);
85782 rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem);
85783 if( rc==SQLITE_OK ){
85784 u8 *zBuf = (u8*)sMem.z;
85785 u32 iSerial;
85786 sqlite3_value *pOut = pRhs->pOut;
85787 int iOff = 1 + getVarint32(&zBuf[1], iSerial);
85788 sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut);
85789 pOut->enc = ENC(pOut->db);
85790 if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
85791 rc = SQLITE_NOMEM;
85792 }else{
85793 *ppOut = pOut;
85794 }
85795 }
85796 sqlite3VdbeMemRelease(&sMem);
85797 }
85798 return rc;
85799 }
85800
85801 /*
85802 ** Set the iterator value pVal to point to the first value in the set.
85803 ** Set (*ppOut) to point to this value before returning.
85804 */
85805 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){
85806 return valueFromValueList(pVal, ppOut, 0);
85807 }
85808
85809 /*
85810 ** Set the iterator value pVal to point to the next value in the set.
85811 ** Set (*ppOut) to point to this value before returning.
85812 */
85813 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){
85814 return valueFromValueList(pVal, ppOut, 1);
85815 }
85816
85817 /*
85818 ** Return the current time for a statement. If the current time
85819 ** is requested more than once within the same run of a single prepared
85820 ** statement, the exact same time is returned for each invocation regardless
@@ -87537,11 +87912,10 @@
87912 */
87913 static u64 filterHash(const Mem *aMem, const Op *pOp){
87914 int i, mx;
87915 u64 h = 0;
87916
 
87917 assert( pOp->p4type==P4_INT32 );
87918 for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
87919 const Mem *p = &aMem[i];
87920 if( p->flags & (MEM_Int|MEM_IntReal) ){
87921 h += p->u.i;
@@ -89020,11 +89394,11 @@
89394 testcase( pIn1->flags & MEM_Real );
89395 testcase( pIn1->flags & MEM_IntReal );
89396 sqlite3VdbeMemStringify(pIn1, encoding, 1);
89397 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
89398 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
89399 if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
89400 }
89401 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
89402 testcase( pIn3->flags & MEM_Int );
89403 testcase( pIn3->flags & MEM_Real );
89404 testcase( pIn3->flags & MEM_IntReal );
@@ -89846,10 +90220,12 @@
90220 case COLTYPE_TEXT: {
90221 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
90222 break;
90223 }
90224 case COLTYPE_REAL: {
90225 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
90226 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
90227 if( pIn1->flags & MEM_Int ){
90228 /* When applying REAL affinity, if the result is still an MEM_Int
90229 ** that will fit in 6 bytes, then change the type to MEM_IntReal
90230 ** so that we keep the high-resolution integer value but know that
90231 ** the type really wants to be REAL. */
@@ -89863,11 +90239,11 @@
90239 }else{
90240 pIn1->u.r = (double)pIn1->u.i;
90241 pIn1->flags |= MEM_Real;
90242 pIn1->flags &= ~MEM_Int;
90243 }
90244 }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
90245 goto vdbe_type_error;
90246 }
90247 break;
90248 }
90249 default: {
@@ -94592,10 +94968,38 @@
94968 goto no_mem;
94969 }
94970 break;
94971 }
94972 #endif /* SQLITE_OMIT_VIRTUALTABLE */
94973
94974 #ifndef SQLITE_OMIT_VIRTUALTABLE
94975 /* Opcode: VInitIn P1 P2 P3 * *
94976 ** Synopsis: r[P2]=ValueList(P1,P3)
94977 **
94978 ** Set register P2 to be a pointer to a ValueList object for cursor P1
94979 ** with cache register P3 and output register P3+1. This ValueList object
94980 ** can be used as the first argument to sqlite3_vtab_in_first() and
94981 ** sqlite3_vtab_in_next() to extract all of the values stored in the P1
94982 ** cursor. Register P3 is used to hold the values returned by
94983 ** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
94984 */
94985 case OP_VInitIn: { /* out2 */
94986 VdbeCursor *pC; /* The cursor containing the RHS values */
94987 ValueList *pRhs; /* New ValueList object to put in reg[P2] */
94988
94989 pC = p->apCsr[pOp->p1];
94990 pRhs = sqlite3_malloc64( sizeof(*pRhs) );
94991 if( pRhs==0 ) goto no_mem;
94992 pRhs->pCsr = pC->uc.pCursor;
94993 pRhs->pOut = &aMem[pOp->p3];
94994 pOut = out2Prerelease(p, pOp);
94995 pOut->flags = MEM_Null;
94996 sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free);
94997 break;
94998 }
94999 #endif /* SQLITE_OMIT_VIRTUALTABLE */
95000
95001
95002 #ifndef SQLITE_OMIT_VIRTUALTABLE
95003 /* Opcode: VFilter P1 P2 P3 P4 *
95004 ** Synopsis: iplan=r[P3] zplan='P4'
95005 **
@@ -95579,14 +95983,13 @@
95983 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
95984
95985 sqlite3_mutex_enter(db->mutex);
95986
95987 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
95988 while(1){
95989 sqlite3ParseObjectInit(&sParse,db);
95990 if( !pBlob ) goto blob_open_out;
 
95991 sqlite3DbFree(db, zErr);
95992 zErr = 0;
95993
95994 sqlite3BtreeEnterAll(db);
95995 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
@@ -95759,11 +96162,13 @@
96162 sqlite3BtreeLeaveAll(db);
96163 if( db->mallocFailed ){
96164 goto blob_open_out;
96165 }
96166 rc = blobSeekToRow(pBlob, iRow, &zErr);
96167 if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break;
96168 sqlite3ParseObjectReset(&sParse);
96169 }
96170
96171 blob_open_out:
96172 if( rc==SQLITE_OK && db->mallocFailed==0 ){
96173 *ppBlob = (sqlite3_blob *)pBlob;
96174 }else{
@@ -95770,11 +96175,11 @@
96175 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
96176 sqlite3DbFree(db, pBlob);
96177 }
96178 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
96179 sqlite3DbFree(db, zErr);
96180 sqlite3ParseObjectReset(&sParse);
96181 rc = sqlite3ApiExit(db, rc);
96182 sqlite3_mutex_leave(db->mutex);
96183 return rc;
96184 }
96185
@@ -100835,11 +101240,11 @@
101240 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
101241 ){
101242 /* Internal-use-only functions are disallowed unless the
101243 ** SQL is being compiled using sqlite3NestedParse() or
101244 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
101245 ** used to activate internal functions for testing purposes */
101246 no_such_func = 1;
101247 pDef = 0;
101248 }else
101249 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
101250 && !IN_RENAME_OBJECT
@@ -101054,11 +101459,12 @@
101459 sqlite3ErrorMsg(pParse, "row value misused");
101460 }
101461 break;
101462 }
101463 }
101464 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
101465 return pParse->nErr ? WRC_Abort : WRC_Continue;
101466 }
101467
101468 /*
101469 ** pEList is a list of expressions which are really the result set of the
101470 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
@@ -101468,11 +101874,11 @@
101874 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
101875 ** this routine in the correct order.
101876 */
101877 if( (p->selFlags & SF_Expanded)==0 ){
101878 sqlite3SelectPrep(pParse, p, pOuterNC);
101879 return pParse->nErr ? WRC_Abort : WRC_Prune;
101880 }
101881
101882 isCompound = p->pPrior!=0;
101883 nCompound = 0;
101884 pLeftmost = p;
@@ -101516,11 +101922,12 @@
101922 const char *zSavedContext = pParse->zAuthContext;
101923
101924 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
101925 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
101926 pParse->zAuthContext = zSavedContext;
101927 if( pParse->nErr ) return WRC_Abort;
101928 assert( db->mallocFailed==0 );
101929
101930 /* If the number of references to the outer context changed when
101931 ** expressions in the sub-select were resolved, the sub-select
101932 ** is correlated. It is not required to check the refcount on any
101933 ** but the innermost outer context object, as lookupName() increments
@@ -104696,12 +105103,11 @@
105103 Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
105104 Expr *pRhs = pEList->a[i].pExpr;
105105 CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
105106 int j;
105107
105108 assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr );
 
105109 for(j=0; j<nExpr; j++){
105110 if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
105111 assert( pIdx->azColl[j] );
105112 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
105113 continue;
@@ -105173,14 +105579,12 @@
105579 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
105580 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
105581 }
105582 pSel->iLimit = 0;
105583 if( sqlite3Select(pParse, pSel, &dest) ){
105584 pExpr->op2 = pExpr->op;
105585 pExpr->op = TK_ERROR;
 
 
105586 return 0;
105587 }
105588 pExpr->iTable = rReg = dest.iSDParm;
105589 ExprSetVVAProperty(pExpr, EP_NoReduce);
105590 if( addrOnce ){
@@ -105393,14 +105797,13 @@
105797 if( destIfNull==destIfFalse ){
105798 destStep2 = destIfFalse;
105799 }else{
105800 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105801 }
 
105802 for(i=0; i<nVector; i++){
105803 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105804 if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105805 if( sqlite3ExprCanBeNull(p) ){
105806 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
105807 VdbeCoverage(v);
105808 }
105809 }
@@ -108571,11 +108974,13 @@
108974 sqlite3 *db; /* The database connection; */
108975 Vdbe *v; /* The prepared statement under construction */
108976 int r1; /* Temporary registers */
108977
108978 db = pParse->db;
108979 assert( db->pParse==pParse );
108980 if( pParse->nErr ) return;
108981 assert( db->mallocFailed==0 );
108982 pNew = pParse->pNewTable;
108983 assert( pNew );
108984
108985 assert( sqlite3BtreeHoldsAllMutexes(db) );
108986 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -108697,11 +109102,11 @@
109102 sqlite3NestedParse(pParse,
109103 "SELECT CASE WHEN quick_check GLOB 'CHECK*'"
109104 " THEN raise(ABORT,'CHECK constraint failed')"
109105 " ELSE raise(ABORT,'NOT NULL constraint failed')"
109106 " END"
109107 " FROM pragma_quick_check(%Q,%Q)"
109108 " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
109109 zTab, zDb
109110 );
109111 }
109112 }
@@ -108982,11 +109387,13 @@
109387 **
109388 ** Technically, as x no longer points into a valid object or to the byte
109389 ** following a valid object, it may not be used in comparison operations.
109390 */
109391 static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
109392 assert( pParse==pParse->db->pParse );
109393 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
109394 if( pParse->nErr==0 ){
109395 const RenameToken *p;
109396 u8 i = 0;
109397 for(p=pParse->pRename; p; p=p->pNext){
109398 if( p->p ){
109399 assert( p->p!=pPtr );
@@ -109379,11 +109786,11 @@
109786 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
109787
109788 /* Parse the SQL statement passed as the first argument. If no error
109789 ** occurs and the parse does not result in a new table, index or
109790 ** trigger object, the database must be corrupt. */
109791 sqlite3ParseObjectInit(p, db);
109792 p->eParseMode = PARSE_MODE_RENAME;
109793 p->db = db;
109794 p->nQueryLoop = 1;
109795 rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM;
109796 if( db->mallocFailed ) rc = SQLITE_NOMEM;
@@ -109664,11 +110071,11 @@
110071 sqlite3FreeIndex(db, pIdx);
110072 }
110073 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
110074 sqlite3DbFree(db, pParse->zErrMsg);
110075 renameTokenFree(db, pParse->pRename);
110076 sqlite3ParseObjectReset(pParse);
110077 }
110078
110079 /*
110080 ** SQL function:
110081 **
@@ -110378,10 +110785,16 @@
110785
110786 /* Edit the sqlite_schema table */
110787 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110788 assert( iDb>=0 );
110789 zDb = db->aDb[iDb].zDbSName;
110790 #ifndef SQLITE_OMIT_AUTHORIZATION
110791 /* Invoke the authorization callback. */
110792 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){
110793 goto exit_drop_column;
110794 }
110795 #endif
110796 renameTestSchema(pParse, zDb, iDb==1, "", 0);
110797 renameFixQuotes(pParse, zDb, iDb==1);
110798 sqlite3NestedParse(pParse,
110799 "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
110800 "sql = sqlite_drop_column(%d, sql, %d) "
@@ -112765,11 +113178,11 @@
113178 ){
113179 goto attach_end;
113180 }
113181
113182 #ifndef SQLITE_OMIT_AUTHORIZATION
113183 if( ALWAYS(pAuthArg) ){
113184 char *zAuthArg;
113185 if( pAuthArg->op==TK_STRING ){
113186 assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
113187 zAuthArg = pAuthArg->u.zToken;
113188 }else{
@@ -113426,15 +113839,17 @@
113839 sqlite3 *db;
113840 Vdbe *v;
113841
113842 assert( pParse->pToplevel==0 );
113843 db = pParse->db;
113844 assert( db->pParse==pParse );
113845 if( pParse->nested ) return;
113846 if( pParse->nErr ){
113847 if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM;
113848 return;
113849 }
113850 assert( db->mallocFailed==0 );
113851
113852 /* Begin by generating some termination code at the end of the
113853 ** vdbe program
113854 */
113855 v = pParse->pVdbe;
@@ -113563,11 +113978,13 @@
113978 }
113979 }
113980
113981 /* Get the VDBE program ready for execution
113982 */
113983 assert( v!=0 || pParse->nErr );
113984 assert( db->mallocFailed==0 || pParse->nErr );
113985 if( pParse->nErr==0 ){
113986 /* A minimum of one cursor is required if autoincrement is used
113987 * See ticket [a696379c1f08866] */
113988 assert( pParse->pAinc==0 || pParse->nTab>0 );
113989 sqlite3VdbeMakeReady(v, pParse);
113990 pParse->rc = SQLITE_DONE;
@@ -115667,14 +116084,15 @@
116084 pList->a[0].sortFlags = pParse->iPkSortOrder;
116085 assert( pParse->pNewTable==pTab );
116086 pTab->iPKey = -1;
116087 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
116088 SQLITE_IDXTYPE_PRIMARYKEY);
116089 if( pParse->nErr ){
116090 pTab->tabFlags &= ~TF_WithoutRowid;
116091 return;
116092 }
116093 assert( db->mallocFailed==0 );
116094 pPk = sqlite3PrimaryKeyIndex(pTab);
116095 assert( pPk->nKeyCol==1 );
116096 }else{
116097 pPk = sqlite3PrimaryKeyIndex(pTab);
116098 assert( pPk!=0 );
@@ -116411,14 +116829,14 @@
116829 ** normally holds CHECK constraints on an ordinary table, but for
116830 ** a VIEW it holds the list of column names.
116831 */
116832 sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
116833 &pTable->nCol, &pTable->aCol);
116834 if( pParse->nErr==0
 
116835 && pTable->nCol==pSel->pEList->nExpr
116836 ){
116837 assert( db->mallocFailed==0 );
116838 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
116839 SQLITE_AFF_NONE);
116840 }
116841 }else{
116842 /* CREATE VIEW name AS... without an argument list. Construct
@@ -117033,11 +117451,11 @@
117451 tnum = (Pgno)memRootPage;
117452 }else{
117453 tnum = pIndex->tnum;
117454 }
117455 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
117456 assert( pKey!=0 || pParse->nErr );
117457
117458 /* Open the sorter cursor if we are to use one. */
117459 iSorter = pParse->nTab++;
117460 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
117461 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
@@ -117197,13 +117615,15 @@
117615 int nExtra = 0; /* Space allocated for zExtra[] */
117616 int nExtraCol; /* Number of extra columns needed */
117617 char *zExtra = 0; /* Extra space after the Index object */
117618 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
117619
117620 assert( db->pParse==pParse );
117621 if( pParse->nErr ){
117622 goto exit_create_index;
117623 }
117624 assert( db->mallocFailed==0 );
117625 if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
117626 goto exit_create_index;
117627 }
117628 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117629 goto exit_create_index;
@@ -117263,11 +117683,10 @@
117683 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117684 }
117685 pDb = &db->aDb[iDb];
117686
117687 assert( pTab!=0 );
 
117688 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
117689 && db->init.busy==0
117690 && pTblName!=0
117691 #if SQLITE_USER_AUTHENTICATION
117692 && sqlite3UserAuthTable(pTab->zName)==0
@@ -117827,14 +118246,14 @@
118246 Index *pIndex;
118247 Vdbe *v;
118248 sqlite3 *db = pParse->db;
118249 int iDb;
118250
 
118251 if( db->mallocFailed ){
118252 goto exit_drop_index;
118253 }
118254 assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
118255 assert( pName->nSrc==1 );
118256 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
118257 goto exit_drop_index;
118258 }
118259 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
@@ -119746,13 +120165,15 @@
120165 Trigger *pTrigger; /* List of table triggers, if required */
120166 #endif
120167
120168 memset(&sContext, 0, sizeof(sContext));
120169 db = pParse->db;
120170 assert( db->pParse==pParse );
120171 if( pParse->nErr ){
120172 goto delete_from_cleanup;
120173 }
120174 assert( db->mallocFailed==0 );
120175 assert( pTabList->nSrc==1 );
120176
120177
120178 /* Locate the table which we want to delete. This table has to be
120179 ** put in an SrcList structure because some of the subroutines we
@@ -119929,11 +120350,11 @@
120350 **
120351 ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values.
120352 ** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
120353 ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
120354 */
120355 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
120356 if( pWInfo==0 ) goto delete_from_cleanup;
120357 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
120358 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
120359 assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
120360 if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
@@ -120542,10 +120963,11 @@
120963 static void subtypeFunc(
120964 sqlite3_context *context,
120965 int argc,
120966 sqlite3_value **argv
120967 ){
120968 UNUSED_PARAMETER(argc);
120969 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
120970 }
120971
120972 /*
120973 ** Implementation of the length() function
@@ -123472,11 +123894,11 @@
123894
123895 /* Create VDBE to loop through the entries in pSrc that match the WHERE
123896 ** clause. For each row found, increment either the deferred or immediate
123897 ** foreign key constraint counter. */
123898 if( pParse->nErr==0 ){
123899 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
123900 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
123901 if( pWInfo ){
123902 sqlite3WhereEnd(pWInfo);
123903 }
123904 }
@@ -125014,13 +125436,15 @@
125436 Trigger *pTrigger; /* List of triggers on pTab, if required */
125437 int tmask; /* Mask of trigger times */
125438 #endif
125439
125440 db = pParse->db;
125441 assert( db->pParse==pParse );
125442 if( pParse->nErr ){
125443 goto insert_cleanup;
125444 }
125445 assert( db->mallocFailed==0 );
125446 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
125447
125448 /* If the Select object is really just a simple VALUES() list with a
125449 ** single row (the common case) then keep that one row of values
125450 ** and discard the other (unused) parts of the pSelect object
@@ -125192,11 +125616,13 @@
125616 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
125617 dest.iSdst = bIdListInOrder ? regData : 0;
125618 dest.nSdst = pTab->nCol;
125619 rc = sqlite3Select(pParse, pSelect, &dest);
125620 regFromSelect = dest.iSdst;
125621 assert( db->pParse==pParse );
125622 if( rc || pParse->nErr ) goto insert_cleanup;
125623 assert( db->mallocFailed==0 );
125624 sqlite3VdbeEndCoroutine(v, regYield);
125625 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
125626 assert( pSelect->pEList );
125627 nColumn = pSelect->pEList->nExpr;
125628
@@ -127937,10 +128363,15 @@
128363 int (*autovacuum_pages)(sqlite3*,
128364 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
128365 void*, void(*)(void*));
128366 /* Version 3.38.0 and later */
128367 int (*error_offset)(sqlite3*);
128368 int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128369 int (*vtab_distinct)(sqlite3_index_info*);
128370 int (*vtab_in)(sqlite3_index_info*,int,int);
128371 int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128372 int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
128373 };
128374
128375 /*
128376 ** This is the function signature used for all extension entry points. It
128377 ** is also defined in the file "loadext.c".
@@ -128250,10 +128681,15 @@
128681 #define sqlite3_total_changes64 sqlite3_api->total_changes64
128682 /* Version 3.37.0 and later */
128683 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128684 /* Version 3.38.0 and later */
128685 #define sqlite3_error_offset sqlite3_api->error_offset
128686 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128687 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
128688 #define sqlite3_vtab_in sqlite3_api->vtab_in
128689 #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
128690 #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
128691 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128692
128693 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128694 /* This case when the file really is being compiled as a loadable
128695 ** extension */
@@ -128741,10 +129177,15 @@
129177 sqlite3_total_changes64,
129178 /* Version 3.37.0 and later */
129179 sqlite3_autovacuum_pages,
129180 /* Version 3.38.0 and later */
129181 sqlite3_error_offset,
129182 sqlite3_vtab_rhs_value,
129183 sqlite3_vtab_distinct,
129184 sqlite3_vtab_in,
129185 sqlite3_vtab_in_first,
129186 sqlite3_vtab_in_next
129187 };
129188
129189 /* True if x is the directory separator character
129190 */
129191 #if SQLITE_OS_WIN
@@ -131042,10 +131483,14 @@
131483 sqlite3_stmt *pDummy = 0;
131484 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
131485 (void)sqlite3_finalize(pDummy);
131486 sqlite3DbFree(db, zSql);
131487 }
131488 if( db->mallocFailed ){
131489 sqlite3ErrorMsg(db->pParse, "out of memory");
131490 db->pParse->rc = SQLITE_NOMEM_BKPT;
131491 }
131492 pHash = &db->aDb[ii].pSchema->tblHash;
131493 break;
131494 }
131495 }
131496 }
@@ -133078,12 +133523,14 @@
133523 }
133524
133525 /*
133526 ** Free all memory allocations in the pParse object
133527 */
133528 SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse *pParse){
133529 sqlite3 *db = pParse->db;
133530 assert( db!=0 );
133531 assert( db->pParse==pParse );
133532 assert( pParse->nested==0 );
133533 #ifndef SQLITE_OMIT_SHARED_CACHE
133534 sqlite3DbFree(db, pParse->aTableLock);
133535 #endif
133536 while( pParse->pCleanup ){
@@ -133094,15 +133541,16 @@
133541 }
133542 sqlite3DbFree(db, pParse->aLabel);
133543 if( pParse->pConstExpr ){
133544 sqlite3ExprListDelete(db, pParse->pConstExpr);
133545 }
133546 assert( db->lookaside.bDisable >= pParse->disableLookaside );
133547 db->lookaside.bDisable -= pParse->disableLookaside;
133548 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133549 assert( pParse->db->pParse==pParse );
133550 db->pParse = pParse->pOuterParse;
133551 pParse->db = 0;
133552 pParse->disableLookaside = 0;
133553 }
133554
133555 /*
133556 ** Add a new cleanup operation to a Parser. The cleanup should happen when
@@ -133111,11 +133559,11 @@
133559 **
133560 ** Use this mechanism for uncommon cleanups. There is a higher setup
133561 ** cost for this mechansim (an extra malloc), so it should not be used
133562 ** for common cleanups that happen on most calls. But for less
133563 ** common cleanups, we save a single NULL-pointer comparison in
133564 ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
133565 **
133566 ** If a memory allocation error occurs, then the cleanup happens immediately.
133567 ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
133568 ** pParse->earlyCleanup flag is set in that case. Calling code show verify
133569 ** that test cases exist for which this happens, to guard against possible
@@ -133150,10 +133598,29 @@
133598 pParse->earlyCleanup = 1;
133599 #endif
133600 }
133601 return pPtr;
133602 }
133603
133604 /*
133605 ** Turn bulk memory into a valid Parse object and link that Parse object
133606 ** into database connection db.
133607 **
133608 ** Call sqlite3ParseObjectReset() to undo this operation.
133609 **
133610 ** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which
133611 ** is generated by Lemon.
133612 */
133613 SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){
133614 memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
133615 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
133616 assert( db->pParse!=pParse );
133617 pParse->pOuterParse = db->pParse;
133618 db->pParse = pParse;
133619 pParse->db = db;
133620 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
133621 }
133622
133623 /*
133624 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133625 */
133626 static int sqlite3Prepare(
@@ -133167,15 +133634,19 @@
133634 ){
133635 int rc = SQLITE_OK; /* Result code */
133636 int i; /* Loop counter */
133637 Parse sParse; /* Parsing context */
133638
133639 /* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
133640 memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
133641 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
133642 sParse.pOuterParse = db->pParse;
133643 db->pParse = &sParse;
133644 sParse.db = db;
133645 sParse.pReprepare = pReprepare;
133646 assert( ppStmt && *ppStmt==0 );
133647 if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory");
133648 assert( sqlite3_mutex_held(db->mutex) );
133649
133650 /* For a long-term use prepared statement avoid the use of
133651 ** lookaside memory.
133652 */
@@ -133224,11 +133695,10 @@
133695 }
133696 }
133697
133698 sqlite3VtabUnlockList(db);
133699
 
133700 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
133701 char *zSqlCopy;
133702 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
133703 testcase( nBytes==mxLen );
133704 testcase( nBytes==mxLen+1 );
@@ -133291,11 +133761,11 @@
133761 sqlite3DbFree(db, pT);
133762 }
133763
133764 end_prepare:
133765
133766 sqlite3ParseObjectReset(&sParse);
133767 return rc;
133768 }
133769 static int sqlite3LockAndPrepare(
133770 sqlite3 *db, /* Database handle. */
133771 const char *zSql, /* UTF-8 encoded SQL statement. */
@@ -134946,11 +135416,11 @@
135416 p->enc = ENC(db);
135417 p->db = db;
135418 p->nRef = 1;
135419 memset(&p[1], 0, nExtra);
135420 }else{
135421 return (KeyInfo*)sqlite3OomFault(db);
135422 }
135423 return p;
135424 }
135425
135426 /*
@@ -135117,10 +135587,13 @@
135587 }
135588 #endif
135589
135590 iTab = pSort->iECursor;
135591 if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
135592 if( eDest==SRT_Mem && p->iOffset ){
135593 sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
135594 }
135595 regRowid = 0;
135596 regRow = pDest->iSdst;
135597 }else{
135598 regRowid = sqlite3GetTempReg(pParse);
135599 if( eDest==SRT_EphemTab || eDest==SRT_Table ){
@@ -136975,10 +137448,11 @@
137448 }else{
137449 pSplit = p;
137450 for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
137451 }
137452 pPrior = pSplit->pPrior;
137453 assert( pPrior!=0 );
137454 pSplit->pPrior = 0;
137455 pPrior->pNext = 0;
137456 assert( p->pOrderBy == pOrderBy );
137457 assert( pOrderBy!=0 || db->mallocFailed );
137458 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
@@ -139126,11 +139600,12 @@
139600 }
139601 }
139602
139603 /* Process NATURAL keywords, and ON and USING clauses of joins.
139604 */
139605 assert( db->mallocFailed==0 || pParse->nErr!=0 );
139606 if( pParse->nErr || sqliteProcessJoin(pParse, p) ){
139607 return WRC_Abort;
139608 }
139609
139610 /* For every "*" that occurs in the column list, insert the names of
139611 ** all columns in all tables. And for every TABLE.* insert the names
@@ -139423,16 +139898,17 @@
139898 Parse *pParse, /* The parser context */
139899 Select *p, /* The SELECT statement being coded. */
139900 NameContext *pOuterNC /* Name context for container */
139901 ){
139902 assert( p!=0 || pParse->db->mallocFailed );
139903 assert( pParse->db->pParse==pParse );
139904 if( pParse->db->mallocFailed ) return;
139905 if( p->selFlags & SF_HasTypeInfo ) return;
139906 sqlite3SelectExpand(pParse, p);
139907 if( pParse->nErr ) return;
139908 sqlite3ResolveSelectNames(pParse, p, pOuterNC);
139909 if( pParse->nErr ) return;
139910 sqlite3SelectAddTypeInfo(pParse, p);
139911 }
139912
139913 /*
139914 ** Reset the aggregate accumulator.
@@ -139445,12 +139921,14 @@
139921 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
139922 Vdbe *v = pParse->pVdbe;
139923 int i;
139924 struct AggInfo_func *pFunc;
139925 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
139926 assert( pParse->db->pParse==pParse );
139927 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
139928 if( nReg==0 ) return;
139929 if( pParse->nErr ) return;
139930 #ifdef SQLITE_DEBUG
139931 /* Verify that all AggInfo registers are within the range specified by
139932 ** AggInfo.mnReg..AggInfo.mxReg */
139933 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
139934 for(i=0; i<pAggInfo->nColumn; i++){
@@ -139869,14 +140347,16 @@
140347 sqlite3 *db; /* The database connection */
140348 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
140349 u8 minMaxFlag; /* Flag for min/max queries */
140350
140351 db = pParse->db;
140352 assert( pParse==db->pParse );
140353 v = sqlite3GetVdbe(pParse);
140354 if( p==0 || pParse->nErr ){
140355 return 1;
140356 }
140357 assert( db->mallocFailed==0 );
140358 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
140359 #if SELECTTRACE_ENABLED
140360 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
140361 if( sqlite3SelectTrace & 0x100 ){
140362 sqlite3TreeViewSelect(0, p, 0);
@@ -139907,13 +140387,14 @@
140387 }
140388 p->selFlags &= ~SF_Distinct;
140389 p->selFlags |= SF_NoopOrderBy;
140390 }
140391 sqlite3SelectPrep(pParse, p, 0);
140392 if( pParse->nErr ){
140393 goto select_end;
140394 }
140395 assert( db->mallocFailed==0 );
140396 assert( p->pEList!=0 );
140397 #if SELECTTRACE_ENABLED
140398 if( sqlite3SelectTrace & 0x104 ){
140399 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
140400 sqlite3TreeViewSelect(0, p, 0);
@@ -139953,11 +140434,11 @@
140434 sqlite3GenerateColumnNames(pParse, p);
140435 }
140436
140437 #ifndef SQLITE_OMIT_WINDOWFUNC
140438 if( sqlite3WindowRewrite(pParse, p) ){
140439 assert( pParse->nErr );
140440 goto select_end;
140441 }
140442 #if SELECTTRACE_ENABLED
140443 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
140444 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -140429,11 +140910,11 @@
140910
140911
140912 /* Begin the database scan. */
140913 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
140914 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
140915 p->pEList, p, wctrlFlags, p->nSelectRow);
140916 if( pWInfo==0 ) goto select_end;
140917 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
140918 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
140919 }
140920 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
@@ -140693,11 +141174,11 @@
141174 ** in the right order to begin with.
141175 */
141176 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
141177 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
141178 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
141179 0, (WHERE_GROUPBY|(orderByGrp ? WHERE_SORTBYGROUP : 0)|distFlag), 0
141180 );
141181 if( pWInfo==0 ){
141182 sqlite3ExprListDelete(db, pDistinct);
141183 goto select_end;
141184 }
@@ -140991,11 +141472,11 @@
141472 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
141473 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
141474
141475 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
141476 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
141477 pDistinct, 0, minMaxFlag|distFlag, 0);
141478 if( pWInfo==0 ){
141479 goto select_end;
141480 }
141481 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
141482 eDist = sqlite3WhereIsDistinct(pWInfo);
@@ -141048,11 +141529,11 @@
141529 /* Control jumps to here if an error is encountered above, or upon
141530 ** successful coding of the SELECT.
141531 */
141532 select_end:
141533 assert( db->mallocFailed==0 || db->mallocFailed==1 );
141534 assert( db->mallocFailed==0 || pParse->nErr!=0 );
141535 sqlite3ExprListDelete(db, pMinMaxOrderBy);
141536 #ifdef SQLITE_DEBUG
141537 if( pAggInfo && !db->mallocFailed ){
141538 for(i=0; i<pAggInfo->nColumn; i++){
141539 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -142200,10 +142681,11 @@
142681 Select sSelect;
142682 SrcList sFrom;
142683
142684 assert( v!=0 );
142685 assert( pParse->bReturning );
142686 assert( db->pParse==pParse );
142687 pReturning = pParse->u1.pReturning;
142688 assert( pTrigger == &(pReturning->retTrig) );
142689 memset(&sSelect, 0, sizeof(sSelect));
142690 memset(&sFrom, 0, sizeof(sFrom));
142691 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
@@ -142210,11 +142692,12 @@
142692 sSelect.pSrc = &sFrom;
142693 sFrom.nSrc = 1;
142694 sFrom.a[0].pTab = pTab;
142695 sFrom.a[0].iCursor = -1;
142696 sqlite3SelectPrep(pParse, &sSelect, 0);
142697 if( pParse->nErr==0 ){
142698 assert( db->mallocFailed==0 );
142699 sqlite3GenerateColumnNames(pParse, &sSelect);
142700 }
142701 sqlite3ExprListDelete(db, sSelect.pEList);
142702 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142703 if( !db->mallocFailed ){
@@ -142228,11 +142711,11 @@
142711 sNC.uNC.iBaseReg = regIn;
142712 sNC.ncFlags = NC_UBaseReg;
142713 pParse->eTriggerOp = pTrigger->op;
142714 pParse->pTriggerTab = pTab;
142715 if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142716 && ALWAYS(!db->mallocFailed)
142717 ){
142718 int i;
142719 int nCol = pNew->nExpr;
142720 int reg = pParse->nMem+1;
142721 pParse->nMem += nCol+2;
@@ -142392,12 +142875,12 @@
142875 TriggerPrg *pPrg; /* Value to return */
142876 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
142877 Vdbe *v; /* Temporary VM */
142878 NameContext sNC; /* Name context for sub-vdbe */
142879 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
 
142880 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
142881 Parse sSubParse; /* Parse context for sub-vdbe */
142882
142883 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
142884 assert( pTop->pVdbe );
142885
142886 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
@@ -142415,23 +142898,21 @@
142898 pPrg->aColmask[0] = 0xffffffff;
142899 pPrg->aColmask[1] = 0xffffffff;
142900
142901 /* Allocate and populate a new Parse context to use for coding the
142902 ** trigger sub-program. */
142903 sqlite3ParseObjectInit(&sSubParse, db);
 
142904 memset(&sNC, 0, sizeof(sNC));
142905 sNC.pParse = &sSubParse;
142906 sSubParse.pTriggerTab = pTab;
142907 sSubParse.pToplevel = pTop;
142908 sSubParse.zAuthContext = pTrigger->zName;
142909 sSubParse.eTriggerOp = pTrigger->op;
142910 sSubParse.nQueryLoop = pParse->nQueryLoop;
142911 sSubParse.disableVtab = pParse->disableVtab;
142912
142913 v = sqlite3GetVdbe(&sSubParse);
 
142914 if( v ){
142915 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
142916 pTrigger->zName, onErrorText(orconf),
142917 (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
142918 (pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
@@ -142453,42 +142934,43 @@
142934 if( pTrigger->pWhen ){
142935 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
142936 if( db->mallocFailed==0
142937 && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
142938 ){
142939 iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse);
142940 sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142941 }
142942 sqlite3ExprDelete(db, pWhen);
142943 }
142944
142945 /* Code the trigger program into the sub-vdbe. */
142946 codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf);
142947
142948 /* Insert an OP_Halt at the end of the sub-program. */
142949 if( iEndTrigger ){
142950 sqlite3VdbeResolveLabel(v, iEndTrigger);
142951 }
142952 sqlite3VdbeAddOp0(v, OP_Halt);
142953 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
142954 transferParseError(pParse, &sSubParse);
142955
142956 if( pParse->nErr==0 ){
142957 assert( db->mallocFailed==0 );
142958 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
142959 }
142960 pProgram->nMem = sSubParse.nMem;
142961 pProgram->nCsr = sSubParse.nTab;
142962 pProgram->token = (void *)pTrigger;
142963 pPrg->aColmask[0] = sSubParse.oldmask;
142964 pPrg->aColmask[1] = sSubParse.newmask;
142965 sqlite3VdbeDelete(v);
142966 }else{
142967 transferParseError(pParse, &sSubParse);
142968 }
142969
142970 assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg );
142971 sqlite3ParseObjectReset(&sSubParse);
 
 
142972 return pPrg;
142973 }
142974
142975 /*
142976 ** Return a pointer to a TriggerPrg object containing the sub-program for
@@ -142539,11 +143021,11 @@
143021 int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
143022 ){
143023 Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
143024 TriggerPrg *pPrg;
143025 pPrg = getRowTrigger(pParse, p, pTab, orconf);
143026 assert( pPrg || pParse->nErr );
143027
143028 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
143029 ** is a pointer to the sub-vdbe containing the trigger program. */
143030 if( pPrg ){
143031 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
@@ -143057,13 +143539,15 @@
143539 int regRowSet = 0; /* Rowset of rows to be updated */
143540 int regKey = 0; /* composite PRIMARY KEY value */
143541
143542 memset(&sContext, 0, sizeof(sContext));
143543 db = pParse->db;
143544 assert( db->pParse==pParse );
143545 if( pParse->nErr ){
143546 goto update_cleanup;
143547 }
143548 assert( db->mallocFailed==0 );
143549
143550 /* Locate the table which we want to update.
143551 */
143552 pTab = sqlite3SrcListLookup(pParse, pTabList);
143553 if( pTab==0 ) goto update_cleanup;
@@ -143431,11 +143915,11 @@
143915 ** or index, causing a single-pass approach to malfunction. */
143916 flags = WHERE_ONEPASS_DESIRED;
143917 if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
143918 flags |= WHERE_ONEPASS_MULTIROW;
143919 }
143920 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
143921 if( pWInfo==0 ) goto update_cleanup;
143922
143923 /* A one-pass strategy that might update more than one row may not
143924 ** be used if any column of the index used for the scan is being
143925 ** updated. Otherwise, if there is an index on "b", statements like
@@ -143953,11 +144437,13 @@
144437 }else{
144438 regRec = ++pParse->nMem;
144439 regRowid = ++pParse->nMem;
144440
144441 /* Start scanning the virtual table */
144442 pWInfo = sqlite3WhereBegin(
144443 pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0
144444 );
144445 if( pWInfo==0 ) return;
144446
144447 /* Populate the argument registers. */
144448 for(i=0; i<pTab->nCol; i++){
144449 assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
@@ -145598,13 +146084,12 @@
146084 return SQLITE_MISUSE_BKPT;
146085 }
146086 pTab = pCtx->pTab;
146087 assert( IsVirtual(pTab) );
146088
146089 sqlite3ParseObjectInit(&sParse, db);
146090 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
 
146091 /* We should never be able to reach this point while loading the
146092 ** schema. Nevertheless, defend against that (turn off db->init.busy)
146093 ** in case a bug arises. */
146094 assert( db->init.busy==0 );
146095 initBusy = db->init.busy;
@@ -145654,11 +146139,11 @@
146139
146140 if( sParse.pVdbe ){
146141 sqlite3VdbeFinalize(sParse.pVdbe);
146142 }
146143 sqlite3DeleteTable(db, sParse.pNewTable);
146144 sqlite3ParseObjectReset(&sParse);
146145 db->init.busy = initBusy;
146146
146147 assert( (rc&0xff)==rc );
146148 rc = sqlite3ApiExit(db, rc);
146149 sqlite3_mutex_leave(db->mutex);
@@ -146265,14 +146750,16 @@
146750 u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
146751 Index *pIndex; /* Index used, or NULL */
146752 } btree;
146753 struct { /* Information for virtual tables */
146754 int idxNum; /* Index number */
146755 u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
146756 u32 bOmitOffset : 1; /* True to let virtual table handle offset */
146757 i8 isOrdered; /* True if satisfies ORDER BY */
146758 u16 omitMask; /* Terms that may be omitted */
146759 char *idxStr; /* Index identifier string */
146760 u32 mHandleIn; /* Terms to handle as IN(...) instead of == */
146761 } vtab;
146762 } u;
146763 u32 wsFlags; /* WHERE_* flags describing the plan */
146764 u16 nLTerm; /* Number of entries in aLTerm[] */
146765 u16 nSkip; /* Number of NULL aLTerm[] entries */
@@ -146425,10 +146912,11 @@
146912 #ifdef SQLITE_ENABLE_STAT4
146913 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
146914 #else
146915 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
146916 #endif
146917 #define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
146918
146919 /*
146920 ** An instance of the WhereScan object is used as an iterator for locating
146921 ** terms in the WHERE clause that are useful to the query planner.
146922 */
@@ -146528,11 +147016,10 @@
147016 ** to construct WhereLoop objects for a particular query.
147017 */
147018 struct WhereLoopBuilder {
147019 WhereInfo *pWInfo; /* Information about this WHERE */
147020 WhereClause *pWC; /* WHERE clause terms */
 
147021 WhereLoop *pNew; /* Template WhereLoop */
147022 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
147023 #ifdef SQLITE_ENABLE_STAT4
147024 UnpackedRecord *pRec; /* Probe for stat4 (if required) */
147025 int nRecValid; /* Number of valid fields currently in pRec */
@@ -146596,10 +147083,13 @@
147083 Parse *pParse; /* Parsing and code generating context */
147084 SrcList *pTabList; /* List of tables in the join */
147085 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
147086 ExprList *pResultSet; /* Result set of the query */
147087 Expr *pWhere; /* The complete WHERE clause */
147088 #ifndef SQLITE_OMIT_VIRTUALTABLE
147089 Select *pLimit; /* Used to access LIMIT expr/registers for vtabs */
147090 #endif
147091 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
147092 int iContinue; /* Jump here to continue with next record */
147093 int iBreak; /* Jump here to break out of the loop */
147094 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
147095 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -146681,10 +147171,11 @@
147171
147172 /* whereexpr.c: */
147173 SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
147174 SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
147175 SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
147176 SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause*, Select*);
147177 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
147178 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
147179 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
147180 SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
147181 SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
@@ -146751,10 +147242,11 @@
147242 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
147243 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
147244 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
147245 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
147246 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
147247 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
147248
147249 #endif /* !defined(SQLITE_WHEREINT_H) */
147250
147251 /************** End of whereInt.h ********************************************/
147252 /************** Continuing where we left off in wherecode.c ******************/
@@ -147561,10 +148053,13 @@
148053 regBase = r1;
148054 }else{
148055 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
148056 }
148057 }
148058 }
148059 for(j=nSkip; j<nEq; j++){
148060 pTerm = pLoop->aLTerm[j];
148061 if( pTerm->eOperator & WO_IN ){
148062 if( pTerm->pExpr->flags & EP_xIsSelect ){
148063 /* No affinity ever needs to be (or should be) applied to a value
148064 ** from the RHS of an "? IN (SELECT ...)" expression. The
148065 ** sqlite3FindInIndex() routine has already ensured that the
@@ -147575,11 +148070,12 @@
148070 Expr *pRight = pTerm->pExpr->pRight;
148071 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
148072 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
148073 VdbeCoverage(v);
148074 }
148075 if( pParse->nErr==0 ){
148076 assert( pParse->db->mallocFailed==0 );
148077 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
148078 zAff[j] = SQLITE_AFF_BLOB;
148079 }
148080 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
148081 zAff[j] = SQLITE_AFF_BLOB;
@@ -148265,15 +148761,31 @@
148761 for(j=0; j<nConstraint; j++){
148762 int iTarget = iReg+j+2;
148763 pTerm = pLoop->aLTerm[j];
148764 if( NEVER(pTerm==0) ) continue;
148765 if( pTerm->eOperator & WO_IN ){
148766 if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
148767 int iTab = pParse->nTab++;
148768 int iCache = ++pParse->nMem;
148769 sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab);
148770 sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
148771 }else{
148772 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148773 addrNotFound = pLevel->addrNxt;
148774 }
148775 }else{
148776 Expr *pRight = pTerm->pExpr->pRight;
148777 codeExprOrVector(pParse, pRight, iTarget, 1);
148778 if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET
148779 && pLoop->u.vtab.bOmitOffset
148780 ){
148781 assert( pTerm->eOperator==WO_AUX );
148782 assert( pWInfo->pLimit!=0 );
148783 assert( pWInfo->pLimit->iOffset>0 );
148784 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pLimit->iOffset);
148785 VdbeComment((v,"Zero OFFSET counter"));
148786 }
148787 }
148788 }
148789 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
148790 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
148791 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
@@ -148292,17 +148804,23 @@
148804 iIn = pLevel->u.in.nIn;
148805 }else{
148806 iIn = 0;
148807 }
148808 for(j=nConstraint-1; j>=0; j--){
148809 int bIn; /* True to generate byte code to loop over RHS IN values */
148810 pTerm = pLoop->aLTerm[j];
148811 if( (pTerm->eOperator & WO_IN)!=0
148812 && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
148813 ){
148814 bIn = 1;
148815 }else{
148816 bIn = 0;
148817 }
148818 if( bIn ) iIn--;
148819 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
148820 disableTerm(pLevel, pTerm);
148821 }else if( bIn && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){
 
 
148822 Expr *pCompare; /* The comparison operator */
148823 Expr *pRight; /* RHS of the comparison */
148824 VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
148825
148826 /* Reload the constraint value into reg[iReg+j+2]. The same value
@@ -149028,11 +149546,11 @@
149546 regRowid = ++pParse->nMem;
149547 }
149548 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
149549
149550 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
149551 ** Then for every term xN, evaluate as the subexpression: xN AND y
149552 ** That way, terms in y that are factored into the disjunction will
149553 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
149554 **
149555 ** Actually, each subexpression is converted to "xN AND w" where w is
149556 ** the "interesting" terms of z - terms that did not originate in the
@@ -149040,19 +149558,28 @@
149558 ** indices.
149559 **
149560 ** This optimization also only applies if the (x1 OR x2 OR ...) term
149561 ** is not contained in the ON clause of a LEFT JOIN.
149562 ** See ticket http://www.sqlite.org/src/info/f2369304e4
149563 **
149564 ** 2022-02-04: Do not push down slices of a row-value comparison.
149565 ** In other words, "w" or "y" may not be a slice of a vector. Otherwise,
149566 ** the initialization of the right-hand operand of the vector comparison
149567 ** might not occur, or might occur only in an OR branch that is not
149568 ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
149569 */
149570 if( pWC->nTerm>1 ){
149571 int iTerm;
149572 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
149573 Expr *pExpr = pWC->a[iTerm].pExpr;
149574 if( &pWC->a[iTerm] == pTerm ) continue;
149575 testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
149576 testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
149577 testcase( pWC->a[iTerm].wtFlags & TERM_SLICE );
149578 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
149579 continue;
149580 }
149581 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
149582 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
149583 pExpr = sqlite3ExprDup(db, pExpr, 0);
149584 pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
149585 }
@@ -149091,13 +149618,13 @@
149618 pOrExpr = pAndExpr;
149619 }
149620 /* Loop through table entries that match term pOrTerm. */
149621 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
149622 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
149623 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0,
149624 WHERE_OR_SUBCLAUSE, iCovCur);
149625 assert( pSubWInfo || pParse->nErr );
149626 if( pSubWInfo ){
149627 WhereLoop *pSubLoop;
149628 int addrExplain = sqlite3WhereExplainOneScan(
149629 pParse, pOrTab, &pSubWInfo->a[0], 0
149630 );
@@ -149831,11 +150358,11 @@
150358 void *pNotUsed;
150359 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
150360 assert( pVtab!=0 );
150361 assert( pVtab->pModule!=0 );
150362 assert( !ExprHasProperty(pExpr, EP_IntValue) );
150363 pMod = (sqlite3_module *)pVtab->pModule;
150364 if( pMod->xFindFunction!=0 ){
150365 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
150366 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
150367 *peOp2 = i;
150368 *ppRight = pList->a[1].pExpr;
@@ -150788,11 +151315,14 @@
151315 ** new terms for each component comparison - "a = ?" and "b = ?". The
151316 ** new terms completely replace the original vector comparison, which is
151317 ** no longer used.
151318 **
151319 ** This is only required if at least one side of the comparison operation
151320 ** is not a sub-select.
151321 **
151322 ** tag-20220128a
151323 */
151324 if( (pExpr->op==TK_EQ || pExpr->op==TK_IS)
151325 && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1
151326 && sqlite3ExprVectorSize(pExpr->pRight)==nLeft
151327 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
151328 || (pExpr->pRight->flags & EP_xIsSelect)==0)
@@ -150805,11 +151335,11 @@
151335 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft);
151336 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft);
151337
151338 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
151339 transferJoinMarkings(pNew, pExpr);
151340 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
151341 exprAnalyze(pSrc, pWC, idxNew);
151342 }
151343 pTerm = &pWC->a[idxTerm];
151344 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
151345 pTerm->eOperator = 0;
@@ -150930,10 +151460,117 @@
151460 }else{
151461 sqlite3WhereSplit(pWC, pE2->pLeft, op);
151462 sqlite3WhereSplit(pWC, pE2->pRight, op);
151463 }
151464 }
151465
151466 /*
151467 ** Add either a LIMIT (if eMatchOp==SQLITE_INDEX_CONSTRAINT_LIMIT) or
151468 ** OFFSET (if eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET) term to the
151469 ** where-clause passed as the first argument. The value for the term
151470 ** is found in register iReg.
151471 **
151472 ** In the common case where the value is a simple integer
151473 ** (example: "LIMIT 5 OFFSET 10") then the expression codes as a
151474 ** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value().
151475 ** If not, then it codes as a TK_REGISTER expression.
151476 */
151477 void whereAddLimitExpr(
151478 WhereClause *pWC, /* Add the constraint to this WHERE clause */
151479 int iReg, /* Register that will hold value of the limit/offset */
151480 Expr *pExpr, /* Expression that defines the limit/offset */
151481 int iCsr, /* Cursor to which the constraint applies */
151482 int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */
151483 ){
151484 Parse *pParse = pWC->pWInfo->pParse;
151485 sqlite3 *db = pParse->db;
151486 Expr *pNew;
151487 int iVal = 0;
151488
151489 if( sqlite3ExprIsInteger(pExpr, &iVal) && iVal>=0 ){
151490 Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0);
151491 if( pVal==0 ) return;
151492 ExprSetProperty(pVal, EP_IntValue);
151493 pVal->u.iValue = iVal;
151494 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
151495 }else{
151496 Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0);
151497 if( pVal==0 ) return;
151498 pVal->iTable = iReg;
151499 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
151500 }
151501 if( pNew ){
151502 WhereTerm *pTerm;
151503 int idx;
151504 idx = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_VIRTUAL);
151505 pTerm = &pWC->a[idx];
151506 pTerm->leftCursor = iCsr;
151507 pTerm->eOperator = WO_AUX;
151508 pTerm->eMatchOp = eMatchOp;
151509 }
151510 }
151511
151512 /*
151513 ** Possibly add terms corresponding to the LIMIT and OFFSET clauses of the
151514 ** SELECT statement passed as the second argument. These terms are only
151515 ** added if:
151516 **
151517 ** 1. The SELECT statement has a LIMIT clause, and
151518 ** 2. The SELECT statement is not an aggregate or DISTINCT query, and
151519 ** 3. The SELECT statement has exactly one object in its from clause, and
151520 ** that object is a virtual table, and
151521 ** 4. There are no terms in the WHERE clause that will not be passed
151522 ** to the virtual table xBestIndex method.
151523 ** 5. The ORDER BY clause, if any, will be made available to the xBestIndex
151524 ** method.
151525 **
151526 ** LIMIT and OFFSET terms are ignored by most of the planner code. They
151527 ** exist only so that they may be passed to the xBestIndex method of the
151528 ** single virtual table in the FROM clause of the SELECT.
151529 */
151530 SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){
151531 assert( p==0 || (p->pGroupBy==0 && (p->selFlags & SF_Aggregate)==0) );
151532 if( (p && p->pLimit) /* 1 */
151533 && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */
151534 && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */
151535 ){
151536 ExprList *pOrderBy = p->pOrderBy;
151537 int iCsr = p->pSrc->a[0].iCursor;
151538 int ii;
151539
151540 /* Check condition (4). Return early if it is not met. */
151541 for(ii=0; ii<pWC->nTerm; ii++){
151542 if( pWC->a[ii].wtFlags & TERM_CODED ){
151543 /* This term is a vector operation that has been decomposed into
151544 ** other, subsequent terms. It can be ignored. See tag-20220128a */
151545 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
151546 assert( pWC->a[ii].eOperator==0 );
151547 continue;
151548 }
151549 if( pWC->a[ii].leftCursor!=iCsr ) return;
151550 }
151551
151552 /* Check condition (5). Return early if it is not met. */
151553 if( pOrderBy ){
151554 for(ii=0; ii<pOrderBy->nExpr; ii++){
151555 Expr *pExpr = pOrderBy->a[ii].pExpr;
151556 if( pExpr->op!=TK_COLUMN ) return;
151557 if( pExpr->iTable!=iCsr ) return;
151558 if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
151559 }
151560 }
151561
151562 /* All conditions are met. Add the terms to the where-clause object. */
151563 assert( p->pLimit->op==TK_LIMIT );
151564 whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft,
151565 iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT);
151566 if( p->iOffset>0 ){
151567 whereAddLimitExpr(pWC, p->iOffset, p->pLimit->pRight,
151568 iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET);
151569 }
151570 }
151571 }
151572
151573 /*
151574 ** Initialize a preallocated WhereClause structure.
151575 */
151576 SQLITE_PRIVATE void sqlite3WhereClauseInit(
@@ -150966,10 +151603,11 @@
151603 for(i=pWC->nBase; i<pWC->nTerm; i++){
151604 assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 );
151605 }
151606 #endif
151607 while(1){
151608 assert( a->eMatchOp==0 || a->eOperator==WO_AUX );
151609 if( a->wtFlags & TERM_DYNAMIC ){
151610 sqlite3ExprDelete(db, a->pExpr);
151611 }
151612 if( a->wtFlags & (TERM_ORINFO|TERM_ANDINFO) ){
151613 if( a->wtFlags & TERM_ORINFO ){
@@ -151123,10 +151761,11 @@
151761 if( pColRef==0 ) return;
151762 pColRef->iTable = pItem->iCursor;
151763 pColRef->iColumn = k++;
151764 assert( ExprUseYTab(pColRef) );
151765 pColRef->y.pTab = pTab;
151766 pItem->colUsed |= sqlite3ExprColUsed(pColRef);
151767 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
151768 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
151769 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
151770 if( pItem->fg.jointype & JT_LEFT ){
151771 sqlite3SetJoinExpr(pTerm, pItem->iCursor);
@@ -151167,12 +151806,18 @@
151806 ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
151807 ** agree on the structure, all will be well.
151808 */
151809 typedef struct HiddenIndexInfo HiddenIndexInfo;
151810 struct HiddenIndexInfo {
151811 WhereClause *pWC; /* The Where clause being analyzed */
151812 Parse *pParse; /* The parsing context */
151813 int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
151814 u32 mIn; /* Mask of terms that are <col> IN (...) */
151815 u32 mHandleIn; /* Terms that vtab will handle as <col> IN (...) */
151816 sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151817 ** because extra space is allocated to hold up
151818 ** to nTerm such values */
151819 };
151820
151821 /* Forward declaration of methods */
151822 static int whereLoopResize(sqlite3*, WhereLoop*, int);
151823
@@ -152232,31 +152877,33 @@
152877
152878 #ifndef SQLITE_OMIT_VIRTUALTABLE
152879 /*
152880 ** Allocate and populate an sqlite3_index_info structure. It is the
152881 ** responsibility of the caller to eventually release the structure
152882 ** by passing the pointer returned by this function to freeIndexInfo().
152883 */
152884 static sqlite3_index_info *allocateIndexInfo(
152885 WhereInfo *pWInfo, /* The WHERE clause */
152886 WhereClause *pWC, /* The WHERE clause being analyzed */
152887 Bitmask mUnusable, /* Ignore terms with these prereqs */
152888 SrcItem *pSrc, /* The FROM clause term that is the vtab */
 
152889 u16 *pmNoOmit /* Mask of terms not to omit */
152890 ){
152891 int i, j;
152892 int nTerm;
152893 Parse *pParse = pWInfo->pParse;
152894 struct sqlite3_index_constraint *pIdxCons;
152895 struct sqlite3_index_orderby *pIdxOrderBy;
152896 struct sqlite3_index_constraint_usage *pUsage;
152897 struct HiddenIndexInfo *pHidden;
152898 WhereTerm *pTerm;
152899 int nOrderBy;
152900 sqlite3_index_info *pIdxInfo;
152901 u16 mNoOmit = 0;
152902 const Table *pTab;
152903 int eDistinct = 0;
152904 ExprList *pOrderBy = pWInfo->pOrderBy;
152905
152906 assert( pSrc!=0 );
152907 pTab = pSrc->pTab;
152908 assert( pTab!=0 );
152909 assert( IsVirtual(pTab) );
@@ -152274,10 +152921,11 @@
152921 testcase( pTerm->eOperator & WO_ISNULL );
152922 testcase( pTerm->eOperator & WO_IS );
152923 testcase( pTerm->eOperator & WO_ALL );
152924 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
152925 if( pTerm->wtFlags & TERM_VNULL ) continue;
152926
152927 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152928 assert( pTerm->u.x.leftColumn>=XN_ROWID );
152929 assert( pTerm->u.x.leftColumn<pTab->nCol );
152930
152931 /* tag-20191211-002: WHERE-clause constraints are not useful to the
@@ -152335,40 +152983,49 @@
152983 }
152984
152985 /* No matches cause a break out of the loop */
152986 break;
152987 }
152988 if( i==n ){
152989 nOrderBy = n;
152990 if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152991 eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152992 }
152993 }
152994 }
152995
152996 /* Allocate the sqlite3_index_info structure
152997 */
152998 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
152999 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
153000 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden)
153001 + sizeof(sqlite3_value*)*nTerm );
153002 if( pIdxInfo==0 ){
153003 sqlite3ErrorMsg(pParse, "out of memory");
153004 return 0;
153005 }
153006 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
153007 pIdxCons = (struct sqlite3_index_constraint*)&pHidden->aRhs[nTerm];
153008 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
153009 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
153010 pIdxInfo->aConstraint = pIdxCons;
153011 pIdxInfo->aOrderBy = pIdxOrderBy;
153012 pIdxInfo->aConstraintUsage = pUsage;
153013 pHidden->pWC = pWC;
153014 pHidden->pParse = pParse;
153015 pHidden->eDistinct = eDistinct;
153016 pHidden->mIn = 0;
153017 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
153018 u16 op;
153019 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
153020 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
153021 pIdxCons[j].iTermOffset = i;
153022 op = pTerm->eOperator & WO_ALL;
153023 if( op==WO_IN ){
153024 pHidden->mIn |= SMASKBIT32(j);
153025 op = WO_EQ;
153026 }
153027 if( op==WO_AUX ){
153028 pIdxCons[j].op = pTerm->eMatchOp;
153029 }else if( op & (WO_ISNULL|WO_IS) ){
153030 if( op==WO_ISNULL ){
153031 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
@@ -152414,10 +153071,28 @@
153071 pIdxInfo->nOrderBy = j;
153072
153073 *pmNoOmit = mNoOmit;
153074 return pIdxInfo;
153075 }
153076
153077 /*
153078 ** Free an sqlite3_index_info structure allocated by allocateIndexInfo()
153079 ** and possibly modified by xBestIndex methods.
153080 */
153081 static void freeIndexInfo(sqlite3 *db, sqlite3_index_info *pIdxInfo){
153082 HiddenIndexInfo *pHidden;
153083 int i;
153084 assert( pIdxInfo!=0 );
153085 pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
153086 assert( pHidden->pParse!=0 );
153087 assert( pHidden->pParse->db==db );
153088 for(i=0; i<pIdxInfo->nConstraint; i++){
153089 sqlite3ValueFree(pHidden->aRhs[i]); /* IMP: R-14553-25174 */
153090 pHidden->aRhs[i] = 0;
153091 }
153092 sqlite3DbFree(db, pIdxInfo);
153093 }
153094
153095 /*
153096 ** The table object reference passed as the second argument to this function
153097 ** must represent a virtual table. This function invokes the xBestIndex()
153098 ** method of the virtual table with the sqlite3_index_info object that
@@ -152436,11 +153111,13 @@
153111 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
153112 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
153113 int rc;
153114
153115 whereTraceIndexInfoInputs(p);
153116 pParse->db->nSchemaLock++;
153117 rc = pVtab->pModule->xBestIndex(pVtab, p);
153118 pParse->db->nSchemaLock--;
153119 whereTraceIndexInfoOutputs(p);
153120
153121 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
153122 if( rc==SQLITE_NOMEM ){
153123 sqlite3OomFault(pParse->db);
@@ -154566,10 +155243,19 @@
155243 }
155244 return rc;
155245 }
155246
155247 #ifndef SQLITE_OMIT_VIRTUALTABLE
155248
155249 /*
155250 ** Return true if pTerm is a virtual table LIMIT or OFFSET term.
155251 */
155252 static int isLimitTerm(WhereTerm *pTerm){
155253 assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 );
155254 return pTerm->eMatchOp>=SQLITE_INDEX_CONSTRAINT_LIMIT
155255 && pTerm->eMatchOp<=SQLITE_INDEX_CONSTRAINT_OFFSET;
155256 }
155257
155258 /*
155259 ** Argument pIdxInfo is already populated with all constraints that may
155260 ** be used by the virtual table identified by pBuilder->pNew->iTab. This
155261 ** function marks a subset of those constraints usable, invokes the
@@ -154594,13 +155280,15 @@
155280 Bitmask mPrereq, /* Mask of tables that must be used. */
155281 Bitmask mUsable, /* Mask of usable tables */
155282 u16 mExclude, /* Exclude terms using these operators */
155283 sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */
155284 u16 mNoOmit, /* Do not omit these constraints */
155285 int *pbIn, /* OUT: True if plan uses an IN(...) op */
155286 int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */
155287 ){
155288 WhereClause *pWC = pBuilder->pWC;
155289 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155290 struct sqlite3_index_constraint *pIdxCons;
155291 struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
155292 int i;
155293 int mxTerm;
155294 int rc = SQLITE_OK;
@@ -154619,10 +155307,11 @@
155307 for(i=0; i<nConstraint; i++, pIdxCons++){
155308 WhereTerm *pTerm = &pWC->a[pIdxCons->iTermOffset];
155309 pIdxCons->usable = 0;
155310 if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight
155311 && (pTerm->eOperator & mExclude)==0
155312 && (pbRetryLimit || !isLimitTerm(pTerm))
155313 ){
155314 pIdxCons->usable = 1;
155315 }
155316 }
155317
@@ -154634,10 +155323,11 @@
155323 pIdxInfo->orderByConsumed = 0;
155324 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
155325 pIdxInfo->estimatedRows = 25;
155326 pIdxInfo->idxFlags = 0;
155327 pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
155328 pHidden->mHandleIn = 0;
155329
155330 /* Invoke the virtual table xBestIndex() method */
155331 rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
155332 if( rc ){
155333 if( rc==SQLITE_CONSTRAINT ){
@@ -154651,12 +155341,12 @@
155341 return rc;
155342 }
155343
155344 mxTerm = -1;
155345 assert( pNew->nLSlot>=nConstraint );
155346 memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint );
155347 memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab));
155348 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
155349 for(i=0; i<nConstraint; i++, pIdxCons++){
155350 int iTerm;
155351 if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
155352 WhereTerm *pTerm;
@@ -154686,21 +155376,41 @@
155376 testcase( i!=iTerm );
155377 pNew->u.vtab.omitMask |= 1<<iTerm;
155378 }else{
155379 testcase( i!=iTerm );
155380 }
155381 if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){
155382 pNew->u.vtab.bOmitOffset = 1;
155383 }
155384 }
155385 if( SMASKBIT32(i) & pHidden->mHandleIn ){
155386 pNew->u.vtab.mHandleIn |= MASKBIT32(iTerm);
155387 }else if( (pTerm->eOperator & WO_IN)!=0 ){
155388 /* A virtual table that is constrained by an IN clause may not
155389 ** consume the ORDER BY clause because (1) the order of IN terms
155390 ** is not necessarily related to the order of output terms and
155391 ** (2) Multiple outputs from a single IN value will not merge
155392 ** together. */
155393 pIdxInfo->orderByConsumed = 0;
155394 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
155395 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
155396 }
155397
155398 if( isLimitTerm(pTerm) && *pbIn ){
155399 /* If there is an IN(...) term handled as an == (separate call to
155400 ** xFilter for each value on the RHS of the IN) and a LIMIT or
155401 ** OFFSET term handled as well, the plan is unusable. Set output
155402 ** variable *pbRetryLimit to true to tell the caller to retry with
155403 ** LIMIT and OFFSET disabled. */
155404 if( pIdxInfo->needToFreeIdxStr ){
155405 sqlite3_free(pIdxInfo->idxStr);
155406 pIdxInfo->idxStr = 0;
155407 pIdxInfo->needToFreeIdxStr = 0;
155408 }
155409 *pbRetryLimit = 1;
155410 return SQLITE_OK;
155411 }
155412 }
155413 }
155414
155415 pNew->nLTerm = mxTerm+1;
155416 for(i=0; i<=mxTerm; i++){
@@ -154769,10 +155479,77 @@
155479 }
155480 zRet = (pC ? pC->zName : sqlite3StrBINARY);
155481 }
155482 return zRet;
155483 }
155484
155485 /*
155486 ** Return true if constraint iCons is really an IN(...) constraint, or
155487 ** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
155488 ** or clear (if bHandle==0) the flag to handle it using an iterator.
155489 */
155490 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *pIdxInfo, int iCons, int bHandle){
155491 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155492 u32 m = SMASKBIT32(iCons);
155493 if( m & pHidden->mIn ){
155494 if( bHandle==0 ){
155495 pHidden->mHandleIn &= ~m;
155496 }else if( bHandle>0 ){
155497 pHidden->mHandleIn |= m;
155498 }
155499 return 1;
155500 }
155501 return 0;
155502 }
155503
155504 /*
155505 ** This interface is callable from within the xBestIndex callback only.
155506 **
155507 ** If possible, set (*ppVal) to point to an object containing the value
155508 ** on the right-hand-side of constraint iCons.
155509 */
155510 SQLITE_API int sqlite3_vtab_rhs_value(
155511 sqlite3_index_info *pIdxInfo, /* Copy of first argument to xBestIndex */
155512 int iCons, /* Constraint for which RHS is wanted */
155513 sqlite3_value **ppVal /* Write value extracted here */
155514 ){
155515 HiddenIndexInfo *pH = (HiddenIndexInfo*)&pIdxInfo[1];
155516 sqlite3_value *pVal = 0;
155517 int rc = SQLITE_OK;
155518 if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
155519 rc = SQLITE_MISUSE; /* EV: R-30545-25046 */
155520 }else{
155521 if( pH->aRhs[iCons]==0 ){
155522 WhereTerm *pTerm = &pH->pWC->a[pIdxInfo->aConstraint[iCons].iTermOffset];
155523 rc = sqlite3ValueFromExpr(
155524 pH->pParse->db, pTerm->pExpr->pRight, ENC(pH->pParse->db),
155525 SQLITE_AFF_BLOB, &pH->aRhs[iCons]
155526 );
155527 testcase( rc!=SQLITE_OK );
155528 }
155529 pVal = pH->aRhs[iCons];
155530 }
155531 *ppVal = pVal;
155532
155533 if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
155534 rc = SQLITE_NOTFOUND; /* IMP: R-36424-56542 */
155535 }
155536
155537 return rc;
155538 }
155539
155540
155541 /*
155542 ** Return true if ORDER BY clause may be handled as DISTINCT.
155543 */
155544 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155545 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155546 assert( pHidden->eDistinct==0
155547 || pHidden->eDistinct==1
155548 || pHidden->eDistinct==2 );
155549 return pHidden->eDistinct;
155550 }
155551
155552 /*
155553 ** Add all WhereLoop objects for a table of the join identified by
155554 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
155555 **
@@ -154811,35 +155588,43 @@
155588 int nConstraint; /* Number of constraints in p */
155589 int bIn; /* True if plan uses IN(...) operator */
155590 WhereLoop *pNew;
155591 Bitmask mBest; /* Tables used by best possible plan */
155592 u16 mNoOmit;
155593 int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */
155594
155595 assert( (mPrereq & mUnusable)==0 );
155596 pWInfo = pBuilder->pWInfo;
155597 pParse = pWInfo->pParse;
155598 pWC = pBuilder->pWC;
155599 pNew = pBuilder->pNew;
155600 pSrc = &pWInfo->pTabList->a[pNew->iTab];
155601 assert( IsVirtual(pSrc->pTab) );
155602 p = allocateIndexInfo(pWInfo, pWC, mUnusable, pSrc, &mNoOmit);
 
155603 if( p==0 ) return SQLITE_NOMEM_BKPT;
155604 pNew->rSetup = 0;
155605 pNew->wsFlags = WHERE_VIRTUALTABLE;
155606 pNew->nLTerm = 0;
155607 pNew->u.vtab.needFree = 0;
155608 nConstraint = p->nConstraint;
155609 if( whereLoopResize(pParse->db, pNew, nConstraint) ){
155610 freeIndexInfo(pParse->db, p);
155611 return SQLITE_NOMEM_BKPT;
155612 }
155613
155614 /* First call xBestIndex() with all constraints usable. */
155615 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
155616 WHERETRACE(0x40, (" VirtualOne: all usable\n"));
155617 rc = whereLoopAddVirtualOne(
155618 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry
155619 );
155620 if( bRetry ){
155621 assert( rc==SQLITE_OK );
155622 rc = whereLoopAddVirtualOne(
155623 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0
155624 );
155625 }
155626
155627 /* If the call to xBestIndex() with all terms enabled produced a plan
155628 ** that does not require any source tables (IOW: a plan with mBest==0)
155629 ** and does not use an IN(...) operator, then there is no point in making
155630 ** any further calls to xBestIndex() since they will all return the same
@@ -154853,11 +155638,11 @@
155638 /* If the plan produced by the earlier call uses an IN(...) term, call
155639 ** xBestIndex again, this time with IN(...) terms disabled. */
155640 if( bIn ){
155641 WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n"));
155642 rc = whereLoopAddVirtualOne(
155643 pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0);
155644 assert( bIn==0 );
155645 mBestNoIn = pNew->prereq & ~mPrereq;
155646 if( mBestNoIn==0 ){
155647 seenZero = 1;
155648 seenZeroNoIN = 1;
@@ -154880,11 +155665,11 @@
155665 if( mNext==ALLBITS ) break;
155666 if( mNext==mBest || mNext==mBestNoIn ) continue;
155667 WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
155668 (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext));
155669 rc = whereLoopAddVirtualOne(
155670 pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0);
155671 if( pNew->prereq==mPrereq ){
155672 seenZero = 1;
155673 if( bIn==0 ) seenZeroNoIN = 1;
155674 }
155675 }
@@ -154893,26 +155678,26 @@
155678 ** that requires no source tables at all (i.e. one guaranteed to be
155679 ** usable), make a call here with all source tables disabled */
155680 if( rc==SQLITE_OK && seenZero==0 ){
155681 WHERETRACE(0x40, (" VirtualOne: all disabled\n"));
155682 rc = whereLoopAddVirtualOne(
155683 pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0);
155684 if( bIn==0 ) seenZeroNoIN = 1;
155685 }
155686
155687 /* If the calls to xBestIndex() have so far failed to find a plan
155688 ** that requires no source tables at all and does not use an IN(...)
155689 ** operator, make a final call to obtain one here. */
155690 if( rc==SQLITE_OK && seenZeroNoIN==0 ){
155691 WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n"));
155692 rc = whereLoopAddVirtualOne(
155693 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0);
155694 }
155695 }
155696
155697 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
155698 freeIndexInfo(pParse->db, p);
155699 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
155700 return rc;
155701 }
155702 #endif /* SQLITE_OMIT_VIRTUALTABLE */
155703
@@ -154952,11 +155737,10 @@
155737 WhereTerm *pOrTerm;
155738 int once = 1;
155739 int i, j;
155740
155741 sSubBuild = *pBuilder;
 
155742 sSubBuild.pOrSet = &sCur;
155743
155744 WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
155745 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
155746 if( (pOrTerm->eOperator & WO_AND)!=0 ){
@@ -156310,10 +157094,11 @@
157094 Parse *pParse, /* The parser context */
157095 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
157096 Expr *pWhere, /* The WHERE clause */
157097 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
157098 ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */
157099 Select *pLimit, /* Use this LIMIT/OFFSET clause, if any */
157100 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
157101 int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
157102 ** If WHERE_USE_LIMIT, then the limit amount */
157103 ){
157104 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
@@ -156344,11 +157129,10 @@
157129 memset(&sWLB, 0, sizeof(sWLB));
157130
157131 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
157132 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
157133 if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
 
157134
157135 /* The number of tables in the FROM clause is limited by the number of
157136 ** bits in a Bitmask
157137 */
157138 testcase( pTabList->nSrc==BMS );
@@ -156387,10 +157171,13 @@
157171 pWInfo->nLevel = nTabList;
157172 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
157173 pWInfo->wctrlFlags = wctrlFlags;
157174 pWInfo->iLimit = iAuxArg;
157175 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
157176 #ifndef SQLITE_OMIT_VIRTUALTABLE
157177 pWInfo->pLimit = pLimit;
157178 #endif
157179 memset(&pWInfo->nOBSat, 0,
157180 offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
157181 memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
157182 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
157183 pMaskSet = &pWInfo->sMaskSet;
@@ -156455,10 +157242,11 @@
157242 #endif
157243 }
157244
157245 /* Analyze all of the subexpressions. */
157246 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
157247 sqlite3WhereAddLimit(&pWInfo->sWC, pLimit);
157248 if( db->mallocFailed ) goto whereBeginError;
157249
157250 /* Special case: WHERE terms that do not refer to any tables in the join
157251 ** (constant expressions). Evaluate each such term, and jump over all the
157252 ** generated code if the result is not true.
@@ -156554,13 +157342,14 @@
157342 }
157343 }
157344 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
157345 pWInfo->revMask = ALLBITS;
157346 }
157347 if( pParse->nErr ){
157348 goto whereBeginError;
157349 }
157350 assert( db->mallocFailed==0 );
157351 #ifdef WHERETRACE_ENABLED
157352 if( sqlite3WhereTrace ){
157353 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
157354 if( pWInfo->nOBSat>0 ){
157355 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
@@ -156700,10 +157489,11 @@
157489 testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 );
157490 testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS );
157491 if( pWInfo->eOnePass==ONEPASS_OFF
157492 && pTab->nCol<BMS
157493 && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
157494 && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0
157495 ){
157496 /* If we know that only a prefix of the record will be used,
157497 ** it is advantageous to reduce the "column count" field in
157498 ** the P4 operand of the OP_OpenRead/Write opcode. */
157499 Bitmask b = pTabItem->colUsed;
@@ -158264,16 +159054,11 @@
159054 ** there could still be references to that table embedded in the
159055 ** result-set or ORDER BY clause of the SELECT statement p. */
159056 sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab);
159057 }
159058
159059 assert( rc==SQLITE_OK || pParse->nErr!=0 );
 
 
 
 
 
159060 return rc;
159061 }
159062
159063 /*
159064 ** Unlink the Window object from the Select to which it is attached,
@@ -193955,12 +194740,12 @@
194740 sqlite3_result_error_nomem(ctx);
194741 goto jsonSetDone;
194742 }else if( x.nErr ){
194743 goto jsonSetDone;
194744 }else if( pNode && (bApnd || bIsSet) ){
194745 testcase( pNode->eU!=0 && pNode->eU!=1 );
194746 assert( pNode->eU!=3 && pNode->eU!=5 );
194747 VVA( pNode->eU = 4 );
194748 pNode->jnFlags |= (u8)JNODE_REPLACE;
194749 pNode->u.iReplace = i + 1;
194750 }
194751 }
@@ -194737,11 +195522,11 @@
195522 sqlite3_module *pModule;
195523 } aMod[] = {
195524 { "json_each", &jsonEachModule },
195525 { "json_tree", &jsonTreeModule },
195526 };
195527 unsigned int i;
195528 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
195529 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
195530 }
195531 return rc;
195532 }
@@ -233334,11 +234119,11 @@
234119 int nArg, /* Number of args */
234120 sqlite3_value **apUnused /* Function arguments */
234121 ){
234122 assert( nArg==0 );
234123 UNUSED_PARAM2(nArg, apUnused);
234124 sqlite3_result_text(pCtx, "fts5: 2022-01-25 16:28:57 6e4154d414afe2562b488149b10c175d1f15bd1d5060ee479d5ae9386a2e277e", -1, SQLITE_TRANSIENT);
234125 }
234126
234127 /*
234128 ** Return true if zName is the extension on one of the shadow tables used
234129 ** by this module.
234130
+284 -19
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.38.0"
150150
#define SQLITE_VERSION_NUMBER 3038000
151
-#define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
151
+#define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -4350,10 +4350,12 @@
43504350
** still make the distinction between protected and unprotected
43514351
** sqlite3_value objects even when not strictly required.
43524352
**
43534353
** ^The sqlite3_value objects that are passed as parameters into the
43544354
** implementation of [application-defined SQL functions] are protected.
4355
+** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4356
+** are protected.
43554357
** ^The sqlite3_value object returned by
43564358
** [sqlite3_column_value()] is unprotected.
43574359
** Unprotected sqlite3_value objects may only be used as arguments
43584360
** to [sqlite3_result_value()], [sqlite3_bind_value()], and
43594361
** [sqlite3_value_dup()].
@@ -7129,28 +7131,60 @@
71297131
/*
71307132
** CAPI3REF: Virtual Table Constraint Operator Codes
71317133
**
71327134
** These macros define the allowed values for the
71337135
** [sqlite3_index_info].aConstraint[].op field. Each value represents
7134
-** an operator that is part of a constraint term in the wHERE clause of
7136
+** an operator that is part of a constraint term in the WHERE clause of
71357137
** a query that uses a [virtual table].
7138
+**
7139
+** ^The left-hand operand of the operator is given by the corresponding
7140
+** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
7141
+** operand is the rowid.
7142
+** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
7143
+** operators have no left-hand operand, and so for those operators the
7144
+** corresponding aConstraint[].iColumn is meaningless and should not be
7145
+** used.
7146
+**
7147
+** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
7148
+** value 255 are reserved to represent functions that are overloaded
7149
+** by the [xFindFunction|xFindFunction method] of the virtual table
7150
+** implementation.
7151
+**
7152
+** The right-hand operands for each constraint might be accessible using
7153
+** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
7154
+** operand is only available if it appears as a single constant literal
7155
+** in the input SQL. If the right-hand operand is another column or an
7156
+** expression (even a constant expression) or a parameter, then the
7157
+** sqlite3_vtab_rhs_value() probably will not be able to extract it.
7158
+** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
7159
+** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
7160
+** and hence calls to sqlite3_vtab_rhs_value() for those operators will
7161
+** always return SQLITE_NOTFOUND.
7162
+**
7163
+** The collating sequence to be used for comparison can be found using
7164
+** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7165
+** tables, the collating sequence of constraints does not matter (for example
7166
+** because the constraints are numeric) and so the sqlite3_vtab_collation()
7167
+** interface is no commonly needed.
71367168
*/
7137
-#define SQLITE_INDEX_CONSTRAINT_EQ 2
7138
-#define SQLITE_INDEX_CONSTRAINT_GT 4
7139
-#define SQLITE_INDEX_CONSTRAINT_LE 8
7140
-#define SQLITE_INDEX_CONSTRAINT_LT 16
7141
-#define SQLITE_INDEX_CONSTRAINT_GE 32
7142
-#define SQLITE_INDEX_CONSTRAINT_MATCH 64
7143
-#define SQLITE_INDEX_CONSTRAINT_LIKE 65
7144
-#define SQLITE_INDEX_CONSTRAINT_GLOB 66
7145
-#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7146
-#define SQLITE_INDEX_CONSTRAINT_NE 68
7147
-#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7148
-#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7149
-#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7150
-#define SQLITE_INDEX_CONSTRAINT_IS 72
7151
-#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
7169
+#define SQLITE_INDEX_CONSTRAINT_EQ 2
7170
+#define SQLITE_INDEX_CONSTRAINT_GT 4
7171
+#define SQLITE_INDEX_CONSTRAINT_LE 8
7172
+#define SQLITE_INDEX_CONSTRAINT_LT 16
7173
+#define SQLITE_INDEX_CONSTRAINT_GE 32
7174
+#define SQLITE_INDEX_CONSTRAINT_MATCH 64
7175
+#define SQLITE_INDEX_CONSTRAINT_LIKE 65
7176
+#define SQLITE_INDEX_CONSTRAINT_GLOB 66
7177
+#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7178
+#define SQLITE_INDEX_CONSTRAINT_NE 68
7179
+#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7180
+#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7181
+#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7182
+#define SQLITE_INDEX_CONSTRAINT_IS 72
7183
+#define SQLITE_INDEX_CONSTRAINT_LIMIT 73
7184
+#define SQLITE_INDEX_CONSTRAINT_OFFSET 74
7185
+#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
71527186
71537187
/*
71547188
** CAPI3REF: Register A Virtual Table Implementation
71557189
** METHOD: sqlite3
71567190
**
@@ -9469,25 +9503,26 @@
94699503
*/
94709504
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
94719505
94729506
/*
94739507
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9508
+** METHOD: sqlite3_index_info
94749509
**
94759510
** This function may only be called from within a call to the [xBestIndex]
94769511
** method of a [virtual table]. This function returns a pointer to a string
94779512
** that is the name of the appropriate collation sequence to use for text
94789513
** comparisons on the constraint identified by its arguments.
94799514
**
9480
-** The first argument must be the pointer to the sqlite3_index_info object
9515
+** The first argument must be the pointer to the [sqlite3_index_info] object
94819516
** that is the first parameter to the xBestIndex() method. The second argument
94829517
** must be an index into the aConstraint[] array belonging to the
94839518
** sqlite3_index_info structure passed to xBestIndex.
94849519
**
94859520
** Important:
94869521
** The first parameter must be the same pointer that is passed into the
94879522
** xBestMethod() method. The first parameter may not be a pointer to a
9488
-** different sqlite3_index_info object, even an exact copy.
9523
+** different [sqlite3_index_info] object, even an exact copy.
94899524
**
94909525
** The return value is computed as follows:
94919526
**
94929527
** <ol>
94939528
** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9501,10 +9536,240 @@
95019536
** <li><p> Otherwise, "BINARY" is returned.
95029537
** </ol>
95039538
*/
95049539
SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
95059540
9541
+/*
9542
+** CAPI3REF: Determine if a virtual table query is DISTINCT
9543
+** METHOD: sqlite3_index_info
9544
+**
9545
+** This API may only be used from within an [xBestIndex|xBestIndex method]
9546
+** of a [virtual table] implementation. The result of calling this
9547
+** interface from outside of xBestIndex() is undefined and probably harmful.
9548
+**
9549
+** ^The sqlite3_vtab_distinct() interface returns an integer that is
9550
+** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9551
+** gives the virtual table additional information about how the query
9552
+** planner wants the output to be ordered. As long as the virtual table
9553
+** can meet the ordering requirements of the query planner, it may set
9554
+** the "orderByConsumed" flag.
9555
+**
9556
+** <ol><li value="0"><p>
9557
+** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9558
+** that the query planner needs the virtual table to return all rows in the
9559
+** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9560
+** [sqlite3_index_info] object. This is the default expectation. If the
9561
+** virtual table outputs all rows in sorted order, then it is always safe for
9562
+** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9563
+** the return value from sqlite3_vtab_distinct().
9564
+** <li value="1"><p>
9565
+** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9566
+** that the query planner does not need the rows to be returned in sorted order
9567
+** as long as all rows with the same values in all columns identified by the
9568
+** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9569
+** is doing a GROUP BY.
9570
+** <li value="2"><p>
9571
+** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9572
+** that the query planner does not need the rows returned in any particular
9573
+** order, as long as rows with the same values in all "aOrderBy" columns
9574
+** are adjacent.)^ ^(Furthermore, only a single row for each particular
9575
+** combination of values in the columns identified by the "aOrderBy" field
9576
+** needs to be returned.)^ ^It is always ok for two or more rows with the same
9577
+** values in all "aOrderBy" columns to be returned, as long as all such rows
9578
+** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9579
+** that have the same value for all columns identified by "aOrderBy".
9580
+** ^However omitting the extra rows is optional.
9581
+** This mode is used for a DISTINCT query.
9582
+** </ol>
9583
+**
9584
+** ^For the purposes of comparing virtual table output values to see if the
9585
+** values are same value for sorting purposes, two NULL values are considered
9586
+** to be the same. In other words, the comparison operator is "IS"
9587
+** (or "IS NOT DISTINCT FROM") and not "==".
9588
+**
9589
+** If a virtual table implementation is unable to meet the requirements
9590
+** specified above, then it must not set the "orderByConsumed" flag in the
9591
+** [sqlite3_index_info] object or an incorrect answer may result.
9592
+**
9593
+** ^A virtual table implementation is always free to return rows in any order
9594
+** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9595
+** the "orderByConsumed" flag is unset, the query planner will add extra
9596
+** [bytecode] to ensure that the final results returned by the SQL query are
9597
+** ordered correctly. The use of the "orderByConsumed" flag and the
9598
+** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9599
+** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9600
+** flag might help queries against a virtual table to run faster. Being
9601
+** overly aggressive and setting the "orderByConsumed" flag when it is not
9602
+** valid to do so, on the other hand, might cause SQLite to return incorrect
9603
+** results.
9604
+*/
9605
+SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9606
+
9607
+/*
9608
+** CAPI3REF: Identify and handle IN constraints in xBestIndex
9609
+**
9610
+** This interface may only be used from within an
9611
+** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9612
+** The result of invoking this interface from any other context is
9613
+** undefined and probably harmful.
9614
+**
9615
+** ^(A constraint on a virtual table of the form
9616
+** "[IN operator|column IN (...)]" is
9617
+** communicated to the xBestIndex method as a
9618
+** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9619
+** this constraint, it must set the corresponding
9620
+** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9621
+** the usual mode of handling IN operators, SQLite generates [bytecode]
9622
+** that invokes the [xFilter|xFilter() method] once for each value
9623
+** on the right-hand side of the IN operator.)^ Thus the virtual table
9624
+** only sees a single value from the right-hand side of the IN operator
9625
+** at a time.
9626
+**
9627
+** In some cases, however, it would be advantageous for the virtual
9628
+** table to see all values on the right-hand of the IN operator all at
9629
+** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9630
+**
9631
+** <ol>
9632
+** <li><p>
9633
+** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9634
+** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9635
+** is an [IN operator] that can be processed all at once. ^In other words,
9636
+** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9637
+** by which the virtual table can ask SQLite if all-at-once processing
9638
+** of the IN operator is even possible.
9639
+**
9640
+** <li><p>
9641
+** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9642
+** to SQLite that the virtual table does or does not want to process
9643
+** the IN operator all-at-once, respectively. ^Thus when the third
9644
+** parameter (F) is non-negative, this interface is the mechanism by
9645
+** which the virtual table tells SQLite how it wants to process the
9646
+** IN operator.
9647
+** </ol>
9648
+**
9649
+** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9650
+** within the same xBestIndex method call. ^For any given P,N pair,
9651
+** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9652
+** within the same xBestIndex call. ^If the interface returns true
9653
+** (non-zero), that means that the constraint is an IN operator
9654
+** that can be processed all-at-once. ^If the constraint is not an IN
9655
+** operator or cannot be processed all-at-once, then the interface returns
9656
+** false.
9657
+**
9658
+** ^(All-at-once processing of the IN operator is selected if both of the
9659
+** following conditions are met:
9660
+**
9661
+** <ol>
9662
+** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9663
+** integer. This is how the virtual table tells SQLite that it wants to
9664
+** use the N-th constraint.
9665
+**
9666
+** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9667
+** non-negative had F>=1.
9668
+** </ol>)^
9669
+**
9670
+** ^If either or both of the conditions above are false, then SQLite uses
9671
+** the traditional one-at-a-time processing strategy for the IN constraint.
9672
+** ^If both conditions are true, then the argvIndex-th parameter to the
9673
+** xFilter method will be an [sqlite3_value] that appears to be NULL,
9674
+** but which can be passed to [sqlite3_vtab_in_first()] and
9675
+** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9676
+** of the IN constraint.
9677
+*/
9678
+SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9679
+
9680
+/*
9681
+** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9682
+**
9683
+** These interfaces are only useful from within the
9684
+** [xFilter|xFilter() method] of a [virtual table] implementation.
9685
+** The result of invoking these interfaces from any other context
9686
+** is undefined and probably harmful.
9687
+**
9688
+** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9689
+** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9690
+** xFilter method which invokes these routines, and specifically
9691
+** a parameter that was previously selected for all-at-once IN constraint
9692
+** processing use the [sqlite3_vtab_in()] interface in the
9693
+** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
9694
+** an xFilter argument that was selected for all-at-once IN constraint
9695
+** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
9696
+** exhibit some other undefined or harmful behavior.
9697
+**
9698
+** ^(Use these routines to access all values on the right-hand side
9699
+** of the IN constraint using code like the following:
9700
+**
9701
+** <blockquote><pre>
9702
+** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
9703
+** &nbsp; rc==SQLITE_OK && pVal
9704
+** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
9705
+** &nbsp; ){
9706
+** &nbsp; // do something with pVal
9707
+** &nbsp; }
9708
+** &nbsp; if( rc!=SQLITE_OK ){
9709
+** &nbsp; // an error has occurred
9710
+** &nbsp; }
9711
+** </pre></blockquote>)^
9712
+**
9713
+** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
9714
+** routines return SQLITE_OK and set *P to point to the first or next value
9715
+** on the RHS of the IN constraint. ^If there are no more values on the
9716
+** right hand side of the IN constraint, then *P is set to NULL and these
9717
+** routines return [SQLITE_DONE]. ^The return value might be
9718
+** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
9719
+**
9720
+** The *ppOut values returned by these routines are only valid until the
9721
+** next call to either of these routines or until the end of the xFilter
9722
+** method from which these routines were called. If the virtual table
9723
+** implementation needs to retain the *ppOut values for longer, it must make
9724
+** copies. The *ppOut values are [protected sqlite3_value|protected].
9725
+*/
9726
+SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
9727
+SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
9728
+
9729
+/*
9730
+** CAPI3REF: Constraint values in xBestIndex()
9731
+** METHOD: sqlite3_index_info
9732
+**
9733
+** This API may only be used from within the [xBestIndex|xBestIndex method]
9734
+** of a [virtual table] implementation. The result of calling this interface
9735
+** from outside of an xBestIndex method are undefined and probably harmful.
9736
+**
9737
+** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
9738
+** the [xBestIndex] method of a [virtual table] implementation, with P being
9739
+** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
9740
+** J being a 0-based index into P->aConstraint[], then this routine
9741
+** attempts to set *V to the value of the right-hand operand of
9742
+** that constraint if the right-hand operand is known. ^If the
9743
+** right-hand operand is not known, then *V is set to a NULL pointer.
9744
+** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
9745
+** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
9746
+** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
9747
+** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
9748
+** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
9749
+** something goes wrong.
9750
+**
9751
+** The sqlite3_vtab_rhs_value() interface is usually only successful if
9752
+** the right-hand operand of a constraint is a literal value in the original
9753
+** SQL statement. If the right-hand operand is an expression or a reference
9754
+** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
9755
+** will probably return [SQLITE_NOTFOUND].
9756
+**
9757
+** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
9758
+** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
9759
+** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
9760
+**
9761
+** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
9762
+** and remains valid for the duration of the xBestIndex method call.
9763
+** ^When xBestIndex returns, the sqlite3_value object returned by
9764
+** sqlite3_vtab_rhs_value() is automatically deallocated.
9765
+**
9766
+** The "_rhs_" in the name of this routine is an appreviation for
9767
+** "Right-Hand Side".
9768
+*/
9769
+SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
9770
+
95069771
/*
95079772
** CAPI3REF: Conflict resolution modes
95089773
** KEYWORDS: {conflict resolution mode}
95099774
**
95109775
** These constants are returned by [sqlite3_vtab_on_conflict()] to
95119776
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -4350,10 +4350,12 @@
4350 ** still make the distinction between protected and unprotected
4351 ** sqlite3_value objects even when not strictly required.
4352 **
4353 ** ^The sqlite3_value objects that are passed as parameters into the
4354 ** implementation of [application-defined SQL functions] are protected.
 
 
4355 ** ^The sqlite3_value object returned by
4356 ** [sqlite3_column_value()] is unprotected.
4357 ** Unprotected sqlite3_value objects may only be used as arguments
4358 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4359 ** [sqlite3_value_dup()].
@@ -7129,28 +7131,60 @@
7129 /*
7130 ** CAPI3REF: Virtual Table Constraint Operator Codes
7131 **
7132 ** These macros define the allowed values for the
7133 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7134 ** an operator that is part of a constraint term in the wHERE clause of
7135 ** a query that uses a [virtual table].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7136 */
7137 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7138 #define SQLITE_INDEX_CONSTRAINT_GT 4
7139 #define SQLITE_INDEX_CONSTRAINT_LE 8
7140 #define SQLITE_INDEX_CONSTRAINT_LT 16
7141 #define SQLITE_INDEX_CONSTRAINT_GE 32
7142 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
7143 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
7144 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
7145 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7146 #define SQLITE_INDEX_CONSTRAINT_NE 68
7147 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7148 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7149 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7150 #define SQLITE_INDEX_CONSTRAINT_IS 72
7151 #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
 
 
7152
7153 /*
7154 ** CAPI3REF: Register A Virtual Table Implementation
7155 ** METHOD: sqlite3
7156 **
@@ -9469,25 +9503,26 @@
9469 */
9470 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9471
9472 /*
9473 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
 
9474 **
9475 ** This function may only be called from within a call to the [xBestIndex]
9476 ** method of a [virtual table]. This function returns a pointer to a string
9477 ** that is the name of the appropriate collation sequence to use for text
9478 ** comparisons on the constraint identified by its arguments.
9479 **
9480 ** The first argument must be the pointer to the sqlite3_index_info object
9481 ** that is the first parameter to the xBestIndex() method. The second argument
9482 ** must be an index into the aConstraint[] array belonging to the
9483 ** sqlite3_index_info structure passed to xBestIndex.
9484 **
9485 ** Important:
9486 ** The first parameter must be the same pointer that is passed into the
9487 ** xBestMethod() method. The first parameter may not be a pointer to a
9488 ** different sqlite3_index_info object, even an exact copy.
9489 **
9490 ** The return value is computed as follows:
9491 **
9492 ** <ol>
9493 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9501,10 +9536,240 @@
9501 ** <li><p> Otherwise, "BINARY" is returned.
9502 ** </ol>
9503 */
9504 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9505
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9506 /*
9507 ** CAPI3REF: Conflict resolution modes
9508 ** KEYWORDS: {conflict resolution mode}
9509 **
9510 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
9511
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -4350,10 +4350,12 @@
4350 ** still make the distinction between protected and unprotected
4351 ** sqlite3_value objects even when not strictly required.
4352 **
4353 ** ^The sqlite3_value objects that are passed as parameters into the
4354 ** implementation of [application-defined SQL functions] are protected.
4355 ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4356 ** are protected.
4357 ** ^The sqlite3_value object returned by
4358 ** [sqlite3_column_value()] is unprotected.
4359 ** Unprotected sqlite3_value objects may only be used as arguments
4360 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4361 ** [sqlite3_value_dup()].
@@ -7129,28 +7131,60 @@
7131 /*
7132 ** CAPI3REF: Virtual Table Constraint Operator Codes
7133 **
7134 ** These macros define the allowed values for the
7135 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7136 ** an operator that is part of a constraint term in the WHERE clause of
7137 ** a query that uses a [virtual table].
7138 **
7139 ** ^The left-hand operand of the operator is given by the corresponding
7140 ** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
7141 ** operand is the rowid.
7142 ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
7143 ** operators have no left-hand operand, and so for those operators the
7144 ** corresponding aConstraint[].iColumn is meaningless and should not be
7145 ** used.
7146 **
7147 ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
7148 ** value 255 are reserved to represent functions that are overloaded
7149 ** by the [xFindFunction|xFindFunction method] of the virtual table
7150 ** implementation.
7151 **
7152 ** The right-hand operands for each constraint might be accessible using
7153 ** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
7154 ** operand is only available if it appears as a single constant literal
7155 ** in the input SQL. If the right-hand operand is another column or an
7156 ** expression (even a constant expression) or a parameter, then the
7157 ** sqlite3_vtab_rhs_value() probably will not be able to extract it.
7158 ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
7159 ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
7160 ** and hence calls to sqlite3_vtab_rhs_value() for those operators will
7161 ** always return SQLITE_NOTFOUND.
7162 **
7163 ** The collating sequence to be used for comparison can be found using
7164 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7165 ** tables, the collating sequence of constraints does not matter (for example
7166 ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7167 ** interface is no commonly needed.
7168 */
7169 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7170 #define SQLITE_INDEX_CONSTRAINT_GT 4
7171 #define SQLITE_INDEX_CONSTRAINT_LE 8
7172 #define SQLITE_INDEX_CONSTRAINT_LT 16
7173 #define SQLITE_INDEX_CONSTRAINT_GE 32
7174 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
7175 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
7176 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
7177 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7178 #define SQLITE_INDEX_CONSTRAINT_NE 68
7179 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7180 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7181 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7182 #define SQLITE_INDEX_CONSTRAINT_IS 72
7183 #define SQLITE_INDEX_CONSTRAINT_LIMIT 73
7184 #define SQLITE_INDEX_CONSTRAINT_OFFSET 74
7185 #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
7186
7187 /*
7188 ** CAPI3REF: Register A Virtual Table Implementation
7189 ** METHOD: sqlite3
7190 **
@@ -9469,25 +9503,26 @@
9503 */
9504 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9505
9506 /*
9507 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9508 ** METHOD: sqlite3_index_info
9509 **
9510 ** This function may only be called from within a call to the [xBestIndex]
9511 ** method of a [virtual table]. This function returns a pointer to a string
9512 ** that is the name of the appropriate collation sequence to use for text
9513 ** comparisons on the constraint identified by its arguments.
9514 **
9515 ** The first argument must be the pointer to the [sqlite3_index_info] object
9516 ** that is the first parameter to the xBestIndex() method. The second argument
9517 ** must be an index into the aConstraint[] array belonging to the
9518 ** sqlite3_index_info structure passed to xBestIndex.
9519 **
9520 ** Important:
9521 ** The first parameter must be the same pointer that is passed into the
9522 ** xBestMethod() method. The first parameter may not be a pointer to a
9523 ** different [sqlite3_index_info] object, even an exact copy.
9524 **
9525 ** The return value is computed as follows:
9526 **
9527 ** <ol>
9528 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9501,10 +9536,240 @@
9536 ** <li><p> Otherwise, "BINARY" is returned.
9537 ** </ol>
9538 */
9539 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9540
9541 /*
9542 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9543 ** METHOD: sqlite3_index_info
9544 **
9545 ** This API may only be used from within an [xBestIndex|xBestIndex method]
9546 ** of a [virtual table] implementation. The result of calling this
9547 ** interface from outside of xBestIndex() is undefined and probably harmful.
9548 **
9549 ** ^The sqlite3_vtab_distinct() interface returns an integer that is
9550 ** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9551 ** gives the virtual table additional information about how the query
9552 ** planner wants the output to be ordered. As long as the virtual table
9553 ** can meet the ordering requirements of the query planner, it may set
9554 ** the "orderByConsumed" flag.
9555 **
9556 ** <ol><li value="0"><p>
9557 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9558 ** that the query planner needs the virtual table to return all rows in the
9559 ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9560 ** [sqlite3_index_info] object. This is the default expectation. If the
9561 ** virtual table outputs all rows in sorted order, then it is always safe for
9562 ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9563 ** the return value from sqlite3_vtab_distinct().
9564 ** <li value="1"><p>
9565 ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9566 ** that the query planner does not need the rows to be returned in sorted order
9567 ** as long as all rows with the same values in all columns identified by the
9568 ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9569 ** is doing a GROUP BY.
9570 ** <li value="2"><p>
9571 ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9572 ** that the query planner does not need the rows returned in any particular
9573 ** order, as long as rows with the same values in all "aOrderBy" columns
9574 ** are adjacent.)^ ^(Furthermore, only a single row for each particular
9575 ** combination of values in the columns identified by the "aOrderBy" field
9576 ** needs to be returned.)^ ^It is always ok for two or more rows with the same
9577 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9578 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9579 ** that have the same value for all columns identified by "aOrderBy".
9580 ** ^However omitting the extra rows is optional.
9581 ** This mode is used for a DISTINCT query.
9582 ** </ol>
9583 **
9584 ** ^For the purposes of comparing virtual table output values to see if the
9585 ** values are same value for sorting purposes, two NULL values are considered
9586 ** to be the same. In other words, the comparison operator is "IS"
9587 ** (or "IS NOT DISTINCT FROM") and not "==".
9588 **
9589 ** If a virtual table implementation is unable to meet the requirements
9590 ** specified above, then it must not set the "orderByConsumed" flag in the
9591 ** [sqlite3_index_info] object or an incorrect answer may result.
9592 **
9593 ** ^A virtual table implementation is always free to return rows in any order
9594 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9595 ** the "orderByConsumed" flag is unset, the query planner will add extra
9596 ** [bytecode] to ensure that the final results returned by the SQL query are
9597 ** ordered correctly. The use of the "orderByConsumed" flag and the
9598 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9599 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9600 ** flag might help queries against a virtual table to run faster. Being
9601 ** overly aggressive and setting the "orderByConsumed" flag when it is not
9602 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9603 ** results.
9604 */
9605 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9606
9607 /*
9608 ** CAPI3REF: Identify and handle IN constraints in xBestIndex
9609 **
9610 ** This interface may only be used from within an
9611 ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9612 ** The result of invoking this interface from any other context is
9613 ** undefined and probably harmful.
9614 **
9615 ** ^(A constraint on a virtual table of the form
9616 ** "[IN operator|column IN (...)]" is
9617 ** communicated to the xBestIndex method as a
9618 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9619 ** this constraint, it must set the corresponding
9620 ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9621 ** the usual mode of handling IN operators, SQLite generates [bytecode]
9622 ** that invokes the [xFilter|xFilter() method] once for each value
9623 ** on the right-hand side of the IN operator.)^ Thus the virtual table
9624 ** only sees a single value from the right-hand side of the IN operator
9625 ** at a time.
9626 **
9627 ** In some cases, however, it would be advantageous for the virtual
9628 ** table to see all values on the right-hand of the IN operator all at
9629 ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9630 **
9631 ** <ol>
9632 ** <li><p>
9633 ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9634 ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9635 ** is an [IN operator] that can be processed all at once. ^In other words,
9636 ** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9637 ** by which the virtual table can ask SQLite if all-at-once processing
9638 ** of the IN operator is even possible.
9639 **
9640 ** <li><p>
9641 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9642 ** to SQLite that the virtual table does or does not want to process
9643 ** the IN operator all-at-once, respectively. ^Thus when the third
9644 ** parameter (F) is non-negative, this interface is the mechanism by
9645 ** which the virtual table tells SQLite how it wants to process the
9646 ** IN operator.
9647 ** </ol>
9648 **
9649 ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9650 ** within the same xBestIndex method call. ^For any given P,N pair,
9651 ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9652 ** within the same xBestIndex call. ^If the interface returns true
9653 ** (non-zero), that means that the constraint is an IN operator
9654 ** that can be processed all-at-once. ^If the constraint is not an IN
9655 ** operator or cannot be processed all-at-once, then the interface returns
9656 ** false.
9657 **
9658 ** ^(All-at-once processing of the IN operator is selected if both of the
9659 ** following conditions are met:
9660 **
9661 ** <ol>
9662 ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9663 ** integer. This is how the virtual table tells SQLite that it wants to
9664 ** use the N-th constraint.
9665 **
9666 ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9667 ** non-negative had F>=1.
9668 ** </ol>)^
9669 **
9670 ** ^If either or both of the conditions above are false, then SQLite uses
9671 ** the traditional one-at-a-time processing strategy for the IN constraint.
9672 ** ^If both conditions are true, then the argvIndex-th parameter to the
9673 ** xFilter method will be an [sqlite3_value] that appears to be NULL,
9674 ** but which can be passed to [sqlite3_vtab_in_first()] and
9675 ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9676 ** of the IN constraint.
9677 */
9678 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9679
9680 /*
9681 ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9682 **
9683 ** These interfaces are only useful from within the
9684 ** [xFilter|xFilter() method] of a [virtual table] implementation.
9685 ** The result of invoking these interfaces from any other context
9686 ** is undefined and probably harmful.
9687 **
9688 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9689 ** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9690 ** xFilter method which invokes these routines, and specifically
9691 ** a parameter that was previously selected for all-at-once IN constraint
9692 ** processing use the [sqlite3_vtab_in()] interface in the
9693 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
9694 ** an xFilter argument that was selected for all-at-once IN constraint
9695 ** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
9696 ** exhibit some other undefined or harmful behavior.
9697 **
9698 ** ^(Use these routines to access all values on the right-hand side
9699 ** of the IN constraint using code like the following:
9700 **
9701 ** <blockquote><pre>
9702 ** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
9703 ** &nbsp; rc==SQLITE_OK && pVal
9704 ** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
9705 ** &nbsp; ){
9706 ** &nbsp; // do something with pVal
9707 ** &nbsp; }
9708 ** &nbsp; if( rc!=SQLITE_OK ){
9709 ** &nbsp; // an error has occurred
9710 ** &nbsp; }
9711 ** </pre></blockquote>)^
9712 **
9713 ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
9714 ** routines return SQLITE_OK and set *P to point to the first or next value
9715 ** on the RHS of the IN constraint. ^If there are no more values on the
9716 ** right hand side of the IN constraint, then *P is set to NULL and these
9717 ** routines return [SQLITE_DONE]. ^The return value might be
9718 ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
9719 **
9720 ** The *ppOut values returned by these routines are only valid until the
9721 ** next call to either of these routines or until the end of the xFilter
9722 ** method from which these routines were called. If the virtual table
9723 ** implementation needs to retain the *ppOut values for longer, it must make
9724 ** copies. The *ppOut values are [protected sqlite3_value|protected].
9725 */
9726 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
9727 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
9728
9729 /*
9730 ** CAPI3REF: Constraint values in xBestIndex()
9731 ** METHOD: sqlite3_index_info
9732 **
9733 ** This API may only be used from within the [xBestIndex|xBestIndex method]
9734 ** of a [virtual table] implementation. The result of calling this interface
9735 ** from outside of an xBestIndex method are undefined and probably harmful.
9736 **
9737 ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
9738 ** the [xBestIndex] method of a [virtual table] implementation, with P being
9739 ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
9740 ** J being a 0-based index into P->aConstraint[], then this routine
9741 ** attempts to set *V to the value of the right-hand operand of
9742 ** that constraint if the right-hand operand is known. ^If the
9743 ** right-hand operand is not known, then *V is set to a NULL pointer.
9744 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
9745 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
9746 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
9747 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
9748 ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
9749 ** something goes wrong.
9750 **
9751 ** The sqlite3_vtab_rhs_value() interface is usually only successful if
9752 ** the right-hand operand of a constraint is a literal value in the original
9753 ** SQL statement. If the right-hand operand is an expression or a reference
9754 ** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
9755 ** will probably return [SQLITE_NOTFOUND].
9756 **
9757 ** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
9758 ** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
9759 ** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
9760 **
9761 ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
9762 ** and remains valid for the duration of the xBestIndex method call.
9763 ** ^When xBestIndex returns, the sqlite3_value object returned by
9764 ** sqlite3_vtab_rhs_value() is automatically deallocated.
9765 **
9766 ** The "_rhs_" in the name of this routine is an appreviation for
9767 ** "Right-Hand Side".
9768 */
9769 SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
9770
9771 /*
9772 ** CAPI3REF: Conflict resolution modes
9773 ** KEYWORDS: {conflict resolution mode}
9774 **
9775 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
9776
+1 -1
--- src/alerts.c
+++ src/alerts.c
@@ -2325,11 +2325,11 @@
23252325
sqlite3_int64 iMtime = db_column_int64(&q, 6);
23262326
double rAge = (iNow - iMtime)/86400.0;
23272327
int uid = db_column_int(&q, 8);
23282328
const char *zUname = db_column_text(&q, 3);
23292329
sqlite3_int64 iContact = db_column_int64(&q, 9);
2330
- double rContact = (iNow/86400) - iContact;
2330
+ double rContact = (iNow/86400.0) - iContact;
23312331
@ <tr>
23322332
@ <td><a href='%R/alerts?sid=%d(db_column_int(&q,0))'>\
23332333
@ %h(db_column_text(&q,1))</a></td>
23342334
@ <td>%h(db_column_text(&q,2))</td>
23352335
@ <td>%s(db_column_int(&q,5)?"digest":"")</td>
23362336
--- src/alerts.c
+++ src/alerts.c
@@ -2325,11 +2325,11 @@
2325 sqlite3_int64 iMtime = db_column_int64(&q, 6);
2326 double rAge = (iNow - iMtime)/86400.0;
2327 int uid = db_column_int(&q, 8);
2328 const char *zUname = db_column_text(&q, 3);
2329 sqlite3_int64 iContact = db_column_int64(&q, 9);
2330 double rContact = (iNow/86400) - iContact;
2331 @ <tr>
2332 @ <td><a href='%R/alerts?sid=%d(db_column_int(&q,0))'>\
2333 @ %h(db_column_text(&q,1))</a></td>
2334 @ <td>%h(db_column_text(&q,2))</td>
2335 @ <td>%s(db_column_int(&q,5)?"digest":"")</td>
2336
--- src/alerts.c
+++ src/alerts.c
@@ -2325,11 +2325,11 @@
2325 sqlite3_int64 iMtime = db_column_int64(&q, 6);
2326 double rAge = (iNow - iMtime)/86400.0;
2327 int uid = db_column_int(&q, 8);
2328 const char *zUname = db_column_text(&q, 3);
2329 sqlite3_int64 iContact = db_column_int64(&q, 9);
2330 double rContact = (iNow/86400.0) - iContact;
2331 @ <tr>
2332 @ <td><a href='%R/alerts?sid=%d(db_column_int(&q,0))'>\
2333 @ %h(db_column_text(&q,1))</a></td>
2334 @ <td>%h(db_column_text(&q,2))</td>
2335 @ <td>%s(db_column_int(&q,5)?"digest":"")</td>
2336
+3 -3
--- src/blob.c
+++ src/blob.c
@@ -164,11 +164,11 @@
164164
pBlob->aData = 0;
165165
pBlob->nAlloc = 0;
166166
pBlob->nUsed = 0;
167167
pBlob->iCursor = 0;
168168
pBlob->blobFlags = 0;
169
- }else if( newSize>pBlob->nAlloc || newSize<pBlob->nAlloc-4000 ){
169
+ }else if( newSize>pBlob->nAlloc || newSize+4000<pBlob->nAlloc ){
170170
char *pNew = fossil_realloc(pBlob->aData, newSize);
171171
pBlob->aData = pNew;
172172
pBlob->nAlloc = newSize;
173173
if( pBlob->nUsed>pBlob->nAlloc ){
174174
pBlob->nUsed = pBlob->nAlloc;
@@ -595,12 +595,12 @@
595595
** builds.
596596
*/
597597
void blob_reserve(Blob *pBlob, unsigned int newSize){
598598
if(newSize>=0x7fff0000 ){
599599
blob_panic();
600
- }else if(newSize>pBlob->nUsed){
601
- pBlob->xRealloc(pBlob, newSize);
600
+ }else if(newSize>pBlob->nAlloc){
601
+ pBlob->xRealloc(pBlob, newSize+1);
602602
pBlob->aData[newSize] = 0;
603603
}
604604
}
605605
606606
/*
607607
--- src/blob.c
+++ src/blob.c
@@ -164,11 +164,11 @@
164 pBlob->aData = 0;
165 pBlob->nAlloc = 0;
166 pBlob->nUsed = 0;
167 pBlob->iCursor = 0;
168 pBlob->blobFlags = 0;
169 }else if( newSize>pBlob->nAlloc || newSize<pBlob->nAlloc-4000 ){
170 char *pNew = fossil_realloc(pBlob->aData, newSize);
171 pBlob->aData = pNew;
172 pBlob->nAlloc = newSize;
173 if( pBlob->nUsed>pBlob->nAlloc ){
174 pBlob->nUsed = pBlob->nAlloc;
@@ -595,12 +595,12 @@
595 ** builds.
596 */
597 void blob_reserve(Blob *pBlob, unsigned int newSize){
598 if(newSize>=0x7fff0000 ){
599 blob_panic();
600 }else if(newSize>pBlob->nUsed){
601 pBlob->xRealloc(pBlob, newSize);
602 pBlob->aData[newSize] = 0;
603 }
604 }
605
606 /*
607
--- src/blob.c
+++ src/blob.c
@@ -164,11 +164,11 @@
164 pBlob->aData = 0;
165 pBlob->nAlloc = 0;
166 pBlob->nUsed = 0;
167 pBlob->iCursor = 0;
168 pBlob->blobFlags = 0;
169 }else if( newSize>pBlob->nAlloc || newSize+4000<pBlob->nAlloc ){
170 char *pNew = fossil_realloc(pBlob->aData, newSize);
171 pBlob->aData = pNew;
172 pBlob->nAlloc = newSize;
173 if( pBlob->nUsed>pBlob->nAlloc ){
174 pBlob->nUsed = pBlob->nAlloc;
@@ -595,12 +595,12 @@
595 ** builds.
596 */
597 void blob_reserve(Blob *pBlob, unsigned int newSize){
598 if(newSize>=0x7fff0000 ){
599 blob_panic();
600 }else if(newSize>pBlob->nAlloc){
601 pBlob->xRealloc(pBlob, newSize+1);
602 pBlob->aData[newSize] = 0;
603 }
604 }
605
606 /*
607
+22 -78
--- src/cgi.c
+++ src/cgi.c
@@ -364,19 +364,19 @@
364364
}
365365
366366
/* Works like fread():
367367
**
368368
** Read as many as bytes of content as we can, up to a maximum of nmemb
369
-** bytes. Return the number of bytes read. Return -1 if there is no
369
+** bytes. Return the number of bytes read. Return 0 if there is no
370370
** further input or if an I/O error occurs.
371371
*/
372372
size_t cgi_fread(void *ptr, size_t nmemb){
373373
if( !g.httpUseSSL ){
374374
return fread(ptr, 1, nmemb, g.httpIn);
375375
}
376376
#ifdef FOSSIL_ENABLE_SSL
377
- return ssl_read_server(g.httpSSLConn, ptr, nmemb);
377
+ return ssl_read_server(g.httpSSLConn, ptr, nmemb, 1);
378378
#else
379379
fossil_fatal("SSL not available");
380380
#endif
381381
}
382382
@@ -1061,71 +1061,23 @@
10611061
}
10621062
10631063
10641064
#ifdef FOSSIL_ENABLE_JSON
10651065
/*
1066
-** Internal helper for cson_data_source_FILE_n().
1067
-*/
1068
-typedef struct CgiPostReadState_ {
1069
- FILE * fh;
1070
- unsigned int len;
1071
- unsigned int pos;
1072
-} CgiPostReadState;
1073
-
1074
-/*
1075
-** cson_data_source_f() impl which reads only up to
1076
-** a specified amount of data from its input FILE.
1077
-** state MUST be a full populated (CgiPostReadState*).
1078
-*/
1079
-static int cson_data_source_FILE_n( void * state,
1080
- void * dest,
1081
- unsigned int * n ){
1082
- if( ! state || !dest || !n ) return cson_rc.ArgError;
1083
- else {
1084
- CgiPostReadState * st = (CgiPostReadState *)state;
1085
- if( st->pos >= st->len ){
1086
- *n = 0;
1087
- return 0;
1088
- }else if( !*n || ((st->pos + *n) > st->len) ){
1089
- return cson_rc.RangeError;
1090
- }else{
1091
- unsigned int rsz = (unsigned int)fread( dest, 1, *n, st->fh );
1092
- if( ! rsz ){
1093
- *n = rsz;
1094
- return feof(st->fh) ? 0 : cson_rc.IOError;
1095
- }else{
1096
- *n = rsz;
1097
- st->pos += *n;
1098
- return 0;
1099
- }
1100
- }
1101
- }
1102
-}
1103
-
1104
-/*
1105
-** Reads a JSON object from the first contentLen bytes of zIn. On
1106
-** g.json.post is updated to hold the content. On error a
1107
-** FSL_JSON_E_INVALID_REQUEST response is output and fossil_exit() is
1108
-** called (in HTTP mode exit code 0 is used).
1109
-**
1110
-** If contentLen is 0 then the whole file is read.
1111
-*/
1112
-void cgi_parse_POST_JSON( FILE * zIn, unsigned int contentLen ){
1113
- cson_value * jv = NULL;
1114
- int rc;
1115
- CgiPostReadState state;
1116
- cson_parse_opt popt = cson_parse_opt_empty;
1066
+** Reads a JSON object from the given blob, which is assumed to have
1067
+** been populated by the caller from stdin, the SSL API, or a file, as
1068
+** appropriate for the particular use case. On success g.json.post is
1069
+** updated to hold the content. On error a FSL_JSON_E_INVALID_REQUEST
1070
+** response is output and fossil_exit() is called (in HTTP mode exit
1071
+** code 0 is used).
1072
+*/
1073
+void cgi_parse_POST_JSON( Blob * pIn ){
1074
+ cson_value * jv = NULL;
11171075
cson_parse_info pinfo = cson_parse_info_empty;
11181076
assert(g.json.gc.a && "json_bootstrap_early() was not called!");
1119
- popt.maxDepth = 15;
1120
- state.fh = zIn;
1121
- state.len = contentLen;
1122
- state.pos = 0;
1123
- rc = cson_parse( &jv,
1124
- contentLen ? cson_data_source_FILE_n : cson_data_source_FILE,
1125
- contentLen ? (void *)&state : (void *)zIn, &popt, &pinfo );
1126
- if(rc){
1077
+ jv = cson_parse_Blob(pIn, &pinfo);
1078
+ if( jv==NULL ){
11271079
goto invalidRequest;
11281080
}else{
11291081
json_gc_add( "POST.JSON", jv );
11301082
g.json.post.v = jv;
11311083
g.json.post.o = cson_value_get_object( jv );
@@ -1140,11 +1092,11 @@
11401092
char * msg = mprintf("JSON parse error at line %u, column %u, "
11411093
"byte offset %u: %s",
11421094
pinfo.line, pinfo.col, pinfo.length,
11431095
cson_rc_string(pinfo.errorCode));
11441096
json_err( FSL_JSON_E_INVALID_REQUEST, msg, 1 );
1145
- free(msg);
1097
+ fossil_free(msg);
11461098
}else if(jv && !g.json.post.o){
11471099
json_err( FSL_JSON_E_INVALID_REQUEST,
11481100
"Request envelope must be a JSON Object (not array).", 1 );
11491101
}else{ /* generic error message */
11501102
json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 );
@@ -1362,33 +1314,25 @@
13621314
}else{
13631315
g.zContentType = zType;
13641316
}
13651317
blob_zero(&g.cgiIn);
13661318
if( len>0 && zType ){
1319
+ if( blob_read_from_cgi(&g.cgiIn, len)<len ){
1320
+ char *zMsg = mprintf("CGI content-length mismatch: Wanted %d bytes"
1321
+ " but got only %d\n", len, blob_size(&g.cgiIn));
1322
+ malformed_request(zMsg);
1323
+ }
13671324
if( fossil_strcmp(zType, "application/x-fossil")==0 ){
1368
- if( blob_read_from_cgi(&g.cgiIn, len)!=len ){
1369
- malformed_request("CGI content-length mismatch");
1370
- }
13711325
blob_uncompress(&g.cgiIn, &g.cgiIn);
13721326
}
13731327
#ifdef FOSSIL_ENABLE_JSON
1374
- else if( noJson==0 && g.json.isJsonMode!=0
1375
- && json_can_consume_content_type(zType)!=0 ){
1376
- assert( !g.httpUseSSL );
1377
- cgi_parse_POST_JSON(g.httpIn, (unsigned int)len);
1378
- /*
1379
- Potential TODOs:
1380
-
1381
- 1) If parsing fails, immediately return an error response
1382
- without dispatching the ostensibly-upcoming JSON API.
1383
- */
1328
+ if( noJson==0 && g.json.isJsonMode!=0
1329
+ && json_can_consume_content_type(zType)!=0 ){
1330
+ cgi_parse_POST_JSON(&g.cgiIn);
13841331
cgi_set_content_type(json_guess_content_type());
13851332
}
13861333
#endif /* FOSSIL_ENABLE_JSON */
1387
- else{
1388
- blob_read_from_cgi(&g.cgiIn, len);
1389
- }
13901334
}
13911335
}
13921336
13931337
/*
13941338
** Decode POST parameter information in the cgiIn content, if any.
13951339
--- src/cgi.c
+++ src/cgi.c
@@ -364,19 +364,19 @@
364 }
365
366 /* Works like fread():
367 **
368 ** Read as many as bytes of content as we can, up to a maximum of nmemb
369 ** bytes. Return the number of bytes read. Return -1 if there is no
370 ** further input or if an I/O error occurs.
371 */
372 size_t cgi_fread(void *ptr, size_t nmemb){
373 if( !g.httpUseSSL ){
374 return fread(ptr, 1, nmemb, g.httpIn);
375 }
376 #ifdef FOSSIL_ENABLE_SSL
377 return ssl_read_server(g.httpSSLConn, ptr, nmemb);
378 #else
379 fossil_fatal("SSL not available");
380 #endif
381 }
382
@@ -1061,71 +1061,23 @@
1061 }
1062
1063
1064 #ifdef FOSSIL_ENABLE_JSON
1065 /*
1066 ** Internal helper for cson_data_source_FILE_n().
1067 */
1068 typedef struct CgiPostReadState_ {
1069 FILE * fh;
1070 unsigned int len;
1071 unsigned int pos;
1072 } CgiPostReadState;
1073
1074 /*
1075 ** cson_data_source_f() impl which reads only up to
1076 ** a specified amount of data from its input FILE.
1077 ** state MUST be a full populated (CgiPostReadState*).
1078 */
1079 static int cson_data_source_FILE_n( void * state,
1080 void * dest,
1081 unsigned int * n ){
1082 if( ! state || !dest || !n ) return cson_rc.ArgError;
1083 else {
1084 CgiPostReadState * st = (CgiPostReadState *)state;
1085 if( st->pos >= st->len ){
1086 *n = 0;
1087 return 0;
1088 }else if( !*n || ((st->pos + *n) > st->len) ){
1089 return cson_rc.RangeError;
1090 }else{
1091 unsigned int rsz = (unsigned int)fread( dest, 1, *n, st->fh );
1092 if( ! rsz ){
1093 *n = rsz;
1094 return feof(st->fh) ? 0 : cson_rc.IOError;
1095 }else{
1096 *n = rsz;
1097 st->pos += *n;
1098 return 0;
1099 }
1100 }
1101 }
1102 }
1103
1104 /*
1105 ** Reads a JSON object from the first contentLen bytes of zIn. On
1106 ** g.json.post is updated to hold the content. On error a
1107 ** FSL_JSON_E_INVALID_REQUEST response is output and fossil_exit() is
1108 ** called (in HTTP mode exit code 0 is used).
1109 **
1110 ** If contentLen is 0 then the whole file is read.
1111 */
1112 void cgi_parse_POST_JSON( FILE * zIn, unsigned int contentLen ){
1113 cson_value * jv = NULL;
1114 int rc;
1115 CgiPostReadState state;
1116 cson_parse_opt popt = cson_parse_opt_empty;
1117 cson_parse_info pinfo = cson_parse_info_empty;
1118 assert(g.json.gc.a && "json_bootstrap_early() was not called!");
1119 popt.maxDepth = 15;
1120 state.fh = zIn;
1121 state.len = contentLen;
1122 state.pos = 0;
1123 rc = cson_parse( &jv,
1124 contentLen ? cson_data_source_FILE_n : cson_data_source_FILE,
1125 contentLen ? (void *)&state : (void *)zIn, &popt, &pinfo );
1126 if(rc){
1127 goto invalidRequest;
1128 }else{
1129 json_gc_add( "POST.JSON", jv );
1130 g.json.post.v = jv;
1131 g.json.post.o = cson_value_get_object( jv );
@@ -1140,11 +1092,11 @@
1140 char * msg = mprintf("JSON parse error at line %u, column %u, "
1141 "byte offset %u: %s",
1142 pinfo.line, pinfo.col, pinfo.length,
1143 cson_rc_string(pinfo.errorCode));
1144 json_err( FSL_JSON_E_INVALID_REQUEST, msg, 1 );
1145 free(msg);
1146 }else if(jv && !g.json.post.o){
1147 json_err( FSL_JSON_E_INVALID_REQUEST,
1148 "Request envelope must be a JSON Object (not array).", 1 );
1149 }else{ /* generic error message */
1150 json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 );
@@ -1362,33 +1314,25 @@
1362 }else{
1363 g.zContentType = zType;
1364 }
1365 blob_zero(&g.cgiIn);
1366 if( len>0 && zType ){
 
 
 
 
 
1367 if( fossil_strcmp(zType, "application/x-fossil")==0 ){
1368 if( blob_read_from_cgi(&g.cgiIn, len)!=len ){
1369 malformed_request("CGI content-length mismatch");
1370 }
1371 blob_uncompress(&g.cgiIn, &g.cgiIn);
1372 }
1373 #ifdef FOSSIL_ENABLE_JSON
1374 else if( noJson==0 && g.json.isJsonMode!=0
1375 && json_can_consume_content_type(zType)!=0 ){
1376 assert( !g.httpUseSSL );
1377 cgi_parse_POST_JSON(g.httpIn, (unsigned int)len);
1378 /*
1379 Potential TODOs:
1380
1381 1) If parsing fails, immediately return an error response
1382 without dispatching the ostensibly-upcoming JSON API.
1383 */
1384 cgi_set_content_type(json_guess_content_type());
1385 }
1386 #endif /* FOSSIL_ENABLE_JSON */
1387 else{
1388 blob_read_from_cgi(&g.cgiIn, len);
1389 }
1390 }
1391 }
1392
1393 /*
1394 ** Decode POST parameter information in the cgiIn content, if any.
1395
--- src/cgi.c
+++ src/cgi.c
@@ -364,19 +364,19 @@
364 }
365
366 /* Works like fread():
367 **
368 ** Read as many as bytes of content as we can, up to a maximum of nmemb
369 ** bytes. Return the number of bytes read. Return 0 if there is no
370 ** further input or if an I/O error occurs.
371 */
372 size_t cgi_fread(void *ptr, size_t nmemb){
373 if( !g.httpUseSSL ){
374 return fread(ptr, 1, nmemb, g.httpIn);
375 }
376 #ifdef FOSSIL_ENABLE_SSL
377 return ssl_read_server(g.httpSSLConn, ptr, nmemb, 1);
378 #else
379 fossil_fatal("SSL not available");
380 #endif
381 }
382
@@ -1061,71 +1061,23 @@
1061 }
1062
1063
1064 #ifdef FOSSIL_ENABLE_JSON
1065 /*
1066 ** Reads a JSON object from the given blob, which is assumed to have
1067 ** been populated by the caller from stdin, the SSL API, or a file, as
1068 ** appropriate for the particular use case. On success g.json.post is
1069 ** updated to hold the content. On error a FSL_JSON_E_INVALID_REQUEST
1070 ** response is output and fossil_exit() is called (in HTTP mode exit
1071 ** code 0 is used).
1072 */
1073 void cgi_parse_POST_JSON( Blob * pIn ){
1074 cson_value * jv = NULL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1075 cson_parse_info pinfo = cson_parse_info_empty;
1076 assert(g.json.gc.a && "json_bootstrap_early() was not called!");
1077 jv = cson_parse_Blob(pIn, &pinfo);
1078 if( jv==NULL ){
 
 
 
 
 
 
1079 goto invalidRequest;
1080 }else{
1081 json_gc_add( "POST.JSON", jv );
1082 g.json.post.v = jv;
1083 g.json.post.o = cson_value_get_object( jv );
@@ -1140,11 +1092,11 @@
1092 char * msg = mprintf("JSON parse error at line %u, column %u, "
1093 "byte offset %u: %s",
1094 pinfo.line, pinfo.col, pinfo.length,
1095 cson_rc_string(pinfo.errorCode));
1096 json_err( FSL_JSON_E_INVALID_REQUEST, msg, 1 );
1097 fossil_free(msg);
1098 }else if(jv && !g.json.post.o){
1099 json_err( FSL_JSON_E_INVALID_REQUEST,
1100 "Request envelope must be a JSON Object (not array).", 1 );
1101 }else{ /* generic error message */
1102 json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 );
@@ -1362,33 +1314,25 @@
1314 }else{
1315 g.zContentType = zType;
1316 }
1317 blob_zero(&g.cgiIn);
1318 if( len>0 && zType ){
1319 if( blob_read_from_cgi(&g.cgiIn, len)<len ){
1320 char *zMsg = mprintf("CGI content-length mismatch: Wanted %d bytes"
1321 " but got only %d\n", len, blob_size(&g.cgiIn));
1322 malformed_request(zMsg);
1323 }
1324 if( fossil_strcmp(zType, "application/x-fossil")==0 ){
 
 
 
1325 blob_uncompress(&g.cgiIn, &g.cgiIn);
1326 }
1327 #ifdef FOSSIL_ENABLE_JSON
1328 if( noJson==0 && g.json.isJsonMode!=0
1329 && json_can_consume_content_type(zType)!=0 ){
1330 cgi_parse_POST_JSON(&g.cgiIn);
 
 
 
 
 
 
 
1331 cgi_set_content_type(json_guess_content_type());
1332 }
1333 #endif /* FOSSIL_ENABLE_JSON */
 
 
 
1334 }
1335 }
1336
1337 /*
1338 ** Decode POST parameter information in the cgiIn content, if any.
1339
+13 -3
--- src/chat.c
+++ src/chat.c
@@ -483,10 +483,15 @@
483483
** needs to take care to inject them at the end of the history rather
484484
** than the same place new messages go.
485485
**
486486
** If "before" is provided, "name" is ignored.
487487
**
488
+** If "raw" is provided, the "xmsg" text is sent back as-is, in
489
+** markdown format, rather than being HTML-ized. This is not used or
490
+** supported by fossil's own chat client but is intended for 3rd-party
491
+** clients. (Specifically, for Brad Harder's curses-based client.)
492
+**
488493
** The reply from this webpage is JSON that describes the new content.
489494
** Format of the json:
490495
**
491496
** | {
492497
** | "msgs":[
@@ -542,10 +547,11 @@
542547
const int iDelay = 1000; /* Delay until next poll (milliseconds) */
543548
int nDelay; /* Maximum delay.*/
544549
int msgid = atoi(PD("name","0"));
545550
const int msgBefore = atoi(PD("before","0"));
546551
int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
552
+ const int bRaw = P("raw")!=0;
547553
Blob sql = empty_blob;
548554
Stmt q1;
549555
nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
550556
login_check_credentials();
551557
if( !g.perm.Chat ) {
@@ -619,13 +625,17 @@
619625
blob_appendf(&json, "null,");
620626
}
621627
blob_appendf(&json, "\"uclr\":%!j,",
622628
user_color(zFrom ? zFrom : "nobody"));
623629
624
- zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
625
- blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
626
- fossil_free(zMsg);
630
+ if(bRaw){
631
+ blob_appendf(&json, "\"xmsg\":%!j,", zRawMsg);
632
+ }else{
633
+ zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
634
+ blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
635
+ fossil_free(zMsg);
636
+ }
627637
628638
if( nByte==0 ){
629639
blob_appendf(&json, "\"fsize\":0");
630640
}else{
631641
blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j",
632642
--- src/chat.c
+++ src/chat.c
@@ -483,10 +483,15 @@
483 ** needs to take care to inject them at the end of the history rather
484 ** than the same place new messages go.
485 **
486 ** If "before" is provided, "name" is ignored.
487 **
 
 
 
 
 
488 ** The reply from this webpage is JSON that describes the new content.
489 ** Format of the json:
490 **
491 ** | {
492 ** | "msgs":[
@@ -542,10 +547,11 @@
542 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
543 int nDelay; /* Maximum delay.*/
544 int msgid = atoi(PD("name","0"));
545 const int msgBefore = atoi(PD("before","0"));
546 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
 
547 Blob sql = empty_blob;
548 Stmt q1;
549 nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
550 login_check_credentials();
551 if( !g.perm.Chat ) {
@@ -619,13 +625,17 @@
619 blob_appendf(&json, "null,");
620 }
621 blob_appendf(&json, "\"uclr\":%!j,",
622 user_color(zFrom ? zFrom : "nobody"));
623
624 zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
625 blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
626 fossil_free(zMsg);
 
 
 
 
627
628 if( nByte==0 ){
629 blob_appendf(&json, "\"fsize\":0");
630 }else{
631 blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j",
632
--- src/chat.c
+++ src/chat.c
@@ -483,10 +483,15 @@
483 ** needs to take care to inject them at the end of the history rather
484 ** than the same place new messages go.
485 **
486 ** If "before" is provided, "name" is ignored.
487 **
488 ** If "raw" is provided, the "xmsg" text is sent back as-is, in
489 ** markdown format, rather than being HTML-ized. This is not used or
490 ** supported by fossil's own chat client but is intended for 3rd-party
491 ** clients. (Specifically, for Brad Harder's curses-based client.)
492 **
493 ** The reply from this webpage is JSON that describes the new content.
494 ** Format of the json:
495 **
496 ** | {
497 ** | "msgs":[
@@ -542,10 +547,11 @@
547 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
548 int nDelay; /* Maximum delay.*/
549 int msgid = atoi(PD("name","0"));
550 const int msgBefore = atoi(PD("before","0"));
551 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
552 const int bRaw = P("raw")!=0;
553 Blob sql = empty_blob;
554 Stmt q1;
555 nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
556 login_check_credentials();
557 if( !g.perm.Chat ) {
@@ -619,13 +625,17 @@
625 blob_appendf(&json, "null,");
626 }
627 blob_appendf(&json, "\"uclr\":%!j,",
628 user_color(zFrom ? zFrom : "nobody"));
629
630 if(bRaw){
631 blob_appendf(&json, "\"xmsg\":%!j,", zRawMsg);
632 }else{
633 zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
634 blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
635 fossil_free(zMsg);
636 }
637
638 if( nByte==0 ){
639 blob_appendf(&json, "\"fsize\":0");
640 }else{
641 blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j",
642
+322 -86
--- src/diff.c
+++ src/diff.c
@@ -121,12 +121,13 @@
121121
*/
122122
typedef struct DLine DLine;
123123
struct DLine {
124124
const char *z; /* The text of the line */
125125
u64 h; /* Hash of the line */
126
- unsigned short indent; /* Indent of the line. Only !=0 with -w/-Z option */
126
+ unsigned short indent; /* Index of first non-space */
127127
unsigned short n; /* number of bytes */
128
+ unsigned short nw; /* number of bytes without leading/trailing space */
128129
unsigned int iNext; /* 1+(Index of next line with same the same hash) */
129130
130131
/* an array of DLine elements serves two purposes. The fields
131132
** above are one per line of input text. But each entry is also
132133
** a bucket in a hash table, as follows: */
@@ -163,12 +164,34 @@
163164
int nEditAlloc; /* Space allocated for aEdit[] */
164165
DLine *aFrom; /* File on left side of the diff */
165166
int nFrom; /* Number of lines in aFrom[] */
166167
DLine *aTo; /* File on right side of the diff */
167168
int nTo; /* Number of lines in aTo[] */
168
- int (*xDiffer)(const DLine*,const DLine*); /* comparison function */
169
+ int (*xDiffer)(const DLine *,const DLine *); /* comparison function */
170
+};
171
+
172
+/* Fast isspace for use by diff */
173
+static const char diffIsSpace[] = {
174
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0,
175
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
176
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
177
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
178
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
179
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
180
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182
+
183
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
184
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
185
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
186
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
187
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
188
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
189
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
190
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
169191
};
192
+#define diff_isspace(X) (diffIsSpace[(unsigned char)(X)])
170193
171194
/*
172195
** Count the number of lines in the input string. Include the last line
173196
** in the count even if it lacks the \n terminator. If an empty string
174197
** is specified, the number of lines is zero. For the purposes of this
@@ -245,38 +268,38 @@
245268
k = nn;
246269
if( diffFlags & DIFF_STRIP_EOLCR ){
247270
if( k>0 && z[k-1]=='\r' ){ k--; }
248271
}
249272
a[i].n = k;
250
- s = 0;
251273
if( diffFlags & DIFF_IGNORE_EOLWS ){
252
- while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
274
+ while( k>0 && diff_isspace(z[k-1]) ){ k--; }
253275
}
254276
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
255277
int numws = 0;
256
- while( s<k && fossil_isspace(z[s]) ){ s++; }
278
+ for(s=0; s<k && z[s]<=' '; s++){}
279
+ a[i].indent = s;
280
+ a[i].nw = k - s;
257281
for(h=0, x=s; x<k; x++){
258282
char c = z[x];
259
- if( fossil_isspace(c) ){
283
+ if( diff_isspace(c) ){
260284
++numws;
261285
}else{
262286
h = (h^c)*9000000000000000041LL;
263287
}
264288
}
265289
k -= numws;
266290
}else{
267291
int k2 = k & ~0x7;
268292
u64 m;
269
- for(h=0, x=s; x<k2; x += 8){
293
+ for(h=x=s=0; x<k2; x += 8){
270294
memcpy(&m, z+x, 8);
271295
h = (h^m)*9000000000000000041LL;
272296
}
273297
m = 0;
274298
memcpy(&m, z+x, k-k2);
275299
h ^= m;
276300
}
277
- a[i].indent = s;
278301
a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s);
279302
h2 = h % nLine;
280303
a[i].iNext = a[h2].iHash;
281304
a[h2].iHash = i+1;
282305
z += nn+1; n -= nn+1;
@@ -300,18 +323,20 @@
300323
/*
301324
** Return zero if two DLine elements are identical, ignoring
302325
** all whitespace. The indent field of pA/pB already points
303326
** to the first non-space character in the string.
304327
*/
305
-
306328
static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
307
- int a = pA->indent, b = pB->indent;
308329
if( pA->h==pB->h ){
330
+ int a, b;
331
+ if( memcmp(pA->z, pB->z, pA->h&LENGTH_MASK)==0 ) return 0;
332
+ a = pA->indent;
333
+ b = pB->indent;
309334
while( a<pA->n || b<pB->n ){
310335
if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
311
- while( a<pA->n && fossil_isspace(pA->z[a])) ++a;
312
- while( b<pB->n && fossil_isspace(pB->z[b])) ++b;
336
+ while( a<pA->n && diff_isspace(pA->z[a])) ++a;
337
+ while( b<pB->n && diff_isspace(pB->z[b])) ++b;
313338
}
314339
return pA->n-a != pB->n-b;
315340
}
316341
return 1;
317342
}
@@ -338,11 +363,11 @@
338363
** Append a single line of context-diff output to pOut.
339364
*/
340365
static void appendDiffLine(
341366
Blob *pOut, /* Where to write the line of output */
342367
char cPrefix, /* One of " ", "+", or "-" */
343
- DLine *pLine /* The line to be output */
368
+ const DLine *pLine /* The line to be output */
344369
){
345370
blob_append_char(pOut, cPrefix);
346371
blob_append(pOut, pLine->z, pLine->n);
347372
blob_append_char(pOut, '\n');
348373
}
@@ -371,14 +396,14 @@
371396
static void contextDiff(
372397
DContext *p, /* The difference */
373398
Blob *pOut, /* Output a context diff to here */
374399
DiffConfig *pCfg /* Configuration options */
375400
){
376
- DLine *A; /* Left side of the diff */
377
- DLine *B; /* Right side of the diff */
378
- int a = 0; /* Index of next line in A[] */
379
- int b = 0; /* Index of next line in B[] */
401
+ const DLine *A; /* Left side of the diff */
402
+ const DLine *B; /* Right side of the diff */
403
+ int a = 0; /* Index of next line in A[] */
404
+ int b = 0; /* Index of next line in B[] */
380405
int *R; /* Array of COPY/DELETE/INSERT triples */
381406
int r; /* Index into R[] */
382407
int nr; /* Number of COPY/DELETE/INSERT triples to process */
383408
int mxr; /* Maximum value for r */
384409
int na, nb; /* Number of lines shown from A and B */
@@ -619,11 +644,11 @@
619644
/*
620645
** Return true if the string starts with n spaces
621646
*/
622647
static int allSpaces(const char *z, int n){
623648
int i;
624
- for(i=0; i<n && fossil_isspace(z[i]); i++){}
649
+ for(i=0; i<n && diff_isspace(z[i]); i++){}
625650
return i==n;
626651
}
627652
628653
/*
629654
** Try to improve the human-readability of the LineChange p.
@@ -745,17 +770,17 @@
745770
int nLong = nLeft<nRight ? nRight : nLeft;
746771
int nGap = nLong - nShort;
747772
for(i=nShort-nSuffix; i<=nPrefix; i++){
748773
int iVal = 0;
749774
char c = zLeft[i];
750
- if( fossil_isspace(c) ){
775
+ if( diff_isspace(c) ){
751776
iVal += 5;
752777
}else if( !fossil_isalnum(c) ){
753778
iVal += 2;
754779
}
755780
c = zLeft[i+nGap-1];
756
- if( fossil_isspace(c) ){
781
+ if( diff_isspace(c) ){
757782
iVal += 5;
758783
}else if( !fossil_isalnum(c) ){
759784
iVal += 2;
760785
}
761786
if( iVal>iBestVal ){
@@ -889,11 +914,11 @@
889914
struct DiffBuilder {
890915
void (*xSkip)(DiffBuilder*, unsigned int, int);
891916
void (*xCommon)(DiffBuilder*,const DLine*);
892917
void (*xInsert)(DiffBuilder*,const DLine*);
893918
void (*xDelete)(DiffBuilder*,const DLine*);
894
- void (*xReplace)(DiffBuilder*,const DLine*, const DLine*);
919
+ void (*xReplace)(DiffBuilder*,const DLine*,const DLine*);
895920
void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
896921
void (*xEnd)(DiffBuilder*);
897922
unsigned int lnLeft; /* Lines seen on the left (delete) side */
898923
unsigned int lnRight; /* Lines seen on the right (insert) side */
899924
unsigned int nPending; /* Number of pending lines */
@@ -1733,11 +1758,11 @@
17331758
** (3) If the two strings have a common prefix, measure that prefix
17341759
** (4) Find the length of the longest common subsequence that is
17351760
** at least 150% longer than the common prefix.
17361761
** (5) Longer common subsequences yield lower scores.
17371762
*/
1738
-static int match_dline(const DLine *pA, const DLine *pB){
1763
+static int match_dline(DLine *pA, DLine *pB){
17391764
const char *zA; /* Left string */
17401765
const char *zB; /* right string */
17411766
int nA; /* Bytes in zA[] */
17421767
int nB; /* Bytes in zB[] */
17431768
int nMin;
@@ -1749,17 +1774,29 @@
17491774
unsigned char c; /* Character being examined */
17501775
unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */
17511776
unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */
17521777
17531778
zA = pA->z;
1779
+ if( pA->nw==0 && pA->n ){
1780
+ for(i=0; i<pA->n && diff_isspace(zA[i]); i++){}
1781
+ pA->indent = i;
1782
+ for(j=pA->n-1; j>i && diff_isspace(zA[j]); j--){}
1783
+ pA->nw = j - i + 1;
1784
+ }
1785
+ zA += pA->indent;
1786
+ nA = pA->nw;
1787
+
17541788
zB = pB->z;
1755
- nA = pA->n;
1756
- nB = pB->n;
1757
- while( nA>0 && (unsigned char)zA[0]<=' ' ){ nA--; zA++; }
1758
- while( nA>0 && (unsigned char)zA[nA-1]<=' ' ){ nA--; }
1759
- while( nB>0 && (unsigned char)zB[0]<=' ' ){ nB--; zB++; }
1760
- while( nB>0 && (unsigned char)zB[nB-1]<=' ' ){ nB--; }
1789
+ if( pB->nw==0 && pB->n ){
1790
+ for(i=0; i<pB->n && diff_isspace(zB[i]); i++){}
1791
+ pB->indent = i;
1792
+ for(j=pB->n-1; j>i && diff_isspace(zB[j]); j--){}
1793
+ pB->nw = j - i + 1;
1794
+ }
1795
+ zB += pB->indent;
1796
+ nB = pB->nw;
1797
+
17611798
if( nA>250 ) nA = 250;
17621799
if( nB>250 ) nB = 250;
17631800
avg = (nA+nB)/2;
17641801
if( avg==0 ) return 0;
17651802
nMin = nA;
@@ -1785,11 +1822,11 @@
17851822
int limit = minInt(nA-i, nB-j);
17861823
for(k=best; k<=limit && zA[k+i]==zB[k+j]; k++){}
17871824
if( k>best ) best = k;
17881825
}
17891826
}
1790
- score = (best>=avg) ? 0 : (avg - best)*100/avg;
1827
+ score = 5 + ((best>=avg) ? 0 : (avg - best)*95/avg);
17911828
17921829
#if 0
17931830
fprintf(stderr, "A: [%.*s]\nB: [%.*s]\nbest=%d avg=%d score=%d\n",
17941831
nA, zA+1, nB, zB+1, best, avg, score);
17951832
#endif
@@ -1817,10 +1854,183 @@
18171854
b.z = g.argv[3];
18181855
b.n = (int)strlen(b.z);
18191856
x = match_dline(&a, &b);
18201857
fossil_print("%d\n", x);
18211858
}
1859
+
1860
+/* Forward declarations for recursion */
1861
+static unsigned char *diffBlockAlignment(
1862
+ DLine *aLeft, int nLeft, /* Text on the left */
1863
+ DLine *aRight, int nRight, /* Text on the right */
1864
+ DiffConfig *pCfg, /* Configuration options */
1865
+ int *pNResult /* OUTPUT: Bytes of result */
1866
+);
1867
+static void longestCommonSequence(
1868
+ DContext *p, /* Two files being compared */
1869
+ int iS1, int iE1, /* Range of lines in p->aFrom[] */
1870
+ int iS2, int iE2, /* Range of lines in p->aTo[] */
1871
+ int *piSX, int *piEX, /* Write p->aFrom[] common segment here */
1872
+ int *piSY, int *piEY /* Write p->aTo[] common segment here */
1873
+);
1874
+
1875
+/*
1876
+** Make a copy of a list of nLine DLine objects from one array to
1877
+** another. Hash the new array to ignore whitespace.
1878
+*/
1879
+static void diffDLineXfer(
1880
+ DLine *aTo,
1881
+ const DLine *aFrom,
1882
+ int nLine
1883
+){
1884
+ int i, j, k;
1885
+ u64 h, h2;
1886
+ for(i=0; i<nLine; i++) aTo[i].iHash = 0;
1887
+ for(i=0; i<nLine; i++){
1888
+ const char *z = aFrom[i].z;
1889
+ int n = aFrom[i].n;
1890
+ for(j=0; j<n && diff_isspace(z[j]); j++){}
1891
+ aTo[i].z = &z[j];
1892
+ for(k=aFrom[i].n; k>j && diff_isspace(z[k-1]); k--){}
1893
+ aTo[i].n = n = k-j;
1894
+ aTo[i].indent = 0;
1895
+ aTo[i].nw = 0;
1896
+ for(h=0; j<k; j++){
1897
+ char c = z[j];
1898
+ if( !diff_isspace(c) ){
1899
+ h = (h^c)*9000000000000000041LL;
1900
+ }
1901
+ }
1902
+ aTo[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | n;
1903
+ h2 = h % nLine;
1904
+ aTo[i].iNext = aTo[h2].iHash;
1905
+ aTo[h2].iHash = i+1;
1906
+ }
1907
+}
1908
+
1909
+
1910
+/*
1911
+** For a difficult diff-block alignment that was originally for
1912
+** the default consider-all-whitespace algorithm, try to find the
1913
+** longest common subsequence between the two blocks that involves
1914
+** only whitespace changes.
1915
+*/
1916
+static unsigned char *diffBlockAlignmentIgnoreSpace(
1917
+ DLine *aLeft, int nLeft, /* Text on the left */
1918
+ DLine *aRight, int nRight, /* Text on the right */
1919
+ DiffConfig *pCfg, /* Configuration options */
1920
+ int *pNResult /* OUTPUT: Bytes of result */
1921
+){
1922
+ DContext dc;
1923
+ int iSX, iEX; /* Start and end of LCS on the left */
1924
+ int iSY, iEY; /* Start and end of the LCS on the right */
1925
+ unsigned char *a1, *a2;
1926
+ int n1, n2, nLCS;
1927
+
1928
+ dc.aEdit = 0;
1929
+ dc.nEdit = 0;
1930
+ dc.nEditAlloc = 0;
1931
+ dc.nFrom = nLeft;
1932
+ dc.nTo = nRight;
1933
+ dc.xDiffer = compare_dline_ignore_allws;
1934
+ dc.aFrom = fossil_malloc( sizeof(DLine)*(nLeft+nRight) );
1935
+ dc.aTo = &dc.aFrom[dc.nFrom];
1936
+ diffDLineXfer(dc.aFrom, aLeft, nLeft);
1937
+ diffDLineXfer(dc.aTo, aRight, nRight);
1938
+ longestCommonSequence(&dc,0,nLeft,0,nRight,&iSX,&iEX,&iSY,&iEY);
1939
+ fossil_free(dc.aFrom);
1940
+ nLCS = iEX - iSX;
1941
+ if( nLCS<5 ) return 0; /* No good LCS was found */
1942
+
1943
+ if( pCfg->diffFlags & DIFF_DEBUG ){
1944
+ fossil_print(" LCS size=%d\n"
1945
+ " [%.*s]\n"
1946
+ " [%.*s]\n",
1947
+ nLCS, aLeft[iSX].n, aLeft[iSX].z,
1948
+ aLeft[iEX-1].n, aLeft[iEX-1].z);
1949
+ }
1950
+
1951
+ a1 = diffBlockAlignment(aLeft,iSX,aRight,iSY,pCfg,&n1);
1952
+ a2 = diffBlockAlignment(aLeft+iEX, nLeft-iEX,
1953
+ aRight+iEY, nRight-iEY,
1954
+ pCfg, &n2);
1955
+ a1 = fossil_realloc(a1, n1+nLCS+n2);
1956
+ memcpy(a1+n1+nLCS,a2,n2);
1957
+ memset(a1+n1,3,nLCS);
1958
+ fossil_free(a2);
1959
+ *pNResult = n1+n2+nLCS;
1960
+ return a1;
1961
+}
1962
+
1963
+
1964
+/*
1965
+** This is a helper route for diffBlockAlignment(). In this case,
1966
+** a very large block is encountered that might be too expensive to
1967
+** use the O(N*N) Wagner edit distance algorithm. So instead, this
1968
+** block implements a less-precise but faster O(N*logN) divide-and-conquer
1969
+** approach.
1970
+*/
1971
+static unsigned char *diffBlockAlignmentDivideAndConquer(
1972
+ DLine *aLeft, int nLeft, /* Text on the left */
1973
+ DLine *aRight, int nRight, /* Text on the right */
1974
+ DiffConfig *pCfg, /* Configuration options */
1975
+ int *pNResult /* OUTPUT: Bytes of result */
1976
+){
1977
+ DLine *aSmall; /* The smaller of aLeft and aRight */
1978
+ DLine *aBig; /* The larger of aLeft and aRight */
1979
+ int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1980
+ int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
1981
+ int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
1982
+ unsigned char *a1, *a2; /* Results of the alignments on two halves */
1983
+ int n1, n2; /* Number of entries in a1 and a2 */
1984
+ int score, bestScore; /* Score and best score seen so far */
1985
+ int i; /* Loop counter */
1986
+
1987
+ if( nLeft>nRight ){
1988
+ aSmall = aRight;
1989
+ nSmall = nRight;
1990
+ aBig = aLeft;
1991
+ nBig = nLeft;
1992
+ }else{
1993
+ aSmall = aLeft;
1994
+ nSmall = nLeft;
1995
+ aBig = aRight;
1996
+ nBig = nRight;
1997
+ }
1998
+ iDivBig = nBig/2;
1999
+ iDivSmall = nSmall/2;
2000
+
2001
+ if( pCfg->diffFlags & DIFF_DEBUG ){
2002
+ fossil_print(" Divide at [%.*s]\n",
2003
+ aBig[iDivBig].n, aBig[iDivBig].z);
2004
+ }
2005
+
2006
+ bestScore = 10000;
2007
+ for(i=0; i<nSmall; i++){
2008
+ score = match_dline(aBig+iDivBig, aSmall+i) + abs(i-nSmall/2)*2;
2009
+ if( score<bestScore ){
2010
+ bestScore = score;
2011
+ iDivSmall = i;
2012
+ }
2013
+ }
2014
+ if( aSmall==aRight ){
2015
+ iDivRight = iDivSmall;
2016
+ iDivLeft = iDivBig;
2017
+ }else{
2018
+ iDivRight = iDivBig;
2019
+ iDivLeft = iDivSmall;
2020
+ }
2021
+ a1 = diffBlockAlignment(aLeft,iDivLeft,aRight,iDivRight,pCfg,&n1);
2022
+ a2 = diffBlockAlignment(aLeft+iDivLeft, nLeft-iDivLeft,
2023
+ aRight+iDivRight, nRight-iDivRight,
2024
+ pCfg, &n2);
2025
+ a1 = fossil_realloc(a1, n1+n2 );
2026
+ memcpy(a1+n1,a2,n2);
2027
+ fossil_free(a2);
2028
+ *pNResult = n1+n2;
2029
+ return a1;
2030
+}
2031
+
18222032
18232033
/*
18242034
** The threshold at which diffBlockAlignment transitions from the
18252035
** O(N*N) Wagner minimum-edit-distance algorithm to a less process
18262036
** O(NlogN) divide-and-conquer approach.
@@ -1850,14 +2060,14 @@
18502060
** each other. Insertion and deletion costs are 50. Match costs
18512061
** are between 0 and 100 where 0 is a perfect match 100 is a complete
18522062
** mismatch.
18532063
*/
18542064
static unsigned char *diffBlockAlignment(
1855
- const DLine *aLeft, int nLeft, /* Text on the left */
1856
- const DLine *aRight, int nRight, /* Text on the right */
1857
- DiffConfig *pCfg, /* Configuration options */
1858
- int *pNResult /* OUTPUT: Bytes of result */
2065
+ DLine *aLeft, int nLeft, /* Text on the left */
2066
+ DLine *aRight, int nRight, /* Text on the right */
2067
+ DiffConfig *pCfg, /* Configuration options */
2068
+ int *pNResult /* OUTPUT: Bytes of result */
18592069
){
18602070
int i, j, k; /* Loop counters */
18612071
int *a; /* One row of the Wagner matrix */
18622072
int *pToFree; /* Space that needs to be freed */
18632073
unsigned char *aM; /* Wagner result matrix */
@@ -1875,61 +2085,28 @@
18752085
memset(aM, 1, nLeft);
18762086
*pNResult = nLeft;
18772087
return aM;
18782088
}
18792089
1880
- /* For large alignments, use a divide and conquer algorithm that is
1881
- ** O(NlogN). The result is not as precise, but this whole thing is an
1882
- ** approximation anyhow, and the faster response time is an acceptable
1883
- ** trade-off for reduced precision.
2090
+ if( pCfg->diffFlags & DIFF_DEBUG ){
2091
+ fossil_print("BlockAlignment:\n [%.*s] + %d\n [%.*s] + %d\n",
2092
+ aLeft[0].n, aLeft[0].z, nLeft,
2093
+ aRight[0].n, aRight[0].z, nRight);
2094
+ }
2095
+
2096
+ /* For large alignments, try to use alternative algorithms that are
2097
+ ** faster than the O(N*N) Wagner edit distance.
18842098
*/
18852099
if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
1886
- const DLine *aSmall; /* The smaller of aLeft and aRight */
1887
- const DLine *aBig; /* The larger of aLeft and aRight */
1888
- int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1889
- int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
1890
- int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
1891
- unsigned char *a1, *a2; /* Results of the alignments on two halves */
1892
- int n1, n2; /* Number of entries in a1 and a2 */
1893
- int score, bestScore; /* Score and best score seen so far */
1894
- if( nLeft>nRight ){
1895
- aSmall = aRight;
1896
- nSmall = nRight;
1897
- aBig = aLeft;
1898
- nBig = nLeft;
1899
- }else{
1900
- aSmall = aLeft;
1901
- nSmall = nLeft;
1902
- aBig = aRight;
1903
- nBig = nRight;
1904
- }
1905
- iDivBig = nBig/2;
1906
- iDivSmall = nSmall/2;
1907
- bestScore = 10000;
1908
- for(i=0; i<nSmall; i++){
1909
- score = match_dline(aBig+iDivBig, aSmall+i) + abs(i-nSmall/2)*2;
1910
- if( score<bestScore ){
1911
- bestScore = score;
1912
- iDivSmall = i;
1913
- }
1914
- }
1915
- if( aSmall==aRight ){
1916
- iDivRight = iDivSmall;
1917
- iDivLeft = iDivBig;
1918
- }else{
1919
- iDivRight = iDivBig;
1920
- iDivLeft = iDivSmall;
1921
- }
1922
- a1 = diffBlockAlignment(aLeft,iDivLeft,aRight,iDivRight,pCfg,&n1);
1923
- a2 = diffBlockAlignment(aLeft+iDivLeft, nLeft-iDivLeft,
1924
- aRight+iDivRight, nRight-iDivRight,
1925
- pCfg, &n2);
1926
- a1 = fossil_realloc(a1, n1+n2 );
1927
- memcpy(a1+n1,a2,n2);
1928
- fossil_free(a2);
1929
- *pNResult = n1+n2;
1930
- return a1;
2100
+ if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){
2101
+ unsigned char *aRes;
2102
+ aRes = diffBlockAlignmentIgnoreSpace(
2103
+ aLeft, nLeft,aRight, nRight,pCfg,pNResult);
2104
+ if( aRes ) return aRes;
2105
+ }
2106
+ return diffBlockAlignmentDivideAndConquer(
2107
+ aLeft, nLeft,aRight, nRight,pCfg,pNResult);
19312108
}
19322109
19332110
/* If we reach this point, we will be doing an O(N*N) Wagner minimum
19342111
** edit distance to compute the alignment.
19352112
*/
@@ -2026,12 +2203,12 @@
20262203
static void formatDiff(
20272204
DContext *p, /* The computed diff */
20282205
DiffConfig *pCfg, /* Configuration options */
20292206
DiffBuilder *pBuilder /* The formatter object */
20302207
){
2031
- const DLine *A; /* Left side of the diff */
2032
- const DLine *B; /* Right side of the diff */
2208
+ DLine *A; /* Left side of the diff */
2209
+ DLine *B; /* Right side of the diff */
20332210
unsigned int a = 0; /* Index of next line in A[] */
20342211
unsigned int b = 0; /* Index of next line in B[] */
20352212
const int *R; /* Array of COPY/DELETE/INSERT triples */
20362213
unsigned int r; /* Index into R[] */
20372214
unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
@@ -2410,10 +2587,66 @@
24102587
}
24112588
p->aEdit[p->nEdit++] = nCopy;
24122589
p->aEdit[p->nEdit++] = nDel;
24132590
p->aEdit[p->nEdit++] = nIns;
24142591
}
2592
+
2593
+/*
2594
+** A common subsequene between p->aFrom and p->aTo has been found.
2595
+** This routine tries to judge if the subsequence really is a valid
2596
+** match or rather is just an artifact of an indentation change.
2597
+**
2598
+** Return non-zero if the subsequence is valid. Return zero if the
2599
+** subsequence seems likely to be an editing artifact and should be
2600
+** ignored.
2601
+**
2602
+** This routine is a heuristic optimization intended to give more
2603
+** intuitive diff results following an indentation change it code that
2604
+** is formatted similarly to C/C++, Javascript, Go, TCL, and similar
2605
+** languages that use {...} for nesting. A correct diff is computed
2606
+** even if this routine always returns true (non-zero). But sometimes
2607
+** a more intuitive diff can result if this routine returns false.
2608
+**
2609
+** The subsequences consists of the rows iSX through iEX-1 (inclusive)
2610
+** in p->aFrom[]. The total sequences is iS1 through iE1-1 (inclusive)
2611
+** of p->aFrom[].
2612
+**
2613
+** Example where this heuristic is useful, see the diff at
2614
+** https://www.sqlite.org/src/fdiff?v1=0e79dd15cbdb4f48&v2=33955a6fd874dd97
2615
+**
2616
+** See also discussion at https://fossil-scm.org/forum/forumpost/9ba3284295
2617
+**
2618
+** ALGORITHM (subject to change and refinement):
2619
+**
2620
+** 1. If the subsequence is larger than 1/7th of the original span,
2621
+** then consider it valid. --> return 1
2622
+**
2623
+** 2. If the subsequence contains any charaters other than '}', '{",
2624
+** or whitespace, then consider it valid. --> return 1
2625
+**
2626
+** 3. Otherwise, it is potentially an artifact of an indentation
2627
+** change. --> return 0
2628
+*/
2629
+static int likelyNotIndentChngArtifact(
2630
+ DContext *p, /* The complete diff context */
2631
+ int iS1, /* Start of the main segment */
2632
+ int iSX, /* Start of the subsequence */
2633
+ int iEX, /* First row past the end of the subsequence */
2634
+ int iE1 /* First row past the end of the main segment */
2635
+){
2636
+ int i, j;
2637
+ if( (iEX-iSX)*7 >= (iE1-iS1) ) return 1;
2638
+ for(i=iSX; i<iEX; i++){
2639
+ const char *z = p->aFrom[i].z;
2640
+ for(j=p->aFrom[i].n-1; j>=0; j--){
2641
+ char c = z[j];
2642
+ if( c!='}' && c!='{' && !diff_isspace(c) ) return 1;
2643
+ }
2644
+ }
2645
+ return 0;
2646
+}
2647
+
24152648
24162649
/*
24172650
** Do a single step in the difference. Compute a sequence of
24182651
** copy/delete/insert steps that will convert lines iS1 through iE1-1 of
24192652
** the input into lines iS2 through iE2-1 of the output and write
@@ -2442,11 +2675,13 @@
24422675
}
24432676
24442677
/* Find the longest matching segment between the two sequences */
24452678
longestCommonSequence(p, iS1, iE1, iS2, iE2, &iSX, &iEX, &iSY, &iEY);
24462679
2447
- if( iEX>iSX ){
2680
+ if( iEX>iSX+5
2681
+ || (iEX>iSX && likelyNotIndentChngArtifact(p,iS1,iSX,iEX,iE1) )
2682
+ ){
24482683
/* A common segment has been found.
24492684
** Recursively diff either side of the matching segment */
24502685
diff_step(p, iS1, iSX, iS2, iSY);
24512686
if( iEX>iSX ){
24522687
appendTriple(p, iEX - iSX, 0, 0);
@@ -3120,11 +3355,12 @@
31203355
if( strcmp(zLimit,"none")==0 ){
31213356
iLimit = 0;
31223357
mxTime = 0;
31233358
}else if( sqlite3_strglob("*[0-9]s", zLimit)==0 ){
31243359
iLimit = 0;
3125
- mxTime = current_time_in_milliseconds() + 1000.0*atof(zLimit);
3360
+ mxTime =
3361
+ (sqlite3_int64)(current_time_in_milliseconds() + 1000.0*atof(zLimit));
31263362
}else{
31273363
iLimit = atoi(zLimit);
31283364
if( iLimit<=0 ) iLimit = 30;
31293365
mxTime = 0;
31303366
}
31313367
--- src/diff.c
+++ src/diff.c
@@ -121,12 +121,13 @@
121 */
122 typedef struct DLine DLine;
123 struct DLine {
124 const char *z; /* The text of the line */
125 u64 h; /* Hash of the line */
126 unsigned short indent; /* Indent of the line. Only !=0 with -w/-Z option */
127 unsigned short n; /* number of bytes */
 
128 unsigned int iNext; /* 1+(Index of next line with same the same hash) */
129
130 /* an array of DLine elements serves two purposes. The fields
131 ** above are one per line of input text. But each entry is also
132 ** a bucket in a hash table, as follows: */
@@ -163,12 +164,34 @@
163 int nEditAlloc; /* Space allocated for aEdit[] */
164 DLine *aFrom; /* File on left side of the diff */
165 int nFrom; /* Number of lines in aFrom[] */
166 DLine *aTo; /* File on right side of the diff */
167 int nTo; /* Number of lines in aTo[] */
168 int (*xDiffer)(const DLine*,const DLine*); /* comparison function */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169 };
 
170
171 /*
172 ** Count the number of lines in the input string. Include the last line
173 ** in the count even if it lacks the \n terminator. If an empty string
174 ** is specified, the number of lines is zero. For the purposes of this
@@ -245,38 +268,38 @@
245 k = nn;
246 if( diffFlags & DIFF_STRIP_EOLCR ){
247 if( k>0 && z[k-1]=='\r' ){ k--; }
248 }
249 a[i].n = k;
250 s = 0;
251 if( diffFlags & DIFF_IGNORE_EOLWS ){
252 while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
253 }
254 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
255 int numws = 0;
256 while( s<k && fossil_isspace(z[s]) ){ s++; }
 
 
257 for(h=0, x=s; x<k; x++){
258 char c = z[x];
259 if( fossil_isspace(c) ){
260 ++numws;
261 }else{
262 h = (h^c)*9000000000000000041LL;
263 }
264 }
265 k -= numws;
266 }else{
267 int k2 = k & ~0x7;
268 u64 m;
269 for(h=0, x=s; x<k2; x += 8){
270 memcpy(&m, z+x, 8);
271 h = (h^m)*9000000000000000041LL;
272 }
273 m = 0;
274 memcpy(&m, z+x, k-k2);
275 h ^= m;
276 }
277 a[i].indent = s;
278 a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s);
279 h2 = h % nLine;
280 a[i].iNext = a[h2].iHash;
281 a[h2].iHash = i+1;
282 z += nn+1; n -= nn+1;
@@ -300,18 +323,20 @@
300 /*
301 ** Return zero if two DLine elements are identical, ignoring
302 ** all whitespace. The indent field of pA/pB already points
303 ** to the first non-space character in the string.
304 */
305
306 static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
307 int a = pA->indent, b = pB->indent;
308 if( pA->h==pB->h ){
 
 
 
 
309 while( a<pA->n || b<pB->n ){
310 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
311 while( a<pA->n && fossil_isspace(pA->z[a])) ++a;
312 while( b<pB->n && fossil_isspace(pB->z[b])) ++b;
313 }
314 return pA->n-a != pB->n-b;
315 }
316 return 1;
317 }
@@ -338,11 +363,11 @@
338 ** Append a single line of context-diff output to pOut.
339 */
340 static void appendDiffLine(
341 Blob *pOut, /* Where to write the line of output */
342 char cPrefix, /* One of " ", "+", or "-" */
343 DLine *pLine /* The line to be output */
344 ){
345 blob_append_char(pOut, cPrefix);
346 blob_append(pOut, pLine->z, pLine->n);
347 blob_append_char(pOut, '\n');
348 }
@@ -371,14 +396,14 @@
371 static void contextDiff(
372 DContext *p, /* The difference */
373 Blob *pOut, /* Output a context diff to here */
374 DiffConfig *pCfg /* Configuration options */
375 ){
376 DLine *A; /* Left side of the diff */
377 DLine *B; /* Right side of the diff */
378 int a = 0; /* Index of next line in A[] */
379 int b = 0; /* Index of next line in B[] */
380 int *R; /* Array of COPY/DELETE/INSERT triples */
381 int r; /* Index into R[] */
382 int nr; /* Number of COPY/DELETE/INSERT triples to process */
383 int mxr; /* Maximum value for r */
384 int na, nb; /* Number of lines shown from A and B */
@@ -619,11 +644,11 @@
619 /*
620 ** Return true if the string starts with n spaces
621 */
622 static int allSpaces(const char *z, int n){
623 int i;
624 for(i=0; i<n && fossil_isspace(z[i]); i++){}
625 return i==n;
626 }
627
628 /*
629 ** Try to improve the human-readability of the LineChange p.
@@ -745,17 +770,17 @@
745 int nLong = nLeft<nRight ? nRight : nLeft;
746 int nGap = nLong - nShort;
747 for(i=nShort-nSuffix; i<=nPrefix; i++){
748 int iVal = 0;
749 char c = zLeft[i];
750 if( fossil_isspace(c) ){
751 iVal += 5;
752 }else if( !fossil_isalnum(c) ){
753 iVal += 2;
754 }
755 c = zLeft[i+nGap-1];
756 if( fossil_isspace(c) ){
757 iVal += 5;
758 }else if( !fossil_isalnum(c) ){
759 iVal += 2;
760 }
761 if( iVal>iBestVal ){
@@ -889,11 +914,11 @@
889 struct DiffBuilder {
890 void (*xSkip)(DiffBuilder*, unsigned int, int);
891 void (*xCommon)(DiffBuilder*,const DLine*);
892 void (*xInsert)(DiffBuilder*,const DLine*);
893 void (*xDelete)(DiffBuilder*,const DLine*);
894 void (*xReplace)(DiffBuilder*,const DLine*, const DLine*);
895 void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
896 void (*xEnd)(DiffBuilder*);
897 unsigned int lnLeft; /* Lines seen on the left (delete) side */
898 unsigned int lnRight; /* Lines seen on the right (insert) side */
899 unsigned int nPending; /* Number of pending lines */
@@ -1733,11 +1758,11 @@
1733 ** (3) If the two strings have a common prefix, measure that prefix
1734 ** (4) Find the length of the longest common subsequence that is
1735 ** at least 150% longer than the common prefix.
1736 ** (5) Longer common subsequences yield lower scores.
1737 */
1738 static int match_dline(const DLine *pA, const DLine *pB){
1739 const char *zA; /* Left string */
1740 const char *zB; /* right string */
1741 int nA; /* Bytes in zA[] */
1742 int nB; /* Bytes in zB[] */
1743 int nMin;
@@ -1749,17 +1774,29 @@
1749 unsigned char c; /* Character being examined */
1750 unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */
1751 unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */
1752
1753 zA = pA->z;
 
 
 
 
 
 
 
 
 
1754 zB = pB->z;
1755 nA = pA->n;
1756 nB = pB->n;
1757 while( nA>0 && (unsigned char)zA[0]<=' ' ){ nA--; zA++; }
1758 while( nA>0 && (unsigned char)zA[nA-1]<=' ' ){ nA--; }
1759 while( nB>0 && (unsigned char)zB[0]<=' ' ){ nB--; zB++; }
1760 while( nB>0 && (unsigned char)zB[nB-1]<=' ' ){ nB--; }
 
 
 
1761 if( nA>250 ) nA = 250;
1762 if( nB>250 ) nB = 250;
1763 avg = (nA+nB)/2;
1764 if( avg==0 ) return 0;
1765 nMin = nA;
@@ -1785,11 +1822,11 @@
1785 int limit = minInt(nA-i, nB-j);
1786 for(k=best; k<=limit && zA[k+i]==zB[k+j]; k++){}
1787 if( k>best ) best = k;
1788 }
1789 }
1790 score = (best>=avg) ? 0 : (avg - best)*100/avg;
1791
1792 #if 0
1793 fprintf(stderr, "A: [%.*s]\nB: [%.*s]\nbest=%d avg=%d score=%d\n",
1794 nA, zA+1, nB, zB+1, best, avg, score);
1795 #endif
@@ -1817,10 +1854,183 @@
1817 b.z = g.argv[3];
1818 b.n = (int)strlen(b.z);
1819 x = match_dline(&a, &b);
1820 fossil_print("%d\n", x);
1821 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1822
1823 /*
1824 ** The threshold at which diffBlockAlignment transitions from the
1825 ** O(N*N) Wagner minimum-edit-distance algorithm to a less process
1826 ** O(NlogN) divide-and-conquer approach.
@@ -1850,14 +2060,14 @@
1850 ** each other. Insertion and deletion costs are 50. Match costs
1851 ** are between 0 and 100 where 0 is a perfect match 100 is a complete
1852 ** mismatch.
1853 */
1854 static unsigned char *diffBlockAlignment(
1855 const DLine *aLeft, int nLeft, /* Text on the left */
1856 const DLine *aRight, int nRight, /* Text on the right */
1857 DiffConfig *pCfg, /* Configuration options */
1858 int *pNResult /* OUTPUT: Bytes of result */
1859 ){
1860 int i, j, k; /* Loop counters */
1861 int *a; /* One row of the Wagner matrix */
1862 int *pToFree; /* Space that needs to be freed */
1863 unsigned char *aM; /* Wagner result matrix */
@@ -1875,61 +2085,28 @@
1875 memset(aM, 1, nLeft);
1876 *pNResult = nLeft;
1877 return aM;
1878 }
1879
1880 /* For large alignments, use a divide and conquer algorithm that is
1881 ** O(NlogN). The result is not as precise, but this whole thing is an
1882 ** approximation anyhow, and the faster response time is an acceptable
1883 ** trade-off for reduced precision.
 
 
 
 
1884 */
1885 if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
1886 const DLine *aSmall; /* The smaller of aLeft and aRight */
1887 const DLine *aBig; /* The larger of aLeft and aRight */
1888 int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1889 int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
1890 int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
1891 unsigned char *a1, *a2; /* Results of the alignments on two halves */
1892 int n1, n2; /* Number of entries in a1 and a2 */
1893 int score, bestScore; /* Score and best score seen so far */
1894 if( nLeft>nRight ){
1895 aSmall = aRight;
1896 nSmall = nRight;
1897 aBig = aLeft;
1898 nBig = nLeft;
1899 }else{
1900 aSmall = aLeft;
1901 nSmall = nLeft;
1902 aBig = aRight;
1903 nBig = nRight;
1904 }
1905 iDivBig = nBig/2;
1906 iDivSmall = nSmall/2;
1907 bestScore = 10000;
1908 for(i=0; i<nSmall; i++){
1909 score = match_dline(aBig+iDivBig, aSmall+i) + abs(i-nSmall/2)*2;
1910 if( score<bestScore ){
1911 bestScore = score;
1912 iDivSmall = i;
1913 }
1914 }
1915 if( aSmall==aRight ){
1916 iDivRight = iDivSmall;
1917 iDivLeft = iDivBig;
1918 }else{
1919 iDivRight = iDivBig;
1920 iDivLeft = iDivSmall;
1921 }
1922 a1 = diffBlockAlignment(aLeft,iDivLeft,aRight,iDivRight,pCfg,&n1);
1923 a2 = diffBlockAlignment(aLeft+iDivLeft, nLeft-iDivLeft,
1924 aRight+iDivRight, nRight-iDivRight,
1925 pCfg, &n2);
1926 a1 = fossil_realloc(a1, n1+n2 );
1927 memcpy(a1+n1,a2,n2);
1928 fossil_free(a2);
1929 *pNResult = n1+n2;
1930 return a1;
1931 }
1932
1933 /* If we reach this point, we will be doing an O(N*N) Wagner minimum
1934 ** edit distance to compute the alignment.
1935 */
@@ -2026,12 +2203,12 @@
2026 static void formatDiff(
2027 DContext *p, /* The computed diff */
2028 DiffConfig *pCfg, /* Configuration options */
2029 DiffBuilder *pBuilder /* The formatter object */
2030 ){
2031 const DLine *A; /* Left side of the diff */
2032 const DLine *B; /* Right side of the diff */
2033 unsigned int a = 0; /* Index of next line in A[] */
2034 unsigned int b = 0; /* Index of next line in B[] */
2035 const int *R; /* Array of COPY/DELETE/INSERT triples */
2036 unsigned int r; /* Index into R[] */
2037 unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
@@ -2410,10 +2587,66 @@
2410 }
2411 p->aEdit[p->nEdit++] = nCopy;
2412 p->aEdit[p->nEdit++] = nDel;
2413 p->aEdit[p->nEdit++] = nIns;
2414 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2415
2416 /*
2417 ** Do a single step in the difference. Compute a sequence of
2418 ** copy/delete/insert steps that will convert lines iS1 through iE1-1 of
2419 ** the input into lines iS2 through iE2-1 of the output and write
@@ -2442,11 +2675,13 @@
2442 }
2443
2444 /* Find the longest matching segment between the two sequences */
2445 longestCommonSequence(p, iS1, iE1, iS2, iE2, &iSX, &iEX, &iSY, &iEY);
2446
2447 if( iEX>iSX ){
 
 
2448 /* A common segment has been found.
2449 ** Recursively diff either side of the matching segment */
2450 diff_step(p, iS1, iSX, iS2, iSY);
2451 if( iEX>iSX ){
2452 appendTriple(p, iEX - iSX, 0, 0);
@@ -3120,11 +3355,12 @@
3120 if( strcmp(zLimit,"none")==0 ){
3121 iLimit = 0;
3122 mxTime = 0;
3123 }else if( sqlite3_strglob("*[0-9]s", zLimit)==0 ){
3124 iLimit = 0;
3125 mxTime = current_time_in_milliseconds() + 1000.0*atof(zLimit);
 
3126 }else{
3127 iLimit = atoi(zLimit);
3128 if( iLimit<=0 ) iLimit = 30;
3129 mxTime = 0;
3130 }
3131
--- src/diff.c
+++ src/diff.c
@@ -121,12 +121,13 @@
121 */
122 typedef struct DLine DLine;
123 struct DLine {
124 const char *z; /* The text of the line */
125 u64 h; /* Hash of the line */
126 unsigned short indent; /* Index of first non-space */
127 unsigned short n; /* number of bytes */
128 unsigned short nw; /* number of bytes without leading/trailing space */
129 unsigned int iNext; /* 1+(Index of next line with same the same hash) */
130
131 /* an array of DLine elements serves two purposes. The fields
132 ** above are one per line of input text. But each entry is also
133 ** a bucket in a hash table, as follows: */
@@ -163,12 +164,34 @@
164 int nEditAlloc; /* Space allocated for aEdit[] */
165 DLine *aFrom; /* File on left side of the diff */
166 int nFrom; /* Number of lines in aFrom[] */
167 DLine *aTo; /* File on right side of the diff */
168 int nTo; /* Number of lines in aTo[] */
169 int (*xDiffer)(const DLine *,const DLine *); /* comparison function */
170 };
171
172 /* Fast isspace for use by diff */
173 static const char diffIsSpace[] = {
174 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0,
175 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
176 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
177 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
178 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
179 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
180 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182
183 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
184 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
185 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
186 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
187 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
188 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
189 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
191 };
192 #define diff_isspace(X) (diffIsSpace[(unsigned char)(X)])
193
194 /*
195 ** Count the number of lines in the input string. Include the last line
196 ** in the count even if it lacks the \n terminator. If an empty string
197 ** is specified, the number of lines is zero. For the purposes of this
@@ -245,38 +268,38 @@
268 k = nn;
269 if( diffFlags & DIFF_STRIP_EOLCR ){
270 if( k>0 && z[k-1]=='\r' ){ k--; }
271 }
272 a[i].n = k;
 
273 if( diffFlags & DIFF_IGNORE_EOLWS ){
274 while( k>0 && diff_isspace(z[k-1]) ){ k--; }
275 }
276 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
277 int numws = 0;
278 for(s=0; s<k && z[s]<=' '; s++){}
279 a[i].indent = s;
280 a[i].nw = k - s;
281 for(h=0, x=s; x<k; x++){
282 char c = z[x];
283 if( diff_isspace(c) ){
284 ++numws;
285 }else{
286 h = (h^c)*9000000000000000041LL;
287 }
288 }
289 k -= numws;
290 }else{
291 int k2 = k & ~0x7;
292 u64 m;
293 for(h=x=s=0; x<k2; x += 8){
294 memcpy(&m, z+x, 8);
295 h = (h^m)*9000000000000000041LL;
296 }
297 m = 0;
298 memcpy(&m, z+x, k-k2);
299 h ^= m;
300 }
 
301 a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s);
302 h2 = h % nLine;
303 a[i].iNext = a[h2].iHash;
304 a[h2].iHash = i+1;
305 z += nn+1; n -= nn+1;
@@ -300,18 +323,20 @@
323 /*
324 ** Return zero if two DLine elements are identical, ignoring
325 ** all whitespace. The indent field of pA/pB already points
326 ** to the first non-space character in the string.
327 */
 
328 static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
 
329 if( pA->h==pB->h ){
330 int a, b;
331 if( memcmp(pA->z, pB->z, pA->h&LENGTH_MASK)==0 ) return 0;
332 a = pA->indent;
333 b = pB->indent;
334 while( a<pA->n || b<pB->n ){
335 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
336 while( a<pA->n && diff_isspace(pA->z[a])) ++a;
337 while( b<pB->n && diff_isspace(pB->z[b])) ++b;
338 }
339 return pA->n-a != pB->n-b;
340 }
341 return 1;
342 }
@@ -338,11 +363,11 @@
363 ** Append a single line of context-diff output to pOut.
364 */
365 static void appendDiffLine(
366 Blob *pOut, /* Where to write the line of output */
367 char cPrefix, /* One of " ", "+", or "-" */
368 const DLine *pLine /* The line to be output */
369 ){
370 blob_append_char(pOut, cPrefix);
371 blob_append(pOut, pLine->z, pLine->n);
372 blob_append_char(pOut, '\n');
373 }
@@ -371,14 +396,14 @@
396 static void contextDiff(
397 DContext *p, /* The difference */
398 Blob *pOut, /* Output a context diff to here */
399 DiffConfig *pCfg /* Configuration options */
400 ){
401 const DLine *A; /* Left side of the diff */
402 const DLine *B; /* Right side of the diff */
403 int a = 0; /* Index of next line in A[] */
404 int b = 0; /* Index of next line in B[] */
405 int *R; /* Array of COPY/DELETE/INSERT triples */
406 int r; /* Index into R[] */
407 int nr; /* Number of COPY/DELETE/INSERT triples to process */
408 int mxr; /* Maximum value for r */
409 int na, nb; /* Number of lines shown from A and B */
@@ -619,11 +644,11 @@
644 /*
645 ** Return true if the string starts with n spaces
646 */
647 static int allSpaces(const char *z, int n){
648 int i;
649 for(i=0; i<n && diff_isspace(z[i]); i++){}
650 return i==n;
651 }
652
653 /*
654 ** Try to improve the human-readability of the LineChange p.
@@ -745,17 +770,17 @@
770 int nLong = nLeft<nRight ? nRight : nLeft;
771 int nGap = nLong - nShort;
772 for(i=nShort-nSuffix; i<=nPrefix; i++){
773 int iVal = 0;
774 char c = zLeft[i];
775 if( diff_isspace(c) ){
776 iVal += 5;
777 }else if( !fossil_isalnum(c) ){
778 iVal += 2;
779 }
780 c = zLeft[i+nGap-1];
781 if( diff_isspace(c) ){
782 iVal += 5;
783 }else if( !fossil_isalnum(c) ){
784 iVal += 2;
785 }
786 if( iVal>iBestVal ){
@@ -889,11 +914,11 @@
914 struct DiffBuilder {
915 void (*xSkip)(DiffBuilder*, unsigned int, int);
916 void (*xCommon)(DiffBuilder*,const DLine*);
917 void (*xInsert)(DiffBuilder*,const DLine*);
918 void (*xDelete)(DiffBuilder*,const DLine*);
919 void (*xReplace)(DiffBuilder*,const DLine*,const DLine*);
920 void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
921 void (*xEnd)(DiffBuilder*);
922 unsigned int lnLeft; /* Lines seen on the left (delete) side */
923 unsigned int lnRight; /* Lines seen on the right (insert) side */
924 unsigned int nPending; /* Number of pending lines */
@@ -1733,11 +1758,11 @@
1758 ** (3) If the two strings have a common prefix, measure that prefix
1759 ** (4) Find the length of the longest common subsequence that is
1760 ** at least 150% longer than the common prefix.
1761 ** (5) Longer common subsequences yield lower scores.
1762 */
1763 static int match_dline(DLine *pA, DLine *pB){
1764 const char *zA; /* Left string */
1765 const char *zB; /* right string */
1766 int nA; /* Bytes in zA[] */
1767 int nB; /* Bytes in zB[] */
1768 int nMin;
@@ -1749,17 +1774,29 @@
1774 unsigned char c; /* Character being examined */
1775 unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */
1776 unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */
1777
1778 zA = pA->z;
1779 if( pA->nw==0 && pA->n ){
1780 for(i=0; i<pA->n && diff_isspace(zA[i]); i++){}
1781 pA->indent = i;
1782 for(j=pA->n-1; j>i && diff_isspace(zA[j]); j--){}
1783 pA->nw = j - i + 1;
1784 }
1785 zA += pA->indent;
1786 nA = pA->nw;
1787
1788 zB = pB->z;
1789 if( pB->nw==0 && pB->n ){
1790 for(i=0; i<pB->n && diff_isspace(zB[i]); i++){}
1791 pB->indent = i;
1792 for(j=pB->n-1; j>i && diff_isspace(zB[j]); j--){}
1793 pB->nw = j - i + 1;
1794 }
1795 zB += pB->indent;
1796 nB = pB->nw;
1797
1798 if( nA>250 ) nA = 250;
1799 if( nB>250 ) nB = 250;
1800 avg = (nA+nB)/2;
1801 if( avg==0 ) return 0;
1802 nMin = nA;
@@ -1785,11 +1822,11 @@
1822 int limit = minInt(nA-i, nB-j);
1823 for(k=best; k<=limit && zA[k+i]==zB[k+j]; k++){}
1824 if( k>best ) best = k;
1825 }
1826 }
1827 score = 5 + ((best>=avg) ? 0 : (avg - best)*95/avg);
1828
1829 #if 0
1830 fprintf(stderr, "A: [%.*s]\nB: [%.*s]\nbest=%d avg=%d score=%d\n",
1831 nA, zA+1, nB, zB+1, best, avg, score);
1832 #endif
@@ -1817,10 +1854,183 @@
1854 b.z = g.argv[3];
1855 b.n = (int)strlen(b.z);
1856 x = match_dline(&a, &b);
1857 fossil_print("%d\n", x);
1858 }
1859
1860 /* Forward declarations for recursion */
1861 static unsigned char *diffBlockAlignment(
1862 DLine *aLeft, int nLeft, /* Text on the left */
1863 DLine *aRight, int nRight, /* Text on the right */
1864 DiffConfig *pCfg, /* Configuration options */
1865 int *pNResult /* OUTPUT: Bytes of result */
1866 );
1867 static void longestCommonSequence(
1868 DContext *p, /* Two files being compared */
1869 int iS1, int iE1, /* Range of lines in p->aFrom[] */
1870 int iS2, int iE2, /* Range of lines in p->aTo[] */
1871 int *piSX, int *piEX, /* Write p->aFrom[] common segment here */
1872 int *piSY, int *piEY /* Write p->aTo[] common segment here */
1873 );
1874
1875 /*
1876 ** Make a copy of a list of nLine DLine objects from one array to
1877 ** another. Hash the new array to ignore whitespace.
1878 */
1879 static void diffDLineXfer(
1880 DLine *aTo,
1881 const DLine *aFrom,
1882 int nLine
1883 ){
1884 int i, j, k;
1885 u64 h, h2;
1886 for(i=0; i<nLine; i++) aTo[i].iHash = 0;
1887 for(i=0; i<nLine; i++){
1888 const char *z = aFrom[i].z;
1889 int n = aFrom[i].n;
1890 for(j=0; j<n && diff_isspace(z[j]); j++){}
1891 aTo[i].z = &z[j];
1892 for(k=aFrom[i].n; k>j && diff_isspace(z[k-1]); k--){}
1893 aTo[i].n = n = k-j;
1894 aTo[i].indent = 0;
1895 aTo[i].nw = 0;
1896 for(h=0; j<k; j++){
1897 char c = z[j];
1898 if( !diff_isspace(c) ){
1899 h = (h^c)*9000000000000000041LL;
1900 }
1901 }
1902 aTo[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | n;
1903 h2 = h % nLine;
1904 aTo[i].iNext = aTo[h2].iHash;
1905 aTo[h2].iHash = i+1;
1906 }
1907 }
1908
1909
1910 /*
1911 ** For a difficult diff-block alignment that was originally for
1912 ** the default consider-all-whitespace algorithm, try to find the
1913 ** longest common subsequence between the two blocks that involves
1914 ** only whitespace changes.
1915 */
1916 static unsigned char *diffBlockAlignmentIgnoreSpace(
1917 DLine *aLeft, int nLeft, /* Text on the left */
1918 DLine *aRight, int nRight, /* Text on the right */
1919 DiffConfig *pCfg, /* Configuration options */
1920 int *pNResult /* OUTPUT: Bytes of result */
1921 ){
1922 DContext dc;
1923 int iSX, iEX; /* Start and end of LCS on the left */
1924 int iSY, iEY; /* Start and end of the LCS on the right */
1925 unsigned char *a1, *a2;
1926 int n1, n2, nLCS;
1927
1928 dc.aEdit = 0;
1929 dc.nEdit = 0;
1930 dc.nEditAlloc = 0;
1931 dc.nFrom = nLeft;
1932 dc.nTo = nRight;
1933 dc.xDiffer = compare_dline_ignore_allws;
1934 dc.aFrom = fossil_malloc( sizeof(DLine)*(nLeft+nRight) );
1935 dc.aTo = &dc.aFrom[dc.nFrom];
1936 diffDLineXfer(dc.aFrom, aLeft, nLeft);
1937 diffDLineXfer(dc.aTo, aRight, nRight);
1938 longestCommonSequence(&dc,0,nLeft,0,nRight,&iSX,&iEX,&iSY,&iEY);
1939 fossil_free(dc.aFrom);
1940 nLCS = iEX - iSX;
1941 if( nLCS<5 ) return 0; /* No good LCS was found */
1942
1943 if( pCfg->diffFlags & DIFF_DEBUG ){
1944 fossil_print(" LCS size=%d\n"
1945 " [%.*s]\n"
1946 " [%.*s]\n",
1947 nLCS, aLeft[iSX].n, aLeft[iSX].z,
1948 aLeft[iEX-1].n, aLeft[iEX-1].z);
1949 }
1950
1951 a1 = diffBlockAlignment(aLeft,iSX,aRight,iSY,pCfg,&n1);
1952 a2 = diffBlockAlignment(aLeft+iEX, nLeft-iEX,
1953 aRight+iEY, nRight-iEY,
1954 pCfg, &n2);
1955 a1 = fossil_realloc(a1, n1+nLCS+n2);
1956 memcpy(a1+n1+nLCS,a2,n2);
1957 memset(a1+n1,3,nLCS);
1958 fossil_free(a2);
1959 *pNResult = n1+n2+nLCS;
1960 return a1;
1961 }
1962
1963
1964 /*
1965 ** This is a helper route for diffBlockAlignment(). In this case,
1966 ** a very large block is encountered that might be too expensive to
1967 ** use the O(N*N) Wagner edit distance algorithm. So instead, this
1968 ** block implements a less-precise but faster O(N*logN) divide-and-conquer
1969 ** approach.
1970 */
1971 static unsigned char *diffBlockAlignmentDivideAndConquer(
1972 DLine *aLeft, int nLeft, /* Text on the left */
1973 DLine *aRight, int nRight, /* Text on the right */
1974 DiffConfig *pCfg, /* Configuration options */
1975 int *pNResult /* OUTPUT: Bytes of result */
1976 ){
1977 DLine *aSmall; /* The smaller of aLeft and aRight */
1978 DLine *aBig; /* The larger of aLeft and aRight */
1979 int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1980 int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
1981 int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
1982 unsigned char *a1, *a2; /* Results of the alignments on two halves */
1983 int n1, n2; /* Number of entries in a1 and a2 */
1984 int score, bestScore; /* Score and best score seen so far */
1985 int i; /* Loop counter */
1986
1987 if( nLeft>nRight ){
1988 aSmall = aRight;
1989 nSmall = nRight;
1990 aBig = aLeft;
1991 nBig = nLeft;
1992 }else{
1993 aSmall = aLeft;
1994 nSmall = nLeft;
1995 aBig = aRight;
1996 nBig = nRight;
1997 }
1998 iDivBig = nBig/2;
1999 iDivSmall = nSmall/2;
2000
2001 if( pCfg->diffFlags & DIFF_DEBUG ){
2002 fossil_print(" Divide at [%.*s]\n",
2003 aBig[iDivBig].n, aBig[iDivBig].z);
2004 }
2005
2006 bestScore = 10000;
2007 for(i=0; i<nSmall; i++){
2008 score = match_dline(aBig+iDivBig, aSmall+i) + abs(i-nSmall/2)*2;
2009 if( score<bestScore ){
2010 bestScore = score;
2011 iDivSmall = i;
2012 }
2013 }
2014 if( aSmall==aRight ){
2015 iDivRight = iDivSmall;
2016 iDivLeft = iDivBig;
2017 }else{
2018 iDivRight = iDivBig;
2019 iDivLeft = iDivSmall;
2020 }
2021 a1 = diffBlockAlignment(aLeft,iDivLeft,aRight,iDivRight,pCfg,&n1);
2022 a2 = diffBlockAlignment(aLeft+iDivLeft, nLeft-iDivLeft,
2023 aRight+iDivRight, nRight-iDivRight,
2024 pCfg, &n2);
2025 a1 = fossil_realloc(a1, n1+n2 );
2026 memcpy(a1+n1,a2,n2);
2027 fossil_free(a2);
2028 *pNResult = n1+n2;
2029 return a1;
2030 }
2031
2032
2033 /*
2034 ** The threshold at which diffBlockAlignment transitions from the
2035 ** O(N*N) Wagner minimum-edit-distance algorithm to a less process
2036 ** O(NlogN) divide-and-conquer approach.
@@ -1850,14 +2060,14 @@
2060 ** each other. Insertion and deletion costs are 50. Match costs
2061 ** are between 0 and 100 where 0 is a perfect match 100 is a complete
2062 ** mismatch.
2063 */
2064 static unsigned char *diffBlockAlignment(
2065 DLine *aLeft, int nLeft, /* Text on the left */
2066 DLine *aRight, int nRight, /* Text on the right */
2067 DiffConfig *pCfg, /* Configuration options */
2068 int *pNResult /* OUTPUT: Bytes of result */
2069 ){
2070 int i, j, k; /* Loop counters */
2071 int *a; /* One row of the Wagner matrix */
2072 int *pToFree; /* Space that needs to be freed */
2073 unsigned char *aM; /* Wagner result matrix */
@@ -1875,61 +2085,28 @@
2085 memset(aM, 1, nLeft);
2086 *pNResult = nLeft;
2087 return aM;
2088 }
2089
2090 if( pCfg->diffFlags & DIFF_DEBUG ){
2091 fossil_print("BlockAlignment:\n [%.*s] + %d\n [%.*s] + %d\n",
2092 aLeft[0].n, aLeft[0].z, nLeft,
2093 aRight[0].n, aRight[0].z, nRight);
2094 }
2095
2096 /* For large alignments, try to use alternative algorithms that are
2097 ** faster than the O(N*N) Wagner edit distance.
2098 */
2099 if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
2100 if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){
2101 unsigned char *aRes;
2102 aRes = diffBlockAlignmentIgnoreSpace(
2103 aLeft, nLeft,aRight, nRight,pCfg,pNResult);
2104 if( aRes ) return aRes;
2105 }
2106 return diffBlockAlignmentDivideAndConquer(
2107 aLeft, nLeft,aRight, nRight,pCfg,pNResult);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2108 }
2109
2110 /* If we reach this point, we will be doing an O(N*N) Wagner minimum
2111 ** edit distance to compute the alignment.
2112 */
@@ -2026,12 +2203,12 @@
2203 static void formatDiff(
2204 DContext *p, /* The computed diff */
2205 DiffConfig *pCfg, /* Configuration options */
2206 DiffBuilder *pBuilder /* The formatter object */
2207 ){
2208 DLine *A; /* Left side of the diff */
2209 DLine *B; /* Right side of the diff */
2210 unsigned int a = 0; /* Index of next line in A[] */
2211 unsigned int b = 0; /* Index of next line in B[] */
2212 const int *R; /* Array of COPY/DELETE/INSERT triples */
2213 unsigned int r; /* Index into R[] */
2214 unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
@@ -2410,10 +2587,66 @@
2587 }
2588 p->aEdit[p->nEdit++] = nCopy;
2589 p->aEdit[p->nEdit++] = nDel;
2590 p->aEdit[p->nEdit++] = nIns;
2591 }
2592
2593 /*
2594 ** A common subsequene between p->aFrom and p->aTo has been found.
2595 ** This routine tries to judge if the subsequence really is a valid
2596 ** match or rather is just an artifact of an indentation change.
2597 **
2598 ** Return non-zero if the subsequence is valid. Return zero if the
2599 ** subsequence seems likely to be an editing artifact and should be
2600 ** ignored.
2601 **
2602 ** This routine is a heuristic optimization intended to give more
2603 ** intuitive diff results following an indentation change it code that
2604 ** is formatted similarly to C/C++, Javascript, Go, TCL, and similar
2605 ** languages that use {...} for nesting. A correct diff is computed
2606 ** even if this routine always returns true (non-zero). But sometimes
2607 ** a more intuitive diff can result if this routine returns false.
2608 **
2609 ** The subsequences consists of the rows iSX through iEX-1 (inclusive)
2610 ** in p->aFrom[]. The total sequences is iS1 through iE1-1 (inclusive)
2611 ** of p->aFrom[].
2612 **
2613 ** Example where this heuristic is useful, see the diff at
2614 ** https://www.sqlite.org/src/fdiff?v1=0e79dd15cbdb4f48&v2=33955a6fd874dd97
2615 **
2616 ** See also discussion at https://fossil-scm.org/forum/forumpost/9ba3284295
2617 **
2618 ** ALGORITHM (subject to change and refinement):
2619 **
2620 ** 1. If the subsequence is larger than 1/7th of the original span,
2621 ** then consider it valid. --> return 1
2622 **
2623 ** 2. If the subsequence contains any charaters other than '}', '{",
2624 ** or whitespace, then consider it valid. --> return 1
2625 **
2626 ** 3. Otherwise, it is potentially an artifact of an indentation
2627 ** change. --> return 0
2628 */
2629 static int likelyNotIndentChngArtifact(
2630 DContext *p, /* The complete diff context */
2631 int iS1, /* Start of the main segment */
2632 int iSX, /* Start of the subsequence */
2633 int iEX, /* First row past the end of the subsequence */
2634 int iE1 /* First row past the end of the main segment */
2635 ){
2636 int i, j;
2637 if( (iEX-iSX)*7 >= (iE1-iS1) ) return 1;
2638 for(i=iSX; i<iEX; i++){
2639 const char *z = p->aFrom[i].z;
2640 for(j=p->aFrom[i].n-1; j>=0; j--){
2641 char c = z[j];
2642 if( c!='}' && c!='{' && !diff_isspace(c) ) return 1;
2643 }
2644 }
2645 return 0;
2646 }
2647
2648
2649 /*
2650 ** Do a single step in the difference. Compute a sequence of
2651 ** copy/delete/insert steps that will convert lines iS1 through iE1-1 of
2652 ** the input into lines iS2 through iE2-1 of the output and write
@@ -2442,11 +2675,13 @@
2675 }
2676
2677 /* Find the longest matching segment between the two sequences */
2678 longestCommonSequence(p, iS1, iE1, iS2, iE2, &iSX, &iEX, &iSY, &iEY);
2679
2680 if( iEX>iSX+5
2681 || (iEX>iSX && likelyNotIndentChngArtifact(p,iS1,iSX,iEX,iE1) )
2682 ){
2683 /* A common segment has been found.
2684 ** Recursively diff either side of the matching segment */
2685 diff_step(p, iS1, iSX, iS2, iSY);
2686 if( iEX>iSX ){
2687 appendTriple(p, iEX - iSX, 0, 0);
@@ -3120,11 +3355,12 @@
3355 if( strcmp(zLimit,"none")==0 ){
3356 iLimit = 0;
3357 mxTime = 0;
3358 }else if( sqlite3_strglob("*[0-9]s", zLimit)==0 ){
3359 iLimit = 0;
3360 mxTime =
3361 (sqlite3_int64)(current_time_in_milliseconds() + 1000.0*atof(zLimit));
3362 }else{
3363 iLimit = atoi(zLimit);
3364 if( iLimit<=0 ) iLimit = 30;
3365 mxTime = 0;
3366 }
3367
--- src/dispatch.c
+++ src/dispatch.c
@@ -1008,17 +1008,20 @@
10081008
/* @-comment: # */
10091009
static const char zOptions[] =
10101010
@ Command-line options common to all commands:
10111011
@
10121012
@ --args FILENAME Read additional arguments and options from FILENAME
1013
+@ --case-sensitive BOOL Set case sensitivity for file names
10131014
@ --cgitrace Active CGI tracing
1015
+@ --chdir PATH Change to PATH before performing any operations
10141016
@ --comfmtflags VALUE Set comment formatting flags to VALUE
10151017
@ --comment-format VALUE Alias for --comfmtflags
10161018
@ --errorlog FILENAME Log errors to FILENAME
10171019
@ --help Show help on the command rather than running it
10181020
@ --httptrace Trace outbound HTTP requests
10191021
@ --localtime Display times using the local timezone
1022
+@ --nocgi Do not act as GCI
10201023
@ --no-th-hook Do not run TH1 hooks
10211024
@ --quiet Reduce the amount of output
10221025
@ --sqlstats Show SQL usage statistics when done
10231026
@ --sqltrace Trace all SQL commands
10241027
@ --sshtrace Trace SSH activity
10251028
--- src/dispatch.c
+++ src/dispatch.c
@@ -1008,17 +1008,20 @@
1008 /* @-comment: # */
1009 static const char zOptions[] =
1010 @ Command-line options common to all commands:
1011 @
1012 @ --args FILENAME Read additional arguments and options from FILENAME
 
1013 @ --cgitrace Active CGI tracing
 
1014 @ --comfmtflags VALUE Set comment formatting flags to VALUE
1015 @ --comment-format VALUE Alias for --comfmtflags
1016 @ --errorlog FILENAME Log errors to FILENAME
1017 @ --help Show help on the command rather than running it
1018 @ --httptrace Trace outbound HTTP requests
1019 @ --localtime Display times using the local timezone
 
1020 @ --no-th-hook Do not run TH1 hooks
1021 @ --quiet Reduce the amount of output
1022 @ --sqlstats Show SQL usage statistics when done
1023 @ --sqltrace Trace all SQL commands
1024 @ --sshtrace Trace SSH activity
1025
--- src/dispatch.c
+++ src/dispatch.c
@@ -1008,17 +1008,20 @@
1008 /* @-comment: # */
1009 static const char zOptions[] =
1010 @ Command-line options common to all commands:
1011 @
1012 @ --args FILENAME Read additional arguments and options from FILENAME
1013 @ --case-sensitive BOOL Set case sensitivity for file names
1014 @ --cgitrace Active CGI tracing
1015 @ --chdir PATH Change to PATH before performing any operations
1016 @ --comfmtflags VALUE Set comment formatting flags to VALUE
1017 @ --comment-format VALUE Alias for --comfmtflags
1018 @ --errorlog FILENAME Log errors to FILENAME
1019 @ --help Show help on the command rather than running it
1020 @ --httptrace Trace outbound HTTP requests
1021 @ --localtime Display times using the local timezone
1022 @ --nocgi Do not act as GCI
1023 @ --no-th-hook Do not run TH1 hooks
1024 @ --quiet Reduce the amount of output
1025 @ --sqlstats Show SQL usage statistics when done
1026 @ --sqltrace Trace all SQL commands
1027 @ --sshtrace Trace SSH activity
1028
+7 -2
--- src/fusefs.c
+++ src/fusefs.c
@@ -20,14 +20,14 @@
2020
**
2121
** This module is a mostly a no-op unless compiled with -DFOSSIL_HAVE_FUSEFS.
2222
** The FOSSIL_HAVE_FUSEFS should be omitted on systems that lack support for
2323
** the Fuse Filesystem, of course.
2424
*/
25
-#ifdef FOSSIL_HAVE_FUSEFS
2625
#include "config.h"
2726
#include <stdio.h>
2827
#include <string.h>
28
+#ifdef FOSSIL_HAVE_FUSEFS
2929
#include <errno.h>
3030
#include <fcntl.h>
3131
#include <stdlib.h>
3232
#include <unistd.h>
3333
#include <sys/types.h>
@@ -283,10 +283,11 @@
283283
static struct fuse_operations fusefs_methods = {
284284
.getattr = fusefs_getattr,
285285
.readdir = fusefs_readdir,
286286
.read = fusefs_read,
287287
};
288
+#endif /* FOSSIL_HAVE_FUSEFS */
288289
289290
/*
290291
** COMMAND: fusefs*
291292
**
292293
** Usage: %fossil fusefs [--debug] DIRECTORY
@@ -314,10 +315,11 @@
314315
** After stopping the "fossil fusefs" command, it might also be necessary
315316
** to run "fusermount -u DIRECTORY" to reset the FuseFS before using it
316317
** again.
317318
*/
318319
void fusefs_cmd(void){
320
+#ifdef FOSSIL_HAVE_FUSEFS
319321
char *zMountPoint;
320322
char *azNewArgv[5];
321323
int doDebug = find_option("debug","d",0)!=0;
322324
323325
db_find_and_open_repository(0,0);
@@ -335,12 +337,15 @@
335337
azNewArgv[4] = 0;
336338
g.localOpen = 0; /* Prevent tags like "current" and "prev" */
337339
fuse_main(4, azNewArgv, &fusefs_methods, NULL);
338340
fusefs_reset();
339341
fusefs_clear_path();
340
-}
342
+#else
343
+ fprintf(stderr, "The FuseFS is not available in this build.\n");
344
+ exit(1);
341345
#endif /* FOSSIL_HAVE_FUSEFS */
346
+}
342347
343348
/*
344349
** Return version numbers for the FUSE header that was used at compile-time
345350
** and/or the FUSE library that was loaded at runtime.
346351
*/
347352
--- src/fusefs.c
+++ src/fusefs.c
@@ -20,14 +20,14 @@
20 **
21 ** This module is a mostly a no-op unless compiled with -DFOSSIL_HAVE_FUSEFS.
22 ** The FOSSIL_HAVE_FUSEFS should be omitted on systems that lack support for
23 ** the Fuse Filesystem, of course.
24 */
25 #ifdef FOSSIL_HAVE_FUSEFS
26 #include "config.h"
27 #include <stdio.h>
28 #include <string.h>
 
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <sys/types.h>
@@ -283,10 +283,11 @@
283 static struct fuse_operations fusefs_methods = {
284 .getattr = fusefs_getattr,
285 .readdir = fusefs_readdir,
286 .read = fusefs_read,
287 };
 
288
289 /*
290 ** COMMAND: fusefs*
291 **
292 ** Usage: %fossil fusefs [--debug] DIRECTORY
@@ -314,10 +315,11 @@
314 ** After stopping the "fossil fusefs" command, it might also be necessary
315 ** to run "fusermount -u DIRECTORY" to reset the FuseFS before using it
316 ** again.
317 */
318 void fusefs_cmd(void){
 
319 char *zMountPoint;
320 char *azNewArgv[5];
321 int doDebug = find_option("debug","d",0)!=0;
322
323 db_find_and_open_repository(0,0);
@@ -335,12 +337,15 @@
335 azNewArgv[4] = 0;
336 g.localOpen = 0; /* Prevent tags like "current" and "prev" */
337 fuse_main(4, azNewArgv, &fusefs_methods, NULL);
338 fusefs_reset();
339 fusefs_clear_path();
340 }
 
 
341 #endif /* FOSSIL_HAVE_FUSEFS */
 
342
343 /*
344 ** Return version numbers for the FUSE header that was used at compile-time
345 ** and/or the FUSE library that was loaded at runtime.
346 */
347
--- src/fusefs.c
+++ src/fusefs.c
@@ -20,14 +20,14 @@
20 **
21 ** This module is a mostly a no-op unless compiled with -DFOSSIL_HAVE_FUSEFS.
22 ** The FOSSIL_HAVE_FUSEFS should be omitted on systems that lack support for
23 ** the Fuse Filesystem, of course.
24 */
 
25 #include "config.h"
26 #include <stdio.h>
27 #include <string.h>
28 #ifdef FOSSIL_HAVE_FUSEFS
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <sys/types.h>
@@ -283,10 +283,11 @@
283 static struct fuse_operations fusefs_methods = {
284 .getattr = fusefs_getattr,
285 .readdir = fusefs_readdir,
286 .read = fusefs_read,
287 };
288 #endif /* FOSSIL_HAVE_FUSEFS */
289
290 /*
291 ** COMMAND: fusefs*
292 **
293 ** Usage: %fossil fusefs [--debug] DIRECTORY
@@ -314,10 +315,11 @@
315 ** After stopping the "fossil fusefs" command, it might also be necessary
316 ** to run "fusermount -u DIRECTORY" to reset the FuseFS before using it
317 ** again.
318 */
319 void fusefs_cmd(void){
320 #ifdef FOSSIL_HAVE_FUSEFS
321 char *zMountPoint;
322 char *azNewArgv[5];
323 int doDebug = find_option("debug","d",0)!=0;
324
325 db_find_and_open_repository(0,0);
@@ -335,12 +337,15 @@
337 azNewArgv[4] = 0;
338 g.localOpen = 0; /* Prevent tags like "current" and "prev" */
339 fuse_main(4, azNewArgv, &fusefs_methods, NULL);
340 fusefs_reset();
341 fusefs_clear_path();
342 #else
343 fprintf(stderr, "The FuseFS is not available in this build.\n");
344 exit(1);
345 #endif /* FOSSIL_HAVE_FUSEFS */
346 }
347
348 /*
349 ** Return version numbers for the FUSE header that was used at compile-time
350 ** and/or the FUSE library that was loaded at runtime.
351 */
352
+26 -18
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -770,11 +770,10 @@
770770
}
771771
}
772772
773773
typedef struct SslServerConn {
774774
SSL *ssl; /* The SSL codec */
775
- int atEof; /* True when EOF reached. */
776775
int iSocket; /* The socket */
777776
BIO *bio; /* BIO object. Needed for EOF detection. */
778777
} SslServerConn;
779778
780779
/*
@@ -784,11 +783,10 @@
784783
*/
785784
void *ssl_new_server(int iSocket){
786785
SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
787786
BIO *b = BIO_new_socket(iSocket, 0);
788787
pServer->ssl = SSL_new(sslCtx);
789
- pServer->atEof = 0;
790788
pServer->iSocket = iSocket;
791789
pServer->bio = b;
792790
SSL_set_bio(pServer->ssl, b, b);
793791
SSL_accept(pServer->ssl);
794792
return (void*)pServer;
@@ -807,48 +805,54 @@
807805
** Return TRUE if there are no more bytes available to be read from
808806
** the client.
809807
*/
810808
int ssl_eof(void *pServerArg){
811809
SslServerConn *pServer = (SslServerConn*)pServerArg;
812
- return pServer->atEof;
810
+ return BIO_eof(pServer->bio);
813811
}
814812
815813
/*
816814
** Read cleartext bytes that have been received from the client and
817815
** decrypted by the SSL server codec.
816
+**
817
+** If the expected payload size unknown, i.e. if the HTTP
818
+** Content-Length: header field has not been parsed, the doLoop
819
+** argument should be 0, or SSL_read() may block and wait for more
820
+** data than is eventually going to arrive (on Windows). On
821
+** non-Windows builds, it has been our experience that the final
822
+** argument must always be true, as discussed at length at:
823
+**
824
+** https://fossil-scm.org/forum/forumpost/2f818850abb72719
818825
*/
819
-size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){
820
- int n, err = 0;
826
+size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf, int doLoop){
827
+ int n;
821828
size_t rc = 0;
822829
SslServerConn *pServer = (SslServerConn*)pServerArg;
823830
if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); }
824
- while( 0==err && nBuf!=rc && 0==pServer->atEof ){
831
+ while( nBuf!=rc && BIO_eof(pServer->bio)==0 ){
825832
n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc));
826
- if( n==0 ){
827
- pServer->atEof = 1;
828
- break;
829
- }
830
- err = SSL_get_error(pServer->ssl, n);
831
- if(0==err){
833
+ if( n>0 ){
832834
rc += n;
833
- pServer->atEof = BIO_eof(pServer->bio);
834
- }else{
835
- fossil_fatal("SSL read error.");
835
+ }
836
+ if( doLoop==0 || n<=0 ){
837
+ break;
836838
}
837839
}
838840
return rc;
839841
}
840842
841843
/*
842
-** Read a single line of text from the client.
844
+** Read a single line of text from the client, up to nBuf-1 bytes. On
845
+** success, writes nBuf-1 bytes to zBuf and NUL-terminates zBuf.
846
+** Returns NULL on an I/O error or at EOF.
843847
*/
844848
char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){
845849
int n = 0;
846850
int i;
847851
SslServerConn *pServer = (SslServerConn*)pServerArg;
848
-
849
- if( pServer->atEof ) return 0;
852
+
853
+ if( BIO_eof(pServer->bio) ) return 0;
850854
for(i=0; i<nBuf-1; i++){
851855
n = SSL_read(pServer->ssl, &zBuf[i], 1);
852856
if( n<=0 ){
853857
return 0;
854858
}
@@ -876,10 +880,11 @@
876880
}
877881
}
878882
879883
#endif /* FOSSIL_ENABLE_SSL */
880884
885
+#ifdef FOSSIL_ENABLE_SSL
881886
/*
882887
** zPath is a name that might be a file or directory containing a trust
883888
** store. *pzStore is the name of the trust store to actually use.
884889
**
885890
** If *pzStore is not NULL (meaning no trust store has been found yet)
@@ -887,10 +892,11 @@
887892
*/
888893
static void trust_location_usable(const char *zPath, const char **pzStore){
889894
if( *pzStore!=0 ) return;
890895
if( file_isdir(zPath, ExtFILE)>0 ) *pzStore = zPath;
891896
}
897
+#endif /* FOSSIL_ENABLE_SSL */
892898
893899
/*
894900
** COMMAND: tls-config*
895901
** COMMAND: ssl-config
896902
**
@@ -947,13 +953,15 @@
947953
"DELETE FROM config WHERE name GLOB 'ssl-*';"
948954
);
949955
db_protect_pop();
950956
}else
951957
if( strncmp("show",zCmd,nCmd)==0 ){
958
+#if defined(FOSSIL_ENABLE_SSL)
952959
const char *zName, *zValue;
953960
const char *zUsed = 0; /* Trust store location actually used */
954961
size_t nName;
962
+#endif
955963
Stmt q;
956964
int verbose = find_option("verbose","v",0)!=0;
957965
verify_all_options();
958966
959967
#if !defined(FOSSIL_ENABLE_SSL)
960968
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -770,11 +770,10 @@
770 }
771 }
772
773 typedef struct SslServerConn {
774 SSL *ssl; /* The SSL codec */
775 int atEof; /* True when EOF reached. */
776 int iSocket; /* The socket */
777 BIO *bio; /* BIO object. Needed for EOF detection. */
778 } SslServerConn;
779
780 /*
@@ -784,11 +783,10 @@
784 */
785 void *ssl_new_server(int iSocket){
786 SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
787 BIO *b = BIO_new_socket(iSocket, 0);
788 pServer->ssl = SSL_new(sslCtx);
789 pServer->atEof = 0;
790 pServer->iSocket = iSocket;
791 pServer->bio = b;
792 SSL_set_bio(pServer->ssl, b, b);
793 SSL_accept(pServer->ssl);
794 return (void*)pServer;
@@ -807,48 +805,54 @@
807 ** Return TRUE if there are no more bytes available to be read from
808 ** the client.
809 */
810 int ssl_eof(void *pServerArg){
811 SslServerConn *pServer = (SslServerConn*)pServerArg;
812 return pServer->atEof;
813 }
814
815 /*
816 ** Read cleartext bytes that have been received from the client and
817 ** decrypted by the SSL server codec.
 
 
 
 
 
 
 
 
 
818 */
819 size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){
820 int n, err = 0;
821 size_t rc = 0;
822 SslServerConn *pServer = (SslServerConn*)pServerArg;
823 if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); }
824 while( 0==err && nBuf!=rc && 0==pServer->atEof ){
825 n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc));
826 if( n==0 ){
827 pServer->atEof = 1;
828 break;
829 }
830 err = SSL_get_error(pServer->ssl, n);
831 if(0==err){
832 rc += n;
833 pServer->atEof = BIO_eof(pServer->bio);
834 }else{
835 fossil_fatal("SSL read error.");
836 }
837 }
838 return rc;
839 }
840
841 /*
842 ** Read a single line of text from the client.
 
 
843 */
844 char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){
845 int n = 0;
846 int i;
847 SslServerConn *pServer = (SslServerConn*)pServerArg;
848
849 if( pServer->atEof ) return 0;
850 for(i=0; i<nBuf-1; i++){
851 n = SSL_read(pServer->ssl, &zBuf[i], 1);
852 if( n<=0 ){
853 return 0;
854 }
@@ -876,10 +880,11 @@
876 }
877 }
878
879 #endif /* FOSSIL_ENABLE_SSL */
880
 
881 /*
882 ** zPath is a name that might be a file or directory containing a trust
883 ** store. *pzStore is the name of the trust store to actually use.
884 **
885 ** If *pzStore is not NULL (meaning no trust store has been found yet)
@@ -887,10 +892,11 @@
887 */
888 static void trust_location_usable(const char *zPath, const char **pzStore){
889 if( *pzStore!=0 ) return;
890 if( file_isdir(zPath, ExtFILE)>0 ) *pzStore = zPath;
891 }
 
892
893 /*
894 ** COMMAND: tls-config*
895 ** COMMAND: ssl-config
896 **
@@ -947,13 +953,15 @@
947 "DELETE FROM config WHERE name GLOB 'ssl-*';"
948 );
949 db_protect_pop();
950 }else
951 if( strncmp("show",zCmd,nCmd)==0 ){
 
952 const char *zName, *zValue;
953 const char *zUsed = 0; /* Trust store location actually used */
954 size_t nName;
 
955 Stmt q;
956 int verbose = find_option("verbose","v",0)!=0;
957 verify_all_options();
958
959 #if !defined(FOSSIL_ENABLE_SSL)
960
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -770,11 +770,10 @@
770 }
771 }
772
773 typedef struct SslServerConn {
774 SSL *ssl; /* The SSL codec */
 
775 int iSocket; /* The socket */
776 BIO *bio; /* BIO object. Needed for EOF detection. */
777 } SslServerConn;
778
779 /*
@@ -784,11 +783,10 @@
783 */
784 void *ssl_new_server(int iSocket){
785 SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
786 BIO *b = BIO_new_socket(iSocket, 0);
787 pServer->ssl = SSL_new(sslCtx);
 
788 pServer->iSocket = iSocket;
789 pServer->bio = b;
790 SSL_set_bio(pServer->ssl, b, b);
791 SSL_accept(pServer->ssl);
792 return (void*)pServer;
@@ -807,48 +805,54 @@
805 ** Return TRUE if there are no more bytes available to be read from
806 ** the client.
807 */
808 int ssl_eof(void *pServerArg){
809 SslServerConn *pServer = (SslServerConn*)pServerArg;
810 return BIO_eof(pServer->bio);
811 }
812
813 /*
814 ** Read cleartext bytes that have been received from the client and
815 ** decrypted by the SSL server codec.
816 **
817 ** If the expected payload size unknown, i.e. if the HTTP
818 ** Content-Length: header field has not been parsed, the doLoop
819 ** argument should be 0, or SSL_read() may block and wait for more
820 ** data than is eventually going to arrive (on Windows). On
821 ** non-Windows builds, it has been our experience that the final
822 ** argument must always be true, as discussed at length at:
823 **
824 ** https://fossil-scm.org/forum/forumpost/2f818850abb72719
825 */
826 size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf, int doLoop){
827 int n;
828 size_t rc = 0;
829 SslServerConn *pServer = (SslServerConn*)pServerArg;
830 if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); }
831 while( nBuf!=rc && BIO_eof(pServer->bio)==0 ){
832 n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc));
833 if( n>0 ){
 
 
 
 
 
834 rc += n;
835 }
836 if( doLoop==0 || n<=0 ){
837 break;
838 }
839 }
840 return rc;
841 }
842
843 /*
844 ** Read a single line of text from the client, up to nBuf-1 bytes. On
845 ** success, writes nBuf-1 bytes to zBuf and NUL-terminates zBuf.
846 ** Returns NULL on an I/O error or at EOF.
847 */
848 char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){
849 int n = 0;
850 int i;
851 SslServerConn *pServer = (SslServerConn*)pServerArg;
852
853 if( BIO_eof(pServer->bio) ) return 0;
854 for(i=0; i<nBuf-1; i++){
855 n = SSL_read(pServer->ssl, &zBuf[i], 1);
856 if( n<=0 ){
857 return 0;
858 }
@@ -876,10 +880,11 @@
880 }
881 }
882
883 #endif /* FOSSIL_ENABLE_SSL */
884
885 #ifdef FOSSIL_ENABLE_SSL
886 /*
887 ** zPath is a name that might be a file or directory containing a trust
888 ** store. *pzStore is the name of the trust store to actually use.
889 **
890 ** If *pzStore is not NULL (meaning no trust store has been found yet)
@@ -887,10 +892,11 @@
892 */
893 static void trust_location_usable(const char *zPath, const char **pzStore){
894 if( *pzStore!=0 ) return;
895 if( file_isdir(zPath, ExtFILE)>0 ) *pzStore = zPath;
896 }
897 #endif /* FOSSIL_ENABLE_SSL */
898
899 /*
900 ** COMMAND: tls-config*
901 ** COMMAND: ssl-config
902 **
@@ -947,13 +953,15 @@
953 "DELETE FROM config WHERE name GLOB 'ssl-*';"
954 );
955 db_protect_pop();
956 }else
957 if( strncmp("show",zCmd,nCmd)==0 ){
958 #if defined(FOSSIL_ENABLE_SSL)
959 const char *zName, *zValue;
960 const char *zUsed = 0; /* Trust store location actually used */
961 size_t nName;
962 #endif
963 Stmt q;
964 int verbose = find_option("verbose","v",0)!=0;
965 verify_all_options();
966
967 #if !defined(FOSSIL_ENABLE_SSL)
968
+6 -15
--- src/json.c
+++ src/json.c
@@ -1,8 +1,8 @@
11
#ifdef FOSSIL_ENABLE_JSON
22
/*
3
-** Copyright (c) 2011 D. Richard Hipp
3
+** Copyright (c) 2011-2022 D. Richard Hipp
44
**
55
** This program is free software; you can redistribute it and/or
66
** modify it under the terms of the Simplified BSD License (also
77
** known as the "2-Clause License" or "FreeBSD License".)
88
@@ -172,21 +172,10 @@
172172
Blob * b = (Blob*)pState;
173173
blob_append( b, (char const *)src, (int)n ) /* will die on OOM */;
174174
return 0;
175175
}
176176
177
-/*
178
-** Implements the cson_data_source_f() interface and reads input from
179
-** a fossil Blob object. pState must be-a (Blob*) populated with JSON
180
-** data.
181
-*/
182
-int cson_data_src_Blob(void * pState, void * dest, unsigned int * n){
183
- Blob * b = (Blob*)pState;
184
- *n = blob_read( b, dest, *n );
185
- return 0;
186
-}
187
-
188177
/*
189178
** Convenience wrapper around cson_output() which appends the output
190179
** to pDest. pOpt may be NULL, in which case g.json.outOpt will be used.
191180
*/
192181
int cson_output_Blob( cson_value const * pVal, Blob * pDest, cson_output_opt const * pOpt ){
@@ -204,12 +193,11 @@
204193
** On success a new JSON Object or Array is returned (owned by the
205194
** caller). On error NULL is returned.
206195
*/
207196
cson_value * cson_parse_Blob( Blob * pSrc, cson_parse_info * pInfo ){
208197
cson_value * root = NULL;
209
- blob_rewind( pSrc );
210
- cson_parse( &root, cson_data_src_Blob, pSrc, NULL, pInfo );
198
+ cson_parse_string( &root, blob_str(pSrc), blob_size(pSrc), NULL, pInfo );
211199
return root;
212200
}
213201
214202
/*
215203
** Implements the cson_data_dest_f() interface and outputs the data to
@@ -1065,10 +1053,11 @@
10651053
because outOpt cannot (generically) be configured until after
10661054
POST-reading is finished.
10671055
*/
10681056
FILE * inFile = NULL;
10691057
char const * jfile = find_option("json-input",NULL,1);
1058
+ Blob json = BLOB_INITIALIZER;
10701059
if(!jfile || !*jfile){
10711060
break;
10721061
}
10731062
inFile = (0==strcmp("-",jfile))
10741063
? stdin
@@ -1077,12 +1066,14 @@
10771066
g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
10781067
fossil_fatal("Could not open JSON file [%s].",jfile)
10791068
/* Does not return. */
10801069
;
10811070
}
1082
- cgi_parse_POST_JSON(inFile, 0);
1071
+ blob_read_from_channel(&json, inFile, -1);
10831072
fossil_fclose(inFile);
1073
+ cgi_parse_POST_JSON(&json);
1074
+ blob_reset(&json);
10841075
break;
10851076
}
10861077
10871078
/* g.json.reqPayload exists only to simplify some of our access to
10881079
the request payload. We currently only use this in the context of
10891080
--- src/json.c
+++ src/json.c
@@ -1,8 +1,8 @@
1 #ifdef FOSSIL_ENABLE_JSON
2 /*
3 ** Copyright (c) 2011 D. Richard Hipp
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the Simplified BSD License (also
7 ** known as the "2-Clause License" or "FreeBSD License".)
8
@@ -172,21 +172,10 @@
172 Blob * b = (Blob*)pState;
173 blob_append( b, (char const *)src, (int)n ) /* will die on OOM */;
174 return 0;
175 }
176
177 /*
178 ** Implements the cson_data_source_f() interface and reads input from
179 ** a fossil Blob object. pState must be-a (Blob*) populated with JSON
180 ** data.
181 */
182 int cson_data_src_Blob(void * pState, void * dest, unsigned int * n){
183 Blob * b = (Blob*)pState;
184 *n = blob_read( b, dest, *n );
185 return 0;
186 }
187
188 /*
189 ** Convenience wrapper around cson_output() which appends the output
190 ** to pDest. pOpt may be NULL, in which case g.json.outOpt will be used.
191 */
192 int cson_output_Blob( cson_value const * pVal, Blob * pDest, cson_output_opt const * pOpt ){
@@ -204,12 +193,11 @@
204 ** On success a new JSON Object or Array is returned (owned by the
205 ** caller). On error NULL is returned.
206 */
207 cson_value * cson_parse_Blob( Blob * pSrc, cson_parse_info * pInfo ){
208 cson_value * root = NULL;
209 blob_rewind( pSrc );
210 cson_parse( &root, cson_data_src_Blob, pSrc, NULL, pInfo );
211 return root;
212 }
213
214 /*
215 ** Implements the cson_data_dest_f() interface and outputs the data to
@@ -1065,10 +1053,11 @@
1065 because outOpt cannot (generically) be configured until after
1066 POST-reading is finished.
1067 */
1068 FILE * inFile = NULL;
1069 char const * jfile = find_option("json-input",NULL,1);
 
1070 if(!jfile || !*jfile){
1071 break;
1072 }
1073 inFile = (0==strcmp("-",jfile))
1074 ? stdin
@@ -1077,12 +1066,14 @@
1077 g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
1078 fossil_fatal("Could not open JSON file [%s].",jfile)
1079 /* Does not return. */
1080 ;
1081 }
1082 cgi_parse_POST_JSON(inFile, 0);
1083 fossil_fclose(inFile);
 
 
1084 break;
1085 }
1086
1087 /* g.json.reqPayload exists only to simplify some of our access to
1088 the request payload. We currently only use this in the context of
1089
--- src/json.c
+++ src/json.c
@@ -1,8 +1,8 @@
1 #ifdef FOSSIL_ENABLE_JSON
2 /*
3 ** Copyright (c) 2011-2022 D. Richard Hipp
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the Simplified BSD License (also
7 ** known as the "2-Clause License" or "FreeBSD License".)
8
@@ -172,21 +172,10 @@
172 Blob * b = (Blob*)pState;
173 blob_append( b, (char const *)src, (int)n ) /* will die on OOM */;
174 return 0;
175 }
176
 
 
 
 
 
 
 
 
 
 
 
177 /*
178 ** Convenience wrapper around cson_output() which appends the output
179 ** to pDest. pOpt may be NULL, in which case g.json.outOpt will be used.
180 */
181 int cson_output_Blob( cson_value const * pVal, Blob * pDest, cson_output_opt const * pOpt ){
@@ -204,12 +193,11 @@
193 ** On success a new JSON Object or Array is returned (owned by the
194 ** caller). On error NULL is returned.
195 */
196 cson_value * cson_parse_Blob( Blob * pSrc, cson_parse_info * pInfo ){
197 cson_value * root = NULL;
198 cson_parse_string( &root, blob_str(pSrc), blob_size(pSrc), NULL, pInfo );
 
199 return root;
200 }
201
202 /*
203 ** Implements the cson_data_dest_f() interface and outputs the data to
@@ -1065,10 +1053,11 @@
1053 because outOpt cannot (generically) be configured until after
1054 POST-reading is finished.
1055 */
1056 FILE * inFile = NULL;
1057 char const * jfile = find_option("json-input",NULL,1);
1058 Blob json = BLOB_INITIALIZER;
1059 if(!jfile || !*jfile){
1060 break;
1061 }
1062 inFile = (0==strcmp("-",jfile))
1063 ? stdin
@@ -1077,12 +1066,14 @@
1066 g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
1067 fossil_fatal("Could not open JSON file [%s].",jfile)
1068 /* Does not return. */
1069 ;
1070 }
1071 blob_read_from_channel(&json, inFile, -1);
1072 fossil_fclose(inFile);
1073 cgi_parse_POST_JSON(&json);
1074 blob_reset(&json);
1075 break;
1076 }
1077
1078 /* g.json.reqPayload exists only to simplify some of our access to
1079 the request payload. We currently only use this in the context of
1080
+27 -6
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -273,30 +273,51 @@
273273
return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
274274
}
275275
276276
/*
277277
** Implementation of /json/wiki/preview.
278
-**
279278
*/
280279
static cson_value * json_wiki_preview(){
281280
char const * zContent = NULL;
281
+ char const * zMime = NULL;
282
+ cson_string * sContent = NULL;
282283
cson_value * pay = NULL;
283284
Blob contentOrig = empty_blob;
284285
Blob contentHtml = empty_blob;
285286
if( !g.perm.WrWiki ){
286287
json_set_err(FSL_JSON_E_DENIED,
287288
"Requires 'k' access.");
288289
return NULL;
289290
}
290
- zContent = cson_string_cstr(cson_value_get_string(g.json.reqPayload.v));
291
- if(!zContent) {
291
+
292
+ if(g.json.reqPayload.o){
293
+ sContent = cson_value_get_string(
294
+ cson_object_get(g.json.reqPayload.o, "body"));
295
+ zMime = cson_value_get_cstr(cson_object_get(g.json.reqPayload.o,
296
+ "mimetype"));
297
+ }else{
298
+ sContent = cson_value_get_string(g.json.reqPayload.v);
299
+ }
300
+ if(!sContent) {
292301
json_set_err(FSL_JSON_E_MISSING_ARGS,
293
- "The 'payload' property must be a string containing the wiki code to preview.");
302
+ "The 'payload' property must be either a string containing the "
303
+ "Fossil wiki code to preview or an object with body + mimetype "
304
+ "properties.");
294305
return NULL;
295306
}
296
- blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(cson_value_get_string(g.json.reqPayload.v)) );
297
- wiki_convert( &contentOrig, &contentHtml, 0 );
307
+ zContent = cson_string_cstr(sContent);
308
+ blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(sContent) );
309
+ zMime = wiki_filter_mimetypes(zMime);
310
+ if( 0==fossil_strcmp(zMime, "text/x-markdown") ){
311
+ markdown_to_html(&contentOrig, 0, &contentHtml);
312
+ }else if( 0==fossil_strcmp(zMime, "text/plain") ){
313
+ blob_append(&contentHtml, "<pre class='textPlain'>", -1);
314
+ blob_append(&contentHtml, blob_str(&contentOrig), blob_size(&contentOrig));
315
+ blob_append(&contentHtml, "</pre>", -1);
316
+ }else{
317
+ wiki_convert( &contentOrig, &contentHtml, 0 );
318
+ }
298319
blob_reset( &contentOrig );
299320
pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml));
300321
blob_reset( &contentHtml );
301322
return pay;
302323
}
303324
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -273,30 +273,51 @@
273 return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
274 }
275
276 /*
277 ** Implementation of /json/wiki/preview.
278 **
279 */
280 static cson_value * json_wiki_preview(){
281 char const * zContent = NULL;
 
 
282 cson_value * pay = NULL;
283 Blob contentOrig = empty_blob;
284 Blob contentHtml = empty_blob;
285 if( !g.perm.WrWiki ){
286 json_set_err(FSL_JSON_E_DENIED,
287 "Requires 'k' access.");
288 return NULL;
289 }
290 zContent = cson_string_cstr(cson_value_get_string(g.json.reqPayload.v));
291 if(!zContent) {
 
 
 
 
 
 
 
 
292 json_set_err(FSL_JSON_E_MISSING_ARGS,
293 "The 'payload' property must be a string containing the wiki code to preview.");
 
 
294 return NULL;
295 }
296 blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(cson_value_get_string(g.json.reqPayload.v)) );
297 wiki_convert( &contentOrig, &contentHtml, 0 );
 
 
 
 
 
 
 
 
 
 
298 blob_reset( &contentOrig );
299 pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml));
300 blob_reset( &contentHtml );
301 return pay;
302 }
303
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -273,30 +273,51 @@
273 return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
274 }
275
276 /*
277 ** Implementation of /json/wiki/preview.
 
278 */
279 static cson_value * json_wiki_preview(){
280 char const * zContent = NULL;
281 char const * zMime = NULL;
282 cson_string * sContent = NULL;
283 cson_value * pay = NULL;
284 Blob contentOrig = empty_blob;
285 Blob contentHtml = empty_blob;
286 if( !g.perm.WrWiki ){
287 json_set_err(FSL_JSON_E_DENIED,
288 "Requires 'k' access.");
289 return NULL;
290 }
291
292 if(g.json.reqPayload.o){
293 sContent = cson_value_get_string(
294 cson_object_get(g.json.reqPayload.o, "body"));
295 zMime = cson_value_get_cstr(cson_object_get(g.json.reqPayload.o,
296 "mimetype"));
297 }else{
298 sContent = cson_value_get_string(g.json.reqPayload.v);
299 }
300 if(!sContent) {
301 json_set_err(FSL_JSON_E_MISSING_ARGS,
302 "The 'payload' property must be either a string containing the "
303 "Fossil wiki code to preview or an object with body + mimetype "
304 "properties.");
305 return NULL;
306 }
307 zContent = cson_string_cstr(sContent);
308 blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(sContent) );
309 zMime = wiki_filter_mimetypes(zMime);
310 if( 0==fossil_strcmp(zMime, "text/x-markdown") ){
311 markdown_to_html(&contentOrig, 0, &contentHtml);
312 }else if( 0==fossil_strcmp(zMime, "text/plain") ){
313 blob_append(&contentHtml, "<pre class='textPlain'>", -1);
314 blob_append(&contentHtml, blob_str(&contentOrig), blob_size(&contentOrig));
315 blob_append(&contentHtml, "</pre>", -1);
316 }else{
317 wiki_convert( &contentOrig, &contentHtml, 0 );
318 }
319 blob_reset( &contentOrig );
320 pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml));
321 blob_reset( &contentHtml );
322 return pay;
323 }
324
+25 -23
--- src/main.c
+++ src/main.c
@@ -2616,12 +2616,12 @@
26162616
**
26172617
** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
26182618
**
26192619
** Handle a single HTTP request appearing on stdin. The resulting webpage
26202620
** is delivered on stdout. This method is used to launch an HTTP request
2621
-** handler from inetd, for example. The argument is the name of the
2622
-** repository.
2621
+** handler from inetd, for example. The REPOSITORY argument is the name of
2622
+** the repository.
26232623
**
26242624
** If REPOSITORY is a directory that contains one or more repositories,
26252625
** either directly in REPOSITORY itself or in subdirectories, and
26262626
** with names of the form "*.fossil" then a prefix of the URL pathname
26272627
** selects from among the various repositories. If the pathname does
@@ -2632,31 +2632,24 @@
26322632
** and every "." must be surrounded on both sides by alphanumerics or else
26332633
** a 404 error is returned. Static content files in the directory are
26342634
** returned if they match comma-separate GLOB pattern specified by --files
26352635
** and do not match "*.fossil*" and have a well-known suffix.
26362636
**
2637
-** The --host option can be used to specify the hostname for the server.
2638
-** The --https option indicates that the request came from HTTPS rather
2639
-** than HTTP. If --nossl is given, then SSL connections will not be available,
2640
-** thus also no redirecting from http: to https: will take place.
2641
-**
2642
-** If the --localauth option is given, then automatic login is performed
2643
-** for requests coming from localhost, if the "localauth" setting is not
2644
-** enabled.
2645
-**
26462637
** Options:
26472638
** --acme Deliver files from the ".well-known" subdirectory
26482639
** --baseurl URL base URL (useful with reverse proxies)
26492640
** --cert FILE Use TLS (HTTPS) encryption with the certificate (the
26502641
** fullchain.pem) taken from FILE.
26512642
** --chroot DIR Use directory for chroot instead of repository path.
26522643
** --ckout-alias N Treat URIs of the form /doc/N/... as if they were
26532644
** /doc/ckout/...
2654
-** --extroot DIR document root for the /ext extension mechanism
2655
-** --files GLOB comma-separate glob patterns for static file to serve
2656
-** --host NAME specify hostname of the server
2657
-** --https signal a request coming in via https
2645
+** --extroot DIR Document root for the /ext extension mechanism
2646
+** --files GLOB Comma-separate glob patterns for static file to serve
2647
+** --host NAME DNS Hostname of the server
2648
+** --https The HTTP request originated from https but has already
2649
+** been decoded by a reverse proxy. Hence, URLs created
2650
+** by Fossil should use "https:" rather than "http:".
26582651
** --in FILE Take input from FILE instead of standard input
26592652
** --ipaddr ADDR Assume the request comes from the given IP address
26602653
** --jsmode MODE Determine how JavaScript is delivered with pages.
26612654
** Mode can be one of:
26622655
** inline All JavaScript is inserted inline at
@@ -2668,25 +2661,28 @@
26682661
** concatenate scripts together.
26692662
** Depending on the needs of any given page, inline
26702663
** and bundled modes might result in a single
26712664
** amalgamated script or several, but both approaches
26722665
** result in fewer HTTP requests than the separate mode.
2673
-** --localauth enable automatic login for local connections
2666
+** --localauth Connections from localhost are given "setup"
2667
+** privileges without having to log in.
26742668
** --mainmenu FILE Override the mainmenu config setting with the contents
26752669
** of the given file.
2676
-** --nocompress do not compress HTTP replies
2677
-** --nodelay omit backoffice processing if it would delay
2670
+** --nocompress Do not compress HTTP replies
2671
+** --nodelay Omit backoffice processing if it would delay
26782672
** process exit
2679
-** --nojail drop root privilege but do not enter the chroot jail
2680
-** --nossl signal that no SSL connections are available
2681
-** --notfound URL use URL as "HTTP 404, object not found" page.
2682
-** --out FILE write results to FILE instead of to standard output
2673
+** --nojail Drop root privilege but do not enter the chroot jail
2674
+** --nossl Do not do http: to https: redirects, regardless of
2675
+** the redirect-to-https setting.
2676
+** --notfound URL Use URL as the "HTTP 404, object not found" page.
2677
+** --out FILE Write the HTTP reply to FILE instead of to
2678
+** standard output
26832679
** --pkey FILE Read the private key used for TLS from FILE.
26842680
** --repolist If REPOSITORY is directory, URL "/" lists all repos
26852681
** --scgi Interpret input as SCGI rather than HTTP
26862682
** --skin LABEL Use override skin LABEL
2687
-** --th-trace trace TH1 execution (for debugging purposes)
2683
+** --th-trace Trace TH1 execution (for debugging purposes)
26882684
** --usepidkey Use saved encryption key from parent process. This is
26892685
** only necessary when using SEE on Windows.
26902686
**
26912687
** See also: [[cgi]], [[server]], [[winsrv]]
26922688
*/
@@ -2733,17 +2729,23 @@
27332729
backoffice_disable();
27342730
g.httpIn = fossil_fopen(zInFile, "rb");
27352731
if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
27362732
}else{
27372733
g.httpIn = stdin;
2734
+#if defined(_WIN32)
2735
+ _setmode(_fileno(stdin), _O_BINARY);
2736
+#endif
27382737
}
27392738
zOutFile = find_option("out",0,1);
27402739
if( zOutFile ){
27412740
g.httpOut = fossil_fopen(zOutFile, "wb");
27422741
if( g.httpOut==0 ) fossil_fatal("cannot open \"%s\" for writing", zOutFile);
27432742
}else{
27442743
g.httpOut = stdout;
2744
+#if defined(_WIN32)
2745
+ _setmode(_fileno(stdout), _O_BINARY);
2746
+#endif
27452747
}
27462748
zIpAddr = find_option("ipaddr",0,1);
27472749
useSCGI = find_option("scgi", 0, 0)!=0;
27482750
zAltBase = find_option("baseurl", 0, 1);
27492751
if( find_option("nodelay",0,0)!=0 ) backoffice_no_delay();
27502752
--- src/main.c
+++ src/main.c
@@ -2616,12 +2616,12 @@
2616 **
2617 ** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
2618 **
2619 ** Handle a single HTTP request appearing on stdin. The resulting webpage
2620 ** is delivered on stdout. This method is used to launch an HTTP request
2621 ** handler from inetd, for example. The argument is the name of the
2622 ** repository.
2623 **
2624 ** If REPOSITORY is a directory that contains one or more repositories,
2625 ** either directly in REPOSITORY itself or in subdirectories, and
2626 ** with names of the form "*.fossil" then a prefix of the URL pathname
2627 ** selects from among the various repositories. If the pathname does
@@ -2632,31 +2632,24 @@
2632 ** and every "." must be surrounded on both sides by alphanumerics or else
2633 ** a 404 error is returned. Static content files in the directory are
2634 ** returned if they match comma-separate GLOB pattern specified by --files
2635 ** and do not match "*.fossil*" and have a well-known suffix.
2636 **
2637 ** The --host option can be used to specify the hostname for the server.
2638 ** The --https option indicates that the request came from HTTPS rather
2639 ** than HTTP. If --nossl is given, then SSL connections will not be available,
2640 ** thus also no redirecting from http: to https: will take place.
2641 **
2642 ** If the --localauth option is given, then automatic login is performed
2643 ** for requests coming from localhost, if the "localauth" setting is not
2644 ** enabled.
2645 **
2646 ** Options:
2647 ** --acme Deliver files from the ".well-known" subdirectory
2648 ** --baseurl URL base URL (useful with reverse proxies)
2649 ** --cert FILE Use TLS (HTTPS) encryption with the certificate (the
2650 ** fullchain.pem) taken from FILE.
2651 ** --chroot DIR Use directory for chroot instead of repository path.
2652 ** --ckout-alias N Treat URIs of the form /doc/N/... as if they were
2653 ** /doc/ckout/...
2654 ** --extroot DIR document root for the /ext extension mechanism
2655 ** --files GLOB comma-separate glob patterns for static file to serve
2656 ** --host NAME specify hostname of the server
2657 ** --https signal a request coming in via https
 
 
2658 ** --in FILE Take input from FILE instead of standard input
2659 ** --ipaddr ADDR Assume the request comes from the given IP address
2660 ** --jsmode MODE Determine how JavaScript is delivered with pages.
2661 ** Mode can be one of:
2662 ** inline All JavaScript is inserted inline at
@@ -2668,25 +2661,28 @@
2668 ** concatenate scripts together.
2669 ** Depending on the needs of any given page, inline
2670 ** and bundled modes might result in a single
2671 ** amalgamated script or several, but both approaches
2672 ** result in fewer HTTP requests than the separate mode.
2673 ** --localauth enable automatic login for local connections
 
2674 ** --mainmenu FILE Override the mainmenu config setting with the contents
2675 ** of the given file.
2676 ** --nocompress do not compress HTTP replies
2677 ** --nodelay omit backoffice processing if it would delay
2678 ** process exit
2679 ** --nojail drop root privilege but do not enter the chroot jail
2680 ** --nossl signal that no SSL connections are available
2681 ** --notfound URL use URL as "HTTP 404, object not found" page.
2682 ** --out FILE write results to FILE instead of to standard output
 
 
2683 ** --pkey FILE Read the private key used for TLS from FILE.
2684 ** --repolist If REPOSITORY is directory, URL "/" lists all repos
2685 ** --scgi Interpret input as SCGI rather than HTTP
2686 ** --skin LABEL Use override skin LABEL
2687 ** --th-trace trace TH1 execution (for debugging purposes)
2688 ** --usepidkey Use saved encryption key from parent process. This is
2689 ** only necessary when using SEE on Windows.
2690 **
2691 ** See also: [[cgi]], [[server]], [[winsrv]]
2692 */
@@ -2733,17 +2729,23 @@
2733 backoffice_disable();
2734 g.httpIn = fossil_fopen(zInFile, "rb");
2735 if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
2736 }else{
2737 g.httpIn = stdin;
 
 
 
2738 }
2739 zOutFile = find_option("out",0,1);
2740 if( zOutFile ){
2741 g.httpOut = fossil_fopen(zOutFile, "wb");
2742 if( g.httpOut==0 ) fossil_fatal("cannot open \"%s\" for writing", zOutFile);
2743 }else{
2744 g.httpOut = stdout;
 
 
 
2745 }
2746 zIpAddr = find_option("ipaddr",0,1);
2747 useSCGI = find_option("scgi", 0, 0)!=0;
2748 zAltBase = find_option("baseurl", 0, 1);
2749 if( find_option("nodelay",0,0)!=0 ) backoffice_no_delay();
2750
--- src/main.c
+++ src/main.c
@@ -2616,12 +2616,12 @@
2616 **
2617 ** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
2618 **
2619 ** Handle a single HTTP request appearing on stdin. The resulting webpage
2620 ** is delivered on stdout. This method is used to launch an HTTP request
2621 ** handler from inetd, for example. The REPOSITORY argument is the name of
2622 ** the repository.
2623 **
2624 ** If REPOSITORY is a directory that contains one or more repositories,
2625 ** either directly in REPOSITORY itself or in subdirectories, and
2626 ** with names of the form "*.fossil" then a prefix of the URL pathname
2627 ** selects from among the various repositories. If the pathname does
@@ -2632,31 +2632,24 @@
2632 ** and every "." must be surrounded on both sides by alphanumerics or else
2633 ** a 404 error is returned. Static content files in the directory are
2634 ** returned if they match comma-separate GLOB pattern specified by --files
2635 ** and do not match "*.fossil*" and have a well-known suffix.
2636 **
 
 
 
 
 
 
 
 
 
2637 ** Options:
2638 ** --acme Deliver files from the ".well-known" subdirectory
2639 ** --baseurl URL base URL (useful with reverse proxies)
2640 ** --cert FILE Use TLS (HTTPS) encryption with the certificate (the
2641 ** fullchain.pem) taken from FILE.
2642 ** --chroot DIR Use directory for chroot instead of repository path.
2643 ** --ckout-alias N Treat URIs of the form /doc/N/... as if they were
2644 ** /doc/ckout/...
2645 ** --extroot DIR Document root for the /ext extension mechanism
2646 ** --files GLOB Comma-separate glob patterns for static file to serve
2647 ** --host NAME DNS Hostname of the server
2648 ** --https The HTTP request originated from https but has already
2649 ** been decoded by a reverse proxy. Hence, URLs created
2650 ** by Fossil should use "https:" rather than "http:".
2651 ** --in FILE Take input from FILE instead of standard input
2652 ** --ipaddr ADDR Assume the request comes from the given IP address
2653 ** --jsmode MODE Determine how JavaScript is delivered with pages.
2654 ** Mode can be one of:
2655 ** inline All JavaScript is inserted inline at
@@ -2668,25 +2661,28 @@
2661 ** concatenate scripts together.
2662 ** Depending on the needs of any given page, inline
2663 ** and bundled modes might result in a single
2664 ** amalgamated script or several, but both approaches
2665 ** result in fewer HTTP requests than the separate mode.
2666 ** --localauth Connections from localhost are given "setup"
2667 ** privileges without having to log in.
2668 ** --mainmenu FILE Override the mainmenu config setting with the contents
2669 ** of the given file.
2670 ** --nocompress Do not compress HTTP replies
2671 ** --nodelay Omit backoffice processing if it would delay
2672 ** process exit
2673 ** --nojail Drop root privilege but do not enter the chroot jail
2674 ** --nossl Do not do http: to https: redirects, regardless of
2675 ** the redirect-to-https setting.
2676 ** --notfound URL Use URL as the "HTTP 404, object not found" page.
2677 ** --out FILE Write the HTTP reply to FILE instead of to
2678 ** standard output
2679 ** --pkey FILE Read the private key used for TLS from FILE.
2680 ** --repolist If REPOSITORY is directory, URL "/" lists all repos
2681 ** --scgi Interpret input as SCGI rather than HTTP
2682 ** --skin LABEL Use override skin LABEL
2683 ** --th-trace Trace TH1 execution (for debugging purposes)
2684 ** --usepidkey Use saved encryption key from parent process. This is
2685 ** only necessary when using SEE on Windows.
2686 **
2687 ** See also: [[cgi]], [[server]], [[winsrv]]
2688 */
@@ -2733,17 +2729,23 @@
2729 backoffice_disable();
2730 g.httpIn = fossil_fopen(zInFile, "rb");
2731 if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
2732 }else{
2733 g.httpIn = stdin;
2734 #if defined(_WIN32)
2735 _setmode(_fileno(stdin), _O_BINARY);
2736 #endif
2737 }
2738 zOutFile = find_option("out",0,1);
2739 if( zOutFile ){
2740 g.httpOut = fossil_fopen(zOutFile, "wb");
2741 if( g.httpOut==0 ) fossil_fatal("cannot open \"%s\" for writing", zOutFile);
2742 }else{
2743 g.httpOut = stdout;
2744 #if defined(_WIN32)
2745 _setmode(_fileno(stdout), _O_BINARY);
2746 #endif
2747 }
2748 zIpAddr = find_option("ipaddr",0,1);
2749 useSCGI = find_option("scgi", 0, 0)!=0;
2750 zAltBase = find_option("baseurl", 0, 1);
2751 if( find_option("nodelay",0,0)!=0 ) backoffice_no_delay();
2752
+12 -3
--- src/repolist.c
+++ src/repolist.c
@@ -174,11 +174,11 @@
174174
int nName = (int)strlen(zName);
175175
char *zUrl;
176176
char *zAge;
177177
char *zFull;
178178
RepoInfo x;
179
- int iAge;
179
+ sqlite3_int64 iAge;
180180
if( nName<7 ) continue;
181181
zUrl = sqlite3_mprintf("%.*s", nName-7, zName);
182182
if( zName[0]=='/'
183183
#ifdef _WIN32
184184
|| sqlite3_strglob("[a-zA-Z]:/*", zName)==0
@@ -205,13 +205,22 @@
205205
if( x.isRepolistSkin==2 && !allRepo ){
206206
/* Repositories with repolist-skin==2 are omitted from directory
207207
** scan lists, but included in "fossil all ui" lists */
208208
continue;
209209
}
210
- iAge = (rNow - x.rMTime)*86400;
211
- if( iAge<0 ) x.rMTime = rNow;
210
+ if( rNow <= x.rMTime ){
211
+ x.rMTime = rNow;
212
+ }else if( x.rMTime<0.0 ){
213
+ x.rMTime = rNow;
214
+ }
215
+ iAge = (int)(rNow - x.rMTime)*86400;
212216
zAge = human_readable_age(rNow - x.rMTime);
217
+ if( x.rMTime==0.0 ){
218
+ /* This repository has no entry in the "event" table.
219
+ ** Its age will still be maximum, so data-sortkey will work. */
220
+ zAge = mprintf("unknown");
221
+ }
213222
blob_append_sql(&html, "<tr><td valign='top'>");
214223
if( sqlite3_strglob("*.fossil", zName)!=0 ){
215224
/* The "fossil server DIRECTORY" and "fossil ui DIRECTORY" commands
216225
** do not work for repositories whose names do not end in ".fossil".
217226
** So do not hyperlink those cases. */
218227
--- src/repolist.c
+++ src/repolist.c
@@ -174,11 +174,11 @@
174 int nName = (int)strlen(zName);
175 char *zUrl;
176 char *zAge;
177 char *zFull;
178 RepoInfo x;
179 int iAge;
180 if( nName<7 ) continue;
181 zUrl = sqlite3_mprintf("%.*s", nName-7, zName);
182 if( zName[0]=='/'
183 #ifdef _WIN32
184 || sqlite3_strglob("[a-zA-Z]:/*", zName)==0
@@ -205,13 +205,22 @@
205 if( x.isRepolistSkin==2 && !allRepo ){
206 /* Repositories with repolist-skin==2 are omitted from directory
207 ** scan lists, but included in "fossil all ui" lists */
208 continue;
209 }
210 iAge = (rNow - x.rMTime)*86400;
211 if( iAge<0 ) x.rMTime = rNow;
 
 
 
 
212 zAge = human_readable_age(rNow - x.rMTime);
 
 
 
 
 
213 blob_append_sql(&html, "<tr><td valign='top'>");
214 if( sqlite3_strglob("*.fossil", zName)!=0 ){
215 /* The "fossil server DIRECTORY" and "fossil ui DIRECTORY" commands
216 ** do not work for repositories whose names do not end in ".fossil".
217 ** So do not hyperlink those cases. */
218
--- src/repolist.c
+++ src/repolist.c
@@ -174,11 +174,11 @@
174 int nName = (int)strlen(zName);
175 char *zUrl;
176 char *zAge;
177 char *zFull;
178 RepoInfo x;
179 sqlite3_int64 iAge;
180 if( nName<7 ) continue;
181 zUrl = sqlite3_mprintf("%.*s", nName-7, zName);
182 if( zName[0]=='/'
183 #ifdef _WIN32
184 || sqlite3_strglob("[a-zA-Z]:/*", zName)==0
@@ -205,13 +205,22 @@
205 if( x.isRepolistSkin==2 && !allRepo ){
206 /* Repositories with repolist-skin==2 are omitted from directory
207 ** scan lists, but included in "fossil all ui" lists */
208 continue;
209 }
210 if( rNow <= x.rMTime ){
211 x.rMTime = rNow;
212 }else if( x.rMTime<0.0 ){
213 x.rMTime = rNow;
214 }
215 iAge = (int)(rNow - x.rMTime)*86400;
216 zAge = human_readable_age(rNow - x.rMTime);
217 if( x.rMTime==0.0 ){
218 /* This repository has no entry in the "event" table.
219 ** Its age will still be maximum, so data-sortkey will work. */
220 zAge = mprintf("unknown");
221 }
222 blob_append_sql(&html, "<tr><td valign='top'>");
223 if( sqlite3_strglob("*.fossil", zName)!=0 ){
224 /* The "fossil server DIRECTORY" and "fossil ui DIRECTORY" commands
225 ** do not work for repositories whose names do not end in ".fossil".
226 ** So do not hyperlink those cases. */
227
+7 -4
--- src/stat.c
+++ src/stat.c
@@ -999,14 +999,17 @@
999999
r = 0;
10001000
n = 0;
10011001
while( db_step(&q)==SQLITE_ROW ){
10021002
r += db_column_int(&q, 0);
10031003
if( n50pct==0 && r>=sumCmpr/2 ) n50pct = n;
1004
- if( n==(nTotal+99)/100 ) sz1pct = r;
1005
- if( n==(nTotal+9)/10 ) sz10pct = r;
1006
- if( n==(nTotal+4)/5 ) sz25pct = r;
1007
- if( n==(nTotal+1)/2 ){ sz50pct = r; medCmpr = db_column_int(&q,0); }
1004
+ if( n==(nTotal+99)/100 ) sz1pct = (sqlite3_int64)r;
1005
+ if( n==(nTotal+9)/10 ) sz10pct = (sqlite3_int64)r;
1006
+ if( n==(nTotal+4)/5 ) sz25pct = (sqlite3_int64)r;
1007
+ if( n==(nTotal+1)/2 ){
1008
+ sz50pct = (sqlite3_int64)r;
1009
+ medCmpr = db_column_int(&q,0);
1010
+ }
10081011
n++;
10091012
}
10101013
db_finalize(&q);
10111014
10121015
@ <h1>Overall Artifact Size Statistics:</h1>
10131016
--- src/stat.c
+++ src/stat.c
@@ -999,14 +999,17 @@
999 r = 0;
1000 n = 0;
1001 while( db_step(&q)==SQLITE_ROW ){
1002 r += db_column_int(&q, 0);
1003 if( n50pct==0 && r>=sumCmpr/2 ) n50pct = n;
1004 if( n==(nTotal+99)/100 ) sz1pct = r;
1005 if( n==(nTotal+9)/10 ) sz10pct = r;
1006 if( n==(nTotal+4)/5 ) sz25pct = r;
1007 if( n==(nTotal+1)/2 ){ sz50pct = r; medCmpr = db_column_int(&q,0); }
 
 
 
1008 n++;
1009 }
1010 db_finalize(&q);
1011
1012 @ <h1>Overall Artifact Size Statistics:</h1>
1013
--- src/stat.c
+++ src/stat.c
@@ -999,14 +999,17 @@
999 r = 0;
1000 n = 0;
1001 while( db_step(&q)==SQLITE_ROW ){
1002 r += db_column_int(&q, 0);
1003 if( n50pct==0 && r>=sumCmpr/2 ) n50pct = n;
1004 if( n==(nTotal+99)/100 ) sz1pct = (sqlite3_int64)r;
1005 if( n==(nTotal+9)/10 ) sz10pct = (sqlite3_int64)r;
1006 if( n==(nTotal+4)/5 ) sz25pct = (sqlite3_int64)r;
1007 if( n==(nTotal+1)/2 ){
1008 sz50pct = (sqlite3_int64)r;
1009 medCmpr = db_column_int(&q,0);
1010 }
1011 n++;
1012 }
1013 db_finalize(&q);
1014
1015 @ <h1>Overall Artifact Size Statistics:</h1>
1016
+1 -1
--- src/tar.c
+++ src/tar.c
@@ -496,11 +496,11 @@
496496
nPrefix = blob_size(&filename);
497497
498498
pManifest = manifest_get(rid, CFTYPE_MANIFEST, 0);
499499
if( pManifest ){
500500
int flg, eflg = 0;
501
- mTime = (pManifest->rDate - 2440587.5)*86400.0;
501
+ mTime = (unsigned)((pManifest->rDate - 2440587.5)*86400.0);
502502
if( pTar ) tar_begin(mTime);
503503
flg = db_get_manifest_setting();
504504
if( flg ){
505505
/* eflg is the effective flags, taking include/exclude into account */
506506
if( (pInclude==0 || glob_match(pInclude, "manifest"))
507507
--- src/tar.c
+++ src/tar.c
@@ -496,11 +496,11 @@
496 nPrefix = blob_size(&filename);
497
498 pManifest = manifest_get(rid, CFTYPE_MANIFEST, 0);
499 if( pManifest ){
500 int flg, eflg = 0;
501 mTime = (pManifest->rDate - 2440587.5)*86400.0;
502 if( pTar ) tar_begin(mTime);
503 flg = db_get_manifest_setting();
504 if( flg ){
505 /* eflg is the effective flags, taking include/exclude into account */
506 if( (pInclude==0 || glob_match(pInclude, "manifest"))
507
--- src/tar.c
+++ src/tar.c
@@ -496,11 +496,11 @@
496 nPrefix = blob_size(&filename);
497
498 pManifest = manifest_get(rid, CFTYPE_MANIFEST, 0);
499 if( pManifest ){
500 int flg, eflg = 0;
501 mTime = (unsigned)((pManifest->rDate - 2440587.5)*86400.0);
502 if( pTar ) tar_begin(mTime);
503 flg = db_get_manifest_setting();
504 if( flg ){
505 /* eflg is the effective flags, taking include/exclude into account */
506 if( (pInclude==0 || glob_match(pInclude, "manifest"))
507
+17 -8
--- src/winhttp.c
+++ src/winhttp.c
@@ -363,14 +363,14 @@
363363
#endif
364364
}
365365
while( amt<szHdr ){
366366
if( sslConn ){
367367
#ifdef FOSSIL_ENABLE_SSL
368
- got = ssl_read_server(sslConn, &zBuf[amt], szHdr-amt);
368
+ got = ssl_read_server(sslConn, &zBuf[amt], szHdr-1-amt, 0);
369369
#endif
370370
}else{
371
- got = recv(p->s, &zBuf[amt], szHdr-amt, 0);
371
+ got = recv(p->s, &zBuf[amt], szHdr-1-amt, 0);
372372
if( got==SOCKET_ERROR ) goto end_request;
373373
}
374374
if( got==0 ){
375375
wanted = 0;
376376
break;
@@ -394,11 +394,11 @@
394394
if( out==0 ) goto end_request;
395395
fwrite(zBuf, 1, amt, out);
396396
while( wanted>0 ){
397397
if( sslConn ){
398398
#ifdef FOSSIL_ENABLE_SSL
399
- got = ssl_read_server(sslConn, zBuf, sizeof(zBuf));
399
+ got = ssl_read_server(sslConn, zBuf, min(wanted, sizeof(zBuf)), 1);
400400
#endif
401401
}else{
402402
got = recv(p->s, zBuf, sizeof(zBuf), 0);
403403
if( got==SOCKET_ERROR ) goto end_request;
404404
}
@@ -437,10 +437,13 @@
437437
g.httpUseSSL ? "" : " --nossl", p->zOptions
438438
);
439439
in = fossil_fopen(zReplyFName, "w+b");
440440
fflush(out);
441441
fflush(aux);
442
+ if( g.fHttpTrace ){
443
+ fossil_print("%s\n", zCmd);
444
+ }
442445
fossil_system(zCmd);
443446
if( in ){
444447
while( (got = fread(zBuf, 1, sizeof(zBuf), in))>0 ){
445448
if( sslConn ){
446449
#ifdef FOSSIL_ENABLE_SSL
@@ -465,13 +468,15 @@
465468
if( shutdown(p->s,1)==0 ) shutdown(p->s,0);
466469
closesocket(p->s);
467470
/* Make multiple attempts to delete the temporary files. Sometimes AV
468471
** software keeps the files open for a few seconds, preventing the file
469472
** from being deleted on the first try. */
470
- for(i=1; i<=10 && file_delete(zRequestFName); i++){ Sleep(1000*i); }
471
- for(i=1; i<=10 && file_delete(zCmdFName); i++){ Sleep(1000*i); }
472
- for(i=1; i<=10 && file_delete(zReplyFName); i++){ Sleep(1000*i); }
473
+ if( !g.fHttpTrace ){
474
+ for(i=1; i<=10 && file_delete(zRequestFName); i++){ Sleep(1000*i); }
475
+ for(i=1; i<=10 && file_delete(zCmdFName); i++){ Sleep(1000*i); }
476
+ for(i=1; i<=10 && file_delete(zReplyFName); i++){ Sleep(1000*i); }
477
+ }
473478
fossil_free(p);
474479
}
475480
476481
/*
477482
** Process a single incoming SCGI request.
@@ -652,12 +657,16 @@
652657
}
653658
}
654659
if( !GetTempPathW(MAX_PATH, zTmpPath) ){
655660
fossil_panic("unable to get path to the temporary directory.");
656661
}
657
- zTempPrefix = mprintf("%sfossil_server_P%d",
658
- fossil_unicode_to_utf8(zTmpPath), iPort);
662
+ if( g.fHttpTrace ){
663
+ zTempPrefix = mprintf("httptrace");
664
+ }else{
665
+ zTempPrefix = mprintf("%sfossil_server_P%d",
666
+ fossil_unicode_to_utf8(zTmpPath), iPort);
667
+ }
659668
fossil_print("Temporary files: %s*\n", zTempPrefix);
660669
fossil_print("Listening for %s requests on TCP port %d\n",
661670
(flags&HTTP_SERVER_SCGI)!=0 ? "SCGI" :
662671
g.httpUseSSL ? "TLS-encrypted HTTPS" : "HTTP", iPort);
663672
if( zBrowser ){
664673
--- src/winhttp.c
+++ src/winhttp.c
@@ -363,14 +363,14 @@
363 #endif
364 }
365 while( amt<szHdr ){
366 if( sslConn ){
367 #ifdef FOSSIL_ENABLE_SSL
368 got = ssl_read_server(sslConn, &zBuf[amt], szHdr-amt);
369 #endif
370 }else{
371 got = recv(p->s, &zBuf[amt], szHdr-amt, 0);
372 if( got==SOCKET_ERROR ) goto end_request;
373 }
374 if( got==0 ){
375 wanted = 0;
376 break;
@@ -394,11 +394,11 @@
394 if( out==0 ) goto end_request;
395 fwrite(zBuf, 1, amt, out);
396 while( wanted>0 ){
397 if( sslConn ){
398 #ifdef FOSSIL_ENABLE_SSL
399 got = ssl_read_server(sslConn, zBuf, sizeof(zBuf));
400 #endif
401 }else{
402 got = recv(p->s, zBuf, sizeof(zBuf), 0);
403 if( got==SOCKET_ERROR ) goto end_request;
404 }
@@ -437,10 +437,13 @@
437 g.httpUseSSL ? "" : " --nossl", p->zOptions
438 );
439 in = fossil_fopen(zReplyFName, "w+b");
440 fflush(out);
441 fflush(aux);
 
 
 
442 fossil_system(zCmd);
443 if( in ){
444 while( (got = fread(zBuf, 1, sizeof(zBuf), in))>0 ){
445 if( sslConn ){
446 #ifdef FOSSIL_ENABLE_SSL
@@ -465,13 +468,15 @@
465 if( shutdown(p->s,1)==0 ) shutdown(p->s,0);
466 closesocket(p->s);
467 /* Make multiple attempts to delete the temporary files. Sometimes AV
468 ** software keeps the files open for a few seconds, preventing the file
469 ** from being deleted on the first try. */
470 for(i=1; i<=10 && file_delete(zRequestFName); i++){ Sleep(1000*i); }
471 for(i=1; i<=10 && file_delete(zCmdFName); i++){ Sleep(1000*i); }
472 for(i=1; i<=10 && file_delete(zReplyFName); i++){ Sleep(1000*i); }
 
 
473 fossil_free(p);
474 }
475
476 /*
477 ** Process a single incoming SCGI request.
@@ -652,12 +657,16 @@
652 }
653 }
654 if( !GetTempPathW(MAX_PATH, zTmpPath) ){
655 fossil_panic("unable to get path to the temporary directory.");
656 }
657 zTempPrefix = mprintf("%sfossil_server_P%d",
658 fossil_unicode_to_utf8(zTmpPath), iPort);
 
 
 
 
659 fossil_print("Temporary files: %s*\n", zTempPrefix);
660 fossil_print("Listening for %s requests on TCP port %d\n",
661 (flags&HTTP_SERVER_SCGI)!=0 ? "SCGI" :
662 g.httpUseSSL ? "TLS-encrypted HTTPS" : "HTTP", iPort);
663 if( zBrowser ){
664
--- src/winhttp.c
+++ src/winhttp.c
@@ -363,14 +363,14 @@
363 #endif
364 }
365 while( amt<szHdr ){
366 if( sslConn ){
367 #ifdef FOSSIL_ENABLE_SSL
368 got = ssl_read_server(sslConn, &zBuf[amt], szHdr-1-amt, 0);
369 #endif
370 }else{
371 got = recv(p->s, &zBuf[amt], szHdr-1-amt, 0);
372 if( got==SOCKET_ERROR ) goto end_request;
373 }
374 if( got==0 ){
375 wanted = 0;
376 break;
@@ -394,11 +394,11 @@
394 if( out==0 ) goto end_request;
395 fwrite(zBuf, 1, amt, out);
396 while( wanted>0 ){
397 if( sslConn ){
398 #ifdef FOSSIL_ENABLE_SSL
399 got = ssl_read_server(sslConn, zBuf, min(wanted, sizeof(zBuf)), 1);
400 #endif
401 }else{
402 got = recv(p->s, zBuf, sizeof(zBuf), 0);
403 if( got==SOCKET_ERROR ) goto end_request;
404 }
@@ -437,10 +437,13 @@
437 g.httpUseSSL ? "" : " --nossl", p->zOptions
438 );
439 in = fossil_fopen(zReplyFName, "w+b");
440 fflush(out);
441 fflush(aux);
442 if( g.fHttpTrace ){
443 fossil_print("%s\n", zCmd);
444 }
445 fossil_system(zCmd);
446 if( in ){
447 while( (got = fread(zBuf, 1, sizeof(zBuf), in))>0 ){
448 if( sslConn ){
449 #ifdef FOSSIL_ENABLE_SSL
@@ -465,13 +468,15 @@
468 if( shutdown(p->s,1)==0 ) shutdown(p->s,0);
469 closesocket(p->s);
470 /* Make multiple attempts to delete the temporary files. Sometimes AV
471 ** software keeps the files open for a few seconds, preventing the file
472 ** from being deleted on the first try. */
473 if( !g.fHttpTrace ){
474 for(i=1; i<=10 && file_delete(zRequestFName); i++){ Sleep(1000*i); }
475 for(i=1; i<=10 && file_delete(zCmdFName); i++){ Sleep(1000*i); }
476 for(i=1; i<=10 && file_delete(zReplyFName); i++){ Sleep(1000*i); }
477 }
478 fossil_free(p);
479 }
480
481 /*
482 ** Process a single incoming SCGI request.
@@ -652,12 +657,16 @@
657 }
658 }
659 if( !GetTempPathW(MAX_PATH, zTmpPath) ){
660 fossil_panic("unable to get path to the temporary directory.");
661 }
662 if( g.fHttpTrace ){
663 zTempPrefix = mprintf("httptrace");
664 }else{
665 zTempPrefix = mprintf("%sfossil_server_P%d",
666 fossil_unicode_to_utf8(zTmpPath), iPort);
667 }
668 fossil_print("Temporary files: %s*\n", zTempPrefix);
669 fossil_print("Listening for %s requests on TCP port %d\n",
670 (flags&HTTP_SERVER_SCGI)!=0 ? "SCGI" :
671 g.httpUseSSL ? "TLS-encrypted HTTPS" : "HTTP", iPort);
672 if( zBrowser ){
673
+1 -1
--- src/zip.c
+++ src/zip.c
@@ -236,11 +236,11 @@
236236
*/
237237
void zip_set_timedate(double rDate){
238238
char *zDate = db_text(0, "SELECT datetime(%.17g)", rDate);
239239
zip_set_timedate_from_str(zDate);
240240
fossil_free(zDate);
241
- unixTime = (rDate - 2440587.5)*86400.0;
241
+ unixTime = (int)((rDate - 2440587.5)*86400.0);
242242
}
243243
244244
/*
245245
** Append a single file to a growing ZIP archive.
246246
**
247247
--- src/zip.c
+++ src/zip.c
@@ -236,11 +236,11 @@
236 */
237 void zip_set_timedate(double rDate){
238 char *zDate = db_text(0, "SELECT datetime(%.17g)", rDate);
239 zip_set_timedate_from_str(zDate);
240 fossil_free(zDate);
241 unixTime = (rDate - 2440587.5)*86400.0;
242 }
243
244 /*
245 ** Append a single file to a growing ZIP archive.
246 **
247
--- src/zip.c
+++ src/zip.c
@@ -236,11 +236,11 @@
236 */
237 void zip_set_timedate(double rDate){
238 char *zDate = db_text(0, "SELECT datetime(%.17g)", rDate);
239 zip_set_timedate_from_str(zDate);
240 fossil_free(zDate);
241 unixTime = (int)((rDate - 2440587.5)*86400.0);
242 }
243
244 /*
245 ** Append a single file to a growing ZIP archive.
246 **
247
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -1436,10 +1436,13 @@
14361436
14371437
writeln -nonewline "headers: makeheaders\$E page_index.h builtin_data.h VERSION.h\n\t +makeheaders\$E "
14381438
foreach s [lsort $src] {
14391439
writeln -nonewline "${s}_.c:$s.h "
14401440
}
1441
+foreach s [lsort $src_ext] {
1442
+ writeln -nonewline "\$(SRCDIR_extsrc)\\${s}.c:$s.h "
1443
+}
14411444
writeln "\$(SRCDIR_extsrc)\\sqlite3.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR_extsrc)\\cson_amalgamation.h"
14421445
writeln "\t@copy /Y nul: headers"
14431446
14441447
close $output_file
14451448
#
@@ -1571,11 +1574,10 @@
15711574
!if $(FOSSIL_DYNAMIC_BUILD)!=0
15721575
SSLLIBDIR = $(SSLDIR)
15731576
!else
15741577
SSLLIBDIR = $(SSLDIR)
15751578
!endif
1576
-SSLLFLAGS = /nologo /opt:ref /debug
15771579
SSLLIB = libssl.lib libcrypto.lib user32.lib gdi32.lib crypt32.lib
15781580
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
15791581
!message Using 'x64' platform for OpenSSL...
15801582
SSLCONFIG = VC-WIN64A no-asm no-ssl3 no-weak-ssl-ciphers
15811583
!if $(FOSSIL_DYNAMIC_BUILD)!=0
@@ -1628,11 +1630,11 @@
16281630
16291631
!if $(FOSSIL_ENABLE_TCL)!=0
16301632
INCL = $(INCL) /I"$(TCLINCDIR)"
16311633
!endif
16321634
1633
-CFLAGS = /nologo
1635
+CFLAGS = /nologo /W2 /WX
16341636
LDFLAGS =
16351637
16361638
CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS
16371639
CFLAGS = $(CFLAGS) /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_NONSTDC_NO_WARNINGS
16381640
@@ -1643,16 +1645,27 @@
16431645
!endif
16441646
16451647
!if $(FOSSIL_ENABLE_WINXP)!=0
16461648
XPCFLAGS = $(XPCFLAGS) /D_WIN32_WINNT=0x0501 /D_USING_V110_SDK71_=1
16471649
CFLAGS = $(CFLAGS) $(XPCFLAGS)
1650
+#
1651
+# NOTE: For regular builds, /OSVERSION defaults to the /SUBSYSTEM version and
1652
+# explicit initialization is redundant, but is required for post-built edits.
1653
+#
16481654
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1649
-XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
1655
+XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.02 /SUBSYSTEM:CONSOLE,5.02
16501656
!else
1651
-XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
1657
+XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.01 /SUBSYSTEM:CONSOLE,5.01
16521658
!endif
16531659
LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
1660
+#
1661
+# NOTE: Only XPCFLAGS is forwarded to the OpenSSL configuration, and XPLDFLAGS
1662
+# is applied in a separate post-build step, see below for more information.
1663
+#
1664
+!if $(FOSSIL_ENABLE_SSL)!=0
1665
+SSLCONFIG = $(SSLCONFIG) $(XPCFLAGS)
1666
+!endif
16541667
!endif
16551668
16561669
!if $(FOSSIL_DYNAMIC_BUILD)!=0
16571670
!if $(DEBUG)!=0
16581671
CRTFLAGS = /MDd
@@ -1759,10 +1772,15 @@
17591772
writeln " \\"
17601773
writeln -nonewline " "
17611774
}
17621775
writeln -nonewline "\"\$(OX)\\${s}_.c\""; incr i
17631776
}
1777
+foreach s [lsort $src_ext] {
1778
+ writeln " \\"
1779
+ writeln -nonewline " "
1780
+ writeln -nonewline "\"\$(SRCDIR_extsrc)\\${s}.c\""; incr i
1781
+}
17641782
writeln "\n"
17651783
writeln -nonewline "EXTRA_FILES = "
17661784
set i 0
17671785
foreach s [lsort $extra_files] {
17681786
if {$i > 0} {
@@ -1823,19 +1841,42 @@
18231841
@pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc clean && popd
18241842
18251843
!if $(FOSSIL_ENABLE_SSL)!=0
18261844
openssl:
18271845
@echo Building OpenSSL from "$(SSLDIR)"...
1846
+!if $(FOSSIL_ENABLE_WINXP)!=0
1847
+ @echo Passing XPCFLAGS = [ $(XPCFLAGS) ] to the OpenSSL configuration...
1848
+!endif
18281849
!ifdef PERLDIR
18291850
@pushd "$(SSLDIR)" && "$(PERLDIR)\$(PERL)" Configure $(SSLCONFIG) && popd
18301851
!else
18311852
@pushd "$(SSLDIR)" && "$(PERL)" Configure $(SSLCONFIG) && popd
18321853
!endif
1833
-!if $(FOSSIL_ENABLE_WINXP)!=0
1834
- @pushd "$(SSLDIR)" && $(MAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(XPLDFLAGS)" && popd
1835
-!else
18361854
@pushd "$(SSLDIR)" && $(MAKE) && popd
1855
+!if $(FOSSIL_ENABLE_WINXP)!=0 && $(FOSSIL_DYNAMIC_BUILD)!=0
1856
+#
1857
+# NOTE: Appending custom linker flags to the OpenSSL default linker flags is
1858
+# somewhat difficult, as summarized in this Fossil Forum post:
1859
+#
1860
+# https://fossil-scm.org/forum/forumpost/a9a2d6af28b
1861
+#
1862
+# Therefore the custom linker flags required for Windows XP dynamic builds are
1863
+# applied in a separate post-build step.
1864
+#
1865
+# If the build stops here, or if the custom linker flags are outside the scope
1866
+# of `editbin` or `link /EDIT` (i.e. additional libraries), consider tweaking
1867
+# the OpenSSL makefile by hand.
1868
+#
1869
+# Also note that this step changes the subsystem for the OpenSSL DLLs from
1870
+# WINDOWS to CONSOLE, but which has no effect on DLLs.
1871
+#
1872
+ @echo Applying XPLDFLAGS = [ $(XPLDFLAGS) ] to the OpenSSL DLLs...
1873
+ @for /F "usebackq delims=" %F in (`dir /A:-D/B "$(SSLDIR)\*.dll" 2^>nul`) <<<NEXT_LINE>>>
1874
+ do @( <<<NEXT_LINE>>>
1875
+ echo %F & <<<NEXT_LINE>>>
1876
+ link /EDIT /NOLOGO $(XPLDFLAGS) "$(SSLDIR)\%F" || exit 1 <<<NEXT_LINE>>>
1877
+ )
18371878
!endif
18381879
18391880
clean-openssl:
18401881
@pushd "$(SSLDIR)" && $(MAKE) clean && popd
18411882
!endif
@@ -2002,10 +2043,15 @@
20022043
writeln " \\"
20032044
writeln -nonewline "\t\t\t"
20042045
}
20052046
writeln -nonewline "\"\$(OX)\\${s}_.c\":\"\$(OX)\\$s.h\""; incr i
20062047
}
2048
+foreach s [lsort $src_ext] {
2049
+ writeln " \\"
2050
+ writeln -nonewline "\t\t\t"
2051
+ writeln -nonewline "\"\$(SRCDIR_extsrc)\\${s}.c\":\"\$(OX)\\$s.h\""; incr i
2052
+}
20072053
writeln " \\\n\t\t\t\"\$(SRCDIR_extsrc)\\sqlite3.h\" \\"
20082054
writeln "\t\t\t\"\$(SRCDIR)\\th.h\" \\"
20092055
writeln "\t\t\t\"\$(OX)\\VERSION.h\" \\"
20102056
writeln "\t\t\t\"\$(SRCDIR_extsrc)\\cson_amalgamation.h\""
20112057
writeln "\t@copy /Y nul: $@"
20122058
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -1436,10 +1436,13 @@
1436
1437 writeln -nonewline "headers: makeheaders\$E page_index.h builtin_data.h VERSION.h\n\t +makeheaders\$E "
1438 foreach s [lsort $src] {
1439 writeln -nonewline "${s}_.c:$s.h "
1440 }
 
 
 
1441 writeln "\$(SRCDIR_extsrc)\\sqlite3.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR_extsrc)\\cson_amalgamation.h"
1442 writeln "\t@copy /Y nul: headers"
1443
1444 close $output_file
1445 #
@@ -1571,11 +1574,10 @@
1571 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1572 SSLLIBDIR = $(SSLDIR)
1573 !else
1574 SSLLIBDIR = $(SSLDIR)
1575 !endif
1576 SSLLFLAGS = /nologo /opt:ref /debug
1577 SSLLIB = libssl.lib libcrypto.lib user32.lib gdi32.lib crypt32.lib
1578 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1579 !message Using 'x64' platform for OpenSSL...
1580 SSLCONFIG = VC-WIN64A no-asm no-ssl3 no-weak-ssl-ciphers
1581 !if $(FOSSIL_DYNAMIC_BUILD)!=0
@@ -1628,11 +1630,11 @@
1628
1629 !if $(FOSSIL_ENABLE_TCL)!=0
1630 INCL = $(INCL) /I"$(TCLINCDIR)"
1631 !endif
1632
1633 CFLAGS = /nologo
1634 LDFLAGS =
1635
1636 CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS
1637 CFLAGS = $(CFLAGS) /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_NONSTDC_NO_WARNINGS
1638
@@ -1643,16 +1645,27 @@
1643 !endif
1644
1645 !if $(FOSSIL_ENABLE_WINXP)!=0
1646 XPCFLAGS = $(XPCFLAGS) /D_WIN32_WINNT=0x0501 /D_USING_V110_SDK71_=1
1647 CFLAGS = $(CFLAGS) $(XPCFLAGS)
 
 
 
 
1648 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1649 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
1650 !else
1651 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
1652 !endif
1653 LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
 
 
 
 
 
 
 
1654 !endif
1655
1656 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1657 !if $(DEBUG)!=0
1658 CRTFLAGS = /MDd
@@ -1759,10 +1772,15 @@
1759 writeln " \\"
1760 writeln -nonewline " "
1761 }
1762 writeln -nonewline "\"\$(OX)\\${s}_.c\""; incr i
1763 }
 
 
 
 
 
1764 writeln "\n"
1765 writeln -nonewline "EXTRA_FILES = "
1766 set i 0
1767 foreach s [lsort $extra_files] {
1768 if {$i > 0} {
@@ -1823,19 +1841,42 @@
1823 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc clean && popd
1824
1825 !if $(FOSSIL_ENABLE_SSL)!=0
1826 openssl:
1827 @echo Building OpenSSL from "$(SSLDIR)"...
 
 
 
1828 !ifdef PERLDIR
1829 @pushd "$(SSLDIR)" && "$(PERLDIR)\$(PERL)" Configure $(SSLCONFIG) && popd
1830 !else
1831 @pushd "$(SSLDIR)" && "$(PERL)" Configure $(SSLCONFIG) && popd
1832 !endif
1833 !if $(FOSSIL_ENABLE_WINXP)!=0
1834 @pushd "$(SSLDIR)" && $(MAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(XPLDFLAGS)" && popd
1835 !else
1836 @pushd "$(SSLDIR)" && $(MAKE) && popd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1837 !endif
1838
1839 clean-openssl:
1840 @pushd "$(SSLDIR)" && $(MAKE) clean && popd
1841 !endif
@@ -2002,10 +2043,15 @@
2002 writeln " \\"
2003 writeln -nonewline "\t\t\t"
2004 }
2005 writeln -nonewline "\"\$(OX)\\${s}_.c\":\"\$(OX)\\$s.h\""; incr i
2006 }
 
 
 
 
 
2007 writeln " \\\n\t\t\t\"\$(SRCDIR_extsrc)\\sqlite3.h\" \\"
2008 writeln "\t\t\t\"\$(SRCDIR)\\th.h\" \\"
2009 writeln "\t\t\t\"\$(OX)\\VERSION.h\" \\"
2010 writeln "\t\t\t\"\$(SRCDIR_extsrc)\\cson_amalgamation.h\""
2011 writeln "\t@copy /Y nul: $@"
2012
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -1436,10 +1436,13 @@
1436
1437 writeln -nonewline "headers: makeheaders\$E page_index.h builtin_data.h VERSION.h\n\t +makeheaders\$E "
1438 foreach s [lsort $src] {
1439 writeln -nonewline "${s}_.c:$s.h "
1440 }
1441 foreach s [lsort $src_ext] {
1442 writeln -nonewline "\$(SRCDIR_extsrc)\\${s}.c:$s.h "
1443 }
1444 writeln "\$(SRCDIR_extsrc)\\sqlite3.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR_extsrc)\\cson_amalgamation.h"
1445 writeln "\t@copy /Y nul: headers"
1446
1447 close $output_file
1448 #
@@ -1571,11 +1574,10 @@
1574 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1575 SSLLIBDIR = $(SSLDIR)
1576 !else
1577 SSLLIBDIR = $(SSLDIR)
1578 !endif
 
1579 SSLLIB = libssl.lib libcrypto.lib user32.lib gdi32.lib crypt32.lib
1580 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1581 !message Using 'x64' platform for OpenSSL...
1582 SSLCONFIG = VC-WIN64A no-asm no-ssl3 no-weak-ssl-ciphers
1583 !if $(FOSSIL_DYNAMIC_BUILD)!=0
@@ -1628,11 +1630,11 @@
1630
1631 !if $(FOSSIL_ENABLE_TCL)!=0
1632 INCL = $(INCL) /I"$(TCLINCDIR)"
1633 !endif
1634
1635 CFLAGS = /nologo /W2 /WX
1636 LDFLAGS =
1637
1638 CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS
1639 CFLAGS = $(CFLAGS) /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_NONSTDC_NO_WARNINGS
1640
@@ -1643,16 +1645,27 @@
1645 !endif
1646
1647 !if $(FOSSIL_ENABLE_WINXP)!=0
1648 XPCFLAGS = $(XPCFLAGS) /D_WIN32_WINNT=0x0501 /D_USING_V110_SDK71_=1
1649 CFLAGS = $(CFLAGS) $(XPCFLAGS)
1650 #
1651 # NOTE: For regular builds, /OSVERSION defaults to the /SUBSYSTEM version and
1652 # explicit initialization is redundant, but is required for post-built edits.
1653 #
1654 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1655 XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.02 /SUBSYSTEM:CONSOLE,5.02
1656 !else
1657 XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.01 /SUBSYSTEM:CONSOLE,5.01
1658 !endif
1659 LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
1660 #
1661 # NOTE: Only XPCFLAGS is forwarded to the OpenSSL configuration, and XPLDFLAGS
1662 # is applied in a separate post-build step, see below for more information.
1663 #
1664 !if $(FOSSIL_ENABLE_SSL)!=0
1665 SSLCONFIG = $(SSLCONFIG) $(XPCFLAGS)
1666 !endif
1667 !endif
1668
1669 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1670 !if $(DEBUG)!=0
1671 CRTFLAGS = /MDd
@@ -1759,10 +1772,15 @@
1772 writeln " \\"
1773 writeln -nonewline " "
1774 }
1775 writeln -nonewline "\"\$(OX)\\${s}_.c\""; incr i
1776 }
1777 foreach s [lsort $src_ext] {
1778 writeln " \\"
1779 writeln -nonewline " "
1780 writeln -nonewline "\"\$(SRCDIR_extsrc)\\${s}.c\""; incr i
1781 }
1782 writeln "\n"
1783 writeln -nonewline "EXTRA_FILES = "
1784 set i 0
1785 foreach s [lsort $extra_files] {
1786 if {$i > 0} {
@@ -1823,19 +1841,42 @@
1841 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc clean && popd
1842
1843 !if $(FOSSIL_ENABLE_SSL)!=0
1844 openssl:
1845 @echo Building OpenSSL from "$(SSLDIR)"...
1846 !if $(FOSSIL_ENABLE_WINXP)!=0
1847 @echo Passing XPCFLAGS = [ $(XPCFLAGS) ] to the OpenSSL configuration...
1848 !endif
1849 !ifdef PERLDIR
1850 @pushd "$(SSLDIR)" && "$(PERLDIR)\$(PERL)" Configure $(SSLCONFIG) && popd
1851 !else
1852 @pushd "$(SSLDIR)" && "$(PERL)" Configure $(SSLCONFIG) && popd
1853 !endif
 
 
 
1854 @pushd "$(SSLDIR)" && $(MAKE) && popd
1855 !if $(FOSSIL_ENABLE_WINXP)!=0 && $(FOSSIL_DYNAMIC_BUILD)!=0
1856 #
1857 # NOTE: Appending custom linker flags to the OpenSSL default linker flags is
1858 # somewhat difficult, as summarized in this Fossil Forum post:
1859 #
1860 # https://fossil-scm.org/forum/forumpost/a9a2d6af28b
1861 #
1862 # Therefore the custom linker flags required for Windows XP dynamic builds are
1863 # applied in a separate post-build step.
1864 #
1865 # If the build stops here, or if the custom linker flags are outside the scope
1866 # of `editbin` or `link /EDIT` (i.e. additional libraries), consider tweaking
1867 # the OpenSSL makefile by hand.
1868 #
1869 # Also note that this step changes the subsystem for the OpenSSL DLLs from
1870 # WINDOWS to CONSOLE, but which has no effect on DLLs.
1871 #
1872 @echo Applying XPLDFLAGS = [ $(XPLDFLAGS) ] to the OpenSSL DLLs...
1873 @for /F "usebackq delims=" %F in (`dir /A:-D/B "$(SSLDIR)\*.dll" 2^>nul`) <<<NEXT_LINE>>>
1874 do @( <<<NEXT_LINE>>>
1875 echo %F & <<<NEXT_LINE>>>
1876 link /EDIT /NOLOGO $(XPLDFLAGS) "$(SSLDIR)\%F" || exit 1 <<<NEXT_LINE>>>
1877 )
1878 !endif
1879
1880 clean-openssl:
1881 @pushd "$(SSLDIR)" && $(MAKE) clean && popd
1882 !endif
@@ -2002,10 +2043,15 @@
2043 writeln " \\"
2044 writeln -nonewline "\t\t\t"
2045 }
2046 writeln -nonewline "\"\$(OX)\\${s}_.c\":\"\$(OX)\\$s.h\""; incr i
2047 }
2048 foreach s [lsort $src_ext] {
2049 writeln " \\"
2050 writeln -nonewline "\t\t\t"
2051 writeln -nonewline "\"\$(SRCDIR_extsrc)\\${s}.c\":\"\$(OX)\\$s.h\""; incr i
2052 }
2053 writeln " \\\n\t\t\t\"\$(SRCDIR_extsrc)\\sqlite3.h\" \\"
2054 writeln "\t\t\t\"\$(SRCDIR)\\th.h\" \\"
2055 writeln "\t\t\t\"\$(OX)\\VERSION.h\" \\"
2056 writeln "\t\t\t\"\$(SRCDIR_extsrc)\\cson_amalgamation.h\""
2057 writeln "\t@copy /Y nul: $@"
2058
--- tools/mkversion.c
+++ tools/mkversion.c
@@ -88,11 +88,11 @@
8888
FILE *m,*u,*v;
8989
char *z;
9090
#if defined(__DMC__) /* e.g. 0x857 */
9191
int i = 0;
9292
#endif
93
- int j = 0, x = 0, d = 0;
93
+ int j = 0, x = 0, d = 0, p = 0;
9494
size_t n;
9595
int vn[3];
9696
char b[1000];
9797
char vx[1000];
9898
if( argc!=4 ){
@@ -200,11 +200,13 @@
200200
#elif defined(__POCC__) /* e.g. 700 */
201201
d = (__POCC__ / 100); /* major */
202202
x = (__POCC__ % 100); /* minor */
203203
printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
204204
#elif defined(_MSC_VER) /* e.g. 1800 */
205
+ /* _MSC_FULL_VER also defined, e.g. 193030709 */
205206
d = (_MSC_VER / 100); /* major */
206207
x = (_MSC_VER % 100); /* minor */
207
- printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
208
+ p = (_MSC_FULL_VER % 100000); /* build (patch) */
209
+ printf("#define COMPILER_VERSION \"%d.%02d.%05d\"\n", d, x, p);
208210
#endif
209211
return 0;
210212
}
211213
--- tools/mkversion.c
+++ tools/mkversion.c
@@ -88,11 +88,11 @@
88 FILE *m,*u,*v;
89 char *z;
90 #if defined(__DMC__) /* e.g. 0x857 */
91 int i = 0;
92 #endif
93 int j = 0, x = 0, d = 0;
94 size_t n;
95 int vn[3];
96 char b[1000];
97 char vx[1000];
98 if( argc!=4 ){
@@ -200,11 +200,13 @@
200 #elif defined(__POCC__) /* e.g. 700 */
201 d = (__POCC__ / 100); /* major */
202 x = (__POCC__ % 100); /* minor */
203 printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
204 #elif defined(_MSC_VER) /* e.g. 1800 */
 
205 d = (_MSC_VER / 100); /* major */
206 x = (_MSC_VER % 100); /* minor */
207 printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
 
208 #endif
209 return 0;
210 }
211
--- tools/mkversion.c
+++ tools/mkversion.c
@@ -88,11 +88,11 @@
88 FILE *m,*u,*v;
89 char *z;
90 #if defined(__DMC__) /* e.g. 0x857 */
91 int i = 0;
92 #endif
93 int j = 0, x = 0, d = 0, p = 0;
94 size_t n;
95 int vn[3];
96 char b[1000];
97 char vx[1000];
98 if( argc!=4 ){
@@ -200,11 +200,13 @@
200 #elif defined(__POCC__) /* e.g. 700 */
201 d = (__POCC__ / 100); /* major */
202 x = (__POCC__ % 100); /* minor */
203 printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
204 #elif defined(_MSC_VER) /* e.g. 1800 */
205 /* _MSC_FULL_VER also defined, e.g. 193030709 */
206 d = (_MSC_VER / 100); /* major */
207 x = (_MSC_VER % 100); /* minor */
208 p = (_MSC_FULL_VER % 100000); /* build (patch) */
209 printf("#define COMPILER_VERSION \"%d.%02d.%05d\"\n", d, x, p);
210 #endif
211 return 0;
212 }
213
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -1007,7 +1007,7 @@
10071007
10081008
zip_.c : $(SRCDIR)\zip.c
10091009
+translate$E $** > $@
10101010
10111011
headers: makeheaders$E page_index.h builtin_data.h VERSION.h
1012
- +makeheaders$E add_.c:add.h ajax_.c:ajax.h alerts_.c:alerts.h allrepo_.c:allrepo.h attach_.c:attach.h backlink_.c:backlink.h backoffice_.c:backoffice.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h capabilities_.c:capabilities.h captcha_.c:captcha.h cgi_.c:cgi.h chat_.c:chat.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h color_.c:color.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h cookies_.c:cookies.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h deltafunc_.c:deltafunc.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h dispatch_.c:dispatch.h doc_.c:doc.h encode_.c:encode.h etag_.c:etag.h event_.c:event.h export_.c:export.h extcgi_.c:extcgi.h file_.c:file.h fileedit_.c:fileedit.h finfo_.c:finfo.h foci_.c:foci.h forum_.c:forum.h fshell_.c:fshell.h fusefs_.c:fusefs.h fuzz_.c:fuzz.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h hname_.c:hname.h hook_.c:hook.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h interwiki_.c:interwiki.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h patch_.c:patch.h path_.c:path.h piechart_.c:piechart.h pikchrshow_.c:pikchrshow.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h repolist_.c:repolist.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h security_audit_.c:security_audit.h setup_.c:setup.h setupuser_.c:setupuser.h sha1_.c:sha1.h sha1hard_.c:sha1hard.h sha3_.c:sha3.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h smtp_.c:smtp.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h terminal_.c:terminal.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h unversioned_.c:unversioned.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR_extsrc)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR_extsrc)\cson_amalgamation.h
1012
+ +makeheaders$E add_.c:add.h ajax_.c:ajax.h alerts_.c:alerts.h allrepo_.c:allrepo.h attach_.c:attach.h backlink_.c:backlink.h backoffice_.c:backoffice.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h capabilities_.c:capabilities.h captcha_.c:captcha.h cgi_.c:cgi.h chat_.c:chat.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h color_.c:color.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h cookies_.c:cookies.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h deltafunc_.c:deltafunc.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h dispatch_.c:dispatch.h doc_.c:doc.h encode_.c:encode.h etag_.c:etag.h event_.c:event.h export_.c:export.h extcgi_.c:extcgi.h file_.c:file.h fileedit_.c:fileedit.h finfo_.c:finfo.h foci_.c:foci.h forum_.c:forum.h fshell_.c:fshell.h fusefs_.c:fusefs.h fuzz_.c:fuzz.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h hname_.c:hname.h hook_.c:hook.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h interwiki_.c:interwiki.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h patch_.c:patch.h path_.c:path.h piechart_.c:piechart.h pikchrshow_.c:pikchrshow.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h repolist_.c:repolist.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h security_audit_.c:security_audit.h setup_.c:setup.h setupuser_.c:setupuser.h sha1_.c:sha1.h sha1hard_.c:sha1hard.h sha3_.c:sha3.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h smtp_.c:smtp.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h terminal_.c:terminal.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h unversioned_.c:unversioned.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR_extsrc)\pikchr.c:pikchr.h $(SRCDIR_extsrc)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR_extsrc)\cson_amalgamation.h
10131013
@copy /Y nul: headers
10141014
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -1007,7 +1007,7 @@
1007
1008 zip_.c : $(SRCDIR)\zip.c
1009 +translate$E $** > $@
1010
1011 headers: makeheaders$E page_index.h builtin_data.h VERSION.h
1012 +makeheaders$E add_.c:add.h ajax_.c:ajax.h alerts_.c:alerts.h allrepo_.c:allrepo.h attach_.c:attach.h backlink_.c:backlink.h backoffice_.c:backoffice.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h capabilities_.c:capabilities.h captcha_.c:captcha.h cgi_.c:cgi.h chat_.c:chat.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h color_.c:color.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h cookies_.c:cookies.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h deltafunc_.c:deltafunc.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h dispatch_.c:dispatch.h doc_.c:doc.h encode_.c:encode.h etag_.c:etag.h event_.c:event.h export_.c:export.h extcgi_.c:extcgi.h file_.c:file.h fileedit_.c:fileedit.h finfo_.c:finfo.h foci_.c:foci.h forum_.c:forum.h fshell_.c:fshell.h fusefs_.c:fusefs.h fuzz_.c:fuzz.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h hname_.c:hname.h hook_.c:hook.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h interwiki_.c:interwiki.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h patch_.c:patch.h path_.c:path.h piechart_.c:piechart.h pikchrshow_.c:pikchrshow.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h repolist_.c:repolist.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h security_audit_.c:security_audit.h setup_.c:setup.h setupuser_.c:setupuser.h sha1_.c:sha1.h sha1hard_.c:sha1hard.h sha3_.c:sha3.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h smtp_.c:smtp.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h terminal_.c:terminal.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h unversioned_.c:unversioned.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR_extsrc)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR_extsrc)\cson_amalgamation.h
1013 @copy /Y nul: headers
1014
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -1007,7 +1007,7 @@
1007
1008 zip_.c : $(SRCDIR)\zip.c
1009 +translate$E $** > $@
1010
1011 headers: makeheaders$E page_index.h builtin_data.h VERSION.h
1012 +makeheaders$E add_.c:add.h ajax_.c:ajax.h alerts_.c:alerts.h allrepo_.c:allrepo.h attach_.c:attach.h backlink_.c:backlink.h backoffice_.c:backoffice.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h capabilities_.c:capabilities.h captcha_.c:captcha.h cgi_.c:cgi.h chat_.c:chat.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h color_.c:color.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h cookies_.c:cookies.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h deltafunc_.c:deltafunc.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h dispatch_.c:dispatch.h doc_.c:doc.h encode_.c:encode.h etag_.c:etag.h event_.c:event.h export_.c:export.h extcgi_.c:extcgi.h file_.c:file.h fileedit_.c:fileedit.h finfo_.c:finfo.h foci_.c:foci.h forum_.c:forum.h fshell_.c:fshell.h fusefs_.c:fusefs.h fuzz_.c:fuzz.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h hname_.c:hname.h hook_.c:hook.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h interwiki_.c:interwiki.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h patch_.c:patch.h path_.c:path.h piechart_.c:piechart.h pikchrshow_.c:pikchrshow.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h repolist_.c:repolist.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h security_audit_.c:security_audit.h setup_.c:setup.h setupuser_.c:setupuser.h sha1_.c:sha1.h sha1hard_.c:sha1hard.h sha3_.c:sha3.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h smtp_.c:smtp.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h terminal_.c:terminal.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h unversioned_.c:unversioned.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR_extsrc)\pikchr.c:pikchr.h $(SRCDIR_extsrc)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR_extsrc)\cson_amalgamation.h
1013 @copy /Y nul: headers
1014
+43 -8
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -116,11 +116,10 @@
116116
!if $(FOSSIL_DYNAMIC_BUILD)!=0
117117
SSLLIBDIR = $(SSLDIR)
118118
!else
119119
SSLLIBDIR = $(SSLDIR)
120120
!endif
121
-SSLLFLAGS = /nologo /opt:ref /debug
122121
SSLLIB = libssl.lib libcrypto.lib user32.lib gdi32.lib crypt32.lib
123122
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
124123
!message Using 'x64' platform for OpenSSL...
125124
SSLCONFIG = VC-WIN64A no-asm no-ssl3 no-weak-ssl-ciphers
126125
!if $(FOSSIL_DYNAMIC_BUILD)!=0
@@ -173,11 +172,11 @@
173172
174173
!if $(FOSSIL_ENABLE_TCL)!=0
175174
INCL = $(INCL) /I"$(TCLINCDIR)"
176175
!endif
177176
178
-CFLAGS = /nologo
177
+CFLAGS = /nologo /W2 /WX
179178
LDFLAGS =
180179
181180
CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS
182181
CFLAGS = $(CFLAGS) /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_NONSTDC_NO_WARNINGS
183182
@@ -188,16 +187,27 @@
188187
!endif
189188
190189
!if $(FOSSIL_ENABLE_WINXP)!=0
191190
XPCFLAGS = $(XPCFLAGS) /D_WIN32_WINNT=0x0501 /D_USING_V110_SDK71_=1
192191
CFLAGS = $(CFLAGS) $(XPCFLAGS)
192
+#
193
+# NOTE: For regular builds, /OSVERSION defaults to the /SUBSYSTEM version and
194
+# explicit initialization is redundant, but is required for post-built edits.
195
+#
193196
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
194
-XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
197
+XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.02 /SUBSYSTEM:CONSOLE,5.02
195198
!else
196
-XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
199
+XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.01 /SUBSYSTEM:CONSOLE,5.01
197200
!endif
198201
LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
202
+#
203
+# NOTE: Only XPCFLAGS is forwarded to the OpenSSL configuration, and XPLDFLAGS
204
+# is applied in a separate post-build step, see below for more information.
205
+#
206
+!if $(FOSSIL_ENABLE_SSL)!=0
207
+SSLCONFIG = $(SSLCONFIG) $(XPCFLAGS)
208
+!endif
199209
!endif
200210
201211
!if $(FOSSIL_DYNAMIC_BUILD)!=0
202212
!if $(DEBUG)!=0
203213
CRTFLAGS = /MDd
@@ -490,11 +500,12 @@
490500
"$(OX)\wikiformat_.c" \
491501
"$(OX)\winfile_.c" \
492502
"$(OX)\winhttp_.c" \
493503
"$(OX)\xfer_.c" \
494504
"$(OX)\xfersetup_.c" \
495
- "$(OX)\zip_.c"
505
+ "$(OX)\zip_.c" \
506
+ "$(SRCDIR_extsrc)\pikchr.c"
496507
497508
EXTRA_FILES = "$(SRCDIR)\..\skins\ardoise\css.txt" \
498509
"$(SRCDIR)\..\skins\ardoise\details.txt" \
499510
"$(SRCDIR)\..\skins\ardoise\footer.txt" \
500511
"$(SRCDIR)\..\skins\ardoise\header.txt" \
@@ -794,19 +805,42 @@
794805
@pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc clean && popd
795806
796807
!if $(FOSSIL_ENABLE_SSL)!=0
797808
openssl:
798809
@echo Building OpenSSL from "$(SSLDIR)"...
810
+!if $(FOSSIL_ENABLE_WINXP)!=0
811
+ @echo Passing XPCFLAGS = [ $(XPCFLAGS) ] to the OpenSSL configuration...
812
+!endif
799813
!ifdef PERLDIR
800814
@pushd "$(SSLDIR)" && "$(PERLDIR)\$(PERL)" Configure $(SSLCONFIG) && popd
801815
!else
802816
@pushd "$(SSLDIR)" && "$(PERL)" Configure $(SSLCONFIG) && popd
803817
!endif
804
-!if $(FOSSIL_ENABLE_WINXP)!=0
805
- @pushd "$(SSLDIR)" && $(MAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(XPLDFLAGS)" && popd
806
-!else
807818
@pushd "$(SSLDIR)" && $(MAKE) && popd
819
+!if $(FOSSIL_ENABLE_WINXP)!=0 && $(FOSSIL_DYNAMIC_BUILD)!=0
820
+#
821
+# NOTE: Appending custom linker flags to the OpenSSL default linker flags is
822
+# somewhat difficult, as summarized in this Fossil Forum post:
823
+#
824
+# https://fossil-scm.org/forum/forumpost/a9a2d6af28b
825
+#
826
+# Therefore the custom linker flags required for Windows XP dynamic builds are
827
+# applied in a separate post-build step.
828
+#
829
+# If the build stops here, or if the custom linker flags are outside the scope
830
+# of `editbin` or `link /EDIT` (i.e. additional libraries), consider tweaking
831
+# the OpenSSL makefile by hand.
832
+#
833
+# Also note that this step changes the subsystem for the OpenSSL DLLs from
834
+# WINDOWS to CONSOLE, but which has no effect on DLLs.
835
+#
836
+ @echo Applying XPLDFLAGS = [ $(XPLDFLAGS) ] to the OpenSSL DLLs...
837
+ @for /F "usebackq delims=" %F in (`dir /A:-D/B "$(SSLDIR)\*.dll" 2^>nul`) \
838
+ do @( \
839
+ echo %F & \
840
+ link /EDIT /NOLOGO $(XPLDFLAGS) "$(SSLDIR)\%F" || exit 1 \
841
+ )
808842
!endif
809843
810844
clean-openssl:
811845
@pushd "$(SSLDIR)" && $(MAKE) clean && popd
812846
!endif
@@ -2234,10 +2268,11 @@
22342268
"$(OX)\winfile_.c":"$(OX)\winfile.h" \
22352269
"$(OX)\winhttp_.c":"$(OX)\winhttp.h" \
22362270
"$(OX)\xfer_.c":"$(OX)\xfer.h" \
22372271
"$(OX)\xfersetup_.c":"$(OX)\xfersetup.h" \
22382272
"$(OX)\zip_.c":"$(OX)\zip.h" \
2273
+ "$(SRCDIR_extsrc)\pikchr.c":"$(OX)\pikchr.h" \
22392274
"$(SRCDIR_extsrc)\sqlite3.h" \
22402275
"$(SRCDIR)\th.h" \
22412276
"$(OX)\VERSION.h" \
22422277
"$(SRCDIR_extsrc)\cson_amalgamation.h"
22432278
@copy /Y nul: $@
22442279
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -116,11 +116,10 @@
116 !if $(FOSSIL_DYNAMIC_BUILD)!=0
117 SSLLIBDIR = $(SSLDIR)
118 !else
119 SSLLIBDIR = $(SSLDIR)
120 !endif
121 SSLLFLAGS = /nologo /opt:ref /debug
122 SSLLIB = libssl.lib libcrypto.lib user32.lib gdi32.lib crypt32.lib
123 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
124 !message Using 'x64' platform for OpenSSL...
125 SSLCONFIG = VC-WIN64A no-asm no-ssl3 no-weak-ssl-ciphers
126 !if $(FOSSIL_DYNAMIC_BUILD)!=0
@@ -173,11 +172,11 @@
173
174 !if $(FOSSIL_ENABLE_TCL)!=0
175 INCL = $(INCL) /I"$(TCLINCDIR)"
176 !endif
177
178 CFLAGS = /nologo
179 LDFLAGS =
180
181 CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS
182 CFLAGS = $(CFLAGS) /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_NONSTDC_NO_WARNINGS
183
@@ -188,16 +187,27 @@
188 !endif
189
190 !if $(FOSSIL_ENABLE_WINXP)!=0
191 XPCFLAGS = $(XPCFLAGS) /D_WIN32_WINNT=0x0501 /D_USING_V110_SDK71_=1
192 CFLAGS = $(CFLAGS) $(XPCFLAGS)
 
 
 
 
193 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
194 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
195 !else
196 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
197 !endif
198 LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
 
 
 
 
 
 
 
199 !endif
200
201 !if $(FOSSIL_DYNAMIC_BUILD)!=0
202 !if $(DEBUG)!=0
203 CRTFLAGS = /MDd
@@ -490,11 +500,12 @@
490 "$(OX)\wikiformat_.c" \
491 "$(OX)\winfile_.c" \
492 "$(OX)\winhttp_.c" \
493 "$(OX)\xfer_.c" \
494 "$(OX)\xfersetup_.c" \
495 "$(OX)\zip_.c"
 
496
497 EXTRA_FILES = "$(SRCDIR)\..\skins\ardoise\css.txt" \
498 "$(SRCDIR)\..\skins\ardoise\details.txt" \
499 "$(SRCDIR)\..\skins\ardoise\footer.txt" \
500 "$(SRCDIR)\..\skins\ardoise\header.txt" \
@@ -794,19 +805,42 @@
794 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc clean && popd
795
796 !if $(FOSSIL_ENABLE_SSL)!=0
797 openssl:
798 @echo Building OpenSSL from "$(SSLDIR)"...
 
 
 
799 !ifdef PERLDIR
800 @pushd "$(SSLDIR)" && "$(PERLDIR)\$(PERL)" Configure $(SSLCONFIG) && popd
801 !else
802 @pushd "$(SSLDIR)" && "$(PERL)" Configure $(SSLCONFIG) && popd
803 !endif
804 !if $(FOSSIL_ENABLE_WINXP)!=0
805 @pushd "$(SSLDIR)" && $(MAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(XPLDFLAGS)" && popd
806 !else
807 @pushd "$(SSLDIR)" && $(MAKE) && popd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
808 !endif
809
810 clean-openssl:
811 @pushd "$(SSLDIR)" && $(MAKE) clean && popd
812 !endif
@@ -2234,10 +2268,11 @@
2234 "$(OX)\winfile_.c":"$(OX)\winfile.h" \
2235 "$(OX)\winhttp_.c":"$(OX)\winhttp.h" \
2236 "$(OX)\xfer_.c":"$(OX)\xfer.h" \
2237 "$(OX)\xfersetup_.c":"$(OX)\xfersetup.h" \
2238 "$(OX)\zip_.c":"$(OX)\zip.h" \
 
2239 "$(SRCDIR_extsrc)\sqlite3.h" \
2240 "$(SRCDIR)\th.h" \
2241 "$(OX)\VERSION.h" \
2242 "$(SRCDIR_extsrc)\cson_amalgamation.h"
2243 @copy /Y nul: $@
2244
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -116,11 +116,10 @@
116 !if $(FOSSIL_DYNAMIC_BUILD)!=0
117 SSLLIBDIR = $(SSLDIR)
118 !else
119 SSLLIBDIR = $(SSLDIR)
120 !endif
 
121 SSLLIB = libssl.lib libcrypto.lib user32.lib gdi32.lib crypt32.lib
122 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
123 !message Using 'x64' platform for OpenSSL...
124 SSLCONFIG = VC-WIN64A no-asm no-ssl3 no-weak-ssl-ciphers
125 !if $(FOSSIL_DYNAMIC_BUILD)!=0
@@ -173,11 +172,11 @@
172
173 !if $(FOSSIL_ENABLE_TCL)!=0
174 INCL = $(INCL) /I"$(TCLINCDIR)"
175 !endif
176
177 CFLAGS = /nologo /W2 /WX
178 LDFLAGS =
179
180 CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS
181 CFLAGS = $(CFLAGS) /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_NONSTDC_NO_WARNINGS
182
@@ -188,16 +187,27 @@
187 !endif
188
189 !if $(FOSSIL_ENABLE_WINXP)!=0
190 XPCFLAGS = $(XPCFLAGS) /D_WIN32_WINNT=0x0501 /D_USING_V110_SDK71_=1
191 CFLAGS = $(CFLAGS) $(XPCFLAGS)
192 #
193 # NOTE: For regular builds, /OSVERSION defaults to the /SUBSYSTEM version and
194 # explicit initialization is redundant, but is required for post-built edits.
195 #
196 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
197 XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.02 /SUBSYSTEM:CONSOLE,5.02
198 !else
199 XPLDFLAGS = $(XPLDFLAGS) /OSVERSION:5.01 /SUBSYSTEM:CONSOLE,5.01
200 !endif
201 LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
202 #
203 # NOTE: Only XPCFLAGS is forwarded to the OpenSSL configuration, and XPLDFLAGS
204 # is applied in a separate post-build step, see below for more information.
205 #
206 !if $(FOSSIL_ENABLE_SSL)!=0
207 SSLCONFIG = $(SSLCONFIG) $(XPCFLAGS)
208 !endif
209 !endif
210
211 !if $(FOSSIL_DYNAMIC_BUILD)!=0
212 !if $(DEBUG)!=0
213 CRTFLAGS = /MDd
@@ -490,11 +500,12 @@
500 "$(OX)\wikiformat_.c" \
501 "$(OX)\winfile_.c" \
502 "$(OX)\winhttp_.c" \
503 "$(OX)\xfer_.c" \
504 "$(OX)\xfersetup_.c" \
505 "$(OX)\zip_.c" \
506 "$(SRCDIR_extsrc)\pikchr.c"
507
508 EXTRA_FILES = "$(SRCDIR)\..\skins\ardoise\css.txt" \
509 "$(SRCDIR)\..\skins\ardoise\details.txt" \
510 "$(SRCDIR)\..\skins\ardoise\footer.txt" \
511 "$(SRCDIR)\..\skins\ardoise\header.txt" \
@@ -794,19 +805,42 @@
805 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc clean && popd
806
807 !if $(FOSSIL_ENABLE_SSL)!=0
808 openssl:
809 @echo Building OpenSSL from "$(SSLDIR)"...
810 !if $(FOSSIL_ENABLE_WINXP)!=0
811 @echo Passing XPCFLAGS = [ $(XPCFLAGS) ] to the OpenSSL configuration...
812 !endif
813 !ifdef PERLDIR
814 @pushd "$(SSLDIR)" && "$(PERLDIR)\$(PERL)" Configure $(SSLCONFIG) && popd
815 !else
816 @pushd "$(SSLDIR)" && "$(PERL)" Configure $(SSLCONFIG) && popd
817 !endif
 
 
 
818 @pushd "$(SSLDIR)" && $(MAKE) && popd
819 !if $(FOSSIL_ENABLE_WINXP)!=0 && $(FOSSIL_DYNAMIC_BUILD)!=0
820 #
821 # NOTE: Appending custom linker flags to the OpenSSL default linker flags is
822 # somewhat difficult, as summarized in this Fossil Forum post:
823 #
824 # https://fossil-scm.org/forum/forumpost/a9a2d6af28b
825 #
826 # Therefore the custom linker flags required for Windows XP dynamic builds are
827 # applied in a separate post-build step.
828 #
829 # If the build stops here, or if the custom linker flags are outside the scope
830 # of `editbin` or `link /EDIT` (i.e. additional libraries), consider tweaking
831 # the OpenSSL makefile by hand.
832 #
833 # Also note that this step changes the subsystem for the OpenSSL DLLs from
834 # WINDOWS to CONSOLE, but which has no effect on DLLs.
835 #
836 @echo Applying XPLDFLAGS = [ $(XPLDFLAGS) ] to the OpenSSL DLLs...
837 @for /F "usebackq delims=" %F in (`dir /A:-D/B "$(SSLDIR)\*.dll" 2^>nul`) \
838 do @( \
839 echo %F & \
840 link /EDIT /NOLOGO $(XPLDFLAGS) "$(SSLDIR)\%F" || exit 1 \
841 )
842 !endif
843
844 clean-openssl:
845 @pushd "$(SSLDIR)" && $(MAKE) clean && popd
846 !endif
@@ -2234,10 +2268,11 @@
2268 "$(OX)\winfile_.c":"$(OX)\winfile.h" \
2269 "$(OX)\winhttp_.c":"$(OX)\winhttp.h" \
2270 "$(OX)\xfer_.c":"$(OX)\xfer.h" \
2271 "$(OX)\xfersetup_.c":"$(OX)\xfersetup.h" \
2272 "$(OX)\zip_.c":"$(OX)\zip.h" \
2273 "$(SRCDIR_extsrc)\pikchr.c":"$(OX)\pikchr.h" \
2274 "$(SRCDIR_extsrc)\sqlite3.h" \
2275 "$(SRCDIR)\th.h" \
2276 "$(OX)\VERSION.h" \
2277 "$(SRCDIR_extsrc)\cson_amalgamation.h"
2278 @copy /Y nul: $@
2279
--- www/changes.wiki
+++ www/changes.wiki
@@ -25,10 +25,14 @@
2525
* Add options --project-name and --project-desc to the
2626
"[/help?cmd=init|fossil init]" command.
2727
* Query parameter "year=YYYY" is now accepted by [/help?cmd=/timeline|/timeline].
2828
* Add the "--as FILENAME" option to the "[/help?cmd=chat|fossil chat send]"
2929
command.
30
+ * The [/help?cmd=/ext|/ext page] generates the SERVER_SOFTWARE environment
31
+ variable for clients.
32
+ * The [/help?cmd=tar|tar] and [/help?cmd=zip|zip commands] no longer
33
+ sterilize the manifest file.
3034
3135
<h2 id='v2_17'>Changes for version 2.17 (2021-10-09)</h2>
3236
3337
* Major improvements to the "diff" subsystem, including: <ul>
3438
<li> Added new [/help?cmd=diff|formatting options]: --by, -b, --webpage, --json, --tcl.
3539
--- www/changes.wiki
+++ www/changes.wiki
@@ -25,10 +25,14 @@
25 * Add options --project-name and --project-desc to the
26 "[/help?cmd=init|fossil init]" command.
27 * Query parameter "year=YYYY" is now accepted by [/help?cmd=/timeline|/timeline].
28 * Add the "--as FILENAME" option to the "[/help?cmd=chat|fossil chat send]"
29 command.
 
 
 
 
30
31 <h2 id='v2_17'>Changes for version 2.17 (2021-10-09)</h2>
32
33 * Major improvements to the "diff" subsystem, including: <ul>
34 <li> Added new [/help?cmd=diff|formatting options]: --by, -b, --webpage, --json, --tcl.
35
--- www/changes.wiki
+++ www/changes.wiki
@@ -25,10 +25,14 @@
25 * Add options --project-name and --project-desc to the
26 "[/help?cmd=init|fossil init]" command.
27 * Query parameter "year=YYYY" is now accepted by [/help?cmd=/timeline|/timeline].
28 * Add the "--as FILENAME" option to the "[/help?cmd=chat|fossil chat send]"
29 command.
30 * The [/help?cmd=/ext|/ext page] generates the SERVER_SOFTWARE environment
31 variable for clients.
32 * The [/help?cmd=tar|tar] and [/help?cmd=zip|zip commands] no longer
33 sterilize the manifest file.
34
35 <h2 id='v2_17'>Changes for version 2.17 (2021-10-09)</h2>
36
37 * Major improvements to the "diff" subsystem, including: <ul>
38 <li> Added new [/help?cmd=diff|formatting options]: --by, -b, --webpage, --json, --tcl.
39
+1 -1
--- www/defcsp.md
+++ www/defcsp.md
@@ -30,11 +30,11 @@
3030
style-src 'self' 'unsafe-inline';
3131
img-src * data:;
3232
</pre>
3333
3434
The default is recommended for most installations. However,
35
-the site administrators can overwrite this default DSP using the
35
+the site administrators can overwrite this default CSP using the
3636
[default-csp setting](/help?cmd=default-csp). For example,
3737
CSP restrictions can be completely disabled by setting the default-csp to:
3838
3939
<pre>
4040
default-src *;
4141
--- www/defcsp.md
+++ www/defcsp.md
@@ -30,11 +30,11 @@
30 style-src 'self' 'unsafe-inline';
31 img-src * data:;
32 </pre>
33
34 The default is recommended for most installations. However,
35 the site administrators can overwrite this default DSP using the
36 [default-csp setting](/help?cmd=default-csp). For example,
37 CSP restrictions can be completely disabled by setting the default-csp to:
38
39 <pre>
40 default-src *;
41
--- www/defcsp.md
+++ www/defcsp.md
@@ -30,11 +30,11 @@
30 style-src 'self' 'unsafe-inline';
31 img-src * data:;
32 </pre>
33
34 The default is recommended for most installations. However,
35 the site administrators can overwrite this default CSP using the
36 [default-csp setting](/help?cmd=default-csp). For example,
37 CSP restrictions can be completely disabled by setting the default-csp to:
38
39 <pre>
40 default-src *;
41
+2 -6
--- www/env-opts.md
+++ www/env-opts.md
@@ -26,10 +26,12 @@
2626
file names: insensitive on Windows, sensitive on Unix. There are
2727
probably odd interactions possible if you mix case sensitive and case
2828
insensitive file systems on any single platform. This option or the
2929
global setting should be used to force the case sensitivity to the
3030
most sensible condition.
31
+
32
+`--cgitrace`: Active CGI tracing.
3133
3234
`--chdir DIRECTORY`: Change to the named directory before processing
3335
any commands.
3436
3537
@@ -311,16 +313,10 @@
311313
See the comment above the implementation of [`json_getenv`][json.c]
312314
for some further discussion.
313315
314316
[json.c]: /artifact/6df1d80dece8968b?ln=277,290
315317
316
-### CGI Server Extensions
317
-
318
-The [CGI Server Extensions](/doc/trunk/www/serverext.wiki) feature passes
319
-parameters to the CGI program using environment variables, as listed in
320
-the [CGI Inputs](/doc/trunk/www/serverext.wiki#cgi-inputs) section.
321
-
322318
### Comment Editor
323319
324320
The editor used to edit a check-in or stash comment is named by the
325321
local or global setting `editor`. If neither is set, then the environment
326322
variables `VISUAL`, and `EDITOR` are checked in that order.
327323
--- www/env-opts.md
+++ www/env-opts.md
@@ -26,10 +26,12 @@
26 file names: insensitive on Windows, sensitive on Unix. There are
27 probably odd interactions possible if you mix case sensitive and case
28 insensitive file systems on any single platform. This option or the
29 global setting should be used to force the case sensitivity to the
30 most sensible condition.
 
 
31
32 `--chdir DIRECTORY`: Change to the named directory before processing
33 any commands.
34
35
@@ -311,16 +313,10 @@
311 See the comment above the implementation of [`json_getenv`][json.c]
312 for some further discussion.
313
314 [json.c]: /artifact/6df1d80dece8968b?ln=277,290
315
316 ### CGI Server Extensions
317
318 The [CGI Server Extensions](/doc/trunk/www/serverext.wiki) feature passes
319 parameters to the CGI program using environment variables, as listed in
320 the [CGI Inputs](/doc/trunk/www/serverext.wiki#cgi-inputs) section.
321
322 ### Comment Editor
323
324 The editor used to edit a check-in or stash comment is named by the
325 local or global setting `editor`. If neither is set, then the environment
326 variables `VISUAL`, and `EDITOR` are checked in that order.
327
--- www/env-opts.md
+++ www/env-opts.md
@@ -26,10 +26,12 @@
26 file names: insensitive on Windows, sensitive on Unix. There are
27 probably odd interactions possible if you mix case sensitive and case
28 insensitive file systems on any single platform. This option or the
29 global setting should be used to force the case sensitivity to the
30 most sensible condition.
31
32 `--cgitrace`: Active CGI tracing.
33
34 `--chdir DIRECTORY`: Change to the named directory before processing
35 any commands.
36
37
@@ -311,16 +313,10 @@
313 See the comment above the implementation of [`json_getenv`][json.c]
314 for some further discussion.
315
316 [json.c]: /artifact/6df1d80dece8968b?ln=277,290
317
 
 
 
 
 
 
318 ### Comment Editor
319
320 The editor used to edit a check-in or stash comment is named by the
321 local or global setting `editor`. If neither is set, then the environment
322 variables `VISUAL`, and `EDITOR` are checked in that order.
323
--- www/json-api/api-wiki.md
+++ www/json-api/api-wiki.md
@@ -166,10 +166,13 @@
166166
- `name=string` specifies the page name.
167167
- `content=string` is the body text.\
168168
Content is required for save (unless `createIfNotExists` is true *and*
169169
the page does not exist), optional for create. It *may* be an empty
170170
string.
171
+- `mimetype=string` specifies the mimetype for the body, noting any any
172
+ unrecognized/unsupported mimetype is silently treated as
173
+ `text/x-fossil-wiki`.
171174
- Save (not create) supports a `createIfNotExists` boolean option which
172175
makes it a functional superset of the create/save features. i.e. it
173176
will create if needed, else it will update. If createIfNotExists is
174177
false (the default) then save will fail if given a page name which
175178
does not refer to an existing page.
@@ -179,10 +182,11 @@
179182
high-priority addition. See:\
180183
[](/doc/trunk/www/fileformat.wiki#wikichng)
181184
- **Potential TODO:** we *could* optionally also support
182185
multi-page saving using an array of pages in the request payload:\
183186
`[… page objects … ]`
187
+
184188
185189
186190
<a id="diffs"></a>
187191
# Wiki Diffs
188192
@@ -238,28 +242,29 @@
238242
239243
This command wiki-processes arbitrary text sent from the client. To help
240244
curb potential abuse, its use is restricted to those with "k" access
241245
rights.
242246
243
-The `POST.payload` property must be a string containing Fossil wiki
244
-markup. The response payload is also a string, but contains the
245
-HTML-processed form of the string. Whether or not "all HTML" is allowed
246
-depends on site-level configuration options, and that changes how the
247
-input is processed.
247
+The `POST.payload` property must be either:
248
+
249
+1) A string containing Fossil wiki markup.
250
+
251
+2) An Object with a `body` property holding the text to render and a
252
+ `mimetype` property describing the wiki format:
253
+ `text/x-fossil-wiki` (the default), `text/x-markdown`, or
254
+ `text/plain`. Any unknown type is treated as `text/x-fossil-wiki`.
255
+
256
+The response payload is a string containing the rendered page. Whether
257
+or not "all HTML" is allowed depends on site-level configuration
258
+options, and that changes how the input is processed.
248259
249260
Note that the links in the generated page are for the HTML interface,
250261
and will not work as-is for arbitrary JSON clients. In order to
251262
integrate the parsed content with JSON-based clients the HTML will
252263
probably need to be post-processed, e.g. using jQuery to fish out the
253264
links and re-map wiki page links to a JSON-capable page handler.
254265
255
-**TODO**: Update this to accept the other two wiki formats (which
256
-didn't exist when this API was implemented): markdown and plain text
257
-(which gets HTML-ized for preview purposes). That requires changing
258
-the payload to an object, perhaps simply submitting the same thing as
259
-`/json/save`. There's no reason we can't support both call forms.
260
-
261266
262267
<a id="todo"></a>
263268
# Notes and TODOs
264269
265270
- When server-parsing the wiki content, the generated
266271
--- www/json-api/api-wiki.md
+++ www/json-api/api-wiki.md
@@ -166,10 +166,13 @@
166 - `name=string` specifies the page name.
167 - `content=string` is the body text.\
168 Content is required for save (unless `createIfNotExists` is true *and*
169 the page does not exist), optional for create. It *may* be an empty
170 string.
 
 
 
171 - Save (not create) supports a `createIfNotExists` boolean option which
172 makes it a functional superset of the create/save features. i.e. it
173 will create if needed, else it will update. If createIfNotExists is
174 false (the default) then save will fail if given a page name which
175 does not refer to an existing page.
@@ -179,10 +182,11 @@
179 high-priority addition. See:\
180 [](/doc/trunk/www/fileformat.wiki#wikichng)
181 - **Potential TODO:** we *could* optionally also support
182 multi-page saving using an array of pages in the request payload:\
183 `[… page objects … ]`
 
184
185
186 <a id="diffs"></a>
187 # Wiki Diffs
188
@@ -238,28 +242,29 @@
238
239 This command wiki-processes arbitrary text sent from the client. To help
240 curb potential abuse, its use is restricted to those with "k" access
241 rights.
242
243 The `POST.payload` property must be a string containing Fossil wiki
244 markup. The response payload is also a string, but contains the
245 HTML-processed form of the string. Whether or not "all HTML" is allowed
246 depends on site-level configuration options, and that changes how the
247 input is processed.
 
 
 
 
 
 
 
248
249 Note that the links in the generated page are for the HTML interface,
250 and will not work as-is for arbitrary JSON clients. In order to
251 integrate the parsed content with JSON-based clients the HTML will
252 probably need to be post-processed, e.g. using jQuery to fish out the
253 links and re-map wiki page links to a JSON-capable page handler.
254
255 **TODO**: Update this to accept the other two wiki formats (which
256 didn't exist when this API was implemented): markdown and plain text
257 (which gets HTML-ized for preview purposes). That requires changing
258 the payload to an object, perhaps simply submitting the same thing as
259 `/json/save`. There's no reason we can't support both call forms.
260
261
262 <a id="todo"></a>
263 # Notes and TODOs
264
265 - When server-parsing the wiki content, the generated
266
--- www/json-api/api-wiki.md
+++ www/json-api/api-wiki.md
@@ -166,10 +166,13 @@
166 - `name=string` specifies the page name.
167 - `content=string` is the body text.\
168 Content is required for save (unless `createIfNotExists` is true *and*
169 the page does not exist), optional for create. It *may* be an empty
170 string.
171 - `mimetype=string` specifies the mimetype for the body, noting any any
172 unrecognized/unsupported mimetype is silently treated as
173 `text/x-fossil-wiki`.
174 - Save (not create) supports a `createIfNotExists` boolean option which
175 makes it a functional superset of the create/save features. i.e. it
176 will create if needed, else it will update. If createIfNotExists is
177 false (the default) then save will fail if given a page name which
178 does not refer to an existing page.
@@ -179,10 +182,11 @@
182 high-priority addition. See:\
183 [](/doc/trunk/www/fileformat.wiki#wikichng)
184 - **Potential TODO:** we *could* optionally also support
185 multi-page saving using an array of pages in the request payload:\
186 `[… page objects … ]`
187
188
189
190 <a id="diffs"></a>
191 # Wiki Diffs
192
@@ -238,28 +242,29 @@
242
243 This command wiki-processes arbitrary text sent from the client. To help
244 curb potential abuse, its use is restricted to those with "k" access
245 rights.
246
247 The `POST.payload` property must be either:
248
249 1) A string containing Fossil wiki markup.
250
251 2) An Object with a `body` property holding the text to render and a
252 `mimetype` property describing the wiki format:
253 `text/x-fossil-wiki` (the default), `text/x-markdown`, or
254 `text/plain`. Any unknown type is treated as `text/x-fossil-wiki`.
255
256 The response payload is a string containing the rendered page. Whether
257 or not "all HTML" is allowed depends on site-level configuration
258 options, and that changes how the input is processed.
259
260 Note that the links in the generated page are for the HTML interface,
261 and will not work as-is for arbitrary JSON clients. In order to
262 integrate the parsed content with JSON-based clients the HTML will
263 probably need to be post-processed, e.g. using jQuery to fish out the
264 links and re-map wiki page links to a JSON-capable page handler.
265
 
 
 
 
 
 
266
267 <a id="todo"></a>
268 # Notes and TODOs
269
270 - When server-parsing the wiki content, the generated
271
--- www/userlinks.wiki
+++ www/userlinks.wiki
@@ -31,14 +31,10 @@
3131
* [./stats.wiki | Performance statistics] taken from real-world projects
3232
hosted on Fossil.
3333
* How to [./shunning.wiki | delete content] from a Fossil repository.
3434
* How Fossil does [./password.wiki | password management].
3535
* On-line [/help | help].
36
- * Documentation on the
37
- [http://www.sqliteconcepts.org/THManual.pdf | TH1 scripting language],
38
- used to customize [./custom_ticket.wiki | ticketing], and several other
39
- subsystems, including [./customskin.md | theming].
4036
* List of [./th1.md | TH1 commands provided by Fossil itself] that expose
4137
its key functionality to TH1 scripts.
4238
* List of [./th1-hooks.md | TH1 hooks exposed by Fossil] that enable
4339
customization of commands and web pages.
4440
* A free hosting server for Fossil repositories is available at
@@ -49,5 +45,6 @@
4945
* [./inout.wiki | Import and export] from and to Git.
5046
* [./fossil-v-git.wiki | Fossil versus Git].
5147
* [./fiveminutes.wiki | Up and running in 5 minutes as a single user]
5248
(contributed by Gilles Ganault on 2013-01-08).
5349
* [./antibot.wiki | How Fossil defends against abuse by spiders and bots].
50
+ * [./wsl_caveats.wiki | Using Fossil on WSL], caveats and guidance.
5451
--- www/userlinks.wiki
+++ www/userlinks.wiki
@@ -31,14 +31,10 @@
31 * [./stats.wiki | Performance statistics] taken from real-world projects
32 hosted on Fossil.
33 * How to [./shunning.wiki | delete content] from a Fossil repository.
34 * How Fossil does [./password.wiki | password management].
35 * On-line [/help | help].
36 * Documentation on the
37 [http://www.sqliteconcepts.org/THManual.pdf | TH1 scripting language],
38 used to customize [./custom_ticket.wiki | ticketing], and several other
39 subsystems, including [./customskin.md | theming].
40 * List of [./th1.md | TH1 commands provided by Fossil itself] that expose
41 its key functionality to TH1 scripts.
42 * List of [./th1-hooks.md | TH1 hooks exposed by Fossil] that enable
43 customization of commands and web pages.
44 * A free hosting server for Fossil repositories is available at
@@ -49,5 +45,6 @@
49 * [./inout.wiki | Import and export] from and to Git.
50 * [./fossil-v-git.wiki | Fossil versus Git].
51 * [./fiveminutes.wiki | Up and running in 5 minutes as a single user]
52 (contributed by Gilles Ganault on 2013-01-08).
53 * [./antibot.wiki | How Fossil defends against abuse by spiders and bots].
 
54
--- www/userlinks.wiki
+++ www/userlinks.wiki
@@ -31,14 +31,10 @@
31 * [./stats.wiki | Performance statistics] taken from real-world projects
32 hosted on Fossil.
33 * How to [./shunning.wiki | delete content] from a Fossil repository.
34 * How Fossil does [./password.wiki | password management].
35 * On-line [/help | help].
 
 
 
 
36 * List of [./th1.md | TH1 commands provided by Fossil itself] that expose
37 its key functionality to TH1 scripts.
38 * List of [./th1-hooks.md | TH1 hooks exposed by Fossil] that enable
39 customization of commands and web pages.
40 * A free hosting server for Fossil repositories is available at
@@ -49,5 +45,6 @@
45 * [./inout.wiki | Import and export] from and to Git.
46 * [./fossil-v-git.wiki | Fossil versus Git].
47 * [./fiveminutes.wiki | Up and running in 5 minutes as a single user]
48 (contributed by Gilles Ganault on 2013-01-08).
49 * [./antibot.wiki | How Fossil defends against abuse by spiders and bots].
50 * [./wsl_caveats.wiki | Using Fossil on WSL], caveats and guidance.
51
--- www/wsl_caveats.wiki
+++ www/wsl_caveats.wiki
@@ -2,15 +2,15 @@
22
33
<h2>When These Issues Matter</h2>
44
55
The discussion following is relevant to those who:
66
7
- * Are using the Windows Subsystem for Linux (aka "WSL");
8
- * Create a Fossil checkout in a directory accessible from WSL and Windows;
9
- * Use both Linux Fossil and Windows tools to modify files in a checkout;
10
- * Desire to or must preserve execute permissions set for repository files;
11
- * and Use Linux Fossil to commit changes made within the checkout.
7
+ * Are using the Windows Subsystem for Linux (aka "WSL");
8
+ * Create a Fossil checkout in a directory accessible from WSL and Windows;
9
+ * Use both Linux Fossil and Windows tools to modify files in a checkout;
10
+ * Desire to or must preserve execute permissions set for repository files;
11
+ * and Use Linux Fossil to commit changes made within the checkout.
1212
1313
Note that these criteria apply conjunctively; if any are not met,
1414
then the consequences of the issues below are at worst annoying
1515
and otherwise harmless or absent.
1616
@@ -74,65 +74,65 @@
7474
7575
<h2>Problematic Usage Scenarios</h2>
7676
7777
<h3>A Simple Example</h3>
7878
79
-* Open a checkout in Windows (using fossil.exe) from a project
79
+ * Open a checkout in Windows (using fossil.exe) from a project
8080
whose files have a mixture of executable and non-executable files.
8181
Use a checkout directory visible when running under WSL.
8282
83
-* Navigate to the same directory in a Linux shell on WSL, then
83
+ * Navigate to the same directory in a Linux shell on WSL, then
8484
run "fossil status".
8585
86
-* Depending upon /etc/wsl.conf content (or defaults in its absence),
86
+ * Depending upon /etc/wsl.conf content (or defaults in its absence),
8787
the status ouput will tag checkout files as EXECUTABLE or NOEXEC.
8888
8989
<h3>Continuation of Simple Example</h3>
9090
91
-* In the same checkout as above "Simple Example", on WSL,
91
+ * In the same checkout as above "Simple Example", on WSL,
9292
run "fossil revert" to correct all those errant X-bit values.
9393
94
-* Run "fossil status" again in WSL to verify absence of toggled X-bits.
94
+ * Run "fossil status" again in WSL to verify absence of toggled X-bits.
9595
96
-* Run "ls -l" from WSL to find two files, one with its X-bit set
96
+ * Run "ls -l" from WSL to find two files, one with its X-bit set
9797
and the other with it clear.
9898
99
-* From Windows, perform these steps on each of those files:
100
-(1) read the_file content into a buffer<br>
101
-(2) rename the_file the_file.bak<br>
102
-(3) write buffer content to new file, the_file<br>
103
-(4) del the_file.bak (or leave it)<br>
104
-(Note that this sequence is similar to what many editors do when
99
+ * From Windows, perform these steps on each of those files:<br>
100
+&nbsp;&nbsp;(1) read the_file content into a buffer<br>
101
+&nbsp;&nbsp;(2) rename the_file the_file.bak<br>
102
+&nbsp;&nbsp;(3) write buffer content to new file, the_file<br>
103
+&nbsp;&nbsp;(4) del the_file.bak (or leave it)<br>
104
+&nbsp;&nbsp;(Note that this sequence is similar to what many editors do when
105105
a user modifies a file then uses undo to reverse the changes.)
106106
107
-* Run "fossil status" again in WSL and observe that one of the
107
+ * Run "fossil status" again in WSL and observe that one of the
108108
two files has had its X-bit toggled.
109109
110110
<h3>A Fossil-Only Example</h3>
111111
112
-* In the another (different) checkout of the same version,
112
+ * In the another (different) checkout of the same version,
113113
somehow cause "legitimate" X-bit toggles of two files whose
114114
X-bits differ. (This "somehow" probably will involve WSL to
115115
toggle file bits and fossil on WSL to commit the toggles.)
116116
117
-* In the Simple Example checkout, use fossil.exe on Windows
117
+ * In the Simple Example checkout, use fossil.exe on Windows
118118
to update the checkout, ostensibly bringing the X-bit toggles
119119
into the affected checkout files.
120120
121
-* In the Simple Example checkout, use fossil on WSL to run
121
+ * In the Simple Example checkout, use fossil on WSL to run
122122
"fossil status", and observe at least one X-bit discrepancy.
123123
124124
<h2>Recommended Workflow</h2>
125125
126126
There are two simple approaches for dealing with this issue when
127127
one wishes to continue using the same checkout directory from
128128
Windows and WSL. Either one is effective. These are:
129129
130
-* Do not use fossil on WSL for any operations which will modify
130
+ * Do not use fossil on WSL for any operations which will modify
131131
the repository. Instead, block those operations in some manner.
132132
133
-* Do not use any tools on Windows, (including certain subcommands
133
+ * Do not use any tools on Windows, (including certain subcommands
134134
of fossil.exe,) which may modify the X-bits on files within the
135135
shared checkout, instead restricting use of Windows tools to those
136136
which are known to only (and actually) modify file content in place
137137
while preserving X-bit values. (The "actually" proviso emphasizes
138138
that tools which only simulate in-place file modification, but do
139139
--- www/wsl_caveats.wiki
+++ www/wsl_caveats.wiki
@@ -2,15 +2,15 @@
2
3 <h2>When These Issues Matter</h2>
4
5 The discussion following is relevant to those who:
6
7 * Are using the Windows Subsystem for Linux (aka "WSL");
8 * Create a Fossil checkout in a directory accessible from WSL and Windows;
9 * Use both Linux Fossil and Windows tools to modify files in a checkout;
10 * Desire to or must preserve execute permissions set for repository files;
11 * and Use Linux Fossil to commit changes made within the checkout.
12
13 Note that these criteria apply conjunctively; if any are not met,
14 then the consequences of the issues below are at worst annoying
15 and otherwise harmless or absent.
16
@@ -74,65 +74,65 @@
74
75 <h2>Problematic Usage Scenarios</h2>
76
77 <h3>A Simple Example</h3>
78
79 * Open a checkout in Windows (using fossil.exe) from a project
80 whose files have a mixture of executable and non-executable files.
81 Use a checkout directory visible when running under WSL.
82
83 * Navigate to the same directory in a Linux shell on WSL, then
84 run "fossil status".
85
86 * Depending upon /etc/wsl.conf content (or defaults in its absence),
87 the status ouput will tag checkout files as EXECUTABLE or NOEXEC.
88
89 <h3>Continuation of Simple Example</h3>
90
91 * In the same checkout as above "Simple Example", on WSL,
92 run "fossil revert" to correct all those errant X-bit values.
93
94 * Run "fossil status" again in WSL to verify absence of toggled X-bits.
95
96 * Run "ls -l" from WSL to find two files, one with its X-bit set
97 and the other with it clear.
98
99 * From Windows, perform these steps on each of those files:
100 (1) read the_file content into a buffer<br>
101 (2) rename the_file the_file.bak<br>
102 (3) write buffer content to new file, the_file<br>
103 (4) del the_file.bak (or leave it)<br>
104 (Note that this sequence is similar to what many editors do when
105 a user modifies a file then uses undo to reverse the changes.)
106
107 * Run "fossil status" again in WSL and observe that one of the
108 two files has had its X-bit toggled.
109
110 <h3>A Fossil-Only Example</h3>
111
112 * In the another (different) checkout of the same version,
113 somehow cause "legitimate" X-bit toggles of two files whose
114 X-bits differ. (This "somehow" probably will involve WSL to
115 toggle file bits and fossil on WSL to commit the toggles.)
116
117 * In the Simple Example checkout, use fossil.exe on Windows
118 to update the checkout, ostensibly bringing the X-bit toggles
119 into the affected checkout files.
120
121 * In the Simple Example checkout, use fossil on WSL to run
122 "fossil status", and observe at least one X-bit discrepancy.
123
124 <h2>Recommended Workflow</h2>
125
126 There are two simple approaches for dealing with this issue when
127 one wishes to continue using the same checkout directory from
128 Windows and WSL. Either one is effective. These are:
129
130 * Do not use fossil on WSL for any operations which will modify
131 the repository. Instead, block those operations in some manner.
132
133 * Do not use any tools on Windows, (including certain subcommands
134 of fossil.exe,) which may modify the X-bits on files within the
135 shared checkout, instead restricting use of Windows tools to those
136 which are known to only (and actually) modify file content in place
137 while preserving X-bit values. (The "actually" proviso emphasizes
138 that tools which only simulate in-place file modification, but do
139
--- www/wsl_caveats.wiki
+++ www/wsl_caveats.wiki
@@ -2,15 +2,15 @@
2
3 <h2>When These Issues Matter</h2>
4
5 The discussion following is relevant to those who:
6
7 * Are using the Windows Subsystem for Linux (aka "WSL");
8 * Create a Fossil checkout in a directory accessible from WSL and Windows;
9 * Use both Linux Fossil and Windows tools to modify files in a checkout;
10 * Desire to or must preserve execute permissions set for repository files;
11 * and Use Linux Fossil to commit changes made within the checkout.
12
13 Note that these criteria apply conjunctively; if any are not met,
14 then the consequences of the issues below are at worst annoying
15 and otherwise harmless or absent.
16
@@ -74,65 +74,65 @@
74
75 <h2>Problematic Usage Scenarios</h2>
76
77 <h3>A Simple Example</h3>
78
79 * Open a checkout in Windows (using fossil.exe) from a project
80 whose files have a mixture of executable and non-executable files.
81 Use a checkout directory visible when running under WSL.
82
83 * Navigate to the same directory in a Linux shell on WSL, then
84 run "fossil status".
85
86 * Depending upon /etc/wsl.conf content (or defaults in its absence),
87 the status ouput will tag checkout files as EXECUTABLE or NOEXEC.
88
89 <h3>Continuation of Simple Example</h3>
90
91 * In the same checkout as above "Simple Example", on WSL,
92 run "fossil revert" to correct all those errant X-bit values.
93
94 * Run "fossil status" again in WSL to verify absence of toggled X-bits.
95
96 * Run "ls -l" from WSL to find two files, one with its X-bit set
97 and the other with it clear.
98
99 * From Windows, perform these steps on each of those files:<br>
100 &nbsp;&nbsp;(1) read the_file content into a buffer<br>
101 &nbsp;&nbsp;(2) rename the_file the_file.bak<br>
102 &nbsp;&nbsp;(3) write buffer content to new file, the_file<br>
103 &nbsp;&nbsp;(4) del the_file.bak (or leave it)<br>
104 &nbsp;&nbsp;(Note that this sequence is similar to what many editors do when
105 a user modifies a file then uses undo to reverse the changes.)
106
107 * Run "fossil status" again in WSL and observe that one of the
108 two files has had its X-bit toggled.
109
110 <h3>A Fossil-Only Example</h3>
111
112 * In the another (different) checkout of the same version,
113 somehow cause "legitimate" X-bit toggles of two files whose
114 X-bits differ. (This "somehow" probably will involve WSL to
115 toggle file bits and fossil on WSL to commit the toggles.)
116
117 * In the Simple Example checkout, use fossil.exe on Windows
118 to update the checkout, ostensibly bringing the X-bit toggles
119 into the affected checkout files.
120
121 * In the Simple Example checkout, use fossil on WSL to run
122 "fossil status", and observe at least one X-bit discrepancy.
123
124 <h2>Recommended Workflow</h2>
125
126 There are two simple approaches for dealing with this issue when
127 one wishes to continue using the same checkout directory from
128 Windows and WSL. Either one is effective. These are:
129
130 * Do not use fossil on WSL for any operations which will modify
131 the repository. Instead, block those operations in some manner.
132
133 * Do not use any tools on Windows, (including certain subcommands
134 of fossil.exe,) which may modify the X-bits on files within the
135 shared checkout, instead restricting use of Windows tools to those
136 which are known to only (and actually) modify file content in place
137 while preserving X-bit values. (The "actually" proviso emphasizes
138 that tools which only simulate in-place file modification, but do
139

Keyboard Shortcuts

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