Fossil SCM

Merge the latest trunk enhancements into the timestamp-vfs branch.

drh 2026-02-17 16:47 timestamp-vfs merge
Commit 99aa77d96eb9ee99b0d836845dbd353024e815b8dc3f8fd19a9144094ea89a7f
+342 -179
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -876,10 +876,11 @@
876876
#ifndef SQLITE_QRF_H
877877
#include "qrf.h"
878878
#endif
879879
#include <string.h>
880880
#include <assert.h>
881
+#include <stdint.h>
881882
882883
/* typedef sqlite3_int64 i64; */
883884
884885
/* A single line in the EQP output */
885886
typedef struct qrfEQPGraphRow qrfEQPGraphRow;
@@ -893,11 +894,12 @@
893894
/* All EQP output is collected into an instance of the following */
894895
typedef struct qrfEQPGraph qrfEQPGraph;
895896
struct qrfEQPGraph {
896897
qrfEQPGraphRow *pRow; /* Linked list of all rows of the EQP output */
897898
qrfEQPGraphRow *pLast; /* Last element of the pRow list */
898
- char zPrefix[100]; /* Graph prefix */
899
+ int nWidth; /* Width of the graph */
900
+ char zPrefix[400]; /* Graph prefix */
899901
};
900902
901903
/*
902904
** Private state information. Subject to change from one release to the
903905
** next.
@@ -1087,10 +1089,49 @@
10871089
qrfEqpRenderLevel(p, pRow->iEqpId);
10881090
p->u.pGraph->zPrefix[n] = 0;
10891091
}
10901092
}
10911093
}
1094
+
1095
+/*
1096
+** Render the 64-bit value N in a more human-readable format into
1097
+** pOut.
1098
+**
1099
+** + Only show the first three significant digits.
1100
+** + Append suffixes K, M, G, T, P, and E for 1e3, 1e6, ... 1e18
1101
+*/
1102
+static void qrfApproxInt64(sqlite3_str *pOut, i64 N){
1103
+ static const char aSuffix[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
1104
+ int i;
1105
+ if( N<0 ){
1106
+ N = N==INT64_MIN ? INT64_MAX : -N;
1107
+ sqlite3_str_append(pOut, "-", 1);
1108
+ }
1109
+ if( N<10000 ){
1110
+ sqlite3_str_appendf(pOut, "%4lld ", N);
1111
+ return;
1112
+ }
1113
+ for(i=1; i<=18; i++){
1114
+ N = (N+5)/10;
1115
+ if( N<10000 ){
1116
+ int n = (int)N;
1117
+ switch( i%3 ){
1118
+ case 0:
1119
+ sqlite3_str_appendf(pOut, "%d.%02d", n/1000, (n%1000)/10);
1120
+ break;
1121
+ case 1:
1122
+ sqlite3_str_appendf(pOut, "%2d.%d", n/100, (n%100)/10);
1123
+ break;
1124
+ case 2:
1125
+ sqlite3_str_appendf(pOut, "%4d", n/10);
1126
+ break;
1127
+ }
1128
+ sqlite3_str_append(pOut, &aSuffix[i/3], 1);
1129
+ break;
1130
+ }
1131
+ }
1132
+}
10921133
10931134
/*
10941135
** Display and reset the EXPLAIN QUERY PLAN data
10951136
*/
10961137
static void qrfEqpRender(Qrf *p, i64 nCycle){
@@ -1103,11 +1144,30 @@
11031144
}
11041145
sqlite3_str_appendf(p->pOut, "%s\n", pRow->zText+3);
11051146
p->u.pGraph->pRow = pRow->pNext;
11061147
sqlite3_free(pRow);
11071148
}else if( nCycle>0 ){
1108
- sqlite3_str_appendf(p->pOut, "QUERY PLAN (cycles=%lld [100%%])\n",nCycle);
1149
+ int nSp = p->u.pGraph->nWidth - 2;
1150
+ if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1151
+ sqlite3_str_appendchar(p->pOut, nSp, ' ');
1152
+ sqlite3_str_appendall(p->pOut,
1153
+ "Cycles Loops (est) Rows (est)\n");
1154
+ sqlite3_str_appendchar(p->pOut, nSp, ' ');
1155
+ sqlite3_str_appendall(p->pOut,
1156
+ "---------- ------------ ------------\n");
1157
+ }else{
1158
+ sqlite3_str_appendchar(p->pOut, nSp, ' ');
1159
+ sqlite3_str_appendall(p->pOut,
1160
+ "Cycles Loops Rows \n");
1161
+ sqlite3_str_appendchar(p->pOut, nSp, ' ');
1162
+ sqlite3_str_appendall(p->pOut,
1163
+ "---------- ----- -----\n");
1164
+ }
1165
+ sqlite3_str_appendall(p->pOut, "QUERY PLAN");
1166
+ sqlite3_str_appendchar(p->pOut, nSp - 10, ' ');
1167
+ qrfApproxInt64(p->pOut, nCycle);
1168
+ sqlite3_str_appendall(p->pOut, " 100%\n");
11091169
}else{
11101170
sqlite3_str_appendall(p->pOut, "QUERY PLAN\n");
11111171
}
11121172
p->u.pGraph->zPrefix[0] = 0;
11131173
qrfEqpRenderLevel(p, 0);
@@ -1158,10 +1218,12 @@
11581218
static const int f = SQLITE_SCANSTAT_COMPLEX;
11591219
sqlite3_stmt *pS = p->pStmt;
11601220
int i = 0;
11611221
i64 nTotal = 0;
11621222
int nWidth = 0;
1223
+ int prevPid = -1; /* Previous iPid */
1224
+ double rEstCum = 1.0; /* Cumulative row estimate */
11631225
sqlite3_str *pLine = sqlite3_str_new(p->db);
11641226
sqlite3_str *pStats = sqlite3_str_new(p->db);
11651227
qrfEqpReset(p);
11661228
11671229
for(i=0; 1; i++){
@@ -1171,11 +1233,11 @@
11711233
break;
11721234
}
11731235
n = (int)strlen(z) + qrfStatsHeight(pS,i)*3;
11741236
if( n>nWidth ) nWidth = n;
11751237
}
1176
- nWidth += 4;
1238
+ nWidth += 2;
11771239
11781240
sqlite3_stmt_scanstatus_v2(pS,-1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
11791241
for(i=0; 1; i++){
11801242
i64 nLoop = 0;
11811243
i64 nRow = 0;
@@ -1186,54 +1248,64 @@
11861248
const char *zName = 0;
11871249
double rEst = 0.0;
11881250
11891251
if( sqlite3_stmt_scanstatus_v2(pS,i,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&zo) ){
11901252
break;
1253
+ }
1254
+ sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_PARENTID,f,(void*)&iPid);
1255
+ if( iPid!=prevPid ){
1256
+ prevPid = iPid;
1257
+ rEstCum = 1.0;
11911258
}
11921259
sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_EST,f,(void*)&rEst);
1260
+ rEstCum *= rEst;
11931261
sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NLOOP,f,(void*)&nLoop);
11941262
sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NVISIT,f,(void*)&nRow);
11951263
sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NCYCLE,f,(void*)&nCycle);
11961264
sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_SELECTID,f,(void*)&iId);
1197
- sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_PARENTID,f,(void*)&iPid);
11981265
sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NAME,f,(void*)&zName);
11991266
12001267
if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
1201
- const char *zSp = "";
1202
- double rpl;
1268
+ int nSp = 0;
12031269
sqlite3_str_reset(pStats);
12041270
if( nCycle>=0 && nTotal>0 ){
1205
- sqlite3_str_appendf(pStats, "cycles=%lld [%d%%]",
1206
- nCycle, ((nCycle*100)+nTotal/2) / nTotal
1271
+ qrfApproxInt64(pStats, nCycle);
1272
+ sqlite3_str_appendf(pStats, " %3d%%",
1273
+ ((nCycle*100)+nTotal/2) / nTotal
12071274
);
1208
- zSp = " ";
1275
+ nSp = 2;
12091276
}
12101277
if( nLoop>=0 ){
1211
- sqlite3_str_appendf(pStats, "%sloops=%lld", zSp, nLoop);
1212
- zSp = " ";
1278
+ if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
1279
+ qrfApproxInt64(pStats, nLoop);
1280
+ nSp = 2;
1281
+ if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1282
+ sqlite3_str_appendf(pStats, " ");
1283
+ qrfApproxInt64(pStats, (i64)(rEstCum/rEst));
1284
+ }
12131285
}
12141286
if( nRow>=0 ){
1215
- sqlite3_str_appendf(pStats, "%srows=%lld", zSp, nRow);
1216
- zSp = " ";
1217
- }
1218
-
1219
- if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1220
- rpl = (double)nRow / (double)nLoop;
1221
- sqlite3_str_appendf(pStats, "%srpl=%.1f est=%.1f", zSp, rpl, rEst);
1222
- }
1223
-
1287
+ if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
1288
+ qrfApproxInt64(pStats, nRow);
1289
+ nSp = 2;
1290
+ if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1291
+ sqlite3_str_appendf(pStats, " ");
1292
+ qrfApproxInt64(pStats, (i64)rEstCum);
1293
+ }
1294
+ }
12241295
sqlite3_str_appendf(pLine,
1225
- "% *s (%s)", -1*(nWidth-qrfStatsHeight(pS,i)*3), zo,
1296
+ "% *s %s", -1*(nWidth-qrfStatsHeight(pS,i)*3), zo,
12261297
sqlite3_str_value(pStats)
12271298
);
12281299
sqlite3_str_reset(pStats);
12291300
qrfEqpAppend(p, iId, iPid, sqlite3_str_value(pLine));
12301301
sqlite3_str_reset(pLine);
12311302
}else{
12321303
qrfEqpAppend(p, iId, iPid, zo);
12331304
}
12341305
}
1306
+ if( p->u.pGraph ) p->u.pGraph->nWidth = nWidth;
12351307
qrfStrErr(p, pLine);
12361308
sqlite3_free(sqlite3_str_finish(pLine));
12371309
qrfStrErr(p, pStats);
12381310
sqlite3_free(sqlite3_str_finish(pStats));
12391311
#endif
@@ -3664,11 +3736,20 @@
36643736
sqlite3_free(p->u.sLine.azCol);
36653737
}
36663738
break;
36673739
}
36683740
case QRF_STYLE_Stats:
3669
- case QRF_STYLE_StatsEst:
3741
+ case QRF_STYLE_StatsEst: {
3742
+ i64 nCycle = 0;
3743
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
3744
+ sqlite3_stmt_scanstatus_v2(p->pStmt, -1, SQLITE_SCANSTAT_NCYCLE,
3745
+ SQLITE_SCANSTAT_COMPLEX, (void*)&nCycle);
3746
+#endif
3747
+ qrfEqpRender(p, nCycle);
3748
+ qrfWrite(p);
3749
+ break;
3750
+ }
36703751
case QRF_STYLE_Eqp: {
36713752
qrfEqpRender(p, 0);
36723753
qrfWrite(p);
36733754
break;
36743755
}
@@ -3836,13 +3917,10 @@
38363917
38373918
38383919
#define eputz(z) cli_puts(z,stderr)
38393920
#define sputz(fp,z) cli_puts(z,fp)
38403921
3841
-/* True if the timer is enabled */
3842
-static int enableTimer = 0;
3843
-
38443922
/* A version of strcmp() that works with NULL values */
38453923
static int cli_strcmp(const char *a, const char *b){
38463924
if( a==0 ) a = "";
38473925
if( b==0 ) b = "";
38483926
return strcmp(a,b);
@@ -3883,154 +3961,10 @@
38833961
(void)gettimeofday(&sNow,0);
38843962
return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
38853963
#endif
38863964
}
38873965
3888
-#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
3889
-#include <sys/time.h>
3890
-#include <sys/resource.h>
3891
-
3892
-/* VxWorks does not support getrusage() as far as we can determine */
3893
-#if defined(_WRS_KERNEL) || defined(__RTP__)
3894
-struct rusage {
3895
- struct timeval ru_utime; /* user CPU time used */
3896
- struct timeval ru_stime; /* system CPU time used */
3897
-};
3898
-#define getrusage(A,B) memset(B,0,sizeof(*B))
3899
-#endif
3900
-
3901
-
3902
-/* Saved resource information for the beginning of an operation */
3903
-static struct rusage sBegin; /* CPU time at start */
3904
-static sqlite3_int64 iBegin; /* Wall-clock time at start */
3905
-
3906
-/*
3907
-** Begin timing an operation
3908
-*/
3909
-static void beginTimer(void){
3910
- if( enableTimer ){
3911
- getrusage(RUSAGE_SELF, &sBegin);
3912
- iBegin = timeOfDay();
3913
- }
3914
-}
3915
-
3916
-/* Return the difference of two time_structs in seconds */
3917
-static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
3918
- return (pEnd->tv_usec - pStart->tv_usec)*0.000001 +
3919
- (double)(pEnd->tv_sec - pStart->tv_sec);
3920
-}
3921
-
3922
-/*
3923
-** Print the timing results.
3924
-*/
3925
-static void endTimer(FILE *out){
3926
- if( enableTimer ){
3927
- sqlite3_int64 iEnd = timeOfDay();
3928
- struct rusage sEnd;
3929
- getrusage(RUSAGE_SELF, &sEnd);
3930
- cli_printf(out, "Run Time: real %.6f user %.6f sys %.6f\n",
3931
- (iEnd - iBegin)*0.000001,
3932
- timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
3933
- timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
3934
- }
3935
-}
3936
-
3937
-#define BEGIN_TIMER beginTimer()
3938
-#define END_TIMER(X) endTimer(X)
3939
-#define HAS_TIMER 1
3940
-
3941
-#elif (defined(_WIN32) || defined(WIN32))
3942
-
3943
-/* Saved resource information for the beginning of an operation */
3944
-static HANDLE hProcess;
3945
-static FILETIME ftKernelBegin;
3946
-static FILETIME ftUserBegin;
3947
-static sqlite3_int64 ftWallBegin;
3948
-typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
3949
- LPFILETIME, LPFILETIME);
3950
-static GETPROCTIMES getProcessTimesAddr = NULL;
3951
-
3952
-/*
3953
-** Check to see if we have timer support. Return 1 if necessary
3954
-** support found (or found previously).
3955
-*/
3956
-static int hasTimer(void){
3957
- if( getProcessTimesAddr ){
3958
- return 1;
3959
- } else {
3960
- /* GetProcessTimes() isn't supported in WIN95 and some other Windows
3961
- ** versions. See if the version we are running on has it, and if it
3962
- ** does, save off a pointer to it and the current process handle.
3963
- */
3964
- hProcess = GetCurrentProcess();
3965
- if( hProcess ){
3966
- HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
3967
- if( NULL != hinstLib ){
3968
- getProcessTimesAddr =
3969
- (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
3970
- if( NULL != getProcessTimesAddr ){
3971
- return 1;
3972
- }
3973
- FreeLibrary(hinstLib);
3974
- }
3975
- }
3976
- }
3977
- return 0;
3978
-}
3979
-
3980
-/*
3981
-** Begin timing an operation
3982
-*/
3983
-static void beginTimer(void){
3984
- if( enableTimer && getProcessTimesAddr ){
3985
- FILETIME ftCreation, ftExit;
3986
- getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
3987
- &ftKernelBegin,&ftUserBegin);
3988
- ftWallBegin = timeOfDay();
3989
- }
3990
-}
3991
-
3992
-/* Return the difference of two FILETIME structs in seconds */
3993
-static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
3994
- sqlite_int64 i64Start = *((sqlite_int64 *) pStart);
3995
- sqlite_int64 i64End = *((sqlite_int64 *) pEnd);
3996
- return (double) ((i64End - i64Start) / 10000000.0);
3997
-}
3998
-
3999
-/*
4000
-** Print the timing results.
4001
-*/
4002
-static void endTimer(FILE *out){
4003
- if( enableTimer && getProcessTimesAddr){
4004
- FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
4005
- sqlite3_int64 ftWallEnd = timeOfDay();
4006
- getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
4007
-#ifdef _WIN64
4008
- /* microsecond precision on 64-bit windows */
4009
- cli_printf(out, "Run Time: real %.6f user %f sys %f\n",
4010
- (ftWallEnd - ftWallBegin)*0.000001,
4011
- timeDiff(&ftUserBegin, &ftUserEnd),
4012
- timeDiff(&ftKernelBegin, &ftKernelEnd));
4013
-#else
4014
- /* millisecond precisino on 32-bit windows */
4015
- cli_printf(out, "Run Time: real %.3f user %.3f sys %.3f\n",
4016
- (ftWallEnd - ftWallBegin)*0.000001,
4017
- timeDiff(&ftUserBegin, &ftUserEnd),
4018
- timeDiff(&ftKernelBegin, &ftKernelEnd));
4019
-#endif
4020
- }
4021
-}
4022
-
4023
-#define BEGIN_TIMER beginTimer()
4024
-#define END_TIMER(X) endTimer(X)
4025
-#define HAS_TIMER hasTimer()
4026
-
4027
-#else
4028
-#define BEGIN_TIMER
4029
-#define END_TIMER(X) /*no-op*/
4030
-#define HAS_TIMER 0
4031
-#endif
40323966
40333967
/*
40343968
** Used to prevent warnings about unused parameters
40353969
*/
40363970
#define UNUSED_PARAMETER(x) (void)(x)
@@ -24226,11 +24160,14 @@
2422624160
u8 eRestoreState; /* See comments above doAutoDetectRestore() */
2422724161
unsigned statsOn; /* True to display memory stats before each finalize */
2422824162
unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
2422924163
u8 nPopOutput; /* Revert .output settings when reaching zero */
2423024164
u8 nPopMode; /* Revert .mode settings when reaching zero */
24165
+ u8 enableTimer; /* Enable the timer. 2: permanently 1: only once */
2423124166
int inputNesting; /* Track nesting level of .read and other redirects */
24167
+ double prevTimer; /* Last reported timer value */
24168
+ double tmProgress; /* --timeout option for .progress */
2423224169
i64 lineno; /* Line number of last line read from in */
2423324170
const char *zInFile; /* Name of the input file */
2423424171
int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
2423524172
FILE *in; /* Read commands from this stream */
2423624173
FILE *out; /* Write results here */
@@ -24322,10 +24259,11 @@
2432224259
#define SHELL_PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */
2432324260
#define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress
2432424261
** callback limit is reached, and for each
2432524262
** top-level SQL statement */
2432624263
#define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
24264
+#define SHELL_PROGRESS_TMOUT 0x08 /* Stop after tmProgress seconds */
2432724265
2432824266
/* Names of values for Mode.spec.eEsc and Mode.spec.eText
2432924267
*/
2433024268
static const char *qrfEscNames[] = { "auto", "off", "ascii", "symbol" };
2433124269
static const char *qrfQuoteNames[] =
@@ -24483,10 +24421,185 @@
2448324421
** Limit input nesting via .read or any other input redirect.
2448424422
** It's not too expensive, so a generous allowance can be made.
2448524423
*/
2448624424
#define MAX_INPUT_NESTING 25
2448724425
24426
+/************************* BEGIN PERFORMANCE TIMER *****************************/
24427
+#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
24428
+#include <sys/time.h>
24429
+#include <sys/resource.h>
24430
+/* VxWorks does not support getrusage() as far as we can determine */
24431
+#if defined(_WRS_KERNEL) || defined(__RTP__)
24432
+struct rusage {
24433
+ struct timeval ru_utime; /* user CPU time used */
24434
+ struct timeval ru_stime; /* system CPU time used */
24435
+};
24436
+#define getrusage(A,B) memset(B,0,sizeof(*B))
24437
+#endif
24438
+
24439
+/* Saved resource information for the beginning of an operation */
24440
+static struct rusage sBegin; /* CPU time at start */
24441
+static sqlite3_int64 iBegin; /* Wall-clock time at start */
24442
+
24443
+/*
24444
+** Begin timing an operation
24445
+*/
24446
+static void beginTimer(ShellState *p){
24447
+ if( p->enableTimer || (p->flgProgress & SHELL_PROGRESS_TMOUT)!=0 ){
24448
+ getrusage(RUSAGE_SELF, &sBegin);
24449
+ iBegin = timeOfDay();
24450
+ }
24451
+}
24452
+
24453
+/* Return the difference of two time_structs in seconds */
24454
+static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
24455
+ return (pEnd->tv_usec - pStart->tv_usec)*0.000001 +
24456
+ (double)(pEnd->tv_sec - pStart->tv_sec);
24457
+}
24458
+
24459
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
24460
+/* Return the time since the start of the timer in
24461
+** seconds. */
24462
+static double elapseTime(ShellState *NotUsed){
24463
+ (void)NotUsed;
24464
+ if( iBegin==0 ) return 0.0;
24465
+ return (timeOfDay() - iBegin)*0.000001;
24466
+}
24467
+#endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
24468
+
24469
+/*
24470
+** Print the timing results.
24471
+*/
24472
+static void endTimer(ShellState *p){
24473
+ if( p->enableTimer ){
24474
+ sqlite3_int64 iEnd = timeOfDay();
24475
+ struct rusage sEnd;
24476
+ getrusage(RUSAGE_SELF, &sEnd);
24477
+ p->prevTimer = (iEnd - iBegin)*0.000001;
24478
+ cli_printf(p->out, "Run Time: real %.6f user %.6f sys %.6f\n",
24479
+ p->prevTimer,
24480
+ timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
24481
+ timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
24482
+ if( p->enableTimer==1 ) p->enableTimer = 0;
24483
+ iBegin = 0;
24484
+ }
24485
+}
24486
+
24487
+#define BEGIN_TIMER(X) beginTimer(X)
24488
+#define END_TIMER(X) endTimer(X)
24489
+#define ELAPSE_TIME(X) elapseTime(X)
24490
+#define HAS_TIMER 1
24491
+
24492
+#elif (defined(_WIN32) || defined(WIN32))
24493
+
24494
+/* Saved resource information for the beginning of an operation */
24495
+static HANDLE hProcess;
24496
+static FILETIME ftKernelBegin;
24497
+static FILETIME ftUserBegin;
24498
+static sqlite3_int64 ftWallBegin;
24499
+typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
24500
+ LPFILETIME, LPFILETIME);
24501
+static GETPROCTIMES getProcessTimesAddr = NULL;
24502
+
24503
+/*
24504
+** Check to see if we have timer support. Return 1 if necessary
24505
+** support found (or found previously).
24506
+*/
24507
+static int hasTimer(void){
24508
+ if( getProcessTimesAddr ){
24509
+ return 1;
24510
+ } else {
24511
+ /* GetProcessTimes() isn't supported in WIN95 and some other Windows
24512
+ ** versions. See if the version we are running on has it, and if it
24513
+ ** does, save off a pointer to it and the current process handle.
24514
+ */
24515
+ hProcess = GetCurrentProcess();
24516
+ if( hProcess ){
24517
+ HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
24518
+ if( NULL != hinstLib ){
24519
+ getProcessTimesAddr =
24520
+ (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
24521
+ if( NULL != getProcessTimesAddr ){
24522
+ return 1;
24523
+ }
24524
+ FreeLibrary(hinstLib);
24525
+ }
24526
+ }
24527
+ }
24528
+ return 0;
24529
+}
24530
+
24531
+/*
24532
+** Begin timing an operation
24533
+*/
24534
+static void beginTimer(ShellState *p){
24535
+ if( (p->enableTimer || (p->flgProgress & SHELL_PROGRESS_TMOUT)!=0)
24536
+ && getProcessTimesAddr
24537
+ ){
24538
+ FILETIME ftCreation, ftExit;
24539
+ getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
24540
+ &ftKernelBegin,&ftUserBegin);
24541
+ ftWallBegin = timeOfDay();
24542
+ }
24543
+}
24544
+
24545
+/* Return the difference of two FILETIME structs in seconds */
24546
+static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
24547
+ sqlite_int64 i64Start = *((sqlite_int64 *) pStart);
24548
+ sqlite_int64 i64End = *((sqlite_int64 *) pEnd);
24549
+ return (double) ((i64End - i64Start) / 10000000.0);
24550
+}
24551
+
24552
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
24553
+/* Return the time since the start of the timer in
24554
+** seconds. */
24555
+static double elapseTime(ShellState *NotUsed){
24556
+ (void)NotUsed;
24557
+ if( ftWallBegin==0 ) return 0.0;
24558
+ return (timeOfDay() - ftWallBegin)*0.000001;
24559
+}
24560
+#endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
24561
+
24562
+/*
24563
+** Print the timing results.
24564
+*/
24565
+static void endTimer(ShellState *p){
24566
+ if( p->enableTimer && getProcessTimesAddr){
24567
+ FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
24568
+ sqlite3_int64 ftWallEnd = timeOfDay();
24569
+ getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
24570
+ p->prevTimer = (ftWallEnd - ftWallBegin)*0.000001;
24571
+#ifdef _WIN64
24572
+ /* microsecond precision on 64-bit windows */
24573
+ cli_printf(p->out, "Run Time: real %.6f user %f sys %f\n",
24574
+ p->prevTimer,
24575
+ timeDiff(&ftUserBegin, &ftUserEnd),
24576
+ timeDiff(&ftKernelBegin, &ftKernelEnd));
24577
+#else
24578
+ /* millisecond precisino on 32-bit windows */
24579
+ cli_printf(p->out, "Run Time: real %.3f user %.3f sys %.3f\n",
24580
+ p->prevTimer,
24581
+ timeDiff(&ftUserBegin, &ftUserEnd),
24582
+ timeDiff(&ftKernelBegin, &ftKernelEnd));
24583
+#endif
24584
+ if( p->enableTimer==1 ) p->enableTimer = 0;
24585
+ ftWallBegin = 0;
24586
+ }
24587
+}
24588
+
24589
+#define BEGIN_TIMER(X) beginTimer(X)
24590
+#define ELAPSE_TIME(X) elapseTime(X)
24591
+#define END_TIMER(X) endTimer(X)
24592
+#define HAS_TIMER hasTimer()
24593
+
24594
+#else
24595
+#define BEGIN_TIMER(X) /* no-op */
24596
+#define ELAPSE_TIME(X) 0.0
24597
+#define END_TIMER(X) /*no-op*/
24598
+#define HAS_TIMER 0
24599
+#endif
24600
+/************************* END PERFORMANCE TIMER ******************************/
2448824601
2448924602
/*
2449024603
** Clear a display mode, freeing any allocated memory that it
2449124604
** contains.
2449224605
*/
@@ -25408,10 +25521,17 @@
2540825521
** Progress handler callback.
2540925522
*/
2541025523
static int progress_handler(void *pClientData) {
2541125524
ShellState *p = (ShellState*)pClientData;
2541225525
p->nProgress++;
25526
+ if( (p->flgProgress & SHELL_PROGRESS_TMOUT)!=0
25527
+ && ELAPSE_TIME(p)>=p->tmProgress
25528
+ ){
25529
+ cli_printf(p->out, "Progress timeout after %.6f seconds\n",
25530
+ ELAPSE_TIME(p));
25531
+ return 1;
25532
+ }
2541325533
if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){
2541425534
cli_printf(p->out, "Progress limit reached (%u)\n", p->nProgress);
2541525535
if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
2541625536
if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0;
2541725537
return 1;
@@ -25945,10 +26065,12 @@
2594526065
char *zBuf = sqlite3_malloc64( szVar-5 );
2594626066
if( zBuf ){
2594726067
memcpy(zBuf, &zVar[6], szVar-5);
2594826068
sqlite3_bind_text64(pStmt, i, zBuf, szVar-6, sqlite3_free, SQLITE_UTF8);
2594926069
}
26070
+ }else if( strcmp(zVar, "$TIMER")==0 ){
26071
+ sqlite3_bind_double(pStmt, i, pArg->prevTimer);
2595026072
#ifdef SQLITE_ENABLE_CARRAY
2595126073
}else if( strncmp(zVar, "$carray_", 8)==0 ){
2595226074
static char *azColorNames[] = {
2595326075
"azure", "black", "blue", "brown", "cyan", "fuchsia", "gold",
2595426076
"gray", "green", "indigo", "khaki", "lime", "magenta", "maroon",
@@ -26204,12 +26326,14 @@
2620426326
pArg->pStmt = pStmt;
2620526327
}
2620626328
2620726329
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
2620826330
isExplain = sqlite3_stmt_isexplain(pStmt);
26209
- if( pArg && pArg->mode.autoEQP && isExplain==0 ){
26331
+ if( pArg && pArg->mode.autoEQP && isExplain==0 && pArg->dot.nArg==0 ){
2621026332
int triggerEQP = 0;
26333
+ u8 savedEnableTimer = pArg->enableTimer;
26334
+ pArg->enableTimer = 0;
2621126335
disable_debug_trace_modes();
2621226336
sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
2621326337
if( pArg->mode.autoEQP>=AUTOEQP_trigger ){
2621426338
sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
2621526339
}
@@ -26227,10 +26351,11 @@
2622726351
sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0);
2622826352
}
2622926353
sqlite3_reset(pStmt);
2623026354
sqlite3_stmt_explain(pStmt, 0);
2623126355
restore_debug_trace_modes();
26356
+ pArg->enableTimer = savedEnableTimer;
2623226357
}
2623326358
2623426359
bind_prepared_stmt(pArg, pStmt);
2623526360
if( isExplain && pArg->mode.autoExplain ){
2623626361
spec.eStyle = isExplain==1 ? QRF_STYLE_Explain : QRF_STYLE_Eqp;
@@ -26764,10 +26889,11 @@
2676426889
".progress N Invoke progress handler after every N opcodes",
2676526890
" --limit N Interrupt after N progress callbacks",
2676626891
" --once Do no more than one progress interrupt",
2676726892
" --quiet|-q No output except at interrupts",
2676826893
" --reset Reset the count for each input and interrupt",
26894
+ " --timeout S Halt after running for S seconds",
2676926895
#endif
2677026896
".prompt MAIN CONTINUE Replace the standard prompts",
2677126897
#ifndef SQLITE_SHELL_FIDDLE
2677226898
".quit Stop interpreting input stream, exit if primary.",
2677326899
".read FILE Read input from FILE or command output",
@@ -26832,11 +26958,11 @@
2683226958
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
2683326959
".testcase NAME Begin a test case.",
2683426960
",testctrl CMD ... Run various sqlite3_test_control() operations",
2683526961
" Run \".testctrl\" with no arguments for details",
2683626962
".timeout MS Try opening locked tables for MS milliseconds",
26837
- ".timer on|off Turn SQL timer on or off",
26963
+ ".timer on|off|once Turn SQL timer on or off.",
2683826964
#ifndef SQLITE_OMIT_TRACE
2683926965
".trace ?OPTIONS? Output each SQL statement as it is run",
2684026966
" FILE Send output to FILE",
2684126967
" stdout Send output to stdout",
2684226968
" stderr Send output to stderr",
@@ -26897,10 +27023,12 @@
2689727023
" --ascii Do not use RFC-4180 quoting. Use \\037 and \\036\n"
2689827024
" as column and row separators on input, unless other\n"
2689927025
" delimiters are specified using --colsep and/or --rowsep\n"
2690027026
" --colsep CHAR Use CHAR as the column separator.\n"
2690127027
" --csv Input is standard RFC-4180 CSV.\n"
27028
+" --esc CHAR Use CHAR as an escape character in unquoted CSV inputs.\n"
27029
+" --qesc CHAR Use CHAR as an escape character in quoted CSV inputs.\n"
2690227030
" --rowsep CHAR Use CHAR as the row separator.\n"
2690327031
" --schema S When creating TABLE, put it in schema S\n"
2690427032
" --skip N Ignore the first N rows of input\n"
2690527033
" -v Verbose mode\n"
2690627034
},
@@ -28054,10 +28182,12 @@
2805428182
int nErr; /* Number of errors encountered */
2805528183
int bNotFirst; /* True if one or more bytes already read */
2805628184
int cTerm; /* Character that terminated the most recent field */
2805728185
int cColSep; /* The column separator character. (Usually ",") */
2805828186
int cRowSep; /* The row separator character. (Usually "\n") */
28187
+ int cQEscape; /* Escape character with "...". 0 for none */
28188
+ int cUQEscape; /* Escape character not with "...". 0 for none */
2805928189
};
2806028190
2806128191
/* Clean up resourced used by an ImportCtx */
2806228192
static void import_cleanup(ImportCtx *p){
2806328193
if( p->in!=0 && p->xCloser!=0 ){
@@ -28122,14 +28252,21 @@
2812228252
}
2812328253
if( c=='"' ){
2812428254
int pc, ppc;
2812528255
int startLine = p->nLine;
2812628256
int cQuote = c;
28257
+ int cEsc = (u8)p->cQEscape;
2812728258
pc = ppc = 0;
2812828259
while( 1 ){
2812928260
c = import_getc(p);
2813028261
if( c==rSep ) p->nLine++;
28262
+ if( c==cEsc && cEsc!=0 ){
28263
+ c = import_getc(p);
28264
+ import_append_char(p, c);
28265
+ ppc = pc = 0;
28266
+ continue;
28267
+ }
2813128268
if( c==cQuote ){
2813228269
if( pc==cQuote ){
2813328270
pc = 0;
2813428271
continue;
2813528272
}
@@ -28143,11 +28280,11 @@
2814328280
p->cTerm = c;
2814428281
break;
2814528282
}
2814628283
if( pc==cQuote && c!='\r' ){
2814728284
cli_printf(stderr,"%s:%d: unescaped %c character\n",
28148
- p->zFile, p->nLine, cQuote);
28285
+ p->zFile, p->nLine, cQuote);
2814928286
}
2815028287
if( c==EOF ){
2815128288
cli_printf(stderr,"%s:%d: unterminated %c-quoted field\n",
2815228289
p->zFile, startLine, cQuote);
2815328290
p->cTerm = c;
@@ -28158,10 +28295,11 @@
2815828295
pc = c;
2815928296
}
2816028297
}else{
2816128298
/* If this is the first field being parsed and it begins with the
2816228299
** UTF-8 BOM (0xEF BB BF) then skip the BOM */
28300
+ int cEsc = p->cUQEscape;
2816328301
if( (c&0xff)==0xef && p->bNotFirst==0 ){
2816428302
import_append_char(p, c);
2816528303
c = import_getc(p);
2816628304
if( (c&0xff)==0xbb ){
2816728305
import_append_char(p, c);
@@ -28172,10 +28310,11 @@
2817228310
return csv_read_one_field(p);
2817328311
}
2817428312
}
2817528313
}
2817628314
while( c!=EOF && c!=cSep && c!=rSep ){
28315
+ if( c==cEsc && cEsc!=0 ) c = import_getc(p);
2817728316
import_append_char(p, c);
2817828317
c = import_getc(p);
2817928318
}
2818028319
if( c==rSep ){
2818128320
p->nLine++;
@@ -30315,11 +30454,11 @@
3031530454
;
3031630455
static const char * const zCollectVar = "\
3031730456
SELECT\
3031830457
'('||x'0a'\
3031930458
|| group_concat(\
30320
- cname||' TEXT',\
30459
+ cname||' ANY',\
3032130460
','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
3032230461
||')' AS ColsSpec \
3032330462
FROM (\
3032430463
SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \
3032530464
FROM ColNames ORDER BY cpos\
@@ -30535,10 +30674,12 @@
3053530674
** --ascii Do not use RFC-4180 quoting. Use \037 and \036
3053630675
** as column and row separators on input, unless other
3053730676
** delimiters are specified using --colsep and/or --rowsep
3053830677
** --colsep CHAR Use CHAR as the column separator.
3053930678
** --csv Input is standard RFC-4180 CSV.
30679
+** --esc CHAR Use CHAR as an escape character in unquoted CSV inputs.
30680
+** --qesc CHAR Use CHAR as an escape character in quoted CSV inputs.
3054030681
** --rowsep CHAR Use CHAR as the row separator.
3054130682
** --schema S When creating TABLE, put it in schema S
3054230683
** --skip N Ignore the first N rows of input
3054330684
** -v Verbose mode
3054430685
*/
@@ -30593,10 +30734,14 @@
3059330734
xRead = ascii_read_one_field;
3059430735
}else if( cli_strcmp(z,"-csv")==0 ){
3059530736
if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
3059630737
if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
3059730738
xRead = csv_read_one_field;
30739
+ }else if( cli_strcmp(z,"-esc")==0 ){
30740
+ sCtx.cUQEscape = azArg[++i][0];
30741
+ }else if( cli_strcmp(z,"-qesc")==0 ){
30742
+ sCtx.cQEscape = azArg[++i][0];
3059830743
}else if( cli_strcmp(z,"-colsep")==0 ){
3059930744
if( i==nArg-1 ){
3060030745
dotCmdError(p, i, "missing argument", 0);
3060130746
return 1;
3060230747
}
@@ -33351,10 +33496,23 @@
3335133496
continue;
3335233497
}
3335333498
if( cli_strcmp(z,"once")==0 ){
3335433499
p->flgProgress |= SHELL_PROGRESS_ONCE;
3335533500
continue;
33501
+ }
33502
+ if( cli_strcmp(z,"timeout")==0 ){
33503
+ if( i==nArg-1 ){
33504
+ dotCmdError(p, i, "missing argument", 0);
33505
+ return 1;
33506
+ }
33507
+ i++;
33508
+ p->tmProgress = atof(azArg[i]);
33509
+ if( p->tmProgress>0.0 ){
33510
+ p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
33511
+ if( nn==0 ) nn = 100;
33512
+ }
33513
+ continue;
3335633514
}
3335733515
if( cli_strcmp(z,"limit")==0 ){
3335833516
if( i+1>=nArg ){
3335933517
eputz("Error: missing argument on --limit\n");
3336033518
rc = 1;
@@ -34843,17 +35001,21 @@
3484335001
sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
3484435002
}else
3484535003
3484635004
if( c=='t' && n>=5 && cli_strncmp(azArg[0], "timer", n)==0 ){
3484735005
if( nArg==2 ){
34848
- enableTimer = booleanValue(azArg[1]);
34849
- if( enableTimer && !HAS_TIMER ){
35006
+ if( cli_strcmp(azArg[1],"once")==0 ){
35007
+ p->enableTimer = 1;
35008
+ }else{
35009
+ p->enableTimer = 2*booleanValue(azArg[1]);
35010
+ }
35011
+ if( p->enableTimer && !HAS_TIMER ){
3485035012
eputz("Error: timer not available on this system.\n");
34851
- enableTimer = 0;
35013
+ p->enableTimer = 0;
3485235014
}
3485335015
}else{
34854
- eputz("Usage: .timer on|off\n");
35016
+ eputz("Usage: .timer on|off|once\n");
3485535017
rc = 1;
3485635018
}
3485735019
}else
3485835020
3485935021
#ifndef SQLITE_OMIT_TRACE
@@ -35024,10 +35186,11 @@
3502435186
if( p->nPopOutput ){
3502535187
p->nPopOutput--;
3502635188
if( p->nPopOutput==0 ) output_reset(p);
3502735189
}
3502835190
p->bSafeMode = p->bSafeModePersist;
35191
+ p->dot.nArg = 0;
3502935192
return rc;
3503035193
}
3503135194
3503235195
/* Line scan result and intermediate states (supporting scan resumption)
3503335196
*/
@@ -35260,13 +35423,13 @@
3526035423
char *zErrMsg = 0;
3526135424
3526235425
open_db(p, 0);
3526335426
if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
3526435427
if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
35265
- BEGIN_TIMER;
35428
+ BEGIN_TIMER(p);
3526635429
rc = shell_exec(p, zSql, &zErrMsg);
35267
- END_TIMER(p->out);
35430
+ END_TIMER(p);
3526835431
if( rc || zErrMsg ){
3526935432
char zPrefix[100];
3527035433
const char *zErrorTail;
3527135434
const char *zErrorType;
3527235435
if( zErrMsg==0 ){
3527335436
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -876,10 +876,11 @@
876 #ifndef SQLITE_QRF_H
877 #include "qrf.h"
878 #endif
879 #include <string.h>
880 #include <assert.h>
 
881
882 /* typedef sqlite3_int64 i64; */
883
884 /* A single line in the EQP output */
885 typedef struct qrfEQPGraphRow qrfEQPGraphRow;
@@ -893,11 +894,12 @@
893 /* All EQP output is collected into an instance of the following */
894 typedef struct qrfEQPGraph qrfEQPGraph;
895 struct qrfEQPGraph {
896 qrfEQPGraphRow *pRow; /* Linked list of all rows of the EQP output */
897 qrfEQPGraphRow *pLast; /* Last element of the pRow list */
898 char zPrefix[100]; /* Graph prefix */
 
899 };
900
901 /*
902 ** Private state information. Subject to change from one release to the
903 ** next.
@@ -1087,10 +1089,49 @@
1087 qrfEqpRenderLevel(p, pRow->iEqpId);
1088 p->u.pGraph->zPrefix[n] = 0;
1089 }
1090 }
1091 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1092
1093 /*
1094 ** Display and reset the EXPLAIN QUERY PLAN data
1095 */
1096 static void qrfEqpRender(Qrf *p, i64 nCycle){
@@ -1103,11 +1144,30 @@
1103 }
1104 sqlite3_str_appendf(p->pOut, "%s\n", pRow->zText+3);
1105 p->u.pGraph->pRow = pRow->pNext;
1106 sqlite3_free(pRow);
1107 }else if( nCycle>0 ){
1108 sqlite3_str_appendf(p->pOut, "QUERY PLAN (cycles=%lld [100%%])\n",nCycle);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1109 }else{
1110 sqlite3_str_appendall(p->pOut, "QUERY PLAN\n");
1111 }
1112 p->u.pGraph->zPrefix[0] = 0;
1113 qrfEqpRenderLevel(p, 0);
@@ -1158,10 +1218,12 @@
1158 static const int f = SQLITE_SCANSTAT_COMPLEX;
1159 sqlite3_stmt *pS = p->pStmt;
1160 int i = 0;
1161 i64 nTotal = 0;
1162 int nWidth = 0;
 
 
1163 sqlite3_str *pLine = sqlite3_str_new(p->db);
1164 sqlite3_str *pStats = sqlite3_str_new(p->db);
1165 qrfEqpReset(p);
1166
1167 for(i=0; 1; i++){
@@ -1171,11 +1233,11 @@
1171 break;
1172 }
1173 n = (int)strlen(z) + qrfStatsHeight(pS,i)*3;
1174 if( n>nWidth ) nWidth = n;
1175 }
1176 nWidth += 4;
1177
1178 sqlite3_stmt_scanstatus_v2(pS,-1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
1179 for(i=0; 1; i++){
1180 i64 nLoop = 0;
1181 i64 nRow = 0;
@@ -1186,54 +1248,64 @@
1186 const char *zName = 0;
1187 double rEst = 0.0;
1188
1189 if( sqlite3_stmt_scanstatus_v2(pS,i,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&zo) ){
1190 break;
 
 
 
 
 
1191 }
1192 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_EST,f,(void*)&rEst);
 
1193 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NLOOP,f,(void*)&nLoop);
1194 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NVISIT,f,(void*)&nRow);
1195 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NCYCLE,f,(void*)&nCycle);
1196 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_SELECTID,f,(void*)&iId);
1197 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_PARENTID,f,(void*)&iPid);
1198 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NAME,f,(void*)&zName);
1199
1200 if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
1201 const char *zSp = "";
1202 double rpl;
1203 sqlite3_str_reset(pStats);
1204 if( nCycle>=0 && nTotal>0 ){
1205 sqlite3_str_appendf(pStats, "cycles=%lld [%d%%]",
1206 nCycle, ((nCycle*100)+nTotal/2) / nTotal
 
1207 );
1208 zSp = " ";
1209 }
1210 if( nLoop>=0 ){
1211 sqlite3_str_appendf(pStats, "%sloops=%lld", zSp, nLoop);
1212 zSp = " ";
 
 
 
 
 
1213 }
1214 if( nRow>=0 ){
1215 sqlite3_str_appendf(pStats, "%srows=%lld", zSp, nRow);
1216 zSp = " ";
1217 }
1218
1219 if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1220 rpl = (double)nRow / (double)nLoop;
1221 sqlite3_str_appendf(pStats, "%srpl=%.1f est=%.1f", zSp, rpl, rEst);
1222 }
1223
1224 sqlite3_str_appendf(pLine,
1225 "% *s (%s)", -1*(nWidth-qrfStatsHeight(pS,i)*3), zo,
1226 sqlite3_str_value(pStats)
1227 );
1228 sqlite3_str_reset(pStats);
1229 qrfEqpAppend(p, iId, iPid, sqlite3_str_value(pLine));
1230 sqlite3_str_reset(pLine);
1231 }else{
1232 qrfEqpAppend(p, iId, iPid, zo);
1233 }
1234 }
 
1235 qrfStrErr(p, pLine);
1236 sqlite3_free(sqlite3_str_finish(pLine));
1237 qrfStrErr(p, pStats);
1238 sqlite3_free(sqlite3_str_finish(pStats));
1239 #endif
@@ -3664,11 +3736,20 @@
3664 sqlite3_free(p->u.sLine.azCol);
3665 }
3666 break;
3667 }
3668 case QRF_STYLE_Stats:
3669 case QRF_STYLE_StatsEst:
 
 
 
 
 
 
 
 
 
3670 case QRF_STYLE_Eqp: {
3671 qrfEqpRender(p, 0);
3672 qrfWrite(p);
3673 break;
3674 }
@@ -3836,13 +3917,10 @@
3836
3837
3838 #define eputz(z) cli_puts(z,stderr)
3839 #define sputz(fp,z) cli_puts(z,fp)
3840
3841 /* True if the timer is enabled */
3842 static int enableTimer = 0;
3843
3844 /* A version of strcmp() that works with NULL values */
3845 static int cli_strcmp(const char *a, const char *b){
3846 if( a==0 ) a = "";
3847 if( b==0 ) b = "";
3848 return strcmp(a,b);
@@ -3883,154 +3961,10 @@
3883 (void)gettimeofday(&sNow,0);
3884 return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
3885 #endif
3886 }
3887
3888 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
3889 #include <sys/time.h>
3890 #include <sys/resource.h>
3891
3892 /* VxWorks does not support getrusage() as far as we can determine */
3893 #if defined(_WRS_KERNEL) || defined(__RTP__)
3894 struct rusage {
3895 struct timeval ru_utime; /* user CPU time used */
3896 struct timeval ru_stime; /* system CPU time used */
3897 };
3898 #define getrusage(A,B) memset(B,0,sizeof(*B))
3899 #endif
3900
3901
3902 /* Saved resource information for the beginning of an operation */
3903 static struct rusage sBegin; /* CPU time at start */
3904 static sqlite3_int64 iBegin; /* Wall-clock time at start */
3905
3906 /*
3907 ** Begin timing an operation
3908 */
3909 static void beginTimer(void){
3910 if( enableTimer ){
3911 getrusage(RUSAGE_SELF, &sBegin);
3912 iBegin = timeOfDay();
3913 }
3914 }
3915
3916 /* Return the difference of two time_structs in seconds */
3917 static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
3918 return (pEnd->tv_usec - pStart->tv_usec)*0.000001 +
3919 (double)(pEnd->tv_sec - pStart->tv_sec);
3920 }
3921
3922 /*
3923 ** Print the timing results.
3924 */
3925 static void endTimer(FILE *out){
3926 if( enableTimer ){
3927 sqlite3_int64 iEnd = timeOfDay();
3928 struct rusage sEnd;
3929 getrusage(RUSAGE_SELF, &sEnd);
3930 cli_printf(out, "Run Time: real %.6f user %.6f sys %.6f\n",
3931 (iEnd - iBegin)*0.000001,
3932 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
3933 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
3934 }
3935 }
3936
3937 #define BEGIN_TIMER beginTimer()
3938 #define END_TIMER(X) endTimer(X)
3939 #define HAS_TIMER 1
3940
3941 #elif (defined(_WIN32) || defined(WIN32))
3942
3943 /* Saved resource information for the beginning of an operation */
3944 static HANDLE hProcess;
3945 static FILETIME ftKernelBegin;
3946 static FILETIME ftUserBegin;
3947 static sqlite3_int64 ftWallBegin;
3948 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
3949 LPFILETIME, LPFILETIME);
3950 static GETPROCTIMES getProcessTimesAddr = NULL;
3951
3952 /*
3953 ** Check to see if we have timer support. Return 1 if necessary
3954 ** support found (or found previously).
3955 */
3956 static int hasTimer(void){
3957 if( getProcessTimesAddr ){
3958 return 1;
3959 } else {
3960 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
3961 ** versions. See if the version we are running on has it, and if it
3962 ** does, save off a pointer to it and the current process handle.
3963 */
3964 hProcess = GetCurrentProcess();
3965 if( hProcess ){
3966 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
3967 if( NULL != hinstLib ){
3968 getProcessTimesAddr =
3969 (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
3970 if( NULL != getProcessTimesAddr ){
3971 return 1;
3972 }
3973 FreeLibrary(hinstLib);
3974 }
3975 }
3976 }
3977 return 0;
3978 }
3979
3980 /*
3981 ** Begin timing an operation
3982 */
3983 static void beginTimer(void){
3984 if( enableTimer && getProcessTimesAddr ){
3985 FILETIME ftCreation, ftExit;
3986 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
3987 &ftKernelBegin,&ftUserBegin);
3988 ftWallBegin = timeOfDay();
3989 }
3990 }
3991
3992 /* Return the difference of two FILETIME structs in seconds */
3993 static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
3994 sqlite_int64 i64Start = *((sqlite_int64 *) pStart);
3995 sqlite_int64 i64End = *((sqlite_int64 *) pEnd);
3996 return (double) ((i64End - i64Start) / 10000000.0);
3997 }
3998
3999 /*
4000 ** Print the timing results.
4001 */
4002 static void endTimer(FILE *out){
4003 if( enableTimer && getProcessTimesAddr){
4004 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
4005 sqlite3_int64 ftWallEnd = timeOfDay();
4006 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
4007 #ifdef _WIN64
4008 /* microsecond precision on 64-bit windows */
4009 cli_printf(out, "Run Time: real %.6f user %f sys %f\n",
4010 (ftWallEnd - ftWallBegin)*0.000001,
4011 timeDiff(&ftUserBegin, &ftUserEnd),
4012 timeDiff(&ftKernelBegin, &ftKernelEnd));
4013 #else
4014 /* millisecond precisino on 32-bit windows */
4015 cli_printf(out, "Run Time: real %.3f user %.3f sys %.3f\n",
4016 (ftWallEnd - ftWallBegin)*0.000001,
4017 timeDiff(&ftUserBegin, &ftUserEnd),
4018 timeDiff(&ftKernelBegin, &ftKernelEnd));
4019 #endif
4020 }
4021 }
4022
4023 #define BEGIN_TIMER beginTimer()
4024 #define END_TIMER(X) endTimer(X)
4025 #define HAS_TIMER hasTimer()
4026
4027 #else
4028 #define BEGIN_TIMER
4029 #define END_TIMER(X) /*no-op*/
4030 #define HAS_TIMER 0
4031 #endif
4032
4033 /*
4034 ** Used to prevent warnings about unused parameters
4035 */
4036 #define UNUSED_PARAMETER(x) (void)(x)
@@ -24226,11 +24160,14 @@
24226 u8 eRestoreState; /* See comments above doAutoDetectRestore() */
24227 unsigned statsOn; /* True to display memory stats before each finalize */
24228 unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
24229 u8 nPopOutput; /* Revert .output settings when reaching zero */
24230 u8 nPopMode; /* Revert .mode settings when reaching zero */
 
24231 int inputNesting; /* Track nesting level of .read and other redirects */
 
 
24232 i64 lineno; /* Line number of last line read from in */
24233 const char *zInFile; /* Name of the input file */
24234 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
24235 FILE *in; /* Read commands from this stream */
24236 FILE *out; /* Write results here */
@@ -24322,10 +24259,11 @@
24322 #define SHELL_PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */
24323 #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress
24324 ** callback limit is reached, and for each
24325 ** top-level SQL statement */
24326 #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
 
24327
24328 /* Names of values for Mode.spec.eEsc and Mode.spec.eText
24329 */
24330 static const char *qrfEscNames[] = { "auto", "off", "ascii", "symbol" };
24331 static const char *qrfQuoteNames[] =
@@ -24483,10 +24421,185 @@
24483 ** Limit input nesting via .read or any other input redirect.
24484 ** It's not too expensive, so a generous allowance can be made.
24485 */
24486 #define MAX_INPUT_NESTING 25
24487
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24488
24489 /*
24490 ** Clear a display mode, freeing any allocated memory that it
24491 ** contains.
24492 */
@@ -25408,10 +25521,17 @@
25408 ** Progress handler callback.
25409 */
25410 static int progress_handler(void *pClientData) {
25411 ShellState *p = (ShellState*)pClientData;
25412 p->nProgress++;
 
 
 
 
 
 
 
25413 if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){
25414 cli_printf(p->out, "Progress limit reached (%u)\n", p->nProgress);
25415 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
25416 if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0;
25417 return 1;
@@ -25945,10 +26065,12 @@
25945 char *zBuf = sqlite3_malloc64( szVar-5 );
25946 if( zBuf ){
25947 memcpy(zBuf, &zVar[6], szVar-5);
25948 sqlite3_bind_text64(pStmt, i, zBuf, szVar-6, sqlite3_free, SQLITE_UTF8);
25949 }
 
 
25950 #ifdef SQLITE_ENABLE_CARRAY
25951 }else if( strncmp(zVar, "$carray_", 8)==0 ){
25952 static char *azColorNames[] = {
25953 "azure", "black", "blue", "brown", "cyan", "fuchsia", "gold",
25954 "gray", "green", "indigo", "khaki", "lime", "magenta", "maroon",
@@ -26204,12 +26326,14 @@
26204 pArg->pStmt = pStmt;
26205 }
26206
26207 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
26208 isExplain = sqlite3_stmt_isexplain(pStmt);
26209 if( pArg && pArg->mode.autoEQP && isExplain==0 ){
26210 int triggerEQP = 0;
 
 
26211 disable_debug_trace_modes();
26212 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
26213 if( pArg->mode.autoEQP>=AUTOEQP_trigger ){
26214 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
26215 }
@@ -26227,10 +26351,11 @@
26227 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0);
26228 }
26229 sqlite3_reset(pStmt);
26230 sqlite3_stmt_explain(pStmt, 0);
26231 restore_debug_trace_modes();
 
26232 }
26233
26234 bind_prepared_stmt(pArg, pStmt);
26235 if( isExplain && pArg->mode.autoExplain ){
26236 spec.eStyle = isExplain==1 ? QRF_STYLE_Explain : QRF_STYLE_Eqp;
@@ -26764,10 +26889,11 @@
26764 ".progress N Invoke progress handler after every N opcodes",
26765 " --limit N Interrupt after N progress callbacks",
26766 " --once Do no more than one progress interrupt",
26767 " --quiet|-q No output except at interrupts",
26768 " --reset Reset the count for each input and interrupt",
 
26769 #endif
26770 ".prompt MAIN CONTINUE Replace the standard prompts",
26771 #ifndef SQLITE_SHELL_FIDDLE
26772 ".quit Stop interpreting input stream, exit if primary.",
26773 ".read FILE Read input from FILE or command output",
@@ -26832,11 +26958,11 @@
26832 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
26833 ".testcase NAME Begin a test case.",
26834 ",testctrl CMD ... Run various sqlite3_test_control() operations",
26835 " Run \".testctrl\" with no arguments for details",
26836 ".timeout MS Try opening locked tables for MS milliseconds",
26837 ".timer on|off Turn SQL timer on or off",
26838 #ifndef SQLITE_OMIT_TRACE
26839 ".trace ?OPTIONS? Output each SQL statement as it is run",
26840 " FILE Send output to FILE",
26841 " stdout Send output to stdout",
26842 " stderr Send output to stderr",
@@ -26897,10 +27023,12 @@
26897 " --ascii Do not use RFC-4180 quoting. Use \\037 and \\036\n"
26898 " as column and row separators on input, unless other\n"
26899 " delimiters are specified using --colsep and/or --rowsep\n"
26900 " --colsep CHAR Use CHAR as the column separator.\n"
26901 " --csv Input is standard RFC-4180 CSV.\n"
 
 
26902 " --rowsep CHAR Use CHAR as the row separator.\n"
26903 " --schema S When creating TABLE, put it in schema S\n"
26904 " --skip N Ignore the first N rows of input\n"
26905 " -v Verbose mode\n"
26906 },
@@ -28054,10 +28182,12 @@
28054 int nErr; /* Number of errors encountered */
28055 int bNotFirst; /* True if one or more bytes already read */
28056 int cTerm; /* Character that terminated the most recent field */
28057 int cColSep; /* The column separator character. (Usually ",") */
28058 int cRowSep; /* The row separator character. (Usually "\n") */
 
 
28059 };
28060
28061 /* Clean up resourced used by an ImportCtx */
28062 static void import_cleanup(ImportCtx *p){
28063 if( p->in!=0 && p->xCloser!=0 ){
@@ -28122,14 +28252,21 @@
28122 }
28123 if( c=='"' ){
28124 int pc, ppc;
28125 int startLine = p->nLine;
28126 int cQuote = c;
 
28127 pc = ppc = 0;
28128 while( 1 ){
28129 c = import_getc(p);
28130 if( c==rSep ) p->nLine++;
 
 
 
 
 
 
28131 if( c==cQuote ){
28132 if( pc==cQuote ){
28133 pc = 0;
28134 continue;
28135 }
@@ -28143,11 +28280,11 @@
28143 p->cTerm = c;
28144 break;
28145 }
28146 if( pc==cQuote && c!='\r' ){
28147 cli_printf(stderr,"%s:%d: unescaped %c character\n",
28148 p->zFile, p->nLine, cQuote);
28149 }
28150 if( c==EOF ){
28151 cli_printf(stderr,"%s:%d: unterminated %c-quoted field\n",
28152 p->zFile, startLine, cQuote);
28153 p->cTerm = c;
@@ -28158,10 +28295,11 @@
28158 pc = c;
28159 }
28160 }else{
28161 /* If this is the first field being parsed and it begins with the
28162 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */
 
28163 if( (c&0xff)==0xef && p->bNotFirst==0 ){
28164 import_append_char(p, c);
28165 c = import_getc(p);
28166 if( (c&0xff)==0xbb ){
28167 import_append_char(p, c);
@@ -28172,10 +28310,11 @@
28172 return csv_read_one_field(p);
28173 }
28174 }
28175 }
28176 while( c!=EOF && c!=cSep && c!=rSep ){
 
28177 import_append_char(p, c);
28178 c = import_getc(p);
28179 }
28180 if( c==rSep ){
28181 p->nLine++;
@@ -30315,11 +30454,11 @@
30315 ;
30316 static const char * const zCollectVar = "\
30317 SELECT\
30318 '('||x'0a'\
30319 || group_concat(\
30320 cname||' TEXT',\
30321 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
30322 ||')' AS ColsSpec \
30323 FROM (\
30324 SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \
30325 FROM ColNames ORDER BY cpos\
@@ -30535,10 +30674,12 @@
30535 ** --ascii Do not use RFC-4180 quoting. Use \037 and \036
30536 ** as column and row separators on input, unless other
30537 ** delimiters are specified using --colsep and/or --rowsep
30538 ** --colsep CHAR Use CHAR as the column separator.
30539 ** --csv Input is standard RFC-4180 CSV.
 
 
30540 ** --rowsep CHAR Use CHAR as the row separator.
30541 ** --schema S When creating TABLE, put it in schema S
30542 ** --skip N Ignore the first N rows of input
30543 ** -v Verbose mode
30544 */
@@ -30593,10 +30734,14 @@
30593 xRead = ascii_read_one_field;
30594 }else if( cli_strcmp(z,"-csv")==0 ){
30595 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
30596 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
30597 xRead = csv_read_one_field;
 
 
 
 
30598 }else if( cli_strcmp(z,"-colsep")==0 ){
30599 if( i==nArg-1 ){
30600 dotCmdError(p, i, "missing argument", 0);
30601 return 1;
30602 }
@@ -33351,10 +33496,23 @@
33351 continue;
33352 }
33353 if( cli_strcmp(z,"once")==0 ){
33354 p->flgProgress |= SHELL_PROGRESS_ONCE;
33355 continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
33356 }
33357 if( cli_strcmp(z,"limit")==0 ){
33358 if( i+1>=nArg ){
33359 eputz("Error: missing argument on --limit\n");
33360 rc = 1;
@@ -34843,17 +35001,21 @@
34843 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
34844 }else
34845
34846 if( c=='t' && n>=5 && cli_strncmp(azArg[0], "timer", n)==0 ){
34847 if( nArg==2 ){
34848 enableTimer = booleanValue(azArg[1]);
34849 if( enableTimer && !HAS_TIMER ){
 
 
 
 
34850 eputz("Error: timer not available on this system.\n");
34851 enableTimer = 0;
34852 }
34853 }else{
34854 eputz("Usage: .timer on|off\n");
34855 rc = 1;
34856 }
34857 }else
34858
34859 #ifndef SQLITE_OMIT_TRACE
@@ -35024,10 +35186,11 @@
35024 if( p->nPopOutput ){
35025 p->nPopOutput--;
35026 if( p->nPopOutput==0 ) output_reset(p);
35027 }
35028 p->bSafeMode = p->bSafeModePersist;
 
35029 return rc;
35030 }
35031
35032 /* Line scan result and intermediate states (supporting scan resumption)
35033 */
@@ -35260,13 +35423,13 @@
35260 char *zErrMsg = 0;
35261
35262 open_db(p, 0);
35263 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
35264 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
35265 BEGIN_TIMER;
35266 rc = shell_exec(p, zSql, &zErrMsg);
35267 END_TIMER(p->out);
35268 if( rc || zErrMsg ){
35269 char zPrefix[100];
35270 const char *zErrorTail;
35271 const char *zErrorType;
35272 if( zErrMsg==0 ){
35273
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -876,10 +876,11 @@
876 #ifndef SQLITE_QRF_H
877 #include "qrf.h"
878 #endif
879 #include <string.h>
880 #include <assert.h>
881 #include <stdint.h>
882
883 /* typedef sqlite3_int64 i64; */
884
885 /* A single line in the EQP output */
886 typedef struct qrfEQPGraphRow qrfEQPGraphRow;
@@ -893,11 +894,12 @@
894 /* All EQP output is collected into an instance of the following */
895 typedef struct qrfEQPGraph qrfEQPGraph;
896 struct qrfEQPGraph {
897 qrfEQPGraphRow *pRow; /* Linked list of all rows of the EQP output */
898 qrfEQPGraphRow *pLast; /* Last element of the pRow list */
899 int nWidth; /* Width of the graph */
900 char zPrefix[400]; /* Graph prefix */
901 };
902
903 /*
904 ** Private state information. Subject to change from one release to the
905 ** next.
@@ -1087,10 +1089,49 @@
1089 qrfEqpRenderLevel(p, pRow->iEqpId);
1090 p->u.pGraph->zPrefix[n] = 0;
1091 }
1092 }
1093 }
1094
1095 /*
1096 ** Render the 64-bit value N in a more human-readable format into
1097 ** pOut.
1098 **
1099 ** + Only show the first three significant digits.
1100 ** + Append suffixes K, M, G, T, P, and E for 1e3, 1e6, ... 1e18
1101 */
1102 static void qrfApproxInt64(sqlite3_str *pOut, i64 N){
1103 static const char aSuffix[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
1104 int i;
1105 if( N<0 ){
1106 N = N==INT64_MIN ? INT64_MAX : -N;
1107 sqlite3_str_append(pOut, "-", 1);
1108 }
1109 if( N<10000 ){
1110 sqlite3_str_appendf(pOut, "%4lld ", N);
1111 return;
1112 }
1113 for(i=1; i<=18; i++){
1114 N = (N+5)/10;
1115 if( N<10000 ){
1116 int n = (int)N;
1117 switch( i%3 ){
1118 case 0:
1119 sqlite3_str_appendf(pOut, "%d.%02d", n/1000, (n%1000)/10);
1120 break;
1121 case 1:
1122 sqlite3_str_appendf(pOut, "%2d.%d", n/100, (n%100)/10);
1123 break;
1124 case 2:
1125 sqlite3_str_appendf(pOut, "%4d", n/10);
1126 break;
1127 }
1128 sqlite3_str_append(pOut, &aSuffix[i/3], 1);
1129 break;
1130 }
1131 }
1132 }
1133
1134 /*
1135 ** Display and reset the EXPLAIN QUERY PLAN data
1136 */
1137 static void qrfEqpRender(Qrf *p, i64 nCycle){
@@ -1103,11 +1144,30 @@
1144 }
1145 sqlite3_str_appendf(p->pOut, "%s\n", pRow->zText+3);
1146 p->u.pGraph->pRow = pRow->pNext;
1147 sqlite3_free(pRow);
1148 }else if( nCycle>0 ){
1149 int nSp = p->u.pGraph->nWidth - 2;
1150 if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1151 sqlite3_str_appendchar(p->pOut, nSp, ' ');
1152 sqlite3_str_appendall(p->pOut,
1153 "Cycles Loops (est) Rows (est)\n");
1154 sqlite3_str_appendchar(p->pOut, nSp, ' ');
1155 sqlite3_str_appendall(p->pOut,
1156 "---------- ------------ ------------\n");
1157 }else{
1158 sqlite3_str_appendchar(p->pOut, nSp, ' ');
1159 sqlite3_str_appendall(p->pOut,
1160 "Cycles Loops Rows \n");
1161 sqlite3_str_appendchar(p->pOut, nSp, ' ');
1162 sqlite3_str_appendall(p->pOut,
1163 "---------- ----- -----\n");
1164 }
1165 sqlite3_str_appendall(p->pOut, "QUERY PLAN");
1166 sqlite3_str_appendchar(p->pOut, nSp - 10, ' ');
1167 qrfApproxInt64(p->pOut, nCycle);
1168 sqlite3_str_appendall(p->pOut, " 100%\n");
1169 }else{
1170 sqlite3_str_appendall(p->pOut, "QUERY PLAN\n");
1171 }
1172 p->u.pGraph->zPrefix[0] = 0;
1173 qrfEqpRenderLevel(p, 0);
@@ -1158,10 +1218,12 @@
1218 static const int f = SQLITE_SCANSTAT_COMPLEX;
1219 sqlite3_stmt *pS = p->pStmt;
1220 int i = 0;
1221 i64 nTotal = 0;
1222 int nWidth = 0;
1223 int prevPid = -1; /* Previous iPid */
1224 double rEstCum = 1.0; /* Cumulative row estimate */
1225 sqlite3_str *pLine = sqlite3_str_new(p->db);
1226 sqlite3_str *pStats = sqlite3_str_new(p->db);
1227 qrfEqpReset(p);
1228
1229 for(i=0; 1; i++){
@@ -1171,11 +1233,11 @@
1233 break;
1234 }
1235 n = (int)strlen(z) + qrfStatsHeight(pS,i)*3;
1236 if( n>nWidth ) nWidth = n;
1237 }
1238 nWidth += 2;
1239
1240 sqlite3_stmt_scanstatus_v2(pS,-1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
1241 for(i=0; 1; i++){
1242 i64 nLoop = 0;
1243 i64 nRow = 0;
@@ -1186,54 +1248,64 @@
1248 const char *zName = 0;
1249 double rEst = 0.0;
1250
1251 if( sqlite3_stmt_scanstatus_v2(pS,i,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&zo) ){
1252 break;
1253 }
1254 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_PARENTID,f,(void*)&iPid);
1255 if( iPid!=prevPid ){
1256 prevPid = iPid;
1257 rEstCum = 1.0;
1258 }
1259 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_EST,f,(void*)&rEst);
1260 rEstCum *= rEst;
1261 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NLOOP,f,(void*)&nLoop);
1262 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NVISIT,f,(void*)&nRow);
1263 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NCYCLE,f,(void*)&nCycle);
1264 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_SELECTID,f,(void*)&iId);
 
1265 sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NAME,f,(void*)&zName);
1266
1267 if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
1268 int nSp = 0;
 
1269 sqlite3_str_reset(pStats);
1270 if( nCycle>=0 && nTotal>0 ){
1271 qrfApproxInt64(pStats, nCycle);
1272 sqlite3_str_appendf(pStats, " %3d%%",
1273 ((nCycle*100)+nTotal/2) / nTotal
1274 );
1275 nSp = 2;
1276 }
1277 if( nLoop>=0 ){
1278 if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
1279 qrfApproxInt64(pStats, nLoop);
1280 nSp = 2;
1281 if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1282 sqlite3_str_appendf(pStats, " ");
1283 qrfApproxInt64(pStats, (i64)(rEstCum/rEst));
1284 }
1285 }
1286 if( nRow>=0 ){
1287 if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
1288 qrfApproxInt64(pStats, nRow);
1289 nSp = 2;
1290 if( p->spec.eStyle==QRF_STYLE_StatsEst ){
1291 sqlite3_str_appendf(pStats, " ");
1292 qrfApproxInt64(pStats, (i64)rEstCum);
1293 }
1294 }
 
1295 sqlite3_str_appendf(pLine,
1296 "% *s %s", -1*(nWidth-qrfStatsHeight(pS,i)*3), zo,
1297 sqlite3_str_value(pStats)
1298 );
1299 sqlite3_str_reset(pStats);
1300 qrfEqpAppend(p, iId, iPid, sqlite3_str_value(pLine));
1301 sqlite3_str_reset(pLine);
1302 }else{
1303 qrfEqpAppend(p, iId, iPid, zo);
1304 }
1305 }
1306 if( p->u.pGraph ) p->u.pGraph->nWidth = nWidth;
1307 qrfStrErr(p, pLine);
1308 sqlite3_free(sqlite3_str_finish(pLine));
1309 qrfStrErr(p, pStats);
1310 sqlite3_free(sqlite3_str_finish(pStats));
1311 #endif
@@ -3664,11 +3736,20 @@
3736 sqlite3_free(p->u.sLine.azCol);
3737 }
3738 break;
3739 }
3740 case QRF_STYLE_Stats:
3741 case QRF_STYLE_StatsEst: {
3742 i64 nCycle = 0;
3743 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
3744 sqlite3_stmt_scanstatus_v2(p->pStmt, -1, SQLITE_SCANSTAT_NCYCLE,
3745 SQLITE_SCANSTAT_COMPLEX, (void*)&nCycle);
3746 #endif
3747 qrfEqpRender(p, nCycle);
3748 qrfWrite(p);
3749 break;
3750 }
3751 case QRF_STYLE_Eqp: {
3752 qrfEqpRender(p, 0);
3753 qrfWrite(p);
3754 break;
3755 }
@@ -3836,13 +3917,10 @@
3917
3918
3919 #define eputz(z) cli_puts(z,stderr)
3920 #define sputz(fp,z) cli_puts(z,fp)
3921
 
 
 
3922 /* A version of strcmp() that works with NULL values */
3923 static int cli_strcmp(const char *a, const char *b){
3924 if( a==0 ) a = "";
3925 if( b==0 ) b = "";
3926 return strcmp(a,b);
@@ -3883,154 +3961,10 @@
3961 (void)gettimeofday(&sNow,0);
3962 return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
3963 #endif
3964 }
3965
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3966
3967 /*
3968 ** Used to prevent warnings about unused parameters
3969 */
3970 #define UNUSED_PARAMETER(x) (void)(x)
@@ -24226,11 +24160,14 @@
24160 u8 eRestoreState; /* See comments above doAutoDetectRestore() */
24161 unsigned statsOn; /* True to display memory stats before each finalize */
24162 unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
24163 u8 nPopOutput; /* Revert .output settings when reaching zero */
24164 u8 nPopMode; /* Revert .mode settings when reaching zero */
24165 u8 enableTimer; /* Enable the timer. 2: permanently 1: only once */
24166 int inputNesting; /* Track nesting level of .read and other redirects */
24167 double prevTimer; /* Last reported timer value */
24168 double tmProgress; /* --timeout option for .progress */
24169 i64 lineno; /* Line number of last line read from in */
24170 const char *zInFile; /* Name of the input file */
24171 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
24172 FILE *in; /* Read commands from this stream */
24173 FILE *out; /* Write results here */
@@ -24322,10 +24259,11 @@
24259 #define SHELL_PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */
24260 #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress
24261 ** callback limit is reached, and for each
24262 ** top-level SQL statement */
24263 #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
24264 #define SHELL_PROGRESS_TMOUT 0x08 /* Stop after tmProgress seconds */
24265
24266 /* Names of values for Mode.spec.eEsc and Mode.spec.eText
24267 */
24268 static const char *qrfEscNames[] = { "auto", "off", "ascii", "symbol" };
24269 static const char *qrfQuoteNames[] =
@@ -24483,10 +24421,185 @@
24421 ** Limit input nesting via .read or any other input redirect.
24422 ** It's not too expensive, so a generous allowance can be made.
24423 */
24424 #define MAX_INPUT_NESTING 25
24425
24426 /************************* BEGIN PERFORMANCE TIMER *****************************/
24427 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
24428 #include <sys/time.h>
24429 #include <sys/resource.h>
24430 /* VxWorks does not support getrusage() as far as we can determine */
24431 #if defined(_WRS_KERNEL) || defined(__RTP__)
24432 struct rusage {
24433 struct timeval ru_utime; /* user CPU time used */
24434 struct timeval ru_stime; /* system CPU time used */
24435 };
24436 #define getrusage(A,B) memset(B,0,sizeof(*B))
24437 #endif
24438
24439 /* Saved resource information for the beginning of an operation */
24440 static struct rusage sBegin; /* CPU time at start */
24441 static sqlite3_int64 iBegin; /* Wall-clock time at start */
24442
24443 /*
24444 ** Begin timing an operation
24445 */
24446 static void beginTimer(ShellState *p){
24447 if( p->enableTimer || (p->flgProgress & SHELL_PROGRESS_TMOUT)!=0 ){
24448 getrusage(RUSAGE_SELF, &sBegin);
24449 iBegin = timeOfDay();
24450 }
24451 }
24452
24453 /* Return the difference of two time_structs in seconds */
24454 static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
24455 return (pEnd->tv_usec - pStart->tv_usec)*0.000001 +
24456 (double)(pEnd->tv_sec - pStart->tv_sec);
24457 }
24458
24459 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
24460 /* Return the time since the start of the timer in
24461 ** seconds. */
24462 static double elapseTime(ShellState *NotUsed){
24463 (void)NotUsed;
24464 if( iBegin==0 ) return 0.0;
24465 return (timeOfDay() - iBegin)*0.000001;
24466 }
24467 #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
24468
24469 /*
24470 ** Print the timing results.
24471 */
24472 static void endTimer(ShellState *p){
24473 if( p->enableTimer ){
24474 sqlite3_int64 iEnd = timeOfDay();
24475 struct rusage sEnd;
24476 getrusage(RUSAGE_SELF, &sEnd);
24477 p->prevTimer = (iEnd - iBegin)*0.000001;
24478 cli_printf(p->out, "Run Time: real %.6f user %.6f sys %.6f\n",
24479 p->prevTimer,
24480 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
24481 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
24482 if( p->enableTimer==1 ) p->enableTimer = 0;
24483 iBegin = 0;
24484 }
24485 }
24486
24487 #define BEGIN_TIMER(X) beginTimer(X)
24488 #define END_TIMER(X) endTimer(X)
24489 #define ELAPSE_TIME(X) elapseTime(X)
24490 #define HAS_TIMER 1
24491
24492 #elif (defined(_WIN32) || defined(WIN32))
24493
24494 /* Saved resource information for the beginning of an operation */
24495 static HANDLE hProcess;
24496 static FILETIME ftKernelBegin;
24497 static FILETIME ftUserBegin;
24498 static sqlite3_int64 ftWallBegin;
24499 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
24500 LPFILETIME, LPFILETIME);
24501 static GETPROCTIMES getProcessTimesAddr = NULL;
24502
24503 /*
24504 ** Check to see if we have timer support. Return 1 if necessary
24505 ** support found (or found previously).
24506 */
24507 static int hasTimer(void){
24508 if( getProcessTimesAddr ){
24509 return 1;
24510 } else {
24511 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
24512 ** versions. See if the version we are running on has it, and if it
24513 ** does, save off a pointer to it and the current process handle.
24514 */
24515 hProcess = GetCurrentProcess();
24516 if( hProcess ){
24517 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
24518 if( NULL != hinstLib ){
24519 getProcessTimesAddr =
24520 (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
24521 if( NULL != getProcessTimesAddr ){
24522 return 1;
24523 }
24524 FreeLibrary(hinstLib);
24525 }
24526 }
24527 }
24528 return 0;
24529 }
24530
24531 /*
24532 ** Begin timing an operation
24533 */
24534 static void beginTimer(ShellState *p){
24535 if( (p->enableTimer || (p->flgProgress & SHELL_PROGRESS_TMOUT)!=0)
24536 && getProcessTimesAddr
24537 ){
24538 FILETIME ftCreation, ftExit;
24539 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
24540 &ftKernelBegin,&ftUserBegin);
24541 ftWallBegin = timeOfDay();
24542 }
24543 }
24544
24545 /* Return the difference of two FILETIME structs in seconds */
24546 static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
24547 sqlite_int64 i64Start = *((sqlite_int64 *) pStart);
24548 sqlite_int64 i64End = *((sqlite_int64 *) pEnd);
24549 return (double) ((i64End - i64Start) / 10000000.0);
24550 }
24551
24552 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
24553 /* Return the time since the start of the timer in
24554 ** seconds. */
24555 static double elapseTime(ShellState *NotUsed){
24556 (void)NotUsed;
24557 if( ftWallBegin==0 ) return 0.0;
24558 return (timeOfDay() - ftWallBegin)*0.000001;
24559 }
24560 #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
24561
24562 /*
24563 ** Print the timing results.
24564 */
24565 static void endTimer(ShellState *p){
24566 if( p->enableTimer && getProcessTimesAddr){
24567 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
24568 sqlite3_int64 ftWallEnd = timeOfDay();
24569 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
24570 p->prevTimer = (ftWallEnd - ftWallBegin)*0.000001;
24571 #ifdef _WIN64
24572 /* microsecond precision on 64-bit windows */
24573 cli_printf(p->out, "Run Time: real %.6f user %f sys %f\n",
24574 p->prevTimer,
24575 timeDiff(&ftUserBegin, &ftUserEnd),
24576 timeDiff(&ftKernelBegin, &ftKernelEnd));
24577 #else
24578 /* millisecond precisino on 32-bit windows */
24579 cli_printf(p->out, "Run Time: real %.3f user %.3f sys %.3f\n",
24580 p->prevTimer,
24581 timeDiff(&ftUserBegin, &ftUserEnd),
24582 timeDiff(&ftKernelBegin, &ftKernelEnd));
24583 #endif
24584 if( p->enableTimer==1 ) p->enableTimer = 0;
24585 ftWallBegin = 0;
24586 }
24587 }
24588
24589 #define BEGIN_TIMER(X) beginTimer(X)
24590 #define ELAPSE_TIME(X) elapseTime(X)
24591 #define END_TIMER(X) endTimer(X)
24592 #define HAS_TIMER hasTimer()
24593
24594 #else
24595 #define BEGIN_TIMER(X) /* no-op */
24596 #define ELAPSE_TIME(X) 0.0
24597 #define END_TIMER(X) /*no-op*/
24598 #define HAS_TIMER 0
24599 #endif
24600 /************************* END PERFORMANCE TIMER ******************************/
24601
24602 /*
24603 ** Clear a display mode, freeing any allocated memory that it
24604 ** contains.
24605 */
@@ -25408,10 +25521,17 @@
25521 ** Progress handler callback.
25522 */
25523 static int progress_handler(void *pClientData) {
25524 ShellState *p = (ShellState*)pClientData;
25525 p->nProgress++;
25526 if( (p->flgProgress & SHELL_PROGRESS_TMOUT)!=0
25527 && ELAPSE_TIME(p)>=p->tmProgress
25528 ){
25529 cli_printf(p->out, "Progress timeout after %.6f seconds\n",
25530 ELAPSE_TIME(p));
25531 return 1;
25532 }
25533 if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){
25534 cli_printf(p->out, "Progress limit reached (%u)\n", p->nProgress);
25535 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
25536 if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0;
25537 return 1;
@@ -25945,10 +26065,12 @@
26065 char *zBuf = sqlite3_malloc64( szVar-5 );
26066 if( zBuf ){
26067 memcpy(zBuf, &zVar[6], szVar-5);
26068 sqlite3_bind_text64(pStmt, i, zBuf, szVar-6, sqlite3_free, SQLITE_UTF8);
26069 }
26070 }else if( strcmp(zVar, "$TIMER")==0 ){
26071 sqlite3_bind_double(pStmt, i, pArg->prevTimer);
26072 #ifdef SQLITE_ENABLE_CARRAY
26073 }else if( strncmp(zVar, "$carray_", 8)==0 ){
26074 static char *azColorNames[] = {
26075 "azure", "black", "blue", "brown", "cyan", "fuchsia", "gold",
26076 "gray", "green", "indigo", "khaki", "lime", "magenta", "maroon",
@@ -26204,12 +26326,14 @@
26326 pArg->pStmt = pStmt;
26327 }
26328
26329 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
26330 isExplain = sqlite3_stmt_isexplain(pStmt);
26331 if( pArg && pArg->mode.autoEQP && isExplain==0 && pArg->dot.nArg==0 ){
26332 int triggerEQP = 0;
26333 u8 savedEnableTimer = pArg->enableTimer;
26334 pArg->enableTimer = 0;
26335 disable_debug_trace_modes();
26336 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
26337 if( pArg->mode.autoEQP>=AUTOEQP_trigger ){
26338 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
26339 }
@@ -26227,10 +26351,11 @@
26351 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0);
26352 }
26353 sqlite3_reset(pStmt);
26354 sqlite3_stmt_explain(pStmt, 0);
26355 restore_debug_trace_modes();
26356 pArg->enableTimer = savedEnableTimer;
26357 }
26358
26359 bind_prepared_stmt(pArg, pStmt);
26360 if( isExplain && pArg->mode.autoExplain ){
26361 spec.eStyle = isExplain==1 ? QRF_STYLE_Explain : QRF_STYLE_Eqp;
@@ -26764,10 +26889,11 @@
26889 ".progress N Invoke progress handler after every N opcodes",
26890 " --limit N Interrupt after N progress callbacks",
26891 " --once Do no more than one progress interrupt",
26892 " --quiet|-q No output except at interrupts",
26893 " --reset Reset the count for each input and interrupt",
26894 " --timeout S Halt after running for S seconds",
26895 #endif
26896 ".prompt MAIN CONTINUE Replace the standard prompts",
26897 #ifndef SQLITE_SHELL_FIDDLE
26898 ".quit Stop interpreting input stream, exit if primary.",
26899 ".read FILE Read input from FILE or command output",
@@ -26832,11 +26958,11 @@
26958 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
26959 ".testcase NAME Begin a test case.",
26960 ",testctrl CMD ... Run various sqlite3_test_control() operations",
26961 " Run \".testctrl\" with no arguments for details",
26962 ".timeout MS Try opening locked tables for MS milliseconds",
26963 ".timer on|off|once Turn SQL timer on or off.",
26964 #ifndef SQLITE_OMIT_TRACE
26965 ".trace ?OPTIONS? Output each SQL statement as it is run",
26966 " FILE Send output to FILE",
26967 " stdout Send output to stdout",
26968 " stderr Send output to stderr",
@@ -26897,10 +27023,12 @@
27023 " --ascii Do not use RFC-4180 quoting. Use \\037 and \\036\n"
27024 " as column and row separators on input, unless other\n"
27025 " delimiters are specified using --colsep and/or --rowsep\n"
27026 " --colsep CHAR Use CHAR as the column separator.\n"
27027 " --csv Input is standard RFC-4180 CSV.\n"
27028 " --esc CHAR Use CHAR as an escape character in unquoted CSV inputs.\n"
27029 " --qesc CHAR Use CHAR as an escape character in quoted CSV inputs.\n"
27030 " --rowsep CHAR Use CHAR as the row separator.\n"
27031 " --schema S When creating TABLE, put it in schema S\n"
27032 " --skip N Ignore the first N rows of input\n"
27033 " -v Verbose mode\n"
27034 },
@@ -28054,10 +28182,12 @@
28182 int nErr; /* Number of errors encountered */
28183 int bNotFirst; /* True if one or more bytes already read */
28184 int cTerm; /* Character that terminated the most recent field */
28185 int cColSep; /* The column separator character. (Usually ",") */
28186 int cRowSep; /* The row separator character. (Usually "\n") */
28187 int cQEscape; /* Escape character with "...". 0 for none */
28188 int cUQEscape; /* Escape character not with "...". 0 for none */
28189 };
28190
28191 /* Clean up resourced used by an ImportCtx */
28192 static void import_cleanup(ImportCtx *p){
28193 if( p->in!=0 && p->xCloser!=0 ){
@@ -28122,14 +28252,21 @@
28252 }
28253 if( c=='"' ){
28254 int pc, ppc;
28255 int startLine = p->nLine;
28256 int cQuote = c;
28257 int cEsc = (u8)p->cQEscape;
28258 pc = ppc = 0;
28259 while( 1 ){
28260 c = import_getc(p);
28261 if( c==rSep ) p->nLine++;
28262 if( c==cEsc && cEsc!=0 ){
28263 c = import_getc(p);
28264 import_append_char(p, c);
28265 ppc = pc = 0;
28266 continue;
28267 }
28268 if( c==cQuote ){
28269 if( pc==cQuote ){
28270 pc = 0;
28271 continue;
28272 }
@@ -28143,11 +28280,11 @@
28280 p->cTerm = c;
28281 break;
28282 }
28283 if( pc==cQuote && c!='\r' ){
28284 cli_printf(stderr,"%s:%d: unescaped %c character\n",
28285 p->zFile, p->nLine, cQuote);
28286 }
28287 if( c==EOF ){
28288 cli_printf(stderr,"%s:%d: unterminated %c-quoted field\n",
28289 p->zFile, startLine, cQuote);
28290 p->cTerm = c;
@@ -28158,10 +28295,11 @@
28295 pc = c;
28296 }
28297 }else{
28298 /* If this is the first field being parsed and it begins with the
28299 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */
28300 int cEsc = p->cUQEscape;
28301 if( (c&0xff)==0xef && p->bNotFirst==0 ){
28302 import_append_char(p, c);
28303 c = import_getc(p);
28304 if( (c&0xff)==0xbb ){
28305 import_append_char(p, c);
@@ -28172,10 +28310,11 @@
28310 return csv_read_one_field(p);
28311 }
28312 }
28313 }
28314 while( c!=EOF && c!=cSep && c!=rSep ){
28315 if( c==cEsc && cEsc!=0 ) c = import_getc(p);
28316 import_append_char(p, c);
28317 c = import_getc(p);
28318 }
28319 if( c==rSep ){
28320 p->nLine++;
@@ -30315,11 +30454,11 @@
30454 ;
30455 static const char * const zCollectVar = "\
30456 SELECT\
30457 '('||x'0a'\
30458 || group_concat(\
30459 cname||' ANY',\
30460 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
30461 ||')' AS ColsSpec \
30462 FROM (\
30463 SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \
30464 FROM ColNames ORDER BY cpos\
@@ -30535,10 +30674,12 @@
30674 ** --ascii Do not use RFC-4180 quoting. Use \037 and \036
30675 ** as column and row separators on input, unless other
30676 ** delimiters are specified using --colsep and/or --rowsep
30677 ** --colsep CHAR Use CHAR as the column separator.
30678 ** --csv Input is standard RFC-4180 CSV.
30679 ** --esc CHAR Use CHAR as an escape character in unquoted CSV inputs.
30680 ** --qesc CHAR Use CHAR as an escape character in quoted CSV inputs.
30681 ** --rowsep CHAR Use CHAR as the row separator.
30682 ** --schema S When creating TABLE, put it in schema S
30683 ** --skip N Ignore the first N rows of input
30684 ** -v Verbose mode
30685 */
@@ -30593,10 +30734,14 @@
30734 xRead = ascii_read_one_field;
30735 }else if( cli_strcmp(z,"-csv")==0 ){
30736 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
30737 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
30738 xRead = csv_read_one_field;
30739 }else if( cli_strcmp(z,"-esc")==0 ){
30740 sCtx.cUQEscape = azArg[++i][0];
30741 }else if( cli_strcmp(z,"-qesc")==0 ){
30742 sCtx.cQEscape = azArg[++i][0];
30743 }else if( cli_strcmp(z,"-colsep")==0 ){
30744 if( i==nArg-1 ){
30745 dotCmdError(p, i, "missing argument", 0);
30746 return 1;
30747 }
@@ -33351,10 +33496,23 @@
33496 continue;
33497 }
33498 if( cli_strcmp(z,"once")==0 ){
33499 p->flgProgress |= SHELL_PROGRESS_ONCE;
33500 continue;
33501 }
33502 if( cli_strcmp(z,"timeout")==0 ){
33503 if( i==nArg-1 ){
33504 dotCmdError(p, i, "missing argument", 0);
33505 return 1;
33506 }
33507 i++;
33508 p->tmProgress = atof(azArg[i]);
33509 if( p->tmProgress>0.0 ){
33510 p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
33511 if( nn==0 ) nn = 100;
33512 }
33513 continue;
33514 }
33515 if( cli_strcmp(z,"limit")==0 ){
33516 if( i+1>=nArg ){
33517 eputz("Error: missing argument on --limit\n");
33518 rc = 1;
@@ -34843,17 +35001,21 @@
35001 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
35002 }else
35003
35004 if( c=='t' && n>=5 && cli_strncmp(azArg[0], "timer", n)==0 ){
35005 if( nArg==2 ){
35006 if( cli_strcmp(azArg[1],"once")==0 ){
35007 p->enableTimer = 1;
35008 }else{
35009 p->enableTimer = 2*booleanValue(azArg[1]);
35010 }
35011 if( p->enableTimer && !HAS_TIMER ){
35012 eputz("Error: timer not available on this system.\n");
35013 p->enableTimer = 0;
35014 }
35015 }else{
35016 eputz("Usage: .timer on|off|once\n");
35017 rc = 1;
35018 }
35019 }else
35020
35021 #ifndef SQLITE_OMIT_TRACE
@@ -35024,10 +35186,11 @@
35186 if( p->nPopOutput ){
35187 p->nPopOutput--;
35188 if( p->nPopOutput==0 ) output_reset(p);
35189 }
35190 p->bSafeMode = p->bSafeModePersist;
35191 p->dot.nArg = 0;
35192 return rc;
35193 }
35194
35195 /* Line scan result and intermediate states (supporting scan resumption)
35196 */
@@ -35260,13 +35423,13 @@
35423 char *zErrMsg = 0;
35424
35425 open_db(p, 0);
35426 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
35427 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
35428 BEGIN_TIMER(p);
35429 rc = shell_exec(p, zSql, &zErrMsg);
35430 END_TIMER(p);
35431 if( rc || zErrMsg ){
35432 char zPrefix[100];
35433 const char *zErrorTail;
35434 const char *zErrorType;
35435 if( zErrMsg==0 ){
35436
+908 -416
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 4733d351ec2376291f093ba8d2ba71d82c6f with changes in files:
21
+** 2610105a439e25c050b2deb32953861187c8 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.52.0"
471471
#define SQLITE_VERSION_NUMBER 3052000
472
-#define SQLITE_SOURCE_ID "2026-01-26 10:53:24 4733d351ec2376291f093ba8d2ba71d82c6f100c68dc860eee0532986c154e71"
472
+#define SQLITE_SOURCE_ID "2026-02-17 11:28:48 2610105a439e25c050b2deb32953861187c81b1d97407f41dc188e6627e0ac4d"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-01-26T10:53:24.426Z"
475
+#define SQLITE_SCM_DATETIME "2026-02-17T11:28:48.505Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -11571,23 +11571,45 @@
1157111571
#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
1157211572
1157311573
/*
1157411574
** CAPI3REF: Bind array values to the CARRAY table-valued function
1157511575
**
11576
-** The sqlite3_carray_bind(S,I,P,N,F,X) interface binds an array value to
11577
-** one of the first argument of the [carray() table-valued function]. The
11578
-** S parameter is a pointer to the [prepared statement] that uses the carray()
11579
-** functions. I is the parameter index to be bound. P is a pointer to the
11580
-** array to be bound, and N is the number of eements in the array. The
11581
-** F argument is one of constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64],
11582
-** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], or [SQLITE_CARRAY_BLOB] to
11583
-** indicate the datatype of the array being bound. The X argument is not a
11584
-** NULL pointer, then SQLite will invoke the function X on the P parameter
11585
-** after it has finished using P, even if the call to
11586
-** sqlite3_carray_bind() fails. The special-case finalizer
11587
-** SQLITE_TRANSIENT has no effect here.
11576
+** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to
11577
+** parameter that is the first argument of the [carray() table-valued function].
11578
+** The S parameter is a pointer to the [prepared statement] that uses the carray()
11579
+** functions. I is the parameter index to be bound. I must be the index of the
11580
+** parameter that is the first argument to the carray() table-valued function.
11581
+** P is a pointer to the array to be bound, and N is the number of elements in
11582
+** the array. The F argument is one of constants [SQLITE_CARRAY_INT32],
11583
+** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT],
11584
+** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P.
11585
+**
11586
+** If the X argument is not a NULL pointer or one of the special
11587
+** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke
11588
+** the function X with argument D when it is finished using the data in P.
11589
+** The call to X(D) is a destructor for the array P. The destructor X(D)
11590
+** is invoked even if the call to sqlite3_carray_bind() fails. If the X
11591
+** parameter is the special-case value [SQLITE_STATIC], then SQLite assumes
11592
+** that the data static and the destructor is never invoked. If the X
11593
+** parameter is the special-case value [SQLITE_TRANSIENT], then
11594
+** sqlite3_carray_bind_v2() makes its own private copy of the data prior
11595
+** to returning and never invokes the destructor X.
11596
+**
11597
+** The sqlite3_carray_bind() function works the same as sqlite_carray_bind_v2()
11598
+** with a D parameter set to P. In other words,
11599
+** sqlite3_carray_bind(S,I,P,N,F,X) is same as
11600
+** sqlite3_carray_bind(S,I,P,N,F,X,P).
1158811601
*/
11602
+SQLITE_API int sqlite3_carray_bind_v2(
11603
+ sqlite3_stmt *pStmt, /* Statement to be bound */
11604
+ int i, /* Parameter index */
11605
+ void *aData, /* Pointer to array data */
11606
+ int nData, /* Number of data elements */
11607
+ int mFlags, /* CARRAY flags */
11608
+ void (*xDel)(void*), /* Destructor for aData */
11609
+ void *pDel /* Optional argument to xDel() */
11610
+);
1158911611
SQLITE_API int sqlite3_carray_bind(
1159011612
sqlite3_stmt *pStmt, /* Statement to be bound */
1159111613
int i, /* Parameter index */
1159211614
void *aData, /* Pointer to array data */
1159311615
int nData, /* Number of data elements */
@@ -15814,10 +15836,11 @@
1581415836
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
1581515837
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
1581615838
#else
1581715839
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
1581815840
#endif
15841
+#define TWO_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&1)==0)
1581915842
1582015843
/*
1582115844
** Disable MMAP on platforms where it is known to not work
1582215845
*/
1582315846
#if defined(__OpenBSD__) || defined(__QNXNTO__)
@@ -20337,11 +20360,11 @@
2033720360
#define SF_Distinct 0x0000001 /* Output should be DISTINCT */
2033820361
#define SF_All 0x0000002 /* Includes the ALL keyword */
2033920362
#define SF_Resolved 0x0000004 /* Identifiers have been resolved */
2034020363
#define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */
2034120364
#define SF_HasAgg 0x0000010 /* Contains aggregate functions */
20342
-/* 0x0000020 // available for reuse */
20365
+#define SF_ClonedRhsIn 0x0000020 /* Cloned RHS of an IN operator */
2034320366
#define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */
2034420367
#define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */
2034520368
#define SF_Compound 0x0000100 /* Part of a compound query */
2034620369
#define SF_Values 0x0000200 /* Synthesized from VALUES clause */
2034720370
#define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */
@@ -20594,33 +20617,33 @@
2059420617
int rc; /* Return code from execution */
2059520618
LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
2059620619
u8 nested; /* Number of nested calls to the parser/code generator */
2059720620
u8 nTempReg; /* Number of temporary registers in aTempReg[] */
2059820621
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
20599
- u8 mayAbort; /* True if statement may throw an ABORT exception */
20600
- u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
2060120622
u8 disableLookaside; /* Number of times lookaside has been disabled */
2060220623
u8 prepFlags; /* SQLITE_PREPARE_* flags */
2060320624
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20604
- u8 bHasExists; /* Has a correlated "EXISTS (SELECT ....)" expression */
2060520625
u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
2060620626
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20607
- u8 bReturning; /* Coding a RETURNING trigger */
2060820627
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20609
- u8 disableTriggers; /* True to disable triggers */
2061020628
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
2061120629
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
2061220630
#endif
2061320631
#ifdef SQLITE_DEBUG
2061420632
u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
2061520633
u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
2061620634
** and ALTER TABLE ADD COLUMN. */
2061720635
#endif
20618
- bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20619
- bft bHasWith :1; /* True if statement contains WITH */
20620
- bft okConstFactor :1; /* OK to factor out constants */
20621
- bft checkSchema :1; /* Causes schema cookie check after an error */
20636
+ bft disableTriggers:1; /* True to disable triggers */
20637
+ bft mayAbort :1; /* True if statement may throw an ABORT exception */
20638
+ bft hasCompound :1; /* Need to invoke convertCompoundSelectToSubquery() */
20639
+ bft bReturning :1; /* Coding a RETURNING trigger */
20640
+ bft bHasExists :1; /* Has a correlated "EXISTS (SELECT ....)" expression */
20641
+ bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20642
+ bft bHasWith :1; /* True if statement contains WITH */
20643
+ bft okConstFactor:1; /* OK to factor out constants */
20644
+ bft checkSchema :1; /* Causes schema cookie check after an error */
2062220645
int nRangeReg; /* Size of the temporary register block */
2062320646
int iRangeReg; /* First register in temporary register block */
2062420647
int nErr; /* Number of errors seen */
2062520648
int nTab; /* Number of previously allocated VDBE cursors */
2062620649
int nMem; /* Number of memory cells used so far */
@@ -21094,10 +21117,11 @@
2109421117
u16 mWFlags; /* Use-dependent flags */
2109521118
union { /* Extra data for callback */
2109621119
NameContext *pNC; /* Naming context */
2109721120
int n; /* A counter */
2109821121
int iCur; /* A cursor number */
21122
+ int sz; /* String literal length */
2109921123
SrcList *pSrcList; /* FROM clause */
2110021124
struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
2110121125
struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */
2110221126
int *aiCol; /* array of column indexes */
2110321127
struct IdxCover *pIdxCover; /* Check for index coverage */
@@ -21780,10 +21804,11 @@
2178021804
SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
2178121805
SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
2178221806
Expr*,ExprList*,u32,Expr*);
2178321807
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
2178421808
SQLITE_PRIVATE void sqlite3SelectDeleteGeneric(sqlite3*,void*);
21809
+SQLITE_PRIVATE void sqlite3SelectCheckOnClauses(Parse *pParse, Select *pSelect);
2178521810
SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
2178621811
SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, Trigger*);
2178721812
SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
2178821813
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
2178921814
SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -21877,10 +21902,11 @@
2187721902
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
2187821903
#endif
2187921904
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
2188021905
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
2188121906
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
21907
+SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr*);
2188221908
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
2188321909
SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab);
2188421910
SQLITE_PRIVATE void sqlite3GenerateRowDelete(
2188521911
Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
2188621912
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
@@ -22000,11 +22026,11 @@
2200022026
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
2200122027
2200222028
SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
2200322029
SQLITE_PRIVATE i64 sqlite3RealToI64(double);
2200422030
SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*);
22005
-SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
22031
+SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
2200622032
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
2200722033
SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
2200822034
SQLITE_PRIVATE int sqlite3Atoi(const char*);
2200922035
#ifndef SQLITE_OMIT_UTF16
2201022036
SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nByte, int nChar);
@@ -22150,11 +22176,11 @@
2215022176
SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int);
2215122177
SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*);
2215222178
SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *);
2215322179
SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
2215422180
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
22155
-SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
22181
+SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
2215622182
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
2215722183
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
2215822184
SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, SrcItem*);
2215922185
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
2216022186
SQLITE_PRIVATE int sqlite3MatchEName(
@@ -24584,17 +24610,18 @@
2458424610
#endif
2458524611
#ifdef SQLITE_DEBUG
2458624612
SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*);
2458724613
#endif
2458824614
SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*);
24589
-SQLITE_PRIVATE void sqlite3VdbeMemZeroTerminateIfAble(Mem*);
24615
+SQLITE_PRIVATE int sqlite3VdbeMemZeroTerminateIfAble(Mem*);
2459024616
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
2459124617
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
2459224618
SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double);
2459324619
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*);
2459424620
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
2459524621
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
24622
+SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem*, int*);
2459624623
SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
2459724624
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
2459824625
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
2459924626
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
2460024627
SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
@@ -25550,11 +25577,11 @@
2555025577
return 0;
2555125578
}else if( parseHhMmSs(zDate, p)==0 ){
2555225579
return 0;
2555325580
}else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
2555425581
return setDateTimeToCurrent(context, p);
25555
- }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){
25582
+ }else if( sqlite3AtoF(zDate, &r)>0 ){
2555625583
setRawDateNumber(p, r);
2555725584
return 0;
2555825585
}else if( (sqlite3StrICmp(zDate,"subsec")==0
2555925586
|| sqlite3StrICmp(zDate,"subsecond")==0)
2556025587
&& sqlite3NotPureFunc(context) ){
@@ -25996,11 +26023,11 @@
2599626023
** Move the date to the same time on the next occurrence of
2599726024
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
2599826025
** date is already on the appropriate weekday, this is a no-op.
2599926026
*/
2600026027
if( sqlite3_strnicmp(z, "weekday ", 8)==0
26001
- && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
26028
+ && sqlite3AtoF(&z[8], &r)>0
2600226029
&& r>=0.0 && r<7.0 && (n=(int)r)==r ){
2600326030
sqlite3_int64 Z;
2600426031
computeYMD_HMS(p);
2600526032
p->tz = 0;
2600626033
p->validJD = 0;
@@ -26067,23 +26094,29 @@
2606726094
case '6':
2606826095
case '7':
2606926096
case '8':
2607026097
case '9': {
2607126098
double rRounder;
26072
- int i;
26099
+ int i, rx;
2607326100
int Y,M,D,h,m,x;
2607426101
const char *z2 = z;
26102
+ char *zCopy;
26103
+ sqlite3 *db = sqlite3_context_db_handle(pCtx);
2607526104
char z0 = z[0];
2607626105
for(n=1; z[n]; n++){
2607726106
if( z[n]==':' ) break;
2607826107
if( sqlite3Isspace(z[n]) ) break;
2607926108
if( z[n]=='-' ){
2608026109
if( n==5 && getDigits(&z[1], "40f", &Y)==1 ) break;
2608126110
if( n==6 && getDigits(&z[1], "50f", &Y)==1 ) break;
2608226111
}
2608326112
}
26084
- if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
26113
+ zCopy = sqlite3DbStrNDup(db, z, n);
26114
+ if( zCopy==0 ) break;
26115
+ rx = sqlite3AtoF(zCopy, &r)<=0;
26116
+ sqlite3DbFree(db, zCopy);
26117
+ if( rx ){
2608526118
assert( rc==1 );
2608626119
break;
2608726120
}
2608826121
if( z[n]=='-' ){
2608926122
/* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
@@ -34904,11 +34937,17 @@
3490434937
** sqlite3ShowWhereTerm() in where.c
3490534938
*/
3490634939
SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
3490734940
SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
3490834941
SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
34909
-SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); }
34942
+SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){
34943
+ TreeView *pView = 0;
34944
+ sqlite3TreeViewPush(&pView, 0);
34945
+ sqlite3TreeViewLine(pView, "SRCLIST");
34946
+ sqlite3TreeViewSrcList(pView,p);
34947
+ sqlite3TreeViewPop(&pView);
34948
+}
3491034949
SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
3491134950
SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
3491234951
SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
3491334952
#ifndef SQLITE_OMIT_TRIGGER
3491434953
SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep *p){
@@ -36424,52 +36463,261 @@
3642436463
z++;
3642536464
}
3642636465
return h;
3642736466
}
3642836467
36429
-/* Double-Double multiplication. (x[0],x[1]) *= (y,yy)
36430
-**
36431
-** Reference:
36432
-** T. J. Dekker, "A Floating-Point Technique for Extending the
36433
-** Available Precision". 1971-07-26.
36434
-*/
36435
-static void dekkerMul2(volatile double *x, double y, double yy){
36436
- /*
36437
- ** The "volatile" keywords on parameter x[] and on local variables
36438
- ** below are needed force intermediate results to be truncated to
36439
- ** binary64 rather than be carried around in an extended-precision
36440
- ** format. The truncation is necessary for the Dekker algorithm to
36441
- ** work. Intel x86 floating point might omit the truncation without
36442
- ** the use of volatile.
36443
- */
36444
- volatile double tx, ty, p, q, c, cc;
36445
- double hx, hy;
36446
- u64 m;
36447
- memcpy(&m, (void*)&x[0], 8);
36448
- m &= 0xfffffffffc000000LL;
36449
- memcpy(&hx, &m, 8);
36450
- tx = x[0] - hx;
36451
- memcpy(&m, &y, 8);
36452
- m &= 0xfffffffffc000000LL;
36453
- memcpy(&hy, &m, 8);
36454
- ty = y - hy;
36455
- p = hx*hy;
36456
- q = hx*ty + tx*hy;
36457
- c = p+q;
36458
- cc = p - c + q + tx*ty;
36459
- cc = x[0]*yy + x[1]*y + cc;
36460
- x[0] = c + cc;
36461
- x[1] = c - x[0];
36462
- x[1] += cc;
36468
+/*
36469
+** Two inputs are multiplied to get a 128-bit result. Return
36470
+** the high-order 64 bits of that result.
36471
+*/
36472
+static u64 sqlite3Multiply128(u64 a, u64 b){
36473
+#if (defined(__GNUC__) || defined(__clang__)) \
36474
+ && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv))
36475
+ return ((__uint128_t)a * b) >> 64;
36476
+#elif defined(_MSC_VER) && defined(_M_X64)
36477
+ return __umulh(a, b);
36478
+#else
36479
+ u64 a1 = (u32)a;
36480
+ u64 a2 = a >> 32;
36481
+ u64 b1 = (u32)b;
36482
+ u64 b2 = b >> 32;
36483
+ u64 p0 = a1 * b1;
36484
+ u64 p1 = a1 * b2;
36485
+ u64 p2 = a2 * b1;
36486
+ u64 p3 = a2 * b2;
36487
+ u64 carry = ((p0 >> 32) + (u32)p1 + (u32)p2) >> 32;
36488
+ return p3 + (p1 >> 32) + (p2 >> 32) + carry;
36489
+#endif
36490
+}
36491
+
36492
+/*
36493
+** Return a u64 with the N-th bit set.
36494
+*/
36495
+#define U64_BIT(N) (((u64)1)<<(N))
36496
+
36497
+/*
36498
+** Range of powers of 10 that we need to deal with when converting
36499
+** IEEE754 doubles to and from decimal.
36500
+*/
36501
+#define POWERSOF10_FIRST (-348)
36502
+#define POWERSOF10_LAST (+347)
36503
+
36504
+/*
36505
+** For any p between -348 and +347, return the integer part of
36506
+**
36507
+** pow(10,p) * pow(2,63-pow10to2(p))
36508
+**
36509
+** Or, in other words, for any p in range, return the most significant
36510
+** 64 bits of pow(10,p). The pow(10,p) value is shifted left or right,
36511
+** as appropriate so the most significant 64 bits fit exactly into a
36512
+** 64-bit unsigned integer.
36513
+**
36514
+** Algorithm:
36515
+**
36516
+** (1) For p between 0 and 26, return the value directly from the aBase[]
36517
+** lookup table.
36518
+**
36519
+** (2) For p outside the range 0 to 26, use aScale[] for the initial value
36520
+** then refine that result (if necessary) by a single multiplication
36521
+** against aBase[].
36522
+*/
36523
+static u64 powerOfTen(int p){
36524
+ static const u64 aBase[] = {
36525
+ 0x8000000000000000LLU, /* 0: 1.0e+0 << 63 */
36526
+ 0xa000000000000000LLU, /* 1: 1.0e+1 << 60 */
36527
+ 0xc800000000000000LLU, /* 2: 1.0e+2 << 57 */
36528
+ 0xfa00000000000000LLU, /* 3: 1.0e+3 << 54 */
36529
+ 0x9c40000000000000LLU, /* 4: 1.0e+4 << 50 */
36530
+ 0xc350000000000000LLU, /* 5: 1.0e+5 << 47 */
36531
+ 0xf424000000000000LLU, /* 6: 1.0e+6 << 44 */
36532
+ 0x9896800000000000LLU, /* 7: 1.0e+7 << 40 */
36533
+ 0xbebc200000000000LLU, /* 8: 1.0e+8 << 37 */
36534
+ 0xee6b280000000000LLU, /* 9: 1.0e+9 << 34 */
36535
+ 0x9502f90000000000LLU, /* 10: 1.0e+10 << 30 */
36536
+ 0xba43b74000000000LLU, /* 11: 1.0e+11 << 27 */
36537
+ 0xe8d4a51000000000LLU, /* 12: 1.0e+12 << 24 */
36538
+ 0x9184e72a00000000LLU, /* 13: 1.0e+13 << 20 */
36539
+ 0xb5e620f480000000LLU, /* 14: 1.0e+14 << 17 */
36540
+ 0xe35fa931a0000000LLU, /* 15: 1.0e+15 << 14 */
36541
+ 0x8e1bc9bf04000000LLU, /* 16: 1.0e+16 << 10 */
36542
+ 0xb1a2bc2ec5000000LLU, /* 17: 1.0e+17 << 7 */
36543
+ 0xde0b6b3a76400000LLU, /* 18: 1.0e+18 << 4 */
36544
+ 0x8ac7230489e80000LLU, /* 19: 1.0e+19 >> 0 */
36545
+ 0xad78ebc5ac620000LLU, /* 20: 1.0e+20 >> 3 */
36546
+ 0xd8d726b7177a8000LLU, /* 21: 1.0e+21 >> 6 */
36547
+ 0x878678326eac9000LLU, /* 22: 1.0e+22 >> 10 */
36548
+ 0xa968163f0a57b400LLU, /* 23: 1.0e+23 >> 13 */
36549
+ 0xd3c21bcecceda100LLU, /* 24: 1.0e+24 >> 16 */
36550
+ 0x84595161401484a0LLU, /* 25: 1.0e+25 >> 20 */
36551
+ 0xa56fa5b99019a5c8LLU, /* 26: 1.0e+26 >> 23 */
36552
+ };
36553
+ static const u64 aScale[] = {
36554
+ 0x8049a4ac0c5811aeLLU, /* 0: 1.0e-351 << 1229 */
36555
+ 0xcf42894a5dce35eaLLU, /* 1: 1.0e-324 << 1140 */
36556
+ 0xa76c582338ed2621LLU, /* 2: 1.0e-297 << 1050 */
36557
+ 0x873e4f75e2224e68LLU, /* 3: 1.0e-270 << 960 */
36558
+ 0xda7f5bf590966848LLU, /* 4: 1.0e-243 << 871 */
36559
+ 0xb080392cc4349decLLU, /* 5: 1.0e-216 << 781 */
36560
+ 0x8e938662882af53eLLU, /* 6: 1.0e-189 << 691 */
36561
+ 0xe65829b3046b0afaLLU, /* 7: 1.0e-162 << 602 */
36562
+ 0xba121a4650e4ddebLLU, /* 8: 1.0e-135 << 512 */
36563
+ 0x964e858c91ba2655LLU, /* 9: 1.0e-108 << 422 */
36564
+ 0xf2d56790ab41c2a2LLU, /* 10: 1.0e-81 << 333 */
36565
+ 0xc428d05aa4751e4cLLU, /* 11: 1.0e-54 << 243 */
36566
+ 0x9e74d1b791e07e48LLU, /* 12: 1.0e-27 << 153 */
36567
+ 0x8000000000000000LLU, /* 13: 1.0e+0 << 63 */
36568
+ 0xcecb8f27f4200f3aLLU, /* 14: 1.0e+27 >> 26 */
36569
+ 0xa70c3c40a64e6c51LLU, /* 15: 1.0e+54 >> 116 */
36570
+ 0x86f0ac99b4e8dafdLLU, /* 16: 1.0e+81 >> 206 */
36571
+ 0xda01ee641a708de9LLU, /* 17: 1.0e+108 >> 295 */
36572
+ 0xb01ae745b101e9e4LLU, /* 18: 1.0e+135 >> 385 */
36573
+ 0x8e41ade9fbebc27dLLU, /* 19: 1.0e+162 >> 475 */
36574
+ 0xe5d3ef282a242e81LLU, /* 20: 1.0e+189 >> 564 */
36575
+ 0xb9a74a0637ce2ee1LLU, /* 21: 1.0e+216 >> 654 */
36576
+ 0x95f83d0a1fb69cd9LLU, /* 22: 1.0e+243 >> 744 */
36577
+ 0xf24a01a73cf2dccfLLU, /* 23: 1.0e+270 >> 833 */
36578
+ 0xc3b8358109e84f07LLU, /* 24: 1.0e+297 >> 923 */
36579
+ 0x9e19db92b4e31ba9LLU, /* 25: 1.0e+324 >> 1013 */
36580
+ };
36581
+ int g, n;
36582
+ u64 x, y;
36583
+
36584
+ assert( p>=POWERSOF10_FIRST && p<=POWERSOF10_LAST );
36585
+ if( p<0 ){
36586
+ g = p/27;
36587
+ n = p%27;
36588
+ if( n ){
36589
+ g--;
36590
+ n += 27;
36591
+ }
36592
+ }else if( p<27 ){
36593
+ return aBase[p];
36594
+ }else{
36595
+ g = p/27;
36596
+ n = p%27;
36597
+ }
36598
+ y = aScale[g+13];
36599
+ if( n==0 ){
36600
+ return y;
36601
+ }
36602
+ x = sqlite3Multiply128(aBase[n],y);
36603
+ if( (U64_BIT(63) & x)==0 ){
36604
+ x <<= 1;
36605
+ }
36606
+ return x;
36607
+}
36608
+
36609
+/*
36610
+** pow10to2(x) computes floor(log2(pow(10,x))).
36611
+** pow2to10(y) computes floor(log10(pow(2,y))).
36612
+**
36613
+** Conceptually, pow10to2(p) converts a base-10 exponent p into
36614
+** a corresponding base-2 exponent, and pow2to10(e) converts a base-2
36615
+** exponent into a base-10 exponent.
36616
+**
36617
+** The conversions are based on the observation that:
36618
+**
36619
+** ln(10.0)/ln(2.0) == 108853/32768 (approximately)
36620
+** ln(2.0)/ln(10.0) == 78913/262144 (approximately)
36621
+**
36622
+** These ratios are approximate, but they are accurate to 5 digits,
36623
+** which is close enough for the usage here. Right-shift is used
36624
+** for division so that rounding of negative numbers happens in the
36625
+** right direction.
36626
+*/
36627
+static int pwr10to2(int p){ return (p*108853) >> 15; }
36628
+static int pwr2to10(int p){ return (p*78913) >> 18; }
36629
+
36630
+/*
36631
+** Count leading zeros for a 64-bit unsigned integer.
36632
+*/
36633
+static int countLeadingZeros(u64 m){
36634
+#if defined(__GNUC__) || defined(__clang__)
36635
+ return __builtin_clzll(m);
36636
+#else
36637
+ int n = 0;
36638
+ if( m <= 0x00000000ffffffffULL) { n += 32; m <<= 32; }
36639
+ if( m <= 0x0000ffffffffffffULL) { n += 16; m <<= 16; }
36640
+ if( m <= 0x00ffffffffffffffULL) { n += 8; m <<= 8; }
36641
+ if( m <= 0x0fffffffffffffffULL) { n += 4; m <<= 4; }
36642
+ if( m <= 0x3fffffffffffffffULL) { n += 2; m <<= 2; }
36643
+ if( m <= 0x7fffffffffffffffULL) { n += 1; }
36644
+ return n;
36645
+#endif
36646
+}
36647
+
36648
+/*
36649
+** Given m and e, which represent a quantity r == m*pow(2,e),
36650
+** return values *pD and *pP such that r == (*pD)*pow(10,*pP),
36651
+** approximately. *pD should contain at least n significant digits.
36652
+**
36653
+** The input m is required to have its highest bit set. In other words,
36654
+** m should be left-shifted, and e decremented, to maximize the value of m.
36655
+*/
36656
+static void sqlite3Fp2Convert10(u64 m, int e, int n, u64 *pD, int *pP){
36657
+ int p;
36658
+ u64 h, out;
36659
+ p = n - 1 - pwr2to10(e+63);
36660
+ h = sqlite3Multiply128(m, powerOfTen(p));
36661
+ assert( -(e + pwr10to2(p) + 3) >=0 );
36662
+ assert( -(e + pwr10to2(p) + 3) <64 );
36663
+ out = h >> -(e + pwr10to2(p) + 3);
36664
+ *pD = (out + 2 + ((out>>2)&1)) >> 2;
36665
+ *pP = -p;
36666
+}
36667
+
36668
+/*
36669
+** Return an IEEE754 floating point value that approximates d*pow(10,p).
36670
+*/
36671
+static double sqlite3Fp10Convert2(u64 d, int p){
36672
+ u64 out;
36673
+ int b;
36674
+ int e1;
36675
+ int e2;
36676
+ int lp;
36677
+ u64 h;
36678
+ double r;
36679
+ assert( (d & U64_BIT(63))==0 );
36680
+ assert( d!=0 );
36681
+ if( p<POWERSOF10_FIRST ){
36682
+ return 0.0;
36683
+ }
36684
+ if( p>POWERSOF10_LAST ){
36685
+ return INFINITY;
36686
+ }
36687
+ b = 64 - countLeadingZeros(d);
36688
+ lp = pwr10to2(p);
36689
+ e1 = 53 - b - lp;
36690
+ if( e1>1074 ){
36691
+ if( -(b + lp) >= 1077 ) return 0.0;
36692
+ e1 = 1074;
36693
+ }
36694
+ e2 = e1 - (64-b);
36695
+ h = sqlite3Multiply128(d<<(64-b), powerOfTen(p));
36696
+ assert( -(e2 + lp + 3) >=0 );
36697
+ assert( -(e2 + lp + 3) <64 );
36698
+ out = (h >> -(e2 + lp + 3)) | 1;
36699
+ if( out >= U64_BIT(55)-2 ){
36700
+ out = (out>>1) | (out&1);
36701
+ e1--;
36702
+ }
36703
+ if( e1<=(-972) ){
36704
+ return INFINITY;
36705
+ }
36706
+ out = (out + 1 + ((out>>2)&1)) >> 2;
36707
+ if( (out & U64_BIT(52))!=0 ){
36708
+ out = (out & ~U64_BIT(52)) | ((u64)(1075-e1)<<52);
36709
+ }
36710
+ memcpy(&r, &out, 8);
36711
+ return r;
3646336712
}
3646436713
3646536714
/*
3646636715
** The string z[] is an text representation of a real number.
3646736716
** Convert this string to a double and write it into *pResult.
3646836717
**
36469
-** The string z[] is length bytes in length (bytes, not characters) and
36470
-** uses the encoding enc. The string is not necessarily zero-terminated.
36718
+** z[] must be UTF-8 and zero-terminated.
3647136719
**
3647236720
** Return TRUE if the result is a valid real number (or integer) and FALSE
3647336721
** if the string is empty or contains extraneous text. More specifically
3647436722
** return
3647536723
** 1 => The input string is a pure integer
@@ -36492,201 +36740,134 @@
3649236740
** into *pResult.
3649336741
*/
3649436742
#if defined(_MSC_VER)
3649536743
#pragma warning(disable : 4756)
3649636744
#endif
36497
-SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
36745
+SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
3649836746
#ifndef SQLITE_OMIT_FLOATING_POINT
36499
- int incr;
36500
- const char *zEnd;
3650136747
/* sign * significand * (10 ^ (esign * exponent)) */
36502
- int sign = 1; /* sign of significand */
36503
- u64 s = 0; /* significand */
36504
- int d = 0; /* adjust exponent for shifting decimal point */
36505
- int esign = 1; /* sign of exponent */
36506
- int e = 0; /* exponent */
36507
- int eValid = 1; /* True exponent is either not used or is well-formed */
36748
+ int neg = 0; /* True for a negative value */
36749
+ u64 s = 0; /* mantissa */
36750
+ int d = 0; /* Value is s * pow(10,d) */
3650836751
int nDigit = 0; /* Number of digits processed */
36509
- int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
36510
- u64 s2; /* round-tripped significand */
36511
- double rr[2];
36512
-
36513
- assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
36514
- *pResult = 0.0; /* Default return value, in case of an error */
36515
- if( length==0 ) return 0;
36516
-
36517
- if( enc==SQLITE_UTF8 ){
36518
- incr = 1;
36519
- zEnd = z + length;
36520
- }else{
36521
- int i;
36522
- incr = 2;
36523
- length &= ~1;
36524
- assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
36525
- testcase( enc==SQLITE_UTF16LE );
36526
- testcase( enc==SQLITE_UTF16BE );
36527
- for(i=3-enc; i<length && z[i]==0; i+=2){}
36528
- if( i<length ) eType = -100;
36529
- zEnd = &z[i^1];
36530
- z += (enc&1);
36531
- }
36752
+ int eType = 1; /* 1: pure integer, 2+: fractional */
36753
+
36754
+ *pResult = 0.0; /* Default return value, in case of an error */
3653236755
3653336756
/* skip leading spaces */
36534
- while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
36535
- if( z>=zEnd ) return 0;
36757
+ while( sqlite3Isspace(*z) ) z++;
3653636758
3653736759
/* get sign of significand */
3653836760
if( *z=='-' ){
36539
- sign = -1;
36540
- z+=incr;
36761
+ neg = 1;
36762
+ z++;
3654136763
}else if( *z=='+' ){
36542
- z+=incr;
36764
+ z++;
3654336765
}
3654436766
3654536767
/* copy max significant digits to significand */
36546
- while( z<zEnd && sqlite3Isdigit(*z) ){
36768
+ while( sqlite3Isdigit(*z) ){
3654736769
s = s*10 + (*z - '0');
36548
- z+=incr; nDigit++;
36549
- if( s>=((LARGEST_UINT64-9)/10) ){
36770
+ z++; nDigit++;
36771
+ if( s>=((LARGEST_INT64-9)/10) ){
3655036772
/* skip non-significant significand digits
3655136773
** (increase exponent by d to shift decimal left) */
36552
- while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; d++; }
36774
+ while( sqlite3Isdigit(*z) ){ z++; d++; }
3655336775
}
3655436776
}
36555
- if( z>=zEnd ) goto do_atof_calc;
3655636777
3655736778
/* if decimal point is present */
3655836779
if( *z=='.' ){
36559
- z+=incr;
36780
+ z++;
3656036781
eType++;
3656136782
/* copy digits from after decimal to significand
3656236783
** (decrease exponent by d to shift decimal right) */
36563
- while( z<zEnd && sqlite3Isdigit(*z) ){
36564
- if( s<((LARGEST_UINT64-9)/10) ){
36784
+ while( sqlite3Isdigit(*z) ){
36785
+ if( s<((LARGEST_INT64-9)/10) ){
3656536786
s = s*10 + (*z - '0');
3656636787
d--;
3656736788
nDigit++;
3656836789
}
36569
- z+=incr;
36790
+ z++;
3657036791
}
3657136792
}
36572
- if( z>=zEnd ) goto do_atof_calc;
3657336793
3657436794
/* if exponent is present */
3657536795
if( *z=='e' || *z=='E' ){
36576
- z+=incr;
36577
- eValid = 0;
36796
+ int esign = 1; /* sign of exponent */
36797
+ z++;
3657836798
eType++;
3657936799
36580
- /* This branch is needed to avoid a (harmless) buffer overread. The
36581
- ** special comment alerts the mutation tester that the correct answer
36582
- ** is obtained even if the branch is omitted */
36583
- if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
36584
-
3658536800
/* get sign of exponent */
3658636801
if( *z=='-' ){
3658736802
esign = -1;
36588
- z+=incr;
36803
+ z++;
3658936804
}else if( *z=='+' ){
36590
- z+=incr;
36805
+ z++;
3659136806
}
3659236807
/* copy digits to exponent */
36593
- while( z<zEnd && sqlite3Isdigit(*z) ){
36594
- e = e<10000 ? (e*10 + (*z - '0')) : 10000;
36595
- z+=incr;
36596
- eValid = 1;
36808
+ if( sqlite3Isdigit(*z) ){
36809
+ int exp = *z - '0';
36810
+ z++;
36811
+ while( sqlite3Isdigit(*z) ){
36812
+ exp = exp<10000 ? (exp*10 + (*z - '0')) : 10000;
36813
+ z++;
36814
+ }
36815
+ d += esign*exp;
36816
+ }else{
36817
+ eType = -1;
3659736818
}
3659836819
}
3659936820
3660036821
/* skip trailing spaces */
36601
- while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
36822
+ while( sqlite3Isspace(*z) ) z++;
3660236823
36603
-do_atof_calc:
3660436824
/* Zero is a special case */
3660536825
if( s==0 ){
36606
- *pResult = sign<0 ? -0.0 : +0.0;
36607
- goto atof_return;
36608
- }
36609
-
36610
- /* adjust exponent by d, and update sign */
36611
- e = (e*esign) + d;
36612
-
36613
- /* Try to adjust the exponent to make it smaller */
36614
- while( e>0 && s<((LARGEST_UINT64-0x7ff)/10) ){
36615
- s *= 10;
36616
- e--;
36617
- }
36618
- while( e<0 && (s%10)==0 ){
36619
- s /= 10;
36620
- e++;
36621
- }
36622
-
36623
- rr[0] = (double)s;
36624
- assert( sizeof(s2)==sizeof(rr[0]) );
36625
-#ifdef SQLITE_DEBUG
36626
- rr[1] = 18446744073709549568.0;
36627
- memcpy(&s2, &rr[1], sizeof(s2));
36628
- assert( s2==0x43efffffffffffffLL );
36629
-#endif
36630
- /* Largest double that can be safely converted to u64
36631
- ** vvvvvvvvvvvvvvvvvvvvvv */
36632
- if( rr[0]<=18446744073709549568.0 ){
36633
- s2 = (u64)rr[0];
36634
- rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s);
36635
- }else{
36636
- rr[1] = 0.0;
36637
- }
36638
- assert( rr[1]<=1.0e-10*rr[0] ); /* Equal only when rr[0]==0.0 */
36639
-
36640
- if( e>0 ){
36641
- while( e>=100 ){
36642
- e -= 100;
36643
- dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
36644
- }
36645
- while( e>=10 ){
36646
- e -= 10;
36647
- dekkerMul2(rr, 1.0e+10, 0.0);
36648
- }
36649
- while( e>=1 ){
36650
- e -= 1;
36651
- dekkerMul2(rr, 1.0e+01, 0.0);
36652
- }
36653
- }else{
36654
- while( e<=-100 ){
36655
- e += 100;
36656
- dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
36657
- }
36658
- while( e<=-10 ){
36659
- e += 10;
36660
- dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
36661
- }
36662
- while( e<=-1 ){
36663
- e += 1;
36664
- dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
36665
- }
36666
- }
36667
- *pResult = rr[0]+rr[1];
36668
- if( sqlite3IsNaN(*pResult) ) *pResult = 1e300*1e300;
36669
- if( sign<0 ) *pResult = -*pResult;
36670
- assert( !sqlite3IsNaN(*pResult) );
36671
-
36672
-atof_return:
36826
+ *pResult = neg ? -0.0 : +0.0;
36827
+ }else{
36828
+ *pResult = sqlite3Fp10Convert2(s,d);
36829
+ if( neg ) *pResult = -*pResult;
36830
+ assert( !sqlite3IsNaN(*pResult) );
36831
+ }
36832
+
3667336833
/* return true if number and no extra non-whitespace characters after */
36674
- if( z==zEnd && nDigit>0 && eValid && eType>0 ){
36834
+ if( z[0]==0 && nDigit>0 ){
3667536835
return eType;
36676
- }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
36836
+ }else if( eType>=2 && nDigit>0 ){
3667736837
return -1;
3667836838
}else{
3667936839
return 0;
3668036840
}
3668136841
#else
36682
- return !sqlite3Atoi64(z, pResult, length, enc);
36842
+ return !sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8);
3668336843
#endif /* SQLITE_OMIT_FLOATING_POINT */
3668436844
}
3668536845
#if defined(_MSC_VER)
3668636846
#pragma warning(default : 4756)
3668736847
#endif
36848
+
36849
+/*
36850
+** Digit pairs used to convert a U64 or I64 into text, two digits
36851
+** at a time.
36852
+*/
36853
+static const union {
36854
+ char a[200];
36855
+ short int forceAlignment;
36856
+} sqlite3DigitPairs = {
36857
+ "00010203040506070809"
36858
+ "10111213141516171819"
36859
+ "20212223242526272829"
36860
+ "30313233343536373839"
36861
+ "40414243444546474849"
36862
+ "50515253545556575859"
36863
+ "60616263646566676869"
36864
+ "70717273747576777879"
36865
+ "80818283848586878889"
36866
+ "90919293949596979899"
36867
+};
36868
+
3668836869
3668936870
/*
3669036871
** Render an signed 64-bit integer as text. Store the result in zOut[] and
3669136872
** return the length of the string that was stored, in bytes. The value
3669236873
** returned does not include the zero terminator at the end of the output
@@ -36695,27 +36876,39 @@
3669536876
** The caller must ensure that zOut[] is at least 21 bytes in size.
3669636877
*/
3669736878
SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){
3669836879
int i;
3669936880
u64 x;
36700
- char zTemp[22];
36701
- if( v<0 ){
36702
- x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
36703
- }else{
36881
+ union {
36882
+ char a[23];
36883
+ u16 forceAlignment;
36884
+ } u;
36885
+ if( v>0 ){
3670436886
x = v;
36705
- }
36706
- i = sizeof(zTemp)-2;
36707
- zTemp[sizeof(zTemp)-1] = 0;
36708
- while( 1 /*exit-by-break*/ ){
36709
- zTemp[i] = (x%10) + '0';
36710
- x = x/10;
36711
- if( x==0 ) break;
36712
- i--;
36713
- };
36714
- if( v<0 ) zTemp[--i] = '-';
36715
- memcpy(zOut, &zTemp[i], sizeof(zTemp)-i);
36716
- return sizeof(zTemp)-1-i;
36887
+ }else if( v==0 ){
36888
+ zOut[0] = '0';
36889
+ zOut[1] = 0;
36890
+ return 1;
36891
+ }else{
36892
+ x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
36893
+ }
36894
+ i = sizeof(u.a)-1;
36895
+ u.a[i] = 0;
36896
+ while( x>=10 ){
36897
+ int kk = (x%100)*2;
36898
+ assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) );
36899
+ assert( TWO_BYTE_ALIGNMENT(&u.a[i-2]) );
36900
+ *(u16*)(&u.a[i-2]) = *(u16*)&sqlite3DigitPairs.a[kk];
36901
+ i -= 2;
36902
+ x /= 100;
36903
+ }
36904
+ if( x ){
36905
+ u.a[--i] = x + '0';
36906
+ }
36907
+ if( v<0 ) u.a[--i] = '-';
36908
+ memcpy(zOut, &u.a[i], sizeof(u.a)-i);
36909
+ return sizeof(u.a)-1-i;
3671736910
}
3671836911
3671936912
/*
3672036913
** Compare the 19-character string zNum against the text representation
3672136914
** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -36984,11 +37177,10 @@
3698437177
*/
3698537178
SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
3698637179
int i;
3698737180
u64 v;
3698837181
int e, exp = 0;
36989
- double rr[2];
3699037182
3699137183
p->isSpecial = 0;
3699237184
p->z = p->zBuf;
3699337185
assert( mxRound>0 );
3699437186
@@ -37005,64 +37197,43 @@
3700537197
return;
3700637198
}else{
3700737199
p->sign = '+';
3700837200
}
3700937201
memcpy(&v,&r,8);
37010
- e = v>>52;
37011
- if( (e&0x7ff)==0x7ff ){
37202
+ e = (v>>52)&0x7ff;
37203
+ if( e==0x7ff ){
3701237204
p->isSpecial = 1 + (v!=0x7ff0000000000000LL);
3701337205
p->n = 0;
3701437206
p->iDP = 0;
3701537207
return;
3701637208
}
37017
-
37018
- /* Multiply r by powers of ten until it lands somewhere in between
37019
- ** 1.0e+19 and 1.0e+17.
37020
- **
37021
- ** Use Dekker-style double-double computation to increase the
37022
- ** precision.
37023
- **
37024
- ** The error terms on constants like 1.0e+100 computed using the
37025
- ** decimal extension, for example as follows:
37026
- **
37027
- ** SELECT decimal_exp(decimal_sub('1.0e+100',decimal(1.0e+100)));
37028
- */
37029
- rr[0] = r;
37030
- rr[1] = 0.0;
37031
- if( rr[0]>9.223372036854774784e+18 ){
37032
- while( rr[0]>9.223372036854774784e+118 ){
37033
- exp += 100;
37034
- dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
37035
- }
37036
- while( rr[0]>9.223372036854774784e+28 ){
37037
- exp += 10;
37038
- dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
37039
- }
37040
- while( rr[0]>9.223372036854774784e+18 ){
37041
- exp += 1;
37042
- dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
37043
- }
37209
+ v &= 0x000fffffffffffffULL;
37210
+ if( e==0 ){
37211
+ int n = countLeadingZeros(v);
37212
+ v <<= n;
37213
+ e = -1074 - n;
3704437214
}else{
37045
- while( rr[0]<9.223372036854774784e-83 ){
37046
- exp -= 100;
37047
- dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
37048
- }
37049
- while( rr[0]<9.223372036854774784e+07 ){
37050
- exp -= 10;
37051
- dekkerMul2(rr, 1.0e+10, 0.0);
37052
- }
37053
- while( rr[0]<9.22337203685477478e+17 ){
37054
- exp -= 1;
37055
- dekkerMul2(rr, 1.0e+01, 0.0);
37056
- }
37057
- }
37058
- v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1];
37215
+ v = (v<<11) | U64_BIT(63);
37216
+ e -= 1086;
37217
+ }
37218
+ sqlite3Fp2Convert10(v, e, 17, &v, &exp);
3705937219
3706037220
/* Extract significant digits. */
3706137221
i = sizeof(p->zBuf)-1;
3706237222
assert( v>0 );
37063
- while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; }
37223
+ while( v>=10 ){
37224
+ int kk = (v%100)*2;
37225
+ assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) );
37226
+ assert( TWO_BYTE_ALIGNMENT(&p->zBuf[i-1]) );
37227
+ *(u16*)(&p->zBuf[i-1]) = *(u16*)&sqlite3DigitPairs.a[kk];
37228
+ i -= 2;
37229
+ v /= 100;
37230
+ }
37231
+ if( v ){
37232
+ assert( v<10 );
37233
+ p->zBuf[i--] = v + '0';
37234
+ }
3706437235
assert( i>=0 && i<sizeof(p->zBuf)-1 );
3706537236
p->n = sizeof(p->zBuf) - 1 - i;
3706637237
assert( p->n>0 );
3706737238
assert( p->n<sizeof(p->zBuf) );
3706837239
p->iDP = p->n + exp;
@@ -84980,36 +85151,40 @@
8498085151
** If pMem is already a string, detect if it is a zero-terminated
8498185152
** string, or make it into one if possible, and mark it as such.
8498285153
**
8498385154
** This is an optimization. Correct operation continues even if
8498485155
** this routine is a no-op.
85156
+**
85157
+** Return true if the strig is zero-terminated after this routine is
85158
+** called and false if it is not.
8498585159
*/
84986
-SQLITE_PRIVATE void sqlite3VdbeMemZeroTerminateIfAble(Mem *pMem){
85160
+SQLITE_PRIVATE int sqlite3VdbeMemZeroTerminateIfAble(Mem *pMem){
8498785161
if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
8498885162
/* pMem must be a string, and it cannot be an ephemeral or static string */
84989
- return;
85163
+ return 0;
8499085164
}
84991
- if( pMem->enc!=SQLITE_UTF8 ) return;
85165
+ if( pMem->enc!=SQLITE_UTF8 ) return 0;
8499285166
assert( pMem->z!=0 );
8499385167
if( pMem->flags & MEM_Dyn ){
8499485168
if( pMem->xDel==sqlite3_free
8499585169
&& sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
8499685170
){
8499785171
pMem->z[pMem->n] = 0;
8499885172
pMem->flags |= MEM_Term;
84999
- return;
85173
+ return 1;
8500085174
}
8500185175
if( pMem->xDel==sqlite3RCStrUnref ){
8500285176
/* Blindly assume that all RCStr objects are zero-terminated */
8500385177
pMem->flags |= MEM_Term;
85004
- return;
85178
+ return 1;
8500585179
}
8500685180
}else if( pMem->szMalloc >= pMem->n+1 ){
8500785181
pMem->z[pMem->n] = 0;
8500885182
pMem->flags |= MEM_Term;
85009
- return;
85183
+ return 1;
8501085184
}
85185
+ return 0;
8501185186
}
8501285187
8501385188
/*
8501485189
** It is already known that pMem contains an unterminated string.
8501585190
** Add the zero terminator.
@@ -85302,23 +85477,75 @@
8530285477
return memIntValue(pMem);
8530385478
}else{
8530485479
return 0;
8530585480
}
8530685481
}
85482
+
85483
+/*
85484
+** Invoke sqlite3AtoF() on the text value of pMem and return the
85485
+** double result. If sqlite3AtoF() returns an error code, write
85486
+** that code into *pRC if (*pRC)!=NULL.
85487
+**
85488
+** The caller must ensure that pMem->db!=0 and that pMem is in
85489
+** mode MEM_Str or MEM_Blob.
85490
+*/
85491
+SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem *pMem, int *pRC){
85492
+ double val = (double)0;
85493
+ int rc = 0;
85494
+ assert( pMem->db!=0 );
85495
+ assert( pMem->flags & (MEM_Str|MEM_Blob) );
85496
+ if( pMem->z==0 ){
85497
+ /* no-op */
85498
+ }else if( pMem->enc==SQLITE_UTF8
85499
+ && ((pMem->flags & MEM_Term)!=0 || sqlite3VdbeMemZeroTerminateIfAble(pMem))
85500
+ ){
85501
+ rc = sqlite3AtoF(pMem->z, &val);
85502
+ }else if( pMem->n==0 ){
85503
+ /* no-op */
85504
+ }else if( pMem->enc==SQLITE_UTF8 ){
85505
+ char *zCopy = sqlite3DbStrNDup(pMem->db, pMem->z, pMem->n);
85506
+ if( zCopy ){
85507
+ rc = sqlite3AtoF(zCopy, &val);
85508
+ sqlite3DbFree(pMem->db, zCopy);
85509
+ }
85510
+ }else{
85511
+ int n, i, j;
85512
+ char *zCopy;
85513
+ const char *z;
85514
+
85515
+ n = pMem->n & ~1;
85516
+ zCopy = sqlite3DbMallocRaw(pMem->db, n/2 + 2);
85517
+ if( zCopy ){
85518
+ z = pMem->z;
85519
+ if( pMem->enc==SQLITE_UTF16LE ){
85520
+ for(i=j=0; i<n-1; i+=2, j++){
85521
+ zCopy[j] = z[i];
85522
+ if( z[i+1]!=0 ) break;
85523
+ }
85524
+ }else{
85525
+ for(i=j=0; i<n-1; i+=2, j++){
85526
+ if( z[i]!=0 ) break;
85527
+ zCopy[j] = z[i+1];
85528
+ }
85529
+ }
85530
+ assert( j<=n/2 );
85531
+ zCopy[j] = 0;
85532
+ rc = sqlite3AtoF(zCopy, &val);
85533
+ if( i<n ) rc = -100;
85534
+ sqlite3DbFree(pMem->db, zCopy);
85535
+ }
85536
+ }
85537
+ if( pRC ) *pRC = rc;
85538
+ return val;
85539
+}
8530785540
8530885541
/*
8530985542
** Return the best representation of pMem that we can get into a
8531085543
** double. If pMem is already a double or an integer, return its
8531185544
** value. If it is a string or blob, try to convert it to a double.
8531285545
** If it is a NULL, return 0.0.
8531385546
*/
85314
-static SQLITE_NOINLINE double memRealValue(Mem *pMem){
85315
- /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
85316
- double val = (double)0;
85317
- sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
85318
- return val;
85319
-}
8532085547
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
8532185548
assert( pMem!=0 );
8532285549
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
8532385550
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
8532485551
if( pMem->flags & MEM_Real ){
@@ -85325,11 +85552,11 @@
8532585552
return pMem->u.r;
8532685553
}else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
8532785554
testcase( pMem->flags & MEM_IntReal );
8532885555
return (double)pMem->u.i;
8532985556
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
85330
- return memRealValue(pMem);
85557
+ return sqlite3MemRealValueRC(pMem, 0);
8533185558
}else{
8533285559
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
8533385560
return (double)0;
8533485561
}
8533585562
}
@@ -85449,11 +85676,11 @@
8544985676
if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
8545085677
int rc;
8545185678
sqlite3_int64 ix;
8545285679
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
8545385680
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85454
- rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
85681
+ pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
8545585682
if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
8545685683
|| sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
8545785684
){
8545885685
pMem->u.i = ix;
8545985686
MemSetTypeFlag(pMem, MEM_Int);
@@ -86420,11 +86647,11 @@
8642086647
}
8642186648
}
8642286649
if( affinity==SQLITE_AFF_BLOB ){
8642386650
if( op==TK_FLOAT ){
8642486651
assert( pVal && pVal->z && pVal->flags==(MEM_Str|MEM_Term) );
86425
- sqlite3AtoF(pVal->z, &pVal->u.r, pVal->n, SQLITE_UTF8);
86652
+ sqlite3AtoF(pVal->z, &pVal->u.r);
8642686653
pVal->flags = MEM_Real;
8642786654
}else if( op==TK_INTEGER ){
8642886655
/* This case is required by -9223372036854775808 and other strings
8642986656
** that look like integers but cannot be handled by the
8643086657
** sqlite3DecOrHexToI64() call above. */
@@ -86688,10 +86915,15 @@
8668886915
** the column value into *ppVal. If *ppVal is initially NULL then a new
8668986916
** sqlite3_value object is allocated.
8669086917
**
8669186918
** If *ppVal is initially NULL then the caller is responsible for
8669286919
** ensuring that the value written into *ppVal is eventually freed.
86920
+**
86921
+** If the buffer does not contain a well-formed record, this routine may
86922
+** read several bytes past the end of the buffer. Callers must therefore
86923
+** ensure that any buffer which may contain a corrupt record is padded
86924
+** with at least 8 bytes of addressable memory.
8669386925
*/
8669486926
SQLITE_PRIVATE int sqlite3Stat4Column(
8669586927
sqlite3 *db, /* Database handle */
8669686928
const void *pRec, /* Pointer to buffer containing record */
8669786929
int nRec, /* Size of buffer pRec in bytes */
@@ -95661,14 +95893,13 @@
9566195893
** point or exponential notation, the result is only MEM_Real, even
9566295894
** if there is an exact integer representation of the quantity.
9566395895
*/
9566495896
static void applyNumericAffinity(Mem *pRec, int bTryForInt){
9566595897
double rValue;
95666
- u8 enc = pRec->enc;
9566795898
int rc;
9566895899
assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
95669
- rc = sqlite3AtoF(pRec->z, &rValue, pRec->n, enc);
95900
+ rValue = sqlite3MemRealValueRC(pRec, &rc);
9567095901
if( rc<=0 ) return;
9567195902
if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
9567295903
pRec->flags |= MEM_Int;
9567395904
}else{
9567495905
pRec->u.r = rValue;
@@ -95746,11 +95977,14 @@
9574695977
*/
9574795978
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
9574895979
int eType = sqlite3_value_type(pVal);
9574995980
if( eType==SQLITE_TEXT ){
9575095981
Mem *pMem = (Mem*)pVal;
95982
+ assert( pMem->db!=0 );
95983
+ sqlite3_mutex_enter(pMem->db->mutex);
9575195984
applyNumericAffinity(pMem, 0);
95985
+ sqlite3_mutex_leave(pMem->db->mutex);
9575295986
eType = sqlite3_value_type(pVal);
9575395987
}
9575495988
return eType;
9575595989
}
9575695990
@@ -95779,11 +96013,11 @@
9577996013
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
9578096014
if( ExpandBlob(pMem) ){
9578196015
pMem->u.i = 0;
9578296016
return MEM_Int;
9578396017
}
95784
- rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
96018
+ pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
9578596019
if( rc<=0 ){
9578696020
if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
9578796021
pMem->u.i = ix;
9578896022
return MEM_Int;
9578996023
}else{
@@ -110056,11 +110290,11 @@
110056110290
*/
110057110291
static int exprProbability(Expr *p){
110058110292
double r = -1.0;
110059110293
if( p->op!=TK_FLOAT ) return -1;
110060110294
assert( !ExprHasProperty(p, EP_IntValue) );
110061
- sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
110295
+ sqlite3AtoF(p->u.zToken, &r);
110062110296
assert( r>=0.0 );
110063110297
if( r>1.0 ) return -1;
110064110298
return (int)(r*134217728.0);
110065110299
}
110066110300
@@ -111192,10 +111426,18 @@
111192111426
** number of expressions in the select list. */
111193111427
if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
111194111428
sqlite3SelectWrongNumTermsError(pParse, p->pNext);
111195111429
return WRC_Abort;
111196111430
}
111431
+
111432
+ /* If the SELECT statement contains ON clauses that were moved into
111433
+ ** the WHERE clause, go through and verify that none of the terms
111434
+ ** in the ON clauses reference tables to the right of the ON clause. */
111435
+ if( (p->selFlags & SF_OnToWhere) ){
111436
+ sqlite3SelectCheckOnClauses(pParse, p);
111437
+ if( pParse->nErr ) return WRC_Abort;
111438
+ }
111197111439
111198111440
/* Advance to the next term of the compound
111199111441
*/
111200111442
p = p->pPrior;
111201111443
nCompound++;
@@ -114854,18 +115096,25 @@
114854115096
/* Could not find an existing table or index to use as the RHS b-tree.
114855115097
** We will have to generate an ephemeral table to do the job.
114856115098
*/
114857115099
u32 savedNQueryLoop = pParse->nQueryLoop;
114858115100
int rMayHaveNull = 0;
115101
+ int bloomOk = (inFlags & IN_INDEX_MEMBERSHIP)!=0;
114859115102
eType = IN_INDEX_EPH;
114860115103
if( inFlags & IN_INDEX_LOOP ){
114861115104
pParse->nQueryLoop = 0;
114862115105
}else if( prRhsHasNull ){
114863115106
*prRhsHasNull = rMayHaveNull = ++pParse->nMem;
114864115107
}
114865115108
assert( pX->op==TK_IN );
114866
- sqlite3CodeRhsOfIN(pParse, pX, iTab);
115109
+ if( !bloomOk
115110
+ && ExprUseXSelect(pX)
115111
+ && (pX->x.pSelect->selFlags & SF_ClonedRhsIn)!=0
115112
+ ){
115113
+ bloomOk = 1;
115114
+ }
115115
+ sqlite3CodeRhsOfIN(pParse, pX, iTab, bloomOk);
114867115116
if( rMayHaveNull ){
114868115117
sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
114869115118
}
114870115119
pParse->nQueryLoop = savedNQueryLoop;
114871115120
}
@@ -115019,11 +115268,12 @@
115019115268
** is used.
115020115269
*/
115021115270
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
115022115271
Parse *pParse, /* Parsing context */
115023115272
Expr *pExpr, /* The IN operator */
115024
- int iTab /* Use this cursor number */
115273
+ int iTab, /* Use this cursor number */
115274
+ int allowBloom /* True to allow the use of a Bloom filter */
115025115275
){
115026115276
int addrOnce = 0; /* Address of the OP_Once instruction at top */
115027115277
int addr; /* Address of OP_OpenEphemeral instruction */
115028115278
Expr *pLeft; /* the LHS of the IN operator */
115029115279
KeyInfo *pKeyInfo = 0; /* Key information */
@@ -115141,11 +115391,14 @@
115141115391
int rc;
115142115392
int addrBloom = 0;
115143115393
sqlite3SelectDestInit(&dest, SRT_Set, iTab);
115144115394
dest.zAffSdst = exprINAffinity(pParse, pExpr);
115145115395
pSelect->iLimit = 0;
115146
- if( addrOnce && OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){
115396
+ if( addrOnce
115397
+ && allowBloom
115398
+ && OptimizationEnabled(pParse->db, SQLITE_BloomFilter)
115399
+ ){
115147115400
int regBloom = ++pParse->nMem;
115148115401
addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
115149115402
VdbeComment((v, "Bloom filter"));
115150115403
dest.iSDParm2 = regBloom;
115151115404
}
@@ -115726,11 +115979,11 @@
115726115979
** like the continuation of the number.
115727115980
*/
115728115981
static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
115729115982
if( ALWAYS(z!=0) ){
115730115983
double value;
115731
- sqlite3AtoF(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
115984
+ sqlite3AtoF(z, &value);
115732115985
assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
115733115986
if( negateFlag ) value = -value;
115734115987
sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
115735115988
}
115736115989
}
@@ -118827,11 +119080,14 @@
118827119080
if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
118828119081
}
118829119082
if( pIEpr==0 ) break;
118830119083
if( NEVER(!ExprUseYTab(pExpr)) ) break;
118831119084
for(i=0; i<pSrcList->nSrc; i++){
118832
- if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break;
119085
+ if( pSrcList->a[i].iCursor==pIEpr->iDataCur ){
119086
+ testcase( i>0 );
119087
+ break;
119088
+ }
118833119089
}
118834119090
if( i>=pSrcList->nSrc ) break;
118835119091
if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
118836119092
if( pParse->nErr ){ return WRC_Abort; }
118837119093
@@ -124902,11 +125158,11 @@
124902125158
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
124903125159
#endif
124904125160
sqlite3_mutex_enter(db->mutex);
124905125161
db->xAuth = (sqlite3_xauth)xAuth;
124906125162
db->pAuthArg = pArg;
124907
- if( db->xAuth ) sqlite3ExpirePreparedStatements(db, 1);
125163
+ sqlite3ExpirePreparedStatements(db, 1);
124908125164
sqlite3_mutex_leave(db->mutex);
124909125165
return SQLITE_OK;
124910125166
}
124911125167
124912125168
/*
@@ -125573,10 +125829,11 @@
125573125829
SrcItem *p
125574125830
){
125575125831
const char *zDb;
125576125832
if( p->fg.fixedSchema ){
125577125833
int iDb = sqlite3SchemaToIndex(pParse->db, p->u4.pSchema);
125834
+ assert( iDb>=0 && iDb<pParse->db->nDb );
125578125835
zDb = pParse->db->aDb[iDb].zDbSName;
125579125836
}else{
125580125837
assert( !p->fg.isSubquery );
125581125838
zDb = p->u4.zDatabase;
125582125839
}
@@ -127657,17 +127914,18 @@
127657127914
**
127658127915
** zName is temporarily modified while this routine is running, but is
127659127916
** restored to its original value prior to this routine returning.
127660127917
*/
127661127918
SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
127662
- char *zTail; /* Pointer to the last "_" in zName */
127919
+ const char *zTail; /* Pointer to the last "_" in zName */
127663127920
Table *pTab; /* Table that zName is a shadow of */
127921
+ char *zCopy;
127664127922
zTail = strrchr(zName, '_');
127665127923
if( zTail==0 ) return 0;
127666
- *zTail = 0;
127667
- pTab = sqlite3FindTable(db, zName, 0);
127668
- *zTail = '_';
127924
+ zCopy = sqlite3DbStrNDup(db, zName, (int)(zTail-zName));
127925
+ pTab = zCopy ? sqlite3FindTable(db, zCopy, 0) : 0;
127926
+ sqlite3DbFree(db, zCopy);
127669127927
if( pTab==0 ) return 0;
127670127928
if( !IsVirtual(pTab) ) return 0;
127671127929
return sqlite3IsShadowTableOf(db, pTab, zName);
127672127930
}
127673127931
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
@@ -127816,10 +128074,11 @@
127816128074
}
127817128075
p->tabFlags |= TF_WithoutRowid | TF_NoVisibleRowid;
127818128076
convertToWithoutRowidTable(pParse, p);
127819128077
}
127820128078
iDb = sqlite3SchemaToIndex(db, p->pSchema);
128079
+ assert( iDb>=0 && iDb<=db->nDb );
127821128080
127822128081
#ifndef SQLITE_OMIT_CHECK
127823128082
/* Resolve names in all CHECK constraint expressions.
127824128083
*/
127825128084
if( p->pCheck ){
@@ -128111,10 +128370,11 @@
128111128370
p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */
128112128371
#endif
128113128372
128114128373
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
128115128374
iDb = sqlite3SchemaToIndex(db, p->pSchema);
128375
+ assert( iDb>=0 && iDb<db->nDb );
128116128376
sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
128117128377
if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
128118128378
128119128379
/* Make a copy of the entire SELECT statement that defines the view.
128120128380
** This will force all the Expr.token.z values to be dynamically
@@ -129707,10 +129967,11 @@
129707129967
sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
129708129968
"or PRIMARY KEY constraint cannot be dropped", 0);
129709129969
goto exit_drop_index;
129710129970
}
129711129971
iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
129972
+ assert( iDb>=0 && iDb<db->nDb );
129712129973
#ifndef SQLITE_OMIT_AUTHORIZATION
129713129974
{
129714129975
int code = SQLITE_DROP_INDEX;
129715129976
Table *pTab = pIndex->pTable;
129716129977
const char *zDb = db->aDb[iDb].zDbSName;
@@ -132953,11 +133214,11 @@
132953133214
zBuf = sqlite3_mprintf("%!.*f",(int)n,r);
132954133215
if( zBuf==0 ){
132955133216
sqlite3_result_error_nomem(context);
132956133217
return;
132957133218
}
132958
- sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8);
133219
+ sqlite3AtoF(zBuf, &r);
132959133220
sqlite3_free(zBuf);
132960133221
}
132961133222
sqlite3_result_double(context, r);
132962133223
}
132963133224
#endif
@@ -133591,11 +133852,11 @@
133591133852
const char *zVal;
133592133853
r1 = sqlite3_value_double(pValue);
133593133854
sqlite3_str_appendf(pStr, "%!0.15g", r1);
133594133855
zVal = sqlite3_str_value(pStr);
133595133856
if( zVal ){
133596
- sqlite3AtoF(zVal, &r2, pStr->nChar, SQLITE_UTF8);
133857
+ sqlite3AtoF(zVal, &r2);
133597133858
if( r1!=r2 ){
133598133859
sqlite3_str_reset(pStr);
133599133860
sqlite3_str_appendf(pStr, "%!0.20e", r1);
133600133861
}
133601133862
}
@@ -133688,11 +133949,11 @@
133688133949
sqlite3_result_error_nomem(context);
133689133950
return;
133690133951
}
133691133952
i = j = 0;
133692133953
while( i<nIn ){
133693
- char *z = strchr(&zIn[i],'\\');
133954
+ const char *z = strchr(&zIn[i],'\\');
133694133955
if( z==0 ){
133695133956
n = nIn - i;
133696133957
memmove(&zOut[j], &zIn[i], n);
133697133958
j += n;
133698133959
break;
@@ -136859,10 +137120,11 @@
136859137120
/* If foreign-keys are disabled, this function is a no-op. */
136860137121
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
136861137122
if( !IsOrdinaryTable(pTab) ) return;
136862137123
136863137124
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137125
+ assert( iDb>=00 && iDb<db->nDb );
136864137126
zDb = db->aDb[iDb].zDbSName;
136865137127
136866137128
/* Loop through all the foreign key constraints for which pTab is the
136867137129
** child table (the table that the foreign key definition is part of). */
136868137130
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
@@ -141374,10 +141636,11 @@
141374141636
int (*db_status64)(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);
141375141637
/* Version 3.52.0 and later */
141376141638
void (*str_truncate)(sqlite3_str*,int);
141377141639
void (*str_free)(sqlite3_str*);
141378141640
int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
141641
+ int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
141379141642
};
141380141643
141381141644
/*
141382141645
** This is the function signature used for all extension entry points. It
141383141646
** is also defined in the file "loadext.c".
@@ -141716,10 +141979,11 @@
141716141979
#define sqlite3_db_status64 sqlite3_api->db_status64
141717141980
/* Version 3.52.0 and later */
141718141981
#define sqlite3_str_truncate sqlite3_api->str_truncate
141719141982
#define sqlite3_str_free sqlite3_api->str_free
141720141983
#define sqlite3_carray_bind sqlite3_api->carray_bind
141984
+#define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
141721141985
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
141722141986
141723141987
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
141724141988
/* This case when the file really is being compiled as a loadable
141725141989
** extension */
@@ -142247,12 +142511,14 @@
142247142511
sqlite3_db_status64,
142248142512
/* Version 3.52.0 and later */
142249142513
sqlite3_str_truncate,
142250142514
sqlite3_str_free,
142251142515
#ifdef SQLITE_ENABLE_CARRAY
142252
- sqlite3_carray_bind
142516
+ sqlite3_carray_bind,
142517
+ sqlite3_carray_bind_v2
142253142518
#else
142519
+ 0,
142254142520
0
142255142521
#endif
142256142522
};
142257142523
142258142524
/* True if x is the directory separator character
@@ -148181,10 +148447,14 @@
148181148447
p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
148182148448
pRight->u3.pOn = 0;
148183148449
pRight->fg.isOn = 1;
148184148450
p->selFlags |= SF_OnToWhere;
148185148451
}
148452
+
148453
+ if( IsVirtual(pRightTab) && joinType==EP_OuterON && pRight->u1.pFuncArg ){
148454
+ p->selFlags |= SF_OnToWhere;
148455
+ }
148186148456
}
148187148457
return 0;
148188148458
}
148189148459
148190148460
/*
@@ -150108,11 +150378,11 @@
150108150378
** function is responsible for ensuring that this structure is eventually
150109150379
** freed.
150110150380
*/
150111150381
static KeyInfo *multiSelectByMergeKeyInfo(Parse *pParse, Select *p, int nExtra){
150112150382
ExprList *pOrderBy = p->pOrderBy;
150113
- int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0;
150383
+ int nOrderBy = (pOrderBy!=0) ? pOrderBy->nExpr : 0;
150114150384
sqlite3 *db = pParse->db;
150115150385
KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
150116150386
if( pRet ){
150117150387
int i;
150118150388
for(i=0; i<nOrderBy; i++){
@@ -150911,14 +151181,12 @@
150911151181
** EofB: ...
150912151182
** AltB: ...
150913151183
** AeqB: ...
150914151184
** AgtB: ...
150915151185
** Init: initialize coroutine registers
150916
-** yield coA
150917
-** if eof(A) goto EofA
150918
-** yield coB
150919
-** if eof(B) goto EofB
151186
+** yield coA, on eof goto EofA
151187
+** yield coB, on eof goto EofB
150920151188
** Cmpr: Compare A, B
150921151189
** Jump AltB, AeqB, AgtB
150922151190
** End: ...
150923151191
**
150924151192
** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
@@ -151006,30 +151274,33 @@
151006151274
}
151007151275
}
151008151276
}
151009151277
151010151278
/* Compute the comparison permutation and keyinfo that is used with
151011
- ** the permutation used to determine if the next
151012
- ** row of results comes from selectA or selectB. Also add explicit
151013
- ** collations to the ORDER BY clause terms so that when the subqueries
151014
- ** to the right and the left are evaluated, they use the correct
151015
- ** collation.
151279
+ ** the permutation to determine if the next row of results comes
151280
+ ** from selectA or selectB. Also add literal collations to the
151281
+ ** ORDER BY clause terms so that when selectA and selectB are
151282
+ ** evaluated, they use the correct collation.
151016151283
*/
151017151284
aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1));
151018151285
if( aPermute ){
151019151286
struct ExprList_item *pItem;
151287
+ int bKeep = 0;
151020151288
aPermute[0] = nOrderBy;
151021151289
for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
151022151290
assert( pItem!=0 );
151023151291
assert( pItem->u.x.iOrderByCol>0 );
151024151292
assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr );
151025151293
aPermute[i] = pItem->u.x.iOrderByCol - 1;
151294
+ if( aPermute[i]!=(u32)i-1 ) bKeep = 1;
151026151295
}
151027
- pKeyMerge = multiSelectByMergeKeyInfo(pParse, p, 1);
151028
- }else{
151029
- pKeyMerge = 0;
151296
+ if( bKeep==0 ){
151297
+ sqlite3DbFreeNN(db, aPermute);
151298
+ aPermute = 0;
151299
+ }
151030151300
}
151301
+ pKeyMerge = multiSelectByMergeKeyInfo(pParse, p, 1);
151031151302
151032151303
/* Allocate a range of temporary registers and the KeyInfo needed
151033151304
** for the logic that removes duplicate result rows when the
151034151305
** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
151035151306
*/
@@ -151104,11 +151375,11 @@
151104151375
/* Generate a coroutine to evaluate the SELECT statement to the
151105151376
** left of the compound operator - the "A" select.
151106151377
*/
151107151378
addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
151108151379
addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
151109
- VdbeComment((v, "left SELECT"));
151380
+ VdbeComment((v, "SUBR: next-A"));
151110151381
pPrior->iLimit = regLimitA;
151111151382
ExplainQueryPlan((pParse, 1, "LEFT"));
151112151383
sqlite3Select(pParse, pPrior, &destA);
151113151384
sqlite3VdbeEndCoroutine(v, regAddrA);
151114151385
sqlite3VdbeJumpHere(v, addr1);
@@ -151116,11 +151387,11 @@
151116151387
/* Generate a coroutine to evaluate the SELECT statement on
151117151388
** the right - the "B" select
151118151389
*/
151119151390
addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
151120151391
addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
151121
- VdbeComment((v, "right SELECT"));
151392
+ VdbeComment((v, "SUBR: next-B"));
151122151393
savedLimit = p->iLimit;
151123151394
savedOffset = p->iOffset;
151124151395
p->iLimit = regLimitB;
151125151396
p->iOffset = 0;
151126151397
ExplainQueryPlan((pParse, 1, "RIGHT"));
@@ -151130,20 +151401,20 @@
151130151401
sqlite3VdbeEndCoroutine(v, regAddrB);
151131151402
151132151403
/* Generate a subroutine that outputs the current row of the A
151133151404
** select as the next output row of the compound select.
151134151405
*/
151135
- VdbeNoopComment((v, "Output routine for A"));
151406
+ VdbeNoopComment((v, "SUBR: out-A"));
151136151407
addrOutA = generateOutputSubroutine(pParse,
151137151408
p, &destA, pDest, regOutA,
151138151409
regPrev, pKeyDup, labelEnd);
151139151410
151140151411
/* Generate a subroutine that outputs the current row of the B
151141151412
** select as the next output row of the compound select.
151142151413
*/
151143151414
if( op==TK_ALL || op==TK_UNION ){
151144
- VdbeNoopComment((v, "Output routine for B"));
151415
+ VdbeNoopComment((v, "SUBR: out-B"));
151145151416
addrOutB = generateOutputSubroutine(pParse,
151146151417
p, &destB, pDest, regOutB,
151147151418
regPrev, pKeyDup, labelEnd);
151148151419
}
151149151420
sqlite3KeyInfoUnref(pKeyDup);
@@ -151152,14 +151423,16 @@
151152151423
** are exhausted and only data in select B remains.
151153151424
*/
151154151425
if( op==TK_EXCEPT || op==TK_INTERSECT ){
151155151426
addrEofA_noB = addrEofA = labelEnd;
151156151427
}else{
151157
- VdbeNoopComment((v, "eof-A subroutine"));
151428
+ VdbeNoopComment((v, "SUBR: eof-A"));
151158151429
addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
151430
+ VdbeComment((v, "out-B"));
151159151431
addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
151160151432
VdbeCoverage(v);
151433
+ VdbeComment((v, "next-B"));
151161151434
sqlite3VdbeGoto(v, addrEofA);
151162151435
p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
151163151436
}
151164151437
151165151438
/* Generate a subroutine to run when the results from select B
@@ -151167,21 +151440,24 @@
151167151440
*/
151168151441
if( op==TK_INTERSECT ){
151169151442
addrEofB = addrEofA;
151170151443
if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
151171151444
}else{
151172
- VdbeNoopComment((v, "eof-B subroutine"));
151445
+ VdbeNoopComment((v, "SUBR: eof-B"));
151173151446
addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
151447
+ VdbeComment((v, "out-A"));
151174151448
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
151449
+ VdbeComment((v, "next-A"));
151175151450
sqlite3VdbeGoto(v, addrEofB);
151176151451
}
151177151452
151178151453
/* Generate code to handle the case of A<B
151179151454
*/
151180
- VdbeNoopComment((v, "A-lt-B subroutine"));
151181151455
addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
151456
+ VdbeComment((v, "out-A"));
151182151457
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
151458
+ VdbeComment((v, "next-A"));
151183151459
sqlite3VdbeGoto(v, labelCmpr);
151184151460
151185151461
/* Generate code to handle the case of A==B
151186151462
*/
151187151463
if( op==TK_ALL ){
@@ -151188,40 +151464,52 @@
151188151464
addrAeqB = addrAltB;
151189151465
}else if( op==TK_INTERSECT ){
151190151466
addrAeqB = addrAltB;
151191151467
addrAltB++;
151192151468
}else{
151193
- VdbeNoopComment((v, "A-eq-B subroutine"));
151194
- addrAeqB =
151195
- sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
151196
- sqlite3VdbeGoto(v, labelCmpr);
151469
+ addrAeqB = addrAltB + 1;
151197151470
}
151198151471
151199151472
/* Generate code to handle the case of A>B
151200151473
*/
151201
- VdbeNoopComment((v, "A-gt-B subroutine"));
151202151474
addrAgtB = sqlite3VdbeCurrentAddr(v);
151203151475
if( op==TK_ALL || op==TK_UNION ){
151204151476
sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
151477
+ VdbeComment((v, "out-B"));
151478
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
151479
+ VdbeComment((v, "next-B"));
151480
+ sqlite3VdbeGoto(v, labelCmpr);
151481
+ }else{
151482
+ addrAgtB++; /* Just do next-B. Might as well use the next-B call
151483
+ ** in the next code block */
151205151484
}
151206
- sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
151207
- sqlite3VdbeGoto(v, labelCmpr);
151208151485
151209151486
/* This code runs once to initialize everything.
151210151487
*/
151211151488
sqlite3VdbeJumpHere(v, addr1);
151212151489
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
151490
+ VdbeComment((v, "next-A"));
151491
+ /* v--- Also the A>B case for EXCEPT and INTERSECT */
151213151492
sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
151493
+ VdbeComment((v, "next-B"));
151214151494
151215151495
/* Implement the main merge loop
151216151496
*/
151497
+ if( aPermute!=0 ){
151498
+ sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
151499
+ }
151217151500
sqlite3VdbeResolveLabel(v, labelCmpr);
151218
- sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
151219151501
sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
151220151502
(char*)pKeyMerge, P4_KEYINFO);
151221
- sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
151222
- sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
151503
+ if( aPermute!=0 ){
151504
+ sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
151505
+ }
151506
+ sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
151507
+ VdbeCoverageIf(v, op==TK_ALL);
151508
+ VdbeCoverageIf(v, op==TK_UNION);
151509
+ VdbeCoverageIf(v, op==TK_EXCEPT);
151510
+ VdbeCoverageIf(v, op==TK_INTERSECT);
151223151511
151224151512
/* Jump to the this point in order to terminate the query.
151225151513
*/
151226151514
sqlite3VdbeResolveLabel(v, labelEnd);
151227151515
@@ -152774,10 +153062,20 @@
152774153062
x.isOuterJoin = 0;
152775153063
x.nSelDepth = 0;
152776153064
x.pEList = pSubq->pEList;
152777153065
x.pCList = findLeftmostExprlist(pSubq);
152778153066
pNew = substExpr(&x, pNew);
153067
+ assert( pNew!=0 || pParse->nErr!=0 );
153068
+ if( pParse->nErr==0 && pNew->op==TK_IN && ExprUseXSelect(pNew) ){
153069
+ assert( pNew->x.pSelect!=0 );
153070
+ pNew->x.pSelect->selFlags |= SF_ClonedRhsIn;
153071
+ assert( pWhere!=0 );
153072
+ assert( pWhere->op==TK_IN );
153073
+ assert( ExprUseXSelect(pWhere) );
153074
+ assert( pWhere->x.pSelect!=0 );
153075
+ pWhere->x.pSelect->selFlags |= SF_ClonedRhsIn;
153076
+ }
152779153077
#ifndef SQLITE_OMIT_WINDOWFUNC
152780153078
if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
152781153079
/* Restriction 6c has prevented push-down in this case */
152782153080
sqlite3ExprDelete(pParse->db, pNew);
152783153081
nChng--;
@@ -154892,10 +155190,11 @@
154892155190
*/
154893155191
typedef struct CheckOnCtx CheckOnCtx;
154894155192
struct CheckOnCtx {
154895155193
SrcList *pSrc; /* SrcList for this context */
154896155194
int iJoin; /* Cursor numbers must be =< than this */
155195
+ int bFuncArg; /* True for table-function arg */
154897155196
CheckOnCtx *pParent; /* Parent context */
154898155197
};
154899155198
154900155199
/*
154901155200
** True if the SrcList passed as the only argument contains at least
@@ -154943,11 +155242,13 @@
154943155242
SrcList *pSrc = pCtx->pSrc;
154944155243
int iTab = pExpr->iTable;
154945155244
if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){
154946155245
if( pCtx->iJoin && iTab>pCtx->iJoin ){
154947155246
sqlite3ErrorMsg(pWalker->pParse,
154948
- "ON clause references tables to its right");
155247
+ "%s references tables to its right",
155248
+ (pCtx->bFuncArg ? "table-function argument" : "ON clause")
155249
+ );
154949155250
return WRC_Abort;
154950155251
}
154951155252
break;
154952155253
}
154953155254
pCtx = pCtx->pParent;
@@ -154978,24 +155279,39 @@
154978155279
154979155280
/*
154980155281
** Check all ON clauses in pSelect to verify that they do not reference
154981155282
** columns to the right.
154982155283
*/
154983
-static void selectCheckOnClauses(Parse *pParse, Select *pSelect){
155284
+SQLITE_PRIVATE void sqlite3SelectCheckOnClauses(Parse *pParse, Select *pSelect){
154984155285
Walker w;
154985155286
CheckOnCtx sCtx;
155287
+ int ii;
154986155288
assert( pSelect->selFlags & SF_OnToWhere );
154987155289
assert( pSelect->pSrc!=0 && pSelect->pSrc->nSrc>=2 );
154988155290
memset(&w, 0, sizeof(w));
154989155291
w.pParse = pParse;
154990155292
w.xExprCallback = selectCheckOnClausesExpr;
154991155293
w.xSelectCallback = selectCheckOnClausesSelect;
154992155294
w.u.pCheckOnCtx = &sCtx;
154993155295
memset(&sCtx, 0, sizeof(sCtx));
154994155296
sCtx.pSrc = pSelect->pSrc;
154995
- sqlite3WalkExprNN(&w, pSelect->pWhere);
155297
+ sqlite3WalkExpr(&w, pSelect->pWhere);
154996155298
pSelect->selFlags &= ~SF_OnToWhere;
155299
+
155300
+ /* Check for any table-function args that are attached to virtual tables
155301
+ ** on the RHS of an outer join. They are subject to the same constraints
155302
+ ** as ON clauses. */
155303
+ sCtx.bFuncArg = 1;
155304
+ for(ii=0; ii<pSelect->pSrc->nSrc; ii++){
155305
+ SrcItem *pItem = &pSelect->pSrc->a[ii];
155306
+ if( pItem->fg.isTabFunc
155307
+ && (pItem->fg.jointype & JT_OUTER)
155308
+ ){
155309
+ sCtx.iJoin = pItem->iCursor;
155310
+ sqlite3WalkExprList(&w, pItem->u1.pFuncArg);
155311
+ }
155312
+ }
154997155313
}
154998155314
154999155315
/*
155000155316
** If p2 exists and p1 and p2 have the same number of terms, then change
155001155317
** every term of p1 to have the same sort order as p2 and return true.
@@ -155143,22 +155459,10 @@
155143155459
TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
155144155460
sqlite3TreeViewSelect(0, p, 0);
155145155461
}
155146155462
#endif
155147155463
155148
- /* If the SELECT statement contains ON clauses that were moved into
155149
- ** the WHERE clause, go through and verify that none of the terms
155150
- ** in the ON clauses reference tables to the right of the ON clause.
155151
- ** Do this now, after name resolution, but before query flattening
155152
- */
155153
- if( p->selFlags & SF_OnToWhere ){
155154
- selectCheckOnClauses(pParse, p);
155155
- if( pParse->nErr ){
155156
- goto select_end;
155157
- }
155158
- }
155159
-
155160155464
/* If the SF_UFSrcCheck flag is set, then this function is being called
155161155465
** as part of populating the temp table for an UPDATE...FROM statement.
155162155466
** In this case, it is an error if the target object (pSrc->a[0]) name
155163155467
** or alias is duplicated within FROM clause (pSrc->a[1..n]).
155164155468
**
@@ -157006,10 +157310,11 @@
157006157310
157007157311
pParse->pNewTrigger = 0;
157008157312
if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
157009157313
zName = pTrig->zName;
157010157314
iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
157315
+ assert( iDb>=00 && iDb<db->nDb );
157011157316
pTrig->step_list = pStepList;
157012157317
while( pStepList ){
157013157318
pStepList->pTrig = pTrig;
157014157319
pStepList = pStepList->pNext;
157015157320
}
@@ -163989,11 +164294,11 @@
163989164294
if( NEVER(pTerm==0) ) continue;
163990164295
if( pTerm->eOperator & WO_IN ){
163991164296
if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
163992164297
int iTab = pParse->nTab++;
163993164298
int iCache = ++pParse->nMem;
163994
- sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab);
164299
+ sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab, 0);
163995164300
sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
163996164301
}else{
163997164302
codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
163998164303
addrNotFound = pLevel->addrNxt;
163999164304
}
@@ -165648,17 +165953,18 @@
165648165953
&& ALWAYS(pLeft->y.pTab)
165649165954
&& IsVirtual(pLeft->y.pTab)) /* Might be numeric */
165650165955
){
165651165956
int isNum;
165652165957
double rDummy;
165653
- isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
165958
+ assert( zNew[iTo]==0 );
165959
+ isNum = sqlite3AtoF(zNew, &rDummy);
165654165960
if( isNum<=0 ){
165655165961
if( iTo==1 && zNew[0]=='-' ){
165656165962
isNum = +1;
165657165963
}else{
165658165964
zNew[iTo-1]++;
165659
- isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
165965
+ isNum = sqlite3AtoF(zNew, &rDummy);
165660165966
zNew[iTo-1]--;
165661165967
}
165662165968
}
165663165969
if( isNum>0 ){
165664165970
sqlite3ExprDelete(db, pPrefix);
@@ -165697,10 +166003,38 @@
165697166003
sqlite3ValueFree(pVal);
165698166004
return rc;
165699166005
}
165700166006
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
165701166007
166008
+/*
166009
+** If pExpr is one of "like", "glob", "match", or "regexp", then
166010
+** return the corresponding SQLITE_INDEX_CONSTRAINT_xxxx value.
166011
+** If not, return 0.
166012
+**
166013
+** pExpr is guaranteed to be a TK_FUNCTION.
166014
+*/
166015
+SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr *pExpr){
166016
+ static const struct {
166017
+ const char *zOp;
166018
+ unsigned char eOp;
166019
+ } aOp[] = {
166020
+ { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
166021
+ { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
166022
+ { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
166023
+ { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
166024
+ };
166025
+ int i;
166026
+ assert( pExpr->op==TK_FUNCTION );
166027
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
166028
+ for(i=0; i<ArraySize(aOp); i++){
166029
+ if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
166030
+ return aOp[i].eOp;
166031
+ }
166032
+ }
166033
+ return 0;
166034
+}
166035
+
165702166036
165703166037
#ifndef SQLITE_OMIT_VIRTUALTABLE
165704166038
/*
165705166039
** Check to see if the pExpr expression is a form that needs to be passed
165706166040
** to the xBestIndex method of virtual tables. Forms of interest include:
@@ -165733,19 +166067,10 @@
165733166067
unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
165734166068
Expr **ppLeft, /* Column expression to left of MATCH/op2 */
165735166069
Expr **ppRight /* Expression to left of MATCH/op2 */
165736166070
){
165737166071
if( pExpr->op==TK_FUNCTION ){
165738
- static const struct Op2 {
165739
- const char *zOp;
165740
- unsigned char eOp2;
165741
- } aOp[] = {
165742
- { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
165743
- { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
165744
- { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
165745
- { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
165746
- };
165747166072
ExprList *pList;
165748166073
Expr *pCol; /* Column reference */
165749166074
int i;
165750166075
165751166076
assert( ExprUseXList(pExpr) );
@@ -165761,20 +166086,15 @@
165761166086
** vtab_column MATCH expression
165762166087
** MATCH(expression,vtab_column)
165763166088
*/
165764166089
pCol = pList->a[1].pExpr;
165765166090
assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
165766
- if( ExprIsVtab(pCol) ){
165767
- for(i=0; i<ArraySize(aOp); i++){
165768
- assert( !ExprHasProperty(pExpr, EP_IntValue) );
165769
- if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
165770
- *peOp2 = aOp[i].eOp2;
165771
- *ppRight = pList->a[0].pExpr;
165772
- *ppLeft = pCol;
165773
- return 1;
165774
- }
165775
- }
166091
+ if( ExprIsVtab(pCol) && (i = sqlite3ExprIsLikeOperator(pExpr))!=0 ){
166092
+ *peOp2 = i;
166093
+ *ppRight = pList->a[0].pExpr;
166094
+ *ppLeft = pCol;
166095
+ return 1;
165776166096
}
165777166097
165778166098
/* We can also match against the first column of overloaded
165779166099
** functions where xFindFunction returns a value of at least
165780166100
** SQLITE_INDEX_CONSTRAINT_FUNCTION.
@@ -170218,10 +170538,71 @@
170218170538
p->u.btree.pIndex = 0;
170219170539
}
170220170540
}
170221170541
return rc;
170222170542
}
170543
+
170544
+/*
170545
+** Callback for estLikePatternLength().
170546
+**
170547
+** If this node is a string literal that is longer pWalker->sz, then set
170548
+** pWalker->sz to the byte length of that string literal.
170549
+**
170550
+** pWalker->eCode indicates how to count characters:
170551
+**
170552
+** eCode==0 Count as a GLOB pattern
170553
+** eCode==1 Count as a LIKE pattern
170554
+*/
170555
+static int exprNodePatternLengthEst(Walker *pWalker, Expr *pExpr){
170556
+ if( pExpr->op==TK_STRING ){
170557
+ int sz = 0; /* Pattern size in bytes */
170558
+ u8 *z = (u8*)pExpr->u.zToken; /* The pattern */
170559
+ u8 c; /* Next character of the pattern */
170560
+ u8 c1, c2, c3; /* Wildcards */
170561
+ if( pWalker->eCode ){
170562
+ c1 = '%';
170563
+ c2 = '_';
170564
+ c3 = 0;
170565
+ }else{
170566
+ c1 = '*';
170567
+ c2 = '?';
170568
+ c3 = '[';
170569
+ }
170570
+ while( (c = *(z++))!=0 ){
170571
+ if( c==c3 ){
170572
+ if( *z ) z++;
170573
+ while( *z && *z!=']' ) z++;
170574
+ }else if( c!=c1 && c!=c2 ){
170575
+ sz++;
170576
+ }
170577
+ }
170578
+ if( sz>pWalker->u.sz ) pWalker->u.sz = sz;
170579
+ }
170580
+ return WRC_Continue;
170581
+}
170582
+
170583
+/*
170584
+** Return the length of the longest string literal in the given
170585
+** expression.
170586
+**
170587
+** eCode indicates how to count characters:
170588
+**
170589
+** eCode==0 Count as a GLOB pattern
170590
+** eCode==1 Count as a LIKE pattern
170591
+*/
170592
+static int estLikePatternLength(Expr *p, u16 eCode){
170593
+ Walker w;
170594
+ w.u.sz = 0;
170595
+ w.eCode = eCode;
170596
+ w.xExprCallback = exprNodePatternLengthEst;
170597
+ w.xSelectCallback = sqlite3SelectWalkFail;
170598
+#ifdef SQLITE_DEBUG
170599
+ w.xSelectCallback2 = sqlite3SelectWalkAssert2;
170600
+#endif
170601
+ sqlite3WalkExpr(&w, p);
170602
+ return w.u.sz;
170603
+}
170223170604
170224170605
/*
170225170606
** Adjust the WhereLoop.nOut value downward to account for terms of the
170226170607
** WHERE clause that reference the loop but which are not used by an
170227170608
** index.
@@ -170247,10 +170628,17 @@
170247170628
** of rows in the table. In other words, assume that x==EXPR will filter
170248170629
** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
170249170630
** "x" column is boolean or else -1 or 0 or 1 is a common default value
170250170631
** on the "x" column and so in that case only cap the output row estimate
170251170632
** at 1/2 instead of 1/4.
170633
+**
170634
+** Heuristic 3: If there is a LIKE or GLOB (or REGEXP or MATCH) operator
170635
+** with a large constant pattern, then reduce the size of the search
170636
+** space according to the length of the pattern, under the theory that
170637
+** longer patterns are less likely to match. This heuristic was added
170638
+** to give better output-row count estimates when preparing queries for
170639
+** the Join-Order Benchmarks. See forum thread 2026-01-30T09:57:54z
170252170640
*/
170253170641
static void whereLoopOutputAdjust(
170254170642
WhereClause *pWC, /* The WHERE clause */
170255170643
WhereLoop *pLoop, /* The loop to adjust downward */
170256170644
LogEst nRow /* Number of rows in the entire table */
@@ -170296,25 +170684,43 @@
170296170684
** then use the probability provided by the application. */
170297170685
pLoop->nOut += pTerm->truthProb;
170298170686
}else{
170299170687
/* In the absence of explicit truth probabilities, use heuristics to
170300170688
** guess a reasonable truth probability. */
170689
+ Expr *pOpExpr = pTerm->pExpr;
170301170690
pLoop->nOut--;
170302170691
if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
170303170692
&& (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
170304170693
){
170305
- Expr *pRight = pTerm->pExpr->pRight;
170694
+ Expr *pRight = pOpExpr->pRight;
170306170695
int k = 0;
170307
- testcase( pTerm->pExpr->op==TK_IS );
170696
+ testcase( pOpExpr->op==TK_IS );
170308170697
if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
170309170698
k = 10;
170310170699
}else{
170311170700
k = 20;
170312170701
}
170313170702
if( iReduce<k ){
170314170703
pTerm->wtFlags |= TERM_HEURTRUTH;
170315170704
iReduce = k;
170705
+ }
170706
+ }else
170707
+ if( ExprHasProperty(pOpExpr, EP_InfixFunc)
170708
+ && pOpExpr->op==TK_FUNCTION
170709
+ ){
170710
+ int eOp;
170711
+ assert( ExprUseXList(pOpExpr) );
170712
+ assert( pOpExpr->x.pList->nExpr>=2 );
170713
+ eOp = sqlite3ExprIsLikeOperator(pOpExpr);
170714
+ if( ALWAYS(eOp>0) ){
170715
+ int szPattern;
170716
+ Expr *pRHS = pOpExpr->x.pList->a[0].pExpr;
170717
+ eOp = eOp==SQLITE_INDEX_CONSTRAINT_LIKE;
170718
+ szPattern = estLikePatternLength(pRHS, eOp);
170719
+ if( szPattern>0 ){
170720
+ pLoop->nOut -= szPattern*2;
170721
+ }
170316170722
}
170317170723
}
170318170724
}
170319170725
}
170320170726
}
@@ -172136,11 +172542,11 @@
172136172542
SrcItem *pItem;
172137172543
SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
172138172544
sqlite3 *db = pWInfo->pParse->db;
172139172545
int rc = SQLITE_OK;
172140172546
int bFirstPastRJ = 0;
172141
- int hasRightJoin = 0;
172547
+ int hasRightCrossJoin = 0;
172142172548
WhereLoop *pNew;
172143172549
172144172550
172145172551
/* Loop over the tables in the join, from left to right */
172146172552
pNew = pBuilder->pNew;
@@ -172163,16 +172569,24 @@
172163172569
/* Add prerequisites to prevent reordering of FROM clause terms
172164172570
** across CROSS joins and outer joins. The bFirstPastRJ boolean
172165172571
** prevents the right operand of a RIGHT JOIN from being swapped with
172166172572
** other elements even further to the right.
172167172573
**
172168
- ** The JT_LTORJ case and the hasRightJoin flag work together to
172169
- ** prevent FROM-clause terms from moving from the right side of
172170
- ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
172171
- ** is itself on the left side of a RIGHT JOIN.
172574
+ ** The hasRightCrossJoin flag prevent FROM-clause terms from moving
172575
+ ** from the right side of a LEFT JOIN or CROSS JOIN over to the
172576
+ ** left side of that same join. This is a required restriction in
172577
+ ** the case of LEFT JOIN - an incorrect answer may results if it is
172578
+ ** not enforced. This restriction is not required for CROSS JOIN.
172579
+ ** It is provided merely as a means of controlling join order, under
172580
+ ** the theory that no real-world queries that care about performance
172581
+ ** actually use the CROSS JOIN syntax.
172172172582
*/
172173
- if( pItem->fg.jointype & JT_LTORJ ) hasRightJoin = 1;
172583
+ if( pItem->fg.jointype & (JT_LTORJ|JT_CROSS) ){
172584
+ testcase( pItem->fg.jointype & JT_LTORJ );
172585
+ testcase( pItem->fg.jointype & JT_CROSS );
172586
+ hasRightCrossJoin = 1;
172587
+ }
172174172588
mPrereq |= mPrior;
172175172589
bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
172176172590
}else if( pItem->fg.fromExists ){
172177172591
/* joins that result from the EXISTS-to-JOIN optimization should not
172178172592
** be moved to the left of any of their dependencies */
@@ -172182,11 +172596,11 @@
172182172596
for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){
172183172597
if( (pNew->maskSelf & pTerm->prereqAll)!=0 ){
172184172598
mPrereq |= (pTerm->prereqAll & (pNew->maskSelf-1));
172185172599
}
172186172600
}
172187
- }else if( !hasRightJoin ){
172601
+ }else if( !hasRightCrossJoin ){
172188172602
mPrereq = 0;
172189172603
}
172190172604
#ifndef SQLITE_OMIT_VIRTUALTABLE
172191172605
if( IsVirtual(pItem->pSTab) ){
172192172606
SrcItem *p;
@@ -172781,16 +173195,25 @@
172781173195
**
172782173196
** 18 for star queries
172783173197
** 12 otherwise
172784173198
**
172785173199
** For the purposes of this heuristic, a star-query is defined as a query
172786
-** with a large central table that is joined using an INNER JOIN,
172787
-** not CROSS or OUTER JOINs, against four or more smaller tables.
172788
-** The central table is called the "fact" table. The smaller tables
172789
-** that get joined are "dimension tables". Also, any table that is
172790
-** self-joined cannot be a dimension table; we assume that dimension
172791
-** tables may only be joined against fact tables.
173200
+** with a central "fact" table that is joined against multiple
173201
+** "dimension" tables, subject to the following constraints:
173202
+**
173203
+** (aa) Only a five-way or larger join is considered for this
173204
+** optimization. If there are fewer than four terms in the FROM
173205
+** clause, this heuristic does not apply.
173206
+**
173207
+** (bb) The join between the fact table and the dimension tables must
173208
+** be an INNER join. CROSS and OUTER JOINs do not qualify.
173209
+**
173210
+** (cc) A table must have 3 or more dimension tables in order to be
173211
+** considered a fact table. (Was 4 prior to 2026-02-10.)
173212
+**
173213
+** (dd) A table that is a self-join cannot be a dimension table.
173214
+** Dimension tables are joined against fact tables.
172792173215
**
172793173216
** SIDE EFFECT: (and really the whole point of this subroutine)
172794173217
**
172795173218
** If pWInfo describes a star-query, then the cost for SCANs of dimension
172796173219
** WhereLoops is increased to be slightly larger than the cost of a SCAN
@@ -172839,11 +173262,11 @@
172839173262
assert( pWLoop->maskSelf==MASKBIT(pWLoop->iTab) );
172840173263
assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
172841173264
}
172842173265
#endif /* SQLITE_DEBUG */
172843173266
172844
- if( nLoop>=5
173267
+ if( nLoop>=4 /* Constraint (aa) */
172845173268
&& !pWInfo->bStarDone
172846173269
&& OptimizationEnabled(pWInfo->pParse->db, SQLITE_StarQuery)
172847173270
){
172848173271
SrcItem *aFromTabs; /* All terms of the FROM clause */
172849173272
int iFromIdx; /* Term of FROM clause is the candidate fact-table */
@@ -172851,11 +173274,11 @@
172851173274
Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
172852173275
WhereLoop *pStart; /* Where to start searching for dimension-tables */
172853173276
172854173277
pWInfo->bStarDone = 1; /* Only do this computation once */
172855173278
172856
- /* Look for fact tables with four or more dimensions where the
173279
+ /* Look for fact tables with three or more dimensions where the
172857173280
** dimension tables are not separately from the fact tables by an outer
172858173281
** or cross join. Adjust cost weights if found.
172859173282
*/
172860173283
assert( !pWInfo->bStarUsed );
172861173284
aFromTabs = pWInfo->pTabList->a;
@@ -172868,22 +173291,21 @@
172868173291
172869173292
pFactTab = aFromTabs + iFromIdx;
172870173293
if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
172871173294
/* If the candidate fact-table is the right table of an outer join
172872173295
** restrict the search for dimension-tables to be tables to the right
172873
- ** of the fact-table. */
172874
- if( iFromIdx+4 > nLoop ) break; /* Impossible to reach nDep>=4 */
173296
+ ** of the fact-table. Constraint (bb) */
173297
+ if( iFromIdx+3 > nLoop ){
173298
+ break; /* ^-- Impossible to reach nDep>=2 - Constraint (cc) */
173299
+ }
172875173300
while( pStart && pStart->iTab<=iFromIdx ){
172876173301
pStart = pStart->pNextLoop;
172877173302
}
172878173303
}
172879173304
for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
172880173305
if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
172881
- /* Fact-tables and dimension-tables cannot be separated by an
172882
- ** outer join (at least for the definition of fact- and dimension-
172883
- ** used by this heuristic). */
172884
- break;
173306
+ break; /* Constraint (bb) */
172885173307
}
172886173308
if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
172887173309
&& (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
172888173310
&& (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
172889173311
){
@@ -172893,11 +173315,13 @@
172893173315
nDep++;
172894173316
mSeen |= pWLoop->maskSelf;
172895173317
}
172896173318
}
172897173319
}
172898
- if( nDep<=3 ) continue;
173320
+ if( nDep<=2 ){
173321
+ continue; /* Constraint (cc) */
173322
+ }
172899173323
172900173324
/* If we reach this point, it means that pFactTab is a fact table
172901173325
** with four or more dimensions connected by inner joins. Proceed
172902173326
** to make cost adjustments. */
172903173327
@@ -172906,10 +173330,27 @@
172906173330
if( !pWInfo->bStarUsed ){
172907173331
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
172908173332
pWLoop->rStarDelta = 0;
172909173333
}
172910173334
}
173335
+#endif
173336
+#ifdef WHERETRACE_ENABLED /* 0x80000 */
173337
+ if( sqlite3WhereTrace & 0x80000 ){
173338
+ Bitmask mShow = mSeen;
173339
+ sqlite3DebugPrintf("Fact table %s(%d), dimensions:",
173340
+ pFactTab->zAlias ? pFactTab->zAlias : pFactTab->pSTab->zName,
173341
+ iFromIdx);
173342
+ for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
173343
+ if( mShow & pWLoop->maskSelf ){
173344
+ SrcItem *pDim = aFromTabs + pWLoop->iTab;
173345
+ mShow &= ~pWLoop->maskSelf;
173346
+ sqlite3DebugPrintf(" %s(%d)",
173347
+ pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, pWLoop->iTab);
173348
+ }
173349
+ }
173350
+ sqlite3DebugPrintf("\n");
173351
+ }
172911173352
#endif
172912173353
pWInfo->bStarUsed = 1;
172913173354
172914173355
/* Compute the maximum cost of any WhereLoop for the
172915173356
** fact table plus one epsilon */
@@ -172929,14 +173370,12 @@
172929173370
if( pWLoop->rRun<mxRun ){
172930173371
#ifdef WHERETRACE_ENABLED /* 0x80000 */
172931173372
if( sqlite3WhereTrace & 0x80000 ){
172932173373
SrcItem *pDim = aFromTabs + pWLoop->iTab;
172933173374
sqlite3DebugPrintf(
172934
- "Increase SCAN cost of dimension %s(%d) of fact %s(%d) to %d\n",
172935
- pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, pWLoop->iTab,
172936
- pFactTab->zAlias ? pFactTab->zAlias : pFactTab->pSTab->zName,
172937
- iFromIdx, mxRun
173375
+ "Increase SCAN cost of %s to %d\n",
173376
+ pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, mxRun
172938173377
);
172939173378
}
172940173379
pWLoop->rStarDelta = mxRun - pWLoop->rRun;
172941173380
#endif /* WHERETRACE_ENABLED */
172942173381
pWLoop->rRun = mxRun;
@@ -214034,32 +214473,36 @@
214034214473
jsonParseReset(&v);
214035214474
jsonParseReset(&ix);
214036214475
return rc;
214037214476
}
214038214477
}else if( zPath[0]=='[' ){
214478
+ u64 kk = 0;
214039214479
x = pParse->aBlob[iRoot] & 0x0f;
214040214480
if( x!=JSONB_ARRAY ) return JSON_LOOKUP_NOTFOUND;
214041214481
n = jsonbPayloadSize(pParse, iRoot, &sz);
214042
- k = 0;
214043214482
i = 1;
214044214483
while( sqlite3Isdigit(zPath[i]) ){
214045
- k = k*10 + zPath[i] - '0';
214484
+ if( kk<0xffffffff ) kk = kk*10 + zPath[i] - '0';
214485
+ /* ^^^^^^^^^^--- Allow kk to be bigger than any JSON array so that
214486
+ ** we get NOTFOUND instead of PATHERROR, without overflowing kk. */
214046214487
i++;
214047214488
}
214048214489
if( i<2 || zPath[i]!=']' ){
214049214490
if( zPath[1]=='#' ){
214050
- k = jsonbArrayCount(pParse, iRoot);
214491
+ kk = jsonbArrayCount(pParse, iRoot);
214051214492
i = 2;
214052214493
if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){
214053
- unsigned int nn = 0;
214494
+ u64 nn = 0;
214054214495
i = 3;
214055214496
do{
214056
- nn = nn*10 + zPath[i] - '0';
214497
+ if( nn<0xffffffff ) nn = nn*10 + zPath[i] - '0';
214498
+ /* ^^^^^^^^^^--- Allow nn to be bigger than any JSON array to
214499
+ ** get NOTFOUND instead of PATHERROR, without overflowing nn. */
214057214500
i++;
214058214501
}while( sqlite3Isdigit(zPath[i]) );
214059
- if( nn>k ) return JSON_LOOKUP_NOTFOUND;
214060
- k -= nn;
214502
+ if( nn>kk ) return JSON_LOOKUP_NOTFOUND;
214503
+ kk -= nn;
214061214504
}
214062214505
if( zPath[i]!=']' ){
214063214506
return JSON_LOOKUP_PATHERROR;
214064214507
}
214065214508
}else{
@@ -214067,22 +214510,22 @@
214067214510
}
214068214511
}
214069214512
j = iRoot+n;
214070214513
iEnd = j+sz;
214071214514
while( j<iEnd ){
214072
- if( k==0 ){
214515
+ if( kk==0 ){
214073214516
rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
214074214517
if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
214075214518
return rc;
214076214519
}
214077
- k--;
214520
+ kk--;
214078214521
n = jsonbPayloadSize(pParse, j, &sz);
214079214522
if( n==0 ) return JSON_LOOKUP_ERROR;
214080214523
j += n+sz;
214081214524
}
214082214525
if( j>iEnd ) return JSON_LOOKUP_ERROR;
214083
- if( k>0 ) return JSON_LOOKUP_NOTFOUND;
214526
+ if( kk>0 ) return JSON_LOOKUP_NOTFOUND;
214084214527
if( pParse->eEdit>=JEDIT_INS ){
214085214528
JsonParse v;
214086214529
testcase( pParse->eEdit==JEDIT_INS );
214087214530
testcase( pParse->eEdit==JEDIT_AINS );
214088214531
testcase( pParse->eEdit==JEDIT_SET );
@@ -214220,11 +214663,11 @@
214220214663
char *z;
214221214664
if( sz==0 ) goto returnfromblob_malformed;
214222214665
to_double:
214223214666
z = sqlite3DbStrNDup(db, (const char*)&pParse->aBlob[i+n], (int)sz);
214224214667
if( z==0 ) goto returnfromblob_oom;
214225
- rc = sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
214668
+ rc = sqlite3AtoF(z, &r);
214226214669
sqlite3DbFree(db, z);
214227214670
if( rc<=0 ) goto returnfromblob_malformed;
214228214671
sqlite3_result_double(pCtx, r);
214229214672
break;
214230214673
}
@@ -221099,11 +221542,11 @@
221099221542
if( pVal ){
221100221543
#ifdef SQLITE_AMALGAMATION
221101221544
/* The sqlite3AtoF() routine is much much faster than atof(), if it
221102221545
** is available */
221103221546
double r;
221104
- (void)sqlite3AtoF((const char*)p->z, &r, j, SQLITE_UTF8);
221547
+ (void)sqlite3AtoF((const char*)p->z, &r);
221105221548
*pVal = r;
221106221549
#else
221107221550
*pVal = (GeoCoord)atof((const char*)p->z);
221108221551
#endif
221109221552
}
@@ -231358,10 +231801,11 @@
231358231801
struct carray_bind {
231359231802
void *aData; /* The data */
231360231803
int nData; /* Number of elements */
231361231804
int mFlags; /* Control flags */
231362231805
void (*xDel)(void*); /* Destructor for aData */
231806
+ void *pDel; /* Alternative argument to xDel() */
231363231807
};
231364231808
231365231809
231366231810
/* carray_cursor is a subclass of sqlite3_vtab_cursor which will
231367231811
** serve as the underlying representation of a cursor that scans
@@ -231690,26 +232134,38 @@
231690232134
** Destructor for the carray_bind object
231691232135
*/
231692232136
static void carrayBindDel(void *pPtr){
231693232137
carray_bind *p = (carray_bind*)pPtr;
231694232138
if( p->xDel!=SQLITE_STATIC ){
231695
- p->xDel(p->aData);
232139
+ p->xDel(p->pDel);
231696232140
}
231697232141
sqlite3_free(p);
231698232142
}
231699232143
231700232144
/*
231701232145
** Invoke this interface in order to bind to the single-argument
231702232146
** version of CARRAY().
232147
+**
232148
+** pStmt The prepared statement to which to bind
232149
+** idx The index of the parameter of pStmt to which to bind
232150
+** aData The data to be bound
232151
+** nData The number of elements in aData
232152
+** mFlags One of SQLITE_CARRAY_xxxx indicating datatype of aData
232153
+** xDestroy Destructor for pDestroy or aData if pDestroy==NULL.
232154
+** pDestroy Invoke xDestroy on this pointer if not NULL
232155
+**
232156
+** The destructor is called pDestroy if pDestroy!=NULL, or against
232157
+** aData if pDestroy==NULL.
231703232158
*/
231704
-SQLITE_API int sqlite3_carray_bind(
232159
+SQLITE_API int sqlite3_carray_bind_v2(
231705232160
sqlite3_stmt *pStmt,
231706232161
int idx,
231707232162
void *aData,
231708232163
int nData,
231709232164
int mFlags,
231710
- void (*xDestroy)(void*)
232165
+ void (*xDestroy)(void*),
232166
+ void *pDestroy
231711232167
){
231712232168
carray_bind *pNew = 0;
231713232169
int i;
231714232170
int rc = SQLITE_OK;
231715232171
@@ -231782,23 +232238,41 @@
231782232238
}
231783232239
}else{
231784232240
memcpy(pNew->aData, aData, sz);
231785232241
}
231786232242
pNew->xDel = sqlite3_free;
232243
+ pNew->pDel = pNew->aData;
231787232244
}else{
231788232245
pNew->aData = aData;
231789232246
pNew->xDel = xDestroy;
232247
+ pNew->pDel = pDestroy;
231790232248
}
231791232249
return sqlite3_bind_pointer(pStmt, idx, pNew, "carray-bind", carrayBindDel);
231792232250
231793232251
carray_bind_error:
231794232252
if( xDestroy!=SQLITE_STATIC && xDestroy!=SQLITE_TRANSIENT ){
231795
- xDestroy(aData);
232253
+ xDestroy(pDestroy);
231796232254
}
231797232255
sqlite3_free(pNew);
231798232256
return rc;
231799232257
}
232258
+
232259
+/*
232260
+** Invoke this interface in order to bind to the single-argument
232261
+** version of CARRAY(). Same as sqlite3_carray_bind_v2() with the
232262
+** pDestroy parameter set to NULL.
232263
+*/
232264
+SQLITE_API int sqlite3_carray_bind(
232265
+ sqlite3_stmt *pStmt,
232266
+ int idx,
232267
+ void *aData,
232268
+ int nData,
232269
+ int mFlags,
232270
+ void (*xDestroy)(void*)
232271
+){
232272
+ return sqlite3_carray_bind_v2(pStmt,idx,aData,nData,mFlags,xDestroy,aData);
232273
+}
231800232274
231801232275
/*
231802232276
** Invoke this routine to register the carray() function.
231803232277
*/
231804232278
SQLITE_PRIVATE Module *sqlite3CarrayRegister(sqlite3 *db){
@@ -232157,10 +232631,24 @@
232157232631
** bytes read.
232158232632
*/
232159232633
static int sessionVarintGet(const u8 *aBuf, int *piVal){
232160232634
return getVarint32(aBuf, *piVal);
232161232635
}
232636
+
232637
+/*
232638
+** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal.
232639
+** Return the number of bytes read.
232640
+*/
232641
+static int sessionVarintGetSafe(const u8 *aBuf, int nBuf, int *piVal){
232642
+ u8 aCopy[5];
232643
+ const u8 *aRead = aBuf;
232644
+ if( nBuf<5 ){
232645
+ memcpy(aCopy, aBuf, nBuf);
232646
+ aRead = aCopy;
232647
+ }
232648
+ return getVarint32(aRead, *piVal);
232649
+}
232162232650
232163232651
/* Load an unaligned and unsigned 32-bit integer */
232164232652
#define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
232165232653
232166232654
/*
@@ -235370,11 +235858,12 @@
235370235858
235371235859
if( rc==SQLITE_OK ){
235372235860
u8 *aVal = &pIn->aData[pIn->iNext];
235373235861
if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
235374235862
int nByte;
235375
- pIn->iNext += sessionVarintGet(aVal, &nByte);
235863
+ int nRem = pIn->nData - pIn->iNext;
235864
+ pIn->iNext += sessionVarintGetSafe(aVal, nRem, &nByte);
235376235865
rc = sessionInputBuffer(pIn, nByte);
235377235866
if( rc==SQLITE_OK ){
235378235867
if( nByte<0 || nByte>pIn->nData-pIn->iNext ){
235379235868
rc = SQLITE_CORRUPT_BKPT;
235380235869
}else{
@@ -235423,11 +235912,12 @@
235423235912
int nCol = 0;
235424235913
int nRead = 0;
235425235914
235426235915
rc = sessionInputBuffer(pIn, 9);
235427235916
if( rc==SQLITE_OK ){
235428
- nRead += sessionVarintGet(&pIn->aData[pIn->iNext + nRead], &nCol);
235917
+ int nBuf = pIn->nData - pIn->iNext;
235918
+ nRead += sessionVarintGetSafe(&pIn->aData[pIn->iNext], nBuf, &nCol);
235429235919
/* The hard upper limit for the number of columns in an SQLite
235430235920
** database table is, according to sqliteLimit.h, 32676. So
235431235921
** consider any table-header that purports to have more than 65536
235432235922
** columns to be corrupt. This is convenient because otherwise,
235433235923
** if the (nCol>65536) condition below were omitted, a sufficiently
@@ -235583,14 +236073,14 @@
235583236073
sqlite3ValueFree(p->apValue[i]);
235584236074
}
235585236075
memset(p->apValue, 0, sizeof(sqlite3_value*)*p->nCol*2);
235586236076
}
235587236077
235588
- /* Make sure the buffer contains at least 10 bytes of input data, or all
235589
- ** remaining data if there are less than 10 bytes available. This is
235590
- ** sufficient either for the 'T' or 'P' byte and the varint that follows
235591
- ** it, or for the two single byte values otherwise. */
236078
+ /* Make sure the buffer contains at least 2 bytes of input data, or all
236079
+ ** remaining data if there are less than 2 bytes available. This is
236080
+ ** sufficient either for the 'T' or 'P' byte that begins a new table,
236081
+ ** or for the "op" and "bIndirect" single bytes otherwise. */
235592236082
p->rc = sessionInputBuffer(&p->in, 2);
235593236083
if( p->rc!=SQLITE_OK ) return p->rc;
235594236084
235595236085
p->in.iCurrent = p->in.iNext;
235596236086
sessionDiscardData(&p->in);
@@ -235616,15 +236106,17 @@
235616236106
** corrupt changeset. */
235617236107
assert( p->in.iNext==1 || p->zTab );
235618236108
return (p->rc = SQLITE_CORRUPT_BKPT);
235619236109
}
235620236110
235621
- p->op = op;
235622
- p->bIndirect = p->in.aData[p->in.iNext++];
235623
- if( p->op!=SQLITE_UPDATE && p->op!=SQLITE_DELETE && p->op!=SQLITE_INSERT ){
236111
+ if( (op!=SQLITE_UPDATE && op!=SQLITE_DELETE && op!=SQLITE_INSERT)
236112
+ || (p->in.iNext>=p->in.nData)
236113
+ ){
235624236114
return (p->rc = SQLITE_CORRUPT_BKPT);
235625236115
}
236116
+ p->op = op;
236117
+ p->bIndirect = p->in.aData[p->in.iNext++];
235626236118
235627236119
if( paRec ){
235628236120
int nVal; /* Number of values to buffer */
235629236121
if( p->bPatchset==0 && op==SQLITE_UPDATE ){
235630236122
nVal = p->nCol * 2;
@@ -261258,11 +261750,11 @@
261258261750
int nArg, /* Number of args */
261259261751
sqlite3_value **apUnused /* Function arguments */
261260261752
){
261261261753
assert( nArg==0 );
261262261754
UNUSED_PARAM2(nArg, apUnused);
261263
- sqlite3_result_text(pCtx, "fts5: 2026-01-26 10:53:24 4733d351ec2376291f093ba8d2ba71d82c6f100c68dc860eee0532986c154e71", -1, SQLITE_TRANSIENT);
261755
+ sqlite3_result_text(pCtx, "fts5: 2026-02-17 01:04:23 dd5af703e1082951a4295a3453611db12b23cfbcfee4258ec3985abe96ab54ba", -1, SQLITE_TRANSIENT);
261264261756
}
261265261757
261266261758
/*
261267261759
** Implementation of fts5_locale(LOCALE, TEXT) function.
261268261760
**
261269261761
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 4733d351ec2376291f093ba8d2ba71d82c6f with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2026-01-26 10:53:24 4733d351ec2376291f093ba8d2ba71d82c6f100c68dc860eee0532986c154e71"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-01-26T10:53:24.426Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -11571,23 +11571,45 @@
11571 #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
11572
11573 /*
11574 ** CAPI3REF: Bind array values to the CARRAY table-valued function
11575 **
11576 ** The sqlite3_carray_bind(S,I,P,N,F,X) interface binds an array value to
11577 ** one of the first argument of the [carray() table-valued function]. The
11578 ** S parameter is a pointer to the [prepared statement] that uses the carray()
11579 ** functions. I is the parameter index to be bound. P is a pointer to the
11580 ** array to be bound, and N is the number of eements in the array. The
11581 ** F argument is one of constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64],
11582 ** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], or [SQLITE_CARRAY_BLOB] to
11583 ** indicate the datatype of the array being bound. The X argument is not a
11584 ** NULL pointer, then SQLite will invoke the function X on the P parameter
11585 ** after it has finished using P, even if the call to
11586 ** sqlite3_carray_bind() fails. The special-case finalizer
11587 ** SQLITE_TRANSIENT has no effect here.
 
 
 
 
 
 
 
 
 
 
 
 
 
11588 */
 
 
 
 
 
 
 
 
 
11589 SQLITE_API int sqlite3_carray_bind(
11590 sqlite3_stmt *pStmt, /* Statement to be bound */
11591 int i, /* Parameter index */
11592 void *aData, /* Pointer to array data */
11593 int nData, /* Number of data elements */
@@ -15814,10 +15836,11 @@
15814 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
15815 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
15816 #else
15817 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
15818 #endif
 
15819
15820 /*
15821 ** Disable MMAP on platforms where it is known to not work
15822 */
15823 #if defined(__OpenBSD__) || defined(__QNXNTO__)
@@ -20337,11 +20360,11 @@
20337 #define SF_Distinct 0x0000001 /* Output should be DISTINCT */
20338 #define SF_All 0x0000002 /* Includes the ALL keyword */
20339 #define SF_Resolved 0x0000004 /* Identifiers have been resolved */
20340 #define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */
20341 #define SF_HasAgg 0x0000010 /* Contains aggregate functions */
20342 /* 0x0000020 // available for reuse */
20343 #define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */
20344 #define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */
20345 #define SF_Compound 0x0000100 /* Part of a compound query */
20346 #define SF_Values 0x0000200 /* Synthesized from VALUES clause */
20347 #define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */
@@ -20594,33 +20617,33 @@
20594 int rc; /* Return code from execution */
20595 LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
20596 u8 nested; /* Number of nested calls to the parser/code generator */
20597 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
20598 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
20599 u8 mayAbort; /* True if statement may throw an ABORT exception */
20600 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
20601 u8 disableLookaside; /* Number of times lookaside has been disabled */
20602 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20603 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20604 u8 bHasExists; /* Has a correlated "EXISTS (SELECT ....)" expression */
20605 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20606 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20607 u8 bReturning; /* Coding a RETURNING trigger */
20608 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20609 u8 disableTriggers; /* True to disable triggers */
20610 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
20611 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
20612 #endif
20613 #ifdef SQLITE_DEBUG
20614 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
20615 u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
20616 ** and ALTER TABLE ADD COLUMN. */
20617 #endif
20618 bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20619 bft bHasWith :1; /* True if statement contains WITH */
20620 bft okConstFactor :1; /* OK to factor out constants */
20621 bft checkSchema :1; /* Causes schema cookie check after an error */
 
 
 
 
 
20622 int nRangeReg; /* Size of the temporary register block */
20623 int iRangeReg; /* First register in temporary register block */
20624 int nErr; /* Number of errors seen */
20625 int nTab; /* Number of previously allocated VDBE cursors */
20626 int nMem; /* Number of memory cells used so far */
@@ -21094,10 +21117,11 @@
21094 u16 mWFlags; /* Use-dependent flags */
21095 union { /* Extra data for callback */
21096 NameContext *pNC; /* Naming context */
21097 int n; /* A counter */
21098 int iCur; /* A cursor number */
 
21099 SrcList *pSrcList; /* FROM clause */
21100 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
21101 struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */
21102 int *aiCol; /* array of column indexes */
21103 struct IdxCover *pIdxCover; /* Check for index coverage */
@@ -21780,10 +21804,11 @@
21780 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
21781 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
21782 Expr*,ExprList*,u32,Expr*);
21783 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
21784 SQLITE_PRIVATE void sqlite3SelectDeleteGeneric(sqlite3*,void*);
 
21785 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
21786 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, Trigger*);
21787 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
21788 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
21789 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -21877,10 +21902,11 @@
21877 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
21878 #endif
21879 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
21880 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
21881 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
 
21882 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
21883 SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab);
21884 SQLITE_PRIVATE void sqlite3GenerateRowDelete(
21885 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
21886 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
@@ -22000,11 +22026,11 @@
22000 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
22001
22002 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
22003 SQLITE_PRIVATE i64 sqlite3RealToI64(double);
22004 SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*);
22005 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
22006 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
22007 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
22008 SQLITE_PRIVATE int sqlite3Atoi(const char*);
22009 #ifndef SQLITE_OMIT_UTF16
22010 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nByte, int nChar);
@@ -22150,11 +22176,11 @@
22150 SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int);
22151 SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*);
22152 SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *);
22153 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
22154 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
22155 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
22156 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
22157 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
22158 SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, SrcItem*);
22159 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
22160 SQLITE_PRIVATE int sqlite3MatchEName(
@@ -24584,17 +24610,18 @@
24584 #endif
24585 #ifdef SQLITE_DEBUG
24586 SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*);
24587 #endif
24588 SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*);
24589 SQLITE_PRIVATE void sqlite3VdbeMemZeroTerminateIfAble(Mem*);
24590 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
24591 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
24592 SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double);
24593 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*);
24594 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
24595 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
 
24596 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
24597 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
24598 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
24599 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
24600 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
@@ -25550,11 +25577,11 @@
25550 return 0;
25551 }else if( parseHhMmSs(zDate, p)==0 ){
25552 return 0;
25553 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
25554 return setDateTimeToCurrent(context, p);
25555 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){
25556 setRawDateNumber(p, r);
25557 return 0;
25558 }else if( (sqlite3StrICmp(zDate,"subsec")==0
25559 || sqlite3StrICmp(zDate,"subsecond")==0)
25560 && sqlite3NotPureFunc(context) ){
@@ -25996,11 +26023,11 @@
25996 ** Move the date to the same time on the next occurrence of
25997 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
25998 ** date is already on the appropriate weekday, this is a no-op.
25999 */
26000 if( sqlite3_strnicmp(z, "weekday ", 8)==0
26001 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
26002 && r>=0.0 && r<7.0 && (n=(int)r)==r ){
26003 sqlite3_int64 Z;
26004 computeYMD_HMS(p);
26005 p->tz = 0;
26006 p->validJD = 0;
@@ -26067,23 +26094,29 @@
26067 case '6':
26068 case '7':
26069 case '8':
26070 case '9': {
26071 double rRounder;
26072 int i;
26073 int Y,M,D,h,m,x;
26074 const char *z2 = z;
 
 
26075 char z0 = z[0];
26076 for(n=1; z[n]; n++){
26077 if( z[n]==':' ) break;
26078 if( sqlite3Isspace(z[n]) ) break;
26079 if( z[n]=='-' ){
26080 if( n==5 && getDigits(&z[1], "40f", &Y)==1 ) break;
26081 if( n==6 && getDigits(&z[1], "50f", &Y)==1 ) break;
26082 }
26083 }
26084 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
 
 
 
 
26085 assert( rc==1 );
26086 break;
26087 }
26088 if( z[n]=='-' ){
26089 /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
@@ -34904,11 +34937,17 @@
34904 ** sqlite3ShowWhereTerm() in where.c
34905 */
34906 SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
34907 SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
34908 SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
34909 SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); }
 
 
 
 
 
 
34910 SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
34911 SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
34912 SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
34913 #ifndef SQLITE_OMIT_TRIGGER
34914 SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep *p){
@@ -36424,52 +36463,261 @@
36424 z++;
36425 }
36426 return h;
36427 }
36428
36429 /* Double-Double multiplication. (x[0],x[1]) *= (y,yy)
36430 **
36431 ** Reference:
36432 ** T. J. Dekker, "A Floating-Point Technique for Extending the
36433 ** Available Precision". 1971-07-26.
36434 */
36435 static void dekkerMul2(volatile double *x, double y, double yy){
36436 /*
36437 ** The "volatile" keywords on parameter x[] and on local variables
36438 ** below are needed force intermediate results to be truncated to
36439 ** binary64 rather than be carried around in an extended-precision
36440 ** format. The truncation is necessary for the Dekker algorithm to
36441 ** work. Intel x86 floating point might omit the truncation without
36442 ** the use of volatile.
36443 */
36444 volatile double tx, ty, p, q, c, cc;
36445 double hx, hy;
36446 u64 m;
36447 memcpy(&m, (void*)&x[0], 8);
36448 m &= 0xfffffffffc000000LL;
36449 memcpy(&hx, &m, 8);
36450 tx = x[0] - hx;
36451 memcpy(&m, &y, 8);
36452 m &= 0xfffffffffc000000LL;
36453 memcpy(&hy, &m, 8);
36454 ty = y - hy;
36455 p = hx*hy;
36456 q = hx*ty + tx*hy;
36457 c = p+q;
36458 cc = p - c + q + tx*ty;
36459 cc = x[0]*yy + x[1]*y + cc;
36460 x[0] = c + cc;
36461 x[1] = c - x[0];
36462 x[1] += cc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36463 }
36464
36465 /*
36466 ** The string z[] is an text representation of a real number.
36467 ** Convert this string to a double and write it into *pResult.
36468 **
36469 ** The string z[] is length bytes in length (bytes, not characters) and
36470 ** uses the encoding enc. The string is not necessarily zero-terminated.
36471 **
36472 ** Return TRUE if the result is a valid real number (or integer) and FALSE
36473 ** if the string is empty or contains extraneous text. More specifically
36474 ** return
36475 ** 1 => The input string is a pure integer
@@ -36492,201 +36740,134 @@
36492 ** into *pResult.
36493 */
36494 #if defined(_MSC_VER)
36495 #pragma warning(disable : 4756)
36496 #endif
36497 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
36498 #ifndef SQLITE_OMIT_FLOATING_POINT
36499 int incr;
36500 const char *zEnd;
36501 /* sign * significand * (10 ^ (esign * exponent)) */
36502 int sign = 1; /* sign of significand */
36503 u64 s = 0; /* significand */
36504 int d = 0; /* adjust exponent for shifting decimal point */
36505 int esign = 1; /* sign of exponent */
36506 int e = 0; /* exponent */
36507 int eValid = 1; /* True exponent is either not used or is well-formed */
36508 int nDigit = 0; /* Number of digits processed */
36509 int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
36510 u64 s2; /* round-tripped significand */
36511 double rr[2];
36512
36513 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
36514 *pResult = 0.0; /* Default return value, in case of an error */
36515 if( length==0 ) return 0;
36516
36517 if( enc==SQLITE_UTF8 ){
36518 incr = 1;
36519 zEnd = z + length;
36520 }else{
36521 int i;
36522 incr = 2;
36523 length &= ~1;
36524 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
36525 testcase( enc==SQLITE_UTF16LE );
36526 testcase( enc==SQLITE_UTF16BE );
36527 for(i=3-enc; i<length && z[i]==0; i+=2){}
36528 if( i<length ) eType = -100;
36529 zEnd = &z[i^1];
36530 z += (enc&1);
36531 }
36532
36533 /* skip leading spaces */
36534 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
36535 if( z>=zEnd ) return 0;
36536
36537 /* get sign of significand */
36538 if( *z=='-' ){
36539 sign = -1;
36540 z+=incr;
36541 }else if( *z=='+' ){
36542 z+=incr;
36543 }
36544
36545 /* copy max significant digits to significand */
36546 while( z<zEnd && sqlite3Isdigit(*z) ){
36547 s = s*10 + (*z - '0');
36548 z+=incr; nDigit++;
36549 if( s>=((LARGEST_UINT64-9)/10) ){
36550 /* skip non-significant significand digits
36551 ** (increase exponent by d to shift decimal left) */
36552 while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; d++; }
36553 }
36554 }
36555 if( z>=zEnd ) goto do_atof_calc;
36556
36557 /* if decimal point is present */
36558 if( *z=='.' ){
36559 z+=incr;
36560 eType++;
36561 /* copy digits from after decimal to significand
36562 ** (decrease exponent by d to shift decimal right) */
36563 while( z<zEnd && sqlite3Isdigit(*z) ){
36564 if( s<((LARGEST_UINT64-9)/10) ){
36565 s = s*10 + (*z - '0');
36566 d--;
36567 nDigit++;
36568 }
36569 z+=incr;
36570 }
36571 }
36572 if( z>=zEnd ) goto do_atof_calc;
36573
36574 /* if exponent is present */
36575 if( *z=='e' || *z=='E' ){
36576 z+=incr;
36577 eValid = 0;
36578 eType++;
36579
36580 /* This branch is needed to avoid a (harmless) buffer overread. The
36581 ** special comment alerts the mutation tester that the correct answer
36582 ** is obtained even if the branch is omitted */
36583 if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
36584
36585 /* get sign of exponent */
36586 if( *z=='-' ){
36587 esign = -1;
36588 z+=incr;
36589 }else if( *z=='+' ){
36590 z+=incr;
36591 }
36592 /* copy digits to exponent */
36593 while( z<zEnd && sqlite3Isdigit(*z) ){
36594 e = e<10000 ? (e*10 + (*z - '0')) : 10000;
36595 z+=incr;
36596 eValid = 1;
 
 
 
 
 
 
36597 }
36598 }
36599
36600 /* skip trailing spaces */
36601 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
36602
36603 do_atof_calc:
36604 /* Zero is a special case */
36605 if( s==0 ){
36606 *pResult = sign<0 ? -0.0 : +0.0;
36607 goto atof_return;
36608 }
36609
36610 /* adjust exponent by d, and update sign */
36611 e = (e*esign) + d;
36612
36613 /* Try to adjust the exponent to make it smaller */
36614 while( e>0 && s<((LARGEST_UINT64-0x7ff)/10) ){
36615 s *= 10;
36616 e--;
36617 }
36618 while( e<0 && (s%10)==0 ){
36619 s /= 10;
36620 e++;
36621 }
36622
36623 rr[0] = (double)s;
36624 assert( sizeof(s2)==sizeof(rr[0]) );
36625 #ifdef SQLITE_DEBUG
36626 rr[1] = 18446744073709549568.0;
36627 memcpy(&s2, &rr[1], sizeof(s2));
36628 assert( s2==0x43efffffffffffffLL );
36629 #endif
36630 /* Largest double that can be safely converted to u64
36631 ** vvvvvvvvvvvvvvvvvvvvvv */
36632 if( rr[0]<=18446744073709549568.0 ){
36633 s2 = (u64)rr[0];
36634 rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s);
36635 }else{
36636 rr[1] = 0.0;
36637 }
36638 assert( rr[1]<=1.0e-10*rr[0] ); /* Equal only when rr[0]==0.0 */
36639
36640 if( e>0 ){
36641 while( e>=100 ){
36642 e -= 100;
36643 dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
36644 }
36645 while( e>=10 ){
36646 e -= 10;
36647 dekkerMul2(rr, 1.0e+10, 0.0);
36648 }
36649 while( e>=1 ){
36650 e -= 1;
36651 dekkerMul2(rr, 1.0e+01, 0.0);
36652 }
36653 }else{
36654 while( e<=-100 ){
36655 e += 100;
36656 dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
36657 }
36658 while( e<=-10 ){
36659 e += 10;
36660 dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
36661 }
36662 while( e<=-1 ){
36663 e += 1;
36664 dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
36665 }
36666 }
36667 *pResult = rr[0]+rr[1];
36668 if( sqlite3IsNaN(*pResult) ) *pResult = 1e300*1e300;
36669 if( sign<0 ) *pResult = -*pResult;
36670 assert( !sqlite3IsNaN(*pResult) );
36671
36672 atof_return:
36673 /* return true if number and no extra non-whitespace characters after */
36674 if( z==zEnd && nDigit>0 && eValid && eType>0 ){
36675 return eType;
36676 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
36677 return -1;
36678 }else{
36679 return 0;
36680 }
36681 #else
36682 return !sqlite3Atoi64(z, pResult, length, enc);
36683 #endif /* SQLITE_OMIT_FLOATING_POINT */
36684 }
36685 #if defined(_MSC_VER)
36686 #pragma warning(default : 4756)
36687 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36688
36689 /*
36690 ** Render an signed 64-bit integer as text. Store the result in zOut[] and
36691 ** return the length of the string that was stored, in bytes. The value
36692 ** returned does not include the zero terminator at the end of the output
@@ -36695,27 +36876,39 @@
36695 ** The caller must ensure that zOut[] is at least 21 bytes in size.
36696 */
36697 SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){
36698 int i;
36699 u64 x;
36700 char zTemp[22];
36701 if( v<0 ){
36702 x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
36703 }else{
 
36704 x = v;
36705 }
36706 i = sizeof(zTemp)-2;
36707 zTemp[sizeof(zTemp)-1] = 0;
36708 while( 1 /*exit-by-break*/ ){
36709 zTemp[i] = (x%10) + '0';
36710 x = x/10;
36711 if( x==0 ) break;
36712 i--;
36713 };
36714 if( v<0 ) zTemp[--i] = '-';
36715 memcpy(zOut, &zTemp[i], sizeof(zTemp)-i);
36716 return sizeof(zTemp)-1-i;
 
 
 
 
 
 
 
 
 
 
 
36717 }
36718
36719 /*
36720 ** Compare the 19-character string zNum against the text representation
36721 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -36984,11 +37177,10 @@
36984 */
36985 SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
36986 int i;
36987 u64 v;
36988 int e, exp = 0;
36989 double rr[2];
36990
36991 p->isSpecial = 0;
36992 p->z = p->zBuf;
36993 assert( mxRound>0 );
36994
@@ -37005,64 +37197,43 @@
37005 return;
37006 }else{
37007 p->sign = '+';
37008 }
37009 memcpy(&v,&r,8);
37010 e = v>>52;
37011 if( (e&0x7ff)==0x7ff ){
37012 p->isSpecial = 1 + (v!=0x7ff0000000000000LL);
37013 p->n = 0;
37014 p->iDP = 0;
37015 return;
37016 }
37017
37018 /* Multiply r by powers of ten until it lands somewhere in between
37019 ** 1.0e+19 and 1.0e+17.
37020 **
37021 ** Use Dekker-style double-double computation to increase the
37022 ** precision.
37023 **
37024 ** The error terms on constants like 1.0e+100 computed using the
37025 ** decimal extension, for example as follows:
37026 **
37027 ** SELECT decimal_exp(decimal_sub('1.0e+100',decimal(1.0e+100)));
37028 */
37029 rr[0] = r;
37030 rr[1] = 0.0;
37031 if( rr[0]>9.223372036854774784e+18 ){
37032 while( rr[0]>9.223372036854774784e+118 ){
37033 exp += 100;
37034 dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
37035 }
37036 while( rr[0]>9.223372036854774784e+28 ){
37037 exp += 10;
37038 dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
37039 }
37040 while( rr[0]>9.223372036854774784e+18 ){
37041 exp += 1;
37042 dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
37043 }
37044 }else{
37045 while( rr[0]<9.223372036854774784e-83 ){
37046 exp -= 100;
37047 dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
37048 }
37049 while( rr[0]<9.223372036854774784e+07 ){
37050 exp -= 10;
37051 dekkerMul2(rr, 1.0e+10, 0.0);
37052 }
37053 while( rr[0]<9.22337203685477478e+17 ){
37054 exp -= 1;
37055 dekkerMul2(rr, 1.0e+01, 0.0);
37056 }
37057 }
37058 v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1];
37059
37060 /* Extract significant digits. */
37061 i = sizeof(p->zBuf)-1;
37062 assert( v>0 );
37063 while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; }
 
 
 
 
 
 
 
 
 
 
 
37064 assert( i>=0 && i<sizeof(p->zBuf)-1 );
37065 p->n = sizeof(p->zBuf) - 1 - i;
37066 assert( p->n>0 );
37067 assert( p->n<sizeof(p->zBuf) );
37068 p->iDP = p->n + exp;
@@ -84980,36 +85151,40 @@
84980 ** If pMem is already a string, detect if it is a zero-terminated
84981 ** string, or make it into one if possible, and mark it as such.
84982 **
84983 ** This is an optimization. Correct operation continues even if
84984 ** this routine is a no-op.
 
 
 
84985 */
84986 SQLITE_PRIVATE void sqlite3VdbeMemZeroTerminateIfAble(Mem *pMem){
84987 if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
84988 /* pMem must be a string, and it cannot be an ephemeral or static string */
84989 return;
84990 }
84991 if( pMem->enc!=SQLITE_UTF8 ) return;
84992 assert( pMem->z!=0 );
84993 if( pMem->flags & MEM_Dyn ){
84994 if( pMem->xDel==sqlite3_free
84995 && sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
84996 ){
84997 pMem->z[pMem->n] = 0;
84998 pMem->flags |= MEM_Term;
84999 return;
85000 }
85001 if( pMem->xDel==sqlite3RCStrUnref ){
85002 /* Blindly assume that all RCStr objects are zero-terminated */
85003 pMem->flags |= MEM_Term;
85004 return;
85005 }
85006 }else if( pMem->szMalloc >= pMem->n+1 ){
85007 pMem->z[pMem->n] = 0;
85008 pMem->flags |= MEM_Term;
85009 return;
85010 }
 
85011 }
85012
85013 /*
85014 ** It is already known that pMem contains an unterminated string.
85015 ** Add the zero terminator.
@@ -85302,23 +85477,75 @@
85302 return memIntValue(pMem);
85303 }else{
85304 return 0;
85305 }
85306 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85307
85308 /*
85309 ** Return the best representation of pMem that we can get into a
85310 ** double. If pMem is already a double or an integer, return its
85311 ** value. If it is a string or blob, try to convert it to a double.
85312 ** If it is a NULL, return 0.0.
85313 */
85314 static SQLITE_NOINLINE double memRealValue(Mem *pMem){
85315 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
85316 double val = (double)0;
85317 sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
85318 return val;
85319 }
85320 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
85321 assert( pMem!=0 );
85322 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85323 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
85324 if( pMem->flags & MEM_Real ){
@@ -85325,11 +85552,11 @@
85325 return pMem->u.r;
85326 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
85327 testcase( pMem->flags & MEM_IntReal );
85328 return (double)pMem->u.i;
85329 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
85330 return memRealValue(pMem);
85331 }else{
85332 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
85333 return (double)0;
85334 }
85335 }
@@ -85449,11 +85676,11 @@
85449 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
85450 int rc;
85451 sqlite3_int64 ix;
85452 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
85453 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85454 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
85455 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
85456 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
85457 ){
85458 pMem->u.i = ix;
85459 MemSetTypeFlag(pMem, MEM_Int);
@@ -86420,11 +86647,11 @@
86420 }
86421 }
86422 if( affinity==SQLITE_AFF_BLOB ){
86423 if( op==TK_FLOAT ){
86424 assert( pVal && pVal->z && pVal->flags==(MEM_Str|MEM_Term) );
86425 sqlite3AtoF(pVal->z, &pVal->u.r, pVal->n, SQLITE_UTF8);
86426 pVal->flags = MEM_Real;
86427 }else if( op==TK_INTEGER ){
86428 /* This case is required by -9223372036854775808 and other strings
86429 ** that look like integers but cannot be handled by the
86430 ** sqlite3DecOrHexToI64() call above. */
@@ -86688,10 +86915,15 @@
86688 ** the column value into *ppVal. If *ppVal is initially NULL then a new
86689 ** sqlite3_value object is allocated.
86690 **
86691 ** If *ppVal is initially NULL then the caller is responsible for
86692 ** ensuring that the value written into *ppVal is eventually freed.
 
 
 
 
 
86693 */
86694 SQLITE_PRIVATE int sqlite3Stat4Column(
86695 sqlite3 *db, /* Database handle */
86696 const void *pRec, /* Pointer to buffer containing record */
86697 int nRec, /* Size of buffer pRec in bytes */
@@ -95661,14 +95893,13 @@
95661 ** point or exponential notation, the result is only MEM_Real, even
95662 ** if there is an exact integer representation of the quantity.
95663 */
95664 static void applyNumericAffinity(Mem *pRec, int bTryForInt){
95665 double rValue;
95666 u8 enc = pRec->enc;
95667 int rc;
95668 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
95669 rc = sqlite3AtoF(pRec->z, &rValue, pRec->n, enc);
95670 if( rc<=0 ) return;
95671 if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
95672 pRec->flags |= MEM_Int;
95673 }else{
95674 pRec->u.r = rValue;
@@ -95746,11 +95977,14 @@
95746 */
95747 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
95748 int eType = sqlite3_value_type(pVal);
95749 if( eType==SQLITE_TEXT ){
95750 Mem *pMem = (Mem*)pVal;
 
 
95751 applyNumericAffinity(pMem, 0);
 
95752 eType = sqlite3_value_type(pVal);
95753 }
95754 return eType;
95755 }
95756
@@ -95779,11 +96013,11 @@
95779 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
95780 if( ExpandBlob(pMem) ){
95781 pMem->u.i = 0;
95782 return MEM_Int;
95783 }
95784 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
95785 if( rc<=0 ){
95786 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
95787 pMem->u.i = ix;
95788 return MEM_Int;
95789 }else{
@@ -110056,11 +110290,11 @@
110056 */
110057 static int exprProbability(Expr *p){
110058 double r = -1.0;
110059 if( p->op!=TK_FLOAT ) return -1;
110060 assert( !ExprHasProperty(p, EP_IntValue) );
110061 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
110062 assert( r>=0.0 );
110063 if( r>1.0 ) return -1;
110064 return (int)(r*134217728.0);
110065 }
110066
@@ -111192,10 +111426,18 @@
111192 ** number of expressions in the select list. */
111193 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
111194 sqlite3SelectWrongNumTermsError(pParse, p->pNext);
111195 return WRC_Abort;
111196 }
 
 
 
 
 
 
 
 
111197
111198 /* Advance to the next term of the compound
111199 */
111200 p = p->pPrior;
111201 nCompound++;
@@ -114854,18 +115096,25 @@
114854 /* Could not find an existing table or index to use as the RHS b-tree.
114855 ** We will have to generate an ephemeral table to do the job.
114856 */
114857 u32 savedNQueryLoop = pParse->nQueryLoop;
114858 int rMayHaveNull = 0;
 
114859 eType = IN_INDEX_EPH;
114860 if( inFlags & IN_INDEX_LOOP ){
114861 pParse->nQueryLoop = 0;
114862 }else if( prRhsHasNull ){
114863 *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
114864 }
114865 assert( pX->op==TK_IN );
114866 sqlite3CodeRhsOfIN(pParse, pX, iTab);
 
 
 
 
 
 
114867 if( rMayHaveNull ){
114868 sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
114869 }
114870 pParse->nQueryLoop = savedNQueryLoop;
114871 }
@@ -115019,11 +115268,12 @@
115019 ** is used.
115020 */
115021 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
115022 Parse *pParse, /* Parsing context */
115023 Expr *pExpr, /* The IN operator */
115024 int iTab /* Use this cursor number */
 
115025 ){
115026 int addrOnce = 0; /* Address of the OP_Once instruction at top */
115027 int addr; /* Address of OP_OpenEphemeral instruction */
115028 Expr *pLeft; /* the LHS of the IN operator */
115029 KeyInfo *pKeyInfo = 0; /* Key information */
@@ -115141,11 +115391,14 @@
115141 int rc;
115142 int addrBloom = 0;
115143 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
115144 dest.zAffSdst = exprINAffinity(pParse, pExpr);
115145 pSelect->iLimit = 0;
115146 if( addrOnce && OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){
 
 
 
115147 int regBloom = ++pParse->nMem;
115148 addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
115149 VdbeComment((v, "Bloom filter"));
115150 dest.iSDParm2 = regBloom;
115151 }
@@ -115726,11 +115979,11 @@
115726 ** like the continuation of the number.
115727 */
115728 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
115729 if( ALWAYS(z!=0) ){
115730 double value;
115731 sqlite3AtoF(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
115732 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
115733 if( negateFlag ) value = -value;
115734 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
115735 }
115736 }
@@ -118827,11 +119080,14 @@
118827 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
118828 }
118829 if( pIEpr==0 ) break;
118830 if( NEVER(!ExprUseYTab(pExpr)) ) break;
118831 for(i=0; i<pSrcList->nSrc; i++){
118832 if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break;
 
 
 
118833 }
118834 if( i>=pSrcList->nSrc ) break;
118835 if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
118836 if( pParse->nErr ){ return WRC_Abort; }
118837
@@ -124902,11 +125158,11 @@
124902 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
124903 #endif
124904 sqlite3_mutex_enter(db->mutex);
124905 db->xAuth = (sqlite3_xauth)xAuth;
124906 db->pAuthArg = pArg;
124907 if( db->xAuth ) sqlite3ExpirePreparedStatements(db, 1);
124908 sqlite3_mutex_leave(db->mutex);
124909 return SQLITE_OK;
124910 }
124911
124912 /*
@@ -125573,10 +125829,11 @@
125573 SrcItem *p
125574 ){
125575 const char *zDb;
125576 if( p->fg.fixedSchema ){
125577 int iDb = sqlite3SchemaToIndex(pParse->db, p->u4.pSchema);
 
125578 zDb = pParse->db->aDb[iDb].zDbSName;
125579 }else{
125580 assert( !p->fg.isSubquery );
125581 zDb = p->u4.zDatabase;
125582 }
@@ -127657,17 +127914,18 @@
127657 **
127658 ** zName is temporarily modified while this routine is running, but is
127659 ** restored to its original value prior to this routine returning.
127660 */
127661 SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
127662 char *zTail; /* Pointer to the last "_" in zName */
127663 Table *pTab; /* Table that zName is a shadow of */
 
127664 zTail = strrchr(zName, '_');
127665 if( zTail==0 ) return 0;
127666 *zTail = 0;
127667 pTab = sqlite3FindTable(db, zName, 0);
127668 *zTail = '_';
127669 if( pTab==0 ) return 0;
127670 if( !IsVirtual(pTab) ) return 0;
127671 return sqlite3IsShadowTableOf(db, pTab, zName);
127672 }
127673 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
@@ -127816,10 +128074,11 @@
127816 }
127817 p->tabFlags |= TF_WithoutRowid | TF_NoVisibleRowid;
127818 convertToWithoutRowidTable(pParse, p);
127819 }
127820 iDb = sqlite3SchemaToIndex(db, p->pSchema);
 
127821
127822 #ifndef SQLITE_OMIT_CHECK
127823 /* Resolve names in all CHECK constraint expressions.
127824 */
127825 if( p->pCheck ){
@@ -128111,10 +128370,11 @@
128111 p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */
128112 #endif
128113
128114 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
128115 iDb = sqlite3SchemaToIndex(db, p->pSchema);
 
128116 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
128117 if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
128118
128119 /* Make a copy of the entire SELECT statement that defines the view.
128120 ** This will force all the Expr.token.z values to be dynamically
@@ -129707,10 +129967,11 @@
129707 sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
129708 "or PRIMARY KEY constraint cannot be dropped", 0);
129709 goto exit_drop_index;
129710 }
129711 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
 
129712 #ifndef SQLITE_OMIT_AUTHORIZATION
129713 {
129714 int code = SQLITE_DROP_INDEX;
129715 Table *pTab = pIndex->pTable;
129716 const char *zDb = db->aDb[iDb].zDbSName;
@@ -132953,11 +133214,11 @@
132953 zBuf = sqlite3_mprintf("%!.*f",(int)n,r);
132954 if( zBuf==0 ){
132955 sqlite3_result_error_nomem(context);
132956 return;
132957 }
132958 sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8);
132959 sqlite3_free(zBuf);
132960 }
132961 sqlite3_result_double(context, r);
132962 }
132963 #endif
@@ -133591,11 +133852,11 @@
133591 const char *zVal;
133592 r1 = sqlite3_value_double(pValue);
133593 sqlite3_str_appendf(pStr, "%!0.15g", r1);
133594 zVal = sqlite3_str_value(pStr);
133595 if( zVal ){
133596 sqlite3AtoF(zVal, &r2, pStr->nChar, SQLITE_UTF8);
133597 if( r1!=r2 ){
133598 sqlite3_str_reset(pStr);
133599 sqlite3_str_appendf(pStr, "%!0.20e", r1);
133600 }
133601 }
@@ -133688,11 +133949,11 @@
133688 sqlite3_result_error_nomem(context);
133689 return;
133690 }
133691 i = j = 0;
133692 while( i<nIn ){
133693 char *z = strchr(&zIn[i],'\\');
133694 if( z==0 ){
133695 n = nIn - i;
133696 memmove(&zOut[j], &zIn[i], n);
133697 j += n;
133698 break;
@@ -136859,10 +137120,11 @@
136859 /* If foreign-keys are disabled, this function is a no-op. */
136860 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
136861 if( !IsOrdinaryTable(pTab) ) return;
136862
136863 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
 
136864 zDb = db->aDb[iDb].zDbSName;
136865
136866 /* Loop through all the foreign key constraints for which pTab is the
136867 ** child table (the table that the foreign key definition is part of). */
136868 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
@@ -141374,10 +141636,11 @@
141374 int (*db_status64)(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);
141375 /* Version 3.52.0 and later */
141376 void (*str_truncate)(sqlite3_str*,int);
141377 void (*str_free)(sqlite3_str*);
141378 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
 
141379 };
141380
141381 /*
141382 ** This is the function signature used for all extension entry points. It
141383 ** is also defined in the file "loadext.c".
@@ -141716,10 +141979,11 @@
141716 #define sqlite3_db_status64 sqlite3_api->db_status64
141717 /* Version 3.52.0 and later */
141718 #define sqlite3_str_truncate sqlite3_api->str_truncate
141719 #define sqlite3_str_free sqlite3_api->str_free
141720 #define sqlite3_carray_bind sqlite3_api->carray_bind
 
141721 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
141722
141723 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
141724 /* This case when the file really is being compiled as a loadable
141725 ** extension */
@@ -142247,12 +142511,14 @@
142247 sqlite3_db_status64,
142248 /* Version 3.52.0 and later */
142249 sqlite3_str_truncate,
142250 sqlite3_str_free,
142251 #ifdef SQLITE_ENABLE_CARRAY
142252 sqlite3_carray_bind
 
142253 #else
 
142254 0
142255 #endif
142256 };
142257
142258 /* True if x is the directory separator character
@@ -148181,10 +148447,14 @@
148181 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
148182 pRight->u3.pOn = 0;
148183 pRight->fg.isOn = 1;
148184 p->selFlags |= SF_OnToWhere;
148185 }
 
 
 
 
148186 }
148187 return 0;
148188 }
148189
148190 /*
@@ -150108,11 +150378,11 @@
150108 ** function is responsible for ensuring that this structure is eventually
150109 ** freed.
150110 */
150111 static KeyInfo *multiSelectByMergeKeyInfo(Parse *pParse, Select *p, int nExtra){
150112 ExprList *pOrderBy = p->pOrderBy;
150113 int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0;
150114 sqlite3 *db = pParse->db;
150115 KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
150116 if( pRet ){
150117 int i;
150118 for(i=0; i<nOrderBy; i++){
@@ -150911,14 +151181,12 @@
150911 ** EofB: ...
150912 ** AltB: ...
150913 ** AeqB: ...
150914 ** AgtB: ...
150915 ** Init: initialize coroutine registers
150916 ** yield coA
150917 ** if eof(A) goto EofA
150918 ** yield coB
150919 ** if eof(B) goto EofB
150920 ** Cmpr: Compare A, B
150921 ** Jump AltB, AeqB, AgtB
150922 ** End: ...
150923 **
150924 ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
@@ -151006,30 +151274,33 @@
151006 }
151007 }
151008 }
151009
151010 /* Compute the comparison permutation and keyinfo that is used with
151011 ** the permutation used to determine if the next
151012 ** row of results comes from selectA or selectB. Also add explicit
151013 ** collations to the ORDER BY clause terms so that when the subqueries
151014 ** to the right and the left are evaluated, they use the correct
151015 ** collation.
151016 */
151017 aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1));
151018 if( aPermute ){
151019 struct ExprList_item *pItem;
 
151020 aPermute[0] = nOrderBy;
151021 for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
151022 assert( pItem!=0 );
151023 assert( pItem->u.x.iOrderByCol>0 );
151024 assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr );
151025 aPermute[i] = pItem->u.x.iOrderByCol - 1;
 
151026 }
151027 pKeyMerge = multiSelectByMergeKeyInfo(pParse, p, 1);
151028 }else{
151029 pKeyMerge = 0;
 
151030 }
 
151031
151032 /* Allocate a range of temporary registers and the KeyInfo needed
151033 ** for the logic that removes duplicate result rows when the
151034 ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
151035 */
@@ -151104,11 +151375,11 @@
151104 /* Generate a coroutine to evaluate the SELECT statement to the
151105 ** left of the compound operator - the "A" select.
151106 */
151107 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
151108 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
151109 VdbeComment((v, "left SELECT"));
151110 pPrior->iLimit = regLimitA;
151111 ExplainQueryPlan((pParse, 1, "LEFT"));
151112 sqlite3Select(pParse, pPrior, &destA);
151113 sqlite3VdbeEndCoroutine(v, regAddrA);
151114 sqlite3VdbeJumpHere(v, addr1);
@@ -151116,11 +151387,11 @@
151116 /* Generate a coroutine to evaluate the SELECT statement on
151117 ** the right - the "B" select
151118 */
151119 addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
151120 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
151121 VdbeComment((v, "right SELECT"));
151122 savedLimit = p->iLimit;
151123 savedOffset = p->iOffset;
151124 p->iLimit = regLimitB;
151125 p->iOffset = 0;
151126 ExplainQueryPlan((pParse, 1, "RIGHT"));
@@ -151130,20 +151401,20 @@
151130 sqlite3VdbeEndCoroutine(v, regAddrB);
151131
151132 /* Generate a subroutine that outputs the current row of the A
151133 ** select as the next output row of the compound select.
151134 */
151135 VdbeNoopComment((v, "Output routine for A"));
151136 addrOutA = generateOutputSubroutine(pParse,
151137 p, &destA, pDest, regOutA,
151138 regPrev, pKeyDup, labelEnd);
151139
151140 /* Generate a subroutine that outputs the current row of the B
151141 ** select as the next output row of the compound select.
151142 */
151143 if( op==TK_ALL || op==TK_UNION ){
151144 VdbeNoopComment((v, "Output routine for B"));
151145 addrOutB = generateOutputSubroutine(pParse,
151146 p, &destB, pDest, regOutB,
151147 regPrev, pKeyDup, labelEnd);
151148 }
151149 sqlite3KeyInfoUnref(pKeyDup);
@@ -151152,14 +151423,16 @@
151152 ** are exhausted and only data in select B remains.
151153 */
151154 if( op==TK_EXCEPT || op==TK_INTERSECT ){
151155 addrEofA_noB = addrEofA = labelEnd;
151156 }else{
151157 VdbeNoopComment((v, "eof-A subroutine"));
151158 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
 
151159 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
151160 VdbeCoverage(v);
 
151161 sqlite3VdbeGoto(v, addrEofA);
151162 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
151163 }
151164
151165 /* Generate a subroutine to run when the results from select B
@@ -151167,21 +151440,24 @@
151167 */
151168 if( op==TK_INTERSECT ){
151169 addrEofB = addrEofA;
151170 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
151171 }else{
151172 VdbeNoopComment((v, "eof-B subroutine"));
151173 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
 
151174 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
 
151175 sqlite3VdbeGoto(v, addrEofB);
151176 }
151177
151178 /* Generate code to handle the case of A<B
151179 */
151180 VdbeNoopComment((v, "A-lt-B subroutine"));
151181 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
 
151182 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
 
151183 sqlite3VdbeGoto(v, labelCmpr);
151184
151185 /* Generate code to handle the case of A==B
151186 */
151187 if( op==TK_ALL ){
@@ -151188,40 +151464,52 @@
151188 addrAeqB = addrAltB;
151189 }else if( op==TK_INTERSECT ){
151190 addrAeqB = addrAltB;
151191 addrAltB++;
151192 }else{
151193 VdbeNoopComment((v, "A-eq-B subroutine"));
151194 addrAeqB =
151195 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
151196 sqlite3VdbeGoto(v, labelCmpr);
151197 }
151198
151199 /* Generate code to handle the case of A>B
151200 */
151201 VdbeNoopComment((v, "A-gt-B subroutine"));
151202 addrAgtB = sqlite3VdbeCurrentAddr(v);
151203 if( op==TK_ALL || op==TK_UNION ){
151204 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
 
 
 
 
 
 
 
151205 }
151206 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
151207 sqlite3VdbeGoto(v, labelCmpr);
151208
151209 /* This code runs once to initialize everything.
151210 */
151211 sqlite3VdbeJumpHere(v, addr1);
151212 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
 
 
151213 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
 
151214
151215 /* Implement the main merge loop
151216 */
 
 
 
151217 sqlite3VdbeResolveLabel(v, labelCmpr);
151218 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
151219 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
151220 (char*)pKeyMerge, P4_KEYINFO);
151221 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
151222 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
 
 
 
 
 
 
151223
151224 /* Jump to the this point in order to terminate the query.
151225 */
151226 sqlite3VdbeResolveLabel(v, labelEnd);
151227
@@ -152774,10 +153062,20 @@
152774 x.isOuterJoin = 0;
152775 x.nSelDepth = 0;
152776 x.pEList = pSubq->pEList;
152777 x.pCList = findLeftmostExprlist(pSubq);
152778 pNew = substExpr(&x, pNew);
 
 
 
 
 
 
 
 
 
 
152779 #ifndef SQLITE_OMIT_WINDOWFUNC
152780 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
152781 /* Restriction 6c has prevented push-down in this case */
152782 sqlite3ExprDelete(pParse->db, pNew);
152783 nChng--;
@@ -154892,10 +155190,11 @@
154892 */
154893 typedef struct CheckOnCtx CheckOnCtx;
154894 struct CheckOnCtx {
154895 SrcList *pSrc; /* SrcList for this context */
154896 int iJoin; /* Cursor numbers must be =< than this */
 
154897 CheckOnCtx *pParent; /* Parent context */
154898 };
154899
154900 /*
154901 ** True if the SrcList passed as the only argument contains at least
@@ -154943,11 +155242,13 @@
154943 SrcList *pSrc = pCtx->pSrc;
154944 int iTab = pExpr->iTable;
154945 if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){
154946 if( pCtx->iJoin && iTab>pCtx->iJoin ){
154947 sqlite3ErrorMsg(pWalker->pParse,
154948 "ON clause references tables to its right");
 
 
154949 return WRC_Abort;
154950 }
154951 break;
154952 }
154953 pCtx = pCtx->pParent;
@@ -154978,24 +155279,39 @@
154978
154979 /*
154980 ** Check all ON clauses in pSelect to verify that they do not reference
154981 ** columns to the right.
154982 */
154983 static void selectCheckOnClauses(Parse *pParse, Select *pSelect){
154984 Walker w;
154985 CheckOnCtx sCtx;
 
154986 assert( pSelect->selFlags & SF_OnToWhere );
154987 assert( pSelect->pSrc!=0 && pSelect->pSrc->nSrc>=2 );
154988 memset(&w, 0, sizeof(w));
154989 w.pParse = pParse;
154990 w.xExprCallback = selectCheckOnClausesExpr;
154991 w.xSelectCallback = selectCheckOnClausesSelect;
154992 w.u.pCheckOnCtx = &sCtx;
154993 memset(&sCtx, 0, sizeof(sCtx));
154994 sCtx.pSrc = pSelect->pSrc;
154995 sqlite3WalkExprNN(&w, pSelect->pWhere);
154996 pSelect->selFlags &= ~SF_OnToWhere;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154997 }
154998
154999 /*
155000 ** If p2 exists and p1 and p2 have the same number of terms, then change
155001 ** every term of p1 to have the same sort order as p2 and return true.
@@ -155143,22 +155459,10 @@
155143 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
155144 sqlite3TreeViewSelect(0, p, 0);
155145 }
155146 #endif
155147
155148 /* If the SELECT statement contains ON clauses that were moved into
155149 ** the WHERE clause, go through and verify that none of the terms
155150 ** in the ON clauses reference tables to the right of the ON clause.
155151 ** Do this now, after name resolution, but before query flattening
155152 */
155153 if( p->selFlags & SF_OnToWhere ){
155154 selectCheckOnClauses(pParse, p);
155155 if( pParse->nErr ){
155156 goto select_end;
155157 }
155158 }
155159
155160 /* If the SF_UFSrcCheck flag is set, then this function is being called
155161 ** as part of populating the temp table for an UPDATE...FROM statement.
155162 ** In this case, it is an error if the target object (pSrc->a[0]) name
155163 ** or alias is duplicated within FROM clause (pSrc->a[1..n]).
155164 **
@@ -157006,10 +157310,11 @@
157006
157007 pParse->pNewTrigger = 0;
157008 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
157009 zName = pTrig->zName;
157010 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
 
157011 pTrig->step_list = pStepList;
157012 while( pStepList ){
157013 pStepList->pTrig = pTrig;
157014 pStepList = pStepList->pNext;
157015 }
@@ -163989,11 +164294,11 @@
163989 if( NEVER(pTerm==0) ) continue;
163990 if( pTerm->eOperator & WO_IN ){
163991 if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
163992 int iTab = pParse->nTab++;
163993 int iCache = ++pParse->nMem;
163994 sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab);
163995 sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
163996 }else{
163997 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
163998 addrNotFound = pLevel->addrNxt;
163999 }
@@ -165648,17 +165953,18 @@
165648 && ALWAYS(pLeft->y.pTab)
165649 && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
165650 ){
165651 int isNum;
165652 double rDummy;
165653 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
 
165654 if( isNum<=0 ){
165655 if( iTo==1 && zNew[0]=='-' ){
165656 isNum = +1;
165657 }else{
165658 zNew[iTo-1]++;
165659 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
165660 zNew[iTo-1]--;
165661 }
165662 }
165663 if( isNum>0 ){
165664 sqlite3ExprDelete(db, pPrefix);
@@ -165697,10 +166003,38 @@
165697 sqlite3ValueFree(pVal);
165698 return rc;
165699 }
165700 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
165701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165702
165703 #ifndef SQLITE_OMIT_VIRTUALTABLE
165704 /*
165705 ** Check to see if the pExpr expression is a form that needs to be passed
165706 ** to the xBestIndex method of virtual tables. Forms of interest include:
@@ -165733,19 +166067,10 @@
165733 unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
165734 Expr **ppLeft, /* Column expression to left of MATCH/op2 */
165735 Expr **ppRight /* Expression to left of MATCH/op2 */
165736 ){
165737 if( pExpr->op==TK_FUNCTION ){
165738 static const struct Op2 {
165739 const char *zOp;
165740 unsigned char eOp2;
165741 } aOp[] = {
165742 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
165743 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
165744 { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
165745 { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
165746 };
165747 ExprList *pList;
165748 Expr *pCol; /* Column reference */
165749 int i;
165750
165751 assert( ExprUseXList(pExpr) );
@@ -165761,20 +166086,15 @@
165761 ** vtab_column MATCH expression
165762 ** MATCH(expression,vtab_column)
165763 */
165764 pCol = pList->a[1].pExpr;
165765 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
165766 if( ExprIsVtab(pCol) ){
165767 for(i=0; i<ArraySize(aOp); i++){
165768 assert( !ExprHasProperty(pExpr, EP_IntValue) );
165769 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
165770 *peOp2 = aOp[i].eOp2;
165771 *ppRight = pList->a[0].pExpr;
165772 *ppLeft = pCol;
165773 return 1;
165774 }
165775 }
165776 }
165777
165778 /* We can also match against the first column of overloaded
165779 ** functions where xFindFunction returns a value of at least
165780 ** SQLITE_INDEX_CONSTRAINT_FUNCTION.
@@ -170218,10 +170538,71 @@
170218 p->u.btree.pIndex = 0;
170219 }
170220 }
170221 return rc;
170222 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170223
170224 /*
170225 ** Adjust the WhereLoop.nOut value downward to account for terms of the
170226 ** WHERE clause that reference the loop but which are not used by an
170227 ** index.
@@ -170247,10 +170628,17 @@
170247 ** of rows in the table. In other words, assume that x==EXPR will filter
170248 ** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
170249 ** "x" column is boolean or else -1 or 0 or 1 is a common default value
170250 ** on the "x" column and so in that case only cap the output row estimate
170251 ** at 1/2 instead of 1/4.
 
 
 
 
 
 
 
170252 */
170253 static void whereLoopOutputAdjust(
170254 WhereClause *pWC, /* The WHERE clause */
170255 WhereLoop *pLoop, /* The loop to adjust downward */
170256 LogEst nRow /* Number of rows in the entire table */
@@ -170296,25 +170684,43 @@
170296 ** then use the probability provided by the application. */
170297 pLoop->nOut += pTerm->truthProb;
170298 }else{
170299 /* In the absence of explicit truth probabilities, use heuristics to
170300 ** guess a reasonable truth probability. */
 
170301 pLoop->nOut--;
170302 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
170303 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
170304 ){
170305 Expr *pRight = pTerm->pExpr->pRight;
170306 int k = 0;
170307 testcase( pTerm->pExpr->op==TK_IS );
170308 if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
170309 k = 10;
170310 }else{
170311 k = 20;
170312 }
170313 if( iReduce<k ){
170314 pTerm->wtFlags |= TERM_HEURTRUTH;
170315 iReduce = k;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170316 }
170317 }
170318 }
170319 }
170320 }
@@ -172136,11 +172542,11 @@
172136 SrcItem *pItem;
172137 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
172138 sqlite3 *db = pWInfo->pParse->db;
172139 int rc = SQLITE_OK;
172140 int bFirstPastRJ = 0;
172141 int hasRightJoin = 0;
172142 WhereLoop *pNew;
172143
172144
172145 /* Loop over the tables in the join, from left to right */
172146 pNew = pBuilder->pNew;
@@ -172163,16 +172569,24 @@
172163 /* Add prerequisites to prevent reordering of FROM clause terms
172164 ** across CROSS joins and outer joins. The bFirstPastRJ boolean
172165 ** prevents the right operand of a RIGHT JOIN from being swapped with
172166 ** other elements even further to the right.
172167 **
172168 ** The JT_LTORJ case and the hasRightJoin flag work together to
172169 ** prevent FROM-clause terms from moving from the right side of
172170 ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
172171 ** is itself on the left side of a RIGHT JOIN.
 
 
 
 
172172 */
172173 if( pItem->fg.jointype & JT_LTORJ ) hasRightJoin = 1;
 
 
 
 
172174 mPrereq |= mPrior;
172175 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
172176 }else if( pItem->fg.fromExists ){
172177 /* joins that result from the EXISTS-to-JOIN optimization should not
172178 ** be moved to the left of any of their dependencies */
@@ -172182,11 +172596,11 @@
172182 for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){
172183 if( (pNew->maskSelf & pTerm->prereqAll)!=0 ){
172184 mPrereq |= (pTerm->prereqAll & (pNew->maskSelf-1));
172185 }
172186 }
172187 }else if( !hasRightJoin ){
172188 mPrereq = 0;
172189 }
172190 #ifndef SQLITE_OMIT_VIRTUALTABLE
172191 if( IsVirtual(pItem->pSTab) ){
172192 SrcItem *p;
@@ -172781,16 +173195,25 @@
172781 **
172782 ** 18 for star queries
172783 ** 12 otherwise
172784 **
172785 ** For the purposes of this heuristic, a star-query is defined as a query
172786 ** with a large central table that is joined using an INNER JOIN,
172787 ** not CROSS or OUTER JOINs, against four or more smaller tables.
172788 ** The central table is called the "fact" table. The smaller tables
172789 ** that get joined are "dimension tables". Also, any table that is
172790 ** self-joined cannot be a dimension table; we assume that dimension
172791 ** tables may only be joined against fact tables.
 
 
 
 
 
 
 
 
 
172792 **
172793 ** SIDE EFFECT: (and really the whole point of this subroutine)
172794 **
172795 ** If pWInfo describes a star-query, then the cost for SCANs of dimension
172796 ** WhereLoops is increased to be slightly larger than the cost of a SCAN
@@ -172839,11 +173262,11 @@
172839 assert( pWLoop->maskSelf==MASKBIT(pWLoop->iTab) );
172840 assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
172841 }
172842 #endif /* SQLITE_DEBUG */
172843
172844 if( nLoop>=5
172845 && !pWInfo->bStarDone
172846 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_StarQuery)
172847 ){
172848 SrcItem *aFromTabs; /* All terms of the FROM clause */
172849 int iFromIdx; /* Term of FROM clause is the candidate fact-table */
@@ -172851,11 +173274,11 @@
172851 Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
172852 WhereLoop *pStart; /* Where to start searching for dimension-tables */
172853
172854 pWInfo->bStarDone = 1; /* Only do this computation once */
172855
172856 /* Look for fact tables with four or more dimensions where the
172857 ** dimension tables are not separately from the fact tables by an outer
172858 ** or cross join. Adjust cost weights if found.
172859 */
172860 assert( !pWInfo->bStarUsed );
172861 aFromTabs = pWInfo->pTabList->a;
@@ -172868,22 +173291,21 @@
172868
172869 pFactTab = aFromTabs + iFromIdx;
172870 if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
172871 /* If the candidate fact-table is the right table of an outer join
172872 ** restrict the search for dimension-tables to be tables to the right
172873 ** of the fact-table. */
172874 if( iFromIdx+4 > nLoop ) break; /* Impossible to reach nDep>=4 */
 
 
172875 while( pStart && pStart->iTab<=iFromIdx ){
172876 pStart = pStart->pNextLoop;
172877 }
172878 }
172879 for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
172880 if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
172881 /* Fact-tables and dimension-tables cannot be separated by an
172882 ** outer join (at least for the definition of fact- and dimension-
172883 ** used by this heuristic). */
172884 break;
172885 }
172886 if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
172887 && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
172888 && (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
172889 ){
@@ -172893,11 +173315,13 @@
172893 nDep++;
172894 mSeen |= pWLoop->maskSelf;
172895 }
172896 }
172897 }
172898 if( nDep<=3 ) continue;
 
 
172899
172900 /* If we reach this point, it means that pFactTab is a fact table
172901 ** with four or more dimensions connected by inner joins. Proceed
172902 ** to make cost adjustments. */
172903
@@ -172906,10 +173330,27 @@
172906 if( !pWInfo->bStarUsed ){
172907 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
172908 pWLoop->rStarDelta = 0;
172909 }
172910 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172911 #endif
172912 pWInfo->bStarUsed = 1;
172913
172914 /* Compute the maximum cost of any WhereLoop for the
172915 ** fact table plus one epsilon */
@@ -172929,14 +173370,12 @@
172929 if( pWLoop->rRun<mxRun ){
172930 #ifdef WHERETRACE_ENABLED /* 0x80000 */
172931 if( sqlite3WhereTrace & 0x80000 ){
172932 SrcItem *pDim = aFromTabs + pWLoop->iTab;
172933 sqlite3DebugPrintf(
172934 "Increase SCAN cost of dimension %s(%d) of fact %s(%d) to %d\n",
172935 pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, pWLoop->iTab,
172936 pFactTab->zAlias ? pFactTab->zAlias : pFactTab->pSTab->zName,
172937 iFromIdx, mxRun
172938 );
172939 }
172940 pWLoop->rStarDelta = mxRun - pWLoop->rRun;
172941 #endif /* WHERETRACE_ENABLED */
172942 pWLoop->rRun = mxRun;
@@ -214034,32 +214473,36 @@
214034 jsonParseReset(&v);
214035 jsonParseReset(&ix);
214036 return rc;
214037 }
214038 }else if( zPath[0]=='[' ){
 
214039 x = pParse->aBlob[iRoot] & 0x0f;
214040 if( x!=JSONB_ARRAY ) return JSON_LOOKUP_NOTFOUND;
214041 n = jsonbPayloadSize(pParse, iRoot, &sz);
214042 k = 0;
214043 i = 1;
214044 while( sqlite3Isdigit(zPath[i]) ){
214045 k = k*10 + zPath[i] - '0';
 
 
214046 i++;
214047 }
214048 if( i<2 || zPath[i]!=']' ){
214049 if( zPath[1]=='#' ){
214050 k = jsonbArrayCount(pParse, iRoot);
214051 i = 2;
214052 if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){
214053 unsigned int nn = 0;
214054 i = 3;
214055 do{
214056 nn = nn*10 + zPath[i] - '0';
 
 
214057 i++;
214058 }while( sqlite3Isdigit(zPath[i]) );
214059 if( nn>k ) return JSON_LOOKUP_NOTFOUND;
214060 k -= nn;
214061 }
214062 if( zPath[i]!=']' ){
214063 return JSON_LOOKUP_PATHERROR;
214064 }
214065 }else{
@@ -214067,22 +214510,22 @@
214067 }
214068 }
214069 j = iRoot+n;
214070 iEnd = j+sz;
214071 while( j<iEnd ){
214072 if( k==0 ){
214073 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
214074 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
214075 return rc;
214076 }
214077 k--;
214078 n = jsonbPayloadSize(pParse, j, &sz);
214079 if( n==0 ) return JSON_LOOKUP_ERROR;
214080 j += n+sz;
214081 }
214082 if( j>iEnd ) return JSON_LOOKUP_ERROR;
214083 if( k>0 ) return JSON_LOOKUP_NOTFOUND;
214084 if( pParse->eEdit>=JEDIT_INS ){
214085 JsonParse v;
214086 testcase( pParse->eEdit==JEDIT_INS );
214087 testcase( pParse->eEdit==JEDIT_AINS );
214088 testcase( pParse->eEdit==JEDIT_SET );
@@ -214220,11 +214663,11 @@
214220 char *z;
214221 if( sz==0 ) goto returnfromblob_malformed;
214222 to_double:
214223 z = sqlite3DbStrNDup(db, (const char*)&pParse->aBlob[i+n], (int)sz);
214224 if( z==0 ) goto returnfromblob_oom;
214225 rc = sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
214226 sqlite3DbFree(db, z);
214227 if( rc<=0 ) goto returnfromblob_malformed;
214228 sqlite3_result_double(pCtx, r);
214229 break;
214230 }
@@ -221099,11 +221542,11 @@
221099 if( pVal ){
221100 #ifdef SQLITE_AMALGAMATION
221101 /* The sqlite3AtoF() routine is much much faster than atof(), if it
221102 ** is available */
221103 double r;
221104 (void)sqlite3AtoF((const char*)p->z, &r, j, SQLITE_UTF8);
221105 *pVal = r;
221106 #else
221107 *pVal = (GeoCoord)atof((const char*)p->z);
221108 #endif
221109 }
@@ -231358,10 +231801,11 @@
231358 struct carray_bind {
231359 void *aData; /* The data */
231360 int nData; /* Number of elements */
231361 int mFlags; /* Control flags */
231362 void (*xDel)(void*); /* Destructor for aData */
 
231363 };
231364
231365
231366 /* carray_cursor is a subclass of sqlite3_vtab_cursor which will
231367 ** serve as the underlying representation of a cursor that scans
@@ -231690,26 +232134,38 @@
231690 ** Destructor for the carray_bind object
231691 */
231692 static void carrayBindDel(void *pPtr){
231693 carray_bind *p = (carray_bind*)pPtr;
231694 if( p->xDel!=SQLITE_STATIC ){
231695 p->xDel(p->aData);
231696 }
231697 sqlite3_free(p);
231698 }
231699
231700 /*
231701 ** Invoke this interface in order to bind to the single-argument
231702 ** version of CARRAY().
 
 
 
 
 
 
 
 
 
 
 
231703 */
231704 SQLITE_API int sqlite3_carray_bind(
231705 sqlite3_stmt *pStmt,
231706 int idx,
231707 void *aData,
231708 int nData,
231709 int mFlags,
231710 void (*xDestroy)(void*)
 
231711 ){
231712 carray_bind *pNew = 0;
231713 int i;
231714 int rc = SQLITE_OK;
231715
@@ -231782,23 +232238,41 @@
231782 }
231783 }else{
231784 memcpy(pNew->aData, aData, sz);
231785 }
231786 pNew->xDel = sqlite3_free;
 
231787 }else{
231788 pNew->aData = aData;
231789 pNew->xDel = xDestroy;
 
231790 }
231791 return sqlite3_bind_pointer(pStmt, idx, pNew, "carray-bind", carrayBindDel);
231792
231793 carray_bind_error:
231794 if( xDestroy!=SQLITE_STATIC && xDestroy!=SQLITE_TRANSIENT ){
231795 xDestroy(aData);
231796 }
231797 sqlite3_free(pNew);
231798 return rc;
231799 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231800
231801 /*
231802 ** Invoke this routine to register the carray() function.
231803 */
231804 SQLITE_PRIVATE Module *sqlite3CarrayRegister(sqlite3 *db){
@@ -232157,10 +232631,24 @@
232157 ** bytes read.
232158 */
232159 static int sessionVarintGet(const u8 *aBuf, int *piVal){
232160 return getVarint32(aBuf, *piVal);
232161 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232162
232163 /* Load an unaligned and unsigned 32-bit integer */
232164 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
232165
232166 /*
@@ -235370,11 +235858,12 @@
235370
235371 if( rc==SQLITE_OK ){
235372 u8 *aVal = &pIn->aData[pIn->iNext];
235373 if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
235374 int nByte;
235375 pIn->iNext += sessionVarintGet(aVal, &nByte);
 
235376 rc = sessionInputBuffer(pIn, nByte);
235377 if( rc==SQLITE_OK ){
235378 if( nByte<0 || nByte>pIn->nData-pIn->iNext ){
235379 rc = SQLITE_CORRUPT_BKPT;
235380 }else{
@@ -235423,11 +235912,12 @@
235423 int nCol = 0;
235424 int nRead = 0;
235425
235426 rc = sessionInputBuffer(pIn, 9);
235427 if( rc==SQLITE_OK ){
235428 nRead += sessionVarintGet(&pIn->aData[pIn->iNext + nRead], &nCol);
 
235429 /* The hard upper limit for the number of columns in an SQLite
235430 ** database table is, according to sqliteLimit.h, 32676. So
235431 ** consider any table-header that purports to have more than 65536
235432 ** columns to be corrupt. This is convenient because otherwise,
235433 ** if the (nCol>65536) condition below were omitted, a sufficiently
@@ -235583,14 +236073,14 @@
235583 sqlite3ValueFree(p->apValue[i]);
235584 }
235585 memset(p->apValue, 0, sizeof(sqlite3_value*)*p->nCol*2);
235586 }
235587
235588 /* Make sure the buffer contains at least 10 bytes of input data, or all
235589 ** remaining data if there are less than 10 bytes available. This is
235590 ** sufficient either for the 'T' or 'P' byte and the varint that follows
235591 ** it, or for the two single byte values otherwise. */
235592 p->rc = sessionInputBuffer(&p->in, 2);
235593 if( p->rc!=SQLITE_OK ) return p->rc;
235594
235595 p->in.iCurrent = p->in.iNext;
235596 sessionDiscardData(&p->in);
@@ -235616,15 +236106,17 @@
235616 ** corrupt changeset. */
235617 assert( p->in.iNext==1 || p->zTab );
235618 return (p->rc = SQLITE_CORRUPT_BKPT);
235619 }
235620
235621 p->op = op;
235622 p->bIndirect = p->in.aData[p->in.iNext++];
235623 if( p->op!=SQLITE_UPDATE && p->op!=SQLITE_DELETE && p->op!=SQLITE_INSERT ){
235624 return (p->rc = SQLITE_CORRUPT_BKPT);
235625 }
 
 
235626
235627 if( paRec ){
235628 int nVal; /* Number of values to buffer */
235629 if( p->bPatchset==0 && op==SQLITE_UPDATE ){
235630 nVal = p->nCol * 2;
@@ -261258,11 +261750,11 @@
261258 int nArg, /* Number of args */
261259 sqlite3_value **apUnused /* Function arguments */
261260 ){
261261 assert( nArg==0 );
261262 UNUSED_PARAM2(nArg, apUnused);
261263 sqlite3_result_text(pCtx, "fts5: 2026-01-26 10:53:24 4733d351ec2376291f093ba8d2ba71d82c6f100c68dc860eee0532986c154e71", -1, SQLITE_TRANSIENT);
261264 }
261265
261266 /*
261267 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261268 **
261269
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 2610105a439e25c050b2deb32953861187c8 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2026-02-17 11:28:48 2610105a439e25c050b2deb32953861187c81b1d97407f41dc188e6627e0ac4d"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-02-17T11:28:48.505Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -11571,23 +11571,45 @@
11571 #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
11572
11573 /*
11574 ** CAPI3REF: Bind array values to the CARRAY table-valued function
11575 **
11576 ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to
11577 ** parameter that is the first argument of the [carray() table-valued function].
11578 ** The S parameter is a pointer to the [prepared statement] that uses the carray()
11579 ** functions. I is the parameter index to be bound. I must be the index of the
11580 ** parameter that is the first argument to the carray() table-valued function.
11581 ** P is a pointer to the array to be bound, and N is the number of elements in
11582 ** the array. The F argument is one of constants [SQLITE_CARRAY_INT32],
11583 ** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT],
11584 ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P.
11585 **
11586 ** If the X argument is not a NULL pointer or one of the special
11587 ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke
11588 ** the function X with argument D when it is finished using the data in P.
11589 ** The call to X(D) is a destructor for the array P. The destructor X(D)
11590 ** is invoked even if the call to sqlite3_carray_bind() fails. If the X
11591 ** parameter is the special-case value [SQLITE_STATIC], then SQLite assumes
11592 ** that the data static and the destructor is never invoked. If the X
11593 ** parameter is the special-case value [SQLITE_TRANSIENT], then
11594 ** sqlite3_carray_bind_v2() makes its own private copy of the data prior
11595 ** to returning and never invokes the destructor X.
11596 **
11597 ** The sqlite3_carray_bind() function works the same as sqlite_carray_bind_v2()
11598 ** with a D parameter set to P. In other words,
11599 ** sqlite3_carray_bind(S,I,P,N,F,X) is same as
11600 ** sqlite3_carray_bind(S,I,P,N,F,X,P).
11601 */
11602 SQLITE_API int sqlite3_carray_bind_v2(
11603 sqlite3_stmt *pStmt, /* Statement to be bound */
11604 int i, /* Parameter index */
11605 void *aData, /* Pointer to array data */
11606 int nData, /* Number of data elements */
11607 int mFlags, /* CARRAY flags */
11608 void (*xDel)(void*), /* Destructor for aData */
11609 void *pDel /* Optional argument to xDel() */
11610 );
11611 SQLITE_API int sqlite3_carray_bind(
11612 sqlite3_stmt *pStmt, /* Statement to be bound */
11613 int i, /* Parameter index */
11614 void *aData, /* Pointer to array data */
11615 int nData, /* Number of data elements */
@@ -15814,10 +15836,11 @@
15836 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
15837 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
15838 #else
15839 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
15840 #endif
15841 #define TWO_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&1)==0)
15842
15843 /*
15844 ** Disable MMAP on platforms where it is known to not work
15845 */
15846 #if defined(__OpenBSD__) || defined(__QNXNTO__)
@@ -20337,11 +20360,11 @@
20360 #define SF_Distinct 0x0000001 /* Output should be DISTINCT */
20361 #define SF_All 0x0000002 /* Includes the ALL keyword */
20362 #define SF_Resolved 0x0000004 /* Identifiers have been resolved */
20363 #define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */
20364 #define SF_HasAgg 0x0000010 /* Contains aggregate functions */
20365 #define SF_ClonedRhsIn 0x0000020 /* Cloned RHS of an IN operator */
20366 #define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */
20367 #define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */
20368 #define SF_Compound 0x0000100 /* Part of a compound query */
20369 #define SF_Values 0x0000200 /* Synthesized from VALUES clause */
20370 #define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */
@@ -20594,33 +20617,33 @@
20617 int rc; /* Return code from execution */
20618 LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
20619 u8 nested; /* Number of nested calls to the parser/code generator */
20620 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
20621 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
 
 
20622 u8 disableLookaside; /* Number of times lookaside has been disabled */
20623 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20624 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
 
20625 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20626 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
 
20627 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
 
20628 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
20629 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
20630 #endif
20631 #ifdef SQLITE_DEBUG
20632 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
20633 u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
20634 ** and ALTER TABLE ADD COLUMN. */
20635 #endif
20636 bft disableTriggers:1; /* True to disable triggers */
20637 bft mayAbort :1; /* True if statement may throw an ABORT exception */
20638 bft hasCompound :1; /* Need to invoke convertCompoundSelectToSubquery() */
20639 bft bReturning :1; /* Coding a RETURNING trigger */
20640 bft bHasExists :1; /* Has a correlated "EXISTS (SELECT ....)" expression */
20641 bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20642 bft bHasWith :1; /* True if statement contains WITH */
20643 bft okConstFactor:1; /* OK to factor out constants */
20644 bft checkSchema :1; /* Causes schema cookie check after an error */
20645 int nRangeReg; /* Size of the temporary register block */
20646 int iRangeReg; /* First register in temporary register block */
20647 int nErr; /* Number of errors seen */
20648 int nTab; /* Number of previously allocated VDBE cursors */
20649 int nMem; /* Number of memory cells used so far */
@@ -21094,10 +21117,11 @@
21117 u16 mWFlags; /* Use-dependent flags */
21118 union { /* Extra data for callback */
21119 NameContext *pNC; /* Naming context */
21120 int n; /* A counter */
21121 int iCur; /* A cursor number */
21122 int sz; /* String literal length */
21123 SrcList *pSrcList; /* FROM clause */
21124 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
21125 struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */
21126 int *aiCol; /* array of column indexes */
21127 struct IdxCover *pIdxCover; /* Check for index coverage */
@@ -21780,10 +21804,11 @@
21804 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
21805 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
21806 Expr*,ExprList*,u32,Expr*);
21807 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
21808 SQLITE_PRIVATE void sqlite3SelectDeleteGeneric(sqlite3*,void*);
21809 SQLITE_PRIVATE void sqlite3SelectCheckOnClauses(Parse *pParse, Select *pSelect);
21810 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
21811 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, Trigger*);
21812 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
21813 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
21814 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -21877,10 +21902,11 @@
21902 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
21903 #endif
21904 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
21905 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
21906 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
21907 SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr*);
21908 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
21909 SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab);
21910 SQLITE_PRIVATE void sqlite3GenerateRowDelete(
21911 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
21912 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
@@ -22000,11 +22026,11 @@
22026 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
22027
22028 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
22029 SQLITE_PRIVATE i64 sqlite3RealToI64(double);
22030 SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*);
22031 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
22032 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
22033 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
22034 SQLITE_PRIVATE int sqlite3Atoi(const char*);
22035 #ifndef SQLITE_OMIT_UTF16
22036 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nByte, int nChar);
@@ -22150,11 +22176,11 @@
22176 SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int);
22177 SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*);
22178 SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *);
22179 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
22180 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
22181 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
22182 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
22183 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
22184 SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, SrcItem*);
22185 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
22186 SQLITE_PRIVATE int sqlite3MatchEName(
@@ -24584,17 +24610,18 @@
24610 #endif
24611 #ifdef SQLITE_DEBUG
24612 SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*);
24613 #endif
24614 SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*);
24615 SQLITE_PRIVATE int sqlite3VdbeMemZeroTerminateIfAble(Mem*);
24616 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
24617 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
24618 SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double);
24619 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*);
24620 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
24621 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
24622 SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem*, int*);
24623 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
24624 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
24625 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
24626 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
24627 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
@@ -25550,11 +25577,11 @@
25577 return 0;
25578 }else if( parseHhMmSs(zDate, p)==0 ){
25579 return 0;
25580 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
25581 return setDateTimeToCurrent(context, p);
25582 }else if( sqlite3AtoF(zDate, &r)>0 ){
25583 setRawDateNumber(p, r);
25584 return 0;
25585 }else if( (sqlite3StrICmp(zDate,"subsec")==0
25586 || sqlite3StrICmp(zDate,"subsecond")==0)
25587 && sqlite3NotPureFunc(context) ){
@@ -25996,11 +26023,11 @@
26023 ** Move the date to the same time on the next occurrence of
26024 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
26025 ** date is already on the appropriate weekday, this is a no-op.
26026 */
26027 if( sqlite3_strnicmp(z, "weekday ", 8)==0
26028 && sqlite3AtoF(&z[8], &r)>0
26029 && r>=0.0 && r<7.0 && (n=(int)r)==r ){
26030 sqlite3_int64 Z;
26031 computeYMD_HMS(p);
26032 p->tz = 0;
26033 p->validJD = 0;
@@ -26067,23 +26094,29 @@
26094 case '6':
26095 case '7':
26096 case '8':
26097 case '9': {
26098 double rRounder;
26099 int i, rx;
26100 int Y,M,D,h,m,x;
26101 const char *z2 = z;
26102 char *zCopy;
26103 sqlite3 *db = sqlite3_context_db_handle(pCtx);
26104 char z0 = z[0];
26105 for(n=1; z[n]; n++){
26106 if( z[n]==':' ) break;
26107 if( sqlite3Isspace(z[n]) ) break;
26108 if( z[n]=='-' ){
26109 if( n==5 && getDigits(&z[1], "40f", &Y)==1 ) break;
26110 if( n==6 && getDigits(&z[1], "50f", &Y)==1 ) break;
26111 }
26112 }
26113 zCopy = sqlite3DbStrNDup(db, z, n);
26114 if( zCopy==0 ) break;
26115 rx = sqlite3AtoF(zCopy, &r)<=0;
26116 sqlite3DbFree(db, zCopy);
26117 if( rx ){
26118 assert( rc==1 );
26119 break;
26120 }
26121 if( z[n]=='-' ){
26122 /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
@@ -34904,11 +34937,17 @@
34937 ** sqlite3ShowWhereTerm() in where.c
34938 */
34939 SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
34940 SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
34941 SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
34942 SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){
34943 TreeView *pView = 0;
34944 sqlite3TreeViewPush(&pView, 0);
34945 sqlite3TreeViewLine(pView, "SRCLIST");
34946 sqlite3TreeViewSrcList(pView,p);
34947 sqlite3TreeViewPop(&pView);
34948 }
34949 SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
34950 SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
34951 SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
34952 #ifndef SQLITE_OMIT_TRIGGER
34953 SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep *p){
@@ -36424,52 +36463,261 @@
36463 z++;
36464 }
36465 return h;
36466 }
36467
36468 /*
36469 ** Two inputs are multiplied to get a 128-bit result. Return
36470 ** the high-order 64 bits of that result.
36471 */
36472 static u64 sqlite3Multiply128(u64 a, u64 b){
36473 #if (defined(__GNUC__) || defined(__clang__)) \
36474 && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv))
36475 return ((__uint128_t)a * b) >> 64;
36476 #elif defined(_MSC_VER) && defined(_M_X64)
36477 return __umulh(a, b);
36478 #else
36479 u64 a1 = (u32)a;
36480 u64 a2 = a >> 32;
36481 u64 b1 = (u32)b;
36482 u64 b2 = b >> 32;
36483 u64 p0 = a1 * b1;
36484 u64 p1 = a1 * b2;
36485 u64 p2 = a2 * b1;
36486 u64 p3 = a2 * b2;
36487 u64 carry = ((p0 >> 32) + (u32)p1 + (u32)p2) >> 32;
36488 return p3 + (p1 >> 32) + (p2 >> 32) + carry;
36489 #endif
36490 }
36491
36492 /*
36493 ** Return a u64 with the N-th bit set.
36494 */
36495 #define U64_BIT(N) (((u64)1)<<(N))
36496
36497 /*
36498 ** Range of powers of 10 that we need to deal with when converting
36499 ** IEEE754 doubles to and from decimal.
36500 */
36501 #define POWERSOF10_FIRST (-348)
36502 #define POWERSOF10_LAST (+347)
36503
36504 /*
36505 ** For any p between -348 and +347, return the integer part of
36506 **
36507 ** pow(10,p) * pow(2,63-pow10to2(p))
36508 **
36509 ** Or, in other words, for any p in range, return the most significant
36510 ** 64 bits of pow(10,p). The pow(10,p) value is shifted left or right,
36511 ** as appropriate so the most significant 64 bits fit exactly into a
36512 ** 64-bit unsigned integer.
36513 **
36514 ** Algorithm:
36515 **
36516 ** (1) For p between 0 and 26, return the value directly from the aBase[]
36517 ** lookup table.
36518 **
36519 ** (2) For p outside the range 0 to 26, use aScale[] for the initial value
36520 ** then refine that result (if necessary) by a single multiplication
36521 ** against aBase[].
36522 */
36523 static u64 powerOfTen(int p){
36524 static const u64 aBase[] = {
36525 0x8000000000000000LLU, /* 0: 1.0e+0 << 63 */
36526 0xa000000000000000LLU, /* 1: 1.0e+1 << 60 */
36527 0xc800000000000000LLU, /* 2: 1.0e+2 << 57 */
36528 0xfa00000000000000LLU, /* 3: 1.0e+3 << 54 */
36529 0x9c40000000000000LLU, /* 4: 1.0e+4 << 50 */
36530 0xc350000000000000LLU, /* 5: 1.0e+5 << 47 */
36531 0xf424000000000000LLU, /* 6: 1.0e+6 << 44 */
36532 0x9896800000000000LLU, /* 7: 1.0e+7 << 40 */
36533 0xbebc200000000000LLU, /* 8: 1.0e+8 << 37 */
36534 0xee6b280000000000LLU, /* 9: 1.0e+9 << 34 */
36535 0x9502f90000000000LLU, /* 10: 1.0e+10 << 30 */
36536 0xba43b74000000000LLU, /* 11: 1.0e+11 << 27 */
36537 0xe8d4a51000000000LLU, /* 12: 1.0e+12 << 24 */
36538 0x9184e72a00000000LLU, /* 13: 1.0e+13 << 20 */
36539 0xb5e620f480000000LLU, /* 14: 1.0e+14 << 17 */
36540 0xe35fa931a0000000LLU, /* 15: 1.0e+15 << 14 */
36541 0x8e1bc9bf04000000LLU, /* 16: 1.0e+16 << 10 */
36542 0xb1a2bc2ec5000000LLU, /* 17: 1.0e+17 << 7 */
36543 0xde0b6b3a76400000LLU, /* 18: 1.0e+18 << 4 */
36544 0x8ac7230489e80000LLU, /* 19: 1.0e+19 >> 0 */
36545 0xad78ebc5ac620000LLU, /* 20: 1.0e+20 >> 3 */
36546 0xd8d726b7177a8000LLU, /* 21: 1.0e+21 >> 6 */
36547 0x878678326eac9000LLU, /* 22: 1.0e+22 >> 10 */
36548 0xa968163f0a57b400LLU, /* 23: 1.0e+23 >> 13 */
36549 0xd3c21bcecceda100LLU, /* 24: 1.0e+24 >> 16 */
36550 0x84595161401484a0LLU, /* 25: 1.0e+25 >> 20 */
36551 0xa56fa5b99019a5c8LLU, /* 26: 1.0e+26 >> 23 */
36552 };
36553 static const u64 aScale[] = {
36554 0x8049a4ac0c5811aeLLU, /* 0: 1.0e-351 << 1229 */
36555 0xcf42894a5dce35eaLLU, /* 1: 1.0e-324 << 1140 */
36556 0xa76c582338ed2621LLU, /* 2: 1.0e-297 << 1050 */
36557 0x873e4f75e2224e68LLU, /* 3: 1.0e-270 << 960 */
36558 0xda7f5bf590966848LLU, /* 4: 1.0e-243 << 871 */
36559 0xb080392cc4349decLLU, /* 5: 1.0e-216 << 781 */
36560 0x8e938662882af53eLLU, /* 6: 1.0e-189 << 691 */
36561 0xe65829b3046b0afaLLU, /* 7: 1.0e-162 << 602 */
36562 0xba121a4650e4ddebLLU, /* 8: 1.0e-135 << 512 */
36563 0x964e858c91ba2655LLU, /* 9: 1.0e-108 << 422 */
36564 0xf2d56790ab41c2a2LLU, /* 10: 1.0e-81 << 333 */
36565 0xc428d05aa4751e4cLLU, /* 11: 1.0e-54 << 243 */
36566 0x9e74d1b791e07e48LLU, /* 12: 1.0e-27 << 153 */
36567 0x8000000000000000LLU, /* 13: 1.0e+0 << 63 */
36568 0xcecb8f27f4200f3aLLU, /* 14: 1.0e+27 >> 26 */
36569 0xa70c3c40a64e6c51LLU, /* 15: 1.0e+54 >> 116 */
36570 0x86f0ac99b4e8dafdLLU, /* 16: 1.0e+81 >> 206 */
36571 0xda01ee641a708de9LLU, /* 17: 1.0e+108 >> 295 */
36572 0xb01ae745b101e9e4LLU, /* 18: 1.0e+135 >> 385 */
36573 0x8e41ade9fbebc27dLLU, /* 19: 1.0e+162 >> 475 */
36574 0xe5d3ef282a242e81LLU, /* 20: 1.0e+189 >> 564 */
36575 0xb9a74a0637ce2ee1LLU, /* 21: 1.0e+216 >> 654 */
36576 0x95f83d0a1fb69cd9LLU, /* 22: 1.0e+243 >> 744 */
36577 0xf24a01a73cf2dccfLLU, /* 23: 1.0e+270 >> 833 */
36578 0xc3b8358109e84f07LLU, /* 24: 1.0e+297 >> 923 */
36579 0x9e19db92b4e31ba9LLU, /* 25: 1.0e+324 >> 1013 */
36580 };
36581 int g, n;
36582 u64 x, y;
36583
36584 assert( p>=POWERSOF10_FIRST && p<=POWERSOF10_LAST );
36585 if( p<0 ){
36586 g = p/27;
36587 n = p%27;
36588 if( n ){
36589 g--;
36590 n += 27;
36591 }
36592 }else if( p<27 ){
36593 return aBase[p];
36594 }else{
36595 g = p/27;
36596 n = p%27;
36597 }
36598 y = aScale[g+13];
36599 if( n==0 ){
36600 return y;
36601 }
36602 x = sqlite3Multiply128(aBase[n],y);
36603 if( (U64_BIT(63) & x)==0 ){
36604 x <<= 1;
36605 }
36606 return x;
36607 }
36608
36609 /*
36610 ** pow10to2(x) computes floor(log2(pow(10,x))).
36611 ** pow2to10(y) computes floor(log10(pow(2,y))).
36612 **
36613 ** Conceptually, pow10to2(p) converts a base-10 exponent p into
36614 ** a corresponding base-2 exponent, and pow2to10(e) converts a base-2
36615 ** exponent into a base-10 exponent.
36616 **
36617 ** The conversions are based on the observation that:
36618 **
36619 ** ln(10.0)/ln(2.0) == 108853/32768 (approximately)
36620 ** ln(2.0)/ln(10.0) == 78913/262144 (approximately)
36621 **
36622 ** These ratios are approximate, but they are accurate to 5 digits,
36623 ** which is close enough for the usage here. Right-shift is used
36624 ** for division so that rounding of negative numbers happens in the
36625 ** right direction.
36626 */
36627 static int pwr10to2(int p){ return (p*108853) >> 15; }
36628 static int pwr2to10(int p){ return (p*78913) >> 18; }
36629
36630 /*
36631 ** Count leading zeros for a 64-bit unsigned integer.
36632 */
36633 static int countLeadingZeros(u64 m){
36634 #if defined(__GNUC__) || defined(__clang__)
36635 return __builtin_clzll(m);
36636 #else
36637 int n = 0;
36638 if( m <= 0x00000000ffffffffULL) { n += 32; m <<= 32; }
36639 if( m <= 0x0000ffffffffffffULL) { n += 16; m <<= 16; }
36640 if( m <= 0x00ffffffffffffffULL) { n += 8; m <<= 8; }
36641 if( m <= 0x0fffffffffffffffULL) { n += 4; m <<= 4; }
36642 if( m <= 0x3fffffffffffffffULL) { n += 2; m <<= 2; }
36643 if( m <= 0x7fffffffffffffffULL) { n += 1; }
36644 return n;
36645 #endif
36646 }
36647
36648 /*
36649 ** Given m and e, which represent a quantity r == m*pow(2,e),
36650 ** return values *pD and *pP such that r == (*pD)*pow(10,*pP),
36651 ** approximately. *pD should contain at least n significant digits.
36652 **
36653 ** The input m is required to have its highest bit set. In other words,
36654 ** m should be left-shifted, and e decremented, to maximize the value of m.
36655 */
36656 static void sqlite3Fp2Convert10(u64 m, int e, int n, u64 *pD, int *pP){
36657 int p;
36658 u64 h, out;
36659 p = n - 1 - pwr2to10(e+63);
36660 h = sqlite3Multiply128(m, powerOfTen(p));
36661 assert( -(e + pwr10to2(p) + 3) >=0 );
36662 assert( -(e + pwr10to2(p) + 3) <64 );
36663 out = h >> -(e + pwr10to2(p) + 3);
36664 *pD = (out + 2 + ((out>>2)&1)) >> 2;
36665 *pP = -p;
36666 }
36667
36668 /*
36669 ** Return an IEEE754 floating point value that approximates d*pow(10,p).
36670 */
36671 static double sqlite3Fp10Convert2(u64 d, int p){
36672 u64 out;
36673 int b;
36674 int e1;
36675 int e2;
36676 int lp;
36677 u64 h;
36678 double r;
36679 assert( (d & U64_BIT(63))==0 );
36680 assert( d!=0 );
36681 if( p<POWERSOF10_FIRST ){
36682 return 0.0;
36683 }
36684 if( p>POWERSOF10_LAST ){
36685 return INFINITY;
36686 }
36687 b = 64 - countLeadingZeros(d);
36688 lp = pwr10to2(p);
36689 e1 = 53 - b - lp;
36690 if( e1>1074 ){
36691 if( -(b + lp) >= 1077 ) return 0.0;
36692 e1 = 1074;
36693 }
36694 e2 = e1 - (64-b);
36695 h = sqlite3Multiply128(d<<(64-b), powerOfTen(p));
36696 assert( -(e2 + lp + 3) >=0 );
36697 assert( -(e2 + lp + 3) <64 );
36698 out = (h >> -(e2 + lp + 3)) | 1;
36699 if( out >= U64_BIT(55)-2 ){
36700 out = (out>>1) | (out&1);
36701 e1--;
36702 }
36703 if( e1<=(-972) ){
36704 return INFINITY;
36705 }
36706 out = (out + 1 + ((out>>2)&1)) >> 2;
36707 if( (out & U64_BIT(52))!=0 ){
36708 out = (out & ~U64_BIT(52)) | ((u64)(1075-e1)<<52);
36709 }
36710 memcpy(&r, &out, 8);
36711 return r;
36712 }
36713
36714 /*
36715 ** The string z[] is an text representation of a real number.
36716 ** Convert this string to a double and write it into *pResult.
36717 **
36718 ** z[] must be UTF-8 and zero-terminated.
 
36719 **
36720 ** Return TRUE if the result is a valid real number (or integer) and FALSE
36721 ** if the string is empty or contains extraneous text. More specifically
36722 ** return
36723 ** 1 => The input string is a pure integer
@@ -36492,201 +36740,134 @@
36740 ** into *pResult.
36741 */
36742 #if defined(_MSC_VER)
36743 #pragma warning(disable : 4756)
36744 #endif
36745 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
36746 #ifndef SQLITE_OMIT_FLOATING_POINT
 
 
36747 /* sign * significand * (10 ^ (esign * exponent)) */
36748 int neg = 0; /* True for a negative value */
36749 u64 s = 0; /* mantissa */
36750 int d = 0; /* Value is s * pow(10,d) */
 
 
 
36751 int nDigit = 0; /* Number of digits processed */
36752 int eType = 1; /* 1: pure integer, 2+: fractional */
36753
36754 *pResult = 0.0; /* Default return value, in case of an error */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36755
36756 /* skip leading spaces */
36757 while( sqlite3Isspace(*z) ) z++;
 
36758
36759 /* get sign of significand */
36760 if( *z=='-' ){
36761 neg = 1;
36762 z++;
36763 }else if( *z=='+' ){
36764 z++;
36765 }
36766
36767 /* copy max significant digits to significand */
36768 while( sqlite3Isdigit(*z) ){
36769 s = s*10 + (*z - '0');
36770 z++; nDigit++;
36771 if( s>=((LARGEST_INT64-9)/10) ){
36772 /* skip non-significant significand digits
36773 ** (increase exponent by d to shift decimal left) */
36774 while( sqlite3Isdigit(*z) ){ z++; d++; }
36775 }
36776 }
 
36777
36778 /* if decimal point is present */
36779 if( *z=='.' ){
36780 z++;
36781 eType++;
36782 /* copy digits from after decimal to significand
36783 ** (decrease exponent by d to shift decimal right) */
36784 while( sqlite3Isdigit(*z) ){
36785 if( s<((LARGEST_INT64-9)/10) ){
36786 s = s*10 + (*z - '0');
36787 d--;
36788 nDigit++;
36789 }
36790 z++;
36791 }
36792 }
 
36793
36794 /* if exponent is present */
36795 if( *z=='e' || *z=='E' ){
36796 int esign = 1; /* sign of exponent */
36797 z++;
36798 eType++;
36799
 
 
 
 
 
36800 /* get sign of exponent */
36801 if( *z=='-' ){
36802 esign = -1;
36803 z++;
36804 }else if( *z=='+' ){
36805 z++;
36806 }
36807 /* copy digits to exponent */
36808 if( sqlite3Isdigit(*z) ){
36809 int exp = *z - '0';
36810 z++;
36811 while( sqlite3Isdigit(*z) ){
36812 exp = exp<10000 ? (exp*10 + (*z - '0')) : 10000;
36813 z++;
36814 }
36815 d += esign*exp;
36816 }else{
36817 eType = -1;
36818 }
36819 }
36820
36821 /* skip trailing spaces */
36822 while( sqlite3Isspace(*z) ) z++;
36823
 
36824 /* Zero is a special case */
36825 if( s==0 ){
36826 *pResult = neg ? -0.0 : +0.0;
36827 }else{
36828 *pResult = sqlite3Fp10Convert2(s,d);
36829 if( neg ) *pResult = -*pResult;
36830 assert( !sqlite3IsNaN(*pResult) );
36831 }
36832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36833 /* return true if number and no extra non-whitespace characters after */
36834 if( z[0]==0 && nDigit>0 ){
36835 return eType;
36836 }else if( eType>=2 && nDigit>0 ){
36837 return -1;
36838 }else{
36839 return 0;
36840 }
36841 #else
36842 return !sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8);
36843 #endif /* SQLITE_OMIT_FLOATING_POINT */
36844 }
36845 #if defined(_MSC_VER)
36846 #pragma warning(default : 4756)
36847 #endif
36848
36849 /*
36850 ** Digit pairs used to convert a U64 or I64 into text, two digits
36851 ** at a time.
36852 */
36853 static const union {
36854 char a[200];
36855 short int forceAlignment;
36856 } sqlite3DigitPairs = {
36857 "00010203040506070809"
36858 "10111213141516171819"
36859 "20212223242526272829"
36860 "30313233343536373839"
36861 "40414243444546474849"
36862 "50515253545556575859"
36863 "60616263646566676869"
36864 "70717273747576777879"
36865 "80818283848586878889"
36866 "90919293949596979899"
36867 };
36868
36869
36870 /*
36871 ** Render an signed 64-bit integer as text. Store the result in zOut[] and
36872 ** return the length of the string that was stored, in bytes. The value
36873 ** returned does not include the zero terminator at the end of the output
@@ -36695,27 +36876,39 @@
36876 ** The caller must ensure that zOut[] is at least 21 bytes in size.
36877 */
36878 SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){
36879 int i;
36880 u64 x;
36881 union {
36882 char a[23];
36883 u16 forceAlignment;
36884 } u;
36885 if( v>0 ){
36886 x = v;
36887 }else if( v==0 ){
36888 zOut[0] = '0';
36889 zOut[1] = 0;
36890 return 1;
36891 }else{
36892 x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
36893 }
36894 i = sizeof(u.a)-1;
36895 u.a[i] = 0;
36896 while( x>=10 ){
36897 int kk = (x%100)*2;
36898 assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) );
36899 assert( TWO_BYTE_ALIGNMENT(&u.a[i-2]) );
36900 *(u16*)(&u.a[i-2]) = *(u16*)&sqlite3DigitPairs.a[kk];
36901 i -= 2;
36902 x /= 100;
36903 }
36904 if( x ){
36905 u.a[--i] = x + '0';
36906 }
36907 if( v<0 ) u.a[--i] = '-';
36908 memcpy(zOut, &u.a[i], sizeof(u.a)-i);
36909 return sizeof(u.a)-1-i;
36910 }
36911
36912 /*
36913 ** Compare the 19-character string zNum against the text representation
36914 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -36984,11 +37177,10 @@
37177 */
37178 SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
37179 int i;
37180 u64 v;
37181 int e, exp = 0;
 
37182
37183 p->isSpecial = 0;
37184 p->z = p->zBuf;
37185 assert( mxRound>0 );
37186
@@ -37005,64 +37197,43 @@
37197 return;
37198 }else{
37199 p->sign = '+';
37200 }
37201 memcpy(&v,&r,8);
37202 e = (v>>52)&0x7ff;
37203 if( e==0x7ff ){
37204 p->isSpecial = 1 + (v!=0x7ff0000000000000LL);
37205 p->n = 0;
37206 p->iDP = 0;
37207 return;
37208 }
37209 v &= 0x000fffffffffffffULL;
37210 if( e==0 ){
37211 int n = countLeadingZeros(v);
37212 v <<= n;
37213 e = -1074 - n;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37214 }else{
37215 v = (v<<11) | U64_BIT(63);
37216 e -= 1086;
37217 }
37218 sqlite3Fp2Convert10(v, e, 17, &v, &exp);
 
 
 
 
 
 
 
 
 
 
37219
37220 /* Extract significant digits. */
37221 i = sizeof(p->zBuf)-1;
37222 assert( v>0 );
37223 while( v>=10 ){
37224 int kk = (v%100)*2;
37225 assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) );
37226 assert( TWO_BYTE_ALIGNMENT(&p->zBuf[i-1]) );
37227 *(u16*)(&p->zBuf[i-1]) = *(u16*)&sqlite3DigitPairs.a[kk];
37228 i -= 2;
37229 v /= 100;
37230 }
37231 if( v ){
37232 assert( v<10 );
37233 p->zBuf[i--] = v + '0';
37234 }
37235 assert( i>=0 && i<sizeof(p->zBuf)-1 );
37236 p->n = sizeof(p->zBuf) - 1 - i;
37237 assert( p->n>0 );
37238 assert( p->n<sizeof(p->zBuf) );
37239 p->iDP = p->n + exp;
@@ -84980,36 +85151,40 @@
85151 ** If pMem is already a string, detect if it is a zero-terminated
85152 ** string, or make it into one if possible, and mark it as such.
85153 **
85154 ** This is an optimization. Correct operation continues even if
85155 ** this routine is a no-op.
85156 **
85157 ** Return true if the strig is zero-terminated after this routine is
85158 ** called and false if it is not.
85159 */
85160 SQLITE_PRIVATE int sqlite3VdbeMemZeroTerminateIfAble(Mem *pMem){
85161 if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
85162 /* pMem must be a string, and it cannot be an ephemeral or static string */
85163 return 0;
85164 }
85165 if( pMem->enc!=SQLITE_UTF8 ) return 0;
85166 assert( pMem->z!=0 );
85167 if( pMem->flags & MEM_Dyn ){
85168 if( pMem->xDel==sqlite3_free
85169 && sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
85170 ){
85171 pMem->z[pMem->n] = 0;
85172 pMem->flags |= MEM_Term;
85173 return 1;
85174 }
85175 if( pMem->xDel==sqlite3RCStrUnref ){
85176 /* Blindly assume that all RCStr objects are zero-terminated */
85177 pMem->flags |= MEM_Term;
85178 return 1;
85179 }
85180 }else if( pMem->szMalloc >= pMem->n+1 ){
85181 pMem->z[pMem->n] = 0;
85182 pMem->flags |= MEM_Term;
85183 return 1;
85184 }
85185 return 0;
85186 }
85187
85188 /*
85189 ** It is already known that pMem contains an unterminated string.
85190 ** Add the zero terminator.
@@ -85302,23 +85477,75 @@
85477 return memIntValue(pMem);
85478 }else{
85479 return 0;
85480 }
85481 }
85482
85483 /*
85484 ** Invoke sqlite3AtoF() on the text value of pMem and return the
85485 ** double result. If sqlite3AtoF() returns an error code, write
85486 ** that code into *pRC if (*pRC)!=NULL.
85487 **
85488 ** The caller must ensure that pMem->db!=0 and that pMem is in
85489 ** mode MEM_Str or MEM_Blob.
85490 */
85491 SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem *pMem, int *pRC){
85492 double val = (double)0;
85493 int rc = 0;
85494 assert( pMem->db!=0 );
85495 assert( pMem->flags & (MEM_Str|MEM_Blob) );
85496 if( pMem->z==0 ){
85497 /* no-op */
85498 }else if( pMem->enc==SQLITE_UTF8
85499 && ((pMem->flags & MEM_Term)!=0 || sqlite3VdbeMemZeroTerminateIfAble(pMem))
85500 ){
85501 rc = sqlite3AtoF(pMem->z, &val);
85502 }else if( pMem->n==0 ){
85503 /* no-op */
85504 }else if( pMem->enc==SQLITE_UTF8 ){
85505 char *zCopy = sqlite3DbStrNDup(pMem->db, pMem->z, pMem->n);
85506 if( zCopy ){
85507 rc = sqlite3AtoF(zCopy, &val);
85508 sqlite3DbFree(pMem->db, zCopy);
85509 }
85510 }else{
85511 int n, i, j;
85512 char *zCopy;
85513 const char *z;
85514
85515 n = pMem->n & ~1;
85516 zCopy = sqlite3DbMallocRaw(pMem->db, n/2 + 2);
85517 if( zCopy ){
85518 z = pMem->z;
85519 if( pMem->enc==SQLITE_UTF16LE ){
85520 for(i=j=0; i<n-1; i+=2, j++){
85521 zCopy[j] = z[i];
85522 if( z[i+1]!=0 ) break;
85523 }
85524 }else{
85525 for(i=j=0; i<n-1; i+=2, j++){
85526 if( z[i]!=0 ) break;
85527 zCopy[j] = z[i+1];
85528 }
85529 }
85530 assert( j<=n/2 );
85531 zCopy[j] = 0;
85532 rc = sqlite3AtoF(zCopy, &val);
85533 if( i<n ) rc = -100;
85534 sqlite3DbFree(pMem->db, zCopy);
85535 }
85536 }
85537 if( pRC ) *pRC = rc;
85538 return val;
85539 }
85540
85541 /*
85542 ** Return the best representation of pMem that we can get into a
85543 ** double. If pMem is already a double or an integer, return its
85544 ** value. If it is a string or blob, try to convert it to a double.
85545 ** If it is a NULL, return 0.0.
85546 */
 
 
 
 
 
 
85547 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
85548 assert( pMem!=0 );
85549 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85550 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
85551 if( pMem->flags & MEM_Real ){
@@ -85325,11 +85552,11 @@
85552 return pMem->u.r;
85553 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
85554 testcase( pMem->flags & MEM_IntReal );
85555 return (double)pMem->u.i;
85556 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
85557 return sqlite3MemRealValueRC(pMem, 0);
85558 }else{
85559 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
85560 return (double)0;
85561 }
85562 }
@@ -85449,11 +85676,11 @@
85676 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
85677 int rc;
85678 sqlite3_int64 ix;
85679 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
85680 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85681 pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
85682 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
85683 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
85684 ){
85685 pMem->u.i = ix;
85686 MemSetTypeFlag(pMem, MEM_Int);
@@ -86420,11 +86647,11 @@
86647 }
86648 }
86649 if( affinity==SQLITE_AFF_BLOB ){
86650 if( op==TK_FLOAT ){
86651 assert( pVal && pVal->z && pVal->flags==(MEM_Str|MEM_Term) );
86652 sqlite3AtoF(pVal->z, &pVal->u.r);
86653 pVal->flags = MEM_Real;
86654 }else if( op==TK_INTEGER ){
86655 /* This case is required by -9223372036854775808 and other strings
86656 ** that look like integers but cannot be handled by the
86657 ** sqlite3DecOrHexToI64() call above. */
@@ -86688,10 +86915,15 @@
86915 ** the column value into *ppVal. If *ppVal is initially NULL then a new
86916 ** sqlite3_value object is allocated.
86917 **
86918 ** If *ppVal is initially NULL then the caller is responsible for
86919 ** ensuring that the value written into *ppVal is eventually freed.
86920 **
86921 ** If the buffer does not contain a well-formed record, this routine may
86922 ** read several bytes past the end of the buffer. Callers must therefore
86923 ** ensure that any buffer which may contain a corrupt record is padded
86924 ** with at least 8 bytes of addressable memory.
86925 */
86926 SQLITE_PRIVATE int sqlite3Stat4Column(
86927 sqlite3 *db, /* Database handle */
86928 const void *pRec, /* Pointer to buffer containing record */
86929 int nRec, /* Size of buffer pRec in bytes */
@@ -95661,14 +95893,13 @@
95893 ** point or exponential notation, the result is only MEM_Real, even
95894 ** if there is an exact integer representation of the quantity.
95895 */
95896 static void applyNumericAffinity(Mem *pRec, int bTryForInt){
95897 double rValue;
 
95898 int rc;
95899 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
95900 rValue = sqlite3MemRealValueRC(pRec, &rc);
95901 if( rc<=0 ) return;
95902 if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
95903 pRec->flags |= MEM_Int;
95904 }else{
95905 pRec->u.r = rValue;
@@ -95746,11 +95977,14 @@
95977 */
95978 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
95979 int eType = sqlite3_value_type(pVal);
95980 if( eType==SQLITE_TEXT ){
95981 Mem *pMem = (Mem*)pVal;
95982 assert( pMem->db!=0 );
95983 sqlite3_mutex_enter(pMem->db->mutex);
95984 applyNumericAffinity(pMem, 0);
95985 sqlite3_mutex_leave(pMem->db->mutex);
95986 eType = sqlite3_value_type(pVal);
95987 }
95988 return eType;
95989 }
95990
@@ -95779,11 +96013,11 @@
96013 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
96014 if( ExpandBlob(pMem) ){
96015 pMem->u.i = 0;
96016 return MEM_Int;
96017 }
96018 pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
96019 if( rc<=0 ){
96020 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
96021 pMem->u.i = ix;
96022 return MEM_Int;
96023 }else{
@@ -110056,11 +110290,11 @@
110290 */
110291 static int exprProbability(Expr *p){
110292 double r = -1.0;
110293 if( p->op!=TK_FLOAT ) return -1;
110294 assert( !ExprHasProperty(p, EP_IntValue) );
110295 sqlite3AtoF(p->u.zToken, &r);
110296 assert( r>=0.0 );
110297 if( r>1.0 ) return -1;
110298 return (int)(r*134217728.0);
110299 }
110300
@@ -111192,10 +111426,18 @@
111426 ** number of expressions in the select list. */
111427 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
111428 sqlite3SelectWrongNumTermsError(pParse, p->pNext);
111429 return WRC_Abort;
111430 }
111431
111432 /* If the SELECT statement contains ON clauses that were moved into
111433 ** the WHERE clause, go through and verify that none of the terms
111434 ** in the ON clauses reference tables to the right of the ON clause. */
111435 if( (p->selFlags & SF_OnToWhere) ){
111436 sqlite3SelectCheckOnClauses(pParse, p);
111437 if( pParse->nErr ) return WRC_Abort;
111438 }
111439
111440 /* Advance to the next term of the compound
111441 */
111442 p = p->pPrior;
111443 nCompound++;
@@ -114854,18 +115096,25 @@
115096 /* Could not find an existing table or index to use as the RHS b-tree.
115097 ** We will have to generate an ephemeral table to do the job.
115098 */
115099 u32 savedNQueryLoop = pParse->nQueryLoop;
115100 int rMayHaveNull = 0;
115101 int bloomOk = (inFlags & IN_INDEX_MEMBERSHIP)!=0;
115102 eType = IN_INDEX_EPH;
115103 if( inFlags & IN_INDEX_LOOP ){
115104 pParse->nQueryLoop = 0;
115105 }else if( prRhsHasNull ){
115106 *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
115107 }
115108 assert( pX->op==TK_IN );
115109 if( !bloomOk
115110 && ExprUseXSelect(pX)
115111 && (pX->x.pSelect->selFlags & SF_ClonedRhsIn)!=0
115112 ){
115113 bloomOk = 1;
115114 }
115115 sqlite3CodeRhsOfIN(pParse, pX, iTab, bloomOk);
115116 if( rMayHaveNull ){
115117 sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
115118 }
115119 pParse->nQueryLoop = savedNQueryLoop;
115120 }
@@ -115019,11 +115268,12 @@
115268 ** is used.
115269 */
115270 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
115271 Parse *pParse, /* Parsing context */
115272 Expr *pExpr, /* The IN operator */
115273 int iTab, /* Use this cursor number */
115274 int allowBloom /* True to allow the use of a Bloom filter */
115275 ){
115276 int addrOnce = 0; /* Address of the OP_Once instruction at top */
115277 int addr; /* Address of OP_OpenEphemeral instruction */
115278 Expr *pLeft; /* the LHS of the IN operator */
115279 KeyInfo *pKeyInfo = 0; /* Key information */
@@ -115141,11 +115391,14 @@
115391 int rc;
115392 int addrBloom = 0;
115393 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
115394 dest.zAffSdst = exprINAffinity(pParse, pExpr);
115395 pSelect->iLimit = 0;
115396 if( addrOnce
115397 && allowBloom
115398 && OptimizationEnabled(pParse->db, SQLITE_BloomFilter)
115399 ){
115400 int regBloom = ++pParse->nMem;
115401 addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
115402 VdbeComment((v, "Bloom filter"));
115403 dest.iSDParm2 = regBloom;
115404 }
@@ -115726,11 +115979,11 @@
115979 ** like the continuation of the number.
115980 */
115981 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
115982 if( ALWAYS(z!=0) ){
115983 double value;
115984 sqlite3AtoF(z, &value);
115985 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
115986 if( negateFlag ) value = -value;
115987 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
115988 }
115989 }
@@ -118827,11 +119080,14 @@
119080 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
119081 }
119082 if( pIEpr==0 ) break;
119083 if( NEVER(!ExprUseYTab(pExpr)) ) break;
119084 for(i=0; i<pSrcList->nSrc; i++){
119085 if( pSrcList->a[i].iCursor==pIEpr->iDataCur ){
119086 testcase( i>0 );
119087 break;
119088 }
119089 }
119090 if( i>=pSrcList->nSrc ) break;
119091 if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
119092 if( pParse->nErr ){ return WRC_Abort; }
119093
@@ -124902,11 +125158,11 @@
125158 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
125159 #endif
125160 sqlite3_mutex_enter(db->mutex);
125161 db->xAuth = (sqlite3_xauth)xAuth;
125162 db->pAuthArg = pArg;
125163 sqlite3ExpirePreparedStatements(db, 1);
125164 sqlite3_mutex_leave(db->mutex);
125165 return SQLITE_OK;
125166 }
125167
125168 /*
@@ -125573,10 +125829,11 @@
125829 SrcItem *p
125830 ){
125831 const char *zDb;
125832 if( p->fg.fixedSchema ){
125833 int iDb = sqlite3SchemaToIndex(pParse->db, p->u4.pSchema);
125834 assert( iDb>=0 && iDb<pParse->db->nDb );
125835 zDb = pParse->db->aDb[iDb].zDbSName;
125836 }else{
125837 assert( !p->fg.isSubquery );
125838 zDb = p->u4.zDatabase;
125839 }
@@ -127657,17 +127914,18 @@
127914 **
127915 ** zName is temporarily modified while this routine is running, but is
127916 ** restored to its original value prior to this routine returning.
127917 */
127918 SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
127919 const char *zTail; /* Pointer to the last "_" in zName */
127920 Table *pTab; /* Table that zName is a shadow of */
127921 char *zCopy;
127922 zTail = strrchr(zName, '_');
127923 if( zTail==0 ) return 0;
127924 zCopy = sqlite3DbStrNDup(db, zName, (int)(zTail-zName));
127925 pTab = zCopy ? sqlite3FindTable(db, zCopy, 0) : 0;
127926 sqlite3DbFree(db, zCopy);
127927 if( pTab==0 ) return 0;
127928 if( !IsVirtual(pTab) ) return 0;
127929 return sqlite3IsShadowTableOf(db, pTab, zName);
127930 }
127931 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
@@ -127816,10 +128074,11 @@
128074 }
128075 p->tabFlags |= TF_WithoutRowid | TF_NoVisibleRowid;
128076 convertToWithoutRowidTable(pParse, p);
128077 }
128078 iDb = sqlite3SchemaToIndex(db, p->pSchema);
128079 assert( iDb>=0 && iDb<=db->nDb );
128080
128081 #ifndef SQLITE_OMIT_CHECK
128082 /* Resolve names in all CHECK constraint expressions.
128083 */
128084 if( p->pCheck ){
@@ -128111,10 +128370,11 @@
128370 p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */
128371 #endif
128372
128373 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
128374 iDb = sqlite3SchemaToIndex(db, p->pSchema);
128375 assert( iDb>=0 && iDb<db->nDb );
128376 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
128377 if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
128378
128379 /* Make a copy of the entire SELECT statement that defines the view.
128380 ** This will force all the Expr.token.z values to be dynamically
@@ -129707,10 +129967,11 @@
129967 sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
129968 "or PRIMARY KEY constraint cannot be dropped", 0);
129969 goto exit_drop_index;
129970 }
129971 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
129972 assert( iDb>=0 && iDb<db->nDb );
129973 #ifndef SQLITE_OMIT_AUTHORIZATION
129974 {
129975 int code = SQLITE_DROP_INDEX;
129976 Table *pTab = pIndex->pTable;
129977 const char *zDb = db->aDb[iDb].zDbSName;
@@ -132953,11 +133214,11 @@
133214 zBuf = sqlite3_mprintf("%!.*f",(int)n,r);
133215 if( zBuf==0 ){
133216 sqlite3_result_error_nomem(context);
133217 return;
133218 }
133219 sqlite3AtoF(zBuf, &r);
133220 sqlite3_free(zBuf);
133221 }
133222 sqlite3_result_double(context, r);
133223 }
133224 #endif
@@ -133591,11 +133852,11 @@
133852 const char *zVal;
133853 r1 = sqlite3_value_double(pValue);
133854 sqlite3_str_appendf(pStr, "%!0.15g", r1);
133855 zVal = sqlite3_str_value(pStr);
133856 if( zVal ){
133857 sqlite3AtoF(zVal, &r2);
133858 if( r1!=r2 ){
133859 sqlite3_str_reset(pStr);
133860 sqlite3_str_appendf(pStr, "%!0.20e", r1);
133861 }
133862 }
@@ -133688,11 +133949,11 @@
133949 sqlite3_result_error_nomem(context);
133950 return;
133951 }
133952 i = j = 0;
133953 while( i<nIn ){
133954 const char *z = strchr(&zIn[i],'\\');
133955 if( z==0 ){
133956 n = nIn - i;
133957 memmove(&zOut[j], &zIn[i], n);
133958 j += n;
133959 break;
@@ -136859,10 +137120,11 @@
137120 /* If foreign-keys are disabled, this function is a no-op. */
137121 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
137122 if( !IsOrdinaryTable(pTab) ) return;
137123
137124 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137125 assert( iDb>=00 && iDb<db->nDb );
137126 zDb = db->aDb[iDb].zDbSName;
137127
137128 /* Loop through all the foreign key constraints for which pTab is the
137129 ** child table (the table that the foreign key definition is part of). */
137130 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
@@ -141374,10 +141636,11 @@
141636 int (*db_status64)(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);
141637 /* Version 3.52.0 and later */
141638 void (*str_truncate)(sqlite3_str*,int);
141639 void (*str_free)(sqlite3_str*);
141640 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
141641 int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
141642 };
141643
141644 /*
141645 ** This is the function signature used for all extension entry points. It
141646 ** is also defined in the file "loadext.c".
@@ -141716,10 +141979,11 @@
141979 #define sqlite3_db_status64 sqlite3_api->db_status64
141980 /* Version 3.52.0 and later */
141981 #define sqlite3_str_truncate sqlite3_api->str_truncate
141982 #define sqlite3_str_free sqlite3_api->str_free
141983 #define sqlite3_carray_bind sqlite3_api->carray_bind
141984 #define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
141985 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
141986
141987 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
141988 /* This case when the file really is being compiled as a loadable
141989 ** extension */
@@ -142247,12 +142511,14 @@
142511 sqlite3_db_status64,
142512 /* Version 3.52.0 and later */
142513 sqlite3_str_truncate,
142514 sqlite3_str_free,
142515 #ifdef SQLITE_ENABLE_CARRAY
142516 sqlite3_carray_bind,
142517 sqlite3_carray_bind_v2
142518 #else
142519 0,
142520 0
142521 #endif
142522 };
142523
142524 /* True if x is the directory separator character
@@ -148181,10 +148447,14 @@
148447 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
148448 pRight->u3.pOn = 0;
148449 pRight->fg.isOn = 1;
148450 p->selFlags |= SF_OnToWhere;
148451 }
148452
148453 if( IsVirtual(pRightTab) && joinType==EP_OuterON && pRight->u1.pFuncArg ){
148454 p->selFlags |= SF_OnToWhere;
148455 }
148456 }
148457 return 0;
148458 }
148459
148460 /*
@@ -150108,11 +150378,11 @@
150378 ** function is responsible for ensuring that this structure is eventually
150379 ** freed.
150380 */
150381 static KeyInfo *multiSelectByMergeKeyInfo(Parse *pParse, Select *p, int nExtra){
150382 ExprList *pOrderBy = p->pOrderBy;
150383 int nOrderBy = (pOrderBy!=0) ? pOrderBy->nExpr : 0;
150384 sqlite3 *db = pParse->db;
150385 KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
150386 if( pRet ){
150387 int i;
150388 for(i=0; i<nOrderBy; i++){
@@ -150911,14 +151181,12 @@
151181 ** EofB: ...
151182 ** AltB: ...
151183 ** AeqB: ...
151184 ** AgtB: ...
151185 ** Init: initialize coroutine registers
151186 ** yield coA, on eof goto EofA
151187 ** yield coB, on eof goto EofB
 
 
151188 ** Cmpr: Compare A, B
151189 ** Jump AltB, AeqB, AgtB
151190 ** End: ...
151191 **
151192 ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
@@ -151006,30 +151274,33 @@
151274 }
151275 }
151276 }
151277
151278 /* Compute the comparison permutation and keyinfo that is used with
151279 ** the permutation to determine if the next row of results comes
151280 ** from selectA or selectB. Also add literal collations to the
151281 ** ORDER BY clause terms so that when selectA and selectB are
151282 ** evaluated, they use the correct collation.
 
151283 */
151284 aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1));
151285 if( aPermute ){
151286 struct ExprList_item *pItem;
151287 int bKeep = 0;
151288 aPermute[0] = nOrderBy;
151289 for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
151290 assert( pItem!=0 );
151291 assert( pItem->u.x.iOrderByCol>0 );
151292 assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr );
151293 aPermute[i] = pItem->u.x.iOrderByCol - 1;
151294 if( aPermute[i]!=(u32)i-1 ) bKeep = 1;
151295 }
151296 if( bKeep==0 ){
151297 sqlite3DbFreeNN(db, aPermute);
151298 aPermute = 0;
151299 }
151300 }
151301 pKeyMerge = multiSelectByMergeKeyInfo(pParse, p, 1);
151302
151303 /* Allocate a range of temporary registers and the KeyInfo needed
151304 ** for the logic that removes duplicate result rows when the
151305 ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
151306 */
@@ -151104,11 +151375,11 @@
151375 /* Generate a coroutine to evaluate the SELECT statement to the
151376 ** left of the compound operator - the "A" select.
151377 */
151378 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
151379 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
151380 VdbeComment((v, "SUBR: next-A"));
151381 pPrior->iLimit = regLimitA;
151382 ExplainQueryPlan((pParse, 1, "LEFT"));
151383 sqlite3Select(pParse, pPrior, &destA);
151384 sqlite3VdbeEndCoroutine(v, regAddrA);
151385 sqlite3VdbeJumpHere(v, addr1);
@@ -151116,11 +151387,11 @@
151387 /* Generate a coroutine to evaluate the SELECT statement on
151388 ** the right - the "B" select
151389 */
151390 addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
151391 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
151392 VdbeComment((v, "SUBR: next-B"));
151393 savedLimit = p->iLimit;
151394 savedOffset = p->iOffset;
151395 p->iLimit = regLimitB;
151396 p->iOffset = 0;
151397 ExplainQueryPlan((pParse, 1, "RIGHT"));
@@ -151130,20 +151401,20 @@
151401 sqlite3VdbeEndCoroutine(v, regAddrB);
151402
151403 /* Generate a subroutine that outputs the current row of the A
151404 ** select as the next output row of the compound select.
151405 */
151406 VdbeNoopComment((v, "SUBR: out-A"));
151407 addrOutA = generateOutputSubroutine(pParse,
151408 p, &destA, pDest, regOutA,
151409 regPrev, pKeyDup, labelEnd);
151410
151411 /* Generate a subroutine that outputs the current row of the B
151412 ** select as the next output row of the compound select.
151413 */
151414 if( op==TK_ALL || op==TK_UNION ){
151415 VdbeNoopComment((v, "SUBR: out-B"));
151416 addrOutB = generateOutputSubroutine(pParse,
151417 p, &destB, pDest, regOutB,
151418 regPrev, pKeyDup, labelEnd);
151419 }
151420 sqlite3KeyInfoUnref(pKeyDup);
@@ -151152,14 +151423,16 @@
151423 ** are exhausted and only data in select B remains.
151424 */
151425 if( op==TK_EXCEPT || op==TK_INTERSECT ){
151426 addrEofA_noB = addrEofA = labelEnd;
151427 }else{
151428 VdbeNoopComment((v, "SUBR: eof-A"));
151429 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
151430 VdbeComment((v, "out-B"));
151431 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
151432 VdbeCoverage(v);
151433 VdbeComment((v, "next-B"));
151434 sqlite3VdbeGoto(v, addrEofA);
151435 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
151436 }
151437
151438 /* Generate a subroutine to run when the results from select B
@@ -151167,21 +151440,24 @@
151440 */
151441 if( op==TK_INTERSECT ){
151442 addrEofB = addrEofA;
151443 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
151444 }else{
151445 VdbeNoopComment((v, "SUBR: eof-B"));
151446 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
151447 VdbeComment((v, "out-A"));
151448 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
151449 VdbeComment((v, "next-A"));
151450 sqlite3VdbeGoto(v, addrEofB);
151451 }
151452
151453 /* Generate code to handle the case of A<B
151454 */
 
151455 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
151456 VdbeComment((v, "out-A"));
151457 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
151458 VdbeComment((v, "next-A"));
151459 sqlite3VdbeGoto(v, labelCmpr);
151460
151461 /* Generate code to handle the case of A==B
151462 */
151463 if( op==TK_ALL ){
@@ -151188,40 +151464,52 @@
151464 addrAeqB = addrAltB;
151465 }else if( op==TK_INTERSECT ){
151466 addrAeqB = addrAltB;
151467 addrAltB++;
151468 }else{
151469 addrAeqB = addrAltB + 1;
 
 
 
151470 }
151471
151472 /* Generate code to handle the case of A>B
151473 */
 
151474 addrAgtB = sqlite3VdbeCurrentAddr(v);
151475 if( op==TK_ALL || op==TK_UNION ){
151476 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
151477 VdbeComment((v, "out-B"));
151478 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
151479 VdbeComment((v, "next-B"));
151480 sqlite3VdbeGoto(v, labelCmpr);
151481 }else{
151482 addrAgtB++; /* Just do next-B. Might as well use the next-B call
151483 ** in the next code block */
151484 }
 
 
151485
151486 /* This code runs once to initialize everything.
151487 */
151488 sqlite3VdbeJumpHere(v, addr1);
151489 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
151490 VdbeComment((v, "next-A"));
151491 /* v--- Also the A>B case for EXCEPT and INTERSECT */
151492 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
151493 VdbeComment((v, "next-B"));
151494
151495 /* Implement the main merge loop
151496 */
151497 if( aPermute!=0 ){
151498 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
151499 }
151500 sqlite3VdbeResolveLabel(v, labelCmpr);
 
151501 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
151502 (char*)pKeyMerge, P4_KEYINFO);
151503 if( aPermute!=0 ){
151504 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
151505 }
151506 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
151507 VdbeCoverageIf(v, op==TK_ALL);
151508 VdbeCoverageIf(v, op==TK_UNION);
151509 VdbeCoverageIf(v, op==TK_EXCEPT);
151510 VdbeCoverageIf(v, op==TK_INTERSECT);
151511
151512 /* Jump to the this point in order to terminate the query.
151513 */
151514 sqlite3VdbeResolveLabel(v, labelEnd);
151515
@@ -152774,10 +153062,20 @@
153062 x.isOuterJoin = 0;
153063 x.nSelDepth = 0;
153064 x.pEList = pSubq->pEList;
153065 x.pCList = findLeftmostExprlist(pSubq);
153066 pNew = substExpr(&x, pNew);
153067 assert( pNew!=0 || pParse->nErr!=0 );
153068 if( pParse->nErr==0 && pNew->op==TK_IN && ExprUseXSelect(pNew) ){
153069 assert( pNew->x.pSelect!=0 );
153070 pNew->x.pSelect->selFlags |= SF_ClonedRhsIn;
153071 assert( pWhere!=0 );
153072 assert( pWhere->op==TK_IN );
153073 assert( ExprUseXSelect(pWhere) );
153074 assert( pWhere->x.pSelect!=0 );
153075 pWhere->x.pSelect->selFlags |= SF_ClonedRhsIn;
153076 }
153077 #ifndef SQLITE_OMIT_WINDOWFUNC
153078 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
153079 /* Restriction 6c has prevented push-down in this case */
153080 sqlite3ExprDelete(pParse->db, pNew);
153081 nChng--;
@@ -154892,10 +155190,11 @@
155190 */
155191 typedef struct CheckOnCtx CheckOnCtx;
155192 struct CheckOnCtx {
155193 SrcList *pSrc; /* SrcList for this context */
155194 int iJoin; /* Cursor numbers must be =< than this */
155195 int bFuncArg; /* True for table-function arg */
155196 CheckOnCtx *pParent; /* Parent context */
155197 };
155198
155199 /*
155200 ** True if the SrcList passed as the only argument contains at least
@@ -154943,11 +155242,13 @@
155242 SrcList *pSrc = pCtx->pSrc;
155243 int iTab = pExpr->iTable;
155244 if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){
155245 if( pCtx->iJoin && iTab>pCtx->iJoin ){
155246 sqlite3ErrorMsg(pWalker->pParse,
155247 "%s references tables to its right",
155248 (pCtx->bFuncArg ? "table-function argument" : "ON clause")
155249 );
155250 return WRC_Abort;
155251 }
155252 break;
155253 }
155254 pCtx = pCtx->pParent;
@@ -154978,24 +155279,39 @@
155279
155280 /*
155281 ** Check all ON clauses in pSelect to verify that they do not reference
155282 ** columns to the right.
155283 */
155284 SQLITE_PRIVATE void sqlite3SelectCheckOnClauses(Parse *pParse, Select *pSelect){
155285 Walker w;
155286 CheckOnCtx sCtx;
155287 int ii;
155288 assert( pSelect->selFlags & SF_OnToWhere );
155289 assert( pSelect->pSrc!=0 && pSelect->pSrc->nSrc>=2 );
155290 memset(&w, 0, sizeof(w));
155291 w.pParse = pParse;
155292 w.xExprCallback = selectCheckOnClausesExpr;
155293 w.xSelectCallback = selectCheckOnClausesSelect;
155294 w.u.pCheckOnCtx = &sCtx;
155295 memset(&sCtx, 0, sizeof(sCtx));
155296 sCtx.pSrc = pSelect->pSrc;
155297 sqlite3WalkExpr(&w, pSelect->pWhere);
155298 pSelect->selFlags &= ~SF_OnToWhere;
155299
155300 /* Check for any table-function args that are attached to virtual tables
155301 ** on the RHS of an outer join. They are subject to the same constraints
155302 ** as ON clauses. */
155303 sCtx.bFuncArg = 1;
155304 for(ii=0; ii<pSelect->pSrc->nSrc; ii++){
155305 SrcItem *pItem = &pSelect->pSrc->a[ii];
155306 if( pItem->fg.isTabFunc
155307 && (pItem->fg.jointype & JT_OUTER)
155308 ){
155309 sCtx.iJoin = pItem->iCursor;
155310 sqlite3WalkExprList(&w, pItem->u1.pFuncArg);
155311 }
155312 }
155313 }
155314
155315 /*
155316 ** If p2 exists and p1 and p2 have the same number of terms, then change
155317 ** every term of p1 to have the same sort order as p2 and return true.
@@ -155143,22 +155459,10 @@
155459 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
155460 sqlite3TreeViewSelect(0, p, 0);
155461 }
155462 #endif
155463
 
 
 
 
 
 
 
 
 
 
 
 
155464 /* If the SF_UFSrcCheck flag is set, then this function is being called
155465 ** as part of populating the temp table for an UPDATE...FROM statement.
155466 ** In this case, it is an error if the target object (pSrc->a[0]) name
155467 ** or alias is duplicated within FROM clause (pSrc->a[1..n]).
155468 **
@@ -157006,10 +157310,11 @@
157310
157311 pParse->pNewTrigger = 0;
157312 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
157313 zName = pTrig->zName;
157314 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
157315 assert( iDb>=00 && iDb<db->nDb );
157316 pTrig->step_list = pStepList;
157317 while( pStepList ){
157318 pStepList->pTrig = pTrig;
157319 pStepList = pStepList->pNext;
157320 }
@@ -163989,11 +164294,11 @@
164294 if( NEVER(pTerm==0) ) continue;
164295 if( pTerm->eOperator & WO_IN ){
164296 if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
164297 int iTab = pParse->nTab++;
164298 int iCache = ++pParse->nMem;
164299 sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab, 0);
164300 sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
164301 }else{
164302 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
164303 addrNotFound = pLevel->addrNxt;
164304 }
@@ -165648,17 +165953,18 @@
165953 && ALWAYS(pLeft->y.pTab)
165954 && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
165955 ){
165956 int isNum;
165957 double rDummy;
165958 assert( zNew[iTo]==0 );
165959 isNum = sqlite3AtoF(zNew, &rDummy);
165960 if( isNum<=0 ){
165961 if( iTo==1 && zNew[0]=='-' ){
165962 isNum = +1;
165963 }else{
165964 zNew[iTo-1]++;
165965 isNum = sqlite3AtoF(zNew, &rDummy);
165966 zNew[iTo-1]--;
165967 }
165968 }
165969 if( isNum>0 ){
165970 sqlite3ExprDelete(db, pPrefix);
@@ -165697,10 +166003,38 @@
166003 sqlite3ValueFree(pVal);
166004 return rc;
166005 }
166006 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
166007
166008 /*
166009 ** If pExpr is one of "like", "glob", "match", or "regexp", then
166010 ** return the corresponding SQLITE_INDEX_CONSTRAINT_xxxx value.
166011 ** If not, return 0.
166012 **
166013 ** pExpr is guaranteed to be a TK_FUNCTION.
166014 */
166015 SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr *pExpr){
166016 static const struct {
166017 const char *zOp;
166018 unsigned char eOp;
166019 } aOp[] = {
166020 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
166021 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
166022 { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
166023 { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
166024 };
166025 int i;
166026 assert( pExpr->op==TK_FUNCTION );
166027 assert( !ExprHasProperty(pExpr, EP_IntValue) );
166028 for(i=0; i<ArraySize(aOp); i++){
166029 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
166030 return aOp[i].eOp;
166031 }
166032 }
166033 return 0;
166034 }
166035
166036
166037 #ifndef SQLITE_OMIT_VIRTUALTABLE
166038 /*
166039 ** Check to see if the pExpr expression is a form that needs to be passed
166040 ** to the xBestIndex method of virtual tables. Forms of interest include:
@@ -165733,19 +166067,10 @@
166067 unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
166068 Expr **ppLeft, /* Column expression to left of MATCH/op2 */
166069 Expr **ppRight /* Expression to left of MATCH/op2 */
166070 ){
166071 if( pExpr->op==TK_FUNCTION ){
 
 
 
 
 
 
 
 
 
166072 ExprList *pList;
166073 Expr *pCol; /* Column reference */
166074 int i;
166075
166076 assert( ExprUseXList(pExpr) );
@@ -165761,20 +166086,15 @@
166086 ** vtab_column MATCH expression
166087 ** MATCH(expression,vtab_column)
166088 */
166089 pCol = pList->a[1].pExpr;
166090 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
166091 if( ExprIsVtab(pCol) && (i = sqlite3ExprIsLikeOperator(pExpr))!=0 ){
166092 *peOp2 = i;
166093 *ppRight = pList->a[0].pExpr;
166094 *ppLeft = pCol;
166095 return 1;
 
 
 
 
 
166096 }
166097
166098 /* We can also match against the first column of overloaded
166099 ** functions where xFindFunction returns a value of at least
166100 ** SQLITE_INDEX_CONSTRAINT_FUNCTION.
@@ -170218,10 +170538,71 @@
170538 p->u.btree.pIndex = 0;
170539 }
170540 }
170541 return rc;
170542 }
170543
170544 /*
170545 ** Callback for estLikePatternLength().
170546 **
170547 ** If this node is a string literal that is longer pWalker->sz, then set
170548 ** pWalker->sz to the byte length of that string literal.
170549 **
170550 ** pWalker->eCode indicates how to count characters:
170551 **
170552 ** eCode==0 Count as a GLOB pattern
170553 ** eCode==1 Count as a LIKE pattern
170554 */
170555 static int exprNodePatternLengthEst(Walker *pWalker, Expr *pExpr){
170556 if( pExpr->op==TK_STRING ){
170557 int sz = 0; /* Pattern size in bytes */
170558 u8 *z = (u8*)pExpr->u.zToken; /* The pattern */
170559 u8 c; /* Next character of the pattern */
170560 u8 c1, c2, c3; /* Wildcards */
170561 if( pWalker->eCode ){
170562 c1 = '%';
170563 c2 = '_';
170564 c3 = 0;
170565 }else{
170566 c1 = '*';
170567 c2 = '?';
170568 c3 = '[';
170569 }
170570 while( (c = *(z++))!=0 ){
170571 if( c==c3 ){
170572 if( *z ) z++;
170573 while( *z && *z!=']' ) z++;
170574 }else if( c!=c1 && c!=c2 ){
170575 sz++;
170576 }
170577 }
170578 if( sz>pWalker->u.sz ) pWalker->u.sz = sz;
170579 }
170580 return WRC_Continue;
170581 }
170582
170583 /*
170584 ** Return the length of the longest string literal in the given
170585 ** expression.
170586 **
170587 ** eCode indicates how to count characters:
170588 **
170589 ** eCode==0 Count as a GLOB pattern
170590 ** eCode==1 Count as a LIKE pattern
170591 */
170592 static int estLikePatternLength(Expr *p, u16 eCode){
170593 Walker w;
170594 w.u.sz = 0;
170595 w.eCode = eCode;
170596 w.xExprCallback = exprNodePatternLengthEst;
170597 w.xSelectCallback = sqlite3SelectWalkFail;
170598 #ifdef SQLITE_DEBUG
170599 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
170600 #endif
170601 sqlite3WalkExpr(&w, p);
170602 return w.u.sz;
170603 }
170604
170605 /*
170606 ** Adjust the WhereLoop.nOut value downward to account for terms of the
170607 ** WHERE clause that reference the loop but which are not used by an
170608 ** index.
@@ -170247,10 +170628,17 @@
170628 ** of rows in the table. In other words, assume that x==EXPR will filter
170629 ** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
170630 ** "x" column is boolean or else -1 or 0 or 1 is a common default value
170631 ** on the "x" column and so in that case only cap the output row estimate
170632 ** at 1/2 instead of 1/4.
170633 **
170634 ** Heuristic 3: If there is a LIKE or GLOB (or REGEXP or MATCH) operator
170635 ** with a large constant pattern, then reduce the size of the search
170636 ** space according to the length of the pattern, under the theory that
170637 ** longer patterns are less likely to match. This heuristic was added
170638 ** to give better output-row count estimates when preparing queries for
170639 ** the Join-Order Benchmarks. See forum thread 2026-01-30T09:57:54z
170640 */
170641 static void whereLoopOutputAdjust(
170642 WhereClause *pWC, /* The WHERE clause */
170643 WhereLoop *pLoop, /* The loop to adjust downward */
170644 LogEst nRow /* Number of rows in the entire table */
@@ -170296,25 +170684,43 @@
170684 ** then use the probability provided by the application. */
170685 pLoop->nOut += pTerm->truthProb;
170686 }else{
170687 /* In the absence of explicit truth probabilities, use heuristics to
170688 ** guess a reasonable truth probability. */
170689 Expr *pOpExpr = pTerm->pExpr;
170690 pLoop->nOut--;
170691 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
170692 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
170693 ){
170694 Expr *pRight = pOpExpr->pRight;
170695 int k = 0;
170696 testcase( pOpExpr->op==TK_IS );
170697 if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
170698 k = 10;
170699 }else{
170700 k = 20;
170701 }
170702 if( iReduce<k ){
170703 pTerm->wtFlags |= TERM_HEURTRUTH;
170704 iReduce = k;
170705 }
170706 }else
170707 if( ExprHasProperty(pOpExpr, EP_InfixFunc)
170708 && pOpExpr->op==TK_FUNCTION
170709 ){
170710 int eOp;
170711 assert( ExprUseXList(pOpExpr) );
170712 assert( pOpExpr->x.pList->nExpr>=2 );
170713 eOp = sqlite3ExprIsLikeOperator(pOpExpr);
170714 if( ALWAYS(eOp>0) ){
170715 int szPattern;
170716 Expr *pRHS = pOpExpr->x.pList->a[0].pExpr;
170717 eOp = eOp==SQLITE_INDEX_CONSTRAINT_LIKE;
170718 szPattern = estLikePatternLength(pRHS, eOp);
170719 if( szPattern>0 ){
170720 pLoop->nOut -= szPattern*2;
170721 }
170722 }
170723 }
170724 }
170725 }
170726 }
@@ -172136,11 +172542,11 @@
172542 SrcItem *pItem;
172543 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
172544 sqlite3 *db = pWInfo->pParse->db;
172545 int rc = SQLITE_OK;
172546 int bFirstPastRJ = 0;
172547 int hasRightCrossJoin = 0;
172548 WhereLoop *pNew;
172549
172550
172551 /* Loop over the tables in the join, from left to right */
172552 pNew = pBuilder->pNew;
@@ -172163,16 +172569,24 @@
172569 /* Add prerequisites to prevent reordering of FROM clause terms
172570 ** across CROSS joins and outer joins. The bFirstPastRJ boolean
172571 ** prevents the right operand of a RIGHT JOIN from being swapped with
172572 ** other elements even further to the right.
172573 **
172574 ** The hasRightCrossJoin flag prevent FROM-clause terms from moving
172575 ** from the right side of a LEFT JOIN or CROSS JOIN over to the
172576 ** left side of that same join. This is a required restriction in
172577 ** the case of LEFT JOIN - an incorrect answer may results if it is
172578 ** not enforced. This restriction is not required for CROSS JOIN.
172579 ** It is provided merely as a means of controlling join order, under
172580 ** the theory that no real-world queries that care about performance
172581 ** actually use the CROSS JOIN syntax.
172582 */
172583 if( pItem->fg.jointype & (JT_LTORJ|JT_CROSS) ){
172584 testcase( pItem->fg.jointype & JT_LTORJ );
172585 testcase( pItem->fg.jointype & JT_CROSS );
172586 hasRightCrossJoin = 1;
172587 }
172588 mPrereq |= mPrior;
172589 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
172590 }else if( pItem->fg.fromExists ){
172591 /* joins that result from the EXISTS-to-JOIN optimization should not
172592 ** be moved to the left of any of their dependencies */
@@ -172182,11 +172596,11 @@
172596 for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){
172597 if( (pNew->maskSelf & pTerm->prereqAll)!=0 ){
172598 mPrereq |= (pTerm->prereqAll & (pNew->maskSelf-1));
172599 }
172600 }
172601 }else if( !hasRightCrossJoin ){
172602 mPrereq = 0;
172603 }
172604 #ifndef SQLITE_OMIT_VIRTUALTABLE
172605 if( IsVirtual(pItem->pSTab) ){
172606 SrcItem *p;
@@ -172781,16 +173195,25 @@
173195 **
173196 ** 18 for star queries
173197 ** 12 otherwise
173198 **
173199 ** For the purposes of this heuristic, a star-query is defined as a query
173200 ** with a central "fact" table that is joined against multiple
173201 ** "dimension" tables, subject to the following constraints:
173202 **
173203 ** (aa) Only a five-way or larger join is considered for this
173204 ** optimization. If there are fewer than four terms in the FROM
173205 ** clause, this heuristic does not apply.
173206 **
173207 ** (bb) The join between the fact table and the dimension tables must
173208 ** be an INNER join. CROSS and OUTER JOINs do not qualify.
173209 **
173210 ** (cc) A table must have 3 or more dimension tables in order to be
173211 ** considered a fact table. (Was 4 prior to 2026-02-10.)
173212 **
173213 ** (dd) A table that is a self-join cannot be a dimension table.
173214 ** Dimension tables are joined against fact tables.
173215 **
173216 ** SIDE EFFECT: (and really the whole point of this subroutine)
173217 **
173218 ** If pWInfo describes a star-query, then the cost for SCANs of dimension
173219 ** WhereLoops is increased to be slightly larger than the cost of a SCAN
@@ -172839,11 +173262,11 @@
173262 assert( pWLoop->maskSelf==MASKBIT(pWLoop->iTab) );
173263 assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
173264 }
173265 #endif /* SQLITE_DEBUG */
173266
173267 if( nLoop>=4 /* Constraint (aa) */
173268 && !pWInfo->bStarDone
173269 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_StarQuery)
173270 ){
173271 SrcItem *aFromTabs; /* All terms of the FROM clause */
173272 int iFromIdx; /* Term of FROM clause is the candidate fact-table */
@@ -172851,11 +173274,11 @@
173274 Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
173275 WhereLoop *pStart; /* Where to start searching for dimension-tables */
173276
173277 pWInfo->bStarDone = 1; /* Only do this computation once */
173278
173279 /* Look for fact tables with three or more dimensions where the
173280 ** dimension tables are not separately from the fact tables by an outer
173281 ** or cross join. Adjust cost weights if found.
173282 */
173283 assert( !pWInfo->bStarUsed );
173284 aFromTabs = pWInfo->pTabList->a;
@@ -172868,22 +173291,21 @@
173291
173292 pFactTab = aFromTabs + iFromIdx;
173293 if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
173294 /* If the candidate fact-table is the right table of an outer join
173295 ** restrict the search for dimension-tables to be tables to the right
173296 ** of the fact-table. Constraint (bb) */
173297 if( iFromIdx+3 > nLoop ){
173298 break; /* ^-- Impossible to reach nDep>=2 - Constraint (cc) */
173299 }
173300 while( pStart && pStart->iTab<=iFromIdx ){
173301 pStart = pStart->pNextLoop;
173302 }
173303 }
173304 for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
173305 if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
173306 break; /* Constraint (bb) */
 
 
 
173307 }
173308 if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
173309 && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
173310 && (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
173311 ){
@@ -172893,11 +173315,13 @@
173315 nDep++;
173316 mSeen |= pWLoop->maskSelf;
173317 }
173318 }
173319 }
173320 if( nDep<=2 ){
173321 continue; /* Constraint (cc) */
173322 }
173323
173324 /* If we reach this point, it means that pFactTab is a fact table
173325 ** with four or more dimensions connected by inner joins. Proceed
173326 ** to make cost adjustments. */
173327
@@ -172906,10 +173330,27 @@
173330 if( !pWInfo->bStarUsed ){
173331 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
173332 pWLoop->rStarDelta = 0;
173333 }
173334 }
173335 #endif
173336 #ifdef WHERETRACE_ENABLED /* 0x80000 */
173337 if( sqlite3WhereTrace & 0x80000 ){
173338 Bitmask mShow = mSeen;
173339 sqlite3DebugPrintf("Fact table %s(%d), dimensions:",
173340 pFactTab->zAlias ? pFactTab->zAlias : pFactTab->pSTab->zName,
173341 iFromIdx);
173342 for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
173343 if( mShow & pWLoop->maskSelf ){
173344 SrcItem *pDim = aFromTabs + pWLoop->iTab;
173345 mShow &= ~pWLoop->maskSelf;
173346 sqlite3DebugPrintf(" %s(%d)",
173347 pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, pWLoop->iTab);
173348 }
173349 }
173350 sqlite3DebugPrintf("\n");
173351 }
173352 #endif
173353 pWInfo->bStarUsed = 1;
173354
173355 /* Compute the maximum cost of any WhereLoop for the
173356 ** fact table plus one epsilon */
@@ -172929,14 +173370,12 @@
173370 if( pWLoop->rRun<mxRun ){
173371 #ifdef WHERETRACE_ENABLED /* 0x80000 */
173372 if( sqlite3WhereTrace & 0x80000 ){
173373 SrcItem *pDim = aFromTabs + pWLoop->iTab;
173374 sqlite3DebugPrintf(
173375 "Increase SCAN cost of %s to %d\n",
173376 pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, mxRun
 
 
173377 );
173378 }
173379 pWLoop->rStarDelta = mxRun - pWLoop->rRun;
173380 #endif /* WHERETRACE_ENABLED */
173381 pWLoop->rRun = mxRun;
@@ -214034,32 +214473,36 @@
214473 jsonParseReset(&v);
214474 jsonParseReset(&ix);
214475 return rc;
214476 }
214477 }else if( zPath[0]=='[' ){
214478 u64 kk = 0;
214479 x = pParse->aBlob[iRoot] & 0x0f;
214480 if( x!=JSONB_ARRAY ) return JSON_LOOKUP_NOTFOUND;
214481 n = jsonbPayloadSize(pParse, iRoot, &sz);
 
214482 i = 1;
214483 while( sqlite3Isdigit(zPath[i]) ){
214484 if( kk<0xffffffff ) kk = kk*10 + zPath[i] - '0';
214485 /* ^^^^^^^^^^--- Allow kk to be bigger than any JSON array so that
214486 ** we get NOTFOUND instead of PATHERROR, without overflowing kk. */
214487 i++;
214488 }
214489 if( i<2 || zPath[i]!=']' ){
214490 if( zPath[1]=='#' ){
214491 kk = jsonbArrayCount(pParse, iRoot);
214492 i = 2;
214493 if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){
214494 u64 nn = 0;
214495 i = 3;
214496 do{
214497 if( nn<0xffffffff ) nn = nn*10 + zPath[i] - '0';
214498 /* ^^^^^^^^^^--- Allow nn to be bigger than any JSON array to
214499 ** get NOTFOUND instead of PATHERROR, without overflowing nn. */
214500 i++;
214501 }while( sqlite3Isdigit(zPath[i]) );
214502 if( nn>kk ) return JSON_LOOKUP_NOTFOUND;
214503 kk -= nn;
214504 }
214505 if( zPath[i]!=']' ){
214506 return JSON_LOOKUP_PATHERROR;
214507 }
214508 }else{
@@ -214067,22 +214510,22 @@
214510 }
214511 }
214512 j = iRoot+n;
214513 iEnd = j+sz;
214514 while( j<iEnd ){
214515 if( kk==0 ){
214516 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
214517 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
214518 return rc;
214519 }
214520 kk--;
214521 n = jsonbPayloadSize(pParse, j, &sz);
214522 if( n==0 ) return JSON_LOOKUP_ERROR;
214523 j += n+sz;
214524 }
214525 if( j>iEnd ) return JSON_LOOKUP_ERROR;
214526 if( kk>0 ) return JSON_LOOKUP_NOTFOUND;
214527 if( pParse->eEdit>=JEDIT_INS ){
214528 JsonParse v;
214529 testcase( pParse->eEdit==JEDIT_INS );
214530 testcase( pParse->eEdit==JEDIT_AINS );
214531 testcase( pParse->eEdit==JEDIT_SET );
@@ -214220,11 +214663,11 @@
214663 char *z;
214664 if( sz==0 ) goto returnfromblob_malformed;
214665 to_double:
214666 z = sqlite3DbStrNDup(db, (const char*)&pParse->aBlob[i+n], (int)sz);
214667 if( z==0 ) goto returnfromblob_oom;
214668 rc = sqlite3AtoF(z, &r);
214669 sqlite3DbFree(db, z);
214670 if( rc<=0 ) goto returnfromblob_malformed;
214671 sqlite3_result_double(pCtx, r);
214672 break;
214673 }
@@ -221099,11 +221542,11 @@
221542 if( pVal ){
221543 #ifdef SQLITE_AMALGAMATION
221544 /* The sqlite3AtoF() routine is much much faster than atof(), if it
221545 ** is available */
221546 double r;
221547 (void)sqlite3AtoF((const char*)p->z, &r);
221548 *pVal = r;
221549 #else
221550 *pVal = (GeoCoord)atof((const char*)p->z);
221551 #endif
221552 }
@@ -231358,10 +231801,11 @@
231801 struct carray_bind {
231802 void *aData; /* The data */
231803 int nData; /* Number of elements */
231804 int mFlags; /* Control flags */
231805 void (*xDel)(void*); /* Destructor for aData */
231806 void *pDel; /* Alternative argument to xDel() */
231807 };
231808
231809
231810 /* carray_cursor is a subclass of sqlite3_vtab_cursor which will
231811 ** serve as the underlying representation of a cursor that scans
@@ -231690,26 +232134,38 @@
232134 ** Destructor for the carray_bind object
232135 */
232136 static void carrayBindDel(void *pPtr){
232137 carray_bind *p = (carray_bind*)pPtr;
232138 if( p->xDel!=SQLITE_STATIC ){
232139 p->xDel(p->pDel);
232140 }
232141 sqlite3_free(p);
232142 }
232143
232144 /*
232145 ** Invoke this interface in order to bind to the single-argument
232146 ** version of CARRAY().
232147 **
232148 ** pStmt The prepared statement to which to bind
232149 ** idx The index of the parameter of pStmt to which to bind
232150 ** aData The data to be bound
232151 ** nData The number of elements in aData
232152 ** mFlags One of SQLITE_CARRAY_xxxx indicating datatype of aData
232153 ** xDestroy Destructor for pDestroy or aData if pDestroy==NULL.
232154 ** pDestroy Invoke xDestroy on this pointer if not NULL
232155 **
232156 ** The destructor is called pDestroy if pDestroy!=NULL, or against
232157 ** aData if pDestroy==NULL.
232158 */
232159 SQLITE_API int sqlite3_carray_bind_v2(
232160 sqlite3_stmt *pStmt,
232161 int idx,
232162 void *aData,
232163 int nData,
232164 int mFlags,
232165 void (*xDestroy)(void*),
232166 void *pDestroy
232167 ){
232168 carray_bind *pNew = 0;
232169 int i;
232170 int rc = SQLITE_OK;
232171
@@ -231782,23 +232238,41 @@
232238 }
232239 }else{
232240 memcpy(pNew->aData, aData, sz);
232241 }
232242 pNew->xDel = sqlite3_free;
232243 pNew->pDel = pNew->aData;
232244 }else{
232245 pNew->aData = aData;
232246 pNew->xDel = xDestroy;
232247 pNew->pDel = pDestroy;
232248 }
232249 return sqlite3_bind_pointer(pStmt, idx, pNew, "carray-bind", carrayBindDel);
232250
232251 carray_bind_error:
232252 if( xDestroy!=SQLITE_STATIC && xDestroy!=SQLITE_TRANSIENT ){
232253 xDestroy(pDestroy);
232254 }
232255 sqlite3_free(pNew);
232256 return rc;
232257 }
232258
232259 /*
232260 ** Invoke this interface in order to bind to the single-argument
232261 ** version of CARRAY(). Same as sqlite3_carray_bind_v2() with the
232262 ** pDestroy parameter set to NULL.
232263 */
232264 SQLITE_API int sqlite3_carray_bind(
232265 sqlite3_stmt *pStmt,
232266 int idx,
232267 void *aData,
232268 int nData,
232269 int mFlags,
232270 void (*xDestroy)(void*)
232271 ){
232272 return sqlite3_carray_bind_v2(pStmt,idx,aData,nData,mFlags,xDestroy,aData);
232273 }
232274
232275 /*
232276 ** Invoke this routine to register the carray() function.
232277 */
232278 SQLITE_PRIVATE Module *sqlite3CarrayRegister(sqlite3 *db){
@@ -232157,10 +232631,24 @@
232631 ** bytes read.
232632 */
232633 static int sessionVarintGet(const u8 *aBuf, int *piVal){
232634 return getVarint32(aBuf, *piVal);
232635 }
232636
232637 /*
232638 ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal.
232639 ** Return the number of bytes read.
232640 */
232641 static int sessionVarintGetSafe(const u8 *aBuf, int nBuf, int *piVal){
232642 u8 aCopy[5];
232643 const u8 *aRead = aBuf;
232644 if( nBuf<5 ){
232645 memcpy(aCopy, aBuf, nBuf);
232646 aRead = aCopy;
232647 }
232648 return getVarint32(aRead, *piVal);
232649 }
232650
232651 /* Load an unaligned and unsigned 32-bit integer */
232652 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
232653
232654 /*
@@ -235370,11 +235858,12 @@
235858
235859 if( rc==SQLITE_OK ){
235860 u8 *aVal = &pIn->aData[pIn->iNext];
235861 if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
235862 int nByte;
235863 int nRem = pIn->nData - pIn->iNext;
235864 pIn->iNext += sessionVarintGetSafe(aVal, nRem, &nByte);
235865 rc = sessionInputBuffer(pIn, nByte);
235866 if( rc==SQLITE_OK ){
235867 if( nByte<0 || nByte>pIn->nData-pIn->iNext ){
235868 rc = SQLITE_CORRUPT_BKPT;
235869 }else{
@@ -235423,11 +235912,12 @@
235912 int nCol = 0;
235913 int nRead = 0;
235914
235915 rc = sessionInputBuffer(pIn, 9);
235916 if( rc==SQLITE_OK ){
235917 int nBuf = pIn->nData - pIn->iNext;
235918 nRead += sessionVarintGetSafe(&pIn->aData[pIn->iNext], nBuf, &nCol);
235919 /* The hard upper limit for the number of columns in an SQLite
235920 ** database table is, according to sqliteLimit.h, 32676. So
235921 ** consider any table-header that purports to have more than 65536
235922 ** columns to be corrupt. This is convenient because otherwise,
235923 ** if the (nCol>65536) condition below were omitted, a sufficiently
@@ -235583,14 +236073,14 @@
236073 sqlite3ValueFree(p->apValue[i]);
236074 }
236075 memset(p->apValue, 0, sizeof(sqlite3_value*)*p->nCol*2);
236076 }
236077
236078 /* Make sure the buffer contains at least 2 bytes of input data, or all
236079 ** remaining data if there are less than 2 bytes available. This is
236080 ** sufficient either for the 'T' or 'P' byte that begins a new table,
236081 ** or for the "op" and "bIndirect" single bytes otherwise. */
236082 p->rc = sessionInputBuffer(&p->in, 2);
236083 if( p->rc!=SQLITE_OK ) return p->rc;
236084
236085 p->in.iCurrent = p->in.iNext;
236086 sessionDiscardData(&p->in);
@@ -235616,15 +236106,17 @@
236106 ** corrupt changeset. */
236107 assert( p->in.iNext==1 || p->zTab );
236108 return (p->rc = SQLITE_CORRUPT_BKPT);
236109 }
236110
236111 if( (op!=SQLITE_UPDATE && op!=SQLITE_DELETE && op!=SQLITE_INSERT)
236112 || (p->in.iNext>=p->in.nData)
236113 ){
236114 return (p->rc = SQLITE_CORRUPT_BKPT);
236115 }
236116 p->op = op;
236117 p->bIndirect = p->in.aData[p->in.iNext++];
236118
236119 if( paRec ){
236120 int nVal; /* Number of values to buffer */
236121 if( p->bPatchset==0 && op==SQLITE_UPDATE ){
236122 nVal = p->nCol * 2;
@@ -261258,11 +261750,11 @@
261750 int nArg, /* Number of args */
261751 sqlite3_value **apUnused /* Function arguments */
261752 ){
261753 assert( nArg==0 );
261754 UNUSED_PARAM2(nArg, apUnused);
261755 sqlite3_result_text(pCtx, "fts5: 2026-02-17 01:04:23 dd5af703e1082951a4295a3453611db12b23cfbcfee4258ec3985abe96ab54ba", -1, SQLITE_TRANSIENT);
261756 }
261757
261758 /*
261759 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261760 **
261761
+36 -14
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.52.0"
150150
#define SQLITE_VERSION_NUMBER 3052000
151
-#define SQLITE_SOURCE_ID "2026-01-26 10:53:24 4733d351ec2376291f093ba8d2ba71d82c6f100c68dc860eee0532986c154e71"
151
+#define SQLITE_SOURCE_ID "2026-02-17 11:28:48 2610105a439e25c050b2deb32953861187c81b1d97407f41dc188e6627e0ac4d"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-01-26T10:53:24.426Z"
154
+#define SQLITE_SCM_DATETIME "2026-02-17T11:28:48.505Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -11250,23 +11250,45 @@
1125011250
#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
1125111251
1125211252
/*
1125311253
** CAPI3REF: Bind array values to the CARRAY table-valued function
1125411254
**
11255
-** The sqlite3_carray_bind(S,I,P,N,F,X) interface binds an array value to
11256
-** one of the first argument of the [carray() table-valued function]. The
11257
-** S parameter is a pointer to the [prepared statement] that uses the carray()
11258
-** functions. I is the parameter index to be bound. P is a pointer to the
11259
-** array to be bound, and N is the number of eements in the array. The
11260
-** F argument is one of constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64],
11261
-** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], or [SQLITE_CARRAY_BLOB] to
11262
-** indicate the datatype of the array being bound. The X argument is not a
11263
-** NULL pointer, then SQLite will invoke the function X on the P parameter
11264
-** after it has finished using P, even if the call to
11265
-** sqlite3_carray_bind() fails. The special-case finalizer
11266
-** SQLITE_TRANSIENT has no effect here.
11255
+** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to
11256
+** parameter that is the first argument of the [carray() table-valued function].
11257
+** The S parameter is a pointer to the [prepared statement] that uses the carray()
11258
+** functions. I is the parameter index to be bound. I must be the index of the
11259
+** parameter that is the first argument to the carray() table-valued function.
11260
+** P is a pointer to the array to be bound, and N is the number of elements in
11261
+** the array. The F argument is one of constants [SQLITE_CARRAY_INT32],
11262
+** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT],
11263
+** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P.
11264
+**
11265
+** If the X argument is not a NULL pointer or one of the special
11266
+** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke
11267
+** the function X with argument D when it is finished using the data in P.
11268
+** The call to X(D) is a destructor for the array P. The destructor X(D)
11269
+** is invoked even if the call to sqlite3_carray_bind() fails. If the X
11270
+** parameter is the special-case value [SQLITE_STATIC], then SQLite assumes
11271
+** that the data static and the destructor is never invoked. If the X
11272
+** parameter is the special-case value [SQLITE_TRANSIENT], then
11273
+** sqlite3_carray_bind_v2() makes its own private copy of the data prior
11274
+** to returning and never invokes the destructor X.
11275
+**
11276
+** The sqlite3_carray_bind() function works the same as sqlite_carray_bind_v2()
11277
+** with a D parameter set to P. In other words,
11278
+** sqlite3_carray_bind(S,I,P,N,F,X) is same as
11279
+** sqlite3_carray_bind(S,I,P,N,F,X,P).
1126711280
*/
11281
+SQLITE_API int sqlite3_carray_bind_v2(
11282
+ sqlite3_stmt *pStmt, /* Statement to be bound */
11283
+ int i, /* Parameter index */
11284
+ void *aData, /* Pointer to array data */
11285
+ int nData, /* Number of data elements */
11286
+ int mFlags, /* CARRAY flags */
11287
+ void (*xDel)(void*), /* Destructor for aData */
11288
+ void *pDel /* Optional argument to xDel() */
11289
+);
1126811290
SQLITE_API int sqlite3_carray_bind(
1126911291
sqlite3_stmt *pStmt, /* Statement to be bound */
1127011292
int i, /* Parameter index */
1127111293
void *aData, /* Pointer to array data */
1127211294
int nData, /* Number of data elements */
1127311295
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2026-01-26 10:53:24 4733d351ec2376291f093ba8d2ba71d82c6f100c68dc860eee0532986c154e71"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-01-26T10:53:24.426Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -11250,23 +11250,45 @@
11250 #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
11251
11252 /*
11253 ** CAPI3REF: Bind array values to the CARRAY table-valued function
11254 **
11255 ** The sqlite3_carray_bind(S,I,P,N,F,X) interface binds an array value to
11256 ** one of the first argument of the [carray() table-valued function]. The
11257 ** S parameter is a pointer to the [prepared statement] that uses the carray()
11258 ** functions. I is the parameter index to be bound. P is a pointer to the
11259 ** array to be bound, and N is the number of eements in the array. The
11260 ** F argument is one of constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64],
11261 ** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], or [SQLITE_CARRAY_BLOB] to
11262 ** indicate the datatype of the array being bound. The X argument is not a
11263 ** NULL pointer, then SQLite will invoke the function X on the P parameter
11264 ** after it has finished using P, even if the call to
11265 ** sqlite3_carray_bind() fails. The special-case finalizer
11266 ** SQLITE_TRANSIENT has no effect here.
 
 
 
 
 
 
 
 
 
 
 
 
 
11267 */
 
 
 
 
 
 
 
 
 
11268 SQLITE_API int sqlite3_carray_bind(
11269 sqlite3_stmt *pStmt, /* Statement to be bound */
11270 int i, /* Parameter index */
11271 void *aData, /* Pointer to array data */
11272 int nData, /* Number of data elements */
11273
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2026-02-17 11:28:48 2610105a439e25c050b2deb32953861187c81b1d97407f41dc188e6627e0ac4d"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-02-17T11:28:48.505Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -11250,23 +11250,45 @@
11250 #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
11251
11252 /*
11253 ** CAPI3REF: Bind array values to the CARRAY table-valued function
11254 **
11255 ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to
11256 ** parameter that is the first argument of the [carray() table-valued function].
11257 ** The S parameter is a pointer to the [prepared statement] that uses the carray()
11258 ** functions. I is the parameter index to be bound. I must be the index of the
11259 ** parameter that is the first argument to the carray() table-valued function.
11260 ** P is a pointer to the array to be bound, and N is the number of elements in
11261 ** the array. The F argument is one of constants [SQLITE_CARRAY_INT32],
11262 ** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT],
11263 ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P.
11264 **
11265 ** If the X argument is not a NULL pointer or one of the special
11266 ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke
11267 ** the function X with argument D when it is finished using the data in P.
11268 ** The call to X(D) is a destructor for the array P. The destructor X(D)
11269 ** is invoked even if the call to sqlite3_carray_bind() fails. If the X
11270 ** parameter is the special-case value [SQLITE_STATIC], then SQLite assumes
11271 ** that the data static and the destructor is never invoked. If the X
11272 ** parameter is the special-case value [SQLITE_TRANSIENT], then
11273 ** sqlite3_carray_bind_v2() makes its own private copy of the data prior
11274 ** to returning and never invokes the destructor X.
11275 **
11276 ** The sqlite3_carray_bind() function works the same as sqlite_carray_bind_v2()
11277 ** with a D parameter set to P. In other words,
11278 ** sqlite3_carray_bind(S,I,P,N,F,X) is same as
11279 ** sqlite3_carray_bind(S,I,P,N,F,X,P).
11280 */
11281 SQLITE_API int sqlite3_carray_bind_v2(
11282 sqlite3_stmt *pStmt, /* Statement to be bound */
11283 int i, /* Parameter index */
11284 void *aData, /* Pointer to array data */
11285 int nData, /* Number of data elements */
11286 int mFlags, /* CARRAY flags */
11287 void (*xDel)(void*), /* Destructor for aData */
11288 void *pDel /* Optional argument to xDel() */
11289 );
11290 SQLITE_API int sqlite3_carray_bind(
11291 sqlite3_stmt *pStmt, /* Statement to be bound */
11292 int i, /* Parameter index */
11293 void *aData, /* Pointer to array data */
11294 int nData, /* Number of data elements */
11295
+12 -1
--- src/blob.c
+++ src/blob.c
@@ -744,15 +744,26 @@
744744
void blob_rewind(Blob *p){
745745
p->iCursor = 0;
746746
}
747747
748748
/*
749
-** Truncate a blob back to zero length
749
+** Truncate a blob to the specified length in bytes.
750750
*/
751751
void blob_truncate(Blob *p, int sz){
752752
if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz;
753753
}
754
+
755
+/*
756
+** Truncate a blob to the specified length in bytes. If truncation
757
+** results in an incomplete UTF-8 sequence at the end, remove up
758
+** to three more bytes back to the last complete UTF-8 sequence.
759
+*/
760
+void blob_truncate_utf8(Blob *p, int sz){
761
+ if( sz>=0 && sz<(int)(p->nUsed) ){
762
+ p->nUsed = utf8_nearest_codepoint(p->aData,sz);
763
+ }
764
+}
754765
755766
/*
756767
** Seek the cursor in a blob to the indicated offset.
757768
*/
758769
int blob_seek(Blob *p, int offset, int whence){
759770
--- src/blob.c
+++ src/blob.c
@@ -744,15 +744,26 @@
744 void blob_rewind(Blob *p){
745 p->iCursor = 0;
746 }
747
748 /*
749 ** Truncate a blob back to zero length
750 */
751 void blob_truncate(Blob *p, int sz){
752 if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz;
753 }
 
 
 
 
 
 
 
 
 
 
 
754
755 /*
756 ** Seek the cursor in a blob to the indicated offset.
757 */
758 int blob_seek(Blob *p, int offset, int whence){
759
--- src/blob.c
+++ src/blob.c
@@ -744,15 +744,26 @@
744 void blob_rewind(Blob *p){
745 p->iCursor = 0;
746 }
747
748 /*
749 ** Truncate a blob to the specified length in bytes.
750 */
751 void blob_truncate(Blob *p, int sz){
752 if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz;
753 }
754
755 /*
756 ** Truncate a blob to the specified length in bytes. If truncation
757 ** results in an incomplete UTF-8 sequence at the end, remove up
758 ** to three more bytes back to the last complete UTF-8 sequence.
759 */
760 void blob_truncate_utf8(Blob *p, int sz){
761 if( sz>=0 && sz<(int)(p->nUsed) ){
762 p->nUsed = utf8_nearest_codepoint(p->aData,sz);
763 }
764 }
765
766 /*
767 ** Seek the cursor in a blob to the indicated offset.
768 */
769 int blob_seek(Blob *p, int offset, int whence){
770
+1 -30
--- src/checkin.c
+++ src/checkin.c
@@ -2556,22 +2556,19 @@
25562556
int allowEmpty = 0; /* Allow a commit with no changes */
25572557
int onlyIfChanges = 0; /* No-op if there are no changes */
25582558
int allowFork = 0; /* Allow the commit to fork */
25592559
int allowOlder = 0; /* Allow a commit older than its ancestor */
25602560
int noVerifyCom = 0; /* Allow suspicious check-in comments */
2561
- char *zManifestFile; /* Name of the manifest file */
25622561
int useCksum; /* True if checksums should be computed and verified */
2563
- int outputManifest; /* True to output "manifest" and "manifest.uuid" */
25642562
int dryRunFlag; /* True for a test run. Debugging only */
25652563
CheckinInfo sCiInfo; /* Information about this check-in */
25662564
const char *zComFile; /* Read commit message from this file */
25672565
int nTag = 0; /* Number of --tag arguments */
25682566
const char *zTag; /* A single --tag argument */
25692567
ManifestFile *pFile; /* File structure in the manifest */
25702568
Manifest *pManifest; /* Manifest structure */
25712569
Blob manifest; /* Manifest in baseline form */
2572
- Blob muuid; /* Manifest uuid */
25732570
Blob cksum1, cksum2; /* Before and after commit checksums */
25742571
Blob cksum1b; /* Checksum recorded in the manifest */
25752572
int szD; /* Size of the delta manifest */
25762573
int szB; /* Size of the baseline manifest */
25772574
int nConflict = 0; /* Number of unresolved merge conflicts */
@@ -2647,11 +2644,10 @@
26472644
sCiInfo.zUserOvrd = find_option("user-override",0,1);
26482645
noSign = db_get_boolean("omitsign", 0)|noSign;
26492646
if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
26502647
useCksum = db_get_boolean("repo-cksum", 1);
26512648
bIgnoreSkew = find_option("ignore-clock-skew",0,0)!=0;
2652
- outputManifest = db_get_manifest_setting(0);
26532649
mxSize = db_large_file_size();
26542650
if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
26552651
(void)fossil_text_editor();
26562652
verify_all_options();
26572653
@@ -3209,17 +3205,10 @@
32093205
** and rollback the transaction.
32103206
*/
32113207
if( dryRunFlag ){
32123208
blob_write_to_file(&manifest, "");
32133209
}
3214
- if( outputManifest & MFESTFLG_RAW ){
3215
- zManifestFile = mprintf("%smanifest", g.zLocalRoot);
3216
- blob_write_to_file(&manifest, zManifestFile);
3217
- blob_reset(&manifest);
3218
- blob_read_from_file(&manifest, zManifestFile, ExtFILE);
3219
- free(zManifestFile);
3220
- }
32213210
32223211
nvid = content_put(&manifest);
32233212
if( nvid==0 ){
32243213
fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
32253214
}
@@ -3242,18 +3231,10 @@
32423231
}
32433232
}
32443233
db_finalize(&q);
32453234
32463235
fossil_print("New_Version: %s\n", zUuid);
3247
- if( outputManifest & MFESTFLG_UUID ){
3248
- zManifestFile = mprintf("%smanifest.uuid", g.zLocalRoot);
3249
- blob_zero(&muuid);
3250
- blob_appendf(&muuid, "%s\n", zUuid);
3251
- blob_write_to_file(&muuid, zManifestFile);
3252
- free(zManifestFile);
3253
- blob_reset(&muuid);
3254
- }
32553236
32563237
/* Update the vfile and vmerge tables */
32573238
db_multi_exec(
32583239
"DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
32593240
"DELETE FROM vmerge;"
@@ -3260,11 +3241,11 @@
32603241
"UPDATE vfile SET vid=%d;"
32613242
"UPDATE vfile SET rid=mrid, mhash=NULL, chnged=0, deleted=0, origname=NULL"
32623243
" WHERE is_selected(id);"
32633244
, vid, nvid
32643245
);
3265
- db_set_checkout(nvid);
3246
+ db_set_checkout(nvid, !dryRunFlag);
32663247
32673248
/* Update the isexe and islink columns of the vfile table */
32683249
db_prepare(&q,
32693250
"UPDATE vfile SET isexe=:exec, islink=:link"
32703251
" WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
@@ -3325,20 +3306,10 @@
33253306
db_end_transaction(1);
33263307
return;
33273308
}
33283309
db_end_transaction(0);
33293310
3330
- if( outputManifest & MFESTFLG_TAGS ){
3331
- Blob tagslist;
3332
- zManifestFile = mprintf("%smanifest.tags", g.zLocalRoot);
3333
- blob_zero(&tagslist);
3334
- get_checkin_taglist(nvid, &tagslist);
3335
- blob_write_to_file(&tagslist, zManifestFile);
3336
- blob_reset(&tagslist);
3337
- free(zManifestFile);
3338
- }
3339
-
33403311
if( !g.markPrivate ){
33413312
int syncFlags = SYNC_PUSH | SYNC_PULL | SYNC_IFABLE;
33423313
autosync_loop(syncFlags, 0, "commit");
33433314
}
33443315
if( count_nonbranch_children(vid)>1 ){
33453316
--- src/checkin.c
+++ src/checkin.c
@@ -2556,22 +2556,19 @@
2556 int allowEmpty = 0; /* Allow a commit with no changes */
2557 int onlyIfChanges = 0; /* No-op if there are no changes */
2558 int allowFork = 0; /* Allow the commit to fork */
2559 int allowOlder = 0; /* Allow a commit older than its ancestor */
2560 int noVerifyCom = 0; /* Allow suspicious check-in comments */
2561 char *zManifestFile; /* Name of the manifest file */
2562 int useCksum; /* True if checksums should be computed and verified */
2563 int outputManifest; /* True to output "manifest" and "manifest.uuid" */
2564 int dryRunFlag; /* True for a test run. Debugging only */
2565 CheckinInfo sCiInfo; /* Information about this check-in */
2566 const char *zComFile; /* Read commit message from this file */
2567 int nTag = 0; /* Number of --tag arguments */
2568 const char *zTag; /* A single --tag argument */
2569 ManifestFile *pFile; /* File structure in the manifest */
2570 Manifest *pManifest; /* Manifest structure */
2571 Blob manifest; /* Manifest in baseline form */
2572 Blob muuid; /* Manifest uuid */
2573 Blob cksum1, cksum2; /* Before and after commit checksums */
2574 Blob cksum1b; /* Checksum recorded in the manifest */
2575 int szD; /* Size of the delta manifest */
2576 int szB; /* Size of the baseline manifest */
2577 int nConflict = 0; /* Number of unresolved merge conflicts */
@@ -2647,11 +2644,10 @@
2647 sCiInfo.zUserOvrd = find_option("user-override",0,1);
2648 noSign = db_get_boolean("omitsign", 0)|noSign;
2649 if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
2650 useCksum = db_get_boolean("repo-cksum", 1);
2651 bIgnoreSkew = find_option("ignore-clock-skew",0,0)!=0;
2652 outputManifest = db_get_manifest_setting(0);
2653 mxSize = db_large_file_size();
2654 if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
2655 (void)fossil_text_editor();
2656 verify_all_options();
2657
@@ -3209,17 +3205,10 @@
3209 ** and rollback the transaction.
3210 */
3211 if( dryRunFlag ){
3212 blob_write_to_file(&manifest, "");
3213 }
3214 if( outputManifest & MFESTFLG_RAW ){
3215 zManifestFile = mprintf("%smanifest", g.zLocalRoot);
3216 blob_write_to_file(&manifest, zManifestFile);
3217 blob_reset(&manifest);
3218 blob_read_from_file(&manifest, zManifestFile, ExtFILE);
3219 free(zManifestFile);
3220 }
3221
3222 nvid = content_put(&manifest);
3223 if( nvid==0 ){
3224 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
3225 }
@@ -3242,18 +3231,10 @@
3242 }
3243 }
3244 db_finalize(&q);
3245
3246 fossil_print("New_Version: %s\n", zUuid);
3247 if( outputManifest & MFESTFLG_UUID ){
3248 zManifestFile = mprintf("%smanifest.uuid", g.zLocalRoot);
3249 blob_zero(&muuid);
3250 blob_appendf(&muuid, "%s\n", zUuid);
3251 blob_write_to_file(&muuid, zManifestFile);
3252 free(zManifestFile);
3253 blob_reset(&muuid);
3254 }
3255
3256 /* Update the vfile and vmerge tables */
3257 db_multi_exec(
3258 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
3259 "DELETE FROM vmerge;"
@@ -3260,11 +3241,11 @@
3260 "UPDATE vfile SET vid=%d;"
3261 "UPDATE vfile SET rid=mrid, mhash=NULL, chnged=0, deleted=0, origname=NULL"
3262 " WHERE is_selected(id);"
3263 , vid, nvid
3264 );
3265 db_set_checkout(nvid);
3266
3267 /* Update the isexe and islink columns of the vfile table */
3268 db_prepare(&q,
3269 "UPDATE vfile SET isexe=:exec, islink=:link"
3270 " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
@@ -3325,20 +3306,10 @@
3325 db_end_transaction(1);
3326 return;
3327 }
3328 db_end_transaction(0);
3329
3330 if( outputManifest & MFESTFLG_TAGS ){
3331 Blob tagslist;
3332 zManifestFile = mprintf("%smanifest.tags", g.zLocalRoot);
3333 blob_zero(&tagslist);
3334 get_checkin_taglist(nvid, &tagslist);
3335 blob_write_to_file(&tagslist, zManifestFile);
3336 blob_reset(&tagslist);
3337 free(zManifestFile);
3338 }
3339
3340 if( !g.markPrivate ){
3341 int syncFlags = SYNC_PUSH | SYNC_PULL | SYNC_IFABLE;
3342 autosync_loop(syncFlags, 0, "commit");
3343 }
3344 if( count_nonbranch_children(vid)>1 ){
3345
--- src/checkin.c
+++ src/checkin.c
@@ -2556,22 +2556,19 @@
2556 int allowEmpty = 0; /* Allow a commit with no changes */
2557 int onlyIfChanges = 0; /* No-op if there are no changes */
2558 int allowFork = 0; /* Allow the commit to fork */
2559 int allowOlder = 0; /* Allow a commit older than its ancestor */
2560 int noVerifyCom = 0; /* Allow suspicious check-in comments */
 
2561 int useCksum; /* True if checksums should be computed and verified */
 
2562 int dryRunFlag; /* True for a test run. Debugging only */
2563 CheckinInfo sCiInfo; /* Information about this check-in */
2564 const char *zComFile; /* Read commit message from this file */
2565 int nTag = 0; /* Number of --tag arguments */
2566 const char *zTag; /* A single --tag argument */
2567 ManifestFile *pFile; /* File structure in the manifest */
2568 Manifest *pManifest; /* Manifest structure */
2569 Blob manifest; /* Manifest in baseline form */
 
2570 Blob cksum1, cksum2; /* Before and after commit checksums */
2571 Blob cksum1b; /* Checksum recorded in the manifest */
2572 int szD; /* Size of the delta manifest */
2573 int szB; /* Size of the baseline manifest */
2574 int nConflict = 0; /* Number of unresolved merge conflicts */
@@ -2647,11 +2644,10 @@
2644 sCiInfo.zUserOvrd = find_option("user-override",0,1);
2645 noSign = db_get_boolean("omitsign", 0)|noSign;
2646 if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
2647 useCksum = db_get_boolean("repo-cksum", 1);
2648 bIgnoreSkew = find_option("ignore-clock-skew",0,0)!=0;
 
2649 mxSize = db_large_file_size();
2650 if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
2651 (void)fossil_text_editor();
2652 verify_all_options();
2653
@@ -3209,17 +3205,10 @@
3205 ** and rollback the transaction.
3206 */
3207 if( dryRunFlag ){
3208 blob_write_to_file(&manifest, "");
3209 }
 
 
 
 
 
 
 
3210
3211 nvid = content_put(&manifest);
3212 if( nvid==0 ){
3213 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
3214 }
@@ -3242,18 +3231,10 @@
3231 }
3232 }
3233 db_finalize(&q);
3234
3235 fossil_print("New_Version: %s\n", zUuid);
 
 
 
 
 
 
 
 
3236
3237 /* Update the vfile and vmerge tables */
3238 db_multi_exec(
3239 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
3240 "DELETE FROM vmerge;"
@@ -3260,11 +3241,11 @@
3241 "UPDATE vfile SET vid=%d;"
3242 "UPDATE vfile SET rid=mrid, mhash=NULL, chnged=0, deleted=0, origname=NULL"
3243 " WHERE is_selected(id);"
3244 , vid, nvid
3245 );
3246 db_set_checkout(nvid, !dryRunFlag);
3247
3248 /* Update the isexe and islink columns of the vfile table */
3249 db_prepare(&q,
3250 "UPDATE vfile SET isexe=:exec, islink=:link"
3251 " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
@@ -3325,20 +3306,10 @@
3306 db_end_transaction(1);
3307 return;
3308 }
3309 db_end_transaction(0);
3310
 
 
 
 
 
 
 
 
 
 
3311 if( !g.markPrivate ){
3312 int syncFlags = SYNC_PUSH | SYNC_PULL | SYNC_IFABLE;
3313 autosync_loop(syncFlags, 0, "commit");
3314 }
3315 if( count_nonbranch_children(vid)>1 ){
3316
+2 -3
--- src/checkout.c
+++ src/checkout.c
@@ -358,13 +358,12 @@
358358
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
359359
if( !keepFlag ){
360360
vfile_to_disk(vid, 0, !g.fQuiet, promptFlag);
361361
}
362362
checkout_set_all_exe(vid);
363
- manifest_to_disk(vid);
364363
ensure_empty_dirs_created(0);
365
- db_set_checkout(vid);
364
+ db_set_checkout(vid, 1);
366365
undo_reset();
367366
db_multi_exec("DELETE FROM vmerge");
368367
if( !keepFlag && db_get_boolean("repo-cksum",1) ){
369368
vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
370369
vfile_aggregate_checksum_disk(vid, &cksum2);
@@ -467,11 +466,11 @@
467466
** -v|--verbose Show all files as they are extracted
468467
*/
469468
void get_cmd(void){
470469
int forceFlag = find_option("force","f",0)!=0;
471470
int bVerbose = find_option("verbose","v",0)!=0;
472
- int bQuiet = find_option("quiet","q",0)!=0;
471
+ int bQuiet = g.fQuiet;
473472
int bDebug = find_option("debug",0,0)!=0;
474473
int bList = find_option("list",0,0)!=0;
475474
const char *zSqlArchive = find_option("sqlar",0,1);
476475
const char *z;
477476
char *zDest = 0; /* Where to store results */
478477
--- src/checkout.c
+++ src/checkout.c
@@ -358,13 +358,12 @@
358 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
359 if( !keepFlag ){
360 vfile_to_disk(vid, 0, !g.fQuiet, promptFlag);
361 }
362 checkout_set_all_exe(vid);
363 manifest_to_disk(vid);
364 ensure_empty_dirs_created(0);
365 db_set_checkout(vid);
366 undo_reset();
367 db_multi_exec("DELETE FROM vmerge");
368 if( !keepFlag && db_get_boolean("repo-cksum",1) ){
369 vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
370 vfile_aggregate_checksum_disk(vid, &cksum2);
@@ -467,11 +466,11 @@
467 ** -v|--verbose Show all files as they are extracted
468 */
469 void get_cmd(void){
470 int forceFlag = find_option("force","f",0)!=0;
471 int bVerbose = find_option("verbose","v",0)!=0;
472 int bQuiet = find_option("quiet","q",0)!=0;
473 int bDebug = find_option("debug",0,0)!=0;
474 int bList = find_option("list",0,0)!=0;
475 const char *zSqlArchive = find_option("sqlar",0,1);
476 const char *z;
477 char *zDest = 0; /* Where to store results */
478
--- src/checkout.c
+++ src/checkout.c
@@ -358,13 +358,12 @@
358 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
359 if( !keepFlag ){
360 vfile_to_disk(vid, 0, !g.fQuiet, promptFlag);
361 }
362 checkout_set_all_exe(vid);
 
363 ensure_empty_dirs_created(0);
364 db_set_checkout(vid, 1);
365 undo_reset();
366 db_multi_exec("DELETE FROM vmerge");
367 if( !keepFlag && db_get_boolean("repo-cksum",1) ){
368 vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
369 vfile_aggregate_checksum_disk(vid, &cksum2);
@@ -467,11 +466,11 @@
466 ** -v|--verbose Show all files as they are extracted
467 */
468 void get_cmd(void){
469 int forceFlag = find_option("force","f",0)!=0;
470 int bVerbose = find_option("verbose","v",0)!=0;
471 int bQuiet = g.fQuiet;
472 int bDebug = find_option("debug",0,0)!=0;
473 int bList = find_option("list",0,0)!=0;
474 const char *zSqlArchive = find_option("sqlar",0,1);
475 const char *z;
476 char *zDest = 0; /* Where to store results */
477
+4 -4
--- src/content.c
+++ src/content.c
@@ -965,11 +965,11 @@
965965
** Options:
966966
** -d|--db-only Run "PRAGMA integrity_check" on the database only.
967967
** No other validation is performed.
968968
** --parse Parse all manifests, wikis, tickets, events, and
969969
** so forth, reporting any errors found.
970
-** -q|--quick Run "PRAGMA quick_check" on the database only.
970
+** --quick Run "PRAGMA quick_check" on the database only.
971971
** No other validation is performed.
972972
*/
973973
void test_integrity(void){
974974
Stmt q;
975975
Blob content;
@@ -979,11 +979,11 @@
979979
int total;
980980
int nCA = 0;
981981
int anCA[10];
982982
int bParse = find_option("parse",0,0)!=0;
983983
int bDbOnly = find_option("db-only","d",0)!=0;
984
- int bQuick = find_option("quick","q",0)!=0;
984
+ int bQuick = find_option("quick",0,0)!=0;
985985
db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
986986
if( bDbOnly || bQuick ){
987987
const char *zType = bQuick ? "quick" : "integrity";
988988
char *zRes;
989989
zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/);
@@ -1199,11 +1199,11 @@
11991199
** all references are satisfied. Report any referenced artifacts
12001200
** that are missing or shunned.
12011201
**
12021202
** Options:
12031203
** --notshunned Do not report shunned artifacts
1204
-** --quiet Only show output if there are errors
1204
+** -q|--quiet Only show output if there are errors
12051205
*/
12061206
void test_missing(void){
12071207
Stmt q;
12081208
Blob content;
12091209
int nErr = 0;
@@ -1212,11 +1212,11 @@
12121212
Manifest *p;
12131213
unsigned flags = 0;
12141214
int quietFlag;
12151215
12161216
if( find_option("notshunned", 0, 0)!=0 ) flags |= MISSING_SHUNNED;
1217
- quietFlag = find_option("quiet","q",0)!=0;
1217
+ quietFlag = g.fQuiet;
12181218
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
12191219
db_prepare(&q,
12201220
"SELECT mid FROM mlink UNION "
12211221
"SELECT srcid FROM tagxref WHERE srcid>0 UNION "
12221222
"SELECT rid FROM tagxref UNION "
12231223
--- src/content.c
+++ src/content.c
@@ -965,11 +965,11 @@
965 ** Options:
966 ** -d|--db-only Run "PRAGMA integrity_check" on the database only.
967 ** No other validation is performed.
968 ** --parse Parse all manifests, wikis, tickets, events, and
969 ** so forth, reporting any errors found.
970 ** -q|--quick Run "PRAGMA quick_check" on the database only.
971 ** No other validation is performed.
972 */
973 void test_integrity(void){
974 Stmt q;
975 Blob content;
@@ -979,11 +979,11 @@
979 int total;
980 int nCA = 0;
981 int anCA[10];
982 int bParse = find_option("parse",0,0)!=0;
983 int bDbOnly = find_option("db-only","d",0)!=0;
984 int bQuick = find_option("quick","q",0)!=0;
985 db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
986 if( bDbOnly || bQuick ){
987 const char *zType = bQuick ? "quick" : "integrity";
988 char *zRes;
989 zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/);
@@ -1199,11 +1199,11 @@
1199 ** all references are satisfied. Report any referenced artifacts
1200 ** that are missing or shunned.
1201 **
1202 ** Options:
1203 ** --notshunned Do not report shunned artifacts
1204 ** --quiet Only show output if there are errors
1205 */
1206 void test_missing(void){
1207 Stmt q;
1208 Blob content;
1209 int nErr = 0;
@@ -1212,11 +1212,11 @@
1212 Manifest *p;
1213 unsigned flags = 0;
1214 int quietFlag;
1215
1216 if( find_option("notshunned", 0, 0)!=0 ) flags |= MISSING_SHUNNED;
1217 quietFlag = find_option("quiet","q",0)!=0;
1218 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
1219 db_prepare(&q,
1220 "SELECT mid FROM mlink UNION "
1221 "SELECT srcid FROM tagxref WHERE srcid>0 UNION "
1222 "SELECT rid FROM tagxref UNION "
1223
--- src/content.c
+++ src/content.c
@@ -965,11 +965,11 @@
965 ** Options:
966 ** -d|--db-only Run "PRAGMA integrity_check" on the database only.
967 ** No other validation is performed.
968 ** --parse Parse all manifests, wikis, tickets, events, and
969 ** so forth, reporting any errors found.
970 ** --quick Run "PRAGMA quick_check" on the database only.
971 ** No other validation is performed.
972 */
973 void test_integrity(void){
974 Stmt q;
975 Blob content;
@@ -979,11 +979,11 @@
979 int total;
980 int nCA = 0;
981 int anCA[10];
982 int bParse = find_option("parse",0,0)!=0;
983 int bDbOnly = find_option("db-only","d",0)!=0;
984 int bQuick = find_option("quick",0,0)!=0;
985 db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
986 if( bDbOnly || bQuick ){
987 const char *zType = bQuick ? "quick" : "integrity";
988 char *zRes;
989 zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/);
@@ -1199,11 +1199,11 @@
1199 ** all references are satisfied. Report any referenced artifacts
1200 ** that are missing or shunned.
1201 **
1202 ** Options:
1203 ** --notshunned Do not report shunned artifacts
1204 ** -q|--quiet Only show output if there are errors
1205 */
1206 void test_missing(void){
1207 Stmt q;
1208 Blob content;
1209 int nErr = 0;
@@ -1212,11 +1212,11 @@
1212 Manifest *p;
1213 unsigned flags = 0;
1214 int quietFlag;
1215
1216 if( find_option("notshunned", 0, 0)!=0 ) flags |= MISSING_SHUNNED;
1217 quietFlag = g.fQuiet;
1218 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
1219 db_prepare(&q,
1220 "SELECT mid FROM mlink UNION "
1221 "SELECT srcid FROM tagxref WHERE srcid>0 UNION "
1222 "SELECT rid FROM tagxref UNION "
1223
+5 -2
--- src/db.c
+++ src/db.c
@@ -4425,11 +4425,11 @@
44254425
(char*)0);
44264426
db_delete_on_failure(LOCALDB_NAME);
44274427
db_open_local(0);
44284428
db_lset("repository", zRepo);
44294429
db_record_repository_filename(zRepo);
4430
- db_set_checkout(0);
4430
+ db_set_checkout(0, 0); /* manifest files handled by checkout_cmd */
44314431
azNewArgv[0] = g.argv[0];
44324432
g.argv = azNewArgv;
44334433
if( !emptyFlag ){
44344434
g.argc = 3;
44354435
if( g.zOpenRevision ){
@@ -5666,15 +5666,18 @@
56665666
RELEASE_VERSION, MANIFEST_DATE, MANIFEST_UUID);
56675667
}
56685668
56695669
/*
56705670
** Set the value of the "checkout" entry in the VVAR table.
5671
+** If bWriteManifest is non-zero then also attempt to write the manifest
5672
+** files to disk.
56715673
**
56725674
** Also set "fingerprint" and "checkout-hash".
56735675
*/
5674
-void db_set_checkout(int rid){
5676
+void db_set_checkout(int rid, int bWriteManifest){
56755677
char *z;
5678
+ if( bWriteManifest ) manifest_to_disk(rid);
56765679
db_lset_int("checkout", rid);
56775680
if (rid != 0) {
56785681
z = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
56795682
db_lset("checkout-hash", z);
56805683
fossil_free(z);
56815684
--- src/db.c
+++ src/db.c
@@ -4425,11 +4425,11 @@
4425 (char*)0);
4426 db_delete_on_failure(LOCALDB_NAME);
4427 db_open_local(0);
4428 db_lset("repository", zRepo);
4429 db_record_repository_filename(zRepo);
4430 db_set_checkout(0);
4431 azNewArgv[0] = g.argv[0];
4432 g.argv = azNewArgv;
4433 if( !emptyFlag ){
4434 g.argc = 3;
4435 if( g.zOpenRevision ){
@@ -5666,15 +5666,18 @@
5666 RELEASE_VERSION, MANIFEST_DATE, MANIFEST_UUID);
5667 }
5668
5669 /*
5670 ** Set the value of the "checkout" entry in the VVAR table.
 
 
5671 **
5672 ** Also set "fingerprint" and "checkout-hash".
5673 */
5674 void db_set_checkout(int rid){
5675 char *z;
 
5676 db_lset_int("checkout", rid);
5677 if (rid != 0) {
5678 z = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
5679 db_lset("checkout-hash", z);
5680 fossil_free(z);
5681
--- src/db.c
+++ src/db.c
@@ -4425,11 +4425,11 @@
4425 (char*)0);
4426 db_delete_on_failure(LOCALDB_NAME);
4427 db_open_local(0);
4428 db_lset("repository", zRepo);
4429 db_record_repository_filename(zRepo);
4430 db_set_checkout(0, 0); /* manifest files handled by checkout_cmd */
4431 azNewArgv[0] = g.argv[0];
4432 g.argv = azNewArgv;
4433 if( !emptyFlag ){
4434 g.argc = 3;
4435 if( g.zOpenRevision ){
@@ -5666,15 +5666,18 @@
5666 RELEASE_VERSION, MANIFEST_DATE, MANIFEST_UUID);
5667 }
5668
5669 /*
5670 ** Set the value of the "checkout" entry in the VVAR table.
5671 ** If bWriteManifest is non-zero then also attempt to write the manifest
5672 ** files to disk.
5673 **
5674 ** Also set "fingerprint" and "checkout-hash".
5675 */
5676 void db_set_checkout(int rid, int bWriteManifest){
5677 char *z;
5678 if( bWriteManifest ) manifest_to_disk(rid);
5679 db_lset_int("checkout", rid);
5680 if (rid != 0) {
5681 z = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
5682 db_lset("checkout-hash", z);
5683 fossil_free(z);
5684
+1 -1
--- src/dispatch.c
+++ src/dispatch.c
@@ -1439,11 +1439,11 @@
14391439
** -?|--help Show help on the command rather than running it
14401440
** --httptrace Trace outbound HTTP requests
14411441
** --localtime Display times using the local timezone
14421442
** --nocgi Do not act as CGI
14431443
** --no-th-hook Do not run TH1 hooks
1444
-** --quiet Reduce the amount of output
1444
+** -q|--quiet Reduce the amount of output
14451445
** --sqlstats Show SQL usage statistics when done
14461446
** --sqltrace Trace all SQL commands
14471447
** --sshtrace Trace SSH activity
14481448
** --ssl-identity NAME Set the SSL identity to NAME
14491449
** --systemtrace Trace calls to system()
14501450
--- src/dispatch.c
+++ src/dispatch.c
@@ -1439,11 +1439,11 @@
1439 ** -?|--help Show help on the command rather than running it
1440 ** --httptrace Trace outbound HTTP requests
1441 ** --localtime Display times using the local timezone
1442 ** --nocgi Do not act as CGI
1443 ** --no-th-hook Do not run TH1 hooks
1444 ** --quiet Reduce the amount of output
1445 ** --sqlstats Show SQL usage statistics when done
1446 ** --sqltrace Trace all SQL commands
1447 ** --sshtrace Trace SSH activity
1448 ** --ssl-identity NAME Set the SSL identity to NAME
1449 ** --systemtrace Trace calls to system()
1450
--- src/dispatch.c
+++ src/dispatch.c
@@ -1439,11 +1439,11 @@
1439 ** -?|--help Show help on the command rather than running it
1440 ** --httptrace Trace outbound HTTP requests
1441 ** --localtime Display times using the local timezone
1442 ** --nocgi Do not act as CGI
1443 ** --no-th-hook Do not run TH1 hooks
1444 ** -q|--quiet Reduce the amount of output
1445 ** --sqlstats Show SQL usage statistics when done
1446 ** --sqltrace Trace all SQL commands
1447 ** --sshtrace Trace SSH activity
1448 ** --ssl-identity NAME Set the SSL identity to NAME
1449 ** --systemtrace Trace calls to system()
1450
+2 -1
--- src/export.c
+++ src/export.c
@@ -1413,10 +1413,11 @@
14131413
zAutoPush = find_option("autopush",0,1);
14141414
zMainBr = (char*)find_option("mainbranch",0,1);
14151415
bForce = find_option("force","f",0)!=0;
14161416
bIfExists = find_option("if-mirrored",0,0)!=0;
14171417
gitmirror_verbosity = VERB_NORMAL;
1418
+ if( g.fQuiet ){ gitmirror_verbosity--; } /* Global option not repeatable. */
14181419
while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; }
14191420
while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; }
14201421
verify_all_options();
14211422
if( g.argc!=4 && g.argc!=3 ){ usage("export ?MIRROR?"); }
14221423
if( g.argc==4 ){
@@ -1752,11 +1753,11 @@
17521753
int bQuiet = 0;
17531754
int bByAll = 0; /* Undocumented option meaning this command was invoked
17541755
** from "fossil all" and should modify output accordingly */
17551756
17561757
db_find_and_open_repository(0, 0);
1757
- bQuiet = find_option("quiet","q",0)!=0;
1758
+ bQuiet = g.fQuiet;
17581759
bByAll = find_option("by-all",0,0)!=0;
17591760
verify_all_options();
17601761
zMirror = db_get("last-git-export-repo", 0);
17611762
if( zMirror==0 ){
17621763
if( bQuiet ) return;
17631764
--- src/export.c
+++ src/export.c
@@ -1413,10 +1413,11 @@
1413 zAutoPush = find_option("autopush",0,1);
1414 zMainBr = (char*)find_option("mainbranch",0,1);
1415 bForce = find_option("force","f",0)!=0;
1416 bIfExists = find_option("if-mirrored",0,0)!=0;
1417 gitmirror_verbosity = VERB_NORMAL;
 
1418 while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; }
1419 while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; }
1420 verify_all_options();
1421 if( g.argc!=4 && g.argc!=3 ){ usage("export ?MIRROR?"); }
1422 if( g.argc==4 ){
@@ -1752,11 +1753,11 @@
1752 int bQuiet = 0;
1753 int bByAll = 0; /* Undocumented option meaning this command was invoked
1754 ** from "fossil all" and should modify output accordingly */
1755
1756 db_find_and_open_repository(0, 0);
1757 bQuiet = find_option("quiet","q",0)!=0;
1758 bByAll = find_option("by-all",0,0)!=0;
1759 verify_all_options();
1760 zMirror = db_get("last-git-export-repo", 0);
1761 if( zMirror==0 ){
1762 if( bQuiet ) return;
1763
--- src/export.c
+++ src/export.c
@@ -1413,10 +1413,11 @@
1413 zAutoPush = find_option("autopush",0,1);
1414 zMainBr = (char*)find_option("mainbranch",0,1);
1415 bForce = find_option("force","f",0)!=0;
1416 bIfExists = find_option("if-mirrored",0,0)!=0;
1417 gitmirror_verbosity = VERB_NORMAL;
1418 if( g.fQuiet ){ gitmirror_verbosity--; } /* Global option not repeatable. */
1419 while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; }
1420 while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; }
1421 verify_all_options();
1422 if( g.argc!=4 && g.argc!=3 ){ usage("export ?MIRROR?"); }
1423 if( g.argc==4 ){
@@ -1752,11 +1753,11 @@
1753 int bQuiet = 0;
1754 int bByAll = 0; /* Undocumented option meaning this command was invoked
1755 ** from "fossil all" and should modify output accordingly */
1756
1757 db_find_and_open_repository(0, 0);
1758 bQuiet = g.fQuiet;
1759 bByAll = find_option("by-all",0,0)!=0;
1760 verify_all_options();
1761 zMirror = db_get("last-git-export-repo", 0);
1762 if( zMirror==0 ){
1763 if( bQuiet ) return;
1764
+1 -1
--- src/file.c
+++ src/file.c
@@ -2818,11 +2818,11 @@
28182818
i64 nowTime = 0; /* Timestamp of --now or --checkout */
28192819
Stmt q;
28202820
Blob absBuffer = empty_blob; /* Absolute filename buffer */
28212821
28222822
verboseFlag = find_option("verbose","v",0)!=0;
2823
- quietFlag = find_option("quiet","q",0)!=0 || g.fQuiet;
2823
+ quietFlag = g.fQuiet;
28242824
dryRunFlag = find_option("dry-run","n",0)!=0;
28252825
zGlobList = find_option("glob", "g",1);
28262826
zGlobFile = find_option("globfile", "G",1);
28272827
28282828
if(zGlobList && zGlobFile){
28292829
--- src/file.c
+++ src/file.c
@@ -2818,11 +2818,11 @@
2818 i64 nowTime = 0; /* Timestamp of --now or --checkout */
2819 Stmt q;
2820 Blob absBuffer = empty_blob; /* Absolute filename buffer */
2821
2822 verboseFlag = find_option("verbose","v",0)!=0;
2823 quietFlag = find_option("quiet","q",0)!=0 || g.fQuiet;
2824 dryRunFlag = find_option("dry-run","n",0)!=0;
2825 zGlobList = find_option("glob", "g",1);
2826 zGlobFile = find_option("globfile", "G",1);
2827
2828 if(zGlobList && zGlobFile){
2829
--- src/file.c
+++ src/file.c
@@ -2818,11 +2818,11 @@
2818 i64 nowTime = 0; /* Timestamp of --now or --checkout */
2819 Stmt q;
2820 Blob absBuffer = empty_blob; /* Absolute filename buffer */
2821
2822 verboseFlag = find_option("verbose","v",0)!=0;
2823 quietFlag = g.fQuiet;
2824 dryRunFlag = find_option("dry-run","n",0)!=0;
2825 zGlobList = find_option("glob", "g",1);
2826 zGlobFile = find_option("globfile", "G",1);
2827
2828 if(zGlobList && zGlobFile){
2829
+5 -2
--- src/info.c
+++ src/info.c
@@ -2934,19 +2934,22 @@
29342934
if( !isFile && g.perm.Admin ){
29352935
Stmt q;
29362936
db_prepare(&q,
29372937
"SELECT coalesce(user.login,rcvfrom.uid),"
29382938
" datetime(rcvfrom.mtime,toLocal()),"
2939
- " coalesce(rcvfrom.ipaddr,'unknown')"
2939
+ " coalesce(rcvfrom.ipaddr,'unknown'),"
2940
+ " rcvfrom.rcvid"
29402941
" FROM blob, rcvfrom LEFT JOIN user ON user.uid=rcvfrom.uid"
29412942
" WHERE blob.rid=%d"
29422943
" AND rcvfrom.rcvid=blob.rcvid;", rid);
29432944
while( db_step(&q)==SQLITE_ROW ){
29442945
const char *zUser = db_column_text(&q,0);
29452946
const char *zDate = db_column_text(&q,1);
29462947
const char *zIp = db_column_text(&q,2);
2947
- @ <p>Received on %s(zDate) from %h(zUser) at %h(zIp).</p>
2948
+ int rcvid = db_column_int(&q,3);
2949
+ @ <p>Received on %s(zDate) from %h(zUser) at %h(zIp).
2950
+ @ (<a href="%R/rcvfrom?rcvid=%d(rcvid)">rcvid&nbsp;%d(rcvid))</a></p>
29482951
}
29492952
db_finalize(&q);
29502953
}
29512954
if( !docOnly ){
29522955
style_submenu_element("Download", "%R/raw/%s?at=%T",
29532956
--- src/info.c
+++ src/info.c
@@ -2934,19 +2934,22 @@
2934 if( !isFile && g.perm.Admin ){
2935 Stmt q;
2936 db_prepare(&q,
2937 "SELECT coalesce(user.login,rcvfrom.uid),"
2938 " datetime(rcvfrom.mtime,toLocal()),"
2939 " coalesce(rcvfrom.ipaddr,'unknown')"
 
2940 " FROM blob, rcvfrom LEFT JOIN user ON user.uid=rcvfrom.uid"
2941 " WHERE blob.rid=%d"
2942 " AND rcvfrom.rcvid=blob.rcvid;", rid);
2943 while( db_step(&q)==SQLITE_ROW ){
2944 const char *zUser = db_column_text(&q,0);
2945 const char *zDate = db_column_text(&q,1);
2946 const char *zIp = db_column_text(&q,2);
2947 @ <p>Received on %s(zDate) from %h(zUser) at %h(zIp).</p>
 
 
2948 }
2949 db_finalize(&q);
2950 }
2951 if( !docOnly ){
2952 style_submenu_element("Download", "%R/raw/%s?at=%T",
2953
--- src/info.c
+++ src/info.c
@@ -2934,19 +2934,22 @@
2934 if( !isFile && g.perm.Admin ){
2935 Stmt q;
2936 db_prepare(&q,
2937 "SELECT coalesce(user.login,rcvfrom.uid),"
2938 " datetime(rcvfrom.mtime,toLocal()),"
2939 " coalesce(rcvfrom.ipaddr,'unknown'),"
2940 " rcvfrom.rcvid"
2941 " FROM blob, rcvfrom LEFT JOIN user ON user.uid=rcvfrom.uid"
2942 " WHERE blob.rid=%d"
2943 " AND rcvfrom.rcvid=blob.rcvid;", rid);
2944 while( db_step(&q)==SQLITE_ROW ){
2945 const char *zUser = db_column_text(&q,0);
2946 const char *zDate = db_column_text(&q,1);
2947 const char *zIp = db_column_text(&q,2);
2948 int rcvid = db_column_int(&q,3);
2949 @ <p>Received on %s(zDate) from %h(zUser) at %h(zIp).
2950 @ (<a href="%R/rcvfrom?rcvid=%d(rcvid)">rcvid&nbsp;%d(rcvid))</a></p>
2951 }
2952 db_finalize(&q);
2953 }
2954 if( !docOnly ){
2955 style_submenu_element("Download", "%R/raw/%s?at=%T",
2956
+1 -1
--- src/main.c
+++ src/main.c
@@ -831,11 +831,11 @@
831831
fossil_exit(1);
832832
}else{
833833
const char *zChdir = find_option("chdir",0,1);
834834
g.isHTTP = 0;
835835
g.rcvid = 0;
836
- g.fQuiet = find_option("quiet", 0, 0)!=0;
836
+ g.fQuiet = find_option("quiet", "q", 0)!=0;
837837
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
838838
g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
839839
g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
840840
g.fSshTrace = find_option("sshtrace", 0, 0)!=0;
841841
g.fCgiTrace = find_option("cgitrace", 0, 0)!=0;
842842
--- src/main.c
+++ src/main.c
@@ -831,11 +831,11 @@
831 fossil_exit(1);
832 }else{
833 const char *zChdir = find_option("chdir",0,1);
834 g.isHTTP = 0;
835 g.rcvid = 0;
836 g.fQuiet = find_option("quiet", 0, 0)!=0;
837 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
838 g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
839 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
840 g.fSshTrace = find_option("sshtrace", 0, 0)!=0;
841 g.fCgiTrace = find_option("cgitrace", 0, 0)!=0;
842
--- src/main.c
+++ src/main.c
@@ -831,11 +831,11 @@
831 fossil_exit(1);
832 }else{
833 const char *zChdir = find_option("chdir",0,1);
834 g.isHTTP = 0;
835 g.rcvid = 0;
836 g.fQuiet = find_option("quiet", "q", 0)!=0;
837 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
838 g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
839 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
840 g.fSshTrace = find_option("sshtrace", 0, 0)!=0;
841 g.fCgiTrace = find_option("cgitrace", 0, 0)!=0;
842
+16 -4
--- src/name.c
+++ src/name.c
@@ -1131,10 +1131,11 @@
11311131
#if INTERFACE
11321132
#define WHATIS_VERBOSE 0x01 /* Extra output */
11331133
#define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
11341134
#define WHATIS_REPO 0x04 /* Show repository name */
11351135
#define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
1136
+#define WHATIS_HASHONLY 0x10 /* Show only the hash */
11361137
#endif
11371138
11381139
/*
11391140
** Generate a description of artifact "rid"
11401141
*/
@@ -1148,11 +1149,13 @@
11481149
" FROM blob, rcvfrom"
11491150
" WHERE rid=%d"
11501151
" AND rcvfrom.rcvid=blob.rcvid",
11511152
rid);
11521153
if( db_step(&q)==SQLITE_ROW ){
1153
- if( flags & WHATIS_VERBOSE ){
1154
+ if( flags & WHATIS_HASHONLY ){
1155
+ fossil_print("%s\n", db_column_text(&q,0));
1156
+ }else if( flags & WHATIS_VERBOSE ){
11541157
fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
11551158
fossil_print("size: %d bytes\n", db_column_int(&q,1));
11561159
fossil_print("received: %s from %s\n",
11571160
db_column_text(&q, 2),
11581161
db_column_text(&q, 3));
@@ -1160,10 +1163,11 @@
11601163
fossil_print("artifact: %s\n", db_column_text(&q,0));
11611164
fossil_print("size: %d bytes\n", db_column_int(&q,1));
11621165
}
11631166
}
11641167
db_finalize(&q);
1168
+ if( flags & WHATIS_HASHONLY ) return;
11651169
11661170
/* Report any symbolic tags on this artifact */
11671171
db_prepare(&q,
11681172
"SELECT substr(tagname,5)"
11691173
" FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
@@ -1330,11 +1334,11 @@
13301334
if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
13311335
whatis_rid(db_column_int(&q, 0), mFlags);
13321336
}
13331337
db_finalize(&q);
13341338
}else if( rid==0 ){
1335
- if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1339
+ if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
13361340
/* 0123456789 12 */
13371341
if( zFileName ){
13381342
fossil_print("%-12s%s\n", "name:", zFileName);
13391343
}
13401344
fossil_print("unknown: %s\n", zName);
@@ -1344,11 +1348,13 @@
13441348
fossil_print("\nrepository: %s\n", g.zRepositoryName);
13451349
}
13461350
if( zFileName ){
13471351
zName = zFileName;
13481352
}
1349
- fossil_print("%-12s%s\n", "name:", zName);
1353
+ if( (mFlags & WHATIS_HASHONLY)==0 ){
1354
+ fossil_print("%-12s%s\n", "name:", zName);
1355
+ }
13501356
whatis_rid(rid, mFlags);
13511357
}
13521358
}
13531359
13541360
/*
@@ -1361,11 +1367,14 @@
13611367
** plays.
13621368
**
13631369
** Options:
13641370
** -f|--file Find artifacts with the same hash as file NAME.
13651371
** If NAME is "-", read content from standard input.
1372
+** -h|--hash Show only the hash of matching artifacts.
13661373
** -q|--quiet Show nothing if NAME is not found
1374
+** -R REPO_FILE Specifies the repository db to use. Default is
1375
+** the current check-out's repository.
13671376
** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
13681377
** 'w', 'g', or 'e')
13691378
** -v|--verbose Provide extra information (such as the RID)
13701379
*/
13711380
void whatis_cmd(void){
@@ -1375,11 +1384,14 @@
13751384
const char *zType = 0;
13761385
db_find_and_open_repository(0,0);
13771386
if( find_option("verbose","v",0)!=0 ){
13781387
mFlags |= WHATIS_VERBOSE;
13791388
}
1380
- if( find_option("quiet","q",0)!=0 ){
1389
+ if( find_option("hash","h",0)!=0 ){
1390
+ mFlags |= WHATIS_HASHONLY;
1391
+ }
1392
+ if( g.fQuiet ){
13811393
mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
13821394
}
13831395
fileFlag = find_option("file","f",0)!=0;
13841396
zType = find_option("type",0,1);
13851397
13861398
--- src/name.c
+++ src/name.c
@@ -1131,10 +1131,11 @@
1131 #if INTERFACE
1132 #define WHATIS_VERBOSE 0x01 /* Extra output */
1133 #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
1134 #define WHATIS_REPO 0x04 /* Show repository name */
1135 #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
 
1136 #endif
1137
1138 /*
1139 ** Generate a description of artifact "rid"
1140 */
@@ -1148,11 +1149,13 @@
1148 " FROM blob, rcvfrom"
1149 " WHERE rid=%d"
1150 " AND rcvfrom.rcvid=blob.rcvid",
1151 rid);
1152 if( db_step(&q)==SQLITE_ROW ){
1153 if( flags & WHATIS_VERBOSE ){
 
 
1154 fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
1155 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1156 fossil_print("received: %s from %s\n",
1157 db_column_text(&q, 2),
1158 db_column_text(&q, 3));
@@ -1160,10 +1163,11 @@
1160 fossil_print("artifact: %s\n", db_column_text(&q,0));
1161 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1162 }
1163 }
1164 db_finalize(&q);
 
1165
1166 /* Report any symbolic tags on this artifact */
1167 db_prepare(&q,
1168 "SELECT substr(tagname,5)"
1169 " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
@@ -1330,11 +1334,11 @@
1330 if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1331 whatis_rid(db_column_int(&q, 0), mFlags);
1332 }
1333 db_finalize(&q);
1334 }else if( rid==0 ){
1335 if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1336 /* 0123456789 12 */
1337 if( zFileName ){
1338 fossil_print("%-12s%s\n", "name:", zFileName);
1339 }
1340 fossil_print("unknown: %s\n", zName);
@@ -1344,11 +1348,13 @@
1344 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1345 }
1346 if( zFileName ){
1347 zName = zFileName;
1348 }
1349 fossil_print("%-12s%s\n", "name:", zName);
 
 
1350 whatis_rid(rid, mFlags);
1351 }
1352 }
1353
1354 /*
@@ -1361,11 +1367,14 @@
1361 ** plays.
1362 **
1363 ** Options:
1364 ** -f|--file Find artifacts with the same hash as file NAME.
1365 ** If NAME is "-", read content from standard input.
 
1366 ** -q|--quiet Show nothing if NAME is not found
 
 
1367 ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
1368 ** 'w', 'g', or 'e')
1369 ** -v|--verbose Provide extra information (such as the RID)
1370 */
1371 void whatis_cmd(void){
@@ -1375,11 +1384,14 @@
1375 const char *zType = 0;
1376 db_find_and_open_repository(0,0);
1377 if( find_option("verbose","v",0)!=0 ){
1378 mFlags |= WHATIS_VERBOSE;
1379 }
1380 if( find_option("quiet","q",0)!=0 ){
 
 
 
1381 mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
1382 }
1383 fileFlag = find_option("file","f",0)!=0;
1384 zType = find_option("type",0,1);
1385
1386
--- src/name.c
+++ src/name.c
@@ -1131,10 +1131,11 @@
1131 #if INTERFACE
1132 #define WHATIS_VERBOSE 0x01 /* Extra output */
1133 #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
1134 #define WHATIS_REPO 0x04 /* Show repository name */
1135 #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
1136 #define WHATIS_HASHONLY 0x10 /* Show only the hash */
1137 #endif
1138
1139 /*
1140 ** Generate a description of artifact "rid"
1141 */
@@ -1148,11 +1149,13 @@
1149 " FROM blob, rcvfrom"
1150 " WHERE rid=%d"
1151 " AND rcvfrom.rcvid=blob.rcvid",
1152 rid);
1153 if( db_step(&q)==SQLITE_ROW ){
1154 if( flags & WHATIS_HASHONLY ){
1155 fossil_print("%s\n", db_column_text(&q,0));
1156 }else if( flags & WHATIS_VERBOSE ){
1157 fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
1158 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1159 fossil_print("received: %s from %s\n",
1160 db_column_text(&q, 2),
1161 db_column_text(&q, 3));
@@ -1160,10 +1163,11 @@
1163 fossil_print("artifact: %s\n", db_column_text(&q,0));
1164 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1165 }
1166 }
1167 db_finalize(&q);
1168 if( flags & WHATIS_HASHONLY ) return;
1169
1170 /* Report any symbolic tags on this artifact */
1171 db_prepare(&q,
1172 "SELECT substr(tagname,5)"
1173 " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
@@ -1330,11 +1334,11 @@
1334 if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1335 whatis_rid(db_column_int(&q, 0), mFlags);
1336 }
1337 db_finalize(&q);
1338 }else if( rid==0 ){
1339 if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
1340 /* 0123456789 12 */
1341 if( zFileName ){
1342 fossil_print("%-12s%s\n", "name:", zFileName);
1343 }
1344 fossil_print("unknown: %s\n", zName);
@@ -1344,11 +1348,13 @@
1348 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1349 }
1350 if( zFileName ){
1351 zName = zFileName;
1352 }
1353 if( (mFlags & WHATIS_HASHONLY)==0 ){
1354 fossil_print("%-12s%s\n", "name:", zName);
1355 }
1356 whatis_rid(rid, mFlags);
1357 }
1358 }
1359
1360 /*
@@ -1361,11 +1367,14 @@
1367 ** plays.
1368 **
1369 ** Options:
1370 ** -f|--file Find artifacts with the same hash as file NAME.
1371 ** If NAME is "-", read content from standard input.
1372 ** -h|--hash Show only the hash of matching artifacts.
1373 ** -q|--quiet Show nothing if NAME is not found
1374 ** -R REPO_FILE Specifies the repository db to use. Default is
1375 ** the current check-out's repository.
1376 ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
1377 ** 'w', 'g', or 'e')
1378 ** -v|--verbose Provide extra information (such as the RID)
1379 */
1380 void whatis_cmd(void){
@@ -1375,11 +1384,14 @@
1384 const char *zType = 0;
1385 db_find_and_open_repository(0,0);
1386 if( find_option("verbose","v",0)!=0 ){
1387 mFlags |= WHATIS_VERBOSE;
1388 }
1389 if( find_option("hash","h",0)!=0 ){
1390 mFlags |= WHATIS_HASHONLY;
1391 }
1392 if( g.fQuiet ){
1393 mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
1394 }
1395 fileFlag = find_option("file","f",0)!=0;
1396 zType = find_option("type",0,1);
1397
1398
+1 -1
--- src/regexp.c
+++ src/regexp.c
@@ -993,11 +993,11 @@
993993
994994
995995
if( find_option("ignore-case","i",0)!=0 ) ignoreCase = 1;
996996
if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
997997
if( find_option("verbose",0,0)!=0 ) bVerbose = 1;
998
- if( find_option("quiet","q",0) ) flags |= GREP_QUIET|GREP_EXISTS;
998
+ if( g.fQuiet ) flags |= GREP_QUIET|GREP_EXISTS;
999999
bNoMsg = find_option("no-messages","s",0)!=0;
10001000
bOnce = find_option("once",0,0)!=0;
10011001
bInvert = find_option("invert-match","v",0)!=0;
10021002
if( bInvert ){
10031003
flags |= GREP_QUIET|GREP_EXISTS;
10041004
--- src/regexp.c
+++ src/regexp.c
@@ -993,11 +993,11 @@
993
994
995 if( find_option("ignore-case","i",0)!=0 ) ignoreCase = 1;
996 if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
997 if( find_option("verbose",0,0)!=0 ) bVerbose = 1;
998 if( find_option("quiet","q",0) ) flags |= GREP_QUIET|GREP_EXISTS;
999 bNoMsg = find_option("no-messages","s",0)!=0;
1000 bOnce = find_option("once",0,0)!=0;
1001 bInvert = find_option("invert-match","v",0)!=0;
1002 if( bInvert ){
1003 flags |= GREP_QUIET|GREP_EXISTS;
1004
--- src/regexp.c
+++ src/regexp.c
@@ -993,11 +993,11 @@
993
994
995 if( find_option("ignore-case","i",0)!=0 ) ignoreCase = 1;
996 if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
997 if( find_option("verbose",0,0)!=0 ) bVerbose = 1;
998 if( g.fQuiet ) flags |= GREP_QUIET|GREP_EXISTS;
999 bNoMsg = find_option("no-messages","s",0)!=0;
1000 bOnce = find_option("once",0,0)!=0;
1001 bInvert = find_option("invert-match","v",0)!=0;
1002 if( bInvert ){
1003 flags |= GREP_QUIET|GREP_EXISTS;
1004
+3 -1
--- src/robot.c
+++ src/robot.c
@@ -263,11 +263,11 @@
263263
** The VALUE of this setting is a list of GLOB patterns that match
264264
** pages for which complex HTTP requests from unauthenticated clients
265265
** should be disallowed. "Unauthenticated" means the user is "nobody".
266266
** The recommended value for this setting is:
267267
**
268
-** timelineX,diff,annotate,fileage,file,finfo,reports,tree,download,hexdump
268
+** timelineX,diff,annotate,fileage,file,finfo,reports,tree,hexdump,download
269269
**
270270
** Usually the tag should exactly match the page name. The "diff" tag
271271
** covers all diffing pages such as /vdiff, /fdiff, and /vpatch. The
272272
** "annotate" tag also covers /blame and /praise. "zip" also covers
273273
** /tarball and /sqlar. If a tag has an "X" character appended then it
@@ -320,10 +320,12 @@
320320
321321
/*
322322
** Return the default restriction GLOB
323323
*/
324324
const char *robot_restrict_default(void){
325
+ /* NOTE: The default value is also mentioned in the online help screen of
326
+ ** the "robot-restrict" setting, and in the www/antibot.wiki document. */
325327
return "timelineX,diff,annotate,fileage,file,finfo,reports,"
326328
"tree,hexdump,download";
327329
}
328330
329331
/*
330332
--- src/robot.c
+++ src/robot.c
@@ -263,11 +263,11 @@
263 ** The VALUE of this setting is a list of GLOB patterns that match
264 ** pages for which complex HTTP requests from unauthenticated clients
265 ** should be disallowed. "Unauthenticated" means the user is "nobody".
266 ** The recommended value for this setting is:
267 **
268 ** timelineX,diff,annotate,fileage,file,finfo,reports,tree,download,hexdump
269 **
270 ** Usually the tag should exactly match the page name. The "diff" tag
271 ** covers all diffing pages such as /vdiff, /fdiff, and /vpatch. The
272 ** "annotate" tag also covers /blame and /praise. "zip" also covers
273 ** /tarball and /sqlar. If a tag has an "X" character appended then it
@@ -320,10 +320,12 @@
320
321 /*
322 ** Return the default restriction GLOB
323 */
324 const char *robot_restrict_default(void){
 
 
325 return "timelineX,diff,annotate,fileage,file,finfo,reports,"
326 "tree,hexdump,download";
327 }
328
329 /*
330
--- src/robot.c
+++ src/robot.c
@@ -263,11 +263,11 @@
263 ** The VALUE of this setting is a list of GLOB patterns that match
264 ** pages for which complex HTTP requests from unauthenticated clients
265 ** should be disallowed. "Unauthenticated" means the user is "nobody".
266 ** The recommended value for this setting is:
267 **
268 ** timelineX,diff,annotate,fileage,file,finfo,reports,tree,hexdump,download
269 **
270 ** Usually the tag should exactly match the page name. The "diff" tag
271 ** covers all diffing pages such as /vdiff, /fdiff, and /vpatch. The
272 ** "annotate" tag also covers /blame and /praise. "zip" also covers
273 ** /tarball and /sqlar. If a tag has an "X" character appended then it
@@ -320,10 +320,12 @@
320
321 /*
322 ** Return the default restriction GLOB
323 */
324 const char *robot_restrict_default(void){
325 /* NOTE: The default value is also mentioned in the online help screen of
326 ** the "robot-restrict" setting, and in the www/antibot.wiki document. */
327 return "timelineX,diff,annotate,fileage,file,finfo,reports,"
328 "tree,hexdump,download";
329 }
330
331 /*
332
+15 -11
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -221,12 +221,14 @@
221221
helptext_vtab_register(db);
222222
builtin_vtab_register(db);
223223
g.repositoryOpen = 1;
224224
g.db = db;
225225
sqlite3_busy_timeout(db, 10000);
226
- sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
227
- db_maybe_set_encryption_key(db, g.zRepositoryName);
226
+ if( g.zRepositoryName ){
227
+ sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
228
+ db_maybe_set_encryption_key(db, g.zRepositoryName);
229
+ }
228230
if( g.zLocalDbName ){
229231
char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
230232
g.zLocalDbName);
231233
sqlite3_exec(db, zSql, 0, 0, 0);
232234
sqlite3_free(zSql);
@@ -240,19 +242,21 @@
240242
(void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
241243
/* Arrange to trace close operations so that static prepared statements
242244
** will get cleaned up when the shell closes the database connection */
243245
if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
244246
sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
245
- db_protect_only(PROTECT_NONE);
246
- sqlite3_set_authorizer(db, db_top_authorizer, db);
247
- if( local_bSqlCmdTest ){
248
- sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
249
- sqlcmd_db_protect, 0, 0);
250
- sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
251
- sqlcmd_db_protect_pop, 0, 0);
252
- sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
253
- sha1_shared_secret_sql_function, 0, 0);
247
+ if( g.zRepositoryName ){
248
+ db_protect_only(PROTECT_NONE);
249
+ sqlite3_set_authorizer(db, db_top_authorizer, db);
250
+ if( local_bSqlCmdTest ){
251
+ sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
252
+ sqlcmd_db_protect, 0, 0);
253
+ sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
254
+ sqlcmd_db_protect_pop, 0, 0);
255
+ sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
256
+ sha1_shared_secret_sql_function, 0, 0);
257
+ }
254258
}
255259
return SQLITE_OK;
256260
}
257261
258262
/*
259263
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -221,12 +221,14 @@
221 helptext_vtab_register(db);
222 builtin_vtab_register(db);
223 g.repositoryOpen = 1;
224 g.db = db;
225 sqlite3_busy_timeout(db, 10000);
226 sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
227 db_maybe_set_encryption_key(db, g.zRepositoryName);
 
 
228 if( g.zLocalDbName ){
229 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
230 g.zLocalDbName);
231 sqlite3_exec(db, zSql, 0, 0, 0);
232 sqlite3_free(zSql);
@@ -240,19 +242,21 @@
240 (void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
241 /* Arrange to trace close operations so that static prepared statements
242 ** will get cleaned up when the shell closes the database connection */
243 if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
244 sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
245 db_protect_only(PROTECT_NONE);
246 sqlite3_set_authorizer(db, db_top_authorizer, db);
247 if( local_bSqlCmdTest ){
248 sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
249 sqlcmd_db_protect, 0, 0);
250 sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
251 sqlcmd_db_protect_pop, 0, 0);
252 sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
253 sha1_shared_secret_sql_function, 0, 0);
 
 
254 }
255 return SQLITE_OK;
256 }
257
258 /*
259
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -221,12 +221,14 @@
221 helptext_vtab_register(db);
222 builtin_vtab_register(db);
223 g.repositoryOpen = 1;
224 g.db = db;
225 sqlite3_busy_timeout(db, 10000);
226 if( g.zRepositoryName ){
227 sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
228 db_maybe_set_encryption_key(db, g.zRepositoryName);
229 }
230 if( g.zLocalDbName ){
231 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
232 g.zLocalDbName);
233 sqlite3_exec(db, zSql, 0, 0, 0);
234 sqlite3_free(zSql);
@@ -240,19 +242,21 @@
242 (void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
243 /* Arrange to trace close operations so that static prepared statements
244 ** will get cleaned up when the shell closes the database connection */
245 if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
246 sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
247 if( g.zRepositoryName ){
248 db_protect_only(PROTECT_NONE);
249 sqlite3_set_authorizer(db, db_top_authorizer, db);
250 if( local_bSqlCmdTest ){
251 sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
252 sqlcmd_db_protect, 0, 0);
253 sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
254 sqlcmd_db_protect_pop, 0, 0);
255 sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
256 sha1_shared_secret_sql_function, 0, 0);
257 }
258 }
259 return SQLITE_OK;
260 }
261
262 /*
263
+1 -1
--- src/sync.c
+++ src/sync.c
@@ -510,11 +510,11 @@
510510
syncFlags |= SYNC_UNVERSIONED;
511511
}
512512
if( find_option("ping",0,0)!=0 ){
513513
syncFlags = SYNC_PING;
514514
}
515
- if( find_option("quiet","q",0)!=0 ){
515
+ if( g.fQuiet ){
516516
syncFlags |= SYNC_QUIET;
517517
}
518518
process_sync_args(&configFlags, &syncFlags, 0, 0);
519519
520520
/* We should be done with options.. */
521521
--- src/sync.c
+++ src/sync.c
@@ -510,11 +510,11 @@
510 syncFlags |= SYNC_UNVERSIONED;
511 }
512 if( find_option("ping",0,0)!=0 ){
513 syncFlags = SYNC_PING;
514 }
515 if( find_option("quiet","q",0)!=0 ){
516 syncFlags |= SYNC_QUIET;
517 }
518 process_sync_args(&configFlags, &syncFlags, 0, 0);
519
520 /* We should be done with options.. */
521
--- src/sync.c
+++ src/sync.c
@@ -510,11 +510,11 @@
510 syncFlags |= SYNC_UNVERSIONED;
511 }
512 if( find_option("ping",0,0)!=0 ){
513 syncFlags = SYNC_PING;
514 }
515 if( g.fQuiet ){
516 syncFlags |= SYNC_QUIET;
517 }
518 process_sync_args(&configFlags, &syncFlags, 0, 0);
519
520 /* We should be done with options.. */
521
+20 -10
--- src/timeline.c
+++ src/timeline.c
@@ -730,10 +730,14 @@
730730
** will simply be rendered in the older format. */
731731
wiki_convert(&comment, 0, WIKI_INLINE);
732732
}
733733
wiki_hyperlink_override(0);
734734
}else{
735
+ if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){
736
+ blob_truncate_utf8(&comment, mxWikiLen);
737
+ blob_append(&comment, "...", 3);
738
+ }
735739
wiki_convert(&comment, 0, WIKI_INLINE);
736740
}
737741
}else{
738742
if( bCommentGitStyle ){
739743
/* Truncate comment at first blank line */
@@ -747,16 +751,13 @@
747751
}
748752
}
749753
z[ii] = 0;
750754
cgi_printf("%W",z);
751755
}else if( mxWikiLen>0 && (int)blob_size(&comment)>mxWikiLen ){
752
- Blob truncated;
753
- blob_zero(&truncated);
754
- blob_append(&truncated, blob_buffer(&comment), mxWikiLen);
755
- blob_append(&truncated, "...", 3);
756
- @ %W(blob_str(&truncated))
757
- blob_reset(&truncated);
756
+ blob_truncate_utf8(&comment, mxWikiLen);
757
+ blob_append(&comment, "...", 3);
758
+ @ %W(blob_str(&comment))
758759
drawDetailEllipsis = 0;
759760
}else{
760761
cgi_printf("%W",blob_str(&comment));
761762
}
762763
}
@@ -3451,14 +3452,18 @@
34513452
int n = 0;
34523453
char zPrefix[80];
34533454
34543455
if( nAbsLimit!=0 ){
34553456
if( nLimit<0 && nLine>=nAbsLimit ){
3456
- fossil_print("--- line limit (%d) reached ---\n", nAbsLimit);
3457
+ if( !g.fQuiet ){
3458
+ fossil_print("--- line limit (%d) reached ---\n", nAbsLimit);
3459
+ }
34573460
break; /* line count limit hit, stop. */
34583461
}else if( nEntry>=nAbsLimit ){
3459
- fossil_print("--- entry limit (%d) reached ---\n", nAbsLimit);
3462
+ if( !g.fQuiet ){
3463
+ fossil_print("--- entry limit (%d) reached ---\n", nAbsLimit);
3464
+ }
34603465
break; /* entry count limit hit, stop. */
34613466
}
34623467
}
34633468
if( zFormat == 0 && fossil_strnicmp(zDate, zPrevDate, 10) ){
34643469
fossil_print("=== %.10s ===\n", zDate);
@@ -3569,13 +3574,17 @@
35693574
nEntry++; /* record another complete entry */
35703575
}
35713576
if( rc==SQLITE_DONE ){
35723577
/* Did the underlying query actually have all entries? */
35733578
if( nAbsLimit==0 ){
3574
- fossil_print("+++ end of timeline (%d) +++\n", nEntry);
3579
+ if( !g.fQuiet ){
3580
+ fossil_print("+++ end of timeline (%d) +++\n", nEntry);
3581
+ }
35753582
}else{
3576
- fossil_print("+++ no more data (%d) +++\n", nEntry);
3583
+ if( !g.fQuiet ){
3584
+ fossil_print("+++ no more data (%d) +++\n", nEntry);
3585
+ }
35773586
}
35783587
}
35793588
if( fchngQueryInit ) db_finalize(&fchngQuery);
35803589
}
35813590
@@ -3729,10 +3738,11 @@
37293738
** N is negative, output the first -N lines. If N is
37303739
** zero, no limit. Default is -20 meaning 20 lines.
37313740
** --offset P Skip P changes
37323741
** -p|--path PATH Output items affecting PATH only.
37333742
** PATH can be a file or a subdirectory.
3743
+** -q|--quiet Do not print notifications at the end of the timeline.
37343744
** -r|--reverse Show items in chronological order.
37353745
** -R REPO_FILE Specifies the repository db to use. Default is
37363746
** the current check-out's repository.
37373747
** --sql Show the SQL used to generate the timeline
37383748
** -t|--type TYPE Output items from the given types only, such as:
37393749
--- src/timeline.c
+++ src/timeline.c
@@ -730,10 +730,14 @@
730 ** will simply be rendered in the older format. */
731 wiki_convert(&comment, 0, WIKI_INLINE);
732 }
733 wiki_hyperlink_override(0);
734 }else{
 
 
 
 
735 wiki_convert(&comment, 0, WIKI_INLINE);
736 }
737 }else{
738 if( bCommentGitStyle ){
739 /* Truncate comment at first blank line */
@@ -747,16 +751,13 @@
747 }
748 }
749 z[ii] = 0;
750 cgi_printf("%W",z);
751 }else if( mxWikiLen>0 && (int)blob_size(&comment)>mxWikiLen ){
752 Blob truncated;
753 blob_zero(&truncated);
754 blob_append(&truncated, blob_buffer(&comment), mxWikiLen);
755 blob_append(&truncated, "...", 3);
756 @ %W(blob_str(&truncated))
757 blob_reset(&truncated);
758 drawDetailEllipsis = 0;
759 }else{
760 cgi_printf("%W",blob_str(&comment));
761 }
762 }
@@ -3451,14 +3452,18 @@
3451 int n = 0;
3452 char zPrefix[80];
3453
3454 if( nAbsLimit!=0 ){
3455 if( nLimit<0 && nLine>=nAbsLimit ){
3456 fossil_print("--- line limit (%d) reached ---\n", nAbsLimit);
 
 
3457 break; /* line count limit hit, stop. */
3458 }else if( nEntry>=nAbsLimit ){
3459 fossil_print("--- entry limit (%d) reached ---\n", nAbsLimit);
 
 
3460 break; /* entry count limit hit, stop. */
3461 }
3462 }
3463 if( zFormat == 0 && fossil_strnicmp(zDate, zPrevDate, 10) ){
3464 fossil_print("=== %.10s ===\n", zDate);
@@ -3569,13 +3574,17 @@
3569 nEntry++; /* record another complete entry */
3570 }
3571 if( rc==SQLITE_DONE ){
3572 /* Did the underlying query actually have all entries? */
3573 if( nAbsLimit==0 ){
3574 fossil_print("+++ end of timeline (%d) +++\n", nEntry);
 
 
3575 }else{
3576 fossil_print("+++ no more data (%d) +++\n", nEntry);
 
 
3577 }
3578 }
3579 if( fchngQueryInit ) db_finalize(&fchngQuery);
3580 }
3581
@@ -3729,10 +3738,11 @@
3729 ** N is negative, output the first -N lines. If N is
3730 ** zero, no limit. Default is -20 meaning 20 lines.
3731 ** --offset P Skip P changes
3732 ** -p|--path PATH Output items affecting PATH only.
3733 ** PATH can be a file or a subdirectory.
 
3734 ** -r|--reverse Show items in chronological order.
3735 ** -R REPO_FILE Specifies the repository db to use. Default is
3736 ** the current check-out's repository.
3737 ** --sql Show the SQL used to generate the timeline
3738 ** -t|--type TYPE Output items from the given types only, such as:
3739
--- src/timeline.c
+++ src/timeline.c
@@ -730,10 +730,14 @@
730 ** will simply be rendered in the older format. */
731 wiki_convert(&comment, 0, WIKI_INLINE);
732 }
733 wiki_hyperlink_override(0);
734 }else{
735 if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){
736 blob_truncate_utf8(&comment, mxWikiLen);
737 blob_append(&comment, "...", 3);
738 }
739 wiki_convert(&comment, 0, WIKI_INLINE);
740 }
741 }else{
742 if( bCommentGitStyle ){
743 /* Truncate comment at first blank line */
@@ -747,16 +751,13 @@
751 }
752 }
753 z[ii] = 0;
754 cgi_printf("%W",z);
755 }else if( mxWikiLen>0 && (int)blob_size(&comment)>mxWikiLen ){
756 blob_truncate_utf8(&comment, mxWikiLen);
757 blob_append(&comment, "...", 3);
758 @ %W(blob_str(&comment))
 
 
 
759 drawDetailEllipsis = 0;
760 }else{
761 cgi_printf("%W",blob_str(&comment));
762 }
763 }
@@ -3451,14 +3452,18 @@
3452 int n = 0;
3453 char zPrefix[80];
3454
3455 if( nAbsLimit!=0 ){
3456 if( nLimit<0 && nLine>=nAbsLimit ){
3457 if( !g.fQuiet ){
3458 fossil_print("--- line limit (%d) reached ---\n", nAbsLimit);
3459 }
3460 break; /* line count limit hit, stop. */
3461 }else if( nEntry>=nAbsLimit ){
3462 if( !g.fQuiet ){
3463 fossil_print("--- entry limit (%d) reached ---\n", nAbsLimit);
3464 }
3465 break; /* entry count limit hit, stop. */
3466 }
3467 }
3468 if( zFormat == 0 && fossil_strnicmp(zDate, zPrevDate, 10) ){
3469 fossil_print("=== %.10s ===\n", zDate);
@@ -3569,13 +3574,17 @@
3574 nEntry++; /* record another complete entry */
3575 }
3576 if( rc==SQLITE_DONE ){
3577 /* Did the underlying query actually have all entries? */
3578 if( nAbsLimit==0 ){
3579 if( !g.fQuiet ){
3580 fossil_print("+++ end of timeline (%d) +++\n", nEntry);
3581 }
3582 }else{
3583 if( !g.fQuiet ){
3584 fossil_print("+++ no more data (%d) +++\n", nEntry);
3585 }
3586 }
3587 }
3588 if( fchngQueryInit ) db_finalize(&fchngQuery);
3589 }
3590
@@ -3729,10 +3738,11 @@
3738 ** N is negative, output the first -N lines. If N is
3739 ** zero, no limit. Default is -20 meaning 20 lines.
3740 ** --offset P Skip P changes
3741 ** -p|--path PATH Output items affecting PATH only.
3742 ** PATH can be a file or a subdirectory.
3743 ** -q|--quiet Do not print notifications at the end of the timeline.
3744 ** -r|--reverse Show items in chronological order.
3745 ** -R REPO_FILE Specifies the repository db to use. Default is
3746 ** the current check-out's repository.
3747 ** --sql Show the SQL used to generate the timeline
3748 ** -t|--type TYPE Output items from the given types only, such as:
3749
+5 -5
--- src/tkt.c
+++ src/tkt.c
@@ -1520,11 +1520,11 @@
15201520
**
15211521
** > fossil ticket show (REPORTTITLE|REPORTNR) ?TICKETFILTER? ?OPTIONS?
15221522
**
15231523
** Options:
15241524
** -l|--limit LIMITCHAR
1525
-** -q|--quote
1525
+** --quote
15261526
** -R|--repository REPO
15271527
**
15281528
** Run the ticket report, identified by the report format title
15291529
** used in the GUI. The data is written as flat file on stdout,
15301530
** using TAB as separator. The separator can be changed using
@@ -1555,12 +1555,12 @@
15551555
** > fossil ticket list reports
15561556
** > fossil ticket ls reports
15571557
**
15581558
** List all ticket reports defined in the fossil repository.
15591559
**
1560
-** > fossil ticket set TICKETUUID (FIELD VALUE)+ ?-q|--quote?
1561
-** > fossil ticket change TICKETUUID (FIELD VALUE)+ ?-q|--quote?
1560
+** > fossil ticket set TICKETUUID (FIELD VALUE)+ ?--quote?
1561
+** > fossil ticket change TICKETUUID (FIELD VALUE)+ ?--quote?
15621562
**
15631563
** Change ticket identified by TICKETUUID to set the values of
15641564
** each field FIELD to VALUE.
15651565
**
15661566
** Field names as defined in the TICKET table. By default, these
@@ -1572,11 +1572,11 @@
15721572
** can use more than one field/value pair on the command line. Using
15731573
** --quote enables the special character decoding as in "ticket
15741574
** show", which allows setting multiline text or text with special
15751575
** characters.
15761576
**
1577
-** > fossil ticket add FIELD VALUE ?FIELD VALUE .. ? ?-q|--quote?
1577
+** > fossil ticket add FIELD VALUE ?FIELD VALUE .. ? ?--quote?
15781578
**
15791579
** Like set, but create a new ticket with the given values.
15801580
**
15811581
** > fossil ticket history TICKETUUID
15821582
**
@@ -1642,11 +1642,11 @@
16421642
}
16431643
}else{
16441644
/* add a new ticket or set fields on existing tickets */
16451645
tTktShowEncoding tktEncoding;
16461646
1647
- tktEncoding = find_option("quote","q",0) ? tktFossilize : tktNoTab;
1647
+ tktEncoding = find_option("quote",0,0) ? tktFossilize : tktNoTab;
16481648
16491649
if( strncmp(g.argv[2],"show",n)==0 ){
16501650
if( g.argc==3 ){
16511651
usage("show REPORTNR");
16521652
}else{
16531653
--- src/tkt.c
+++ src/tkt.c
@@ -1520,11 +1520,11 @@
1520 **
1521 ** > fossil ticket show (REPORTTITLE|REPORTNR) ?TICKETFILTER? ?OPTIONS?
1522 **
1523 ** Options:
1524 ** -l|--limit LIMITCHAR
1525 ** -q|--quote
1526 ** -R|--repository REPO
1527 **
1528 ** Run the ticket report, identified by the report format title
1529 ** used in the GUI. The data is written as flat file on stdout,
1530 ** using TAB as separator. The separator can be changed using
@@ -1555,12 +1555,12 @@
1555 ** > fossil ticket list reports
1556 ** > fossil ticket ls reports
1557 **
1558 ** List all ticket reports defined in the fossil repository.
1559 **
1560 ** > fossil ticket set TICKETUUID (FIELD VALUE)+ ?-q|--quote?
1561 ** > fossil ticket change TICKETUUID (FIELD VALUE)+ ?-q|--quote?
1562 **
1563 ** Change ticket identified by TICKETUUID to set the values of
1564 ** each field FIELD to VALUE.
1565 **
1566 ** Field names as defined in the TICKET table. By default, these
@@ -1572,11 +1572,11 @@
1572 ** can use more than one field/value pair on the command line. Using
1573 ** --quote enables the special character decoding as in "ticket
1574 ** show", which allows setting multiline text or text with special
1575 ** characters.
1576 **
1577 ** > fossil ticket add FIELD VALUE ?FIELD VALUE .. ? ?-q|--quote?
1578 **
1579 ** Like set, but create a new ticket with the given values.
1580 **
1581 ** > fossil ticket history TICKETUUID
1582 **
@@ -1642,11 +1642,11 @@
1642 }
1643 }else{
1644 /* add a new ticket or set fields on existing tickets */
1645 tTktShowEncoding tktEncoding;
1646
1647 tktEncoding = find_option("quote","q",0) ? tktFossilize : tktNoTab;
1648
1649 if( strncmp(g.argv[2],"show",n)==0 ){
1650 if( g.argc==3 ){
1651 usage("show REPORTNR");
1652 }else{
1653
--- src/tkt.c
+++ src/tkt.c
@@ -1520,11 +1520,11 @@
1520 **
1521 ** > fossil ticket show (REPORTTITLE|REPORTNR) ?TICKETFILTER? ?OPTIONS?
1522 **
1523 ** Options:
1524 ** -l|--limit LIMITCHAR
1525 ** --quote
1526 ** -R|--repository REPO
1527 **
1528 ** Run the ticket report, identified by the report format title
1529 ** used in the GUI. The data is written as flat file on stdout,
1530 ** using TAB as separator. The separator can be changed using
@@ -1555,12 +1555,12 @@
1555 ** > fossil ticket list reports
1556 ** > fossil ticket ls reports
1557 **
1558 ** List all ticket reports defined in the fossil repository.
1559 **
1560 ** > fossil ticket set TICKETUUID (FIELD VALUE)+ ?--quote?
1561 ** > fossil ticket change TICKETUUID (FIELD VALUE)+ ?--quote?
1562 **
1563 ** Change ticket identified by TICKETUUID to set the values of
1564 ** each field FIELD to VALUE.
1565 **
1566 ** Field names as defined in the TICKET table. By default, these
@@ -1572,11 +1572,11 @@
1572 ** can use more than one field/value pair on the command line. Using
1573 ** --quote enables the special character decoding as in "ticket
1574 ** show", which allows setting multiline text or text with special
1575 ** characters.
1576 **
1577 ** > fossil ticket add FIELD VALUE ?FIELD VALUE .. ? ?--quote?
1578 **
1579 ** Like set, but create a new ticket with the given values.
1580 **
1581 ** > fossil ticket history TICKETUUID
1582 **
@@ -1642,11 +1642,11 @@
1642 }
1643 }else{
1644 /* add a new ticket or set fields on existing tickets */
1645 tTktShowEncoding tktEncoding;
1646
1647 tktEncoding = find_option("quote",0,0) ? tktFossilize : tktNoTab;
1648
1649 if( strncmp(g.argv[2],"show",n)==0 ){
1650 if( g.argc==3 ){
1651 usage("show REPORTNR");
1652 }else{
1653
+1 -1
--- src/undo.c
+++ src/undo.c
@@ -166,11 +166,11 @@
166166
}
167167
}
168168
ncid = db_lget_int("undo_checkout", 0);
169169
ucid = db_lget_int("checkout", 0);
170170
db_lset_int("undo_checkout", ucid);
171
- db_set_checkout(ncid);
171
+ db_set_checkout(ncid, 1);
172172
}
173173
174174
/*
175175
** Reset the undo memory.
176176
*/
177177
--- src/undo.c
+++ src/undo.c
@@ -166,11 +166,11 @@
166 }
167 }
168 ncid = db_lget_int("undo_checkout", 0);
169 ucid = db_lget_int("checkout", 0);
170 db_lset_int("undo_checkout", ucid);
171 db_set_checkout(ncid);
172 }
173
174 /*
175 ** Reset the undo memory.
176 */
177
--- src/undo.c
+++ src/undo.c
@@ -166,11 +166,11 @@
166 }
167 }
168 ncid = db_lget_int("undo_checkout", 0);
169 ucid = db_lget_int("checkout", 0);
170 db_lset_int("undo_checkout", ucid);
171 db_set_checkout(ncid, 1);
172 }
173
174 /*
175 ** Reset the undo memory.
176 */
177
+1 -2
--- src/update.c
+++ src/update.c
@@ -687,12 +687,11 @@
687687
fossil_free(zPwd);
688688
if( g.argc<=3 ){
689689
/* All files updated. Shift the current check-out to the target. */
690690
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
691691
checkout_set_all_exe(tid);
692
- manifest_to_disk(tid);
693
- db_set_checkout(tid);
692
+ db_set_checkout(tid, 1);
694693
}else{
695694
/* A subset of files have been checked out. Keep the current
696695
** check-out unchanged. */
697696
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
698697
}
699698
--- src/update.c
+++ src/update.c
@@ -687,12 +687,11 @@
687 fossil_free(zPwd);
688 if( g.argc<=3 ){
689 /* All files updated. Shift the current check-out to the target. */
690 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
691 checkout_set_all_exe(tid);
692 manifest_to_disk(tid);
693 db_set_checkout(tid);
694 }else{
695 /* A subset of files have been checked out. Keep the current
696 ** check-out unchanged. */
697 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
698 }
699
--- src/update.c
+++ src/update.c
@@ -687,12 +687,11 @@
687 fossil_free(zPwd);
688 if( g.argc<=3 ){
689 /* All files updated. Shift the current check-out to the target. */
690 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
691 checkout_set_all_exe(tid);
692 db_set_checkout(tid, 1);
 
693 }else{
694 /* A subset of files have been checked out. Keep the current
695 ** check-out unchanged. */
696 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
697 }
698
+1 -1
--- src/vfile.c
+++ src/vfile.c
@@ -571,11 +571,11 @@
571571
}
572572
}
573573
574574
/*
575575
** Scans the specified base directory for any directories within it, while
576
-** keeping a count of how many files they each contains, either directly or
576
+** keeping a count of how many files they each contain, either directly or
577577
** indirectly.
578578
**
579579
** Subdirectories are scanned recursively.
580580
** Omit files named in VFILE.
581581
**
582582
--- src/vfile.c
+++ src/vfile.c
@@ -571,11 +571,11 @@
571 }
572 }
573
574 /*
575 ** Scans the specified base directory for any directories within it, while
576 ** keeping a count of how many files they each contains, either directly or
577 ** indirectly.
578 **
579 ** Subdirectories are scanned recursively.
580 ** Omit files named in VFILE.
581 **
582
--- src/vfile.c
+++ src/vfile.c
@@ -571,11 +571,11 @@
571 }
572 }
573
574 /*
575 ** Scans the specified base directory for any directories within it, while
576 ** keeping a count of how many files they each contain, either directly or
577 ** indirectly.
578 **
579 ** Subdirectories are scanned recursively.
580 ** Omit files named in VFILE.
581 **
582
--- src/xsystem.c
+++ src/xsystem.c
@@ -442,10 +442,76 @@
442442
}
443443
}
444444
sqlite3_finalize(pStmt);
445445
sqlite3_close(db);
446446
}
447
+
448
+/*
449
+** unzip [-l] ZIPFILE
450
+*/
451
+void xsystem_unzip(int argc, char **argv){
452
+ const char *zZipfile = 0;
453
+ int doList = 0;
454
+ int i;
455
+ char *a[5];
456
+ int n;
457
+ extern int sqlite3_shell(int, char**);
458
+
459
+ for(i=1; i<argc; i++){
460
+ const char *z = argv[i];
461
+ if( z[0]=='-' ){
462
+ if( z[1]=='-' && z[2]!=0 ) z++;
463
+ if( strcmp(z,"-l")==0 ){
464
+ doList = 1;
465
+ }else
466
+ {
467
+ fossil_fatal("unknown option: %s", argv[i]);
468
+ }
469
+ }else if( zZipfile!=0 ){
470
+ fossil_fatal("extra argument: %s", z);
471
+ }else{
472
+ zZipfile = z;
473
+ }
474
+ }
475
+ if( zZipfile==0 ){
476
+ fossil_fatal("Usage: fossil sys unzip [-l] ZIPFILE");
477
+ }else if( file_size(zZipfile, ExtFILE)<0 ){
478
+ fossil_fatal("No such file: %s\n", zZipfile);
479
+ }
480
+ g.zRepositoryName = 0;
481
+ g.zLocalDbName = 0;
482
+ g.zConfigDbName = 0;
483
+ sqlite3_shutdown();
484
+ a[0] = argv[0];
485
+ a[1] = (char*)zZipfile;
486
+ if( doList ){
487
+ a[2] = ".mode column";
488
+ a[3] = "SELECT sz AS Size, date(mtime,'unixepoch') AS Date,"
489
+ " time(mtime,'unixepoch') AS Time, name AS Name"
490
+ " FROM zip;";
491
+ n = 4;
492
+ }else{
493
+ a[2] = ".mode list";
494
+ a[3] = "SELECT if(writefile(name,data,mode,mtime) IS NULL,"
495
+ "'error: '||name,'extracting: '||name) FROM zip;";
496
+ n = 4;
497
+ }
498
+ a[n] = 0;
499
+ sqlite3_shell(n,a);
500
+}
501
+
502
+/*
503
+** zip [OPTIONS] ZIPFILE FILE ...
504
+*/
505
+void xsystem_zip(int argc, char **argv){
506
+ int i;
507
+ for(i=0; i<argc; i++){
508
+ g.argv[i+1] = argv[i];
509
+ }
510
+ g.argc = argc+1;
511
+ filezip_cmd();
512
+}
447513
448514
/*
449515
** Available system commands.
450516
*/
451517
typedef struct XSysCmd XSysCmd;
@@ -476,17 +542,26 @@
476542
"Show the Present Working Directory name\n"
477543
},
478544
{ "stty", xsystem_stty,
479545
"\n"
480546
"Show the size of the TTY\n"
547
+ },
548
+ { "unzip", xsystem_unzip,
549
+ "[-l] ZIPFILE\n\n"
550
+ "Extract content from ZIPFILE, or list the content if the -l option\n"
551
+ "is used.\n"
481552
},
482553
{ "which", xsystem_which,
483554
"EXE ...\n"
484555
"Show the location on PATH of executables EXE\n"
485556
"Options:\n"
486557
" -a Show all path locations rather than just the first\n"
487558
},
559
+ { "zip", xsystem_zip,
560
+ "ZIPFILE FILE ...\n\n"
561
+ "Create a new ZIP archive named ZIPFILE using listed files as content\n"
562
+ },
488563
};
489564
490565
/*
491566
** COMMAND: system
492567
**
493568
--- src/xsystem.c
+++ src/xsystem.c
@@ -442,10 +442,76 @@
442 }
443 }
444 sqlite3_finalize(pStmt);
445 sqlite3_close(db);
446 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
448 /*
449 ** Available system commands.
450 */
451 typedef struct XSysCmd XSysCmd;
@@ -476,17 +542,26 @@
476 "Show the Present Working Directory name\n"
477 },
478 { "stty", xsystem_stty,
479 "\n"
480 "Show the size of the TTY\n"
 
 
 
 
 
481 },
482 { "which", xsystem_which,
483 "EXE ...\n"
484 "Show the location on PATH of executables EXE\n"
485 "Options:\n"
486 " -a Show all path locations rather than just the first\n"
487 },
 
 
 
 
488 };
489
490 /*
491 ** COMMAND: system
492 **
493
--- src/xsystem.c
+++ src/xsystem.c
@@ -442,10 +442,76 @@
442 }
443 }
444 sqlite3_finalize(pStmt);
445 sqlite3_close(db);
446 }
447
448 /*
449 ** unzip [-l] ZIPFILE
450 */
451 void xsystem_unzip(int argc, char **argv){
452 const char *zZipfile = 0;
453 int doList = 0;
454 int i;
455 char *a[5];
456 int n;
457 extern int sqlite3_shell(int, char**);
458
459 for(i=1; i<argc; i++){
460 const char *z = argv[i];
461 if( z[0]=='-' ){
462 if( z[1]=='-' && z[2]!=0 ) z++;
463 if( strcmp(z,"-l")==0 ){
464 doList = 1;
465 }else
466 {
467 fossil_fatal("unknown option: %s", argv[i]);
468 }
469 }else if( zZipfile!=0 ){
470 fossil_fatal("extra argument: %s", z);
471 }else{
472 zZipfile = z;
473 }
474 }
475 if( zZipfile==0 ){
476 fossil_fatal("Usage: fossil sys unzip [-l] ZIPFILE");
477 }else if( file_size(zZipfile, ExtFILE)<0 ){
478 fossil_fatal("No such file: %s\n", zZipfile);
479 }
480 g.zRepositoryName = 0;
481 g.zLocalDbName = 0;
482 g.zConfigDbName = 0;
483 sqlite3_shutdown();
484 a[0] = argv[0];
485 a[1] = (char*)zZipfile;
486 if( doList ){
487 a[2] = ".mode column";
488 a[3] = "SELECT sz AS Size, date(mtime,'unixepoch') AS Date,"
489 " time(mtime,'unixepoch') AS Time, name AS Name"
490 " FROM zip;";
491 n = 4;
492 }else{
493 a[2] = ".mode list";
494 a[3] = "SELECT if(writefile(name,data,mode,mtime) IS NULL,"
495 "'error: '||name,'extracting: '||name) FROM zip;";
496 n = 4;
497 }
498 a[n] = 0;
499 sqlite3_shell(n,a);
500 }
501
502 /*
503 ** zip [OPTIONS] ZIPFILE FILE ...
504 */
505 void xsystem_zip(int argc, char **argv){
506 int i;
507 for(i=0; i<argc; i++){
508 g.argv[i+1] = argv[i];
509 }
510 g.argc = argc+1;
511 filezip_cmd();
512 }
513
514 /*
515 ** Available system commands.
516 */
517 typedef struct XSysCmd XSysCmd;
@@ -476,17 +542,26 @@
542 "Show the Present Working Directory name\n"
543 },
544 { "stty", xsystem_stty,
545 "\n"
546 "Show the size of the TTY\n"
547 },
548 { "unzip", xsystem_unzip,
549 "[-l] ZIPFILE\n\n"
550 "Extract content from ZIPFILE, or list the content if the -l option\n"
551 "is used.\n"
552 },
553 { "which", xsystem_which,
554 "EXE ...\n"
555 "Show the location on PATH of executables EXE\n"
556 "Options:\n"
557 " -a Show all path locations rather than just the first\n"
558 },
559 { "zip", xsystem_zip,
560 "ZIPFILE FILE ...\n\n"
561 "Create a new ZIP archive named ZIPFILE using listed files as content\n"
562 },
563 };
564
565 /*
566 ** COMMAND: system
567 **
568
--- www/antibot.wiki
+++ www/antibot.wiki
@@ -139,11 +139,11 @@
139139
The [/help/robot-restrict|robot-restrict setting] is a comma-separated
140140
list of GLOB patterns for pages for which robot access is prohibited.
141141
The default value is:
142142
143143
<blockquote><pre>
144
-timelineX,diff,annotate,fileage,file,finfo,reports
144
+timelineX,diff,annotate,fileage,file,finfo,reports,tree,hexdump,download
145145
</pre></blockquote>
146146
147147
Each entry corresponds to the first path element on the URI for a
148148
Fossil-generated page. If Fossil does not know for certain that the
149149
HTTP request is coming from a human, then any attempt to access one of
150150
--- www/antibot.wiki
+++ www/antibot.wiki
@@ -139,11 +139,11 @@
139 The [/help/robot-restrict|robot-restrict setting] is a comma-separated
140 list of GLOB patterns for pages for which robot access is prohibited.
141 The default value is:
142
143 <blockquote><pre>
144 timelineX,diff,annotate,fileage,file,finfo,reports
145 </pre></blockquote>
146
147 Each entry corresponds to the first path element on the URI for a
148 Fossil-generated page. If Fossil does not know for certain that the
149 HTTP request is coming from a human, then any attempt to access one of
150
--- www/antibot.wiki
+++ www/antibot.wiki
@@ -139,11 +139,11 @@
139 The [/help/robot-restrict|robot-restrict setting] is a comma-separated
140 list of GLOB patterns for pages for which robot access is prohibited.
141 The default value is:
142
143 <blockquote><pre>
144 timelineX,diff,annotate,fileage,file,finfo,reports,tree,hexdump,download
145 </pre></blockquote>
146
147 Each entry corresponds to the first path element on the URI for a
148 Fossil-generated page. If Fossil does not know for certain that the
149 HTTP request is coming from a human, then any attempt to access one of
150
--- www/customskin.md
+++ www/customskin.md
@@ -336,11 +336,12 @@
336336
output and is instead run as a TH1 script. That TH1
337337
script has the opportunity to insert new text in place of itself,
338338
or to inhibit or enable the output of subsequent text.
339339
340340
* Text of the form "$NAME" or "$&lt;NAME&gt;" is replaced with
341
- the value of the TH1 variable NAME.
341
+ the value of the TH1 variable NAME. See the [TH1 Variables](#vars)
342
+ section for more information on the two possible variable formats.
342343
343344
For example, first few lines of a typical Skin Header will look
344345
like this:
345346
346347
<div class="header">
@@ -424,18 +425,32 @@
424425
## <a id="vars"></a>TH1 Variables
425426
426427
Before expanding the TH1 within the header and footer, Fossil first
427428
initializes a number of TH1 variables to values that depend on
428429
repository settings and the specific page being generated.
430
+
431
+Variables holding text that is loaded from "external, potentially untrusted"
432
+sources (including the repository settings) are treated as [tainted strings]
433
+(./th1.md#taint) and must be noted in the `$<NAME>` form, instead of `$NAME`,
434
+or they may trigger an error (see the linked document for details). The
435
+`$<NAME>` form corresponds to the TH1 statement `puts [ htmlize "$NAME" ]`,
436
+where the [htmlize](./th1.md#htmlize) function escapes the tainted string,
437
+making it safe for output in HTML code.
438
+
429439
430440
* **`project_name`** - The project_name variable is filled with the
431441
name of the project as configured under the Admin/Configuration
432
- menu.
442
+ menu. This is a [tainted string](./th1.md#taint) variable and must
443
+ be used as `$<project_name>`.
433444
434445
* **`project_description`** - The project_description variable is
435446
filled with the description of the project as configured under
436
- the Admin/Configuration menu.
447
+ the Admin/Configuration menu. This is a [tainted string]
448
+ (./th1.md#taint) variable and must be used as `$<project_description>`.
449
+
450
+ * **`mainmenu`** - The mainmenu variable contains a TCL list with the main
451
+ menu entries. See the [mainmenu](/help/mainmenu) setting for details.
437452
438453
* **`title`** - The title variable holds the title of the page being
439454
generated.
440455
441456
The title variable is special in that it is deleted after
442457
--- www/customskin.md
+++ www/customskin.md
@@ -336,11 +336,12 @@
336 output and is instead run as a TH1 script. That TH1
337 script has the opportunity to insert new text in place of itself,
338 or to inhibit or enable the output of subsequent text.
339
340 * Text of the form "$NAME" or "$&lt;NAME&gt;" is replaced with
341 the value of the TH1 variable NAME.
 
342
343 For example, first few lines of a typical Skin Header will look
344 like this:
345
346 <div class="header">
@@ -424,18 +425,32 @@
424 ## <a id="vars"></a>TH1 Variables
425
426 Before expanding the TH1 within the header and footer, Fossil first
427 initializes a number of TH1 variables to values that depend on
428 repository settings and the specific page being generated.
 
 
 
 
 
 
 
 
 
429
430 * **`project_name`** - The project_name variable is filled with the
431 name of the project as configured under the Admin/Configuration
432 menu.
 
433
434 * **`project_description`** - The project_description variable is
435 filled with the description of the project as configured under
436 the Admin/Configuration menu.
 
 
 
 
437
438 * **`title`** - The title variable holds the title of the page being
439 generated.
440
441 The title variable is special in that it is deleted after
442
--- www/customskin.md
+++ www/customskin.md
@@ -336,11 +336,12 @@
336 output and is instead run as a TH1 script. That TH1
337 script has the opportunity to insert new text in place of itself,
338 or to inhibit or enable the output of subsequent text.
339
340 * Text of the form "$NAME" or "$&lt;NAME&gt;" is replaced with
341 the value of the TH1 variable NAME. See the [TH1 Variables](#vars)
342 section for more information on the two possible variable formats.
343
344 For example, first few lines of a typical Skin Header will look
345 like this:
346
347 <div class="header">
@@ -424,18 +425,32 @@
425 ## <a id="vars"></a>TH1 Variables
426
427 Before expanding the TH1 within the header and footer, Fossil first
428 initializes a number of TH1 variables to values that depend on
429 repository settings and the specific page being generated.
430
431 Variables holding text that is loaded from "external, potentially untrusted"
432 sources (including the repository settings) are treated as [tainted strings]
433 (./th1.md#taint) and must be noted in the `$<NAME>` form, instead of `$NAME`,
434 or they may trigger an error (see the linked document for details). The
435 `$<NAME>` form corresponds to the TH1 statement `puts [ htmlize "$NAME" ]`,
436 where the [htmlize](./th1.md#htmlize) function escapes the tainted string,
437 making it safe for output in HTML code.
438
439
440 * **`project_name`** - The project_name variable is filled with the
441 name of the project as configured under the Admin/Configuration
442 menu. This is a [tainted string](./th1.md#taint) variable and must
443 be used as `$<project_name>`.
444
445 * **`project_description`** - The project_description variable is
446 filled with the description of the project as configured under
447 the Admin/Configuration menu. This is a [tainted string]
448 (./th1.md#taint) variable and must be used as `$<project_description>`.
449
450 * **`mainmenu`** - The mainmenu variable contains a TCL list with the main
451 menu entries. See the [mainmenu](/help/mainmenu) setting for details.
452
453 * **`title`** - The title variable holds the title of the page being
454 generated.
455
456 The title variable is special in that it is deleted after
457

Keyboard Shortcuts

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