Fossil SCM

Add messages to the error log if the authorizer blocks an SQL statement for security reasons. This change requires a bug fix in SQLite and so it also includes the latest trunk version of SQLite.

drh 2022-12-29 18:56 trunk
Commit 3d8bb63aab8aa7770f443ca03476ed841c1811c3051ef54c8dff7aed5d6e8ca3
+890 -141
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -37,11 +37,11 @@
3737
typedef unsigned int u32;
3838
typedef unsigned short int u16;
3939
4040
/*
4141
** Optionally #include a user-defined header, whereby compilation options
42
-** may be set prior to where they take effect, but after platform setup.
42
+** may be set prior to where they take effect, but after platform setup.
4343
** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
4444
** file. Note that this macro has a like effect on sqlite3.c compilation.
4545
*/
4646
# define SHELL_STRINGIFY_(f) #f
4747
# define SHELL_STRINGIFY(f) SHELL_STRINGIFY_(f)
@@ -551,24 +551,25 @@
551551
if( continuePrompt[0]==0
552552
|| (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
553553
return continuePrompt;
554554
}else{
555555
if( dynPrompt.zScannerAwaits ){
556
- size_t ncp = strlen(continuePrompt), ndp = strlen(dynPrompt.zScannerAwaits);
556
+ size_t ncp = strlen(continuePrompt);
557
+ size_t ndp = strlen(dynPrompt.zScannerAwaits);
557558
if( ndp > ncp-3 ) return continuePrompt;
558559
strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
559560
while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
560561
strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
561
- PROMPT_LEN_MAX-4);
562
+ PROMPT_LEN_MAX-4);
562563
}else{
563564
if( dynPrompt.inParenLevel>9 ){
564
- strncpy(dynPrompt.dynamicPrompt, "(..", 4);
565
+ strncpy(dynPrompt.dynamicPrompt, "(..", 4);
565566
}else if( dynPrompt.inParenLevel<0 ){
566
- strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
567
+ strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
567568
}else{
568
- strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
569
- dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
569
+ strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
570
+ dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
570571
}
571572
strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
572573
}
573574
}
574575
return dynPrompt.dynamicPrompt;
@@ -1049,11 +1050,11 @@
10491050
){
10501051
const char *zName;
10511052
char *zFake;
10521053
UNUSED_PARAMETER(nVal);
10531054
zName = (const char*)sqlite3_value_text(apVal[0]);
1054
- zFake = zName ? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
1055
+ zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
10551056
if( zFake ){
10561057
sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
10571058
-1, sqlite3_free);
10581059
free(zFake);
10591060
}
@@ -3050,11 +3051,11 @@
30503051
unsigned int i;
30513052
(void)pzErrMsg; /* Unused parameter */
30523053
30533054
SQLITE_EXTENSION_INIT2(pApi);
30543055
3055
- for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
3056
+ for(i=0; i<(int)(sizeof(aFunc)/sizeof(aFunc[0])) && rc==SQLITE_OK; i++){
30563057
rc = sqlite3_create_function(db, aFunc[i].zFuncName, aFunc[i].nArg,
30573058
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
30583059
0, aFunc[i].xFunc, 0, 0);
30593060
}
30603061
if( rc==SQLITE_OK ){
@@ -3069,10 +3070,724 @@
30693070
}
30703071
return rc;
30713072
}
30723073
30733074
/************************* End ../ext/misc/decimal.c ********************/
3075
+#undef sqlite3_base_init
3076
+#define sqlite3_base_init sqlite3_base64_init
3077
+/************************* Begin ../ext/misc/base64.c ******************/
3078
+/*
3079
+** 2022-11-18
3080
+**
3081
+** The author disclaims copyright to this source code. In place of
3082
+** a legal notice, here is a blessing:
3083
+**
3084
+** May you do good and not evil.
3085
+** May you find forgiveness for yourself and forgive others.
3086
+** May you share freely, never taking more than you give.
3087
+**
3088
+*************************************************************************
3089
+**
3090
+** This is a SQLite extension for converting in either direction
3091
+** between a (binary) blob and base64 text. Base64 can transit a
3092
+** sane USASCII channel unmolested. It also plays nicely in CSV or
3093
+** written as TCL brace-enclosed literals or SQL string literals,
3094
+** and can be used unmodified in XML-like documents.
3095
+**
3096
+** This is an independent implementation of conversions specified in
3097
+** RFC 4648, done on the above date by the author (Larry Brasfield)
3098
+** who thereby has the right to put this into the public domain.
3099
+**
3100
+** The conversions meet RFC 4648 requirements, provided that this
3101
+** C source specifies that line-feeds are included in the encoded
3102
+** data to limit visible line lengths to 72 characters and to
3103
+** terminate any encoded blob having non-zero length.
3104
+**
3105
+** Length limitations are not imposed except that the runtime
3106
+** SQLite string or blob length limits are respected. Otherwise,
3107
+** any length binary sequence can be represented and recovered.
3108
+** Generated base64 sequences, with their line-feeds included,
3109
+** can be concatenated; the result converted back to binary will
3110
+** be the concatenation of the represented binary sequences.
3111
+**
3112
+** This SQLite3 extension creates a function, base64(x), which
3113
+** either: converts text x containing base64 to a returned blob;
3114
+** or converts a blob x to returned text containing base64. An
3115
+** error will be thrown for other input argument types.
3116
+**
3117
+** This code relies on UTF-8 encoding only with respect to the
3118
+** meaning of the first 128 (7-bit) codes matching that of USASCII.
3119
+** It will fail miserably if somehow made to try to convert EBCDIC.
3120
+** Because it is table-driven, it could be enhanced to handle that,
3121
+** but the world and SQLite have moved on from that anachronism.
3122
+**
3123
+** To build the extension:
3124
+** Set shell variable SQDIR=<your favorite SQLite checkout directory>
3125
+** *Nix: gcc -O2 -shared -I$SQDIR -fPIC -o base64.so base64.c
3126
+** OSX: gcc -O2 -dynamiclib -fPIC -I$SQDIR -o base64.dylib base64.c
3127
+** Win32: gcc -O2 -shared -I%SQDIR% -o base64.dll base64.c
3128
+** Win32: cl /Os -I%SQDIR% base64.c -link -dll -out:base64.dll
3129
+*/
3130
+
3131
+#include <assert.h>
3132
+
3133
+/* #include "sqlite3ext.h" */
3134
+
3135
+SQLITE_EXTENSION_INIT1;
3136
+
3137
+#define PC 0x80 /* pad character */
3138
+#define WS 0x81 /* whitespace */
3139
+#define ND 0x82 /* Not above or digit-value */
3140
+#define PAD_CHAR '='
3141
+
3142
+#ifndef U8_TYPEDEF
3143
+/* typedef unsigned char u8; */
3144
+#define U8_TYPEDEF
3145
+#endif
3146
+
3147
+static const u8 b64DigitValues[128] = {
3148
+ /* HT LF VT FF CR */
3149
+ ND,ND,ND,ND, ND,ND,ND,ND, ND,WS,WS,WS, WS,WS,ND,ND,
3150
+ /* US */
3151
+ ND,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,ND,
3152
+ /*sp + / */
3153
+ WS,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,62, ND,ND,ND,63,
3154
+ /* 0 1 5 9 = */
3155
+ 52,53,54,55, 56,57,58,59, 60,61,ND,ND, ND,PC,ND,ND,
3156
+ /* A O */
3157
+ ND, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
3158
+ /* P Z */
3159
+ 15,16,17,18, 19,20,21,22, 23,24,25,ND, ND,ND,ND,ND,
3160
+ /* a o */
3161
+ ND,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
3162
+ /* p z */
3163
+ 41,42,43,44, 45,46,47,48, 49,50,51,ND, ND,ND,ND,ND
3164
+};
3165
+
3166
+static const char b64Numerals[64+1]
3167
+= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3168
+
3169
+#define BX_DV_PROTO(c) \
3170
+ ((((u8)(c))<0x80)? (u8)(b64DigitValues[(u8)(c)]) : 0x80)
3171
+#define IS_BX_DIGIT(bdp) (((u8)(bdp))<0x80)
3172
+#define IS_BX_WS(bdp) ((bdp)==WS)
3173
+#define IS_BX_PAD(bdp) ((bdp)==PC)
3174
+#define BX_NUMERAL(dv) (b64Numerals[(u8)(dv)])
3175
+/* Width of base64 lines. Should be an integer multiple of 4. */
3176
+#define B64_DARK_MAX 72
3177
+
3178
+/* Encode a byte buffer into base64 text with linefeeds appended to limit
3179
+** encoded group lengths to B64_DARK_MAX or to terminate the last group.
3180
+*/
3181
+static char* toBase64( u8 *pIn, int nbIn, char *pOut ){
3182
+ int nCol = 0;
3183
+ while( nbIn >= 3 ){
3184
+ /* Do the bit-shuffle, exploiting unsigned input to avoid masking. */
3185
+ pOut[0] = BX_NUMERAL(pIn[0]>>2);
3186
+ pOut[1] = BX_NUMERAL(((pIn[0]<<4)|(pIn[1]>>4))&0x3f);
3187
+ pOut[2] = BX_NUMERAL(((pIn[1]&0xf)<<2)|(pIn[2]>>6));
3188
+ pOut[3] = BX_NUMERAL(pIn[2]&0x3f);
3189
+ pOut += 4;
3190
+ nbIn -= 3;
3191
+ pIn += 3;
3192
+ if( (nCol += 4)>=B64_DARK_MAX || nbIn<=0 ){
3193
+ *pOut++ = '\n';
3194
+ nCol = 0;
3195
+ }
3196
+ }
3197
+ if( nbIn > 0 ){
3198
+ signed char nco = nbIn+1;
3199
+ int nbe;
3200
+ unsigned long qv = *pIn++;
3201
+ for( nbe=1; nbe<3; ++nbe ){
3202
+ qv <<= 8;
3203
+ if( nbe<nbIn ) qv |= *pIn++;
3204
+ }
3205
+ for( nbe=3; nbe>=0; --nbe ){
3206
+ char ce = (nbe<nco)? BX_NUMERAL((u8)(qv & 0x3f)) : PAD_CHAR;
3207
+ qv >>= 6;
3208
+ pOut[nbe] = ce;
3209
+ }
3210
+ pOut += 4;
3211
+ *pOut++ = '\n';
3212
+ }
3213
+ *pOut = 0;
3214
+ return pOut;
3215
+}
3216
+
3217
+/* Skip over text which is not base64 numeral(s). */
3218
+static char * skipNonB64( char *s ){
3219
+ char c;
3220
+ while( (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
3221
+ return s;
3222
+}
3223
+
3224
+/* Decode base64 text into a byte buffer. */
3225
+static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
3226
+ if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3227
+ while( ncIn>0 && *pIn!=PAD_CHAR ){
3228
+ static signed char nboi[] = { 0, 0, 1, 2, 3 };
3229
+ char *pUse = skipNonB64(pIn);
3230
+ unsigned long qv = 0L;
3231
+ int nti, nbo, nac;
3232
+ ncIn -= (pUse - pIn);
3233
+ pIn = pUse;
3234
+ nti = (ncIn>4)? 4 : ncIn;
3235
+ ncIn -= nti;
3236
+ nbo = nboi[nti];
3237
+ if( nbo==0 ) break;
3238
+ for( nac=0; nac<4; ++nac ){
3239
+ char c = (nac<nti)? *pIn++ : b64Numerals[0];
3240
+ u8 bdp = BX_DV_PROTO(c);
3241
+ switch( bdp ){
3242
+ case ND:
3243
+ /* Treat dark non-digits as pad, but they terminate decode too. */
3244
+ ncIn = 0;
3245
+ /* fall thru */
3246
+ case WS:
3247
+ /* Treat whitespace as pad and terminate this group.*/
3248
+ nti = nac;
3249
+ /* fall thru */
3250
+ case PC:
3251
+ bdp = 0;
3252
+ --nbo;
3253
+ /* fall thru */
3254
+ default: /* bdp is the digit value. */
3255
+ qv = qv<<6 | bdp;
3256
+ break;
3257
+ }
3258
+ }
3259
+ switch( nbo ){
3260
+ case 3:
3261
+ pOut[2] = (qv) & 0xff;
3262
+ case 2:
3263
+ pOut[1] = (qv>>8) & 0xff;
3264
+ case 1:
3265
+ pOut[0] = (qv>>16) & 0xff;
3266
+ }
3267
+ pOut += nbo;
3268
+ }
3269
+ return pOut;
3270
+}
3271
+
3272
+/* This function does the work for the SQLite base64(x) UDF. */
3273
+static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
3274
+ int nb, nc, nv = sqlite3_value_bytes(av[0]);
3275
+ int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
3276
+ SQLITE_LIMIT_LENGTH, -1);
3277
+ char *cBuf;
3278
+ u8 *bBuf;
3279
+ assert(na==1);
3280
+ switch( sqlite3_value_type(av[0]) ){
3281
+ case SQLITE_BLOB:
3282
+ nb = nv;
3283
+ nc = 4*(nv+2/3); /* quads needed */
3284
+ nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
3285
+ if( nvMax < nc ){
3286
+ sqlite3_result_error(context, "blob expanded to base64 too big", -1);
3287
+ return;
3288
+ }
3289
+ cBuf = sqlite3_malloc(nc);
3290
+ if( !cBuf ) goto memFail;
3291
+ bBuf = (u8*)sqlite3_value_blob(av[0]);
3292
+ nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
3293
+ sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3294
+ break;
3295
+ case SQLITE_TEXT:
3296
+ nc = nv;
3297
+ nb = 3*((nv+3)/4); /* may overestimate due to LF and padding */
3298
+ if( nvMax < nb ){
3299
+ sqlite3_result_error(context, "blob from base64 may be too big", -1);
3300
+ return;
3301
+ }else if( nb<1 ){
3302
+ nb = 1;
3303
+ }
3304
+ bBuf = sqlite3_malloc(nb);
3305
+ if( !bBuf ) goto memFail;
3306
+ cBuf = (char *)sqlite3_value_text(av[0]);
3307
+ nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
3308
+ sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3309
+ break;
3310
+ default:
3311
+ sqlite3_result_error(context, "base64 accepts only blob or text", -1);
3312
+ return;
3313
+ }
3314
+ return;
3315
+ memFail:
3316
+ sqlite3_result_error(context, "base64 OOM", -1);
3317
+}
3318
+
3319
+/*
3320
+** Establish linkage to running SQLite library.
3321
+*/
3322
+#ifndef SQLITE_SHELL_EXTFUNCS
3323
+#ifdef _WIN32
3324
+
3325
+#endif
3326
+int sqlite3_base_init
3327
+#else
3328
+static int sqlite3_base64_init
3329
+#endif
3330
+(sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi){
3331
+ SQLITE_EXTENSION_INIT2(pApi);
3332
+ (void)pzErr;
3333
+ return sqlite3_create_function
3334
+ (db, "base64", 1,
3335
+ SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|SQLITE_DIRECTONLY|SQLITE_UTF8,
3336
+ 0, base64, 0, 0);
3337
+}
3338
+
3339
+/*
3340
+** Define some macros to allow this extension to be built into the shell
3341
+** conveniently, in conjunction with use of SQLITE_SHELL_EXTFUNCS. This
3342
+** allows shell.c, as distributed, to have this extension built in.
3343
+*/
3344
+#define BASE64_INIT(db) sqlite3_base64_init(db, 0, 0)
3345
+#define BASE64_EXPOSE(db, pzErr) /* Not needed, ..._init() does this. */
3346
+
3347
+/************************* End ../ext/misc/base64.c ********************/
3348
+#undef sqlite3_base_init
3349
+#define sqlite3_base_init sqlite3_base85_init
3350
+#define OMIT_BASE85_CHECKER
3351
+/************************* Begin ../ext/misc/base85.c ******************/
3352
+/*
3353
+** 2022-11-16
3354
+**
3355
+** The author disclaims copyright to this source code. In place of
3356
+** a legal notice, here is a blessing:
3357
+**
3358
+** May you do good and not evil.
3359
+** May you find forgiveness for yourself and forgive others.
3360
+** May you share freely, never taking more than you give.
3361
+**
3362
+*************************************************************************
3363
+**
3364
+** This is a utility for converting binary to base85 or vice-versa.
3365
+** It can be built as a standalone program or an SQLite3 extension.
3366
+**
3367
+** Much like base64 representations, base85 can be sent through a
3368
+** sane USASCII channel unmolested. It also plays nicely in CSV or
3369
+** written as TCL brace-enclosed literals or SQL string literals.
3370
+** It is not suited for unmodified use in XML-like documents.
3371
+**
3372
+** The encoding used resembles Ascii85, but was devised by the author
3373
+** (Larry Brasfield) before Mozilla, Adobe, ZMODEM or other Ascii85
3374
+** variant sources existed, in the 1984 timeframe on a VAX mainframe.
3375
+** Further, this is an independent implementation of a base85 system.
3376
+** Hence, the author has rightfully put this into the public domain.
3377
+**
3378
+** Base85 numerals are taken from the set of 7-bit USASCII codes,
3379
+** excluding control characters and Space ! " ' ( ) { | } ~ Del
3380
+** in code order representing digit values 0 to 84 (base 10.)
3381
+**
3382
+** Groups of 4 bytes, interpreted as big-endian 32-bit values,
3383
+** are represented as 5-digit base85 numbers with MS to LS digit
3384
+** order. Groups of 1-3 bytes are represented with 2-4 digits,
3385
+** still big-endian but 8-24 bit values. (Using big-endian yields
3386
+** the simplest transition to byte groups smaller than 4 bytes.
3387
+** These byte groups can also be considered base-256 numbers.)
3388
+** Groups of 0 bytes are represented with 0 digits and vice-versa.
3389
+** No pad characters are used; Encoded base85 numeral sequence
3390
+** (aka "group") length maps 1-to-1 to the decoded binary length.
3391
+**
3392
+** Any character not in the base85 numeral set delimits groups.
3393
+** When base85 is streamed or stored in containers of indefinite
3394
+** size, newline is used to separate it into sub-sequences of no
3395
+** more than 80 digits so that fgets() can be used to read it.
3396
+**
3397
+** Length limitations are not imposed except that the runtime
3398
+** SQLite string or blob length limits are respected. Otherwise,
3399
+** any length binary sequence can be represented and recovered.
3400
+** Base85 sequences can be concatenated by separating them with
3401
+** a non-base85 character; the conversion to binary will then
3402
+** be the concatenation of the represented binary sequences.
3403
+
3404
+** The standalone program either converts base85 on stdin to create
3405
+** a binary file or converts a binary file to base85 on stdout.
3406
+** Read or make it blurt its help for invocation details.
3407
+**
3408
+** The SQLite3 extension creates a function, base85(x), which will
3409
+** either convert text base85 to a blob or a blob to text base85
3410
+** and return the result (or throw an error for other types.)
3411
+** Unless built with OMIT_BASE85_CHECKER defined, it also creates a
3412
+** function, is_base85(t), which returns 1 iff the text t contains
3413
+** nothing other than base85 numerals and whitespace, or 0 otherwise.
3414
+**
3415
+** To build the extension:
3416
+** Set shell variable SQDIR=<your favorite SQLite checkout directory>
3417
+** and variable OPTS to -DOMIT_BASE85_CHECKER if is_base85() unwanted.
3418
+** *Nix: gcc -O2 -shared -I$SQDIR $OPTS -fPIC -o base85.so base85.c
3419
+** OSX: gcc -O2 -dynamiclib -fPIC -I$SQDIR $OPTS -o base85.dylib base85.c
3420
+** Win32: gcc -O2 -shared -I%SQDIR% %OPTS% -o base85.dll base85.c
3421
+** Win32: cl /Os -I%SQDIR% %OPTS% base85.c -link -dll -out:base85.dll
3422
+**
3423
+** To build the standalone program, define PP symbol BASE85_STANDALONE. Eg.
3424
+** *Nix or OSX: gcc -O2 -DBASE85_STANDALONE base85.c -o base85
3425
+** Win32: gcc -O2 -DBASE85_STANDALONE -o base85.exe base85.c
3426
+** Win32: cl /Os /MD -DBASE85_STANDALONE base85.c
3427
+*/
3428
+
3429
+#include <stdio.h>
3430
+#include <memory.h>
3431
+#include <string.h>
3432
+#include <assert.h>
3433
+#ifndef OMIT_BASE85_CHECKER
3434
+# include <ctype.h>
3435
+#endif
3436
+
3437
+#ifndef BASE85_STANDALONE
3438
+
3439
+/* # include "sqlite3ext.h" */
3440
+
3441
+SQLITE_EXTENSION_INIT1;
3442
+
3443
+#else
3444
+
3445
+# ifdef _WIN32
3446
+# include <io.h>
3447
+# include <fcntl.h>
3448
+# else
3449
+# define setmode(fd,m)
3450
+# endif
3451
+
3452
+static char *zHelp =
3453
+ "Usage: base85 <dirFlag> <binFile>\n"
3454
+ " <dirFlag> is either -r to read or -w to write <binFile>,\n"
3455
+ " content to be converted to/from base85 on stdout/stdin.\n"
3456
+ " <binFile> names a binary file to be rendered or created.\n"
3457
+ " Or, the name '-' refers to the stdin or stdout stream.\n"
3458
+ ;
3459
+
3460
+static void sayHelp(){
3461
+ printf("%s", zHelp);
3462
+}
3463
+#endif
3464
+
3465
+#ifndef U8_TYPEDEF
3466
+/* typedef unsigned char u8; */
3467
+#define U8_TYPEDEF
3468
+#endif
3469
+
3470
+/* Classify c according to interval within USASCII set w.r.t. base85
3471
+ * Values of 1 and 3 are base85 numerals. Values of 0, 2, or 4 are not.
3472
+ */
3473
+#define B85_CLASS( c ) (((c)>='#')+((c)>'&')+((c)>='*')+((c)>'z'))
3474
+
3475
+/* Provide digitValue to b85Numeral offset as a function of above class. */
3476
+static u8 b85_cOffset[] = { 0, '#', 0, '*'-4, 0 };
3477
+#define B85_DNOS( c ) b85_cOffset[B85_CLASS(c)]
3478
+
3479
+/* Say whether c is a base85 numeral. */
3480
+#define IS_B85( c ) (B85_CLASS(c) & 1)
3481
+
3482
+#if 0 /* Not used, */
3483
+static u8 base85DigitValue( char c ){
3484
+ u8 dv = (u8)(c - '#');
3485
+ if( dv>87 ) return 0xff;
3486
+ return (dv > 3)? dv-3 : dv;
3487
+}
3488
+#endif
3489
+
3490
+/* Width of base64 lines. Should be an integer multiple of 5. */
3491
+#define B85_DARK_MAX 80
3492
+
3493
+
3494
+static char * skipNonB85( char *s ){
3495
+ char c;
3496
+ while( (c = *s) && !IS_B85(c) ) ++s;
3497
+ return s;
3498
+}
3499
+
3500
+/* Convert small integer, known to be in 0..84 inclusive, to base85 numeral.
3501
+ * Do not use the macro form with argument expression having a side-effect.*/
3502
+#if 0
3503
+static char base85Numeral( u8 b ){
3504
+ return (b < 4)? (char)(b + '#') : (char)(b - 4 + '*');
3505
+}
3506
+#else
3507
+# define base85Numeral( dn )\
3508
+ ((char)(((dn) < 4)? (char)((dn) + '#') : (char)((dn) - 4 + '*')))
3509
+#endif
3510
+
3511
+static char *putcs(char *pc, char *s){
3512
+ char c;
3513
+ while( (c = *s++)!=0 ) *pc++ = c;
3514
+ return pc;
3515
+}
3516
+
3517
+/* Encode a byte buffer into base85 text. If pSep!=0, it's a C string
3518
+** to be appended to encoded groups to limit their length to B85_DARK_MAX
3519
+** or to terminate the last group (to aid concatenation.)
3520
+*/
3521
+static char* toBase85( u8 *pIn, int nbIn, char *pOut, char *pSep ){
3522
+ int nCol = 0;
3523
+ while( nbIn >= 4 ){
3524
+ int nco = 5;
3525
+ unsigned long qbv = (pIn[0]<<24)|(pIn[1]<<16)|(pIn[2]<<8)|pIn[3];
3526
+ while( nco > 0 ){
3527
+ unsigned nqv = (unsigned)(qbv/85UL);
3528
+ unsigned char dv = qbv - 85UL*nqv;
3529
+ qbv = nqv;
3530
+ pOut[--nco] = base85Numeral(dv);
3531
+ }
3532
+ nbIn -= 4;
3533
+ pIn += 4;
3534
+ pOut += 5;
3535
+ if( pSep && (nCol += 5)>=B85_DARK_MAX ){
3536
+ pOut = putcs(pOut, pSep);
3537
+ nCol = 0;
3538
+ }
3539
+ }
3540
+ if( nbIn > 0 ){
3541
+ int nco = nbIn + 1;
3542
+ unsigned long qv = *pIn++;
3543
+ int nbe = 1;
3544
+ while( nbe++ < nbIn ){
3545
+ qv = (qv<<8) | *pIn++;
3546
+ }
3547
+ nCol += nco;
3548
+ while( nco > 0 ){
3549
+ u8 dv = (u8)(qv % 85);
3550
+ qv /= 85;
3551
+ pOut[--nco] = base85Numeral(dv);
3552
+ }
3553
+ pOut += (nbIn+1);
3554
+ }
3555
+ if( pSep && nCol>0 ) pOut = putcs(pOut, pSep);
3556
+ *pOut = 0;
3557
+ return pOut;
3558
+}
3559
+
3560
+/* Decode base85 text into a byte buffer. */
3561
+static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
3562
+ if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3563
+ while( ncIn>0 ){
3564
+ static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
3565
+ char *pUse = skipNonB85(pIn);
3566
+ unsigned long qv = 0L;
3567
+ int nti, nbo;
3568
+ ncIn -= (pUse - pIn);
3569
+ pIn = pUse;
3570
+ nti = (ncIn>5)? 5 : ncIn;
3571
+ nbo = nboi[nti];
3572
+ if( nbo==0 ) break;
3573
+ while( nti>0 ){
3574
+ char c = *pIn++;
3575
+ u8 cdo = B85_DNOS(c);
3576
+ --ncIn;
3577
+ if( cdo==0 ) break;
3578
+ qv = 85 * qv + (c - cdo);
3579
+ --nti;
3580
+ }
3581
+ nbo -= nti; /* Adjust for early (non-digit) end of group. */
3582
+ switch( nbo ){
3583
+ case 4:
3584
+ *pOut++ = (qv >> 24)&0xff;
3585
+ case 3:
3586
+ *pOut++ = (qv >> 16)&0xff;
3587
+ case 2:
3588
+ *pOut++ = (qv >> 8)&0xff;
3589
+ case 1:
3590
+ *pOut++ = qv&0xff;
3591
+ case 0:
3592
+ break;
3593
+ }
3594
+ }
3595
+ return pOut;
3596
+}
3597
+
3598
+#ifndef OMIT_BASE85_CHECKER
3599
+/* Say whether input char sequence is all (base85 and/or whitespace).*/
3600
+static int allBase85( char *p, int len ){
3601
+ char c;
3602
+ while( len-- > 0 && (c = *p++) != 0 ){
3603
+ if( !IS_B85(c) && !isspace(c) ) return 0;
3604
+ }
3605
+ return 1;
3606
+}
3607
+#endif
3608
+
3609
+#ifndef BASE85_STANDALONE
3610
+
3611
+# ifndef OMIT_BASE85_CHECKER
3612
+/* This function does the work for the SQLite is_base85(t) UDF. */
3613
+static void is_base85(sqlite3_context *context, int na, sqlite3_value *av[]){
3614
+ assert(na==1);
3615
+ switch( sqlite3_value_type(av[0]) ){
3616
+ case SQLITE_TEXT:
3617
+ {
3618
+ int rv = allBase85( (char *)sqlite3_value_text(av[0]),
3619
+ sqlite3_value_bytes(av[0]) );
3620
+ sqlite3_result_int(context, rv);
3621
+ }
3622
+ break;
3623
+ case SQLITE_NULL:
3624
+ sqlite3_result_null(context);
3625
+ break;
3626
+ default:
3627
+ sqlite3_result_error(context, "is_base85 accepts only text or NULL", -1);
3628
+ return;
3629
+ }
3630
+}
3631
+# endif
3632
+
3633
+/* This function does the work for the SQLite base85(x) UDF. */
3634
+static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
3635
+ int nb, nc, nv = sqlite3_value_bytes(av[0]);
3636
+ int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
3637
+ SQLITE_LIMIT_LENGTH, -1);
3638
+ char *cBuf;
3639
+ u8 *bBuf;
3640
+ assert(na==1);
3641
+ switch( sqlite3_value_type(av[0]) ){
3642
+ case SQLITE_BLOB:
3643
+ nb = nv;
3644
+ /* ulongs tail newlines tailenc+nul*/
3645
+ nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
3646
+ if( nvMax < nc ){
3647
+ sqlite3_result_error(context, "blob expanded to base85 too big", -1);
3648
+ return;
3649
+ }
3650
+ cBuf = sqlite3_malloc(nc);
3651
+ if( !cBuf ) goto memFail;
3652
+ bBuf = (u8*)sqlite3_value_blob(av[0]);
3653
+ nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
3654
+ sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3655
+ break;
3656
+ case SQLITE_TEXT:
3657
+ nc = nv;
3658
+ nb = 4*(nv/5) + nv%5; /* may overestimate */
3659
+ if( nvMax < nb ){
3660
+ sqlite3_result_error(context, "blob from base85 may be too big", -1);
3661
+ return;
3662
+ }else if( nb<1 ){
3663
+ nb = 1;
3664
+ }
3665
+ bBuf = sqlite3_malloc(nb);
3666
+ if( !bBuf ) goto memFail;
3667
+ cBuf = (char *)sqlite3_value_text(av[0]);
3668
+ nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
3669
+ sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3670
+ break;
3671
+ default:
3672
+ sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
3673
+ return;
3674
+ }
3675
+ return;
3676
+ memFail:
3677
+ sqlite3_result_error(context, "base85 OOM", -1);
3678
+}
3679
+
3680
+/*
3681
+** Establish linkage to running SQLite library.
3682
+*/
3683
+#ifndef SQLITE_SHELL_EXTFUNCS
3684
+#ifdef _WIN32
3685
+
3686
+#endif
3687
+int sqlite3_base_init
3688
+#else
3689
+static int sqlite3_base85_init
3690
+#endif
3691
+(sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi){
3692
+ SQLITE_EXTENSION_INIT2(pApi);
3693
+ (void)pzErr;
3694
+# ifndef OMIT_BASE85_CHECKER
3695
+ {
3696
+ int rc = sqlite3_create_function
3697
+ (db, "is_base85", 1,
3698
+ SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|SQLITE_UTF8,
3699
+ 0, is_base85, 0, 0);
3700
+ if( rc!=SQLITE_OK ) return rc;
3701
+ }
3702
+# endif
3703
+ return sqlite3_create_function
3704
+ (db, "base85", 1,
3705
+ SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|SQLITE_DIRECTONLY|SQLITE_UTF8,
3706
+ 0, base85, 0, 0);
3707
+}
3708
+
3709
+/*
3710
+** Define some macros to allow this extension to be built into the shell
3711
+** conveniently, in conjunction with use of SQLITE_SHELL_EXTFUNCS. This
3712
+** allows shell.c, as distributed, to have this extension built in.
3713
+*/
3714
+# define BASE85_INIT(db) sqlite3_base85_init(db, 0, 0)
3715
+# define BASE85_EXPOSE(db, pzErr) /* Not needed, ..._init() does this. */
3716
+
3717
+#else /* standalone program */
3718
+
3719
+int main(int na, char *av[]){
3720
+ int cin;
3721
+ int rc = 0;
3722
+ u8 bBuf[4*(B85_DARK_MAX/5)];
3723
+ char cBuf[5*(sizeof(bBuf)/4)+2];
3724
+ size_t nio;
3725
+# ifndef OMIT_BASE85_CHECKER
3726
+ int b85Clean = 1;
3727
+# endif
3728
+ char rw;
3729
+ FILE *fb = 0, *foc = 0;
3730
+ char fmode[3] = "xb";
3731
+ if( na < 3 || av[1][0]!='-' || (rw = av[1][1])==0 || (rw!='r' && rw!='w') ){
3732
+ sayHelp();
3733
+ return 0;
3734
+ }
3735
+ fmode[0] = rw;
3736
+ if( av[2][0]=='-' && av[2][1]==0 ){
3737
+ switch( rw ){
3738
+ case 'r':
3739
+ fb = stdin;
3740
+ setmode(fileno(stdin), O_BINARY);
3741
+ break;
3742
+ case 'w':
3743
+ fb = stdout;
3744
+ setmode(fileno(stdout), O_BINARY);
3745
+ break;
3746
+ }
3747
+ }else{
3748
+ fb = fopen(av[2], fmode);
3749
+ foc = fb;
3750
+ }
3751
+ if( !fb ){
3752
+ fprintf(stderr, "Cannot open %s for %c\n", av[2], rw);
3753
+ rc = 1;
3754
+ }else{
3755
+ switch( rw ){
3756
+ case 'r':
3757
+ while( (nio = fread( bBuf, 1, sizeof(bBuf), fb))>0 ){
3758
+ toBase85( bBuf, (int)nio, cBuf, 0 );
3759
+ fprintf(stdout, "%s\n", cBuf);
3760
+ }
3761
+ break;
3762
+ case 'w':
3763
+ while( 0 != fgets(cBuf, sizeof(cBuf), stdin) ){
3764
+ int nc = strlen(cBuf);
3765
+ size_t nbo = fromBase85( cBuf, nc, bBuf ) - bBuf;
3766
+ if( 1 != fwrite(bBuf, nbo, 1, fb) ) rc = 1;
3767
+# ifndef OMIT_BASE85_CHECKER
3768
+ b85Clean &= allBase85( cBuf, nc );
3769
+# endif
3770
+ }
3771
+ break;
3772
+ default:
3773
+ sayHelp();
3774
+ rc = 1;
3775
+ }
3776
+ if( foc ) fclose(foc);
3777
+ }
3778
+# ifndef OMIT_BASE85_CHECKER
3779
+ if( !b85Clean ){
3780
+ fprintf(stderr, "Base85 input had non-base85 dark or control content.\n");
3781
+ }
3782
+# endif
3783
+ return rc;
3784
+}
3785
+
3786
+#endif
3787
+
3788
+/************************* End ../ext/misc/base85.c ********************/
30743789
/************************* Begin ../ext/misc/ieee754.c ******************/
30753790
/*
30763791
** 2013-04-17
30773792
**
30783793
** The author disclaims copyright to this source code. In place of
@@ -4633,10 +5348,11 @@
46335348
ReCompiled *pRe;
46345349
sqlite3_str *pStr;
46355350
int i;
46365351
int n;
46375352
char *z;
5353
+ (void)argc;
46385354
46395355
zPattern = (const char*)sqlite3_value_text(argv[0]);
46405356
if( zPattern==0 ) return;
46415357
zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
46425358
if( zErr ){
@@ -7280,10 +7996,11 @@
72807996
int nByte = sizeof(ZipfileTab) + ZIPFILE_BUFFER_SIZE;
72817997
int nFile = 0;
72827998
const char *zFile = 0;
72837999
ZipfileTab *pNew = 0;
72848000
int rc;
8001
+ (void)pAux;
72858002
72868003
/* If the table name is not "zipfile", require that the argument be
72878004
** specified. This stops zipfile tables from being created as:
72888005
**
72898006
** CREATE VIRTUAL TABLE zzz USING zipfile();
@@ -7736,10 +8453,11 @@
77368453
ZipfileEntry **ppEntry /* OUT: Pointer to new object */
77378454
){
77388455
u8 *aRead;
77398456
char **pzErr = &pTab->base.zErrMsg;
77408457
int rc = SQLITE_OK;
8458
+ (void)nBlob;
77418459
77428460
if( aBlob==0 ){
77438461
aRead = pTab->aBuffer;
77448462
rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr);
77458463
}else{
@@ -8181,10 +8899,13 @@
81818899
ZipfileTab *pTab = (ZipfileTab*)cur->pVtab;
81828900
ZipfileCsr *pCsr = (ZipfileCsr*)cur;
81838901
const char *zFile = 0; /* Zip file to scan */
81848902
int rc = SQLITE_OK; /* Return Code */
81858903
int bInMemory = 0; /* True for an in-memory zipfile */
8904
+
8905
+ (void)idxStr;
8906
+ (void)argc;
81868907
81878908
zipfileResetCursor(pCsr);
81888909
81898910
if( pTab->zFile ){
81908911
zFile = pTab->zFile;
@@ -8242,10 +8963,11 @@
82428963
sqlite3_index_info *pIdxInfo
82438964
){
82448965
int i;
82458966
int idx = -1;
82468967
int unusable = 0;
8968
+ (void)tab;
82478969
82488970
for(i=0; i<pIdxInfo->nConstraint; i++){
82498971
const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
82508972
if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue;
82518973
if( pCons->usable==0 ){
@@ -8491,10 +9213,12 @@
84919213
ZipfileEntry *pOld = 0;
84929214
ZipfileEntry *pOld2 = 0;
84939215
int bUpdate = 0; /* True for an update that modifies "name" */
84949216
int bIsDir = 0;
84959217
u32 iCrc32 = 0;
9218
+
9219
+ (void)pRowid;
84969220
84979221
if( pTab->pWriteFd==0 ){
84989222
rc = zipfileBegin(pVtab);
84999223
if( rc!=SQLITE_OK ) return rc;
85009224
}
@@ -8826,10 +9550,11 @@
88269550
int nArg, /* Number of SQL function arguments */
88279551
const char *zName, /* Name of SQL function */
88289552
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
88299553
void **ppArg /* OUT: User data for *pxFunc */
88309554
){
9555
+ (void)nArg;
88319556
if( sqlite3_stricmp("zipfile_cds", zName)==0 ){
88329557
*pxFunc = zipfileFunctionCds;
88339558
*ppArg = (void*)pVtab;
88349559
return 1;
88359560
}
@@ -11917,10 +12642,13 @@
1191712642
char **pzErr
1191812643
){
1191912644
DbdataTable *pTab = 0;
1192012645
int rc = sqlite3_declare_vtab(db, pAux ? DBPTR_SCHEMA : DBDATA_SCHEMA);
1192112646
12647
+ (void)argc;
12648
+ (void)argv;
12649
+ (void)pzErr;
1192212650
if( rc==SQLITE_OK ){
1192312651
pTab = (DbdataTable*)sqlite3_malloc64(sizeof(DbdataTable));
1192412652
if( pTab==0 ){
1192512653
rc = SQLITE_NOMEM;
1192612654
}else{
@@ -12521,10 +13249,12 @@
1252113249
){
1252213250
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
1252313251
DbdataTable *pTab = (DbdataTable*)pCursor->pVtab;
1252413252
int rc = SQLITE_OK;
1252513253
const char *zSchema = "main";
13254
+ (void)idxStr;
13255
+ (void)argc;
1252613256
1252713257
dbdataResetCursor(pCsr);
1252813258
assert( pCsr->iPgno==1 );
1252913259
if( idxNum & 0x01 ){
1253013260
zSchema = (const char*)sqlite3_value_text(argv[0]);
@@ -12689,10 +13419,11 @@
1268913419
sqlite3 *db,
1269013420
char **pzErrMsg,
1269113421
const sqlite3_api_routines *pApi
1269213422
){
1269313423
SQLITE_EXTENSION_INIT2(pApi);
13424
+ (void)pzErrMsg;
1269413425
return sqlite3DbdataRegister(db);
1269513426
}
1269613427
1269713428
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
1269813429
@@ -13459,10 +14190,11 @@
1345914190
sqlite3_context *context,
1346014191
int argc,
1346114192
sqlite3_value **argv
1346214193
){
1346314194
const char *zText = (const char*)sqlite3_value_text(argv[0]);
14195
+ (void)argc;
1346414196
if( zText && zText[0]=='\'' ){
1346514197
int nText = sqlite3_value_bytes(argv[0]);
1346614198
int i;
1346714199
char zBuf1[20];
1346814200
char zBuf2[20];
@@ -13611,11 +14343,11 @@
1361114343
if( rc!=SQLITE_OK ){
1361214344
recoverDbError(p, db2);
1361314345
return;
1361414346
}
1361514347
13616
- for(ii=0; ii<sizeof(aPragma)/sizeof(aPragma[0]); ii++){
14348
+ for(ii=0; ii<(int)(sizeof(aPragma)/sizeof(aPragma[0])); ii++){
1361714349
const char *zPrag = aPragma[ii];
1361814350
sqlite3_stmt *p1 = 0;
1361914351
p1 = recoverPreparePrintf(p, p->dbIn, "PRAGMA %Q.%s", p->zDb, zPrag);
1362014352
if( p->errCode==SQLITE_OK && sqlite3_step(p1)==SQLITE_ROW ){
1362114353
const char *zArg = (const char*)sqlite3_column_text(p1, 0);
@@ -13689,11 +14421,13 @@
1368914421
if( p->errCode==SQLITE_OK ){
1369014422
p->errCode = sqlite3_dbdata_init(db, 0, 0);
1369114423
}
1369214424
1369314425
/* Register the custom user-functions with the output handle. */
13694
- for(ii=0; p->errCode==SQLITE_OK && ii<sizeof(aFunc)/sizeof(aFunc[0]); ii++){
14426
+ for(ii=0;
14427
+ p->errCode==SQLITE_OK && ii<(int)(sizeof(aFunc)/sizeof(aFunc[0]));
14428
+ ii++){
1369514429
p->errCode = sqlite3_create_function(db, aFunc[ii].zName,
1369614430
aFunc[ii].nArg, SQLITE_UTF8, (void*)p, aFunc[ii].xFunc, 0, 0
1369714431
);
1369814432
}
1369914433
@@ -15086,11 +15820,11 @@
1508615820
recoverPutU32(&aHdr[56], enc);
1508715821
recoverPutU16(&aHdr[105], pgsz-nReserve);
1508815822
if( pgsz==65536 ) pgsz = 1;
1508915823
recoverPutU16(&aHdr[16], pgsz);
1509015824
aHdr[20] = nReserve;
15091
- for(ii=0; ii<sizeof(aPreserve)/sizeof(aPreserve[0]); ii++){
15825
+ for(ii=0; ii<(int)(sizeof(aPreserve)/sizeof(aPreserve[0])); ii++){
1509215826
memcpy(&aHdr[aPreserve[ii]], &a[aPreserve[ii]], 4);
1509315827
}
1509415828
memcpy(aBuf, aHdr, sizeof(aHdr));
1509515829
memset(&((u8*)aBuf)[sizeof(aHdr)], 0, nByte-sizeof(aHdr));
1509615830
@@ -15210,14 +15944,20 @@
1521015944
sqlite3_file *pFd,
1521115945
sqlite3_int64 iOff,
1521215946
int iAmt,
1521315947
void **pp
1521415948
){
15949
+ (void)pFd;
15950
+ (void)iOff;
15951
+ (void)iAmt;
1521515952
*pp = 0;
1521615953
return SQLITE_OK;
1521715954
}
1521815955
static int recoverVfsUnfetch(sqlite3_file *pFd, sqlite3_int64 iOff, void *p){
15956
+ (void)pFd;
15957
+ (void)iOff;
15958
+ (void)p;
1521915959
return SQLITE_OK;
1522015960
}
1522115961
1522215962
/*
1522315963
** Install the VFS wrapper around the file-descriptor open on the input
@@ -15990,11 +16730,11 @@
1599016730
if( p[i]=='\r' && p[i+1]=='\n' ) i++;
1599116731
p[j++] = p[i];
1599216732
}
1599316733
sz = j;
1599416734
p[sz] = 0;
15995
- }
16735
+ }
1599616736
sqlite3_result_text64(context, (const char*)p, sz,
1599716737
sqlite3_free, SQLITE_UTF8);
1599816738
}
1599916739
p = 0;
1600016740
@@ -17165,13 +17905,13 @@
1716517905
}
1716617906
zCode = sqlite3_mprintf("%.*s", len, zSql);
1716717907
shell_check_oom(zCode);
1716817908
for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; }
1716917909
if( iOffset<25 ){
17170
- zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode, iOffset, "");
17910
+ zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode,iOffset,"");
1717117911
}else{
17172
- zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode, iOffset-14, "");
17912
+ zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode,iOffset-14,"");
1717317913
}
1717417914
return zMsg;
1717517915
}
1717617916
1717717917
@@ -17355,11 +18095,11 @@
1735518095
}
1735618096
}
1735718097
1735818098
if( pArg->statsOn==3 ){
1735918099
if( pArg->pStmt ){
17360
- iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
18100
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP,bReset);
1736118101
raw_printf(pArg->out, "VM-steps: %d\n", iCur);
1736218102
}
1736318103
return 0;
1736418104
}
1736518105
@@ -17436,12 +18176,14 @@
1743618176
raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur);
1743718177
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1743818178
raw_printf(pArg->out, "Sort Operations: %d\n", iCur);
1743918179
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1744018180
raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur);
17441
- iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT, bReset);
17442
- iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS, bReset);
18181
+ iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT,
18182
+ bReset);
18183
+ iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS,
18184
+ bReset);
1744318185
if( iHit || iMiss ){
1744418186
raw_printf(pArg->out, "Bloom filter bypass taken: %d/%d\n",
1744518187
iHit, iHit+iMiss);
1744618188
}
1744718189
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
@@ -17466,24 +18208,24 @@
1746618208
1746718209
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
1746818210
static int scanStatsHeight(sqlite3_stmt *p, int iEntry){
1746918211
int iPid = 0;
1747018212
int ret = 1;
17471
- sqlite3_stmt_scanstatus_v2(p, iEntry,
18213
+ sqlite3_stmt_scanstatus_v2(p, iEntry,
1747218214
SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
1747318215
);
1747418216
while( iPid!=0 ){
1747518217
int ii;
1747618218
for(ii=0; 1; ii++){
1747718219
int iId;
1747818220
int res;
17479
- res = sqlite3_stmt_scanstatus_v2(p, ii,
18221
+ res = sqlite3_stmt_scanstatus_v2(p, ii,
1748018222
SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iId
1748118223
);
1748218224
if( res ) break;
1748318225
if( iId==iPid ){
17484
- sqlite3_stmt_scanstatus_v2(p, ii,
18226
+ sqlite3_stmt_scanstatus_v2(p, ii,
1748518227
SQLITE_SCANSTAT_PARENTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
1748618228
);
1748718229
}
1748818230
}
1748918231
ret++;
@@ -17811,11 +18553,11 @@
1781118553
1781218554
/* Draw horizontal line N characters long using unicode box
1781318555
** characters
1781418556
*/
1781518557
static void print_box_line(FILE *out, int N){
17816
- const char zDash[] =
18558
+ const char zDash[] =
1781718559
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24
1781818560
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24;
1781918561
const int nDash = sizeof(zDash) - 1;
1782018562
N *= 3;
1782118563
while( N>nDash ){
@@ -17940,11 +18682,11 @@
1794018682
continue;
1794118683
}
1794218684
break;
1794318685
}
1794418686
zOut[j] = 0;
17945
- return (char*)zOut;
18687
+ return (char*)zOut;
1794618688
}
1794718689
1794818690
/* Extract the value of the i-th current column for pStmt as an SQL literal
1794918691
** value. Memory is obtained from sqlite3_malloc64() and must be freed by
1795018692
** the caller.
@@ -18301,22 +19043,22 @@
1830119043
** code. In this case, (*pzErr) may be set to point to a buffer containing
1830219044
** an English language error message. It is the responsibility of the
1830319045
** caller to eventually free this buffer using sqlite3_free().
1830419046
*/
1830519047
static int expertHandleSQL(
18306
- ShellState *pState,
18307
- const char *zSql,
19048
+ ShellState *pState,
19049
+ const char *zSql,
1830819050
char **pzErr
1830919051
){
1831019052
assert( pState->expert.pExpert );
1831119053
assert( pzErr==0 || *pzErr==0 );
1831219054
return sqlite3_expert_sql(pState->expert.pExpert, zSql, pzErr);
1831319055
}
1831419056
1831519057
/*
1831619058
** This function is called either to silently clean up the object
18317
-** created by the ".expert" command (if bCancel==1), or to generate a
19059
+** created by the ".expert" command (if bCancel==1), or to generate a
1831819060
** report from it and then clean it up (if bCancel==0).
1831919061
**
1832019062
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
1832119063
** code. In this case, (*pzErr) may be set to point to a buffer containing
1832219064
** an English language error message. It is the responsibility of the
@@ -18407,11 +19149,12 @@
1840719149
}
1840819150
1840919151
if( rc==SQLITE_OK ){
1841019152
pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
1841119153
if( pState->expert.pExpert==0 ){
18412
- raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory");
19154
+ raw_printf(stderr, "sqlite3_expert_new: %s\n",
19155
+ zErr ? zErr : "out of memory");
1841319156
rc = SQLITE_ERROR;
1841419157
}else{
1841519158
sqlite3_expert_config(
1841619159
pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
1841719160
);
@@ -19368,11 +20111,11 @@
1936820111
}else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
1936920112
rc = SHELL_OPEN_ZIPFILE;
1937020113
}
1937120114
}
1937220115
fclose(f);
19373
- return rc;
20116
+ return rc;
1937420117
}
1937520118
1937620119
#ifndef SQLITE_OMIT_DESERIALIZE
1937720120
/*
1937820121
** Reconstruct an in-memory database using the output from the "dbtotxt"
@@ -19467,12 +20210,12 @@
1946720210
** must be a blob. The second a non-negative integer. This function
1946820211
** reads and returns a 32-bit big-endian integer from byte
1946920212
** offset (4*<arg2>) of the blob.
1947020213
*/
1947120214
static void shellInt32(
19472
- sqlite3_context *context,
19473
- int argc,
20215
+ sqlite3_context *context,
20216
+ int argc,
1947420217
sqlite3_value **argv
1947520218
){
1947620219
const unsigned char *pBlob;
1947720220
int nBlob;
1947820221
int iInt;
@@ -19495,12 +20238,12 @@
1949520238
/*
1949620239
** Scalar function "shell_idquote(X)" returns string X quoted as an identifier,
1949720240
** using "..." with internal double-quote characters doubled.
1949820241
*/
1949920242
static void shellIdQuote(
19500
- sqlite3_context *context,
19501
- int argc,
20243
+ sqlite3_context *context,
20244
+ int argc,
1950220245
sqlite3_value **argv
1950320246
){
1950420247
const char *zName = (const char*)sqlite3_value_text(argv[0]);
1950520248
UNUSED_PARAMETER(argc);
1950620249
if( zName ){
@@ -19511,12 +20254,12 @@
1951120254
1951220255
/*
1951320256
** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
1951420257
*/
1951520258
static void shellUSleepFunc(
19516
- sqlite3_context *context,
19517
- int argcUnused,
20259
+ sqlite3_context *context,
20260
+ int argcUnused,
1951820261
sqlite3_value **argv
1951920262
){
1952020263
int sleep = sqlite3_value_int(argv[0]);
1952120264
(void)argcUnused;
1952220265
sqlite3_sleep(sleep/1000);
@@ -19524,11 +20267,11 @@
1952420267
}
1952520268
1952620269
/*
1952720270
** Scalar function "shell_escape_crnl" used by the .recover command.
1952820271
** The argument passed to this function is the output of built-in
19529
-** function quote(). If the first character of the input is "'",
20272
+** function quote(). If the first character of the input is "'",
1953020273
** indicating that the value passed to quote() was a text value,
1953120274
** then this function searches the input for "\n" and "\r" characters
1953220275
** and adds a wrapper similar to the following:
1953320276
**
1953420277
** replace(replace(<input>, '\n', char(10), '\r', char(13));
@@ -19535,12 +20278,12 @@
1953520278
**
1953620279
** Or, if the first character of the input is not "'", then a copy
1953720280
** of the input is returned.
1953820281
*/
1953920282
static void shellEscapeCrnl(
19540
- sqlite3_context *context,
19541
- int argc,
20283
+ sqlite3_context *context,
20284
+ int argc,
1954220285
sqlite3_value **argv
1954320286
){
1954420287
const char *zText = (const char*)sqlite3_value_text(argv[0]);
1954520288
UNUSED_PARAMETER(argc);
1954620289
if( zText && zText[0]=='\'' ){
@@ -19636,17 +20379,17 @@
1963620379
const char *zDbFilename = p->pAuxDb->zDbFilename;
1963720380
if( p->openMode==SHELL_OPEN_UNSPEC ){
1963820381
if( zDbFilename==0 || zDbFilename[0]==0 ){
1963920382
p->openMode = SHELL_OPEN_NORMAL;
1964020383
}else{
19641
- p->openMode = (u8)deduceDatabaseType(zDbFilename,
20384
+ p->openMode = (u8)deduceDatabaseType(zDbFilename,
1964220385
(openFlags & OPEN_DB_ZIPFILE)!=0);
1964320386
}
1964420387
}
1964520388
switch( p->openMode ){
1964620389
case SHELL_OPEN_APPENDVFS: {
19647
- sqlite3_open_v2(zDbFilename, &p->db,
20390
+ sqlite3_open_v2(zDbFilename, &p->db,
1964820391
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
1964920392
break;
1965020393
}
1965120394
case SHELL_OPEN_HEXDB:
1965220395
case SHELL_OPEN_DESERIALIZE: {
@@ -19684,10 +20427,12 @@
1968420427
sqlite3_enable_load_extension(p->db, 1);
1968520428
#endif
1968620429
sqlite3_shathree_init(p->db, 0, 0);
1968720430
sqlite3_uint_init(p->db, 0, 0);
1968820431
sqlite3_decimal_init(p->db, 0, 0);
20432
+ sqlite3_base64_init(p->db, 0, 0);
20433
+ sqlite3_base85_init(p->db, 0, 0);
1968920434
sqlite3_regexp_init(p->db, 0, 0);
1969020435
sqlite3_ieee_init(p->db, 0, 0);
1969120436
sqlite3_series_init(p->db, 0, 0);
1969220437
#ifndef SQLITE_SHELL_FIDDLE
1969320438
sqlite3_fileio_init(p->db, 0, 0);
@@ -19795,11 +20540,11 @@
1979520540
void close_db(sqlite3 *db){
1979620541
int rc = sqlite3_close(db);
1979720542
if( rc ){
1979820543
utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
1979920544
rc, sqlite3_errmsg(db));
19800
- }
20545
+ }
1980120546
}
1980220547
1980320548
#if HAVE_READLINE || HAVE_EDITLINE
1980420549
/*
1980520550
** Readline completion callbacks
@@ -19825,10 +20570,12 @@
1982520570
zRet = 0;
1982620571
}
1982720572
return zRet;
1982820573
}
1982920574
static char **readline_completion(const char *zText, int iStart, int iEnd){
20575
+ (void)iStart;
20576
+ (void)iEnd;
1983020577
rl_attempted_completion_over = 1;
1983120578
return rl_completion_matches(zText, readline_completion_generator);
1983220579
}
1983320580
1983420581
#elif HAVE_LINENOISE
@@ -21036,20 +21783,20 @@
2103621783
return SQLITE_ERROR;
2103721784
}
2103821785
2103921786
#if !defined SQLITE_OMIT_VIRTUALTABLE
2104021787
static void shellPrepare(
21041
- sqlite3 *db,
21042
- int *pRc,
21043
- const char *zSql,
21788
+ sqlite3 *db,
21789
+ int *pRc,
21790
+ const char *zSql,
2104421791
sqlite3_stmt **ppStmt
2104521792
){
2104621793
*ppStmt = 0;
2104721794
if( *pRc==SQLITE_OK ){
2104821795
int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
2104921796
if( rc!=SQLITE_OK ){
21050
- raw_printf(stderr, "sql error: %s (%d)\n",
21797
+ raw_printf(stderr, "sql error: %s (%d)\n",
2105121798
sqlite3_errmsg(db), sqlite3_errcode(db)
2105221799
);
2105321800
*pRc = rc;
2105421801
}
2105521802
}
@@ -21061,14 +21808,14 @@
2106121808
** This routine is could be marked "static". But it is not always used,
2106221809
** depending on compile-time options. By omitting the "static", we avoid
2106321810
** nuisance compiler warnings about "defined but not used".
2106421811
*/
2106521812
void shellPreparePrintf(
21066
- sqlite3 *db,
21067
- int *pRc,
21813
+ sqlite3 *db,
21814
+ int *pRc,
2106821815
sqlite3_stmt **ppStmt,
21069
- const char *zFmt,
21816
+ const char *zFmt,
2107021817
...
2107121818
){
2107221819
*ppStmt = 0;
2107321820
if( *pRc==SQLITE_OK ){
2107421821
va_list ap;
@@ -21090,11 +21837,11 @@
2109021837
** This routine is could be marked "static". But it is not always used,
2109121838
** depending on compile-time options. By omitting the "static", we avoid
2109221839
** nuisance compiler warnings about "defined but not used".
2109321840
*/
2109421841
void shellFinalize(
21095
- int *pRc,
21842
+ int *pRc,
2109621843
sqlite3_stmt *pStmt
2109721844
){
2109821845
if( pStmt ){
2109921846
sqlite3 *db = sqlite3_db_handle(pStmt);
2110021847
int rc = sqlite3_finalize(pStmt);
@@ -21112,11 +21859,11 @@
2111221859
** This routine is could be marked "static". But it is not always used,
2111321860
** depending on compile-time options. By omitting the "static", we avoid
2111421861
** nuisance compiler warnings about "defined but not used".
2111521862
*/
2111621863
void shellReset(
21117
- int *pRc,
21864
+ int *pRc,
2111821865
sqlite3_stmt *pStmt
2111921866
){
2112021867
int rc = sqlite3_reset(pStmt);
2112121868
if( *pRc==SQLITE_OK ){
2112221869
if( rc!=SQLITE_OK ){
@@ -21160,11 +21907,11 @@
2116021907
showHelp(f,"archive");
2116121908
return SQLITE_ERROR;
2116221909
}
2116321910
2116421911
/*
21165
-** Print an error message for the .ar command to stderr and return
21912
+** Print an error message for the .ar command to stderr and return
2116621913
** SQLITE_ERROR.
2116721914
*/
2116821915
static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
2116921916
va_list ap;
2117021917
char *z;
@@ -21241,11 +21988,11 @@
2124121988
}
2124221989
2124321990
/*
2124421991
** Parse the command line for an ".ar" command. The results are written into
2124521992
** structure (*pAr). SQLITE_OK is returned if the command line is parsed
21246
-** successfully, otherwise an error message is written to stderr and
21993
+** successfully, otherwise an error message is written to stderr and
2124721994
** SQLITE_ERROR returned.
2124821995
*/
2124921996
static int arParseCommand(
2125021997
char **azArg, /* Array of arguments passed to dot command */
2125121998
int nArg, /* Number of entries in azArg[] */
@@ -21437,11 +22184,11 @@
2143722184
** The caller is responsible for eventually calling sqlite3_free() on
2143822185
** any non-NULL (*pzWhere) value. Here, "match" means strict equality
2143922186
** when pAr->bGlob is false and GLOB match when pAr->bGlob is true.
2144022187
*/
2144122188
static void arWhereClause(
21442
- int *pRc,
22189
+ int *pRc,
2144322190
ArCommand *pAr,
2144422191
char **pzWhere /* OUT: New WHERE clause */
2144522192
){
2144622193
char *zWhere = 0;
2144722194
const char *zSameOp = (pAr->bGlob)? "GLOB" : "=";
@@ -21452,11 +22199,11 @@
2145222199
int i;
2145322200
const char *zSep = "";
2145422201
for(i=0; i<pAr->nArg; i++){
2145522202
const char *z = pAr->azArg[i];
2145622203
zWhere = sqlite3_mprintf(
21457
- "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
22204
+ "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
2145822205
zWhere, zSep, zSameOp, z, strlen30(z)+1, zSameOp, z
2145922206
);
2146022207
if( zWhere==0 ){
2146122208
*pRc = SQLITE_NOMEM;
2146222209
break;
@@ -21467,14 +22214,14 @@
2146722214
}
2146822215
*pzWhere = zWhere;
2146922216
}
2147022217
2147122218
/*
21472
-** Implementation of .ar "lisT" command.
22219
+** Implementation of .ar "lisT" command.
2147322220
*/
2147422221
static int arListCommand(ArCommand *pAr){
21475
- const char *zSql = "SELECT %s FROM %s WHERE %s";
22222
+ const char *zSql = "SELECT %s FROM %s WHERE %s";
2147622223
const char *azCols[] = {
2147722224
"name",
2147822225
"lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
2147922226
};
2148022227
@@ -21492,11 +22239,11 @@
2149222239
}else{
2149322240
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
2149422241
if( pAr->bVerbose ){
2149522242
utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
2149622243
sqlite3_column_text(pSql, 0),
21497
- sqlite3_column_int(pSql, 1),
22244
+ sqlite3_column_int(pSql, 1),
2149822245
sqlite3_column_text(pSql, 2),
2149922246
sqlite3_column_text(pSql, 3)
2150022247
);
2150122248
}else{
2150222249
utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
@@ -21549,21 +22296,21 @@
2154922296
sqlite3_free(zSql);
2155022297
return rc;
2155122298
}
2155222299
2155322300
/*
21554
-** Implementation of .ar "eXtract" command.
22301
+** Implementation of .ar "eXtract" command.
2155522302
*/
2155622303
static int arExtractCommand(ArCommand *pAr){
21557
- const char *zSql1 =
22304
+ const char *zSql1 =
2155822305
"SELECT "
2155922306
" ($dir || name),"
2156022307
" writefile(($dir || name), %s, mode, mtime) "
2156122308
"FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)"
2156222309
" AND name NOT GLOB '*..[/\\]*'";
2156322310
21564
- const char *azExtraArg[] = {
22311
+ const char *azExtraArg[] = {
2156522312
"sqlar_uncompress(data, sz)",
2156622313
"data"
2156722314
};
2156822315
2156922316
sqlite3_stmt *pSql = 0;
@@ -21585,11 +22332,11 @@
2158522332
zDir = sqlite3_mprintf("");
2158622333
}
2158722334
if( zDir==0 ) rc = SQLITE_NOMEM;
2158822335
}
2158922336
21590
- shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
22337
+ shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
2159122338
azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
2159222339
);
2159322340
2159422341
if( rc==SQLITE_OK ){
2159522342
j = sqlite3_bind_parameter_index(pSql, "$dir");
@@ -21663,11 +22410,11 @@
2166322410
static int arCreateOrUpdateCommand(
2166422411
ArCommand *pAr, /* Command arguments and options */
2166522412
int bUpdate, /* true for a --create. */
2166622413
int bOnlyIfChanged /* Only update if file has changed */
2166722414
){
21668
- const char *zCreate =
22415
+ const char *zCreate =
2166922416
"CREATE TABLE IF NOT EXISTS sqlar(\n"
2167022417
" name TEXT PRIMARY KEY, -- name of the file\n"
2167122418
" mode INT, -- access permissions\n"
2167222419
" mtime INT, -- last modification time\n"
2167322420
" sz INT, -- original file size\n"
@@ -21705,11 +22452,11 @@
2170522452
char *zExists = 0;
2170622453
2170722454
arExecSql(pAr, "PRAGMA page_size=512");
2170822455
rc = arExecSql(pAr, "SAVEPOINT ar;");
2170922456
if( rc!=SQLITE_OK ) return rc;
21710
- zTemp[0] = 0;
22457
+ zTemp[0] = 0;
2171122458
if( pAr->bZip ){
2171222459
/* Initialize the zipfile virtual table, if necessary */
2171322460
if( pAr->zFile ){
2171422461
sqlite3_uint64 r;
2171522462
sqlite3_randomness(sizeof(r),&r);
@@ -21799,11 +22546,11 @@
2179922546
}
2180022547
cmd.bZip = 1;
2180122548
}else if( cmd.zFile ){
2180222549
int flags;
2180322550
if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
21804
- if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
22551
+ if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
2180522552
|| cmd.eCmd==AR_CMD_REMOVE || cmd.eCmd==AR_CMD_UPDATE ){
2180622553
flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
2180722554
}else{
2180822555
flags = SQLITE_OPEN_READONLY;
2180922556
}
@@ -21810,14 +22557,14 @@
2181022557
cmd.db = 0;
2181122558
if( cmd.bDryRun ){
2181222559
utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
2181322560
eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
2181422561
}
21815
- rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
22562
+ rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
2181622563
eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
2181722564
if( rc!=SQLITE_OK ){
21818
- utf8_printf(stderr, "cannot open file: %s (%s)\n",
22565
+ utf8_printf(stderr, "cannot open file: %s (%s)\n",
2181922566
cmd.zFile, sqlite3_errmsg(cmd.db)
2182022567
);
2182122568
goto end_ar_command;
2182222569
}
2182322570
sqlite3_fileio_init(cmd.db, 0, 0);
@@ -21929,11 +22676,11 @@
2192922676
}else
2193022677
if( n<=10 && memcmp("-no-rowids", z, n)==0 ){
2193122678
bRowids = 0;
2193222679
}
2193322680
else{
21934
- utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
22681
+ utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
2193522682
showHelp(pState->out, azArg[0]);
2193622683
return 1;
2193722684
}
2193822685
}
2193922686
@@ -22292,11 +23039,11 @@
2229223039
if( zDestFile==0 ){
2229323040
raw_printf(stderr, "missing FILENAME argument on .backup\n");
2229423041
return 1;
2229523042
}
2229623043
if( zDb==0 ) zDb = "main";
22297
- rc = sqlite3_open_v2(zDestFile, &pDest,
23044
+ rc = sqlite3_open_v2(zDestFile, &pDest,
2229823045
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
2229923046
if( rc!=SQLITE_OK ){
2230023047
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
2230123048
close_db(pDest);
2230223049
return 1;
@@ -22542,11 +23289,11 @@
2254223289
if( nArg>1 ) break;
2254323290
}
2254423291
if( nArg>1 && ii==ArraySize(aDbConfig) ){
2254523292
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
2254623293
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
22547
- }
23294
+ }
2254823295
}else
2254923296
2255023297
#if SQLITE_SHELL_HAVE_RECOVER
2255123298
if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){
2255223299
rc = shell_dbinfo_command(p, nArg, azArg);
@@ -22609,11 +23356,11 @@
2260923356
" name LIKE %Q ESCAPE '\\' AND"
2261023357
" sql LIKE 'CREATE VIRTUAL TABLE%%' AND"
2261123358
" substr(o.name, 1, length(name)+1) == (name||'_')"
2261223359
")", azArg[i], azArg[i]
2261323360
);
22614
-
23361
+
2261523362
if( zLike ){
2261623363
zLike = sqlite3_mprintf("%z OR %z", zLike, zExpr);
2261723364
}else{
2261823365
zLike = zExpr;
2261923366
}
@@ -22742,11 +23489,11 @@
2274223489
}else
2274323490
2274423491
#ifndef SQLITE_OMIT_VIRTUALTABLE
2274523492
if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
2274623493
if( p->bSafeMode ){
22747
- raw_printf(stderr,
23494
+ raw_printf(stderr,
2274823495
"Cannot run experimental commands such as \"%s\" in safe mode\n",
2274923496
azArg[0]);
2275023497
rc = 1;
2275123498
}else{
2275223499
open_db(p, 0);
@@ -22761,11 +23508,11 @@
2276123508
int ctrlCode; /* Integer code for that option */
2276223509
const char *zUsage; /* Usage notes */
2276323510
} aCtrl[] = {
2276423511
{ "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
2276523512
{ "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
22766
- { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
23513
+ { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
2276723514
{ "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
2276823515
{ "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
2276923516
/* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
2277023517
{ "psow", SQLITE_FCNTL_POWERSAFE_OVERWRITE, "[BOOLEAN]" },
2277123518
{ "reserve_bytes", SQLITE_FCNTL_RESERVE_BYTES, "[N]" },
@@ -22782,11 +23529,11 @@
2278223529
const char *zSchema = 0;
2278323530
2278423531
open_db(p, 0);
2278523532
zCmd = nArg>=2 ? azArg[1] : "help";
2278623533
22787
- if( zCmd[0]=='-'
23534
+ if( zCmd[0]=='-'
2278823535
&& (cli_strcmp(zCmd,"--schema")==0 || cli_strcmp(zCmd,"-schema")==0)
2278923536
&& nArg>=4
2279023537
){
2279123538
zSchema = azArg[2];
2279223539
for(i=3; i<nArg; i++) azArg[i-2] = azArg[i];
@@ -24160,11 +24907,12 @@
2416024907
rc = 1;
2416124908
goto meta_command_exit;
2416224909
}else if( zName==0 ){
2416324910
zName = azArg[ii];
2416424911
}else{
24165
- raw_printf(stderr, "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
24912
+ raw_printf(stderr,
24913
+ "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
2416624914
rc = 1;
2416724915
goto meta_command_exit;
2416824916
}
2416924917
}
2417024918
if( zName!=0 ){
@@ -24276,11 +25024,11 @@
2427625024
}else
2427725025
2427825026
if( (c=='s' && n==11 && cli_strncmp(azArg[0], "selecttrace", n)==0)
2427925027
|| (c=='t' && n==9 && cli_strncmp(azArg[0], "treetrace", n)==0)
2428025028
){
24281
- unsigned int x = nArg>=2 ? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
25029
+ unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
2428225030
sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
2428325031
}else
2428425032
2428525033
#if defined(SQLITE_ENABLE_SESSION)
2428625034
if( c=='s' && cli_strncmp(azArg[0],"session",n)==0 && n>=3 ){
@@ -24461,11 +25209,12 @@
2446125209
utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
2446225210
goto meta_command_exit;
2446325211
}
2446425212
}
2446525213
if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
24466
- raw_printf(stderr, "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
25214
+ raw_printf(stderr,
25215
+ "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
2446725216
goto meta_command_exit;
2446825217
}
2446925218
pSession = &pAuxDb->aSession[pAuxDb->nSession];
2447025219
rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
2447125220
if( rc ){
@@ -24745,30 +25494,30 @@
2474525494
}
2474625495
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE)
2474725496
{
2474825497
int lrc;
2474925498
char *zRevText = /* Query for reversible to-blob-to-text check */
24750
- "SELECT lower(name) as tname FROM sqlite_schema\n"
24751
- "WHERE type='table' AND coalesce(rootpage,0)>1\n"
24752
- "AND name NOT LIKE 'sqlite_%%'%s\n"
24753
- "ORDER BY 1 collate nocase";
25499
+ "SELECT lower(name) as tname FROM sqlite_schema\n"
25500
+ "WHERE type='table' AND coalesce(rootpage,0)>1\n"
25501
+ "AND name NOT LIKE 'sqlite_%%'%s\n"
25502
+ "ORDER BY 1 collate nocase";
2475425503
zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
2475525504
zRevText = sqlite3_mprintf(
24756
- /* lower-case query is first run, producing upper-case query. */
24757
- "with tabcols as materialized(\n"
24758
- "select tname, cname\n"
24759
- "from ("
24760
- " select ss.tname as tname, ti.name as cname\n"
24761
- " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
24762
- "select 'SELECT total(bad_text_count) AS bad_text_count\n"
24763
- "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
24764
- " from (select 'SELECT COUNT(*) AS bad_text_count\n"
24765
- "FROM '||tname||' WHERE '\n"
24766
- "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
24767
- "|| ' AND typeof('||cname||')=''text'' ',\n"
24768
- "' OR ') as query, tname from tabcols group by tname)"
24769
- , zRevText);
25505
+ /* lower-case query is first run, producing upper-case query. */
25506
+ "with tabcols as materialized(\n"
25507
+ "select tname, cname\n"
25508
+ "from ("
25509
+ " select ss.tname as tname, ti.name as cname\n"
25510
+ " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
25511
+ "select 'SELECT total(bad_text_count) AS bad_text_count\n"
25512
+ "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
25513
+ " from (select 'SELECT COUNT(*) AS bad_text_count\n"
25514
+ "FROM '||tname||' WHERE '\n"
25515
+ "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
25516
+ "|| ' AND typeof('||cname||')=''text'' ',\n"
25517
+ "' OR ') as query, tname from tabcols group by tname)"
25518
+ , zRevText);
2477025519
shell_check_oom(zRevText);
2477125520
if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
2477225521
lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
2477325522
assert(lrc==SQLITE_OK);
2477425523
if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
@@ -24777,20 +25526,20 @@
2477725526
const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
2477825527
sqlite3_stmt *pCheckStmt;
2477925528
lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
2478025529
if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
2478125530
if( SQLITE_OK==lrc ){
24782
- if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
24783
- double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
24784
- if( countIrreversible>0 ){
24785
- int sz = (int)(countIrreversible + 0.5);
24786
- utf8_printf(stderr,
24787
- "Digest includes %d invalidly encoded text field%s.\n",
24788
- sz, (sz>1)? "s": "");
24789
- }
24790
- }
24791
- sqlite3_finalize(pCheckStmt);
25531
+ if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
25532
+ double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
25533
+ if( countIrreversible>0 ){
25534
+ int sz = (int)(countIrreversible + 0.5);
25535
+ utf8_printf(stderr,
25536
+ "Digest includes %d invalidly encoded text field%s.\n",
25537
+ sz, (sz>1)? "s": "");
25538
+ }
25539
+ }
25540
+ sqlite3_finalize(pCheckStmt);
2479225541
}
2479325542
sqlite3_finalize(pStmt);
2479425543
}
2479525544
sqlite3_free(zRevText);
2479625545
}
@@ -25022,32 +25771,32 @@
2502225771
const char *zCtrlName; /* Name of a test-control option */
2502325772
int ctrlCode; /* Integer code for that option */
2502425773
int unSafe; /* Not valid for --safe mode */
2502525774
const char *zUsage; /* Usage notes */
2502625775
} aCtrl[] = {
25027
- { "always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
25028
- { "assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
25029
- /*{ "benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
25030
- /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
25031
- { "byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
25032
- { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
25033
- /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/
25034
- { "imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
25035
- { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
25036
- { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
25037
- { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT,1, "BOOLEAN" },
25038
- { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK" },
25776
+ {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
25777
+ {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
25778
+ /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
25779
+ /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
25780
+ {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
25781
+ {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
25782
+ /*{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/
25783
+ {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
25784
+ {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
25785
+ {"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
25786
+ {"never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT,1, "BOOLEAN" },
25787
+ {"optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK" },
2503925788
#ifdef YYCOVERAGE
25040
- { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE,0,"" },
25789
+ {"parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE,0,"" },
2504125790
#endif
25042
- { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE,0, "OFFSET " },
25043
- { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" },
25044
- { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" },
25045
- { "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" },
25046
- { "seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
25047
- { "sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
25048
- { "tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
25791
+ {"pending_byte", SQLITE_TESTCTRL_PENDING_BYTE,0, "OFFSET " },
25792
+ {"prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" },
25793
+ {"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" },
25794
+ {"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" },
25795
+ {"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
25796
+ {"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
25797
+ {"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
2504925798
};
2505025799
int testctrl = -1;
2505125800
int iCtrl = -1;
2505225801
int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
2505325802
int isOk = 0;
@@ -25468,11 +26217,11 @@
2546826217
}
2546926218
}
2547026219
}else
2547126220
2547226221
if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){
25473
- unsigned int x = nArg>=2 ? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
26222
+ unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
2547426223
sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 3, &x);
2547526224
}else
2547626225
2547726226
if( c=='w' && cli_strncmp(azArg[0], "width", n)==0 ){
2547826227
int j;
@@ -25521,11 +26270,11 @@
2552126270
** Scan line for classification to guide shell's handling.
2552226271
** The scan is resumable for subsequent lines when prior
2552326272
** return values are passed as the 2nd argument.
2552426273
*/
2552526274
static QuickScanState quickscan(char *zLine, QuickScanState qss,
25526
- SCAN_TRACKER_REFTYPE pst){
26275
+ SCAN_TRACKER_REFTYPE pst){
2552726276
char cin;
2552826277
char cWait = (char)qss; /* intentional narrowing loss */
2552926278
if( cWait==0 ){
2553026279
PlainScan:
2553126280
assert( cWait==0 );
@@ -25545,11 +26294,11 @@
2554526294
continue;
2554626295
case '/':
2554726296
if( *zLine=='*' ){
2554826297
++zLine;
2554926298
cWait = '*';
25550
- CONTINUE_PROMPT_AWAITS(pst, "/*");
26299
+ CONTINUE_PROMPT_AWAITS(pst, "/*");
2555126300
qss = QSS_SETV(qss, cWait);
2555226301
goto TermScan;
2555326302
}
2555426303
break;
2555526304
case '[':
@@ -25556,18 +26305,18 @@
2555626305
cin = ']';
2555726306
/* fall thru */
2555826307
case '`': case '\'': case '"':
2555926308
cWait = cin;
2556026309
qss = QSS_HasDark | cWait;
25561
- CONTINUE_PROMPT_AWAITC(pst, cin);
26310
+ CONTINUE_PROMPT_AWAITC(pst, cin);
2556226311
goto TermScan;
2556326312
case '(':
25564
- CONTINUE_PAREN_INCR(pst, 1);
25565
- break;
26313
+ CONTINUE_PAREN_INCR(pst, 1);
26314
+ break;
2556626315
case ')':
25567
- CONTINUE_PAREN_INCR(pst, -1);
25568
- break;
26316
+ CONTINUE_PAREN_INCR(pst, -1);
26317
+ break;
2556926318
default:
2557026319
break;
2557126320
}
2557226321
qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
2557326322
}
@@ -25579,23 +26328,23 @@
2557926328
case '*':
2558026329
if( *zLine != '/' )
2558126330
continue;
2558226331
++zLine;
2558326332
cWait = 0;
25584
- CONTINUE_PROMPT_AWAITC(pst, 0);
26333
+ CONTINUE_PROMPT_AWAITC(pst, 0);
2558526334
qss = QSS_SETV(qss, 0);
2558626335
goto PlainScan;
2558726336
case '`': case '\'': case '"':
2558826337
if(*zLine==cWait){
25589
- /* Swallow doubled end-delimiter.*/
26338
+ /* Swallow doubled end-delimiter.*/
2559026339
++zLine;
2559126340
continue;
2559226341
}
2559326342
/* fall thru */
2559426343
case ']':
2559526344
cWait = 0;
25596
- CONTINUE_PROMPT_AWAITC(pst, 0);
26345
+ CONTINUE_PROMPT_AWAITC(pst, 0);
2559726346
qss = QSS_SETV(qss, 0);
2559826347
goto PlainScan;
2559926348
default: assert(0);
2560026349
}
2560126350
}
@@ -25696,13 +26445,13 @@
2569626445
if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
2569726446
}
2569826447
2569926448
#ifdef SQLITE_SHELL_FIDDLE
2570026449
/*
25701
-** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
25702
-** because we need the global shellState and cannot access it from that function
25703
-** without moving lots of code around (creating a larger/messier diff).
26450
+** Alternate one_input_line() impl for wasm mode. This is not in the primary
26451
+** impl because we need the global shellState and cannot access it from that
26452
+** function without moving lots of code around (creating a larger/messier diff).
2570426453
*/
2570526454
static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
2570626455
/* Parse the next line from shellState.wasm.zInput. */
2570726456
const char *zBegin = shellState.wasm.zPos;
2570826457
const char *z = zBegin;
@@ -26517,16 +27266,16 @@
2651727266
data.openMode = SHELL_OPEN_READONLY;
2651827267
}else if( cli_strcmp(z,"-nofollow")==0 ){
2651927268
data.openFlags |= SQLITE_OPEN_NOFOLLOW;
2652027269
}else if( cli_strcmp(z,"-ascii")==0 ){
2652127270
data.mode = MODE_Ascii;
26522
- sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator, SEP_Unit);
26523
- sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator, SEP_Record);
27271
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Unit);
27272
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Record);
2652427273
}else if( cli_strcmp(z,"-tabs")==0 ){
2652527274
data.mode = MODE_List;
26526
- sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator, SEP_Tab);
26527
- sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator, SEP_Row);
27275
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Tab);
27276
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Row);
2652827277
}else if( cli_strcmp(z,"-separator")==0 ){
2652927278
sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
2653027279
"%s",cmdline_option_value(argc,argv,++i));
2653127280
}else if( cli_strcmp(z,"-newline")==0 ){
2653227281
sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
2653327282
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -37,11 +37,11 @@
37 typedef unsigned int u32;
38 typedef unsigned short int u16;
39
40 /*
41 ** Optionally #include a user-defined header, whereby compilation options
42 ** may be set prior to where they take effect, but after platform setup.
43 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
44 ** file. Note that this macro has a like effect on sqlite3.c compilation.
45 */
46 # define SHELL_STRINGIFY_(f) #f
47 # define SHELL_STRINGIFY(f) SHELL_STRINGIFY_(f)
@@ -551,24 +551,25 @@
551 if( continuePrompt[0]==0
552 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
553 return continuePrompt;
554 }else{
555 if( dynPrompt.zScannerAwaits ){
556 size_t ncp = strlen(continuePrompt), ndp = strlen(dynPrompt.zScannerAwaits);
 
557 if( ndp > ncp-3 ) return continuePrompt;
558 strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
559 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
560 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
561 PROMPT_LEN_MAX-4);
562 }else{
563 if( dynPrompt.inParenLevel>9 ){
564 strncpy(dynPrompt.dynamicPrompt, "(..", 4);
565 }else if( dynPrompt.inParenLevel<0 ){
566 strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
567 }else{
568 strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
569 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
570 }
571 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
572 }
573 }
574 return dynPrompt.dynamicPrompt;
@@ -1049,11 +1050,11 @@
1049 ){
1050 const char *zName;
1051 char *zFake;
1052 UNUSED_PARAMETER(nVal);
1053 zName = (const char*)sqlite3_value_text(apVal[0]);
1054 zFake = zName ? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
1055 if( zFake ){
1056 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
1057 -1, sqlite3_free);
1058 free(zFake);
1059 }
@@ -3050,11 +3051,11 @@
3050 unsigned int i;
3051 (void)pzErrMsg; /* Unused parameter */
3052
3053 SQLITE_EXTENSION_INIT2(pApi);
3054
3055 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
3056 rc = sqlite3_create_function(db, aFunc[i].zFuncName, aFunc[i].nArg,
3057 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
3058 0, aFunc[i].xFunc, 0, 0);
3059 }
3060 if( rc==SQLITE_OK ){
@@ -3069,10 +3070,724 @@
3069 }
3070 return rc;
3071 }
3072
3073 /************************* End ../ext/misc/decimal.c ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3074 /************************* Begin ../ext/misc/ieee754.c ******************/
3075 /*
3076 ** 2013-04-17
3077 **
3078 ** The author disclaims copyright to this source code. In place of
@@ -4633,10 +5348,11 @@
4633 ReCompiled *pRe;
4634 sqlite3_str *pStr;
4635 int i;
4636 int n;
4637 char *z;
 
4638
4639 zPattern = (const char*)sqlite3_value_text(argv[0]);
4640 if( zPattern==0 ) return;
4641 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
4642 if( zErr ){
@@ -7280,10 +7996,11 @@
7280 int nByte = sizeof(ZipfileTab) + ZIPFILE_BUFFER_SIZE;
7281 int nFile = 0;
7282 const char *zFile = 0;
7283 ZipfileTab *pNew = 0;
7284 int rc;
 
7285
7286 /* If the table name is not "zipfile", require that the argument be
7287 ** specified. This stops zipfile tables from being created as:
7288 **
7289 ** CREATE VIRTUAL TABLE zzz USING zipfile();
@@ -7736,10 +8453,11 @@
7736 ZipfileEntry **ppEntry /* OUT: Pointer to new object */
7737 ){
7738 u8 *aRead;
7739 char **pzErr = &pTab->base.zErrMsg;
7740 int rc = SQLITE_OK;
 
7741
7742 if( aBlob==0 ){
7743 aRead = pTab->aBuffer;
7744 rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr);
7745 }else{
@@ -8181,10 +8899,13 @@
8181 ZipfileTab *pTab = (ZipfileTab*)cur->pVtab;
8182 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
8183 const char *zFile = 0; /* Zip file to scan */
8184 int rc = SQLITE_OK; /* Return Code */
8185 int bInMemory = 0; /* True for an in-memory zipfile */
 
 
 
8186
8187 zipfileResetCursor(pCsr);
8188
8189 if( pTab->zFile ){
8190 zFile = pTab->zFile;
@@ -8242,10 +8963,11 @@
8242 sqlite3_index_info *pIdxInfo
8243 ){
8244 int i;
8245 int idx = -1;
8246 int unusable = 0;
 
8247
8248 for(i=0; i<pIdxInfo->nConstraint; i++){
8249 const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
8250 if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue;
8251 if( pCons->usable==0 ){
@@ -8491,10 +9213,12 @@
8491 ZipfileEntry *pOld = 0;
8492 ZipfileEntry *pOld2 = 0;
8493 int bUpdate = 0; /* True for an update that modifies "name" */
8494 int bIsDir = 0;
8495 u32 iCrc32 = 0;
 
 
8496
8497 if( pTab->pWriteFd==0 ){
8498 rc = zipfileBegin(pVtab);
8499 if( rc!=SQLITE_OK ) return rc;
8500 }
@@ -8826,10 +9550,11 @@
8826 int nArg, /* Number of SQL function arguments */
8827 const char *zName, /* Name of SQL function */
8828 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
8829 void **ppArg /* OUT: User data for *pxFunc */
8830 ){
 
8831 if( sqlite3_stricmp("zipfile_cds", zName)==0 ){
8832 *pxFunc = zipfileFunctionCds;
8833 *ppArg = (void*)pVtab;
8834 return 1;
8835 }
@@ -11917,10 +12642,13 @@
11917 char **pzErr
11918 ){
11919 DbdataTable *pTab = 0;
11920 int rc = sqlite3_declare_vtab(db, pAux ? DBPTR_SCHEMA : DBDATA_SCHEMA);
11921
 
 
 
11922 if( rc==SQLITE_OK ){
11923 pTab = (DbdataTable*)sqlite3_malloc64(sizeof(DbdataTable));
11924 if( pTab==0 ){
11925 rc = SQLITE_NOMEM;
11926 }else{
@@ -12521,10 +13249,12 @@
12521 ){
12522 DbdataCursor *pCsr = (DbdataCursor*)pCursor;
12523 DbdataTable *pTab = (DbdataTable*)pCursor->pVtab;
12524 int rc = SQLITE_OK;
12525 const char *zSchema = "main";
 
 
12526
12527 dbdataResetCursor(pCsr);
12528 assert( pCsr->iPgno==1 );
12529 if( idxNum & 0x01 ){
12530 zSchema = (const char*)sqlite3_value_text(argv[0]);
@@ -12689,10 +13419,11 @@
12689 sqlite3 *db,
12690 char **pzErrMsg,
12691 const sqlite3_api_routines *pApi
12692 ){
12693 SQLITE_EXTENSION_INIT2(pApi);
 
12694 return sqlite3DbdataRegister(db);
12695 }
12696
12697 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
12698
@@ -13459,10 +14190,11 @@
13459 sqlite3_context *context,
13460 int argc,
13461 sqlite3_value **argv
13462 ){
13463 const char *zText = (const char*)sqlite3_value_text(argv[0]);
 
13464 if( zText && zText[0]=='\'' ){
13465 int nText = sqlite3_value_bytes(argv[0]);
13466 int i;
13467 char zBuf1[20];
13468 char zBuf2[20];
@@ -13611,11 +14343,11 @@
13611 if( rc!=SQLITE_OK ){
13612 recoverDbError(p, db2);
13613 return;
13614 }
13615
13616 for(ii=0; ii<sizeof(aPragma)/sizeof(aPragma[0]); ii++){
13617 const char *zPrag = aPragma[ii];
13618 sqlite3_stmt *p1 = 0;
13619 p1 = recoverPreparePrintf(p, p->dbIn, "PRAGMA %Q.%s", p->zDb, zPrag);
13620 if( p->errCode==SQLITE_OK && sqlite3_step(p1)==SQLITE_ROW ){
13621 const char *zArg = (const char*)sqlite3_column_text(p1, 0);
@@ -13689,11 +14421,13 @@
13689 if( p->errCode==SQLITE_OK ){
13690 p->errCode = sqlite3_dbdata_init(db, 0, 0);
13691 }
13692
13693 /* Register the custom user-functions with the output handle. */
13694 for(ii=0; p->errCode==SQLITE_OK && ii<sizeof(aFunc)/sizeof(aFunc[0]); ii++){
 
 
13695 p->errCode = sqlite3_create_function(db, aFunc[ii].zName,
13696 aFunc[ii].nArg, SQLITE_UTF8, (void*)p, aFunc[ii].xFunc, 0, 0
13697 );
13698 }
13699
@@ -15086,11 +15820,11 @@
15086 recoverPutU32(&aHdr[56], enc);
15087 recoverPutU16(&aHdr[105], pgsz-nReserve);
15088 if( pgsz==65536 ) pgsz = 1;
15089 recoverPutU16(&aHdr[16], pgsz);
15090 aHdr[20] = nReserve;
15091 for(ii=0; ii<sizeof(aPreserve)/sizeof(aPreserve[0]); ii++){
15092 memcpy(&aHdr[aPreserve[ii]], &a[aPreserve[ii]], 4);
15093 }
15094 memcpy(aBuf, aHdr, sizeof(aHdr));
15095 memset(&((u8*)aBuf)[sizeof(aHdr)], 0, nByte-sizeof(aHdr));
15096
@@ -15210,14 +15944,20 @@
15210 sqlite3_file *pFd,
15211 sqlite3_int64 iOff,
15212 int iAmt,
15213 void **pp
15214 ){
 
 
 
15215 *pp = 0;
15216 return SQLITE_OK;
15217 }
15218 static int recoverVfsUnfetch(sqlite3_file *pFd, sqlite3_int64 iOff, void *p){
 
 
 
15219 return SQLITE_OK;
15220 }
15221
15222 /*
15223 ** Install the VFS wrapper around the file-descriptor open on the input
@@ -15990,11 +16730,11 @@
15990 if( p[i]=='\r' && p[i+1]=='\n' ) i++;
15991 p[j++] = p[i];
15992 }
15993 sz = j;
15994 p[sz] = 0;
15995 }
15996 sqlite3_result_text64(context, (const char*)p, sz,
15997 sqlite3_free, SQLITE_UTF8);
15998 }
15999 p = 0;
16000
@@ -17165,13 +17905,13 @@
17165 }
17166 zCode = sqlite3_mprintf("%.*s", len, zSql);
17167 shell_check_oom(zCode);
17168 for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; }
17169 if( iOffset<25 ){
17170 zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode, iOffset, "");
17171 }else{
17172 zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode, iOffset-14, "");
17173 }
17174 return zMsg;
17175 }
17176
17177
@@ -17355,11 +18095,11 @@
17355 }
17356 }
17357
17358 if( pArg->statsOn==3 ){
17359 if( pArg->pStmt ){
17360 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
17361 raw_printf(pArg->out, "VM-steps: %d\n", iCur);
17362 }
17363 return 0;
17364 }
17365
@@ -17436,12 +18176,14 @@
17436 raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur);
17437 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
17438 raw_printf(pArg->out, "Sort Operations: %d\n", iCur);
17439 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
17440 raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur);
17441 iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT, bReset);
17442 iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS, bReset);
 
 
17443 if( iHit || iMiss ){
17444 raw_printf(pArg->out, "Bloom filter bypass taken: %d/%d\n",
17445 iHit, iHit+iMiss);
17446 }
17447 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
@@ -17466,24 +18208,24 @@
17466
17467 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
17468 static int scanStatsHeight(sqlite3_stmt *p, int iEntry){
17469 int iPid = 0;
17470 int ret = 1;
17471 sqlite3_stmt_scanstatus_v2(p, iEntry,
17472 SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
17473 );
17474 while( iPid!=0 ){
17475 int ii;
17476 for(ii=0; 1; ii++){
17477 int iId;
17478 int res;
17479 res = sqlite3_stmt_scanstatus_v2(p, ii,
17480 SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iId
17481 );
17482 if( res ) break;
17483 if( iId==iPid ){
17484 sqlite3_stmt_scanstatus_v2(p, ii,
17485 SQLITE_SCANSTAT_PARENTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
17486 );
17487 }
17488 }
17489 ret++;
@@ -17811,11 +18553,11 @@
17811
17812 /* Draw horizontal line N characters long using unicode box
17813 ** characters
17814 */
17815 static void print_box_line(FILE *out, int N){
17816 const char zDash[] =
17817 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24
17818 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24;
17819 const int nDash = sizeof(zDash) - 1;
17820 N *= 3;
17821 while( N>nDash ){
@@ -17940,11 +18682,11 @@
17940 continue;
17941 }
17942 break;
17943 }
17944 zOut[j] = 0;
17945 return (char*)zOut;
17946 }
17947
17948 /* Extract the value of the i-th current column for pStmt as an SQL literal
17949 ** value. Memory is obtained from sqlite3_malloc64() and must be freed by
17950 ** the caller.
@@ -18301,22 +19043,22 @@
18301 ** code. In this case, (*pzErr) may be set to point to a buffer containing
18302 ** an English language error message. It is the responsibility of the
18303 ** caller to eventually free this buffer using sqlite3_free().
18304 */
18305 static int expertHandleSQL(
18306 ShellState *pState,
18307 const char *zSql,
18308 char **pzErr
18309 ){
18310 assert( pState->expert.pExpert );
18311 assert( pzErr==0 || *pzErr==0 );
18312 return sqlite3_expert_sql(pState->expert.pExpert, zSql, pzErr);
18313 }
18314
18315 /*
18316 ** This function is called either to silently clean up the object
18317 ** created by the ".expert" command (if bCancel==1), or to generate a
18318 ** report from it and then clean it up (if bCancel==0).
18319 **
18320 ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
18321 ** code. In this case, (*pzErr) may be set to point to a buffer containing
18322 ** an English language error message. It is the responsibility of the
@@ -18407,11 +19149,12 @@
18407 }
18408
18409 if( rc==SQLITE_OK ){
18410 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
18411 if( pState->expert.pExpert==0 ){
18412 raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory");
 
18413 rc = SQLITE_ERROR;
18414 }else{
18415 sqlite3_expert_config(
18416 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
18417 );
@@ -19368,11 +20111,11 @@
19368 }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
19369 rc = SHELL_OPEN_ZIPFILE;
19370 }
19371 }
19372 fclose(f);
19373 return rc;
19374 }
19375
19376 #ifndef SQLITE_OMIT_DESERIALIZE
19377 /*
19378 ** Reconstruct an in-memory database using the output from the "dbtotxt"
@@ -19467,12 +20210,12 @@
19467 ** must be a blob. The second a non-negative integer. This function
19468 ** reads and returns a 32-bit big-endian integer from byte
19469 ** offset (4*<arg2>) of the blob.
19470 */
19471 static void shellInt32(
19472 sqlite3_context *context,
19473 int argc,
19474 sqlite3_value **argv
19475 ){
19476 const unsigned char *pBlob;
19477 int nBlob;
19478 int iInt;
@@ -19495,12 +20238,12 @@
19495 /*
19496 ** Scalar function "shell_idquote(X)" returns string X quoted as an identifier,
19497 ** using "..." with internal double-quote characters doubled.
19498 */
19499 static void shellIdQuote(
19500 sqlite3_context *context,
19501 int argc,
19502 sqlite3_value **argv
19503 ){
19504 const char *zName = (const char*)sqlite3_value_text(argv[0]);
19505 UNUSED_PARAMETER(argc);
19506 if( zName ){
@@ -19511,12 +20254,12 @@
19511
19512 /*
19513 ** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
19514 */
19515 static void shellUSleepFunc(
19516 sqlite3_context *context,
19517 int argcUnused,
19518 sqlite3_value **argv
19519 ){
19520 int sleep = sqlite3_value_int(argv[0]);
19521 (void)argcUnused;
19522 sqlite3_sleep(sleep/1000);
@@ -19524,11 +20267,11 @@
19524 }
19525
19526 /*
19527 ** Scalar function "shell_escape_crnl" used by the .recover command.
19528 ** The argument passed to this function is the output of built-in
19529 ** function quote(). If the first character of the input is "'",
19530 ** indicating that the value passed to quote() was a text value,
19531 ** then this function searches the input for "\n" and "\r" characters
19532 ** and adds a wrapper similar to the following:
19533 **
19534 ** replace(replace(<input>, '\n', char(10), '\r', char(13));
@@ -19535,12 +20278,12 @@
19535 **
19536 ** Or, if the first character of the input is not "'", then a copy
19537 ** of the input is returned.
19538 */
19539 static void shellEscapeCrnl(
19540 sqlite3_context *context,
19541 int argc,
19542 sqlite3_value **argv
19543 ){
19544 const char *zText = (const char*)sqlite3_value_text(argv[0]);
19545 UNUSED_PARAMETER(argc);
19546 if( zText && zText[0]=='\'' ){
@@ -19636,17 +20379,17 @@
19636 const char *zDbFilename = p->pAuxDb->zDbFilename;
19637 if( p->openMode==SHELL_OPEN_UNSPEC ){
19638 if( zDbFilename==0 || zDbFilename[0]==0 ){
19639 p->openMode = SHELL_OPEN_NORMAL;
19640 }else{
19641 p->openMode = (u8)deduceDatabaseType(zDbFilename,
19642 (openFlags & OPEN_DB_ZIPFILE)!=0);
19643 }
19644 }
19645 switch( p->openMode ){
19646 case SHELL_OPEN_APPENDVFS: {
19647 sqlite3_open_v2(zDbFilename, &p->db,
19648 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
19649 break;
19650 }
19651 case SHELL_OPEN_HEXDB:
19652 case SHELL_OPEN_DESERIALIZE: {
@@ -19684,10 +20427,12 @@
19684 sqlite3_enable_load_extension(p->db, 1);
19685 #endif
19686 sqlite3_shathree_init(p->db, 0, 0);
19687 sqlite3_uint_init(p->db, 0, 0);
19688 sqlite3_decimal_init(p->db, 0, 0);
 
 
19689 sqlite3_regexp_init(p->db, 0, 0);
19690 sqlite3_ieee_init(p->db, 0, 0);
19691 sqlite3_series_init(p->db, 0, 0);
19692 #ifndef SQLITE_SHELL_FIDDLE
19693 sqlite3_fileio_init(p->db, 0, 0);
@@ -19795,11 +20540,11 @@
19795 void close_db(sqlite3 *db){
19796 int rc = sqlite3_close(db);
19797 if( rc ){
19798 utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
19799 rc, sqlite3_errmsg(db));
19800 }
19801 }
19802
19803 #if HAVE_READLINE || HAVE_EDITLINE
19804 /*
19805 ** Readline completion callbacks
@@ -19825,10 +20570,12 @@
19825 zRet = 0;
19826 }
19827 return zRet;
19828 }
19829 static char **readline_completion(const char *zText, int iStart, int iEnd){
 
 
19830 rl_attempted_completion_over = 1;
19831 return rl_completion_matches(zText, readline_completion_generator);
19832 }
19833
19834 #elif HAVE_LINENOISE
@@ -21036,20 +21783,20 @@
21036 return SQLITE_ERROR;
21037 }
21038
21039 #if !defined SQLITE_OMIT_VIRTUALTABLE
21040 static void shellPrepare(
21041 sqlite3 *db,
21042 int *pRc,
21043 const char *zSql,
21044 sqlite3_stmt **ppStmt
21045 ){
21046 *ppStmt = 0;
21047 if( *pRc==SQLITE_OK ){
21048 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
21049 if( rc!=SQLITE_OK ){
21050 raw_printf(stderr, "sql error: %s (%d)\n",
21051 sqlite3_errmsg(db), sqlite3_errcode(db)
21052 );
21053 *pRc = rc;
21054 }
21055 }
@@ -21061,14 +21808,14 @@
21061 ** This routine is could be marked "static". But it is not always used,
21062 ** depending on compile-time options. By omitting the "static", we avoid
21063 ** nuisance compiler warnings about "defined but not used".
21064 */
21065 void shellPreparePrintf(
21066 sqlite3 *db,
21067 int *pRc,
21068 sqlite3_stmt **ppStmt,
21069 const char *zFmt,
21070 ...
21071 ){
21072 *ppStmt = 0;
21073 if( *pRc==SQLITE_OK ){
21074 va_list ap;
@@ -21090,11 +21837,11 @@
21090 ** This routine is could be marked "static". But it is not always used,
21091 ** depending on compile-time options. By omitting the "static", we avoid
21092 ** nuisance compiler warnings about "defined but not used".
21093 */
21094 void shellFinalize(
21095 int *pRc,
21096 sqlite3_stmt *pStmt
21097 ){
21098 if( pStmt ){
21099 sqlite3 *db = sqlite3_db_handle(pStmt);
21100 int rc = sqlite3_finalize(pStmt);
@@ -21112,11 +21859,11 @@
21112 ** This routine is could be marked "static". But it is not always used,
21113 ** depending on compile-time options. By omitting the "static", we avoid
21114 ** nuisance compiler warnings about "defined but not used".
21115 */
21116 void shellReset(
21117 int *pRc,
21118 sqlite3_stmt *pStmt
21119 ){
21120 int rc = sqlite3_reset(pStmt);
21121 if( *pRc==SQLITE_OK ){
21122 if( rc!=SQLITE_OK ){
@@ -21160,11 +21907,11 @@
21160 showHelp(f,"archive");
21161 return SQLITE_ERROR;
21162 }
21163
21164 /*
21165 ** Print an error message for the .ar command to stderr and return
21166 ** SQLITE_ERROR.
21167 */
21168 static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
21169 va_list ap;
21170 char *z;
@@ -21241,11 +21988,11 @@
21241 }
21242
21243 /*
21244 ** Parse the command line for an ".ar" command. The results are written into
21245 ** structure (*pAr). SQLITE_OK is returned if the command line is parsed
21246 ** successfully, otherwise an error message is written to stderr and
21247 ** SQLITE_ERROR returned.
21248 */
21249 static int arParseCommand(
21250 char **azArg, /* Array of arguments passed to dot command */
21251 int nArg, /* Number of entries in azArg[] */
@@ -21437,11 +22184,11 @@
21437 ** The caller is responsible for eventually calling sqlite3_free() on
21438 ** any non-NULL (*pzWhere) value. Here, "match" means strict equality
21439 ** when pAr->bGlob is false and GLOB match when pAr->bGlob is true.
21440 */
21441 static void arWhereClause(
21442 int *pRc,
21443 ArCommand *pAr,
21444 char **pzWhere /* OUT: New WHERE clause */
21445 ){
21446 char *zWhere = 0;
21447 const char *zSameOp = (pAr->bGlob)? "GLOB" : "=";
@@ -21452,11 +22199,11 @@
21452 int i;
21453 const char *zSep = "";
21454 for(i=0; i<pAr->nArg; i++){
21455 const char *z = pAr->azArg[i];
21456 zWhere = sqlite3_mprintf(
21457 "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
21458 zWhere, zSep, zSameOp, z, strlen30(z)+1, zSameOp, z
21459 );
21460 if( zWhere==0 ){
21461 *pRc = SQLITE_NOMEM;
21462 break;
@@ -21467,14 +22214,14 @@
21467 }
21468 *pzWhere = zWhere;
21469 }
21470
21471 /*
21472 ** Implementation of .ar "lisT" command.
21473 */
21474 static int arListCommand(ArCommand *pAr){
21475 const char *zSql = "SELECT %s FROM %s WHERE %s";
21476 const char *azCols[] = {
21477 "name",
21478 "lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
21479 };
21480
@@ -21492,11 +22239,11 @@
21492 }else{
21493 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
21494 if( pAr->bVerbose ){
21495 utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
21496 sqlite3_column_text(pSql, 0),
21497 sqlite3_column_int(pSql, 1),
21498 sqlite3_column_text(pSql, 2),
21499 sqlite3_column_text(pSql, 3)
21500 );
21501 }else{
21502 utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
@@ -21549,21 +22296,21 @@
21549 sqlite3_free(zSql);
21550 return rc;
21551 }
21552
21553 /*
21554 ** Implementation of .ar "eXtract" command.
21555 */
21556 static int arExtractCommand(ArCommand *pAr){
21557 const char *zSql1 =
21558 "SELECT "
21559 " ($dir || name),"
21560 " writefile(($dir || name), %s, mode, mtime) "
21561 "FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)"
21562 " AND name NOT GLOB '*..[/\\]*'";
21563
21564 const char *azExtraArg[] = {
21565 "sqlar_uncompress(data, sz)",
21566 "data"
21567 };
21568
21569 sqlite3_stmt *pSql = 0;
@@ -21585,11 +22332,11 @@
21585 zDir = sqlite3_mprintf("");
21586 }
21587 if( zDir==0 ) rc = SQLITE_NOMEM;
21588 }
21589
21590 shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
21591 azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
21592 );
21593
21594 if( rc==SQLITE_OK ){
21595 j = sqlite3_bind_parameter_index(pSql, "$dir");
@@ -21663,11 +22410,11 @@
21663 static int arCreateOrUpdateCommand(
21664 ArCommand *pAr, /* Command arguments and options */
21665 int bUpdate, /* true for a --create. */
21666 int bOnlyIfChanged /* Only update if file has changed */
21667 ){
21668 const char *zCreate =
21669 "CREATE TABLE IF NOT EXISTS sqlar(\n"
21670 " name TEXT PRIMARY KEY, -- name of the file\n"
21671 " mode INT, -- access permissions\n"
21672 " mtime INT, -- last modification time\n"
21673 " sz INT, -- original file size\n"
@@ -21705,11 +22452,11 @@
21705 char *zExists = 0;
21706
21707 arExecSql(pAr, "PRAGMA page_size=512");
21708 rc = arExecSql(pAr, "SAVEPOINT ar;");
21709 if( rc!=SQLITE_OK ) return rc;
21710 zTemp[0] = 0;
21711 if( pAr->bZip ){
21712 /* Initialize the zipfile virtual table, if necessary */
21713 if( pAr->zFile ){
21714 sqlite3_uint64 r;
21715 sqlite3_randomness(sizeof(r),&r);
@@ -21799,11 +22546,11 @@
21799 }
21800 cmd.bZip = 1;
21801 }else if( cmd.zFile ){
21802 int flags;
21803 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
21804 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
21805 || cmd.eCmd==AR_CMD_REMOVE || cmd.eCmd==AR_CMD_UPDATE ){
21806 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
21807 }else{
21808 flags = SQLITE_OPEN_READONLY;
21809 }
@@ -21810,14 +22557,14 @@
21810 cmd.db = 0;
21811 if( cmd.bDryRun ){
21812 utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
21813 eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
21814 }
21815 rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
21816 eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
21817 if( rc!=SQLITE_OK ){
21818 utf8_printf(stderr, "cannot open file: %s (%s)\n",
21819 cmd.zFile, sqlite3_errmsg(cmd.db)
21820 );
21821 goto end_ar_command;
21822 }
21823 sqlite3_fileio_init(cmd.db, 0, 0);
@@ -21929,11 +22676,11 @@
21929 }else
21930 if( n<=10 && memcmp("-no-rowids", z, n)==0 ){
21931 bRowids = 0;
21932 }
21933 else{
21934 utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
21935 showHelp(pState->out, azArg[0]);
21936 return 1;
21937 }
21938 }
21939
@@ -22292,11 +23039,11 @@
22292 if( zDestFile==0 ){
22293 raw_printf(stderr, "missing FILENAME argument on .backup\n");
22294 return 1;
22295 }
22296 if( zDb==0 ) zDb = "main";
22297 rc = sqlite3_open_v2(zDestFile, &pDest,
22298 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
22299 if( rc!=SQLITE_OK ){
22300 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
22301 close_db(pDest);
22302 return 1;
@@ -22542,11 +23289,11 @@
22542 if( nArg>1 ) break;
22543 }
22544 if( nArg>1 && ii==ArraySize(aDbConfig) ){
22545 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
22546 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
22547 }
22548 }else
22549
22550 #if SQLITE_SHELL_HAVE_RECOVER
22551 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){
22552 rc = shell_dbinfo_command(p, nArg, azArg);
@@ -22609,11 +23356,11 @@
22609 " name LIKE %Q ESCAPE '\\' AND"
22610 " sql LIKE 'CREATE VIRTUAL TABLE%%' AND"
22611 " substr(o.name, 1, length(name)+1) == (name||'_')"
22612 ")", azArg[i], azArg[i]
22613 );
22614
22615 if( zLike ){
22616 zLike = sqlite3_mprintf("%z OR %z", zLike, zExpr);
22617 }else{
22618 zLike = zExpr;
22619 }
@@ -22742,11 +23489,11 @@
22742 }else
22743
22744 #ifndef SQLITE_OMIT_VIRTUALTABLE
22745 if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
22746 if( p->bSafeMode ){
22747 raw_printf(stderr,
22748 "Cannot run experimental commands such as \"%s\" in safe mode\n",
22749 azArg[0]);
22750 rc = 1;
22751 }else{
22752 open_db(p, 0);
@@ -22761,11 +23508,11 @@
22761 int ctrlCode; /* Integer code for that option */
22762 const char *zUsage; /* Usage notes */
22763 } aCtrl[] = {
22764 { "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
22765 { "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
22766 { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
22767 { "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
22768 { "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
22769 /* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
22770 { "psow", SQLITE_FCNTL_POWERSAFE_OVERWRITE, "[BOOLEAN]" },
22771 { "reserve_bytes", SQLITE_FCNTL_RESERVE_BYTES, "[N]" },
@@ -22782,11 +23529,11 @@
22782 const char *zSchema = 0;
22783
22784 open_db(p, 0);
22785 zCmd = nArg>=2 ? azArg[1] : "help";
22786
22787 if( zCmd[0]=='-'
22788 && (cli_strcmp(zCmd,"--schema")==0 || cli_strcmp(zCmd,"-schema")==0)
22789 && nArg>=4
22790 ){
22791 zSchema = azArg[2];
22792 for(i=3; i<nArg; i++) azArg[i-2] = azArg[i];
@@ -24160,11 +24907,12 @@
24160 rc = 1;
24161 goto meta_command_exit;
24162 }else if( zName==0 ){
24163 zName = azArg[ii];
24164 }else{
24165 raw_printf(stderr, "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
 
24166 rc = 1;
24167 goto meta_command_exit;
24168 }
24169 }
24170 if( zName!=0 ){
@@ -24276,11 +25024,11 @@
24276 }else
24277
24278 if( (c=='s' && n==11 && cli_strncmp(azArg[0], "selecttrace", n)==0)
24279 || (c=='t' && n==9 && cli_strncmp(azArg[0], "treetrace", n)==0)
24280 ){
24281 unsigned int x = nArg>=2 ? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
24282 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
24283 }else
24284
24285 #if defined(SQLITE_ENABLE_SESSION)
24286 if( c=='s' && cli_strncmp(azArg[0],"session",n)==0 && n>=3 ){
@@ -24461,11 +25209,12 @@
24461 utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
24462 goto meta_command_exit;
24463 }
24464 }
24465 if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
24466 raw_printf(stderr, "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
 
24467 goto meta_command_exit;
24468 }
24469 pSession = &pAuxDb->aSession[pAuxDb->nSession];
24470 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
24471 if( rc ){
@@ -24745,30 +25494,30 @@
24745 }
24746 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE)
24747 {
24748 int lrc;
24749 char *zRevText = /* Query for reversible to-blob-to-text check */
24750 "SELECT lower(name) as tname FROM sqlite_schema\n"
24751 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
24752 "AND name NOT LIKE 'sqlite_%%'%s\n"
24753 "ORDER BY 1 collate nocase";
24754 zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
24755 zRevText = sqlite3_mprintf(
24756 /* lower-case query is first run, producing upper-case query. */
24757 "with tabcols as materialized(\n"
24758 "select tname, cname\n"
24759 "from ("
24760 " select ss.tname as tname, ti.name as cname\n"
24761 " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
24762 "select 'SELECT total(bad_text_count) AS bad_text_count\n"
24763 "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
24764 " from (select 'SELECT COUNT(*) AS bad_text_count\n"
24765 "FROM '||tname||' WHERE '\n"
24766 "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
24767 "|| ' AND typeof('||cname||')=''text'' ',\n"
24768 "' OR ') as query, tname from tabcols group by tname)"
24769 , zRevText);
24770 shell_check_oom(zRevText);
24771 if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
24772 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
24773 assert(lrc==SQLITE_OK);
24774 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
@@ -24777,20 +25526,20 @@
24777 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
24778 sqlite3_stmt *pCheckStmt;
24779 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
24780 if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
24781 if( SQLITE_OK==lrc ){
24782 if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
24783 double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
24784 if( countIrreversible>0 ){
24785 int sz = (int)(countIrreversible + 0.5);
24786 utf8_printf(stderr,
24787 "Digest includes %d invalidly encoded text field%s.\n",
24788 sz, (sz>1)? "s": "");
24789 }
24790 }
24791 sqlite3_finalize(pCheckStmt);
24792 }
24793 sqlite3_finalize(pStmt);
24794 }
24795 sqlite3_free(zRevText);
24796 }
@@ -25022,32 +25771,32 @@
25022 const char *zCtrlName; /* Name of a test-control option */
25023 int ctrlCode; /* Integer code for that option */
25024 int unSafe; /* Not valid for --safe mode */
25025 const char *zUsage; /* Usage notes */
25026 } aCtrl[] = {
25027 { "always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
25028 { "assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
25029 /*{ "benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
25030 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
25031 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
25032 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
25033 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/
25034 { "imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
25035 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
25036 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
25037 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT,1, "BOOLEAN" },
25038 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK" },
25039 #ifdef YYCOVERAGE
25040 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE,0,"" },
25041 #endif
25042 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE,0, "OFFSET " },
25043 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" },
25044 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" },
25045 { "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" },
25046 { "seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
25047 { "sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
25048 { "tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
25049 };
25050 int testctrl = -1;
25051 int iCtrl = -1;
25052 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
25053 int isOk = 0;
@@ -25468,11 +26217,11 @@
25468 }
25469 }
25470 }else
25471
25472 if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){
25473 unsigned int x = nArg>=2 ? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
25474 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 3, &x);
25475 }else
25476
25477 if( c=='w' && cli_strncmp(azArg[0], "width", n)==0 ){
25478 int j;
@@ -25521,11 +26270,11 @@
25521 ** Scan line for classification to guide shell's handling.
25522 ** The scan is resumable for subsequent lines when prior
25523 ** return values are passed as the 2nd argument.
25524 */
25525 static QuickScanState quickscan(char *zLine, QuickScanState qss,
25526 SCAN_TRACKER_REFTYPE pst){
25527 char cin;
25528 char cWait = (char)qss; /* intentional narrowing loss */
25529 if( cWait==0 ){
25530 PlainScan:
25531 assert( cWait==0 );
@@ -25545,11 +26294,11 @@
25545 continue;
25546 case '/':
25547 if( *zLine=='*' ){
25548 ++zLine;
25549 cWait = '*';
25550 CONTINUE_PROMPT_AWAITS(pst, "/*");
25551 qss = QSS_SETV(qss, cWait);
25552 goto TermScan;
25553 }
25554 break;
25555 case '[':
@@ -25556,18 +26305,18 @@
25556 cin = ']';
25557 /* fall thru */
25558 case '`': case '\'': case '"':
25559 cWait = cin;
25560 qss = QSS_HasDark | cWait;
25561 CONTINUE_PROMPT_AWAITC(pst, cin);
25562 goto TermScan;
25563 case '(':
25564 CONTINUE_PAREN_INCR(pst, 1);
25565 break;
25566 case ')':
25567 CONTINUE_PAREN_INCR(pst, -1);
25568 break;
25569 default:
25570 break;
25571 }
25572 qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
25573 }
@@ -25579,23 +26328,23 @@
25579 case '*':
25580 if( *zLine != '/' )
25581 continue;
25582 ++zLine;
25583 cWait = 0;
25584 CONTINUE_PROMPT_AWAITC(pst, 0);
25585 qss = QSS_SETV(qss, 0);
25586 goto PlainScan;
25587 case '`': case '\'': case '"':
25588 if(*zLine==cWait){
25589 /* Swallow doubled end-delimiter.*/
25590 ++zLine;
25591 continue;
25592 }
25593 /* fall thru */
25594 case ']':
25595 cWait = 0;
25596 CONTINUE_PROMPT_AWAITC(pst, 0);
25597 qss = QSS_SETV(qss, 0);
25598 goto PlainScan;
25599 default: assert(0);
25600 }
25601 }
@@ -25696,13 +26445,13 @@
25696 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
25697 }
25698
25699 #ifdef SQLITE_SHELL_FIDDLE
25700 /*
25701 ** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
25702 ** because we need the global shellState and cannot access it from that function
25703 ** without moving lots of code around (creating a larger/messier diff).
25704 */
25705 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
25706 /* Parse the next line from shellState.wasm.zInput. */
25707 const char *zBegin = shellState.wasm.zPos;
25708 const char *z = zBegin;
@@ -26517,16 +27266,16 @@
26517 data.openMode = SHELL_OPEN_READONLY;
26518 }else if( cli_strcmp(z,"-nofollow")==0 ){
26519 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
26520 }else if( cli_strcmp(z,"-ascii")==0 ){
26521 data.mode = MODE_Ascii;
26522 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator, SEP_Unit);
26523 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator, SEP_Record);
26524 }else if( cli_strcmp(z,"-tabs")==0 ){
26525 data.mode = MODE_List;
26526 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator, SEP_Tab);
26527 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator, SEP_Row);
26528 }else if( cli_strcmp(z,"-separator")==0 ){
26529 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
26530 "%s",cmdline_option_value(argc,argv,++i));
26531 }else if( cli_strcmp(z,"-newline")==0 ){
26532 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
26533
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -37,11 +37,11 @@
37 typedef unsigned int u32;
38 typedef unsigned short int u16;
39
40 /*
41 ** Optionally #include a user-defined header, whereby compilation options
42 ** may be set prior to where they take effect, but after platform setup.
43 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
44 ** file. Note that this macro has a like effect on sqlite3.c compilation.
45 */
46 # define SHELL_STRINGIFY_(f) #f
47 # define SHELL_STRINGIFY(f) SHELL_STRINGIFY_(f)
@@ -551,24 +551,25 @@
551 if( continuePrompt[0]==0
552 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
553 return continuePrompt;
554 }else{
555 if( dynPrompt.zScannerAwaits ){
556 size_t ncp = strlen(continuePrompt);
557 size_t ndp = strlen(dynPrompt.zScannerAwaits);
558 if( ndp > ncp-3 ) return continuePrompt;
559 strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
560 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
561 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
562 PROMPT_LEN_MAX-4);
563 }else{
564 if( dynPrompt.inParenLevel>9 ){
565 strncpy(dynPrompt.dynamicPrompt, "(..", 4);
566 }else if( dynPrompt.inParenLevel<0 ){
567 strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
568 }else{
569 strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
570 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
571 }
572 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
573 }
574 }
575 return dynPrompt.dynamicPrompt;
@@ -1049,11 +1050,11 @@
1050 ){
1051 const char *zName;
1052 char *zFake;
1053 UNUSED_PARAMETER(nVal);
1054 zName = (const char*)sqlite3_value_text(apVal[0]);
1055 zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
1056 if( zFake ){
1057 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
1058 -1, sqlite3_free);
1059 free(zFake);
1060 }
@@ -3050,11 +3051,11 @@
3051 unsigned int i;
3052 (void)pzErrMsg; /* Unused parameter */
3053
3054 SQLITE_EXTENSION_INIT2(pApi);
3055
3056 for(i=0; i<(int)(sizeof(aFunc)/sizeof(aFunc[0])) && rc==SQLITE_OK; i++){
3057 rc = sqlite3_create_function(db, aFunc[i].zFuncName, aFunc[i].nArg,
3058 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
3059 0, aFunc[i].xFunc, 0, 0);
3060 }
3061 if( rc==SQLITE_OK ){
@@ -3069,10 +3070,724 @@
3070 }
3071 return rc;
3072 }
3073
3074 /************************* End ../ext/misc/decimal.c ********************/
3075 #undef sqlite3_base_init
3076 #define sqlite3_base_init sqlite3_base64_init
3077 /************************* Begin ../ext/misc/base64.c ******************/
3078 /*
3079 ** 2022-11-18
3080 **
3081 ** The author disclaims copyright to this source code. In place of
3082 ** a legal notice, here is a blessing:
3083 **
3084 ** May you do good and not evil.
3085 ** May you find forgiveness for yourself and forgive others.
3086 ** May you share freely, never taking more than you give.
3087 **
3088 *************************************************************************
3089 **
3090 ** This is a SQLite extension for converting in either direction
3091 ** between a (binary) blob and base64 text. Base64 can transit a
3092 ** sane USASCII channel unmolested. It also plays nicely in CSV or
3093 ** written as TCL brace-enclosed literals or SQL string literals,
3094 ** and can be used unmodified in XML-like documents.
3095 **
3096 ** This is an independent implementation of conversions specified in
3097 ** RFC 4648, done on the above date by the author (Larry Brasfield)
3098 ** who thereby has the right to put this into the public domain.
3099 **
3100 ** The conversions meet RFC 4648 requirements, provided that this
3101 ** C source specifies that line-feeds are included in the encoded
3102 ** data to limit visible line lengths to 72 characters and to
3103 ** terminate any encoded blob having non-zero length.
3104 **
3105 ** Length limitations are not imposed except that the runtime
3106 ** SQLite string or blob length limits are respected. Otherwise,
3107 ** any length binary sequence can be represented and recovered.
3108 ** Generated base64 sequences, with their line-feeds included,
3109 ** can be concatenated; the result converted back to binary will
3110 ** be the concatenation of the represented binary sequences.
3111 **
3112 ** This SQLite3 extension creates a function, base64(x), which
3113 ** either: converts text x containing base64 to a returned blob;
3114 ** or converts a blob x to returned text containing base64. An
3115 ** error will be thrown for other input argument types.
3116 **
3117 ** This code relies on UTF-8 encoding only with respect to the
3118 ** meaning of the first 128 (7-bit) codes matching that of USASCII.
3119 ** It will fail miserably if somehow made to try to convert EBCDIC.
3120 ** Because it is table-driven, it could be enhanced to handle that,
3121 ** but the world and SQLite have moved on from that anachronism.
3122 **
3123 ** To build the extension:
3124 ** Set shell variable SQDIR=<your favorite SQLite checkout directory>
3125 ** *Nix: gcc -O2 -shared -I$SQDIR -fPIC -o base64.so base64.c
3126 ** OSX: gcc -O2 -dynamiclib -fPIC -I$SQDIR -o base64.dylib base64.c
3127 ** Win32: gcc -O2 -shared -I%SQDIR% -o base64.dll base64.c
3128 ** Win32: cl /Os -I%SQDIR% base64.c -link -dll -out:base64.dll
3129 */
3130
3131 #include <assert.h>
3132
3133 /* #include "sqlite3ext.h" */
3134
3135 SQLITE_EXTENSION_INIT1;
3136
3137 #define PC 0x80 /* pad character */
3138 #define WS 0x81 /* whitespace */
3139 #define ND 0x82 /* Not above or digit-value */
3140 #define PAD_CHAR '='
3141
3142 #ifndef U8_TYPEDEF
3143 /* typedef unsigned char u8; */
3144 #define U8_TYPEDEF
3145 #endif
3146
3147 static const u8 b64DigitValues[128] = {
3148 /* HT LF VT FF CR */
3149 ND,ND,ND,ND, ND,ND,ND,ND, ND,WS,WS,WS, WS,WS,ND,ND,
3150 /* US */
3151 ND,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,ND,
3152 /*sp + / */
3153 WS,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,62, ND,ND,ND,63,
3154 /* 0 1 5 9 = */
3155 52,53,54,55, 56,57,58,59, 60,61,ND,ND, ND,PC,ND,ND,
3156 /* A O */
3157 ND, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
3158 /* P Z */
3159 15,16,17,18, 19,20,21,22, 23,24,25,ND, ND,ND,ND,ND,
3160 /* a o */
3161 ND,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
3162 /* p z */
3163 41,42,43,44, 45,46,47,48, 49,50,51,ND, ND,ND,ND,ND
3164 };
3165
3166 static const char b64Numerals[64+1]
3167 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3168
3169 #define BX_DV_PROTO(c) \
3170 ((((u8)(c))<0x80)? (u8)(b64DigitValues[(u8)(c)]) : 0x80)
3171 #define IS_BX_DIGIT(bdp) (((u8)(bdp))<0x80)
3172 #define IS_BX_WS(bdp) ((bdp)==WS)
3173 #define IS_BX_PAD(bdp) ((bdp)==PC)
3174 #define BX_NUMERAL(dv) (b64Numerals[(u8)(dv)])
3175 /* Width of base64 lines. Should be an integer multiple of 4. */
3176 #define B64_DARK_MAX 72
3177
3178 /* Encode a byte buffer into base64 text with linefeeds appended to limit
3179 ** encoded group lengths to B64_DARK_MAX or to terminate the last group.
3180 */
3181 static char* toBase64( u8 *pIn, int nbIn, char *pOut ){
3182 int nCol = 0;
3183 while( nbIn >= 3 ){
3184 /* Do the bit-shuffle, exploiting unsigned input to avoid masking. */
3185 pOut[0] = BX_NUMERAL(pIn[0]>>2);
3186 pOut[1] = BX_NUMERAL(((pIn[0]<<4)|(pIn[1]>>4))&0x3f);
3187 pOut[2] = BX_NUMERAL(((pIn[1]&0xf)<<2)|(pIn[2]>>6));
3188 pOut[3] = BX_NUMERAL(pIn[2]&0x3f);
3189 pOut += 4;
3190 nbIn -= 3;
3191 pIn += 3;
3192 if( (nCol += 4)>=B64_DARK_MAX || nbIn<=0 ){
3193 *pOut++ = '\n';
3194 nCol = 0;
3195 }
3196 }
3197 if( nbIn > 0 ){
3198 signed char nco = nbIn+1;
3199 int nbe;
3200 unsigned long qv = *pIn++;
3201 for( nbe=1; nbe<3; ++nbe ){
3202 qv <<= 8;
3203 if( nbe<nbIn ) qv |= *pIn++;
3204 }
3205 for( nbe=3; nbe>=0; --nbe ){
3206 char ce = (nbe<nco)? BX_NUMERAL((u8)(qv & 0x3f)) : PAD_CHAR;
3207 qv >>= 6;
3208 pOut[nbe] = ce;
3209 }
3210 pOut += 4;
3211 *pOut++ = '\n';
3212 }
3213 *pOut = 0;
3214 return pOut;
3215 }
3216
3217 /* Skip over text which is not base64 numeral(s). */
3218 static char * skipNonB64( char *s ){
3219 char c;
3220 while( (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
3221 return s;
3222 }
3223
3224 /* Decode base64 text into a byte buffer. */
3225 static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
3226 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3227 while( ncIn>0 && *pIn!=PAD_CHAR ){
3228 static signed char nboi[] = { 0, 0, 1, 2, 3 };
3229 char *pUse = skipNonB64(pIn);
3230 unsigned long qv = 0L;
3231 int nti, nbo, nac;
3232 ncIn -= (pUse - pIn);
3233 pIn = pUse;
3234 nti = (ncIn>4)? 4 : ncIn;
3235 ncIn -= nti;
3236 nbo = nboi[nti];
3237 if( nbo==0 ) break;
3238 for( nac=0; nac<4; ++nac ){
3239 char c = (nac<nti)? *pIn++ : b64Numerals[0];
3240 u8 bdp = BX_DV_PROTO(c);
3241 switch( bdp ){
3242 case ND:
3243 /* Treat dark non-digits as pad, but they terminate decode too. */
3244 ncIn = 0;
3245 /* fall thru */
3246 case WS:
3247 /* Treat whitespace as pad and terminate this group.*/
3248 nti = nac;
3249 /* fall thru */
3250 case PC:
3251 bdp = 0;
3252 --nbo;
3253 /* fall thru */
3254 default: /* bdp is the digit value. */
3255 qv = qv<<6 | bdp;
3256 break;
3257 }
3258 }
3259 switch( nbo ){
3260 case 3:
3261 pOut[2] = (qv) & 0xff;
3262 case 2:
3263 pOut[1] = (qv>>8) & 0xff;
3264 case 1:
3265 pOut[0] = (qv>>16) & 0xff;
3266 }
3267 pOut += nbo;
3268 }
3269 return pOut;
3270 }
3271
3272 /* This function does the work for the SQLite base64(x) UDF. */
3273 static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
3274 int nb, nc, nv = sqlite3_value_bytes(av[0]);
3275 int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
3276 SQLITE_LIMIT_LENGTH, -1);
3277 char *cBuf;
3278 u8 *bBuf;
3279 assert(na==1);
3280 switch( sqlite3_value_type(av[0]) ){
3281 case SQLITE_BLOB:
3282 nb = nv;
3283 nc = 4*(nv+2/3); /* quads needed */
3284 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
3285 if( nvMax < nc ){
3286 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
3287 return;
3288 }
3289 cBuf = sqlite3_malloc(nc);
3290 if( !cBuf ) goto memFail;
3291 bBuf = (u8*)sqlite3_value_blob(av[0]);
3292 nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
3293 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3294 break;
3295 case SQLITE_TEXT:
3296 nc = nv;
3297 nb = 3*((nv+3)/4); /* may overestimate due to LF and padding */
3298 if( nvMax < nb ){
3299 sqlite3_result_error(context, "blob from base64 may be too big", -1);
3300 return;
3301 }else if( nb<1 ){
3302 nb = 1;
3303 }
3304 bBuf = sqlite3_malloc(nb);
3305 if( !bBuf ) goto memFail;
3306 cBuf = (char *)sqlite3_value_text(av[0]);
3307 nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
3308 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3309 break;
3310 default:
3311 sqlite3_result_error(context, "base64 accepts only blob or text", -1);
3312 return;
3313 }
3314 return;
3315 memFail:
3316 sqlite3_result_error(context, "base64 OOM", -1);
3317 }
3318
3319 /*
3320 ** Establish linkage to running SQLite library.
3321 */
3322 #ifndef SQLITE_SHELL_EXTFUNCS
3323 #ifdef _WIN32
3324
3325 #endif
3326 int sqlite3_base_init
3327 #else
3328 static int sqlite3_base64_init
3329 #endif
3330 (sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi){
3331 SQLITE_EXTENSION_INIT2(pApi);
3332 (void)pzErr;
3333 return sqlite3_create_function
3334 (db, "base64", 1,
3335 SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|SQLITE_DIRECTONLY|SQLITE_UTF8,
3336 0, base64, 0, 0);
3337 }
3338
3339 /*
3340 ** Define some macros to allow this extension to be built into the shell
3341 ** conveniently, in conjunction with use of SQLITE_SHELL_EXTFUNCS. This
3342 ** allows shell.c, as distributed, to have this extension built in.
3343 */
3344 #define BASE64_INIT(db) sqlite3_base64_init(db, 0, 0)
3345 #define BASE64_EXPOSE(db, pzErr) /* Not needed, ..._init() does this. */
3346
3347 /************************* End ../ext/misc/base64.c ********************/
3348 #undef sqlite3_base_init
3349 #define sqlite3_base_init sqlite3_base85_init
3350 #define OMIT_BASE85_CHECKER
3351 /************************* Begin ../ext/misc/base85.c ******************/
3352 /*
3353 ** 2022-11-16
3354 **
3355 ** The author disclaims copyright to this source code. In place of
3356 ** a legal notice, here is a blessing:
3357 **
3358 ** May you do good and not evil.
3359 ** May you find forgiveness for yourself and forgive others.
3360 ** May you share freely, never taking more than you give.
3361 **
3362 *************************************************************************
3363 **
3364 ** This is a utility for converting binary to base85 or vice-versa.
3365 ** It can be built as a standalone program or an SQLite3 extension.
3366 **
3367 ** Much like base64 representations, base85 can be sent through a
3368 ** sane USASCII channel unmolested. It also plays nicely in CSV or
3369 ** written as TCL brace-enclosed literals or SQL string literals.
3370 ** It is not suited for unmodified use in XML-like documents.
3371 **
3372 ** The encoding used resembles Ascii85, but was devised by the author
3373 ** (Larry Brasfield) before Mozilla, Adobe, ZMODEM or other Ascii85
3374 ** variant sources existed, in the 1984 timeframe on a VAX mainframe.
3375 ** Further, this is an independent implementation of a base85 system.
3376 ** Hence, the author has rightfully put this into the public domain.
3377 **
3378 ** Base85 numerals are taken from the set of 7-bit USASCII codes,
3379 ** excluding control characters and Space ! " ' ( ) { | } ~ Del
3380 ** in code order representing digit values 0 to 84 (base 10.)
3381 **
3382 ** Groups of 4 bytes, interpreted as big-endian 32-bit values,
3383 ** are represented as 5-digit base85 numbers with MS to LS digit
3384 ** order. Groups of 1-3 bytes are represented with 2-4 digits,
3385 ** still big-endian but 8-24 bit values. (Using big-endian yields
3386 ** the simplest transition to byte groups smaller than 4 bytes.
3387 ** These byte groups can also be considered base-256 numbers.)
3388 ** Groups of 0 bytes are represented with 0 digits and vice-versa.
3389 ** No pad characters are used; Encoded base85 numeral sequence
3390 ** (aka "group") length maps 1-to-1 to the decoded binary length.
3391 **
3392 ** Any character not in the base85 numeral set delimits groups.
3393 ** When base85 is streamed or stored in containers of indefinite
3394 ** size, newline is used to separate it into sub-sequences of no
3395 ** more than 80 digits so that fgets() can be used to read it.
3396 **
3397 ** Length limitations are not imposed except that the runtime
3398 ** SQLite string or blob length limits are respected. Otherwise,
3399 ** any length binary sequence can be represented and recovered.
3400 ** Base85 sequences can be concatenated by separating them with
3401 ** a non-base85 character; the conversion to binary will then
3402 ** be the concatenation of the represented binary sequences.
3403
3404 ** The standalone program either converts base85 on stdin to create
3405 ** a binary file or converts a binary file to base85 on stdout.
3406 ** Read or make it blurt its help for invocation details.
3407 **
3408 ** The SQLite3 extension creates a function, base85(x), which will
3409 ** either convert text base85 to a blob or a blob to text base85
3410 ** and return the result (or throw an error for other types.)
3411 ** Unless built with OMIT_BASE85_CHECKER defined, it also creates a
3412 ** function, is_base85(t), which returns 1 iff the text t contains
3413 ** nothing other than base85 numerals and whitespace, or 0 otherwise.
3414 **
3415 ** To build the extension:
3416 ** Set shell variable SQDIR=<your favorite SQLite checkout directory>
3417 ** and variable OPTS to -DOMIT_BASE85_CHECKER if is_base85() unwanted.
3418 ** *Nix: gcc -O2 -shared -I$SQDIR $OPTS -fPIC -o base85.so base85.c
3419 ** OSX: gcc -O2 -dynamiclib -fPIC -I$SQDIR $OPTS -o base85.dylib base85.c
3420 ** Win32: gcc -O2 -shared -I%SQDIR% %OPTS% -o base85.dll base85.c
3421 ** Win32: cl /Os -I%SQDIR% %OPTS% base85.c -link -dll -out:base85.dll
3422 **
3423 ** To build the standalone program, define PP symbol BASE85_STANDALONE. Eg.
3424 ** *Nix or OSX: gcc -O2 -DBASE85_STANDALONE base85.c -o base85
3425 ** Win32: gcc -O2 -DBASE85_STANDALONE -o base85.exe base85.c
3426 ** Win32: cl /Os /MD -DBASE85_STANDALONE base85.c
3427 */
3428
3429 #include <stdio.h>
3430 #include <memory.h>
3431 #include <string.h>
3432 #include <assert.h>
3433 #ifndef OMIT_BASE85_CHECKER
3434 # include <ctype.h>
3435 #endif
3436
3437 #ifndef BASE85_STANDALONE
3438
3439 /* # include "sqlite3ext.h" */
3440
3441 SQLITE_EXTENSION_INIT1;
3442
3443 #else
3444
3445 # ifdef _WIN32
3446 # include <io.h>
3447 # include <fcntl.h>
3448 # else
3449 # define setmode(fd,m)
3450 # endif
3451
3452 static char *zHelp =
3453 "Usage: base85 <dirFlag> <binFile>\n"
3454 " <dirFlag> is either -r to read or -w to write <binFile>,\n"
3455 " content to be converted to/from base85 on stdout/stdin.\n"
3456 " <binFile> names a binary file to be rendered or created.\n"
3457 " Or, the name '-' refers to the stdin or stdout stream.\n"
3458 ;
3459
3460 static void sayHelp(){
3461 printf("%s", zHelp);
3462 }
3463 #endif
3464
3465 #ifndef U8_TYPEDEF
3466 /* typedef unsigned char u8; */
3467 #define U8_TYPEDEF
3468 #endif
3469
3470 /* Classify c according to interval within USASCII set w.r.t. base85
3471 * Values of 1 and 3 are base85 numerals. Values of 0, 2, or 4 are not.
3472 */
3473 #define B85_CLASS( c ) (((c)>='#')+((c)>'&')+((c)>='*')+((c)>'z'))
3474
3475 /* Provide digitValue to b85Numeral offset as a function of above class. */
3476 static u8 b85_cOffset[] = { 0, '#', 0, '*'-4, 0 };
3477 #define B85_DNOS( c ) b85_cOffset[B85_CLASS(c)]
3478
3479 /* Say whether c is a base85 numeral. */
3480 #define IS_B85( c ) (B85_CLASS(c) & 1)
3481
3482 #if 0 /* Not used, */
3483 static u8 base85DigitValue( char c ){
3484 u8 dv = (u8)(c - '#');
3485 if( dv>87 ) return 0xff;
3486 return (dv > 3)? dv-3 : dv;
3487 }
3488 #endif
3489
3490 /* Width of base64 lines. Should be an integer multiple of 5. */
3491 #define B85_DARK_MAX 80
3492
3493
3494 static char * skipNonB85( char *s ){
3495 char c;
3496 while( (c = *s) && !IS_B85(c) ) ++s;
3497 return s;
3498 }
3499
3500 /* Convert small integer, known to be in 0..84 inclusive, to base85 numeral.
3501 * Do not use the macro form with argument expression having a side-effect.*/
3502 #if 0
3503 static char base85Numeral( u8 b ){
3504 return (b < 4)? (char)(b + '#') : (char)(b - 4 + '*');
3505 }
3506 #else
3507 # define base85Numeral( dn )\
3508 ((char)(((dn) < 4)? (char)((dn) + '#') : (char)((dn) - 4 + '*')))
3509 #endif
3510
3511 static char *putcs(char *pc, char *s){
3512 char c;
3513 while( (c = *s++)!=0 ) *pc++ = c;
3514 return pc;
3515 }
3516
3517 /* Encode a byte buffer into base85 text. If pSep!=0, it's a C string
3518 ** to be appended to encoded groups to limit their length to B85_DARK_MAX
3519 ** or to terminate the last group (to aid concatenation.)
3520 */
3521 static char* toBase85( u8 *pIn, int nbIn, char *pOut, char *pSep ){
3522 int nCol = 0;
3523 while( nbIn >= 4 ){
3524 int nco = 5;
3525 unsigned long qbv = (pIn[0]<<24)|(pIn[1]<<16)|(pIn[2]<<8)|pIn[3];
3526 while( nco > 0 ){
3527 unsigned nqv = (unsigned)(qbv/85UL);
3528 unsigned char dv = qbv - 85UL*nqv;
3529 qbv = nqv;
3530 pOut[--nco] = base85Numeral(dv);
3531 }
3532 nbIn -= 4;
3533 pIn += 4;
3534 pOut += 5;
3535 if( pSep && (nCol += 5)>=B85_DARK_MAX ){
3536 pOut = putcs(pOut, pSep);
3537 nCol = 0;
3538 }
3539 }
3540 if( nbIn > 0 ){
3541 int nco = nbIn + 1;
3542 unsigned long qv = *pIn++;
3543 int nbe = 1;
3544 while( nbe++ < nbIn ){
3545 qv = (qv<<8) | *pIn++;
3546 }
3547 nCol += nco;
3548 while( nco > 0 ){
3549 u8 dv = (u8)(qv % 85);
3550 qv /= 85;
3551 pOut[--nco] = base85Numeral(dv);
3552 }
3553 pOut += (nbIn+1);
3554 }
3555 if( pSep && nCol>0 ) pOut = putcs(pOut, pSep);
3556 *pOut = 0;
3557 return pOut;
3558 }
3559
3560 /* Decode base85 text into a byte buffer. */
3561 static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
3562 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3563 while( ncIn>0 ){
3564 static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
3565 char *pUse = skipNonB85(pIn);
3566 unsigned long qv = 0L;
3567 int nti, nbo;
3568 ncIn -= (pUse - pIn);
3569 pIn = pUse;
3570 nti = (ncIn>5)? 5 : ncIn;
3571 nbo = nboi[nti];
3572 if( nbo==0 ) break;
3573 while( nti>0 ){
3574 char c = *pIn++;
3575 u8 cdo = B85_DNOS(c);
3576 --ncIn;
3577 if( cdo==0 ) break;
3578 qv = 85 * qv + (c - cdo);
3579 --nti;
3580 }
3581 nbo -= nti; /* Adjust for early (non-digit) end of group. */
3582 switch( nbo ){
3583 case 4:
3584 *pOut++ = (qv >> 24)&0xff;
3585 case 3:
3586 *pOut++ = (qv >> 16)&0xff;
3587 case 2:
3588 *pOut++ = (qv >> 8)&0xff;
3589 case 1:
3590 *pOut++ = qv&0xff;
3591 case 0:
3592 break;
3593 }
3594 }
3595 return pOut;
3596 }
3597
3598 #ifndef OMIT_BASE85_CHECKER
3599 /* Say whether input char sequence is all (base85 and/or whitespace).*/
3600 static int allBase85( char *p, int len ){
3601 char c;
3602 while( len-- > 0 && (c = *p++) != 0 ){
3603 if( !IS_B85(c) && !isspace(c) ) return 0;
3604 }
3605 return 1;
3606 }
3607 #endif
3608
3609 #ifndef BASE85_STANDALONE
3610
3611 # ifndef OMIT_BASE85_CHECKER
3612 /* This function does the work for the SQLite is_base85(t) UDF. */
3613 static void is_base85(sqlite3_context *context, int na, sqlite3_value *av[]){
3614 assert(na==1);
3615 switch( sqlite3_value_type(av[0]) ){
3616 case SQLITE_TEXT:
3617 {
3618 int rv = allBase85( (char *)sqlite3_value_text(av[0]),
3619 sqlite3_value_bytes(av[0]) );
3620 sqlite3_result_int(context, rv);
3621 }
3622 break;
3623 case SQLITE_NULL:
3624 sqlite3_result_null(context);
3625 break;
3626 default:
3627 sqlite3_result_error(context, "is_base85 accepts only text or NULL", -1);
3628 return;
3629 }
3630 }
3631 # endif
3632
3633 /* This function does the work for the SQLite base85(x) UDF. */
3634 static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
3635 int nb, nc, nv = sqlite3_value_bytes(av[0]);
3636 int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
3637 SQLITE_LIMIT_LENGTH, -1);
3638 char *cBuf;
3639 u8 *bBuf;
3640 assert(na==1);
3641 switch( sqlite3_value_type(av[0]) ){
3642 case SQLITE_BLOB:
3643 nb = nv;
3644 /* ulongs tail newlines tailenc+nul*/
3645 nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
3646 if( nvMax < nc ){
3647 sqlite3_result_error(context, "blob expanded to base85 too big", -1);
3648 return;
3649 }
3650 cBuf = sqlite3_malloc(nc);
3651 if( !cBuf ) goto memFail;
3652 bBuf = (u8*)sqlite3_value_blob(av[0]);
3653 nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
3654 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3655 break;
3656 case SQLITE_TEXT:
3657 nc = nv;
3658 nb = 4*(nv/5) + nv%5; /* may overestimate */
3659 if( nvMax < nb ){
3660 sqlite3_result_error(context, "blob from base85 may be too big", -1);
3661 return;
3662 }else if( nb<1 ){
3663 nb = 1;
3664 }
3665 bBuf = sqlite3_malloc(nb);
3666 if( !bBuf ) goto memFail;
3667 cBuf = (char *)sqlite3_value_text(av[0]);
3668 nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
3669 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3670 break;
3671 default:
3672 sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
3673 return;
3674 }
3675 return;
3676 memFail:
3677 sqlite3_result_error(context, "base85 OOM", -1);
3678 }
3679
3680 /*
3681 ** Establish linkage to running SQLite library.
3682 */
3683 #ifndef SQLITE_SHELL_EXTFUNCS
3684 #ifdef _WIN32
3685
3686 #endif
3687 int sqlite3_base_init
3688 #else
3689 static int sqlite3_base85_init
3690 #endif
3691 (sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi){
3692 SQLITE_EXTENSION_INIT2(pApi);
3693 (void)pzErr;
3694 # ifndef OMIT_BASE85_CHECKER
3695 {
3696 int rc = sqlite3_create_function
3697 (db, "is_base85", 1,
3698 SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|SQLITE_UTF8,
3699 0, is_base85, 0, 0);
3700 if( rc!=SQLITE_OK ) return rc;
3701 }
3702 # endif
3703 return sqlite3_create_function
3704 (db, "base85", 1,
3705 SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|SQLITE_DIRECTONLY|SQLITE_UTF8,
3706 0, base85, 0, 0);
3707 }
3708
3709 /*
3710 ** Define some macros to allow this extension to be built into the shell
3711 ** conveniently, in conjunction with use of SQLITE_SHELL_EXTFUNCS. This
3712 ** allows shell.c, as distributed, to have this extension built in.
3713 */
3714 # define BASE85_INIT(db) sqlite3_base85_init(db, 0, 0)
3715 # define BASE85_EXPOSE(db, pzErr) /* Not needed, ..._init() does this. */
3716
3717 #else /* standalone program */
3718
3719 int main(int na, char *av[]){
3720 int cin;
3721 int rc = 0;
3722 u8 bBuf[4*(B85_DARK_MAX/5)];
3723 char cBuf[5*(sizeof(bBuf)/4)+2];
3724 size_t nio;
3725 # ifndef OMIT_BASE85_CHECKER
3726 int b85Clean = 1;
3727 # endif
3728 char rw;
3729 FILE *fb = 0, *foc = 0;
3730 char fmode[3] = "xb";
3731 if( na < 3 || av[1][0]!='-' || (rw = av[1][1])==0 || (rw!='r' && rw!='w') ){
3732 sayHelp();
3733 return 0;
3734 }
3735 fmode[0] = rw;
3736 if( av[2][0]=='-' && av[2][1]==0 ){
3737 switch( rw ){
3738 case 'r':
3739 fb = stdin;
3740 setmode(fileno(stdin), O_BINARY);
3741 break;
3742 case 'w':
3743 fb = stdout;
3744 setmode(fileno(stdout), O_BINARY);
3745 break;
3746 }
3747 }else{
3748 fb = fopen(av[2], fmode);
3749 foc = fb;
3750 }
3751 if( !fb ){
3752 fprintf(stderr, "Cannot open %s for %c\n", av[2], rw);
3753 rc = 1;
3754 }else{
3755 switch( rw ){
3756 case 'r':
3757 while( (nio = fread( bBuf, 1, sizeof(bBuf), fb))>0 ){
3758 toBase85( bBuf, (int)nio, cBuf, 0 );
3759 fprintf(stdout, "%s\n", cBuf);
3760 }
3761 break;
3762 case 'w':
3763 while( 0 != fgets(cBuf, sizeof(cBuf), stdin) ){
3764 int nc = strlen(cBuf);
3765 size_t nbo = fromBase85( cBuf, nc, bBuf ) - bBuf;
3766 if( 1 != fwrite(bBuf, nbo, 1, fb) ) rc = 1;
3767 # ifndef OMIT_BASE85_CHECKER
3768 b85Clean &= allBase85( cBuf, nc );
3769 # endif
3770 }
3771 break;
3772 default:
3773 sayHelp();
3774 rc = 1;
3775 }
3776 if( foc ) fclose(foc);
3777 }
3778 # ifndef OMIT_BASE85_CHECKER
3779 if( !b85Clean ){
3780 fprintf(stderr, "Base85 input had non-base85 dark or control content.\n");
3781 }
3782 # endif
3783 return rc;
3784 }
3785
3786 #endif
3787
3788 /************************* End ../ext/misc/base85.c ********************/
3789 /************************* Begin ../ext/misc/ieee754.c ******************/
3790 /*
3791 ** 2013-04-17
3792 **
3793 ** The author disclaims copyright to this source code. In place of
@@ -4633,10 +5348,11 @@
5348 ReCompiled *pRe;
5349 sqlite3_str *pStr;
5350 int i;
5351 int n;
5352 char *z;
5353 (void)argc;
5354
5355 zPattern = (const char*)sqlite3_value_text(argv[0]);
5356 if( zPattern==0 ) return;
5357 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
5358 if( zErr ){
@@ -7280,10 +7996,11 @@
7996 int nByte = sizeof(ZipfileTab) + ZIPFILE_BUFFER_SIZE;
7997 int nFile = 0;
7998 const char *zFile = 0;
7999 ZipfileTab *pNew = 0;
8000 int rc;
8001 (void)pAux;
8002
8003 /* If the table name is not "zipfile", require that the argument be
8004 ** specified. This stops zipfile tables from being created as:
8005 **
8006 ** CREATE VIRTUAL TABLE zzz USING zipfile();
@@ -7736,10 +8453,11 @@
8453 ZipfileEntry **ppEntry /* OUT: Pointer to new object */
8454 ){
8455 u8 *aRead;
8456 char **pzErr = &pTab->base.zErrMsg;
8457 int rc = SQLITE_OK;
8458 (void)nBlob;
8459
8460 if( aBlob==0 ){
8461 aRead = pTab->aBuffer;
8462 rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr);
8463 }else{
@@ -8181,10 +8899,13 @@
8899 ZipfileTab *pTab = (ZipfileTab*)cur->pVtab;
8900 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
8901 const char *zFile = 0; /* Zip file to scan */
8902 int rc = SQLITE_OK; /* Return Code */
8903 int bInMemory = 0; /* True for an in-memory zipfile */
8904
8905 (void)idxStr;
8906 (void)argc;
8907
8908 zipfileResetCursor(pCsr);
8909
8910 if( pTab->zFile ){
8911 zFile = pTab->zFile;
@@ -8242,10 +8963,11 @@
8963 sqlite3_index_info *pIdxInfo
8964 ){
8965 int i;
8966 int idx = -1;
8967 int unusable = 0;
8968 (void)tab;
8969
8970 for(i=0; i<pIdxInfo->nConstraint; i++){
8971 const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
8972 if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue;
8973 if( pCons->usable==0 ){
@@ -8491,10 +9213,12 @@
9213 ZipfileEntry *pOld = 0;
9214 ZipfileEntry *pOld2 = 0;
9215 int bUpdate = 0; /* True for an update that modifies "name" */
9216 int bIsDir = 0;
9217 u32 iCrc32 = 0;
9218
9219 (void)pRowid;
9220
9221 if( pTab->pWriteFd==0 ){
9222 rc = zipfileBegin(pVtab);
9223 if( rc!=SQLITE_OK ) return rc;
9224 }
@@ -8826,10 +9550,11 @@
9550 int nArg, /* Number of SQL function arguments */
9551 const char *zName, /* Name of SQL function */
9552 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
9553 void **ppArg /* OUT: User data for *pxFunc */
9554 ){
9555 (void)nArg;
9556 if( sqlite3_stricmp("zipfile_cds", zName)==0 ){
9557 *pxFunc = zipfileFunctionCds;
9558 *ppArg = (void*)pVtab;
9559 return 1;
9560 }
@@ -11917,10 +12642,13 @@
12642 char **pzErr
12643 ){
12644 DbdataTable *pTab = 0;
12645 int rc = sqlite3_declare_vtab(db, pAux ? DBPTR_SCHEMA : DBDATA_SCHEMA);
12646
12647 (void)argc;
12648 (void)argv;
12649 (void)pzErr;
12650 if( rc==SQLITE_OK ){
12651 pTab = (DbdataTable*)sqlite3_malloc64(sizeof(DbdataTable));
12652 if( pTab==0 ){
12653 rc = SQLITE_NOMEM;
12654 }else{
@@ -12521,10 +13249,12 @@
13249 ){
13250 DbdataCursor *pCsr = (DbdataCursor*)pCursor;
13251 DbdataTable *pTab = (DbdataTable*)pCursor->pVtab;
13252 int rc = SQLITE_OK;
13253 const char *zSchema = "main";
13254 (void)idxStr;
13255 (void)argc;
13256
13257 dbdataResetCursor(pCsr);
13258 assert( pCsr->iPgno==1 );
13259 if( idxNum & 0x01 ){
13260 zSchema = (const char*)sqlite3_value_text(argv[0]);
@@ -12689,10 +13419,11 @@
13419 sqlite3 *db,
13420 char **pzErrMsg,
13421 const sqlite3_api_routines *pApi
13422 ){
13423 SQLITE_EXTENSION_INIT2(pApi);
13424 (void)pzErrMsg;
13425 return sqlite3DbdataRegister(db);
13426 }
13427
13428 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
13429
@@ -13459,10 +14190,11 @@
14190 sqlite3_context *context,
14191 int argc,
14192 sqlite3_value **argv
14193 ){
14194 const char *zText = (const char*)sqlite3_value_text(argv[0]);
14195 (void)argc;
14196 if( zText && zText[0]=='\'' ){
14197 int nText = sqlite3_value_bytes(argv[0]);
14198 int i;
14199 char zBuf1[20];
14200 char zBuf2[20];
@@ -13611,11 +14343,11 @@
14343 if( rc!=SQLITE_OK ){
14344 recoverDbError(p, db2);
14345 return;
14346 }
14347
14348 for(ii=0; ii<(int)(sizeof(aPragma)/sizeof(aPragma[0])); ii++){
14349 const char *zPrag = aPragma[ii];
14350 sqlite3_stmt *p1 = 0;
14351 p1 = recoverPreparePrintf(p, p->dbIn, "PRAGMA %Q.%s", p->zDb, zPrag);
14352 if( p->errCode==SQLITE_OK && sqlite3_step(p1)==SQLITE_ROW ){
14353 const char *zArg = (const char*)sqlite3_column_text(p1, 0);
@@ -13689,11 +14421,13 @@
14421 if( p->errCode==SQLITE_OK ){
14422 p->errCode = sqlite3_dbdata_init(db, 0, 0);
14423 }
14424
14425 /* Register the custom user-functions with the output handle. */
14426 for(ii=0;
14427 p->errCode==SQLITE_OK && ii<(int)(sizeof(aFunc)/sizeof(aFunc[0]));
14428 ii++){
14429 p->errCode = sqlite3_create_function(db, aFunc[ii].zName,
14430 aFunc[ii].nArg, SQLITE_UTF8, (void*)p, aFunc[ii].xFunc, 0, 0
14431 );
14432 }
14433
@@ -15086,11 +15820,11 @@
15820 recoverPutU32(&aHdr[56], enc);
15821 recoverPutU16(&aHdr[105], pgsz-nReserve);
15822 if( pgsz==65536 ) pgsz = 1;
15823 recoverPutU16(&aHdr[16], pgsz);
15824 aHdr[20] = nReserve;
15825 for(ii=0; ii<(int)(sizeof(aPreserve)/sizeof(aPreserve[0])); ii++){
15826 memcpy(&aHdr[aPreserve[ii]], &a[aPreserve[ii]], 4);
15827 }
15828 memcpy(aBuf, aHdr, sizeof(aHdr));
15829 memset(&((u8*)aBuf)[sizeof(aHdr)], 0, nByte-sizeof(aHdr));
15830
@@ -15210,14 +15944,20 @@
15944 sqlite3_file *pFd,
15945 sqlite3_int64 iOff,
15946 int iAmt,
15947 void **pp
15948 ){
15949 (void)pFd;
15950 (void)iOff;
15951 (void)iAmt;
15952 *pp = 0;
15953 return SQLITE_OK;
15954 }
15955 static int recoverVfsUnfetch(sqlite3_file *pFd, sqlite3_int64 iOff, void *p){
15956 (void)pFd;
15957 (void)iOff;
15958 (void)p;
15959 return SQLITE_OK;
15960 }
15961
15962 /*
15963 ** Install the VFS wrapper around the file-descriptor open on the input
@@ -15990,11 +16730,11 @@
16730 if( p[i]=='\r' && p[i+1]=='\n' ) i++;
16731 p[j++] = p[i];
16732 }
16733 sz = j;
16734 p[sz] = 0;
16735 }
16736 sqlite3_result_text64(context, (const char*)p, sz,
16737 sqlite3_free, SQLITE_UTF8);
16738 }
16739 p = 0;
16740
@@ -17165,13 +17905,13 @@
17905 }
17906 zCode = sqlite3_mprintf("%.*s", len, zSql);
17907 shell_check_oom(zCode);
17908 for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; }
17909 if( iOffset<25 ){
17910 zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode,iOffset,"");
17911 }else{
17912 zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode,iOffset-14,"");
17913 }
17914 return zMsg;
17915 }
17916
17917
@@ -17355,11 +18095,11 @@
18095 }
18096 }
18097
18098 if( pArg->statsOn==3 ){
18099 if( pArg->pStmt ){
18100 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP,bReset);
18101 raw_printf(pArg->out, "VM-steps: %d\n", iCur);
18102 }
18103 return 0;
18104 }
18105
@@ -17436,12 +18176,14 @@
18176 raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur);
18177 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
18178 raw_printf(pArg->out, "Sort Operations: %d\n", iCur);
18179 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
18180 raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur);
18181 iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT,
18182 bReset);
18183 iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS,
18184 bReset);
18185 if( iHit || iMiss ){
18186 raw_printf(pArg->out, "Bloom filter bypass taken: %d/%d\n",
18187 iHit, iHit+iMiss);
18188 }
18189 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
@@ -17466,24 +18208,24 @@
18208
18209 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
18210 static int scanStatsHeight(sqlite3_stmt *p, int iEntry){
18211 int iPid = 0;
18212 int ret = 1;
18213 sqlite3_stmt_scanstatus_v2(p, iEntry,
18214 SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
18215 );
18216 while( iPid!=0 ){
18217 int ii;
18218 for(ii=0; 1; ii++){
18219 int iId;
18220 int res;
18221 res = sqlite3_stmt_scanstatus_v2(p, ii,
18222 SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iId
18223 );
18224 if( res ) break;
18225 if( iId==iPid ){
18226 sqlite3_stmt_scanstatus_v2(p, ii,
18227 SQLITE_SCANSTAT_PARENTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
18228 );
18229 }
18230 }
18231 ret++;
@@ -17811,11 +18553,11 @@
18553
18554 /* Draw horizontal line N characters long using unicode box
18555 ** characters
18556 */
18557 static void print_box_line(FILE *out, int N){
18558 const char zDash[] =
18559 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24
18560 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24;
18561 const int nDash = sizeof(zDash) - 1;
18562 N *= 3;
18563 while( N>nDash ){
@@ -17940,11 +18682,11 @@
18682 continue;
18683 }
18684 break;
18685 }
18686 zOut[j] = 0;
18687 return (char*)zOut;
18688 }
18689
18690 /* Extract the value of the i-th current column for pStmt as an SQL literal
18691 ** value. Memory is obtained from sqlite3_malloc64() and must be freed by
18692 ** the caller.
@@ -18301,22 +19043,22 @@
19043 ** code. In this case, (*pzErr) may be set to point to a buffer containing
19044 ** an English language error message. It is the responsibility of the
19045 ** caller to eventually free this buffer using sqlite3_free().
19046 */
19047 static int expertHandleSQL(
19048 ShellState *pState,
19049 const char *zSql,
19050 char **pzErr
19051 ){
19052 assert( pState->expert.pExpert );
19053 assert( pzErr==0 || *pzErr==0 );
19054 return sqlite3_expert_sql(pState->expert.pExpert, zSql, pzErr);
19055 }
19056
19057 /*
19058 ** This function is called either to silently clean up the object
19059 ** created by the ".expert" command (if bCancel==1), or to generate a
19060 ** report from it and then clean it up (if bCancel==0).
19061 **
19062 ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
19063 ** code. In this case, (*pzErr) may be set to point to a buffer containing
19064 ** an English language error message. It is the responsibility of the
@@ -18407,11 +19149,12 @@
19149 }
19150
19151 if( rc==SQLITE_OK ){
19152 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
19153 if( pState->expert.pExpert==0 ){
19154 raw_printf(stderr, "sqlite3_expert_new: %s\n",
19155 zErr ? zErr : "out of memory");
19156 rc = SQLITE_ERROR;
19157 }else{
19158 sqlite3_expert_config(
19159 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
19160 );
@@ -19368,11 +20111,11 @@
20111 }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
20112 rc = SHELL_OPEN_ZIPFILE;
20113 }
20114 }
20115 fclose(f);
20116 return rc;
20117 }
20118
20119 #ifndef SQLITE_OMIT_DESERIALIZE
20120 /*
20121 ** Reconstruct an in-memory database using the output from the "dbtotxt"
@@ -19467,12 +20210,12 @@
20210 ** must be a blob. The second a non-negative integer. This function
20211 ** reads and returns a 32-bit big-endian integer from byte
20212 ** offset (4*<arg2>) of the blob.
20213 */
20214 static void shellInt32(
20215 sqlite3_context *context,
20216 int argc,
20217 sqlite3_value **argv
20218 ){
20219 const unsigned char *pBlob;
20220 int nBlob;
20221 int iInt;
@@ -19495,12 +20238,12 @@
20238 /*
20239 ** Scalar function "shell_idquote(X)" returns string X quoted as an identifier,
20240 ** using "..." with internal double-quote characters doubled.
20241 */
20242 static void shellIdQuote(
20243 sqlite3_context *context,
20244 int argc,
20245 sqlite3_value **argv
20246 ){
20247 const char *zName = (const char*)sqlite3_value_text(argv[0]);
20248 UNUSED_PARAMETER(argc);
20249 if( zName ){
@@ -19511,12 +20254,12 @@
20254
20255 /*
20256 ** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
20257 */
20258 static void shellUSleepFunc(
20259 sqlite3_context *context,
20260 int argcUnused,
20261 sqlite3_value **argv
20262 ){
20263 int sleep = sqlite3_value_int(argv[0]);
20264 (void)argcUnused;
20265 sqlite3_sleep(sleep/1000);
@@ -19524,11 +20267,11 @@
20267 }
20268
20269 /*
20270 ** Scalar function "shell_escape_crnl" used by the .recover command.
20271 ** The argument passed to this function is the output of built-in
20272 ** function quote(). If the first character of the input is "'",
20273 ** indicating that the value passed to quote() was a text value,
20274 ** then this function searches the input for "\n" and "\r" characters
20275 ** and adds a wrapper similar to the following:
20276 **
20277 ** replace(replace(<input>, '\n', char(10), '\r', char(13));
@@ -19535,12 +20278,12 @@
20278 **
20279 ** Or, if the first character of the input is not "'", then a copy
20280 ** of the input is returned.
20281 */
20282 static void shellEscapeCrnl(
20283 sqlite3_context *context,
20284 int argc,
20285 sqlite3_value **argv
20286 ){
20287 const char *zText = (const char*)sqlite3_value_text(argv[0]);
20288 UNUSED_PARAMETER(argc);
20289 if( zText && zText[0]=='\'' ){
@@ -19636,17 +20379,17 @@
20379 const char *zDbFilename = p->pAuxDb->zDbFilename;
20380 if( p->openMode==SHELL_OPEN_UNSPEC ){
20381 if( zDbFilename==0 || zDbFilename[0]==0 ){
20382 p->openMode = SHELL_OPEN_NORMAL;
20383 }else{
20384 p->openMode = (u8)deduceDatabaseType(zDbFilename,
20385 (openFlags & OPEN_DB_ZIPFILE)!=0);
20386 }
20387 }
20388 switch( p->openMode ){
20389 case SHELL_OPEN_APPENDVFS: {
20390 sqlite3_open_v2(zDbFilename, &p->db,
20391 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
20392 break;
20393 }
20394 case SHELL_OPEN_HEXDB:
20395 case SHELL_OPEN_DESERIALIZE: {
@@ -19684,10 +20427,12 @@
20427 sqlite3_enable_load_extension(p->db, 1);
20428 #endif
20429 sqlite3_shathree_init(p->db, 0, 0);
20430 sqlite3_uint_init(p->db, 0, 0);
20431 sqlite3_decimal_init(p->db, 0, 0);
20432 sqlite3_base64_init(p->db, 0, 0);
20433 sqlite3_base85_init(p->db, 0, 0);
20434 sqlite3_regexp_init(p->db, 0, 0);
20435 sqlite3_ieee_init(p->db, 0, 0);
20436 sqlite3_series_init(p->db, 0, 0);
20437 #ifndef SQLITE_SHELL_FIDDLE
20438 sqlite3_fileio_init(p->db, 0, 0);
@@ -19795,11 +20540,11 @@
20540 void close_db(sqlite3 *db){
20541 int rc = sqlite3_close(db);
20542 if( rc ){
20543 utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
20544 rc, sqlite3_errmsg(db));
20545 }
20546 }
20547
20548 #if HAVE_READLINE || HAVE_EDITLINE
20549 /*
20550 ** Readline completion callbacks
@@ -19825,10 +20570,12 @@
20570 zRet = 0;
20571 }
20572 return zRet;
20573 }
20574 static char **readline_completion(const char *zText, int iStart, int iEnd){
20575 (void)iStart;
20576 (void)iEnd;
20577 rl_attempted_completion_over = 1;
20578 return rl_completion_matches(zText, readline_completion_generator);
20579 }
20580
20581 #elif HAVE_LINENOISE
@@ -21036,20 +21783,20 @@
21783 return SQLITE_ERROR;
21784 }
21785
21786 #if !defined SQLITE_OMIT_VIRTUALTABLE
21787 static void shellPrepare(
21788 sqlite3 *db,
21789 int *pRc,
21790 const char *zSql,
21791 sqlite3_stmt **ppStmt
21792 ){
21793 *ppStmt = 0;
21794 if( *pRc==SQLITE_OK ){
21795 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
21796 if( rc!=SQLITE_OK ){
21797 raw_printf(stderr, "sql error: %s (%d)\n",
21798 sqlite3_errmsg(db), sqlite3_errcode(db)
21799 );
21800 *pRc = rc;
21801 }
21802 }
@@ -21061,14 +21808,14 @@
21808 ** This routine is could be marked "static". But it is not always used,
21809 ** depending on compile-time options. By omitting the "static", we avoid
21810 ** nuisance compiler warnings about "defined but not used".
21811 */
21812 void shellPreparePrintf(
21813 sqlite3 *db,
21814 int *pRc,
21815 sqlite3_stmt **ppStmt,
21816 const char *zFmt,
21817 ...
21818 ){
21819 *ppStmt = 0;
21820 if( *pRc==SQLITE_OK ){
21821 va_list ap;
@@ -21090,11 +21837,11 @@
21837 ** This routine is could be marked "static". But it is not always used,
21838 ** depending on compile-time options. By omitting the "static", we avoid
21839 ** nuisance compiler warnings about "defined but not used".
21840 */
21841 void shellFinalize(
21842 int *pRc,
21843 sqlite3_stmt *pStmt
21844 ){
21845 if( pStmt ){
21846 sqlite3 *db = sqlite3_db_handle(pStmt);
21847 int rc = sqlite3_finalize(pStmt);
@@ -21112,11 +21859,11 @@
21859 ** This routine is could be marked "static". But it is not always used,
21860 ** depending on compile-time options. By omitting the "static", we avoid
21861 ** nuisance compiler warnings about "defined but not used".
21862 */
21863 void shellReset(
21864 int *pRc,
21865 sqlite3_stmt *pStmt
21866 ){
21867 int rc = sqlite3_reset(pStmt);
21868 if( *pRc==SQLITE_OK ){
21869 if( rc!=SQLITE_OK ){
@@ -21160,11 +21907,11 @@
21907 showHelp(f,"archive");
21908 return SQLITE_ERROR;
21909 }
21910
21911 /*
21912 ** Print an error message for the .ar command to stderr and return
21913 ** SQLITE_ERROR.
21914 */
21915 static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
21916 va_list ap;
21917 char *z;
@@ -21241,11 +21988,11 @@
21988 }
21989
21990 /*
21991 ** Parse the command line for an ".ar" command. The results are written into
21992 ** structure (*pAr). SQLITE_OK is returned if the command line is parsed
21993 ** successfully, otherwise an error message is written to stderr and
21994 ** SQLITE_ERROR returned.
21995 */
21996 static int arParseCommand(
21997 char **azArg, /* Array of arguments passed to dot command */
21998 int nArg, /* Number of entries in azArg[] */
@@ -21437,11 +22184,11 @@
22184 ** The caller is responsible for eventually calling sqlite3_free() on
22185 ** any non-NULL (*pzWhere) value. Here, "match" means strict equality
22186 ** when pAr->bGlob is false and GLOB match when pAr->bGlob is true.
22187 */
22188 static void arWhereClause(
22189 int *pRc,
22190 ArCommand *pAr,
22191 char **pzWhere /* OUT: New WHERE clause */
22192 ){
22193 char *zWhere = 0;
22194 const char *zSameOp = (pAr->bGlob)? "GLOB" : "=";
@@ -21452,11 +22199,11 @@
22199 int i;
22200 const char *zSep = "";
22201 for(i=0; i<pAr->nArg; i++){
22202 const char *z = pAr->azArg[i];
22203 zWhere = sqlite3_mprintf(
22204 "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
22205 zWhere, zSep, zSameOp, z, strlen30(z)+1, zSameOp, z
22206 );
22207 if( zWhere==0 ){
22208 *pRc = SQLITE_NOMEM;
22209 break;
@@ -21467,14 +22214,14 @@
22214 }
22215 *pzWhere = zWhere;
22216 }
22217
22218 /*
22219 ** Implementation of .ar "lisT" command.
22220 */
22221 static int arListCommand(ArCommand *pAr){
22222 const char *zSql = "SELECT %s FROM %s WHERE %s";
22223 const char *azCols[] = {
22224 "name",
22225 "lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
22226 };
22227
@@ -21492,11 +22239,11 @@
22239 }else{
22240 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
22241 if( pAr->bVerbose ){
22242 utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
22243 sqlite3_column_text(pSql, 0),
22244 sqlite3_column_int(pSql, 1),
22245 sqlite3_column_text(pSql, 2),
22246 sqlite3_column_text(pSql, 3)
22247 );
22248 }else{
22249 utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
@@ -21549,21 +22296,21 @@
22296 sqlite3_free(zSql);
22297 return rc;
22298 }
22299
22300 /*
22301 ** Implementation of .ar "eXtract" command.
22302 */
22303 static int arExtractCommand(ArCommand *pAr){
22304 const char *zSql1 =
22305 "SELECT "
22306 " ($dir || name),"
22307 " writefile(($dir || name), %s, mode, mtime) "
22308 "FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)"
22309 " AND name NOT GLOB '*..[/\\]*'";
22310
22311 const char *azExtraArg[] = {
22312 "sqlar_uncompress(data, sz)",
22313 "data"
22314 };
22315
22316 sqlite3_stmt *pSql = 0;
@@ -21585,11 +22332,11 @@
22332 zDir = sqlite3_mprintf("");
22333 }
22334 if( zDir==0 ) rc = SQLITE_NOMEM;
22335 }
22336
22337 shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
22338 azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
22339 );
22340
22341 if( rc==SQLITE_OK ){
22342 j = sqlite3_bind_parameter_index(pSql, "$dir");
@@ -21663,11 +22410,11 @@
22410 static int arCreateOrUpdateCommand(
22411 ArCommand *pAr, /* Command arguments and options */
22412 int bUpdate, /* true for a --create. */
22413 int bOnlyIfChanged /* Only update if file has changed */
22414 ){
22415 const char *zCreate =
22416 "CREATE TABLE IF NOT EXISTS sqlar(\n"
22417 " name TEXT PRIMARY KEY, -- name of the file\n"
22418 " mode INT, -- access permissions\n"
22419 " mtime INT, -- last modification time\n"
22420 " sz INT, -- original file size\n"
@@ -21705,11 +22452,11 @@
22452 char *zExists = 0;
22453
22454 arExecSql(pAr, "PRAGMA page_size=512");
22455 rc = arExecSql(pAr, "SAVEPOINT ar;");
22456 if( rc!=SQLITE_OK ) return rc;
22457 zTemp[0] = 0;
22458 if( pAr->bZip ){
22459 /* Initialize the zipfile virtual table, if necessary */
22460 if( pAr->zFile ){
22461 sqlite3_uint64 r;
22462 sqlite3_randomness(sizeof(r),&r);
@@ -21799,11 +22546,11 @@
22546 }
22547 cmd.bZip = 1;
22548 }else if( cmd.zFile ){
22549 int flags;
22550 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
22551 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
22552 || cmd.eCmd==AR_CMD_REMOVE || cmd.eCmd==AR_CMD_UPDATE ){
22553 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
22554 }else{
22555 flags = SQLITE_OPEN_READONLY;
22556 }
@@ -21810,14 +22557,14 @@
22557 cmd.db = 0;
22558 if( cmd.bDryRun ){
22559 utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
22560 eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
22561 }
22562 rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
22563 eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
22564 if( rc!=SQLITE_OK ){
22565 utf8_printf(stderr, "cannot open file: %s (%s)\n",
22566 cmd.zFile, sqlite3_errmsg(cmd.db)
22567 );
22568 goto end_ar_command;
22569 }
22570 sqlite3_fileio_init(cmd.db, 0, 0);
@@ -21929,11 +22676,11 @@
22676 }else
22677 if( n<=10 && memcmp("-no-rowids", z, n)==0 ){
22678 bRowids = 0;
22679 }
22680 else{
22681 utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
22682 showHelp(pState->out, azArg[0]);
22683 return 1;
22684 }
22685 }
22686
@@ -22292,11 +23039,11 @@
23039 if( zDestFile==0 ){
23040 raw_printf(stderr, "missing FILENAME argument on .backup\n");
23041 return 1;
23042 }
23043 if( zDb==0 ) zDb = "main";
23044 rc = sqlite3_open_v2(zDestFile, &pDest,
23045 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
23046 if( rc!=SQLITE_OK ){
23047 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
23048 close_db(pDest);
23049 return 1;
@@ -22542,11 +23289,11 @@
23289 if( nArg>1 ) break;
23290 }
23291 if( nArg>1 && ii==ArraySize(aDbConfig) ){
23292 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
23293 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
23294 }
23295 }else
23296
23297 #if SQLITE_SHELL_HAVE_RECOVER
23298 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){
23299 rc = shell_dbinfo_command(p, nArg, azArg);
@@ -22609,11 +23356,11 @@
23356 " name LIKE %Q ESCAPE '\\' AND"
23357 " sql LIKE 'CREATE VIRTUAL TABLE%%' AND"
23358 " substr(o.name, 1, length(name)+1) == (name||'_')"
23359 ")", azArg[i], azArg[i]
23360 );
23361
23362 if( zLike ){
23363 zLike = sqlite3_mprintf("%z OR %z", zLike, zExpr);
23364 }else{
23365 zLike = zExpr;
23366 }
@@ -22742,11 +23489,11 @@
23489 }else
23490
23491 #ifndef SQLITE_OMIT_VIRTUALTABLE
23492 if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
23493 if( p->bSafeMode ){
23494 raw_printf(stderr,
23495 "Cannot run experimental commands such as \"%s\" in safe mode\n",
23496 azArg[0]);
23497 rc = 1;
23498 }else{
23499 open_db(p, 0);
@@ -22761,11 +23508,11 @@
23508 int ctrlCode; /* Integer code for that option */
23509 const char *zUsage; /* Usage notes */
23510 } aCtrl[] = {
23511 { "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
23512 { "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
23513 { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
23514 { "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
23515 { "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
23516 /* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
23517 { "psow", SQLITE_FCNTL_POWERSAFE_OVERWRITE, "[BOOLEAN]" },
23518 { "reserve_bytes", SQLITE_FCNTL_RESERVE_BYTES, "[N]" },
@@ -22782,11 +23529,11 @@
23529 const char *zSchema = 0;
23530
23531 open_db(p, 0);
23532 zCmd = nArg>=2 ? azArg[1] : "help";
23533
23534 if( zCmd[0]=='-'
23535 && (cli_strcmp(zCmd,"--schema")==0 || cli_strcmp(zCmd,"-schema")==0)
23536 && nArg>=4
23537 ){
23538 zSchema = azArg[2];
23539 for(i=3; i<nArg; i++) azArg[i-2] = azArg[i];
@@ -24160,11 +24907,12 @@
24907 rc = 1;
24908 goto meta_command_exit;
24909 }else if( zName==0 ){
24910 zName = azArg[ii];
24911 }else{
24912 raw_printf(stderr,
24913 "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
24914 rc = 1;
24915 goto meta_command_exit;
24916 }
24917 }
24918 if( zName!=0 ){
@@ -24276,11 +25024,11 @@
25024 }else
25025
25026 if( (c=='s' && n==11 && cli_strncmp(azArg[0], "selecttrace", n)==0)
25027 || (c=='t' && n==9 && cli_strncmp(azArg[0], "treetrace", n)==0)
25028 ){
25029 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
25030 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
25031 }else
25032
25033 #if defined(SQLITE_ENABLE_SESSION)
25034 if( c=='s' && cli_strncmp(azArg[0],"session",n)==0 && n>=3 ){
@@ -24461,11 +25209,12 @@
25209 utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
25210 goto meta_command_exit;
25211 }
25212 }
25213 if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
25214 raw_printf(stderr,
25215 "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
25216 goto meta_command_exit;
25217 }
25218 pSession = &pAuxDb->aSession[pAuxDb->nSession];
25219 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
25220 if( rc ){
@@ -24745,30 +25494,30 @@
25494 }
25495 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE)
25496 {
25497 int lrc;
25498 char *zRevText = /* Query for reversible to-blob-to-text check */
25499 "SELECT lower(name) as tname FROM sqlite_schema\n"
25500 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
25501 "AND name NOT LIKE 'sqlite_%%'%s\n"
25502 "ORDER BY 1 collate nocase";
25503 zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
25504 zRevText = sqlite3_mprintf(
25505 /* lower-case query is first run, producing upper-case query. */
25506 "with tabcols as materialized(\n"
25507 "select tname, cname\n"
25508 "from ("
25509 " select ss.tname as tname, ti.name as cname\n"
25510 " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
25511 "select 'SELECT total(bad_text_count) AS bad_text_count\n"
25512 "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
25513 " from (select 'SELECT COUNT(*) AS bad_text_count\n"
25514 "FROM '||tname||' WHERE '\n"
25515 "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
25516 "|| ' AND typeof('||cname||')=''text'' ',\n"
25517 "' OR ') as query, tname from tabcols group by tname)"
25518 , zRevText);
25519 shell_check_oom(zRevText);
25520 if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
25521 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
25522 assert(lrc==SQLITE_OK);
25523 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
@@ -24777,20 +25526,20 @@
25526 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
25527 sqlite3_stmt *pCheckStmt;
25528 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
25529 if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
25530 if( SQLITE_OK==lrc ){
25531 if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
25532 double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
25533 if( countIrreversible>0 ){
25534 int sz = (int)(countIrreversible + 0.5);
25535 utf8_printf(stderr,
25536 "Digest includes %d invalidly encoded text field%s.\n",
25537 sz, (sz>1)? "s": "");
25538 }
25539 }
25540 sqlite3_finalize(pCheckStmt);
25541 }
25542 sqlite3_finalize(pStmt);
25543 }
25544 sqlite3_free(zRevText);
25545 }
@@ -25022,32 +25771,32 @@
25771 const char *zCtrlName; /* Name of a test-control option */
25772 int ctrlCode; /* Integer code for that option */
25773 int unSafe; /* Not valid for --safe mode */
25774 const char *zUsage; /* Usage notes */
25775 } aCtrl[] = {
25776 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
25777 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
25778 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
25779 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
25780 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
25781 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
25782 /*{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/
25783 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
25784 {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
25785 {"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
25786 {"never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT,1, "BOOLEAN" },
25787 {"optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK" },
25788 #ifdef YYCOVERAGE
25789 {"parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE,0,"" },
25790 #endif
25791 {"pending_byte", SQLITE_TESTCTRL_PENDING_BYTE,0, "OFFSET " },
25792 {"prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" },
25793 {"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" },
25794 {"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" },
25795 {"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
25796 {"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
25797 {"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
25798 };
25799 int testctrl = -1;
25800 int iCtrl = -1;
25801 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
25802 int isOk = 0;
@@ -25468,11 +26217,11 @@
26217 }
26218 }
26219 }else
26220
26221 if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){
26222 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
26223 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 3, &x);
26224 }else
26225
26226 if( c=='w' && cli_strncmp(azArg[0], "width", n)==0 ){
26227 int j;
@@ -25521,11 +26270,11 @@
26270 ** Scan line for classification to guide shell's handling.
26271 ** The scan is resumable for subsequent lines when prior
26272 ** return values are passed as the 2nd argument.
26273 */
26274 static QuickScanState quickscan(char *zLine, QuickScanState qss,
26275 SCAN_TRACKER_REFTYPE pst){
26276 char cin;
26277 char cWait = (char)qss; /* intentional narrowing loss */
26278 if( cWait==0 ){
26279 PlainScan:
26280 assert( cWait==0 );
@@ -25545,11 +26294,11 @@
26294 continue;
26295 case '/':
26296 if( *zLine=='*' ){
26297 ++zLine;
26298 cWait = '*';
26299 CONTINUE_PROMPT_AWAITS(pst, "/*");
26300 qss = QSS_SETV(qss, cWait);
26301 goto TermScan;
26302 }
26303 break;
26304 case '[':
@@ -25556,18 +26305,18 @@
26305 cin = ']';
26306 /* fall thru */
26307 case '`': case '\'': case '"':
26308 cWait = cin;
26309 qss = QSS_HasDark | cWait;
26310 CONTINUE_PROMPT_AWAITC(pst, cin);
26311 goto TermScan;
26312 case '(':
26313 CONTINUE_PAREN_INCR(pst, 1);
26314 break;
26315 case ')':
26316 CONTINUE_PAREN_INCR(pst, -1);
26317 break;
26318 default:
26319 break;
26320 }
26321 qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
26322 }
@@ -25579,23 +26328,23 @@
26328 case '*':
26329 if( *zLine != '/' )
26330 continue;
26331 ++zLine;
26332 cWait = 0;
26333 CONTINUE_PROMPT_AWAITC(pst, 0);
26334 qss = QSS_SETV(qss, 0);
26335 goto PlainScan;
26336 case '`': case '\'': case '"':
26337 if(*zLine==cWait){
26338 /* Swallow doubled end-delimiter.*/
26339 ++zLine;
26340 continue;
26341 }
26342 /* fall thru */
26343 case ']':
26344 cWait = 0;
26345 CONTINUE_PROMPT_AWAITC(pst, 0);
26346 qss = QSS_SETV(qss, 0);
26347 goto PlainScan;
26348 default: assert(0);
26349 }
26350 }
@@ -25696,13 +26445,13 @@
26445 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
26446 }
26447
26448 #ifdef SQLITE_SHELL_FIDDLE
26449 /*
26450 ** Alternate one_input_line() impl for wasm mode. This is not in the primary
26451 ** impl because we need the global shellState and cannot access it from that
26452 ** function without moving lots of code around (creating a larger/messier diff).
26453 */
26454 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
26455 /* Parse the next line from shellState.wasm.zInput. */
26456 const char *zBegin = shellState.wasm.zPos;
26457 const char *z = zBegin;
@@ -26517,16 +27266,16 @@
27266 data.openMode = SHELL_OPEN_READONLY;
27267 }else if( cli_strcmp(z,"-nofollow")==0 ){
27268 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
27269 }else if( cli_strcmp(z,"-ascii")==0 ){
27270 data.mode = MODE_Ascii;
27271 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Unit);
27272 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Record);
27273 }else if( cli_strcmp(z,"-tabs")==0 ){
27274 data.mode = MODE_List;
27275 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Tab);
27276 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Row);
27277 }else if( cli_strcmp(z,"-separator")==0 ){
27278 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
27279 "%s",cmdline_option_value(argc,argv,++i));
27280 }else if( cli_strcmp(z,"-newline")==0 ){
27281 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
27282
+273 -147
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.41.0"
456456
#define SQLITE_VERSION_NUMBER 3041000
457
-#define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
457
+#define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -3602,12 +3602,12 @@
36023602
**
36033603
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
36043604
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
36053605
** information as is provided by the [sqlite3_profile()] callback.
36063606
** ^The P argument is a pointer to the [prepared statement] and the
3607
-** X argument points to a 64-bit integer which is the estimated of
3608
-** the number of nanosecond that the prepared statement took to run.
3607
+** X argument points to a 64-bit integer which is approximately
3608
+** the number of nanoseconds that the prepared statement took to run.
36093609
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
36103610
**
36113611
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
36123612
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
36133613
** statement generates a single row of result.
@@ -14511,13 +14511,13 @@
1451114511
** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
1451214512
** underlying malloc() implementation might return us 4-byte aligned
1451314513
** pointers. In that case, only verify 4-byte alignment.
1451414514
*/
1451514515
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
14516
-# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
14516
+# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
1451714517
#else
14518
-# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0)
14518
+# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
1451914519
#endif
1452014520
1452114521
/*
1452214522
** Disable MMAP on platforms where it is known to not work
1452314523
*/
@@ -17683,10 +17683,11 @@
1768317683
#define SQLITE_AFF_BLOB 0x41 /* 'A' */
1768417684
#define SQLITE_AFF_TEXT 0x42 /* 'B' */
1768517685
#define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
1768617686
#define SQLITE_AFF_INTEGER 0x44 /* 'D' */
1768717687
#define SQLITE_AFF_REAL 0x45 /* 'E' */
17688
+#define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
1768817689
1768917690
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
1769017691
1769117692
/*
1769217693
** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -18238,10 +18239,13 @@
1823818239
int iDistinct; /* Ephemeral table used to enforce DISTINCT */
1823918240
int iDistAddr; /* Address of OP_OpenEphemeral */
1824018241
} *aFunc;
1824118242
int nFunc; /* Number of entries in aFunc[] */
1824218243
u32 selId; /* Select to which this AggInfo belongs */
18244
+#ifdef SQLITE_DEBUG
18245
+ Select *pSelect; /* SELECT statement that this AggInfo supports */
18246
+#endif
1824318247
};
1824418248
1824518249
/*
1824618250
** Macros to compute aCol[] and aFunc[] register numbers.
1824718251
**
@@ -19078,14 +19082,14 @@
1907819082
# define DbMaskAllZero(M) sqlite3DbMaskAllZero(M)
1907919083
# define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
1908019084
#else
1908119085
typedef unsigned int yDbMask;
1908219086
# define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
19083
-# define DbMaskZero(M) (M)=0
19084
-# define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I))
19085
-# define DbMaskAllZero(M) (M)==0
19086
-# define DbMaskNonZero(M) (M)!=0
19087
+# define DbMaskZero(M) ((M)=0)
19088
+# define DbMaskSet(M,I) ((M)|=(((yDbMask)1)<<(I)))
19089
+# define DbMaskAllZero(M) ((M)==0)
19090
+# define DbMaskNonZero(M) ((M)!=0)
1908719091
#endif
1908819092
1908919093
/*
1909019094
** For each index X that has as one of its arguments either an expression
1909119095
** or the name of a virtual generated column, and if X is in scope such that
@@ -20654,11 +20658,11 @@
2065420658
SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
2065520659
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
2065620660
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
2065720661
2065820662
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
20659
-SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, int);
20663
+SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64);
2066020664
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
2066120665
SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
2066220666
SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
2066320667
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
2066420668
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -22786,11 +22790,11 @@
2278622790
2278722791
Op *aOp; /* Space to hold the virtual machine's program */
2278822792
int nOp; /* Number of instructions in the program */
2278922793
int nOpAlloc; /* Slots allocated for aOp[] */
2279022794
Mem *aColName; /* Column names to return */
22791
- Mem *pResultSet; /* Pointer to an array of results */
22795
+ Mem *pResultRow; /* Current output row */
2279222796
char *zErrMsg; /* Error message written here */
2279322797
VList *pVList; /* Name of variables */
2279422798
#ifndef SQLITE_OMIT_TRACE
2279522799
i64 startTime; /* Time when query started - used for profiling */
2279622800
#endif
@@ -27328,13 +27332,17 @@
2732827332
int iFullSz;
2732927333
if( n<=mem5.szAtom*2 ){
2733027334
if( n<=mem5.szAtom ) return mem5.szAtom;
2733127335
return mem5.szAtom*2;
2733227336
}
27333
- if( n>0x40000000 ) return 0;
27337
+ if( n>0x10000000 ){
27338
+ if( n>0x40000000 ) return 0;
27339
+ if( n>0x20000000 ) return 0x40000000;
27340
+ return 0x20000000;
27341
+ }
2733427342
for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27335
- if( (iFullSz/2)>=n ) return iFullSz/2;
27343
+ if( (iFullSz/2)>=(i64)n ) return iFullSz/2;
2733627344
return iFullSz;
2733727345
}
2733827346
2733927347
/*
2734027348
** Return the ceiling of the logarithm base 2 of iValue.
@@ -30600,17 +30608,30 @@
3060030608
buf[3] = 0x80 + (u8)(ch & 0x3f);
3060130609
length = 4;
3060230610
}
3060330611
}
3060430612
if( precision>1 ){
30613
+ i64 nPrior = 1;
3060530614
width -= precision-1;
3060630615
if( width>1 && !flag_leftjustify ){
3060730616
sqlite3_str_appendchar(pAccum, width-1, ' ');
3060830617
width = 0;
3060930618
}
30610
- while( precision-- > 1 ){
30611
- sqlite3_str_append(pAccum, buf, length);
30619
+ sqlite3_str_append(pAccum, buf, length);
30620
+ precision--;
30621
+ while( precision > 1 ){
30622
+ i64 nCopyBytes;
30623
+ if( nPrior > precision-1 ) nPrior = precision - 1;
30624
+ nCopyBytes = length*nPrior;
30625
+ if( nCopyBytes + pAccum->nChar >= pAccum->nAlloc ){
30626
+ sqlite3StrAccumEnlarge(pAccum, nCopyBytes);
30627
+ }
30628
+ if( pAccum->accError ) break;
30629
+ sqlite3_str_append(pAccum,
30630
+ &pAccum->zText[pAccum->nChar-nCopyBytes], nCopyBytes);
30631
+ precision -= nPrior;
30632
+ nPrior *= 2;
3061230633
}
3061330634
}
3061430635
bufpt = buf;
3061530636
flag_altform2 = 1;
3061630637
goto adjust_width_for_utf8;
@@ -30834,13 +30855,13 @@
3083430855
** able to accept at least N more bytes of text.
3083530856
**
3083630857
** Return the number of bytes of text that StrAccum is able to accept
3083730858
** after the attempted enlargement. The value returned might be zero.
3083830859
*/
30839
-SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, int N){
30860
+SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, i64 N){
3084030861
char *zNew;
30841
- assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
30862
+ assert( p->nChar+N >= p->nAlloc ); /* Only called if really needed */
3084230863
if( p->accError ){
3084330864
testcase(p->accError==SQLITE_TOOBIG);
3084430865
testcase(p->accError==SQLITE_NOMEM);
3084530866
return 0;
3084630867
}
@@ -30847,12 +30868,11 @@
3084730868
if( p->mxAlloc==0 ){
3084830869
sqlite3StrAccumSetError(p, SQLITE_TOOBIG);
3084930870
return p->nAlloc - p->nChar - 1;
3085030871
}else{
3085130872
char *zOld = isMalloced(p) ? p->zText : 0;
30852
- i64 szNew = p->nChar;
30853
- szNew += (sqlite3_int64)N + 1;
30873
+ i64 szNew = p->nChar + N + 1;
3085430874
if( szNew+p->nChar<=p->mxAlloc ){
3085530875
/* Force exponential buffer size growth as long as it does not overflow,
3085630876
** to avoid having to call this routine too often */
3085730877
szNew += p->nChar;
3085830878
}
@@ -30878,11 +30898,12 @@
3087830898
sqlite3_str_reset(p);
3087930899
sqlite3StrAccumSetError(p, SQLITE_NOMEM);
3088030900
return 0;
3088130901
}
3088230902
}
30883
- return N;
30903
+ assert( N>=0 && N<=0x7fffffff );
30904
+ return (int)N;
3088430905
}
3088530906
3088630907
/*
3088730908
** Append N copies of character c to the given string buffer.
3088830909
*/
@@ -51226,10 +51247,11 @@
5122651247
static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
5122751248
static int memdbTruncate(sqlite3_file*, sqlite3_int64 size);
5122851249
static int memdbSync(sqlite3_file*, int flags);
5122951250
static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize);
5123051251
static int memdbLock(sqlite3_file*, int);
51252
+static int memdbUnlock(sqlite3_file*, int);
5123151253
/* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */
5123251254
static int memdbFileControl(sqlite3_file*, int op, void *pArg);
5123351255
/* static int memdbSectorSize(sqlite3_file*); // not used */
5123451256
static int memdbDeviceCharacteristics(sqlite3_file*);
5123551257
static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
@@ -51284,11 +51306,11 @@
5128451306
memdbWrite, /* xWrite */
5128551307
memdbTruncate, /* xTruncate */
5128651308
memdbSync, /* xSync */
5128751309
memdbFileSize, /* xFileSize */
5128851310
memdbLock, /* xLock */
51289
- memdbLock, /* xUnlock - same as xLock in this case */
51311
+ memdbUnlock, /* xUnlock */
5129051312
0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
5129151313
memdbFileControl, /* xFileControl */
5129251314
0, /* memdbSectorSize,*/ /* xSectorSize */
5129351315
memdbDeviceCharacteristics, /* xDeviceCharacteristics */
5129451316
0, /* xShmMap */
@@ -51485,69 +51507,86 @@
5148551507
*/
5148651508
static int memdbLock(sqlite3_file *pFile, int eLock){
5148751509
MemFile *pThis = (MemFile*)pFile;
5148851510
MemStore *p = pThis->pStore;
5148951511
int rc = SQLITE_OK;
51490
- if( eLock==pThis->eLock ) return SQLITE_OK;
51512
+ if( eLock<=pThis->eLock ) return SQLITE_OK;
5149151513
memdbEnter(p);
51492
- assert( p->nWrLock==0 || p->nWrLock==1 ); /* No more than 1 write lock */
51493
- if( eLock>SQLITE_LOCK_SHARED ){
51494
- assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51495
- if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
51496
- rc = SQLITE_READONLY;
51497
- }else if( eLock==SQLITE_LOCK_EXCLUSIVE ){
51498
- /* We never go for an EXCLUSIVE lock unless we already hold SHARED or
51499
- ** higher */
51500
- assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51501
- testcase( pThis->eLock==SQLITE_LOCK_SHARED );
51502
-
51503
- /* Because we are holding SHARED or more, there must be at least
51504
- ** one read lock */
51505
- assert( p->nRdLock>0 );
51506
-
51507
- /* The only way that there can be an existing write lock is if we
51508
- ** currently hold it. Otherwise, we would have never been able to
51509
- ** promote from NONE to SHARED. */
51510
- assert( p->nWrLock==0 || pThis->eLock>SQLITE_LOCK_SHARED );
51511
-
51512
- if( p->nRdLock>1 ){
51513
- /* Cannot take EXCLUSIVE if somebody else is holding SHARED */
51514
- rc = SQLITE_BUSY;
51515
- }else{
51516
- p->nWrLock = 1;
51517
- }
51518
- }else if( ALWAYS(pThis->eLock<=SQLITE_LOCK_SHARED) ){
51519
- /* Upgrading to RESERVED or PENDING from SHARED. Fail if any other
51520
- ** client has a write-lock of any kind. */
51521
- if( p->nWrLock ){
51522
- rc = SQLITE_BUSY;
51523
- }else{
51524
- p->nWrLock = 1;
51525
- }
51526
- }
51527
- }else if( eLock==SQLITE_LOCK_SHARED ){
51528
- if( pThis->eLock > SQLITE_LOCK_SHARED ){
51529
- assert( p->nWrLock==1 );
51530
- p->nWrLock = 0;
51531
- }else if( p->nWrLock ){
51532
- rc = SQLITE_BUSY;
51533
- }else{
51534
- p->nRdLock++;
51535
- }
51536
- }else{
51537
- assert( eLock==SQLITE_LOCK_NONE );
51538
- if( pThis->eLock>SQLITE_LOCK_SHARED ){
51539
- assert( p->nWrLock==1 );
51540
- p->nWrLock = 0;
51541
- }
51542
- assert( p->nRdLock>0 );
51543
- p->nRdLock--;
51514
+
51515
+ assert( p->nWrLock==0 || p->nWrLock==1 );
51516
+ assert( pThis->eLock<=SQLITE_LOCK_SHARED || p->nWrLock==1 );
51517
+ assert( pThis->eLock==SQLITE_LOCK_NONE || p->nRdLock>=1 );
51518
+
51519
+ if( eLock>SQLITE_LOCK_SHARED && (p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
51520
+ rc = SQLITE_READONLY;
51521
+ }else{
51522
+ switch( eLock ){
51523
+ case SQLITE_LOCK_SHARED: {
51524
+ assert( pThis->eLock==SQLITE_LOCK_NONE );
51525
+ if( p->nWrLock>0 ){
51526
+ rc = SQLITE_BUSY;
51527
+ }else{
51528
+ p->nRdLock++;
51529
+ }
51530
+ break;
51531
+ };
51532
+
51533
+ case SQLITE_LOCK_RESERVED:
51534
+ case SQLITE_LOCK_PENDING: {
51535
+ assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51536
+ if( ALWAYS(pThis->eLock==SQLITE_LOCK_SHARED) ){
51537
+ if( p->nWrLock>0 ){
51538
+ rc = SQLITE_BUSY;
51539
+ }else{
51540
+ p->nWrLock = 1;
51541
+ }
51542
+ }
51543
+ break;
51544
+ }
51545
+
51546
+ default: {
51547
+ assert( eLock==SQLITE_LOCK_EXCLUSIVE );
51548
+ assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51549
+ if( p->nRdLock>1 ){
51550
+ rc = SQLITE_BUSY;
51551
+ }else if( pThis->eLock==SQLITE_LOCK_SHARED ){
51552
+ p->nWrLock = 1;
51553
+ }
51554
+ break;
51555
+ }
51556
+ }
5154451557
}
5154551558
if( rc==SQLITE_OK ) pThis->eLock = eLock;
5154651559
memdbLeave(p);
5154751560
return rc;
5154851561
}
51562
+
51563
+/*
51564
+** Unlock an memdb-file.
51565
+*/
51566
+static int memdbUnlock(sqlite3_file *pFile, int eLock){
51567
+ MemFile *pThis = (MemFile*)pFile;
51568
+ MemStore *p = pThis->pStore;
51569
+ if( eLock>=pThis->eLock ) return SQLITE_OK;
51570
+ memdbEnter(p);
51571
+
51572
+ assert( eLock==SQLITE_LOCK_SHARED || eLock==SQLITE_LOCK_NONE );
51573
+ if( eLock==SQLITE_LOCK_SHARED ){
51574
+ if( ALWAYS(pThis->eLock>SQLITE_LOCK_SHARED) ){
51575
+ p->nWrLock--;
51576
+ }
51577
+ }else{
51578
+ if( pThis->eLock>SQLITE_LOCK_SHARED ){
51579
+ p->nWrLock--;
51580
+ }
51581
+ p->nRdLock--;
51582
+ }
51583
+
51584
+ pThis->eLock = eLock;
51585
+ memdbLeave(p);
51586
+ return SQLITE_OK;
51587
+}
5154951588
5155051589
#if 0
5155151590
/*
5155251591
** This interface is only used for crash recovery, which does not
5155351592
** occur on an in-memory database.
@@ -51652,11 +51691,11 @@
5165251691
int szName;
5165351692
UNUSED_PARAMETER(pVfs);
5165451693
5165551694
memset(pFile, 0, sizeof(*pFile));
5165651695
szName = sqlite3Strlen30(zName);
51657
- if( szName>1 && zName[0]=='/' ){
51696
+ if( szName>1 && (zName[0]=='/' || zName[0]=='\\') ){
5165851697
int i;
5165951698
#ifndef SQLITE_MUTEX_OMIT
5166051699
sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
5166151700
#endif
5166251701
sqlite3_mutex_enter(pVfsMutex);
@@ -82354,10 +82393,12 @@
8235482393
** sqlite3MisuseError(lineno)
8235582394
** sqlite3CantopenError(lineno)
8235682395
*/
8235782396
static void test_addop_breakpoint(int pc, Op *pOp){
8235882397
static int n = 0;
82398
+ (void)pc;
82399
+ (void)pOp;
8235982400
n++;
8236082401
}
8236182402
#endif
8236282403
8236382404
/*
@@ -84458,11 +84499,10 @@
8445884499
/* Even though this opcode does not use dynamic strings for
8445984500
** the result, result columns may become dynamic if the user calls
8446084501
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
8446184502
*/
8446284503
releaseMemArray(pMem, 8);
84463
- p->pResultSet = 0;
8446484504
8446584505
if( p->rc==SQLITE_NOMEM ){
8446684506
/* This happens if a malloc() inside a call to sqlite3_column_text() or
8446784507
** sqlite3_column_text16() failed. */
8446884508
sqlite3OomFault(db);
@@ -84515,11 +84555,11 @@
8451584555
sqlite3VdbeMemSetNull(pMem+7);
8451684556
#endif
8451784557
sqlite3VdbeMemSetStr(pMem+5, zP4, -1, SQLITE_UTF8, sqlite3_free);
8451884558
p->nResColumn = 8;
8451984559
}
84520
- p->pResultSet = pMem;
84560
+ p->pResultRow = pMem;
8452184561
if( db->mallocFailed ){
8452284562
p->rc = SQLITE_NOMEM;
8452384563
rc = SQLITE_ERROR;
8452484564
}else{
8452584565
p->rc = SQLITE_OK;
@@ -85647,11 +85687,11 @@
8564785687
#endif
8564885688
if( p->zErrMsg ){
8564985689
sqlite3DbFree(db, p->zErrMsg);
8565085690
p->zErrMsg = 0;
8565185691
}
85652
- p->pResultSet = 0;
85692
+ p->pResultRow = 0;
8565385693
#ifdef SQLITE_DEBUG
8565485694
p->nWrite = 0;
8565585695
#endif
8565685696
8565785697
/* Save profiling information from this VDBE run.
@@ -88273,11 +88313,11 @@
8827388313
}else{
8827488314
#ifndef SQLITE_OMIT_TRACE
8827588315
/* If the statement completed successfully, invoke the profile callback */
8827688316
checkProfileCallback(db, p);
8827788317
#endif
88278
-
88318
+ p->pResultRow = 0;
8827988319
if( rc==SQLITE_DONE && db->autoCommit ){
8828088320
assert( p->rc==SQLITE_OK );
8828188321
p->rc = doWalCallbacks(db);
8828288322
if( p->rc!=SQLITE_OK ){
8828388323
rc = SQLITE_ERROR;
@@ -88637,11 +88677,11 @@
8863788677
** Return the number of values available from the current row of the
8863888678
** currently executing statement pStmt.
8863988679
*/
8864088680
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){
8864188681
Vdbe *pVm = (Vdbe *)pStmt;
88642
- if( pVm==0 || pVm->pResultSet==0 ) return 0;
88682
+ if( pVm==0 || pVm->pResultRow==0 ) return 0;
8864388683
return pVm->nResColumn;
8864488684
}
8864588685
8864688686
/*
8864788687
** Return a pointer to static memory containing an SQL NULL value.
@@ -88692,12 +88732,12 @@
8869288732
8869388733
pVm = (Vdbe *)pStmt;
8869488734
if( pVm==0 ) return (Mem*)columnNullValue();
8869588735
assert( pVm->db );
8869688736
sqlite3_mutex_enter(pVm->db->mutex);
88697
- if( pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
88698
- pOut = &pVm->pResultSet[i];
88737
+ if( pVm->pResultRow!=0 && i<pVm->nResColumn && i>=0 ){
88738
+ pOut = &pVm->pResultRow[i];
8869988739
}else{
8870088740
sqlite3Error(pVm->db, SQLITE_RANGE);
8870188741
pOut = (Mem*)columnNullValue();
8870288742
}
8870388743
return pOut;
@@ -90122,10 +90162,13 @@
9012290162
** sqlite3MisuseError(lineno)
9012390163
** sqlite3CantopenError(lineno)
9012490164
*/
9012590165
static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){
9012690166
static int n = 0;
90167
+ (void)pc;
90168
+ (void)pOp;
90169
+ (void)v;
9012790170
n++;
9012890171
}
9012990172
#endif
9013090173
9013190174
/*
@@ -90360,10 +90403,14 @@
9036090403
** floating-point representation if an integer representation
9036190404
** is not possible. Note that the integer representation is
9036290405
** always preferred, even if the affinity is REAL, because
9036390406
** an integer representation is more space efficient on disk.
9036490407
**
90408
+** SQLITE_AFF_FLEXNUM:
90409
+** If the value is text, then try to convert it into a number of
90410
+** some kind (integer or real) but do not make any other changes.
90411
+**
9036590412
** SQLITE_AFF_TEXT:
9036690413
** Convert pRec to a text representation.
9036790414
**
9036890415
** SQLITE_AFF_BLOB:
9036990416
** SQLITE_AFF_NONE:
@@ -90374,15 +90421,15 @@
9037490421
char affinity, /* The affinity to be applied */
9037590422
u8 enc /* Use this text encoding */
9037690423
){
9037790424
if( affinity>=SQLITE_AFF_NUMERIC ){
9037890425
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
90379
- || affinity==SQLITE_AFF_NUMERIC );
90426
+ || affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM );
9038090427
if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
9038190428
if( (pRec->flags & MEM_Real)==0 ){
9038290429
if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
90383
- }else{
90430
+ }else if( affinity<=SQLITE_AFF_REAL ){
9038490431
sqlite3VdbeIntegerAffinity(pRec);
9038590432
}
9038690433
}
9038790434
}else if( affinity==SQLITE_AFF_TEXT ){
9038890435
/* Only attempt the conversion to TEXT if there is an integer or real
@@ -90698,10 +90745,11 @@
9069890745
Op *aOp = p->aOp; /* Copy of p->aOp */
9069990746
Op *pOp = aOp; /* Current operation */
9070090747
#ifdef SQLITE_DEBUG
9070190748
Op *pOrigOp; /* Value of pOp at the top of the loop */
9070290749
int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
90750
+ u8 iCompareIsInit = 0; /* iCompare is initialized */
9070390751
#endif
9070490752
int rc = SQLITE_OK; /* Value to return */
9070590753
sqlite3 *db = p->db; /* The database */
9070690754
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
9070790755
u8 encoding = ENC(db); /* The database encoding */
@@ -90719,11 +90767,13 @@
9071990767
u64 *pnCycle = 0;
9072090768
#endif
9072190769
/*** INSERT STACK UNION HERE ***/
9072290770
9072390771
assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
90724
- sqlite3VdbeEnter(p);
90772
+ if( DbMaskNonZero(p->lockMask) ){
90773
+ sqlite3VdbeEnter(p);
90774
+ }
9072590775
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
9072690776
if( db->xProgress ){
9072790777
u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
9072890778
assert( 0 < db->nProgressOps );
9072990779
nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
@@ -90740,11 +90790,10 @@
9074090790
testcase( p->rc!=SQLITE_OK );
9074190791
p->rc = SQLITE_OK;
9074290792
assert( p->bIsReader || p->readOnly!=0 );
9074390793
p->iCurrentTime = 0;
9074490794
assert( p->explain==0 );
90745
- p->pResultSet = 0;
9074690795
db->busyHandler.nBusy = 0;
9074790796
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
9074890797
sqlite3VdbeIOTraceSql(p);
9074990798
#ifdef SQLITE_DEBUG
9075090799
sqlite3BeginBenignMalloc();
@@ -91571,14 +91620,14 @@
9157191620
assert( p->nResColumn==pOp->p2 );
9157291621
assert( pOp->p1>0 || CORRUPT_DB );
9157391622
assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
9157491623
9157591624
p->cacheCtr = (p->cacheCtr + 2)|1;
91576
- p->pResultSet = &aMem[pOp->p1];
91625
+ p->pResultRow = &aMem[pOp->p1];
9157791626
#ifdef SQLITE_DEBUG
9157891627
{
91579
- Mem *pMem = p->pResultSet;
91628
+ Mem *pMem = p->pResultRow;
9158091629
int i;
9158191630
for(i=0; i<pOp->p2; i++){
9158291631
assert( memIsValid(&pMem[i]) );
9158391632
REGISTER_TRACE(pOp->p1+i, &pMem[i]);
9158491633
/* The registers in the result will not be used again when the
@@ -92111,22 +92160,25 @@
9211192160
if( sqlite3aGTb[pOp->opcode] ){
9211292161
VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
9211392162
goto jump_to_p2;
9211492163
}
9211592164
iCompare = +1;
92165
+ VVA_ONLY( iCompareIsInit = 1; )
9211692166
}else if( pIn3->u.i < pIn1->u.i ){
9211792167
if( sqlite3aLTb[pOp->opcode] ){
9211892168
VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
9211992169
goto jump_to_p2;
9212092170
}
9212192171
iCompare = -1;
92172
+ VVA_ONLY( iCompareIsInit = 1; )
9212292173
}else{
9212392174
if( sqlite3aEQb[pOp->opcode] ){
9212492175
VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
9212592176
goto jump_to_p2;
9212692177
}
9212792178
iCompare = 0;
92179
+ VVA_ONLY( iCompareIsInit = 1; )
9212892180
}
9212992181
VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
9213092182
break;
9213192183
}
9213292184
if( (flags1 | flags3)&MEM_Null ){
@@ -92154,10 +92206,11 @@
9215492206
VdbeBranchTaken(2,3);
9215592207
if( pOp->p5 & SQLITE_JUMPIFNULL ){
9215692208
goto jump_to_p2;
9215792209
}
9215892210
iCompare = 1; /* Operands are not equal */
92211
+ VVA_ONLY( iCompareIsInit = 1; )
9215992212
break;
9216092213
}
9216192214
}else{
9216292215
/* Neither operand is NULL and we couldn't do the special high-speed
9216392216
** integer comparison case. So do a general-case comparison. */
@@ -92179,11 +92232,11 @@
9217992232
testcase( pIn1->flags & MEM_Real );
9218092233
testcase( pIn1->flags & MEM_IntReal );
9218192234
sqlite3VdbeMemStringify(pIn1, encoding, 1);
9218292235
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
9218392236
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
92184
- if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
92237
+ if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
9218592238
}
9218692239
if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
9218792240
testcase( pIn3->flags & MEM_Int );
9218892241
testcase( pIn3->flags & MEM_Real );
9218992242
testcase( pIn3->flags & MEM_IntReal );
@@ -92210,10 +92263,11 @@
9221092263
res2 = sqlite3aEQb[pOp->opcode];
9221192264
}else{
9221292265
res2 = sqlite3aGTb[pOp->opcode];
9221392266
}
9221492267
iCompare = res;
92268
+ VVA_ONLY( iCompareIsInit = 1; )
9221592269
9221692270
/* Undo any changes made by applyAffinity() to the input registers. */
9221792271
assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
9221892272
pIn3->flags = flags3;
9221992273
assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
@@ -92248,10 +92302,11 @@
9224892302
if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
9224992303
assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
9225092304
break;
9225192305
}
9225292306
#endif /* SQLITE_DEBUG */
92307
+ assert( iCompareIsInit );
9225392308
VdbeBranchTaken(iCompare==0, 2);
9225492309
if( iCompare==0 ) goto jump_to_p2;
9225592310
break;
9225692311
}
9225792312
@@ -92342,10 +92397,11 @@
9234292397
REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
9234392398
assert( i<pKeyInfo->nKeyField );
9234492399
pColl = pKeyInfo->aColl[i];
9234592400
bRev = (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC);
9234692401
iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
92402
+ VVA_ONLY( iCompareIsInit = 1; )
9234792403
if( iCompare ){
9234892404
if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
9234992405
&& ((aMem[p1+idx].flags & MEM_Null) || (aMem[p2+idx].flags & MEM_Null))
9235092406
){
9235192407
iCompare = -iCompare;
@@ -92366,10 +92422,11 @@
9236692422
**
9236792423
** This opcode must immediately follow an OP_Compare opcode.
9236892424
*/
9236992425
case OP_Jump: { /* jump */
9237092426
assert( pOp>aOp && pOp[-1].opcode==OP_Compare );
92427
+ assert( iCompareIsInit );
9237192428
if( iCompare<0 ){
9237292429
VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
9237392430
}else if( iCompare==0 ){
9237492431
VdbeBranchTaken(1,4); pOp = &aOp[pOp->p2 - 1];
9237592432
}else{
@@ -95544,12 +95601,15 @@
9554495601
}
9554595602
}
9554695603
if( pOp->p5 & OPFLAG_ISNOOP ) break;
9554795604
#endif
9554895605
95549
- if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
95550
- if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
95606
+ assert( (pOp->p5 & OPFLAG_LASTROWID)==0 || (pOp->p5 & OPFLAG_NCHANGE)!=0 );
95607
+ if( pOp->p5 & OPFLAG_NCHANGE ){
95608
+ p->nChange++;
95609
+ if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
95610
+ }
9555195611
assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
9555295612
x.pData = pData->z;
9555395613
x.nData = pData->n;
9555495614
seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
9555595615
if( pData->flags & MEM_Zero ){
@@ -98812,11 +98872,13 @@
9881298872
goto abort_due_to_error;
9881398873
}
9881498874
}
9881598875
#endif
9881698876
p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
98817
- sqlite3VdbeLeave(p);
98877
+ if( DbMaskNonZero(p->lockMask) ){
98878
+ sqlite3VdbeLeave(p);
98879
+ }
9881898880
assert( rc!=SQLITE_OK || nExtraDelete==0
9881998881
|| sqlite3_strlike("DELETE%",p->zSql,0)!=0
9882098882
);
9882198883
return rc;
9882298884
@@ -102219,10 +102281,13 @@
102219102281
"subprog TEXT,"
102220102282
"stmt HIDDEN"
102221102283
");"
102222102284
};
102223102285
102286
+ (void)argc;
102287
+ (void)argv;
102288
+ (void)pzErr;
102224102289
rc = sqlite3_declare_vtab(db, azSchema[isTabUsed]);
102225102290
if( rc==SQLITE_OK ){
102226102291
pNew = sqlite3_malloc( sizeof(*pNew) );
102227102292
*ppVtab = (sqlite3_vtab*)pNew;
102228102293
if( pNew==0 ) return SQLITE_NOMEM;
@@ -102454,10 +102519,11 @@
102454102519
int argc, sqlite3_value **argv
102455102520
){
102456102521
bytecodevtab_cursor *pCur = (bytecodevtab_cursor *)pVtabCursor;
102457102522
bytecodevtab *pVTab = (bytecodevtab *)pVtabCursor->pVtab;
102458102523
int rc = SQLITE_OK;
102524
+ (void)idxStr;
102459102525
102460102526
bytecodevtabCursorClear(pCur);
102461102527
pCur->iRowid = 0;
102462102528
pCur->iAddr = 0;
102463102529
pCur->showSubprograms = idxNum==0;
@@ -109654,11 +109720,11 @@
109654109720
iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
109655109721
assert( ExprUseYTab(pExpr) );
109656109722
assert( pExpr->y.pTab!=0 );
109657109723
aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
109658109724
if( aff>SQLITE_AFF_BLOB ){
109659
- static const char zAff[] = "B\000C\000D\000E";
109725
+ static const char zAff[] = "B\000C\000D\000E\000F";
109660109726
assert( SQLITE_AFF_BLOB=='A' );
109661109727
assert( SQLITE_AFF_TEXT=='B' );
109662109728
sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
109663109729
&zAff[(aff-'B')*2], P4_STATIC);
109664109730
}
@@ -111651,14 +111717,12 @@
111651111717
** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
111652111718
** object that is referenced does not refer directly to the Expr. If
111653111719
** it does, make a copy. This is done because the pExpr argument is
111654111720
** subject to change.
111655111721
**
111656
-** The copy is stored on pParse->pConstExpr with a register number of 0.
111657
-** This will cause the expression to be deleted automatically when the
111658
-** Parse object is destroyed, but the zero register number means that it
111659
-** will not generate any code in the preamble.
111722
+** The copy is scheduled for deletion using the sqlite3ExprDeferredDelete()
111723
+** which builds on the sqlite3ParserAddCleanup() mechanism.
111660111724
*/
111661111725
static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
111662111726
if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
111663111727
&& pExpr->pAggInfo!=0
111664111728
){
@@ -111665,11 +111729,10 @@
111665111729
AggInfo *pAggInfo = pExpr->pAggInfo;
111666111730
int iAgg = pExpr->iAgg;
111667111731
Parse *pParse = pWalker->pParse;
111668111732
sqlite3 *db = pParse->db;
111669111733
if( pExpr->op!=TK_AGG_FUNCTION ){
111670
- assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_IF_NULL_ROW );
111671111734
assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
111672111735
if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
111673111736
pExpr = sqlite3ExprDup(db, pExpr, 0);
111674111737
if( pExpr ){
111675111738
pAggInfo->aCol[iAgg].pCExpr = pExpr;
@@ -111791,10 +111854,11 @@
111791111854
if( pCol->iSorterColumn<0 ){
111792111855
pCol->iSorterColumn = pAggInfo->nSortingColumn++;
111793111856
}
111794111857
fix_up_expr:
111795111858
ExprSetVVAProperty(pExpr, EP_NoReduce);
111859
+ assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
111796111860
pExpr->pAggInfo = pAggInfo;
111797111861
if( pExpr->op==TK_COLUMN ){
111798111862
pExpr->op = TK_AGG_COLUMN;
111799111863
}
111800111864
pExpr->iAgg = (i16)k;
@@ -111826,10 +111890,11 @@
111826111890
if( iDataCur<0 ) continue;
111827111891
if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
111828111892
}
111829111893
if( pIEpr==0 ) break;
111830111894
if( NEVER(!ExprUseYTab(pExpr)) ) break;
111895
+ if( pExpr->pAggInfo!=0 ) break; /* Already resolved by outer context */
111831111896
111832111897
/* If we reach this point, it means that expression pExpr can be
111833111898
** translated into a reference to an index column as described by
111834111899
** pIEpr.
111835111900
*/
@@ -112780,17 +112845,18 @@
112780112845
static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
112781112846
assert( pParse==pParse->db->pParse );
112782112847
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
112783112848
if( pParse->nErr==0 ){
112784112849
const RenameToken *p;
112785
- u8 i = 0;
112850
+ u32 i = 1;
112786112851
for(p=pParse->pRename; p; p=p->pNext){
112787112852
if( p->p ){
112788112853
assert( p->p!=pPtr );
112789
- i += *(u8*)(p->p);
112854
+ i += *(u8*)(p->p) | 1;
112790112855
}
112791112856
}
112857
+ assert( i>0 );
112792112858
}
112793112859
}
112794112860
#else
112795112861
# define renameTokenCheckAll(x,y)
112796112862
#endif
@@ -117442,10 +117508,11 @@
117442117508
sqlite3 *db = pParse->db;
117443117509
u32 savedDbFlags = db->mDbFlags;
117444117510
char saveBuf[PARSE_TAIL_SZ];
117445117511
117446117512
if( pParse->nErr ) return;
117513
+ if( pParse->eParseMode ) return;
117447117514
assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
117448117515
va_start(ap, zFormat);
117449117516
zSql = sqlite3VMPrintf(db, zFormat, ap);
117450117517
va_end(ap);
117451117518
if( zSql==0 ){
@@ -119139,10 +119206,17 @@
119139119206
assert( TF_HasStored==COLFLAG_STORED );
119140119207
pTab->tabFlags |= eType;
119141119208
if( pCol->colFlags & COLFLAG_PRIMKEY ){
119142119209
makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
119143119210
}
119211
+ if( ALWAYS(pExpr) && pExpr->op==TK_ID ){
119212
+ /* The value of a generated column needs to be a real expression, not
119213
+ ** just a reference to another column, in order for covering index
119214
+ ** optimizations to work correctly. So if the value is not an expression,
119215
+ ** turn it into one by adding a unary "+" operator. */
119216
+ pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
119217
+ }
119144119218
sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
119145119219
pExpr = 0;
119146119220
goto generated_done;
119147119221
119148119222
generated_error:
@@ -119275,11 +119349,12 @@
119275119349
static const char * const azType[] = {
119276119350
/* SQLITE_AFF_BLOB */ "",
119277119351
/* SQLITE_AFF_TEXT */ " TEXT",
119278119352
/* SQLITE_AFF_NUMERIC */ " NUM",
119279119353
/* SQLITE_AFF_INTEGER */ " INT",
119280
- /* SQLITE_AFF_REAL */ " REAL"
119354
+ /* SQLITE_AFF_REAL */ " REAL",
119355
+ /* SQLITE_AFF_FLEXNUM */ " NUM",
119281119356
};
119282119357
int len;
119283119358
const char *zType;
119284119359
119285119360
sqlite3_snprintf(n-k, &zStmt[k], zSep);
@@ -119291,14 +119366,16 @@
119291119366
testcase( pCol->affinity==SQLITE_AFF_BLOB );
119292119367
testcase( pCol->affinity==SQLITE_AFF_TEXT );
119293119368
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
119294119369
testcase( pCol->affinity==SQLITE_AFF_INTEGER );
119295119370
testcase( pCol->affinity==SQLITE_AFF_REAL );
119371
+ testcase( pCol->affinity==SQLITE_AFF_FLEXNUM );
119296119372
119297119373
zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
119298119374
len = sqlite3Strlen30(zType);
119299119375
assert( pCol->affinity==SQLITE_AFF_BLOB
119376
+ || pCol->affinity==SQLITE_AFF_FLEXNUM
119300119377
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
119301119378
memcpy(&zStmt[k], zType, len);
119302119379
k += len;
119303119380
assert( k<=n );
119304119381
}
@@ -119709,10 +119786,11 @@
119709119786
** they should not be changed. Expressions attached to a table or
119710119787
** index definition are tagged this way to help ensure that we do
119711119788
** not pass them into code generator routines by mistake.
119712119789
*/
119713119790
static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){
119791
+ (void)pWalker;
119714119792
ExprSetVVAProperty(pExpr, EP_Immutable);
119715119793
return WRC_Continue;
119716119794
}
119717119795
static void markExprListImmutable(ExprList *pList){
119718119796
if( pList ){
@@ -125459,11 +125537,11 @@
125459125537
sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue));
125460125538
break;
125461125539
}
125462125540
case SQLITE_BLOB: {
125463125541
char const *zBlob = sqlite3_value_blob(pValue);
125464
- int nBlob = sqlite3_value_bytes(pValue);
125542
+ i64 nBlob = sqlite3_value_bytes(pValue);
125465125543
assert( zBlob==sqlite3_value_blob(pValue) ); /* No encoding change */
125466125544
sqlite3StrAccumEnlarge(pStr, nBlob*2 + 4);
125467125545
if( pStr->accError==0 ){
125468125546
char *zText = pStr->zText;
125469125547
int i;
@@ -125817,10 +125895,13 @@
125817125895
sqlite3_context *context,
125818125896
int argc,
125819125897
sqlite3_value **argv
125820125898
){
125821125899
/* no-op */
125900
+ (void)context;
125901
+ (void)argc;
125902
+ (void)argv;
125822125903
}
125823125904
#endif /*SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION*/
125824125905
125825125906
125826125907
/* IMP: R-25361-16150 This function is omitted from SQLite by default. It
@@ -126560,10 +126641,11 @@
126560126641
sqlite3_context *context,
126561126642
int argc,
126562126643
sqlite3_value **argv
126563126644
){
126564126645
assert( argc==0 );
126646
+ (void)argv;
126565126647
sqlite3_result_double(context, M_PI);
126566126648
}
126567126649
126568126650
#endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
126569126651
@@ -139645,11 +139727,11 @@
139645139727
** database table or a subquery.
139646139728
*/
139647139729
Table *pTab = 0; /* Table structure column is extracted from */
139648139730
Select *pS = 0; /* Select the column is extracted from */
139649139731
int iCol = pExpr->iColumn; /* Index of column in pTab */
139650
- while( pNC && !pTab ){
139732
+ while( ALWAYS(pNC) && !pTab ){
139651139733
SrcList *pTabList = pNC->pSrcList;
139652139734
for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
139653139735
if( j<pTabList->nSrc ){
139654139736
pTab = pTabList->a[j].pTab;
139655139737
pS = pTabList->a[j].pSelect;
@@ -139656,11 +139738,11 @@
139656139738
}else{
139657139739
pNC = pNC->pNext;
139658139740
}
139659139741
}
139660139742
139661
- if( pTab==0 ){
139743
+ if( NEVER(pTab==0) ){
139662139744
/* At one time, code such as "SELECT new.x" within a trigger would
139663139745
** cause this condition to run. Since then, we have restructured how
139664139746
** trigger code is generated and so this condition is no longer
139665139747
** possible. However, it can still be true for statements like
139666139748
** the following:
@@ -140032,18 +140114,10 @@
140032140114
return SQLITE_NOMEM_BKPT;
140033140115
}
140034140116
return SQLITE_OK;
140035140117
}
140036140118
140037
-/*
140038
-** This bit, when added to the "aff" parameter of
140039
-** sqlite3ColumnTypeOfSubquery() means that result set
140040
-** expressions of the form "CAST(expr AS NUMERIC)" should result in
140041
-** NONE affinity rather than NUMERIC affinity.
140042
-*/
140043
-#define SQLITE_AFF_FLAG1 0x10
140044
-
140045140119
/*
140046140120
** pTab is a transient Table object that represents a subquery of some
140047140121
** kind (maybe a parenthesized subquery in the FROM clause of a larger
140048140122
** query, or a VIEW, or a CTE). This routine computes type information
140049140123
** for that Table object based on the Select object that implements the
@@ -140050,21 +140124,16 @@
140050140124
** subquery. For the purposes of this routine, "type infomation" means:
140051140125
**
140052140126
** * The datatype name, as it might appear in a CREATE TABLE statement
140053140127
** * Which collating sequence to use for the column
140054140128
** * The affinity of the column
140055
-**
140056
-** The SQLITE_AFF_FLAG1 bit added to parameter aff means that a
140057
-** result set column of the form "CAST(expr AS NUMERIC)" should use
140058
-** NONE affinity rather than NUMERIC affinity. See the
140059
-** 2022-12-10 "reopen" of ticket https://sqlite.org/src/tktview/57c47526c3.
140060140129
*/
140061140130
SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140062140131
Parse *pParse, /* Parsing contexts */
140063140132
Table *pTab, /* Add column type information to this table */
140064140133
Select *pSelect, /* SELECT used to determine types and collations */
140065
- char aff /* Default affinity. Maybe with SQLITE_AFF_FLAG1 too */
140134
+ char aff /* Default affinity. */
140066140135
){
140067140136
sqlite3 *db = pParse->db;
140068140137
Column *pCol;
140069140138
CollSeq *pColl;
140070140139
int i,j;
@@ -140072,10 +140141,11 @@
140072140141
struct ExprList_item *a;
140073140142
140074140143
assert( pSelect!=0 );
140075140144
assert( (pSelect->selFlags & SF_Resolved)!=0 );
140076140145
assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
140146
+ assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
140077140147
if( db->mallocFailed ) return;
140078140148
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
140079140149
a = pSelect->pEList->a;
140080140150
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140081140151
const char *zType;
@@ -140083,17 +140153,13 @@
140083140153
pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140084140154
p = a[i].pExpr;
140085140155
/* pCol->szEst = ... // Column size est for SELECT tables never used */
140086140156
pCol->affinity = sqlite3ExprAffinity(p);
140087140157
if( pCol->affinity<=SQLITE_AFF_NONE ){
140088
- assert( (SQLITE_AFF_FLAG1 & SQLITE_AFF_MASK)==0 );
140089
- pCol->affinity = aff & SQLITE_AFF_MASK;
140090
- }
140091
- if( aff & SQLITE_AFF_FLAG1 ){
140092
- if( pCol->affinity==SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140093
- pCol->affinity = SQLITE_AFF_NONE;
140094
- }
140158
+ pCol->affinity = aff;
140159
+ }else if( pCol->affinity>=SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140160
+ pCol->affinity = SQLITE_AFF_FLEXNUM;
140095140161
}
140096140162
if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140097140163
int m = 0;
140098140164
Select *pS2;
140099140165
for(m=0, pS2=pSelect->pNext; pS2; pS2=pS2->pNext){
@@ -140104,11 +140170,13 @@
140104140170
}else
140105140171
if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140106140172
pCol->affinity = SQLITE_AFF_BLOB;
140107140173
}
140108140174
}
140109
- if( pCol->affinity==SQLITE_AFF_NUMERIC ){
140175
+ if( pCol->affinity==SQLITE_AFF_NUMERIC
140176
+ || pCol->affinity==SQLITE_AFF_FLEXNUM
140177
+ ){
140110140178
zType = "NUM";
140111140179
}else{
140112140180
zType = 0;
140113140181
for(j=1; j<SQLITE_N_STDTYPE; j++){
140114140182
if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
@@ -143998,12 +144066,11 @@
143998144066
assert( pTab!=0 );
143999144067
if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
144000144068
/* A sub-query in the FROM clause of a SELECT */
144001144069
Select *pSel = pFrom->pSelect;
144002144070
if( pSel ){
144003
- sqlite3SubqueryColumnTypes(pParse, pTab, pSel,
144004
- SQLITE_AFF_NONE|SQLITE_AFF_FLAG1);
144071
+ sqlite3SubqueryColumnTypes(pParse, pTab, pSel, SQLITE_AFF_NONE);
144005144072
}
144006144073
}
144007144074
}
144008144075
}
144009144076
#endif
@@ -144073,11 +144140,11 @@
144073144140
ii>=pAggInfo->nAccumulator ? "" : " Accumulator");
144074144141
sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
144075144142
}
144076144143
for(ii=0; ii<pAggInfo->nFunc; ii++){
144077144144
sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
144078
- ii, AggInfoFuncReg(pAggInfo,ii));
144145
+ ii, pAggInfo->iFirstReg+pAggInfo->nColumn+ii);
144079144146
sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
144080144147
}
144081144148
}
144082144149
#endif /* TREETRACE_ENABLED */
144083144150
@@ -145444,10 +145511,13 @@
145444145511
}
145445145512
if( db->mallocFailed ){
145446145513
goto select_end;
145447145514
}
145448145515
pAggInfo->selId = p->selId;
145516
+#ifdef SQLITE_DEBUG
145517
+ pAggInfo->pSelect = p;
145518
+#endif
145449145519
memset(&sNC, 0, sizeof(sNC));
145450145520
sNC.pParse = pParse;
145451145521
sNC.pSrcList = pTabList;
145452145522
sNC.uNC.pAggInfo = pAggInfo;
145453145523
VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
@@ -162038,10 +162108,16 @@
162038162108
}
162039162109
if( sqlite3ExprIsConstant(pExpr) ) continue;
162040162110
p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
162041162111
if( p==0 ) break;
162042162112
p->pIENext = pParse->pIdxEpr;
162113
+#ifdef WHERETRACE_ENABLED
162114
+ if( sqlite3WhereTrace & 0x200 ){
162115
+ sqlite3DebugPrintf("New pParse->pIdxEpr term {%d,%d}\n", iIdxCur, i);
162116
+ if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(pExpr);
162117
+ }
162118
+#endif
162043162119
p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
162044162120
p->iDataCur = pTabItem->iCursor;
162045162121
p->iIdxCur = iIdxCur;
162046162122
p->iIdxCol = i;
162047162123
p->bMaybeNullRow = bMaybeNullRow;
@@ -163000,10 +163076,17 @@
163000163076
}
163001163077
if( pIdx->bHasExpr ){
163002163078
IndexedExpr *p = pParse->pIdxEpr;
163003163079
while( p ){
163004163080
if( p->iIdxCur==pLevel->iIdxCur ){
163081
+#ifdef WHERETRACE_ENABLED
163082
+ if( sqlite3WhereTrace & 0x200 ){
163083
+ sqlite3DebugPrintf("Disable pParse->pIdxEpr term {%d,%d}\n",
163084
+ p->iIdxCur, p->iIdxCol);
163085
+ if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(p->pExpr);
163086
+ }
163087
+#endif
163005163088
p->iDataCur = -1;
163006163089
p->iIdxCur = -1;
163007163090
}
163008163091
p = p->pIENext;
163009163092
}
@@ -201354,11 +201437,11 @@
201354201437
*/
201355201438
static int readInt16(u8 *p){
201356201439
return (p[0]<<8) + p[1];
201357201440
}
201358201441
static void readCoord(u8 *p, RtreeCoord *pCoord){
201359
- assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
201442
+ assert( (((sqlite3_uint64)p)&3)==0 ); /* p is always 4-byte aligned */
201360201443
#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
201361201444
pCoord->u = _byteswap_ulong(*(u32*)p);
201362201445
#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
201363201446
pCoord->u = __builtin_bswap32(*(u32*)p);
201364201447
#elif SQLITE_BYTEORDER==4321
@@ -201408,11 +201491,11 @@
201408201491
p[0] = (i>> 8)&0xFF;
201409201492
p[1] = (i>> 0)&0xFF;
201410201493
}
201411201494
static int writeCoord(u8 *p, RtreeCoord *pCoord){
201412201495
u32 i;
201413
- assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
201496
+ assert( (((sqlite3_uint64)p)&3)==0 ); /* p is always 4-byte aligned */
201414201497
assert( sizeof(RtreeCoord)==4 );
201415201498
assert( sizeof(u32)==4 );
201416201499
#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
201417201500
i = __builtin_bswap32(pCoord->u);
201418201501
memcpy(p, &i, 4);
@@ -202136,11 +202219,11 @@
202136202219
pCellData += 8 + 4*(p->iCoord&0xfe);
202137202220
202138202221
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
202139202222
|| p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
202140202223
|| p->op==RTREE_FALSE );
202141
- assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
202224
+ assert( (((sqlite3_uint64)pCellData)&3)==0 ); /* 4-byte aligned */
202142202225
switch( p->op ){
202143202226
case RTREE_TRUE: return; /* Always satisfied */
202144202227
case RTREE_FALSE: break; /* Never satisfied */
202145202228
case RTREE_EQ:
202146202229
RTREE_DECODE_COORD(eInt, pCellData, val);
@@ -202189,11 +202272,11 @@
202189202272
202190202273
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
202191202274
|| p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
202192202275
|| p->op==RTREE_FALSE );
202193202276
pCellData += 8 + p->iCoord*4;
202194
- assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
202277
+ assert( (((sqlite3_uint64)pCellData)&3)==0 ); /* 4-byte aligned */
202195202278
RTREE_DECODE_COORD(eInt, pCellData, xN);
202196202279
switch( p->op ){
202197202280
case RTREE_TRUE: return; /* Always satisfied */
202198202281
case RTREE_FALSE: break; /* Never satisfied */
202199202282
case RTREE_LE: if( xN <= p->u.rValue ) return; break;
@@ -205561,11 +205644,11 @@
205561205644
){
205562205645
GeoPoly *p = 0;
205563205646
int nByte;
205564205647
testcase( pCtx==0 );
205565205648
if( sqlite3_value_type(pVal)==SQLITE_BLOB
205566
- && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord))
205649
+ && (nByte = sqlite3_value_bytes(pVal))>=(int)(4+6*sizeof(GeoCoord))
205567205650
){
205568205651
const unsigned char *a = sqlite3_value_blob(pVal);
205569205652
int nVertex;
205570205653
if( a==0 ){
205571205654
if( pCtx ) sqlite3_result_error_nomem(pCtx);
@@ -205619,10 +205702,11 @@
205619205702
sqlite3_context *context,
205620205703
int argc,
205621205704
sqlite3_value **argv
205622205705
){
205623205706
GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205707
+ (void)argc;
205624205708
if( p ){
205625205709
sqlite3_result_blob(context, p->hdr,
205626205710
4+8*p->nVertex, SQLITE_TRANSIENT);
205627205711
sqlite3_free(p);
205628205712
}
@@ -205638,10 +205722,11 @@
205638205722
sqlite3_context *context,
205639205723
int argc,
205640205724
sqlite3_value **argv
205641205725
){
205642205726
GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205727
+ (void)argc;
205643205728
if( p ){
205644205729
sqlite3 *db = sqlite3_context_db_handle(context);
205645205730
sqlite3_str *x = sqlite3_str_new(db);
205646205731
int i;
205647205732
sqlite3_str_append(x, "[", 1);
@@ -205719,10 +205804,11 @@
205719205804
double D = sqlite3_value_double(argv[4]);
205720205805
double E = sqlite3_value_double(argv[5]);
205721205806
double F = sqlite3_value_double(argv[6]);
205722205807
GeoCoord x1, y1, x0, y0;
205723205808
int ii;
205809
+ (void)argc;
205724205810
if( p ){
205725205811
for(ii=0; ii<p->nVertex; ii++){
205726205812
x0 = GeoX(p,ii);
205727205813
y0 = GeoY(p,ii);
205728205814
x1 = (GeoCoord)(A*x0 + B*y0 + E);
@@ -205769,10 +205855,11 @@
205769205855
sqlite3_context *context,
205770205856
int argc,
205771205857
sqlite3_value **argv
205772205858
){
205773205859
GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205860
+ (void)argc;
205774205861
if( p ){
205775205862
sqlite3_result_double(context, geopolyArea(p));
205776205863
sqlite3_free(p);
205777205864
}
205778205865
}
@@ -205794,10 +205881,11 @@
205794205881
sqlite3_context *context,
205795205882
int argc,
205796205883
sqlite3_value **argv
205797205884
){
205798205885
GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205886
+ (void)argc;
205799205887
if( p ){
205800205888
if( geopolyArea(p)<0.0 ){
205801205889
int ii, jj;
205802205890
for(ii=1, jj=p->nVertex-1; ii<jj; ii++, jj--){
205803205891
GeoCoord t = GeoX(p,ii);
@@ -205848,10 +205936,11 @@
205848205936
double y = sqlite3_value_double(argv[1]);
205849205937
double r = sqlite3_value_double(argv[2]);
205850205938
int n = sqlite3_value_int(argv[3]);
205851205939
int i;
205852205940
GeoPoly *p;
205941
+ (void)argc;
205853205942
205854205943
if( n<3 || r<=0.0 ) return;
205855205944
if( n>1000 ) n = 1000;
205856205945
p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) );
205857205946
if( p==0 ){
@@ -205957,10 +206046,11 @@
205957206046
sqlite3_context *context,
205958206047
int argc,
205959206048
sqlite3_value **argv
205960206049
){
205961206050
GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
206051
+ (void)argc;
205962206052
if( p ){
205963206053
sqlite3_result_blob(context, p->hdr,
205964206054
4+8*p->nVertex, SQLITE_TRANSIENT);
205965206055
sqlite3_free(p);
205966206056
}
@@ -205984,10 +206074,11 @@
205984206074
int argc,
205985206075
sqlite3_value **argv
205986206076
){
205987206077
RtreeCoord a[4];
205988206078
int rc = SQLITE_OK;
206079
+ (void)argc;
205989206080
(void)geopolyBBox(context, argv[0], a, &rc);
205990206081
if( rc==SQLITE_OK ){
205991206082
GeoBBox *pBBox;
205992206083
pBBox = (GeoBBox*)sqlite3_aggregate_context(context, sizeof(*pBBox));
205993206084
if( pBBox==0 ) return;
@@ -206072,10 +206163,12 @@
206072206163
double x0 = sqlite3_value_double(argv[1]);
206073206164
double y0 = sqlite3_value_double(argv[2]);
206074206165
int v = 0;
206075206166
int cnt = 0;
206076206167
int ii;
206168
+ (void)argc;
206169
+
206077206170
if( p1==0 ) return;
206078206171
for(ii=0; ii<p1->nVertex-1; ii++){
206079206172
v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
206080206173
GeoX(p1,ii+1),GeoY(p1,ii+1));
206081206174
if( v==2 ) break;
@@ -206111,10 +206204,11 @@
206111206204
int argc,
206112206205
sqlite3_value **argv
206113206206
){
206114206207
GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
206115206208
GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
206209
+ (void)argc;
206116206210
if( p1 && p2 ){
206117206211
int x = geopolyOverlap(p1, p2);
206118206212
if( x<0 ){
206119206213
sqlite3_result_error_nomem(context);
206120206214
}else{
@@ -206441,10 +206535,11 @@
206441206535
int argc,
206442206536
sqlite3_value **argv
206443206537
){
206444206538
GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
206445206539
GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
206540
+ (void)argc;
206446206541
if( p1 && p2 ){
206447206542
int x = geopolyOverlap(p1, p2);
206448206543
if( x<0 ){
206449206544
sqlite3_result_error_nomem(context);
206450206545
}else{
@@ -206461,12 +206556,16 @@
206461206556
static void geopolyDebugFunc(
206462206557
sqlite3_context *context,
206463206558
int argc,
206464206559
sqlite3_value **argv
206465206560
){
206561
+ (void)context;
206562
+ (void)argc;
206466206563
#ifdef GEOPOLY_ENABLE_DEBUG
206467206564
geo_debug = sqlite3_value_int(argv[0]);
206565
+#else
206566
+ (void)argv;
206468206567
#endif
206469206568
}
206470206569
206471206570
/*
206472206571
** This function is the implementation of both the xConnect and xCreate
@@ -206490,10 +206589,11 @@
206490206589
sqlite3_int64 nDb; /* Length of string argv[1] */
206491206590
sqlite3_int64 nName; /* Length of string argv[2] */
206492206591
sqlite3_str *pSql;
206493206592
char *zSql;
206494206593
int ii;
206594
+ (void)pAux;
206495206595
206496206596
sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
206497206597
206498206598
/* Allocate the sqlite3_vtab structure */
206499206599
nDb = strlen(argv[1]);
@@ -206606,10 +206706,11 @@
206606206706
Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
206607206707
RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
206608206708
RtreeNode *pRoot = 0;
206609206709
int rc = SQLITE_OK;
206610206710
int iCell = 0;
206711
+ (void)idxStr;
206611206712
206612206713
rtreeReference(pRtree);
206613206714
206614206715
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
206615206716
resetCursor(pCsr);
@@ -206732,10 +206833,11 @@
206732206833
static int geopolyBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
206733206834
int ii;
206734206835
int iRowidTerm = -1;
206735206836
int iFuncTerm = -1;
206736206837
int idxNum = 0;
206838
+ (void)tab;
206737206839
206738206840
for(ii=0; ii<pIdxInfo->nConstraint; ii++){
206739206841
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
206740206842
if( !p->usable ) continue;
206741206843
if( p->iColumn<0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
@@ -206978,10 +207080,12 @@
206978207080
int nArg,
206979207081
const char *zName,
206980207082
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
206981207083
void **ppArg
206982207084
){
207085
+ (void)pVtab;
207086
+ (void)nArg;
206983207087
if( sqlite3_stricmp(zName, "geopoly_overlap")==0 ){
206984207088
*pxFunc = geopolyOverlapFunc;
206985207089
*ppArg = 0;
206986207090
return SQLITE_INDEX_CONSTRAINT_FUNCTION;
206987207091
}
@@ -207047,11 +207151,11 @@
207047207151
void (*xFinal)(sqlite3_context*);
207048207152
const char *zName;
207049207153
} aAgg[] = {
207050207154
{ geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" },
207051207155
};
207052
- int i;
207156
+ unsigned int i;
207053207157
for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
207054207158
int enc;
207055207159
if( aFunc[i].bPure ){
207056207160
enc = SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS;
207057207161
}else{
@@ -214254,10 +214358,11 @@
214254214358
char **pzErr
214255214359
){
214256214360
StatTable *pTab = 0;
214257214361
int rc = SQLITE_OK;
214258214362
int iDb;
214363
+ (void)pAux;
214259214364
214260214365
if( argc>=4 ){
214261214366
Token nm;
214262214367
sqlite3TokenInit(&nm, (char*)argv[3]);
214263214368
iDb = sqlite3FindDb(db, &nm);
@@ -214307,10 +214412,11 @@
214307214412
static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
214308214413
int i;
214309214414
int iSchema = -1;
214310214415
int iName = -1;
214311214416
int iAgg = -1;
214417
+ (void)tab;
214312214418
214313214419
/* Look for a valid schema=? constraint. If found, change the idxNum to
214314214420
** 1 and request the value of that constraint be sent to xFilter. And
214315214421
** lower the cost estimate to encourage the constrained version to be
214316214422
** used.
@@ -214832,10 +214938,12 @@
214832214938
sqlite3_str *pSql; /* Query of btrees to analyze */
214833214939
char *zSql; /* String value of pSql */
214834214940
int iArg = 0; /* Count of argv[] parameters used so far */
214835214941
int rc = SQLITE_OK; /* Result of this operation */
214836214942
const char *zName = 0; /* Only provide analysis of this table */
214943
+ (void)argc;
214944
+ (void)idxStr;
214837214945
214838214946
statResetCsr(pCsr);
214839214947
sqlite3_finalize(pCsr->pStmt);
214840214948
pCsr->pStmt = 0;
214841214949
if( idxNum & 0x01 ){
@@ -215066,10 +215174,14 @@
215066215174
sqlite3_vtab **ppVtab,
215067215175
char **pzErr
215068215176
){
215069215177
DbpageTable *pTab = 0;
215070215178
int rc = SQLITE_OK;
215179
+ (void)pAux;
215180
+ (void)argc;
215181
+ (void)argv;
215182
+ (void)pzErr;
215071215183
215072215184
sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
215073215185
rc = sqlite3_declare_vtab(db,
215074215186
"CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
215075215187
if( rc==SQLITE_OK ){
@@ -215104,10 +215216,11 @@
215104215216
** 3 schema=?1, pgno=?2
215105215217
*/
215106215218
static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
215107215219
int i;
215108215220
int iPlan = 0;
215221
+ (void)tab;
215109215222
215110215223
/* If there is a schema= constraint, it must be honored. Report a
215111215224
** ridiculously large estimated cost if the schema= constraint is
215112215225
** unavailable
215113215226
*/
@@ -215218,10 +215331,12 @@
215218215331
DbpageCursor *pCsr = (DbpageCursor *)pCursor;
215219215332
DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
215220215333
int rc;
215221215334
sqlite3 *db = pTab->db;
215222215335
Btree *pBt;
215336
+
215337
+ (void)idxStr;
215223215338
215224215339
/* Default setting is no rows of result */
215225215340
pCsr->pgno = 1;
215226215341
pCsr->mxPgno = 0;
215227215342
@@ -215314,10 +215429,11 @@
215314215429
int iDb;
215315215430
Btree *pBt;
215316215431
Pager *pPager;
215317215432
int szPage;
215318215433
215434
+ (void)pRowid;
215319215435
if( pTab->db->flags & SQLITE_Defensive ){
215320215436
zErr = "read-only";
215321215437
goto update_fail;
215322215438
}
215323215439
if( argc==1 ){
@@ -216921,10 +217037,12 @@
216921217037
){
216922217038
sqlite3_session *pSession;
216923217039
int nDb = sqlite3Strlen30(zDb);
216924217040
216925217041
assert( sqlite3_mutex_held(db->mutex) );
217042
+ (void)iKey1;
217043
+ (void)iKey2;
216926217044
216927217045
for(pSession=(sqlite3_session *)pCtx; pSession; pSession=pSession->pNext){
216928217046
SessionTable *pTab;
216929217047
216930217048
/* If this session is attached to a different database ("main", "temp"
@@ -216997,10 +217115,11 @@
216997217115
static int sessionDiffCount(void *pCtx){
216998217116
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
216999217117
return p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt);
217000217118
}
217001217119
static int sessionDiffDepth(void *pCtx){
217120
+ (void)pCtx;
217002217121
return 0;
217003217122
}
217004217123
217005217124
/*
217006217125
** Install the diff hooks on the session object passed as the only
@@ -217070,11 +217189,10 @@
217070217189
217071217190
return zRet;
217072217191
}
217073217192
217074217193
static char *sessionSelectFindNew(
217075
- int nCol,
217076217194
const char *zDb1, /* Pick rows in this db only */
217077217195
const char *zDb2, /* But not in this one */
217078217196
const char *zTbl, /* Table name */
217079217197
const char *zExpr
217080217198
){
@@ -217094,11 +217212,11 @@
217094217212
const char *zDb1,
217095217213
const char *zDb2,
217096217214
char *zExpr
217097217215
){
217098217216
int rc = SQLITE_OK;
217099
- char *zStmt = sessionSelectFindNew(pTab->nCol, zDb1, zDb2, pTab->zName,zExpr);
217217
+ char *zStmt = sessionSelectFindNew(zDb1, zDb2, pTab->zName,zExpr);
217100217218
217101217219
if( zStmt==0 ){
217102217220
rc = SQLITE_NOMEM;
217103217221
}else{
217104217222
sqlite3_stmt *pStmt;
@@ -219611,11 +219729,10 @@
219611219729
** If the iterator currently points to an INSERT record, bind values from the
219612219730
** new.* record to the SELECT statement. Or, if it points to a DELETE or
219613219731
** UPDATE, bind values from the old.* record.
219614219732
*/
219615219733
static int sessionSeekToRow(
219616
- sqlite3 *db, /* Database handle */
219617219734
sqlite3_changeset_iter *pIter, /* Changeset iterator */
219618219735
u8 *abPK, /* Primary key flags array */
219619219736
sqlite3_stmt *pSelect /* SELECT statement from sessionSelectRow() */
219620219737
){
219621219738
int rc; /* Return code */
@@ -219741,11 +219858,11 @@
219741219858
assert( SQLITE_CHANGESET_CONFLICT+1==SQLITE_CHANGESET_CONSTRAINT );
219742219859
assert( SQLITE_CHANGESET_DATA+1==SQLITE_CHANGESET_NOTFOUND );
219743219860
219744219861
/* Bind the new.* PRIMARY KEY values to the SELECT statement. */
219745219862
if( pbReplace ){
219746
- rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
219863
+ rc = sessionSeekToRow(pIter, p->abPK, p->pSelect);
219747219864
}else{
219748219865
rc = SQLITE_OK;
219749219866
}
219750219867
219751219868
if( rc==SQLITE_ROW ){
@@ -219915,11 +220032,11 @@
219915220032
assert( op==SQLITE_INSERT );
219916220033
if( p->bStat1 ){
219917220034
/* Check if there is a conflicting row. For sqlite_stat1, this needs
219918220035
** to be done using a SELECT, as there is no PRIMARY KEY in the
219919220036
** database schema to throw an exception if a duplicate is inserted. */
219920
- rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
220037
+ rc = sessionSeekToRow(pIter, p->abPK, p->pSelect);
219921220038
if( rc==SQLITE_ROW ){
219922220039
rc = SQLITE_CONSTRAINT;
219923220040
sqlite3_reset(p->pSelect);
219924220041
}
219925220042
}
@@ -234981,11 +235098,11 @@
234981235098
i64 iLastRowid = 0;
234982235099
234983235100
/* Initialize a doclist-iterator for each input buffer. Arrange them in
234984235101
** a linked-list starting at pHead in ascending order of rowid. Avoid
234985235102
** linking any iterators already at EOF into the linked list at all. */
234986
- assert( nBuf+1<=sizeof(aMerger)/sizeof(aMerger[0]) );
235103
+ assert( nBuf+1<=(int)(sizeof(aMerger)/sizeof(aMerger[0])) );
234987235104
memset(aMerger, 0, sizeof(PrefixMerger)*(nBuf+1));
234988235105
pHead = &aMerger[nBuf];
234989235106
fts5DoclistIterInit(p1, &pHead->iter);
234990235107
for(i=0; i<nBuf; i++){
234991235108
fts5DoclistIterInit(&aBuf[i], &aMerger[i].iter);
@@ -236991,11 +237108,11 @@
236991237108
p->ts.eState = 1;
236992237109
p->ts.iSavepoint = -1;
236993237110
break;
236994237111
236995237112
case FTS5_SYNC:
236996
- assert( p->ts.eState==1 );
237113
+ assert( p->ts.eState==1 || p->ts.eState==2 );
236997237114
p->ts.eState = 2;
236998237115
break;
236999237116
237000237117
case FTS5_COMMIT:
237001237118
assert( p->ts.eState==2 );
@@ -237006,25 +237123,25 @@
237006237123
assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
237007237124
p->ts.eState = 0;
237008237125
break;
237009237126
237010237127
case FTS5_SAVEPOINT:
237011
- assert( p->ts.eState==1 );
237128
+ assert( p->ts.eState>=1 );
237012237129
assert( iSavepoint>=0 );
237013237130
assert( iSavepoint>=p->ts.iSavepoint );
237014237131
p->ts.iSavepoint = iSavepoint;
237015237132
break;
237016237133
237017237134
case FTS5_RELEASE:
237018
- assert( p->ts.eState==1 );
237135
+ assert( p->ts.eState>=1 );
237019237136
assert( iSavepoint>=0 );
237020237137
assert( iSavepoint<=p->ts.iSavepoint );
237021237138
p->ts.iSavepoint = iSavepoint-1;
237022237139
break;
237023237140
237024237141
case FTS5_ROLLBACKTO:
237025
- assert( p->ts.eState==1 );
237142
+ assert( p->ts.eState>=1 );
237026237143
assert( iSavepoint>=-1 );
237027237144
/* The following assert() can fail if another vtab strikes an error
237028237145
** within an xSavepoint() call then SQLite calls xRollbackTo() - without
237029237146
** having called xSavepoint() on this vtab. */
237030237147
/* assert( iSavepoint<=p->ts.iSavepoint ); */
@@ -238356,11 +238473,11 @@
238356238473
Fts5Config *pConfig = pTab->p.pConfig;
238357238474
int eType0; /* value_type() of apVal[0] */
238358238475
int rc = SQLITE_OK; /* Return code */
238359238476
238360238477
/* A transaction must be open when this is called. */
238361
- assert( pTab->ts.eState==1 );
238478
+ assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
238362238479
238363238480
assert( pVtab->zErrMsg==0 );
238364238481
assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
238365238482
assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
238366238483
|| sqlite3_value_type(apVal[0])==SQLITE_NULL
@@ -239524,11 +239641,11 @@
239524239641
int nArg, /* Number of args */
239525239642
sqlite3_value **apUnused /* Function arguments */
239526239643
){
239527239644
assert( nArg==0 );
239528239645
UNUSED_PARAM2(nArg, apUnused);
239529
- sqlite3_result_text(pCtx, "fts5: 2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389", -1, SQLITE_TRANSIENT);
239646
+ sqlite3_result_text(pCtx, "fts5: 2022-12-27 22:46:49 e8afad630b085a9208491e0516a6a30c9cda77a20b1aa2cba49b2f44eb9fa2f8", -1, SQLITE_TRANSIENT);
239530239647
}
239531239648
239532239649
/*
239533239650
** Return true if zName is the extension on one of the shadow tables used
239534239651
** by this module.
@@ -244262,10 +244379,14 @@
244262244379
#define STMT_COLUMN_REPREP 8 /* SQLITE_STMTSTATUS_REPREPARE */
244263244380
#define STMT_COLUMN_RUN 9 /* SQLITE_STMTSTATUS_RUN */
244264244381
#define STMT_COLUMN_MEM 10 /* SQLITE_STMTSTATUS_MEMUSED */
244265244382
244266244383
244384
+ (void)pAux;
244385
+ (void)argc;
244386
+ (void)argv;
244387
+ (void)pzErr;
244267244388
rc = sqlite3_declare_vtab(db,
244268244389
"CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
244269244390
"reprep,run,mem)");
244270244391
if( rc==SQLITE_OK ){
244271244392
pNew = sqlite3_malloc64( sizeof(*pNew) );
@@ -244381,10 +244502,14 @@
244381244502
stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
244382244503
sqlite3_stmt *p = 0;
244383244504
sqlite3_int64 iRowid = 1;
244384244505
StmtRow **ppRow = 0;
244385244506
244507
+ (void)idxNum;
244508
+ (void)idxStr;
244509
+ (void)argc;
244510
+ (void)argv;
244386244511
stmtCsrReset(pCur);
244387244512
ppRow = &pCur->pRow;
244388244513
for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
244389244514
const char *zSql = sqlite3_sql(p);
244390244515
sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
@@ -244436,10 +244561,11 @@
244436244561
*/
244437244562
static int stmtBestIndex(
244438244563
sqlite3_vtab *tab,
244439244564
sqlite3_index_info *pIdxInfo
244440244565
){
244566
+ (void)tab;
244441244567
pIdxInfo->estimatedCost = (double)500;
244442244568
pIdxInfo->estimatedRows = 500;
244443244569
return SQLITE_OK;
244444244570
}
244445244571
244446244572
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.41.0"
456 #define SQLITE_VERSION_NUMBER 3041000
457 #define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -3602,12 +3602,12 @@
3602 **
3603 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3604 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3605 ** information as is provided by the [sqlite3_profile()] callback.
3606 ** ^The P argument is a pointer to the [prepared statement] and the
3607 ** X argument points to a 64-bit integer which is the estimated of
3608 ** the number of nanosecond that the prepared statement took to run.
3609 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3610 **
3611 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3612 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3613 ** statement generates a single row of result.
@@ -14511,13 +14511,13 @@
14511 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
14512 ** underlying malloc() implementation might return us 4-byte aligned
14513 ** pointers. In that case, only verify 4-byte alignment.
14514 */
14515 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
14516 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
14517 #else
14518 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0)
14519 #endif
14520
14521 /*
14522 ** Disable MMAP on platforms where it is known to not work
14523 */
@@ -17683,10 +17683,11 @@
17683 #define SQLITE_AFF_BLOB 0x41 /* 'A' */
17684 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
17685 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
17686 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
17687 #define SQLITE_AFF_REAL 0x45 /* 'E' */
 
17688
17689 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
17690
17691 /*
17692 ** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -18238,10 +18239,13 @@
18238 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
18239 int iDistAddr; /* Address of OP_OpenEphemeral */
18240 } *aFunc;
18241 int nFunc; /* Number of entries in aFunc[] */
18242 u32 selId; /* Select to which this AggInfo belongs */
 
 
 
18243 };
18244
18245 /*
18246 ** Macros to compute aCol[] and aFunc[] register numbers.
18247 **
@@ -19078,14 +19082,14 @@
19078 # define DbMaskAllZero(M) sqlite3DbMaskAllZero(M)
19079 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
19080 #else
19081 typedef unsigned int yDbMask;
19082 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
19083 # define DbMaskZero(M) (M)=0
19084 # define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I))
19085 # define DbMaskAllZero(M) (M)==0
19086 # define DbMaskNonZero(M) (M)!=0
19087 #endif
19088
19089 /*
19090 ** For each index X that has as one of its arguments either an expression
19091 ** or the name of a virtual generated column, and if X is in scope such that
@@ -20654,11 +20658,11 @@
20654 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
20655 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
20656 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
20657
20658 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
20659 SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, int);
20660 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
20661 SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
20662 SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
20663 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
20664 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -22786,11 +22790,11 @@
22786
22787 Op *aOp; /* Space to hold the virtual machine's program */
22788 int nOp; /* Number of instructions in the program */
22789 int nOpAlloc; /* Slots allocated for aOp[] */
22790 Mem *aColName; /* Column names to return */
22791 Mem *pResultSet; /* Pointer to an array of results */
22792 char *zErrMsg; /* Error message written here */
22793 VList *pVList; /* Name of variables */
22794 #ifndef SQLITE_OMIT_TRACE
22795 i64 startTime; /* Time when query started - used for profiling */
22796 #endif
@@ -27328,13 +27332,17 @@
27328 int iFullSz;
27329 if( n<=mem5.szAtom*2 ){
27330 if( n<=mem5.szAtom ) return mem5.szAtom;
27331 return mem5.szAtom*2;
27332 }
27333 if( n>0x40000000 ) return 0;
 
 
 
 
27334 for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27335 if( (iFullSz/2)>=n ) return iFullSz/2;
27336 return iFullSz;
27337 }
27338
27339 /*
27340 ** Return the ceiling of the logarithm base 2 of iValue.
@@ -30600,17 +30608,30 @@
30600 buf[3] = 0x80 + (u8)(ch & 0x3f);
30601 length = 4;
30602 }
30603 }
30604 if( precision>1 ){
 
30605 width -= precision-1;
30606 if( width>1 && !flag_leftjustify ){
30607 sqlite3_str_appendchar(pAccum, width-1, ' ');
30608 width = 0;
30609 }
30610 while( precision-- > 1 ){
30611 sqlite3_str_append(pAccum, buf, length);
 
 
 
 
 
 
 
 
 
 
 
 
30612 }
30613 }
30614 bufpt = buf;
30615 flag_altform2 = 1;
30616 goto adjust_width_for_utf8;
@@ -30834,13 +30855,13 @@
30834 ** able to accept at least N more bytes of text.
30835 **
30836 ** Return the number of bytes of text that StrAccum is able to accept
30837 ** after the attempted enlargement. The value returned might be zero.
30838 */
30839 SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, int N){
30840 char *zNew;
30841 assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
30842 if( p->accError ){
30843 testcase(p->accError==SQLITE_TOOBIG);
30844 testcase(p->accError==SQLITE_NOMEM);
30845 return 0;
30846 }
@@ -30847,12 +30868,11 @@
30847 if( p->mxAlloc==0 ){
30848 sqlite3StrAccumSetError(p, SQLITE_TOOBIG);
30849 return p->nAlloc - p->nChar - 1;
30850 }else{
30851 char *zOld = isMalloced(p) ? p->zText : 0;
30852 i64 szNew = p->nChar;
30853 szNew += (sqlite3_int64)N + 1;
30854 if( szNew+p->nChar<=p->mxAlloc ){
30855 /* Force exponential buffer size growth as long as it does not overflow,
30856 ** to avoid having to call this routine too often */
30857 szNew += p->nChar;
30858 }
@@ -30878,11 +30898,12 @@
30878 sqlite3_str_reset(p);
30879 sqlite3StrAccumSetError(p, SQLITE_NOMEM);
30880 return 0;
30881 }
30882 }
30883 return N;
 
30884 }
30885
30886 /*
30887 ** Append N copies of character c to the given string buffer.
30888 */
@@ -51226,10 +51247,11 @@
51226 static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
51227 static int memdbTruncate(sqlite3_file*, sqlite3_int64 size);
51228 static int memdbSync(sqlite3_file*, int flags);
51229 static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize);
51230 static int memdbLock(sqlite3_file*, int);
 
51231 /* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */
51232 static int memdbFileControl(sqlite3_file*, int op, void *pArg);
51233 /* static int memdbSectorSize(sqlite3_file*); // not used */
51234 static int memdbDeviceCharacteristics(sqlite3_file*);
51235 static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
@@ -51284,11 +51306,11 @@
51284 memdbWrite, /* xWrite */
51285 memdbTruncate, /* xTruncate */
51286 memdbSync, /* xSync */
51287 memdbFileSize, /* xFileSize */
51288 memdbLock, /* xLock */
51289 memdbLock, /* xUnlock - same as xLock in this case */
51290 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
51291 memdbFileControl, /* xFileControl */
51292 0, /* memdbSectorSize,*/ /* xSectorSize */
51293 memdbDeviceCharacteristics, /* xDeviceCharacteristics */
51294 0, /* xShmMap */
@@ -51485,69 +51507,86 @@
51485 */
51486 static int memdbLock(sqlite3_file *pFile, int eLock){
51487 MemFile *pThis = (MemFile*)pFile;
51488 MemStore *p = pThis->pStore;
51489 int rc = SQLITE_OK;
51490 if( eLock==pThis->eLock ) return SQLITE_OK;
51491 memdbEnter(p);
51492 assert( p->nWrLock==0 || p->nWrLock==1 ); /* No more than 1 write lock */
51493 if( eLock>SQLITE_LOCK_SHARED ){
51494 assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51495 if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
51496 rc = SQLITE_READONLY;
51497 }else if( eLock==SQLITE_LOCK_EXCLUSIVE ){
51498 /* We never go for an EXCLUSIVE lock unless we already hold SHARED or
51499 ** higher */
51500 assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51501 testcase( pThis->eLock==SQLITE_LOCK_SHARED );
51502
51503 /* Because we are holding SHARED or more, there must be at least
51504 ** one read lock */
51505 assert( p->nRdLock>0 );
51506
51507 /* The only way that there can be an existing write lock is if we
51508 ** currently hold it. Otherwise, we would have never been able to
51509 ** promote from NONE to SHARED. */
51510 assert( p->nWrLock==0 || pThis->eLock>SQLITE_LOCK_SHARED );
51511
51512 if( p->nRdLock>1 ){
51513 /* Cannot take EXCLUSIVE if somebody else is holding SHARED */
51514 rc = SQLITE_BUSY;
51515 }else{
51516 p->nWrLock = 1;
51517 }
51518 }else if( ALWAYS(pThis->eLock<=SQLITE_LOCK_SHARED) ){
51519 /* Upgrading to RESERVED or PENDING from SHARED. Fail if any other
51520 ** client has a write-lock of any kind. */
51521 if( p->nWrLock ){
51522 rc = SQLITE_BUSY;
51523 }else{
51524 p->nWrLock = 1;
51525 }
51526 }
51527 }else if( eLock==SQLITE_LOCK_SHARED ){
51528 if( pThis->eLock > SQLITE_LOCK_SHARED ){
51529 assert( p->nWrLock==1 );
51530 p->nWrLock = 0;
51531 }else if( p->nWrLock ){
51532 rc = SQLITE_BUSY;
51533 }else{
51534 p->nRdLock++;
51535 }
51536 }else{
51537 assert( eLock==SQLITE_LOCK_NONE );
51538 if( pThis->eLock>SQLITE_LOCK_SHARED ){
51539 assert( p->nWrLock==1 );
51540 p->nWrLock = 0;
51541 }
51542 assert( p->nRdLock>0 );
51543 p->nRdLock--;
51544 }
51545 if( rc==SQLITE_OK ) pThis->eLock = eLock;
51546 memdbLeave(p);
51547 return rc;
51548 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51549
51550 #if 0
51551 /*
51552 ** This interface is only used for crash recovery, which does not
51553 ** occur on an in-memory database.
@@ -51652,11 +51691,11 @@
51652 int szName;
51653 UNUSED_PARAMETER(pVfs);
51654
51655 memset(pFile, 0, sizeof(*pFile));
51656 szName = sqlite3Strlen30(zName);
51657 if( szName>1 && zName[0]=='/' ){
51658 int i;
51659 #ifndef SQLITE_MUTEX_OMIT
51660 sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
51661 #endif
51662 sqlite3_mutex_enter(pVfsMutex);
@@ -82354,10 +82393,12 @@
82354 ** sqlite3MisuseError(lineno)
82355 ** sqlite3CantopenError(lineno)
82356 */
82357 static void test_addop_breakpoint(int pc, Op *pOp){
82358 static int n = 0;
 
 
82359 n++;
82360 }
82361 #endif
82362
82363 /*
@@ -84458,11 +84499,10 @@
84458 /* Even though this opcode does not use dynamic strings for
84459 ** the result, result columns may become dynamic if the user calls
84460 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
84461 */
84462 releaseMemArray(pMem, 8);
84463 p->pResultSet = 0;
84464
84465 if( p->rc==SQLITE_NOMEM ){
84466 /* This happens if a malloc() inside a call to sqlite3_column_text() or
84467 ** sqlite3_column_text16() failed. */
84468 sqlite3OomFault(db);
@@ -84515,11 +84555,11 @@
84515 sqlite3VdbeMemSetNull(pMem+7);
84516 #endif
84517 sqlite3VdbeMemSetStr(pMem+5, zP4, -1, SQLITE_UTF8, sqlite3_free);
84518 p->nResColumn = 8;
84519 }
84520 p->pResultSet = pMem;
84521 if( db->mallocFailed ){
84522 p->rc = SQLITE_NOMEM;
84523 rc = SQLITE_ERROR;
84524 }else{
84525 p->rc = SQLITE_OK;
@@ -85647,11 +85687,11 @@
85647 #endif
85648 if( p->zErrMsg ){
85649 sqlite3DbFree(db, p->zErrMsg);
85650 p->zErrMsg = 0;
85651 }
85652 p->pResultSet = 0;
85653 #ifdef SQLITE_DEBUG
85654 p->nWrite = 0;
85655 #endif
85656
85657 /* Save profiling information from this VDBE run.
@@ -88273,11 +88313,11 @@
88273 }else{
88274 #ifndef SQLITE_OMIT_TRACE
88275 /* If the statement completed successfully, invoke the profile callback */
88276 checkProfileCallback(db, p);
88277 #endif
88278
88279 if( rc==SQLITE_DONE && db->autoCommit ){
88280 assert( p->rc==SQLITE_OK );
88281 p->rc = doWalCallbacks(db);
88282 if( p->rc!=SQLITE_OK ){
88283 rc = SQLITE_ERROR;
@@ -88637,11 +88677,11 @@
88637 ** Return the number of values available from the current row of the
88638 ** currently executing statement pStmt.
88639 */
88640 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){
88641 Vdbe *pVm = (Vdbe *)pStmt;
88642 if( pVm==0 || pVm->pResultSet==0 ) return 0;
88643 return pVm->nResColumn;
88644 }
88645
88646 /*
88647 ** Return a pointer to static memory containing an SQL NULL value.
@@ -88692,12 +88732,12 @@
88692
88693 pVm = (Vdbe *)pStmt;
88694 if( pVm==0 ) return (Mem*)columnNullValue();
88695 assert( pVm->db );
88696 sqlite3_mutex_enter(pVm->db->mutex);
88697 if( pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
88698 pOut = &pVm->pResultSet[i];
88699 }else{
88700 sqlite3Error(pVm->db, SQLITE_RANGE);
88701 pOut = (Mem*)columnNullValue();
88702 }
88703 return pOut;
@@ -90122,10 +90162,13 @@
90122 ** sqlite3MisuseError(lineno)
90123 ** sqlite3CantopenError(lineno)
90124 */
90125 static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){
90126 static int n = 0;
 
 
 
90127 n++;
90128 }
90129 #endif
90130
90131 /*
@@ -90360,10 +90403,14 @@
90360 ** floating-point representation if an integer representation
90361 ** is not possible. Note that the integer representation is
90362 ** always preferred, even if the affinity is REAL, because
90363 ** an integer representation is more space efficient on disk.
90364 **
 
 
 
 
90365 ** SQLITE_AFF_TEXT:
90366 ** Convert pRec to a text representation.
90367 **
90368 ** SQLITE_AFF_BLOB:
90369 ** SQLITE_AFF_NONE:
@@ -90374,15 +90421,15 @@
90374 char affinity, /* The affinity to be applied */
90375 u8 enc /* Use this text encoding */
90376 ){
90377 if( affinity>=SQLITE_AFF_NUMERIC ){
90378 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
90379 || affinity==SQLITE_AFF_NUMERIC );
90380 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
90381 if( (pRec->flags & MEM_Real)==0 ){
90382 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
90383 }else{
90384 sqlite3VdbeIntegerAffinity(pRec);
90385 }
90386 }
90387 }else if( affinity==SQLITE_AFF_TEXT ){
90388 /* Only attempt the conversion to TEXT if there is an integer or real
@@ -90698,10 +90745,11 @@
90698 Op *aOp = p->aOp; /* Copy of p->aOp */
90699 Op *pOp = aOp; /* Current operation */
90700 #ifdef SQLITE_DEBUG
90701 Op *pOrigOp; /* Value of pOp at the top of the loop */
90702 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
 
90703 #endif
90704 int rc = SQLITE_OK; /* Value to return */
90705 sqlite3 *db = p->db; /* The database */
90706 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
90707 u8 encoding = ENC(db); /* The database encoding */
@@ -90719,11 +90767,13 @@
90719 u64 *pnCycle = 0;
90720 #endif
90721 /*** INSERT STACK UNION HERE ***/
90722
90723 assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
90724 sqlite3VdbeEnter(p);
 
 
90725 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
90726 if( db->xProgress ){
90727 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
90728 assert( 0 < db->nProgressOps );
90729 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
@@ -90740,11 +90790,10 @@
90740 testcase( p->rc!=SQLITE_OK );
90741 p->rc = SQLITE_OK;
90742 assert( p->bIsReader || p->readOnly!=0 );
90743 p->iCurrentTime = 0;
90744 assert( p->explain==0 );
90745 p->pResultSet = 0;
90746 db->busyHandler.nBusy = 0;
90747 if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
90748 sqlite3VdbeIOTraceSql(p);
90749 #ifdef SQLITE_DEBUG
90750 sqlite3BeginBenignMalloc();
@@ -91571,14 +91620,14 @@
91571 assert( p->nResColumn==pOp->p2 );
91572 assert( pOp->p1>0 || CORRUPT_DB );
91573 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
91574
91575 p->cacheCtr = (p->cacheCtr + 2)|1;
91576 p->pResultSet = &aMem[pOp->p1];
91577 #ifdef SQLITE_DEBUG
91578 {
91579 Mem *pMem = p->pResultSet;
91580 int i;
91581 for(i=0; i<pOp->p2; i++){
91582 assert( memIsValid(&pMem[i]) );
91583 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
91584 /* The registers in the result will not be used again when the
@@ -92111,22 +92160,25 @@
92111 if( sqlite3aGTb[pOp->opcode] ){
92112 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92113 goto jump_to_p2;
92114 }
92115 iCompare = +1;
 
92116 }else if( pIn3->u.i < pIn1->u.i ){
92117 if( sqlite3aLTb[pOp->opcode] ){
92118 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92119 goto jump_to_p2;
92120 }
92121 iCompare = -1;
 
92122 }else{
92123 if( sqlite3aEQb[pOp->opcode] ){
92124 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92125 goto jump_to_p2;
92126 }
92127 iCompare = 0;
 
92128 }
92129 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92130 break;
92131 }
92132 if( (flags1 | flags3)&MEM_Null ){
@@ -92154,10 +92206,11 @@
92154 VdbeBranchTaken(2,3);
92155 if( pOp->p5 & SQLITE_JUMPIFNULL ){
92156 goto jump_to_p2;
92157 }
92158 iCompare = 1; /* Operands are not equal */
 
92159 break;
92160 }
92161 }else{
92162 /* Neither operand is NULL and we couldn't do the special high-speed
92163 ** integer comparison case. So do a general-case comparison. */
@@ -92179,11 +92232,11 @@
92179 testcase( pIn1->flags & MEM_Real );
92180 testcase( pIn1->flags & MEM_IntReal );
92181 sqlite3VdbeMemStringify(pIn1, encoding, 1);
92182 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
92183 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
92184 if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
92185 }
92186 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
92187 testcase( pIn3->flags & MEM_Int );
92188 testcase( pIn3->flags & MEM_Real );
92189 testcase( pIn3->flags & MEM_IntReal );
@@ -92210,10 +92263,11 @@
92210 res2 = sqlite3aEQb[pOp->opcode];
92211 }else{
92212 res2 = sqlite3aGTb[pOp->opcode];
92213 }
92214 iCompare = res;
 
92215
92216 /* Undo any changes made by applyAffinity() to the input registers. */
92217 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
92218 pIn3->flags = flags3;
92219 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
@@ -92248,10 +92302,11 @@
92248 if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
92249 assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
92250 break;
92251 }
92252 #endif /* SQLITE_DEBUG */
 
92253 VdbeBranchTaken(iCompare==0, 2);
92254 if( iCompare==0 ) goto jump_to_p2;
92255 break;
92256 }
92257
@@ -92342,10 +92397,11 @@
92342 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
92343 assert( i<pKeyInfo->nKeyField );
92344 pColl = pKeyInfo->aColl[i];
92345 bRev = (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC);
92346 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
 
92347 if( iCompare ){
92348 if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
92349 && ((aMem[p1+idx].flags & MEM_Null) || (aMem[p2+idx].flags & MEM_Null))
92350 ){
92351 iCompare = -iCompare;
@@ -92366,10 +92422,11 @@
92366 **
92367 ** This opcode must immediately follow an OP_Compare opcode.
92368 */
92369 case OP_Jump: { /* jump */
92370 assert( pOp>aOp && pOp[-1].opcode==OP_Compare );
 
92371 if( iCompare<0 ){
92372 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
92373 }else if( iCompare==0 ){
92374 VdbeBranchTaken(1,4); pOp = &aOp[pOp->p2 - 1];
92375 }else{
@@ -95544,12 +95601,15 @@
95544 }
95545 }
95546 if( pOp->p5 & OPFLAG_ISNOOP ) break;
95547 #endif
95548
95549 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
95550 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
 
 
 
95551 assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
95552 x.pData = pData->z;
95553 x.nData = pData->n;
95554 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
95555 if( pData->flags & MEM_Zero ){
@@ -98812,11 +98872,13 @@
98812 goto abort_due_to_error;
98813 }
98814 }
98815 #endif
98816 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
98817 sqlite3VdbeLeave(p);
 
 
98818 assert( rc!=SQLITE_OK || nExtraDelete==0
98819 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
98820 );
98821 return rc;
98822
@@ -102219,10 +102281,13 @@
102219 "subprog TEXT,"
102220 "stmt HIDDEN"
102221 ");"
102222 };
102223
 
 
 
102224 rc = sqlite3_declare_vtab(db, azSchema[isTabUsed]);
102225 if( rc==SQLITE_OK ){
102226 pNew = sqlite3_malloc( sizeof(*pNew) );
102227 *ppVtab = (sqlite3_vtab*)pNew;
102228 if( pNew==0 ) return SQLITE_NOMEM;
@@ -102454,10 +102519,11 @@
102454 int argc, sqlite3_value **argv
102455 ){
102456 bytecodevtab_cursor *pCur = (bytecodevtab_cursor *)pVtabCursor;
102457 bytecodevtab *pVTab = (bytecodevtab *)pVtabCursor->pVtab;
102458 int rc = SQLITE_OK;
 
102459
102460 bytecodevtabCursorClear(pCur);
102461 pCur->iRowid = 0;
102462 pCur->iAddr = 0;
102463 pCur->showSubprograms = idxNum==0;
@@ -109654,11 +109720,11 @@
109654 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
109655 assert( ExprUseYTab(pExpr) );
109656 assert( pExpr->y.pTab!=0 );
109657 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
109658 if( aff>SQLITE_AFF_BLOB ){
109659 static const char zAff[] = "B\000C\000D\000E";
109660 assert( SQLITE_AFF_BLOB=='A' );
109661 assert( SQLITE_AFF_TEXT=='B' );
109662 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
109663 &zAff[(aff-'B')*2], P4_STATIC);
109664 }
@@ -111651,14 +111717,12 @@
111651 ** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
111652 ** object that is referenced does not refer directly to the Expr. If
111653 ** it does, make a copy. This is done because the pExpr argument is
111654 ** subject to change.
111655 **
111656 ** The copy is stored on pParse->pConstExpr with a register number of 0.
111657 ** This will cause the expression to be deleted automatically when the
111658 ** Parse object is destroyed, but the zero register number means that it
111659 ** will not generate any code in the preamble.
111660 */
111661 static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
111662 if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
111663 && pExpr->pAggInfo!=0
111664 ){
@@ -111665,11 +111729,10 @@
111665 AggInfo *pAggInfo = pExpr->pAggInfo;
111666 int iAgg = pExpr->iAgg;
111667 Parse *pParse = pWalker->pParse;
111668 sqlite3 *db = pParse->db;
111669 if( pExpr->op!=TK_AGG_FUNCTION ){
111670 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_IF_NULL_ROW );
111671 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
111672 if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
111673 pExpr = sqlite3ExprDup(db, pExpr, 0);
111674 if( pExpr ){
111675 pAggInfo->aCol[iAgg].pCExpr = pExpr;
@@ -111791,10 +111854,11 @@
111791 if( pCol->iSorterColumn<0 ){
111792 pCol->iSorterColumn = pAggInfo->nSortingColumn++;
111793 }
111794 fix_up_expr:
111795 ExprSetVVAProperty(pExpr, EP_NoReduce);
 
111796 pExpr->pAggInfo = pAggInfo;
111797 if( pExpr->op==TK_COLUMN ){
111798 pExpr->op = TK_AGG_COLUMN;
111799 }
111800 pExpr->iAgg = (i16)k;
@@ -111826,10 +111890,11 @@
111826 if( iDataCur<0 ) continue;
111827 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
111828 }
111829 if( pIEpr==0 ) break;
111830 if( NEVER(!ExprUseYTab(pExpr)) ) break;
 
111831
111832 /* If we reach this point, it means that expression pExpr can be
111833 ** translated into a reference to an index column as described by
111834 ** pIEpr.
111835 */
@@ -112780,17 +112845,18 @@
112780 static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
112781 assert( pParse==pParse->db->pParse );
112782 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
112783 if( pParse->nErr==0 ){
112784 const RenameToken *p;
112785 u8 i = 0;
112786 for(p=pParse->pRename; p; p=p->pNext){
112787 if( p->p ){
112788 assert( p->p!=pPtr );
112789 i += *(u8*)(p->p);
112790 }
112791 }
 
112792 }
112793 }
112794 #else
112795 # define renameTokenCheckAll(x,y)
112796 #endif
@@ -117442,10 +117508,11 @@
117442 sqlite3 *db = pParse->db;
117443 u32 savedDbFlags = db->mDbFlags;
117444 char saveBuf[PARSE_TAIL_SZ];
117445
117446 if( pParse->nErr ) return;
 
117447 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
117448 va_start(ap, zFormat);
117449 zSql = sqlite3VMPrintf(db, zFormat, ap);
117450 va_end(ap);
117451 if( zSql==0 ){
@@ -119139,10 +119206,17 @@
119139 assert( TF_HasStored==COLFLAG_STORED );
119140 pTab->tabFlags |= eType;
119141 if( pCol->colFlags & COLFLAG_PRIMKEY ){
119142 makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
119143 }
 
 
 
 
 
 
 
119144 sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
119145 pExpr = 0;
119146 goto generated_done;
119147
119148 generated_error:
@@ -119275,11 +119349,12 @@
119275 static const char * const azType[] = {
119276 /* SQLITE_AFF_BLOB */ "",
119277 /* SQLITE_AFF_TEXT */ " TEXT",
119278 /* SQLITE_AFF_NUMERIC */ " NUM",
119279 /* SQLITE_AFF_INTEGER */ " INT",
119280 /* SQLITE_AFF_REAL */ " REAL"
 
119281 };
119282 int len;
119283 const char *zType;
119284
119285 sqlite3_snprintf(n-k, &zStmt[k], zSep);
@@ -119291,14 +119366,16 @@
119291 testcase( pCol->affinity==SQLITE_AFF_BLOB );
119292 testcase( pCol->affinity==SQLITE_AFF_TEXT );
119293 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
119294 testcase( pCol->affinity==SQLITE_AFF_INTEGER );
119295 testcase( pCol->affinity==SQLITE_AFF_REAL );
 
119296
119297 zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
119298 len = sqlite3Strlen30(zType);
119299 assert( pCol->affinity==SQLITE_AFF_BLOB
 
119300 || pCol->affinity==sqlite3AffinityType(zType, 0) );
119301 memcpy(&zStmt[k], zType, len);
119302 k += len;
119303 assert( k<=n );
119304 }
@@ -119709,10 +119786,11 @@
119709 ** they should not be changed. Expressions attached to a table or
119710 ** index definition are tagged this way to help ensure that we do
119711 ** not pass them into code generator routines by mistake.
119712 */
119713 static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){
 
119714 ExprSetVVAProperty(pExpr, EP_Immutable);
119715 return WRC_Continue;
119716 }
119717 static void markExprListImmutable(ExprList *pList){
119718 if( pList ){
@@ -125459,11 +125537,11 @@
125459 sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue));
125460 break;
125461 }
125462 case SQLITE_BLOB: {
125463 char const *zBlob = sqlite3_value_blob(pValue);
125464 int nBlob = sqlite3_value_bytes(pValue);
125465 assert( zBlob==sqlite3_value_blob(pValue) ); /* No encoding change */
125466 sqlite3StrAccumEnlarge(pStr, nBlob*2 + 4);
125467 if( pStr->accError==0 ){
125468 char *zText = pStr->zText;
125469 int i;
@@ -125817,10 +125895,13 @@
125817 sqlite3_context *context,
125818 int argc,
125819 sqlite3_value **argv
125820 ){
125821 /* no-op */
 
 
 
125822 }
125823 #endif /*SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION*/
125824
125825
125826 /* IMP: R-25361-16150 This function is omitted from SQLite by default. It
@@ -126560,10 +126641,11 @@
126560 sqlite3_context *context,
126561 int argc,
126562 sqlite3_value **argv
126563 ){
126564 assert( argc==0 );
 
126565 sqlite3_result_double(context, M_PI);
126566 }
126567
126568 #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
126569
@@ -139645,11 +139727,11 @@
139645 ** database table or a subquery.
139646 */
139647 Table *pTab = 0; /* Table structure column is extracted from */
139648 Select *pS = 0; /* Select the column is extracted from */
139649 int iCol = pExpr->iColumn; /* Index of column in pTab */
139650 while( pNC && !pTab ){
139651 SrcList *pTabList = pNC->pSrcList;
139652 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
139653 if( j<pTabList->nSrc ){
139654 pTab = pTabList->a[j].pTab;
139655 pS = pTabList->a[j].pSelect;
@@ -139656,11 +139738,11 @@
139656 }else{
139657 pNC = pNC->pNext;
139658 }
139659 }
139660
139661 if( pTab==0 ){
139662 /* At one time, code such as "SELECT new.x" within a trigger would
139663 ** cause this condition to run. Since then, we have restructured how
139664 ** trigger code is generated and so this condition is no longer
139665 ** possible. However, it can still be true for statements like
139666 ** the following:
@@ -140032,18 +140114,10 @@
140032 return SQLITE_NOMEM_BKPT;
140033 }
140034 return SQLITE_OK;
140035 }
140036
140037 /*
140038 ** This bit, when added to the "aff" parameter of
140039 ** sqlite3ColumnTypeOfSubquery() means that result set
140040 ** expressions of the form "CAST(expr AS NUMERIC)" should result in
140041 ** NONE affinity rather than NUMERIC affinity.
140042 */
140043 #define SQLITE_AFF_FLAG1 0x10
140044
140045 /*
140046 ** pTab is a transient Table object that represents a subquery of some
140047 ** kind (maybe a parenthesized subquery in the FROM clause of a larger
140048 ** query, or a VIEW, or a CTE). This routine computes type information
140049 ** for that Table object based on the Select object that implements the
@@ -140050,21 +140124,16 @@
140050 ** subquery. For the purposes of this routine, "type infomation" means:
140051 **
140052 ** * The datatype name, as it might appear in a CREATE TABLE statement
140053 ** * Which collating sequence to use for the column
140054 ** * The affinity of the column
140055 **
140056 ** The SQLITE_AFF_FLAG1 bit added to parameter aff means that a
140057 ** result set column of the form "CAST(expr AS NUMERIC)" should use
140058 ** NONE affinity rather than NUMERIC affinity. See the
140059 ** 2022-12-10 "reopen" of ticket https://sqlite.org/src/tktview/57c47526c3.
140060 */
140061 SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140062 Parse *pParse, /* Parsing contexts */
140063 Table *pTab, /* Add column type information to this table */
140064 Select *pSelect, /* SELECT used to determine types and collations */
140065 char aff /* Default affinity. Maybe with SQLITE_AFF_FLAG1 too */
140066 ){
140067 sqlite3 *db = pParse->db;
140068 Column *pCol;
140069 CollSeq *pColl;
140070 int i,j;
@@ -140072,10 +140141,11 @@
140072 struct ExprList_item *a;
140073
140074 assert( pSelect!=0 );
140075 assert( (pSelect->selFlags & SF_Resolved)!=0 );
140076 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
 
140077 if( db->mallocFailed ) return;
140078 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
140079 a = pSelect->pEList->a;
140080 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140081 const char *zType;
@@ -140083,17 +140153,13 @@
140083 pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140084 p = a[i].pExpr;
140085 /* pCol->szEst = ... // Column size est for SELECT tables never used */
140086 pCol->affinity = sqlite3ExprAffinity(p);
140087 if( pCol->affinity<=SQLITE_AFF_NONE ){
140088 assert( (SQLITE_AFF_FLAG1 & SQLITE_AFF_MASK)==0 );
140089 pCol->affinity = aff & SQLITE_AFF_MASK;
140090 }
140091 if( aff & SQLITE_AFF_FLAG1 ){
140092 if( pCol->affinity==SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140093 pCol->affinity = SQLITE_AFF_NONE;
140094 }
140095 }
140096 if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140097 int m = 0;
140098 Select *pS2;
140099 for(m=0, pS2=pSelect->pNext; pS2; pS2=pS2->pNext){
@@ -140104,11 +140170,13 @@
140104 }else
140105 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140106 pCol->affinity = SQLITE_AFF_BLOB;
140107 }
140108 }
140109 if( pCol->affinity==SQLITE_AFF_NUMERIC ){
 
 
140110 zType = "NUM";
140111 }else{
140112 zType = 0;
140113 for(j=1; j<SQLITE_N_STDTYPE; j++){
140114 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
@@ -143998,12 +144066,11 @@
143998 assert( pTab!=0 );
143999 if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
144000 /* A sub-query in the FROM clause of a SELECT */
144001 Select *pSel = pFrom->pSelect;
144002 if( pSel ){
144003 sqlite3SubqueryColumnTypes(pParse, pTab, pSel,
144004 SQLITE_AFF_NONE|SQLITE_AFF_FLAG1);
144005 }
144006 }
144007 }
144008 }
144009 #endif
@@ -144073,11 +144140,11 @@
144073 ii>=pAggInfo->nAccumulator ? "" : " Accumulator");
144074 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
144075 }
144076 for(ii=0; ii<pAggInfo->nFunc; ii++){
144077 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
144078 ii, AggInfoFuncReg(pAggInfo,ii));
144079 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
144080 }
144081 }
144082 #endif /* TREETRACE_ENABLED */
144083
@@ -145444,10 +145511,13 @@
145444 }
145445 if( db->mallocFailed ){
145446 goto select_end;
145447 }
145448 pAggInfo->selId = p->selId;
 
 
 
145449 memset(&sNC, 0, sizeof(sNC));
145450 sNC.pParse = pParse;
145451 sNC.pSrcList = pTabList;
145452 sNC.uNC.pAggInfo = pAggInfo;
145453 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
@@ -162038,10 +162108,16 @@
162038 }
162039 if( sqlite3ExprIsConstant(pExpr) ) continue;
162040 p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
162041 if( p==0 ) break;
162042 p->pIENext = pParse->pIdxEpr;
 
 
 
 
 
 
162043 p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
162044 p->iDataCur = pTabItem->iCursor;
162045 p->iIdxCur = iIdxCur;
162046 p->iIdxCol = i;
162047 p->bMaybeNullRow = bMaybeNullRow;
@@ -163000,10 +163076,17 @@
163000 }
163001 if( pIdx->bHasExpr ){
163002 IndexedExpr *p = pParse->pIdxEpr;
163003 while( p ){
163004 if( p->iIdxCur==pLevel->iIdxCur ){
 
 
 
 
 
 
 
163005 p->iDataCur = -1;
163006 p->iIdxCur = -1;
163007 }
163008 p = p->pIENext;
163009 }
@@ -201354,11 +201437,11 @@
201354 */
201355 static int readInt16(u8 *p){
201356 return (p[0]<<8) + p[1];
201357 }
201358 static void readCoord(u8 *p, RtreeCoord *pCoord){
201359 assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
201360 #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
201361 pCoord->u = _byteswap_ulong(*(u32*)p);
201362 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
201363 pCoord->u = __builtin_bswap32(*(u32*)p);
201364 #elif SQLITE_BYTEORDER==4321
@@ -201408,11 +201491,11 @@
201408 p[0] = (i>> 8)&0xFF;
201409 p[1] = (i>> 0)&0xFF;
201410 }
201411 static int writeCoord(u8 *p, RtreeCoord *pCoord){
201412 u32 i;
201413 assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
201414 assert( sizeof(RtreeCoord)==4 );
201415 assert( sizeof(u32)==4 );
201416 #if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
201417 i = __builtin_bswap32(pCoord->u);
201418 memcpy(p, &i, 4);
@@ -202136,11 +202219,11 @@
202136 pCellData += 8 + 4*(p->iCoord&0xfe);
202137
202138 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
202139 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
202140 || p->op==RTREE_FALSE );
202141 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
202142 switch( p->op ){
202143 case RTREE_TRUE: return; /* Always satisfied */
202144 case RTREE_FALSE: break; /* Never satisfied */
202145 case RTREE_EQ:
202146 RTREE_DECODE_COORD(eInt, pCellData, val);
@@ -202189,11 +202272,11 @@
202189
202190 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
202191 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
202192 || p->op==RTREE_FALSE );
202193 pCellData += 8 + p->iCoord*4;
202194 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
202195 RTREE_DECODE_COORD(eInt, pCellData, xN);
202196 switch( p->op ){
202197 case RTREE_TRUE: return; /* Always satisfied */
202198 case RTREE_FALSE: break; /* Never satisfied */
202199 case RTREE_LE: if( xN <= p->u.rValue ) return; break;
@@ -205561,11 +205644,11 @@
205561 ){
205562 GeoPoly *p = 0;
205563 int nByte;
205564 testcase( pCtx==0 );
205565 if( sqlite3_value_type(pVal)==SQLITE_BLOB
205566 && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord))
205567 ){
205568 const unsigned char *a = sqlite3_value_blob(pVal);
205569 int nVertex;
205570 if( a==0 ){
205571 if( pCtx ) sqlite3_result_error_nomem(pCtx);
@@ -205619,10 +205702,11 @@
205619 sqlite3_context *context,
205620 int argc,
205621 sqlite3_value **argv
205622 ){
205623 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
 
205624 if( p ){
205625 sqlite3_result_blob(context, p->hdr,
205626 4+8*p->nVertex, SQLITE_TRANSIENT);
205627 sqlite3_free(p);
205628 }
@@ -205638,10 +205722,11 @@
205638 sqlite3_context *context,
205639 int argc,
205640 sqlite3_value **argv
205641 ){
205642 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
 
205643 if( p ){
205644 sqlite3 *db = sqlite3_context_db_handle(context);
205645 sqlite3_str *x = sqlite3_str_new(db);
205646 int i;
205647 sqlite3_str_append(x, "[", 1);
@@ -205719,10 +205804,11 @@
205719 double D = sqlite3_value_double(argv[4]);
205720 double E = sqlite3_value_double(argv[5]);
205721 double F = sqlite3_value_double(argv[6]);
205722 GeoCoord x1, y1, x0, y0;
205723 int ii;
 
205724 if( p ){
205725 for(ii=0; ii<p->nVertex; ii++){
205726 x0 = GeoX(p,ii);
205727 y0 = GeoY(p,ii);
205728 x1 = (GeoCoord)(A*x0 + B*y0 + E);
@@ -205769,10 +205855,11 @@
205769 sqlite3_context *context,
205770 int argc,
205771 sqlite3_value **argv
205772 ){
205773 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
 
205774 if( p ){
205775 sqlite3_result_double(context, geopolyArea(p));
205776 sqlite3_free(p);
205777 }
205778 }
@@ -205794,10 +205881,11 @@
205794 sqlite3_context *context,
205795 int argc,
205796 sqlite3_value **argv
205797 ){
205798 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
 
205799 if( p ){
205800 if( geopolyArea(p)<0.0 ){
205801 int ii, jj;
205802 for(ii=1, jj=p->nVertex-1; ii<jj; ii++, jj--){
205803 GeoCoord t = GeoX(p,ii);
@@ -205848,10 +205936,11 @@
205848 double y = sqlite3_value_double(argv[1]);
205849 double r = sqlite3_value_double(argv[2]);
205850 int n = sqlite3_value_int(argv[3]);
205851 int i;
205852 GeoPoly *p;
 
205853
205854 if( n<3 || r<=0.0 ) return;
205855 if( n>1000 ) n = 1000;
205856 p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) );
205857 if( p==0 ){
@@ -205957,10 +206046,11 @@
205957 sqlite3_context *context,
205958 int argc,
205959 sqlite3_value **argv
205960 ){
205961 GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
 
205962 if( p ){
205963 sqlite3_result_blob(context, p->hdr,
205964 4+8*p->nVertex, SQLITE_TRANSIENT);
205965 sqlite3_free(p);
205966 }
@@ -205984,10 +206074,11 @@
205984 int argc,
205985 sqlite3_value **argv
205986 ){
205987 RtreeCoord a[4];
205988 int rc = SQLITE_OK;
 
205989 (void)geopolyBBox(context, argv[0], a, &rc);
205990 if( rc==SQLITE_OK ){
205991 GeoBBox *pBBox;
205992 pBBox = (GeoBBox*)sqlite3_aggregate_context(context, sizeof(*pBBox));
205993 if( pBBox==0 ) return;
@@ -206072,10 +206163,12 @@
206072 double x0 = sqlite3_value_double(argv[1]);
206073 double y0 = sqlite3_value_double(argv[2]);
206074 int v = 0;
206075 int cnt = 0;
206076 int ii;
 
 
206077 if( p1==0 ) return;
206078 for(ii=0; ii<p1->nVertex-1; ii++){
206079 v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
206080 GeoX(p1,ii+1),GeoY(p1,ii+1));
206081 if( v==2 ) break;
@@ -206111,10 +206204,11 @@
206111 int argc,
206112 sqlite3_value **argv
206113 ){
206114 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
206115 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
 
206116 if( p1 && p2 ){
206117 int x = geopolyOverlap(p1, p2);
206118 if( x<0 ){
206119 sqlite3_result_error_nomem(context);
206120 }else{
@@ -206441,10 +206535,11 @@
206441 int argc,
206442 sqlite3_value **argv
206443 ){
206444 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
206445 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
 
206446 if( p1 && p2 ){
206447 int x = geopolyOverlap(p1, p2);
206448 if( x<0 ){
206449 sqlite3_result_error_nomem(context);
206450 }else{
@@ -206461,12 +206556,16 @@
206461 static void geopolyDebugFunc(
206462 sqlite3_context *context,
206463 int argc,
206464 sqlite3_value **argv
206465 ){
 
 
206466 #ifdef GEOPOLY_ENABLE_DEBUG
206467 geo_debug = sqlite3_value_int(argv[0]);
 
 
206468 #endif
206469 }
206470
206471 /*
206472 ** This function is the implementation of both the xConnect and xCreate
@@ -206490,10 +206589,11 @@
206490 sqlite3_int64 nDb; /* Length of string argv[1] */
206491 sqlite3_int64 nName; /* Length of string argv[2] */
206492 sqlite3_str *pSql;
206493 char *zSql;
206494 int ii;
 
206495
206496 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
206497
206498 /* Allocate the sqlite3_vtab structure */
206499 nDb = strlen(argv[1]);
@@ -206606,10 +206706,11 @@
206606 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
206607 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
206608 RtreeNode *pRoot = 0;
206609 int rc = SQLITE_OK;
206610 int iCell = 0;
 
206611
206612 rtreeReference(pRtree);
206613
206614 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
206615 resetCursor(pCsr);
@@ -206732,10 +206833,11 @@
206732 static int geopolyBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
206733 int ii;
206734 int iRowidTerm = -1;
206735 int iFuncTerm = -1;
206736 int idxNum = 0;
 
206737
206738 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
206739 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
206740 if( !p->usable ) continue;
206741 if( p->iColumn<0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
@@ -206978,10 +207080,12 @@
206978 int nArg,
206979 const char *zName,
206980 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
206981 void **ppArg
206982 ){
 
 
206983 if( sqlite3_stricmp(zName, "geopoly_overlap")==0 ){
206984 *pxFunc = geopolyOverlapFunc;
206985 *ppArg = 0;
206986 return SQLITE_INDEX_CONSTRAINT_FUNCTION;
206987 }
@@ -207047,11 +207151,11 @@
207047 void (*xFinal)(sqlite3_context*);
207048 const char *zName;
207049 } aAgg[] = {
207050 { geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" },
207051 };
207052 int i;
207053 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
207054 int enc;
207055 if( aFunc[i].bPure ){
207056 enc = SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS;
207057 }else{
@@ -214254,10 +214358,11 @@
214254 char **pzErr
214255 ){
214256 StatTable *pTab = 0;
214257 int rc = SQLITE_OK;
214258 int iDb;
 
214259
214260 if( argc>=4 ){
214261 Token nm;
214262 sqlite3TokenInit(&nm, (char*)argv[3]);
214263 iDb = sqlite3FindDb(db, &nm);
@@ -214307,10 +214412,11 @@
214307 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
214308 int i;
214309 int iSchema = -1;
214310 int iName = -1;
214311 int iAgg = -1;
 
214312
214313 /* Look for a valid schema=? constraint. If found, change the idxNum to
214314 ** 1 and request the value of that constraint be sent to xFilter. And
214315 ** lower the cost estimate to encourage the constrained version to be
214316 ** used.
@@ -214832,10 +214938,12 @@
214832 sqlite3_str *pSql; /* Query of btrees to analyze */
214833 char *zSql; /* String value of pSql */
214834 int iArg = 0; /* Count of argv[] parameters used so far */
214835 int rc = SQLITE_OK; /* Result of this operation */
214836 const char *zName = 0; /* Only provide analysis of this table */
 
 
214837
214838 statResetCsr(pCsr);
214839 sqlite3_finalize(pCsr->pStmt);
214840 pCsr->pStmt = 0;
214841 if( idxNum & 0x01 ){
@@ -215066,10 +215174,14 @@
215066 sqlite3_vtab **ppVtab,
215067 char **pzErr
215068 ){
215069 DbpageTable *pTab = 0;
215070 int rc = SQLITE_OK;
 
 
 
 
215071
215072 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
215073 rc = sqlite3_declare_vtab(db,
215074 "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
215075 if( rc==SQLITE_OK ){
@@ -215104,10 +215216,11 @@
215104 ** 3 schema=?1, pgno=?2
215105 */
215106 static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
215107 int i;
215108 int iPlan = 0;
 
215109
215110 /* If there is a schema= constraint, it must be honored. Report a
215111 ** ridiculously large estimated cost if the schema= constraint is
215112 ** unavailable
215113 */
@@ -215218,10 +215331,12 @@
215218 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
215219 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
215220 int rc;
215221 sqlite3 *db = pTab->db;
215222 Btree *pBt;
 
 
215223
215224 /* Default setting is no rows of result */
215225 pCsr->pgno = 1;
215226 pCsr->mxPgno = 0;
215227
@@ -215314,10 +215429,11 @@
215314 int iDb;
215315 Btree *pBt;
215316 Pager *pPager;
215317 int szPage;
215318
 
215319 if( pTab->db->flags & SQLITE_Defensive ){
215320 zErr = "read-only";
215321 goto update_fail;
215322 }
215323 if( argc==1 ){
@@ -216921,10 +217037,12 @@
216921 ){
216922 sqlite3_session *pSession;
216923 int nDb = sqlite3Strlen30(zDb);
216924
216925 assert( sqlite3_mutex_held(db->mutex) );
 
 
216926
216927 for(pSession=(sqlite3_session *)pCtx; pSession; pSession=pSession->pNext){
216928 SessionTable *pTab;
216929
216930 /* If this session is attached to a different database ("main", "temp"
@@ -216997,10 +217115,11 @@
216997 static int sessionDiffCount(void *pCtx){
216998 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
216999 return p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt);
217000 }
217001 static int sessionDiffDepth(void *pCtx){
 
217002 return 0;
217003 }
217004
217005 /*
217006 ** Install the diff hooks on the session object passed as the only
@@ -217070,11 +217189,10 @@
217070
217071 return zRet;
217072 }
217073
217074 static char *sessionSelectFindNew(
217075 int nCol,
217076 const char *zDb1, /* Pick rows in this db only */
217077 const char *zDb2, /* But not in this one */
217078 const char *zTbl, /* Table name */
217079 const char *zExpr
217080 ){
@@ -217094,11 +217212,11 @@
217094 const char *zDb1,
217095 const char *zDb2,
217096 char *zExpr
217097 ){
217098 int rc = SQLITE_OK;
217099 char *zStmt = sessionSelectFindNew(pTab->nCol, zDb1, zDb2, pTab->zName,zExpr);
217100
217101 if( zStmt==0 ){
217102 rc = SQLITE_NOMEM;
217103 }else{
217104 sqlite3_stmt *pStmt;
@@ -219611,11 +219729,10 @@
219611 ** If the iterator currently points to an INSERT record, bind values from the
219612 ** new.* record to the SELECT statement. Or, if it points to a DELETE or
219613 ** UPDATE, bind values from the old.* record.
219614 */
219615 static int sessionSeekToRow(
219616 sqlite3 *db, /* Database handle */
219617 sqlite3_changeset_iter *pIter, /* Changeset iterator */
219618 u8 *abPK, /* Primary key flags array */
219619 sqlite3_stmt *pSelect /* SELECT statement from sessionSelectRow() */
219620 ){
219621 int rc; /* Return code */
@@ -219741,11 +219858,11 @@
219741 assert( SQLITE_CHANGESET_CONFLICT+1==SQLITE_CHANGESET_CONSTRAINT );
219742 assert( SQLITE_CHANGESET_DATA+1==SQLITE_CHANGESET_NOTFOUND );
219743
219744 /* Bind the new.* PRIMARY KEY values to the SELECT statement. */
219745 if( pbReplace ){
219746 rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
219747 }else{
219748 rc = SQLITE_OK;
219749 }
219750
219751 if( rc==SQLITE_ROW ){
@@ -219915,11 +220032,11 @@
219915 assert( op==SQLITE_INSERT );
219916 if( p->bStat1 ){
219917 /* Check if there is a conflicting row. For sqlite_stat1, this needs
219918 ** to be done using a SELECT, as there is no PRIMARY KEY in the
219919 ** database schema to throw an exception if a duplicate is inserted. */
219920 rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
219921 if( rc==SQLITE_ROW ){
219922 rc = SQLITE_CONSTRAINT;
219923 sqlite3_reset(p->pSelect);
219924 }
219925 }
@@ -234981,11 +235098,11 @@
234981 i64 iLastRowid = 0;
234982
234983 /* Initialize a doclist-iterator for each input buffer. Arrange them in
234984 ** a linked-list starting at pHead in ascending order of rowid. Avoid
234985 ** linking any iterators already at EOF into the linked list at all. */
234986 assert( nBuf+1<=sizeof(aMerger)/sizeof(aMerger[0]) );
234987 memset(aMerger, 0, sizeof(PrefixMerger)*(nBuf+1));
234988 pHead = &aMerger[nBuf];
234989 fts5DoclistIterInit(p1, &pHead->iter);
234990 for(i=0; i<nBuf; i++){
234991 fts5DoclistIterInit(&aBuf[i], &aMerger[i].iter);
@@ -236991,11 +237108,11 @@
236991 p->ts.eState = 1;
236992 p->ts.iSavepoint = -1;
236993 break;
236994
236995 case FTS5_SYNC:
236996 assert( p->ts.eState==1 );
236997 p->ts.eState = 2;
236998 break;
236999
237000 case FTS5_COMMIT:
237001 assert( p->ts.eState==2 );
@@ -237006,25 +237123,25 @@
237006 assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
237007 p->ts.eState = 0;
237008 break;
237009
237010 case FTS5_SAVEPOINT:
237011 assert( p->ts.eState==1 );
237012 assert( iSavepoint>=0 );
237013 assert( iSavepoint>=p->ts.iSavepoint );
237014 p->ts.iSavepoint = iSavepoint;
237015 break;
237016
237017 case FTS5_RELEASE:
237018 assert( p->ts.eState==1 );
237019 assert( iSavepoint>=0 );
237020 assert( iSavepoint<=p->ts.iSavepoint );
237021 p->ts.iSavepoint = iSavepoint-1;
237022 break;
237023
237024 case FTS5_ROLLBACKTO:
237025 assert( p->ts.eState==1 );
237026 assert( iSavepoint>=-1 );
237027 /* The following assert() can fail if another vtab strikes an error
237028 ** within an xSavepoint() call then SQLite calls xRollbackTo() - without
237029 ** having called xSavepoint() on this vtab. */
237030 /* assert( iSavepoint<=p->ts.iSavepoint ); */
@@ -238356,11 +238473,11 @@
238356 Fts5Config *pConfig = pTab->p.pConfig;
238357 int eType0; /* value_type() of apVal[0] */
238358 int rc = SQLITE_OK; /* Return code */
238359
238360 /* A transaction must be open when this is called. */
238361 assert( pTab->ts.eState==1 );
238362
238363 assert( pVtab->zErrMsg==0 );
238364 assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
238365 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
238366 || sqlite3_value_type(apVal[0])==SQLITE_NULL
@@ -239524,11 +239641,11 @@
239524 int nArg, /* Number of args */
239525 sqlite3_value **apUnused /* Function arguments */
239526 ){
239527 assert( nArg==0 );
239528 UNUSED_PARAM2(nArg, apUnused);
239529 sqlite3_result_text(pCtx, "fts5: 2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389", -1, SQLITE_TRANSIENT);
239530 }
239531
239532 /*
239533 ** Return true if zName is the extension on one of the shadow tables used
239534 ** by this module.
@@ -244262,10 +244379,14 @@
244262 #define STMT_COLUMN_REPREP 8 /* SQLITE_STMTSTATUS_REPREPARE */
244263 #define STMT_COLUMN_RUN 9 /* SQLITE_STMTSTATUS_RUN */
244264 #define STMT_COLUMN_MEM 10 /* SQLITE_STMTSTATUS_MEMUSED */
244265
244266
 
 
 
 
244267 rc = sqlite3_declare_vtab(db,
244268 "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
244269 "reprep,run,mem)");
244270 if( rc==SQLITE_OK ){
244271 pNew = sqlite3_malloc64( sizeof(*pNew) );
@@ -244381,10 +244502,14 @@
244381 stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
244382 sqlite3_stmt *p = 0;
244383 sqlite3_int64 iRowid = 1;
244384 StmtRow **ppRow = 0;
244385
 
 
 
 
244386 stmtCsrReset(pCur);
244387 ppRow = &pCur->pRow;
244388 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
244389 const char *zSql = sqlite3_sql(p);
244390 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
@@ -244436,10 +244561,11 @@
244436 */
244437 static int stmtBestIndex(
244438 sqlite3_vtab *tab,
244439 sqlite3_index_info *pIdxInfo
244440 ){
 
244441 pIdxInfo->estimatedCost = (double)500;
244442 pIdxInfo->estimatedRows = 500;
244443 return SQLITE_OK;
244444 }
244445
244446
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.41.0"
456 #define SQLITE_VERSION_NUMBER 3041000
457 #define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -3602,12 +3602,12 @@
3602 **
3603 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3604 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3605 ** information as is provided by the [sqlite3_profile()] callback.
3606 ** ^The P argument is a pointer to the [prepared statement] and the
3607 ** X argument points to a 64-bit integer which is approximately
3608 ** the number of nanoseconds that the prepared statement took to run.
3609 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3610 **
3611 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3612 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3613 ** statement generates a single row of result.
@@ -14511,13 +14511,13 @@
14511 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
14512 ** underlying malloc() implementation might return us 4-byte aligned
14513 ** pointers. In that case, only verify 4-byte alignment.
14514 */
14515 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
14516 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
14517 #else
14518 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
14519 #endif
14520
14521 /*
14522 ** Disable MMAP on platforms where it is known to not work
14523 */
@@ -17683,10 +17683,11 @@
17683 #define SQLITE_AFF_BLOB 0x41 /* 'A' */
17684 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
17685 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
17686 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
17687 #define SQLITE_AFF_REAL 0x45 /* 'E' */
17688 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
17689
17690 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
17691
17692 /*
17693 ** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -18238,10 +18239,13 @@
18239 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
18240 int iDistAddr; /* Address of OP_OpenEphemeral */
18241 } *aFunc;
18242 int nFunc; /* Number of entries in aFunc[] */
18243 u32 selId; /* Select to which this AggInfo belongs */
18244 #ifdef SQLITE_DEBUG
18245 Select *pSelect; /* SELECT statement that this AggInfo supports */
18246 #endif
18247 };
18248
18249 /*
18250 ** Macros to compute aCol[] and aFunc[] register numbers.
18251 **
@@ -19078,14 +19082,14 @@
19082 # define DbMaskAllZero(M) sqlite3DbMaskAllZero(M)
19083 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
19084 #else
19085 typedef unsigned int yDbMask;
19086 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
19087 # define DbMaskZero(M) ((M)=0)
19088 # define DbMaskSet(M,I) ((M)|=(((yDbMask)1)<<(I)))
19089 # define DbMaskAllZero(M) ((M)==0)
19090 # define DbMaskNonZero(M) ((M)!=0)
19091 #endif
19092
19093 /*
19094 ** For each index X that has as one of its arguments either an expression
19095 ** or the name of a virtual generated column, and if X is in scope such that
@@ -20654,11 +20658,11 @@
20658 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
20659 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
20660 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
20661
20662 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
20663 SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64);
20664 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
20665 SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
20666 SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
20667 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
20668 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -22786,11 +22790,11 @@
22790
22791 Op *aOp; /* Space to hold the virtual machine's program */
22792 int nOp; /* Number of instructions in the program */
22793 int nOpAlloc; /* Slots allocated for aOp[] */
22794 Mem *aColName; /* Column names to return */
22795 Mem *pResultRow; /* Current output row */
22796 char *zErrMsg; /* Error message written here */
22797 VList *pVList; /* Name of variables */
22798 #ifndef SQLITE_OMIT_TRACE
22799 i64 startTime; /* Time when query started - used for profiling */
22800 #endif
@@ -27328,13 +27332,17 @@
27332 int iFullSz;
27333 if( n<=mem5.szAtom*2 ){
27334 if( n<=mem5.szAtom ) return mem5.szAtom;
27335 return mem5.szAtom*2;
27336 }
27337 if( n>0x10000000 ){
27338 if( n>0x40000000 ) return 0;
27339 if( n>0x20000000 ) return 0x40000000;
27340 return 0x20000000;
27341 }
27342 for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27343 if( (iFullSz/2)>=(i64)n ) return iFullSz/2;
27344 return iFullSz;
27345 }
27346
27347 /*
27348 ** Return the ceiling of the logarithm base 2 of iValue.
@@ -30600,17 +30608,30 @@
30608 buf[3] = 0x80 + (u8)(ch & 0x3f);
30609 length = 4;
30610 }
30611 }
30612 if( precision>1 ){
30613 i64 nPrior = 1;
30614 width -= precision-1;
30615 if( width>1 && !flag_leftjustify ){
30616 sqlite3_str_appendchar(pAccum, width-1, ' ');
30617 width = 0;
30618 }
30619 sqlite3_str_append(pAccum, buf, length);
30620 precision--;
30621 while( precision > 1 ){
30622 i64 nCopyBytes;
30623 if( nPrior > precision-1 ) nPrior = precision - 1;
30624 nCopyBytes = length*nPrior;
30625 if( nCopyBytes + pAccum->nChar >= pAccum->nAlloc ){
30626 sqlite3StrAccumEnlarge(pAccum, nCopyBytes);
30627 }
30628 if( pAccum->accError ) break;
30629 sqlite3_str_append(pAccum,
30630 &pAccum->zText[pAccum->nChar-nCopyBytes], nCopyBytes);
30631 precision -= nPrior;
30632 nPrior *= 2;
30633 }
30634 }
30635 bufpt = buf;
30636 flag_altform2 = 1;
30637 goto adjust_width_for_utf8;
@@ -30834,13 +30855,13 @@
30855 ** able to accept at least N more bytes of text.
30856 **
30857 ** Return the number of bytes of text that StrAccum is able to accept
30858 ** after the attempted enlargement. The value returned might be zero.
30859 */
30860 SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, i64 N){
30861 char *zNew;
30862 assert( p->nChar+N >= p->nAlloc ); /* Only called if really needed */
30863 if( p->accError ){
30864 testcase(p->accError==SQLITE_TOOBIG);
30865 testcase(p->accError==SQLITE_NOMEM);
30866 return 0;
30867 }
@@ -30847,12 +30868,11 @@
30868 if( p->mxAlloc==0 ){
30869 sqlite3StrAccumSetError(p, SQLITE_TOOBIG);
30870 return p->nAlloc - p->nChar - 1;
30871 }else{
30872 char *zOld = isMalloced(p) ? p->zText : 0;
30873 i64 szNew = p->nChar + N + 1;
 
30874 if( szNew+p->nChar<=p->mxAlloc ){
30875 /* Force exponential buffer size growth as long as it does not overflow,
30876 ** to avoid having to call this routine too often */
30877 szNew += p->nChar;
30878 }
@@ -30878,11 +30898,12 @@
30898 sqlite3_str_reset(p);
30899 sqlite3StrAccumSetError(p, SQLITE_NOMEM);
30900 return 0;
30901 }
30902 }
30903 assert( N>=0 && N<=0x7fffffff );
30904 return (int)N;
30905 }
30906
30907 /*
30908 ** Append N copies of character c to the given string buffer.
30909 */
@@ -51226,10 +51247,11 @@
51247 static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
51248 static int memdbTruncate(sqlite3_file*, sqlite3_int64 size);
51249 static int memdbSync(sqlite3_file*, int flags);
51250 static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize);
51251 static int memdbLock(sqlite3_file*, int);
51252 static int memdbUnlock(sqlite3_file*, int);
51253 /* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */
51254 static int memdbFileControl(sqlite3_file*, int op, void *pArg);
51255 /* static int memdbSectorSize(sqlite3_file*); // not used */
51256 static int memdbDeviceCharacteristics(sqlite3_file*);
51257 static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
@@ -51284,11 +51306,11 @@
51306 memdbWrite, /* xWrite */
51307 memdbTruncate, /* xTruncate */
51308 memdbSync, /* xSync */
51309 memdbFileSize, /* xFileSize */
51310 memdbLock, /* xLock */
51311 memdbUnlock, /* xUnlock */
51312 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
51313 memdbFileControl, /* xFileControl */
51314 0, /* memdbSectorSize,*/ /* xSectorSize */
51315 memdbDeviceCharacteristics, /* xDeviceCharacteristics */
51316 0, /* xShmMap */
@@ -51485,69 +51507,86 @@
51507 */
51508 static int memdbLock(sqlite3_file *pFile, int eLock){
51509 MemFile *pThis = (MemFile*)pFile;
51510 MemStore *p = pThis->pStore;
51511 int rc = SQLITE_OK;
51512 if( eLock<=pThis->eLock ) return SQLITE_OK;
51513 memdbEnter(p);
51514
51515 assert( p->nWrLock==0 || p->nWrLock==1 );
51516 assert( pThis->eLock<=SQLITE_LOCK_SHARED || p->nWrLock==1 );
51517 assert( pThis->eLock==SQLITE_LOCK_NONE || p->nRdLock>=1 );
51518
51519 if( eLock>SQLITE_LOCK_SHARED && (p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
51520 rc = SQLITE_READONLY;
51521 }else{
51522 switch( eLock ){
51523 case SQLITE_LOCK_SHARED: {
51524 assert( pThis->eLock==SQLITE_LOCK_NONE );
51525 if( p->nWrLock>0 ){
51526 rc = SQLITE_BUSY;
51527 }else{
51528 p->nRdLock++;
51529 }
51530 break;
51531 };
51532
51533 case SQLITE_LOCK_RESERVED:
51534 case SQLITE_LOCK_PENDING: {
51535 assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51536 if( ALWAYS(pThis->eLock==SQLITE_LOCK_SHARED) ){
51537 if( p->nWrLock>0 ){
51538 rc = SQLITE_BUSY;
51539 }else{
51540 p->nWrLock = 1;
51541 }
51542 }
51543 break;
51544 }
51545
51546 default: {
51547 assert( eLock==SQLITE_LOCK_EXCLUSIVE );
51548 assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51549 if( p->nRdLock>1 ){
51550 rc = SQLITE_BUSY;
51551 }else if( pThis->eLock==SQLITE_LOCK_SHARED ){
51552 p->nWrLock = 1;
51553 }
51554 break;
51555 }
51556 }
 
 
 
 
 
 
 
 
 
51557 }
51558 if( rc==SQLITE_OK ) pThis->eLock = eLock;
51559 memdbLeave(p);
51560 return rc;
51561 }
51562
51563 /*
51564 ** Unlock an memdb-file.
51565 */
51566 static int memdbUnlock(sqlite3_file *pFile, int eLock){
51567 MemFile *pThis = (MemFile*)pFile;
51568 MemStore *p = pThis->pStore;
51569 if( eLock>=pThis->eLock ) return SQLITE_OK;
51570 memdbEnter(p);
51571
51572 assert( eLock==SQLITE_LOCK_SHARED || eLock==SQLITE_LOCK_NONE );
51573 if( eLock==SQLITE_LOCK_SHARED ){
51574 if( ALWAYS(pThis->eLock>SQLITE_LOCK_SHARED) ){
51575 p->nWrLock--;
51576 }
51577 }else{
51578 if( pThis->eLock>SQLITE_LOCK_SHARED ){
51579 p->nWrLock--;
51580 }
51581 p->nRdLock--;
51582 }
51583
51584 pThis->eLock = eLock;
51585 memdbLeave(p);
51586 return SQLITE_OK;
51587 }
51588
51589 #if 0
51590 /*
51591 ** This interface is only used for crash recovery, which does not
51592 ** occur on an in-memory database.
@@ -51652,11 +51691,11 @@
51691 int szName;
51692 UNUSED_PARAMETER(pVfs);
51693
51694 memset(pFile, 0, sizeof(*pFile));
51695 szName = sqlite3Strlen30(zName);
51696 if( szName>1 && (zName[0]=='/' || zName[0]=='\\') ){
51697 int i;
51698 #ifndef SQLITE_MUTEX_OMIT
51699 sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
51700 #endif
51701 sqlite3_mutex_enter(pVfsMutex);
@@ -82354,10 +82393,12 @@
82393 ** sqlite3MisuseError(lineno)
82394 ** sqlite3CantopenError(lineno)
82395 */
82396 static void test_addop_breakpoint(int pc, Op *pOp){
82397 static int n = 0;
82398 (void)pc;
82399 (void)pOp;
82400 n++;
82401 }
82402 #endif
82403
82404 /*
@@ -84458,11 +84499,10 @@
84499 /* Even though this opcode does not use dynamic strings for
84500 ** the result, result columns may become dynamic if the user calls
84501 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
84502 */
84503 releaseMemArray(pMem, 8);
 
84504
84505 if( p->rc==SQLITE_NOMEM ){
84506 /* This happens if a malloc() inside a call to sqlite3_column_text() or
84507 ** sqlite3_column_text16() failed. */
84508 sqlite3OomFault(db);
@@ -84515,11 +84555,11 @@
84555 sqlite3VdbeMemSetNull(pMem+7);
84556 #endif
84557 sqlite3VdbeMemSetStr(pMem+5, zP4, -1, SQLITE_UTF8, sqlite3_free);
84558 p->nResColumn = 8;
84559 }
84560 p->pResultRow = pMem;
84561 if( db->mallocFailed ){
84562 p->rc = SQLITE_NOMEM;
84563 rc = SQLITE_ERROR;
84564 }else{
84565 p->rc = SQLITE_OK;
@@ -85647,11 +85687,11 @@
85687 #endif
85688 if( p->zErrMsg ){
85689 sqlite3DbFree(db, p->zErrMsg);
85690 p->zErrMsg = 0;
85691 }
85692 p->pResultRow = 0;
85693 #ifdef SQLITE_DEBUG
85694 p->nWrite = 0;
85695 #endif
85696
85697 /* Save profiling information from this VDBE run.
@@ -88273,11 +88313,11 @@
88313 }else{
88314 #ifndef SQLITE_OMIT_TRACE
88315 /* If the statement completed successfully, invoke the profile callback */
88316 checkProfileCallback(db, p);
88317 #endif
88318 p->pResultRow = 0;
88319 if( rc==SQLITE_DONE && db->autoCommit ){
88320 assert( p->rc==SQLITE_OK );
88321 p->rc = doWalCallbacks(db);
88322 if( p->rc!=SQLITE_OK ){
88323 rc = SQLITE_ERROR;
@@ -88637,11 +88677,11 @@
88677 ** Return the number of values available from the current row of the
88678 ** currently executing statement pStmt.
88679 */
88680 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){
88681 Vdbe *pVm = (Vdbe *)pStmt;
88682 if( pVm==0 || pVm->pResultRow==0 ) return 0;
88683 return pVm->nResColumn;
88684 }
88685
88686 /*
88687 ** Return a pointer to static memory containing an SQL NULL value.
@@ -88692,12 +88732,12 @@
88732
88733 pVm = (Vdbe *)pStmt;
88734 if( pVm==0 ) return (Mem*)columnNullValue();
88735 assert( pVm->db );
88736 sqlite3_mutex_enter(pVm->db->mutex);
88737 if( pVm->pResultRow!=0 && i<pVm->nResColumn && i>=0 ){
88738 pOut = &pVm->pResultRow[i];
88739 }else{
88740 sqlite3Error(pVm->db, SQLITE_RANGE);
88741 pOut = (Mem*)columnNullValue();
88742 }
88743 return pOut;
@@ -90122,10 +90162,13 @@
90162 ** sqlite3MisuseError(lineno)
90163 ** sqlite3CantopenError(lineno)
90164 */
90165 static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){
90166 static int n = 0;
90167 (void)pc;
90168 (void)pOp;
90169 (void)v;
90170 n++;
90171 }
90172 #endif
90173
90174 /*
@@ -90360,10 +90403,14 @@
90403 ** floating-point representation if an integer representation
90404 ** is not possible. Note that the integer representation is
90405 ** always preferred, even if the affinity is REAL, because
90406 ** an integer representation is more space efficient on disk.
90407 **
90408 ** SQLITE_AFF_FLEXNUM:
90409 ** If the value is text, then try to convert it into a number of
90410 ** some kind (integer or real) but do not make any other changes.
90411 **
90412 ** SQLITE_AFF_TEXT:
90413 ** Convert pRec to a text representation.
90414 **
90415 ** SQLITE_AFF_BLOB:
90416 ** SQLITE_AFF_NONE:
@@ -90374,15 +90421,15 @@
90421 char affinity, /* The affinity to be applied */
90422 u8 enc /* Use this text encoding */
90423 ){
90424 if( affinity>=SQLITE_AFF_NUMERIC ){
90425 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
90426 || affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM );
90427 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
90428 if( (pRec->flags & MEM_Real)==0 ){
90429 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
90430 }else if( affinity<=SQLITE_AFF_REAL ){
90431 sqlite3VdbeIntegerAffinity(pRec);
90432 }
90433 }
90434 }else if( affinity==SQLITE_AFF_TEXT ){
90435 /* Only attempt the conversion to TEXT if there is an integer or real
@@ -90698,10 +90745,11 @@
90745 Op *aOp = p->aOp; /* Copy of p->aOp */
90746 Op *pOp = aOp; /* Current operation */
90747 #ifdef SQLITE_DEBUG
90748 Op *pOrigOp; /* Value of pOp at the top of the loop */
90749 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
90750 u8 iCompareIsInit = 0; /* iCompare is initialized */
90751 #endif
90752 int rc = SQLITE_OK; /* Value to return */
90753 sqlite3 *db = p->db; /* The database */
90754 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
90755 u8 encoding = ENC(db); /* The database encoding */
@@ -90719,11 +90767,13 @@
90767 u64 *pnCycle = 0;
90768 #endif
90769 /*** INSERT STACK UNION HERE ***/
90770
90771 assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
90772 if( DbMaskNonZero(p->lockMask) ){
90773 sqlite3VdbeEnter(p);
90774 }
90775 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
90776 if( db->xProgress ){
90777 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
90778 assert( 0 < db->nProgressOps );
90779 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
@@ -90740,11 +90790,10 @@
90790 testcase( p->rc!=SQLITE_OK );
90791 p->rc = SQLITE_OK;
90792 assert( p->bIsReader || p->readOnly!=0 );
90793 p->iCurrentTime = 0;
90794 assert( p->explain==0 );
 
90795 db->busyHandler.nBusy = 0;
90796 if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
90797 sqlite3VdbeIOTraceSql(p);
90798 #ifdef SQLITE_DEBUG
90799 sqlite3BeginBenignMalloc();
@@ -91571,14 +91620,14 @@
91620 assert( p->nResColumn==pOp->p2 );
91621 assert( pOp->p1>0 || CORRUPT_DB );
91622 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
91623
91624 p->cacheCtr = (p->cacheCtr + 2)|1;
91625 p->pResultRow = &aMem[pOp->p1];
91626 #ifdef SQLITE_DEBUG
91627 {
91628 Mem *pMem = p->pResultRow;
91629 int i;
91630 for(i=0; i<pOp->p2; i++){
91631 assert( memIsValid(&pMem[i]) );
91632 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
91633 /* The registers in the result will not be used again when the
@@ -92111,22 +92160,25 @@
92160 if( sqlite3aGTb[pOp->opcode] ){
92161 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92162 goto jump_to_p2;
92163 }
92164 iCompare = +1;
92165 VVA_ONLY( iCompareIsInit = 1; )
92166 }else if( pIn3->u.i < pIn1->u.i ){
92167 if( sqlite3aLTb[pOp->opcode] ){
92168 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92169 goto jump_to_p2;
92170 }
92171 iCompare = -1;
92172 VVA_ONLY( iCompareIsInit = 1; )
92173 }else{
92174 if( sqlite3aEQb[pOp->opcode] ){
92175 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92176 goto jump_to_p2;
92177 }
92178 iCompare = 0;
92179 VVA_ONLY( iCompareIsInit = 1; )
92180 }
92181 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92182 break;
92183 }
92184 if( (flags1 | flags3)&MEM_Null ){
@@ -92154,10 +92206,11 @@
92206 VdbeBranchTaken(2,3);
92207 if( pOp->p5 & SQLITE_JUMPIFNULL ){
92208 goto jump_to_p2;
92209 }
92210 iCompare = 1; /* Operands are not equal */
92211 VVA_ONLY( iCompareIsInit = 1; )
92212 break;
92213 }
92214 }else{
92215 /* Neither operand is NULL and we couldn't do the special high-speed
92216 ** integer comparison case. So do a general-case comparison. */
@@ -92179,11 +92232,11 @@
92232 testcase( pIn1->flags & MEM_Real );
92233 testcase( pIn1->flags & MEM_IntReal );
92234 sqlite3VdbeMemStringify(pIn1, encoding, 1);
92235 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
92236 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
92237 if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
92238 }
92239 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
92240 testcase( pIn3->flags & MEM_Int );
92241 testcase( pIn3->flags & MEM_Real );
92242 testcase( pIn3->flags & MEM_IntReal );
@@ -92210,10 +92263,11 @@
92263 res2 = sqlite3aEQb[pOp->opcode];
92264 }else{
92265 res2 = sqlite3aGTb[pOp->opcode];
92266 }
92267 iCompare = res;
92268 VVA_ONLY( iCompareIsInit = 1; )
92269
92270 /* Undo any changes made by applyAffinity() to the input registers. */
92271 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
92272 pIn3->flags = flags3;
92273 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
@@ -92248,10 +92302,11 @@
92302 if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
92303 assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
92304 break;
92305 }
92306 #endif /* SQLITE_DEBUG */
92307 assert( iCompareIsInit );
92308 VdbeBranchTaken(iCompare==0, 2);
92309 if( iCompare==0 ) goto jump_to_p2;
92310 break;
92311 }
92312
@@ -92342,10 +92397,11 @@
92397 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
92398 assert( i<pKeyInfo->nKeyField );
92399 pColl = pKeyInfo->aColl[i];
92400 bRev = (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC);
92401 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
92402 VVA_ONLY( iCompareIsInit = 1; )
92403 if( iCompare ){
92404 if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
92405 && ((aMem[p1+idx].flags & MEM_Null) || (aMem[p2+idx].flags & MEM_Null))
92406 ){
92407 iCompare = -iCompare;
@@ -92366,10 +92422,11 @@
92422 **
92423 ** This opcode must immediately follow an OP_Compare opcode.
92424 */
92425 case OP_Jump: { /* jump */
92426 assert( pOp>aOp && pOp[-1].opcode==OP_Compare );
92427 assert( iCompareIsInit );
92428 if( iCompare<0 ){
92429 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
92430 }else if( iCompare==0 ){
92431 VdbeBranchTaken(1,4); pOp = &aOp[pOp->p2 - 1];
92432 }else{
@@ -95544,12 +95601,15 @@
95601 }
95602 }
95603 if( pOp->p5 & OPFLAG_ISNOOP ) break;
95604 #endif
95605
95606 assert( (pOp->p5 & OPFLAG_LASTROWID)==0 || (pOp->p5 & OPFLAG_NCHANGE)!=0 );
95607 if( pOp->p5 & OPFLAG_NCHANGE ){
95608 p->nChange++;
95609 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
95610 }
95611 assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
95612 x.pData = pData->z;
95613 x.nData = pData->n;
95614 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
95615 if( pData->flags & MEM_Zero ){
@@ -98812,11 +98872,13 @@
98872 goto abort_due_to_error;
98873 }
98874 }
98875 #endif
98876 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
98877 if( DbMaskNonZero(p->lockMask) ){
98878 sqlite3VdbeLeave(p);
98879 }
98880 assert( rc!=SQLITE_OK || nExtraDelete==0
98881 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
98882 );
98883 return rc;
98884
@@ -102219,10 +102281,13 @@
102281 "subprog TEXT,"
102282 "stmt HIDDEN"
102283 ");"
102284 };
102285
102286 (void)argc;
102287 (void)argv;
102288 (void)pzErr;
102289 rc = sqlite3_declare_vtab(db, azSchema[isTabUsed]);
102290 if( rc==SQLITE_OK ){
102291 pNew = sqlite3_malloc( sizeof(*pNew) );
102292 *ppVtab = (sqlite3_vtab*)pNew;
102293 if( pNew==0 ) return SQLITE_NOMEM;
@@ -102454,10 +102519,11 @@
102519 int argc, sqlite3_value **argv
102520 ){
102521 bytecodevtab_cursor *pCur = (bytecodevtab_cursor *)pVtabCursor;
102522 bytecodevtab *pVTab = (bytecodevtab *)pVtabCursor->pVtab;
102523 int rc = SQLITE_OK;
102524 (void)idxStr;
102525
102526 bytecodevtabCursorClear(pCur);
102527 pCur->iRowid = 0;
102528 pCur->iAddr = 0;
102529 pCur->showSubprograms = idxNum==0;
@@ -109654,11 +109720,11 @@
109720 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
109721 assert( ExprUseYTab(pExpr) );
109722 assert( pExpr->y.pTab!=0 );
109723 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
109724 if( aff>SQLITE_AFF_BLOB ){
109725 static const char zAff[] = "B\000C\000D\000E\000F";
109726 assert( SQLITE_AFF_BLOB=='A' );
109727 assert( SQLITE_AFF_TEXT=='B' );
109728 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
109729 &zAff[(aff-'B')*2], P4_STATIC);
109730 }
@@ -111651,14 +111717,12 @@
111717 ** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
111718 ** object that is referenced does not refer directly to the Expr. If
111719 ** it does, make a copy. This is done because the pExpr argument is
111720 ** subject to change.
111721 **
111722 ** The copy is scheduled for deletion using the sqlite3ExprDeferredDelete()
111723 ** which builds on the sqlite3ParserAddCleanup() mechanism.
 
 
111724 */
111725 static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
111726 if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
111727 && pExpr->pAggInfo!=0
111728 ){
@@ -111665,11 +111729,10 @@
111729 AggInfo *pAggInfo = pExpr->pAggInfo;
111730 int iAgg = pExpr->iAgg;
111731 Parse *pParse = pWalker->pParse;
111732 sqlite3 *db = pParse->db;
111733 if( pExpr->op!=TK_AGG_FUNCTION ){
 
111734 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
111735 if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
111736 pExpr = sqlite3ExprDup(db, pExpr, 0);
111737 if( pExpr ){
111738 pAggInfo->aCol[iAgg].pCExpr = pExpr;
@@ -111791,10 +111854,11 @@
111854 if( pCol->iSorterColumn<0 ){
111855 pCol->iSorterColumn = pAggInfo->nSortingColumn++;
111856 }
111857 fix_up_expr:
111858 ExprSetVVAProperty(pExpr, EP_NoReduce);
111859 assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
111860 pExpr->pAggInfo = pAggInfo;
111861 if( pExpr->op==TK_COLUMN ){
111862 pExpr->op = TK_AGG_COLUMN;
111863 }
111864 pExpr->iAgg = (i16)k;
@@ -111826,10 +111890,11 @@
111890 if( iDataCur<0 ) continue;
111891 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
111892 }
111893 if( pIEpr==0 ) break;
111894 if( NEVER(!ExprUseYTab(pExpr)) ) break;
111895 if( pExpr->pAggInfo!=0 ) break; /* Already resolved by outer context */
111896
111897 /* If we reach this point, it means that expression pExpr can be
111898 ** translated into a reference to an index column as described by
111899 ** pIEpr.
111900 */
@@ -112780,17 +112845,18 @@
112845 static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
112846 assert( pParse==pParse->db->pParse );
112847 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
112848 if( pParse->nErr==0 ){
112849 const RenameToken *p;
112850 u32 i = 1;
112851 for(p=pParse->pRename; p; p=p->pNext){
112852 if( p->p ){
112853 assert( p->p!=pPtr );
112854 i += *(u8*)(p->p) | 1;
112855 }
112856 }
112857 assert( i>0 );
112858 }
112859 }
112860 #else
112861 # define renameTokenCheckAll(x,y)
112862 #endif
@@ -117442,10 +117508,11 @@
117508 sqlite3 *db = pParse->db;
117509 u32 savedDbFlags = db->mDbFlags;
117510 char saveBuf[PARSE_TAIL_SZ];
117511
117512 if( pParse->nErr ) return;
117513 if( pParse->eParseMode ) return;
117514 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
117515 va_start(ap, zFormat);
117516 zSql = sqlite3VMPrintf(db, zFormat, ap);
117517 va_end(ap);
117518 if( zSql==0 ){
@@ -119139,10 +119206,17 @@
119206 assert( TF_HasStored==COLFLAG_STORED );
119207 pTab->tabFlags |= eType;
119208 if( pCol->colFlags & COLFLAG_PRIMKEY ){
119209 makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
119210 }
119211 if( ALWAYS(pExpr) && pExpr->op==TK_ID ){
119212 /* The value of a generated column needs to be a real expression, not
119213 ** just a reference to another column, in order for covering index
119214 ** optimizations to work correctly. So if the value is not an expression,
119215 ** turn it into one by adding a unary "+" operator. */
119216 pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
119217 }
119218 sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
119219 pExpr = 0;
119220 goto generated_done;
119221
119222 generated_error:
@@ -119275,11 +119349,12 @@
119349 static const char * const azType[] = {
119350 /* SQLITE_AFF_BLOB */ "",
119351 /* SQLITE_AFF_TEXT */ " TEXT",
119352 /* SQLITE_AFF_NUMERIC */ " NUM",
119353 /* SQLITE_AFF_INTEGER */ " INT",
119354 /* SQLITE_AFF_REAL */ " REAL",
119355 /* SQLITE_AFF_FLEXNUM */ " NUM",
119356 };
119357 int len;
119358 const char *zType;
119359
119360 sqlite3_snprintf(n-k, &zStmt[k], zSep);
@@ -119291,14 +119366,16 @@
119366 testcase( pCol->affinity==SQLITE_AFF_BLOB );
119367 testcase( pCol->affinity==SQLITE_AFF_TEXT );
119368 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
119369 testcase( pCol->affinity==SQLITE_AFF_INTEGER );
119370 testcase( pCol->affinity==SQLITE_AFF_REAL );
119371 testcase( pCol->affinity==SQLITE_AFF_FLEXNUM );
119372
119373 zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
119374 len = sqlite3Strlen30(zType);
119375 assert( pCol->affinity==SQLITE_AFF_BLOB
119376 || pCol->affinity==SQLITE_AFF_FLEXNUM
119377 || pCol->affinity==sqlite3AffinityType(zType, 0) );
119378 memcpy(&zStmt[k], zType, len);
119379 k += len;
119380 assert( k<=n );
119381 }
@@ -119709,10 +119786,11 @@
119786 ** they should not be changed. Expressions attached to a table or
119787 ** index definition are tagged this way to help ensure that we do
119788 ** not pass them into code generator routines by mistake.
119789 */
119790 static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){
119791 (void)pWalker;
119792 ExprSetVVAProperty(pExpr, EP_Immutable);
119793 return WRC_Continue;
119794 }
119795 static void markExprListImmutable(ExprList *pList){
119796 if( pList ){
@@ -125459,11 +125537,11 @@
125537 sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue));
125538 break;
125539 }
125540 case SQLITE_BLOB: {
125541 char const *zBlob = sqlite3_value_blob(pValue);
125542 i64 nBlob = sqlite3_value_bytes(pValue);
125543 assert( zBlob==sqlite3_value_blob(pValue) ); /* No encoding change */
125544 sqlite3StrAccumEnlarge(pStr, nBlob*2 + 4);
125545 if( pStr->accError==0 ){
125546 char *zText = pStr->zText;
125547 int i;
@@ -125817,10 +125895,13 @@
125895 sqlite3_context *context,
125896 int argc,
125897 sqlite3_value **argv
125898 ){
125899 /* no-op */
125900 (void)context;
125901 (void)argc;
125902 (void)argv;
125903 }
125904 #endif /*SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION*/
125905
125906
125907 /* IMP: R-25361-16150 This function is omitted from SQLite by default. It
@@ -126560,10 +126641,11 @@
126641 sqlite3_context *context,
126642 int argc,
126643 sqlite3_value **argv
126644 ){
126645 assert( argc==0 );
126646 (void)argv;
126647 sqlite3_result_double(context, M_PI);
126648 }
126649
126650 #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
126651
@@ -139645,11 +139727,11 @@
139727 ** database table or a subquery.
139728 */
139729 Table *pTab = 0; /* Table structure column is extracted from */
139730 Select *pS = 0; /* Select the column is extracted from */
139731 int iCol = pExpr->iColumn; /* Index of column in pTab */
139732 while( ALWAYS(pNC) && !pTab ){
139733 SrcList *pTabList = pNC->pSrcList;
139734 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
139735 if( j<pTabList->nSrc ){
139736 pTab = pTabList->a[j].pTab;
139737 pS = pTabList->a[j].pSelect;
@@ -139656,11 +139738,11 @@
139738 }else{
139739 pNC = pNC->pNext;
139740 }
139741 }
139742
139743 if( NEVER(pTab==0) ){
139744 /* At one time, code such as "SELECT new.x" within a trigger would
139745 ** cause this condition to run. Since then, we have restructured how
139746 ** trigger code is generated and so this condition is no longer
139747 ** possible. However, it can still be true for statements like
139748 ** the following:
@@ -140032,18 +140114,10 @@
140114 return SQLITE_NOMEM_BKPT;
140115 }
140116 return SQLITE_OK;
140117 }
140118
 
 
 
 
 
 
 
 
140119 /*
140120 ** pTab is a transient Table object that represents a subquery of some
140121 ** kind (maybe a parenthesized subquery in the FROM clause of a larger
140122 ** query, or a VIEW, or a CTE). This routine computes type information
140123 ** for that Table object based on the Select object that implements the
@@ -140050,21 +140124,16 @@
140124 ** subquery. For the purposes of this routine, "type infomation" means:
140125 **
140126 ** * The datatype name, as it might appear in a CREATE TABLE statement
140127 ** * Which collating sequence to use for the column
140128 ** * The affinity of the column
 
 
 
 
 
140129 */
140130 SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140131 Parse *pParse, /* Parsing contexts */
140132 Table *pTab, /* Add column type information to this table */
140133 Select *pSelect, /* SELECT used to determine types and collations */
140134 char aff /* Default affinity. */
140135 ){
140136 sqlite3 *db = pParse->db;
140137 Column *pCol;
140138 CollSeq *pColl;
140139 int i,j;
@@ -140072,10 +140141,11 @@
140141 struct ExprList_item *a;
140142
140143 assert( pSelect!=0 );
140144 assert( (pSelect->selFlags & SF_Resolved)!=0 );
140145 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
140146 assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
140147 if( db->mallocFailed ) return;
140148 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
140149 a = pSelect->pEList->a;
140150 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140151 const char *zType;
@@ -140083,17 +140153,13 @@
140153 pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140154 p = a[i].pExpr;
140155 /* pCol->szEst = ... // Column size est for SELECT tables never used */
140156 pCol->affinity = sqlite3ExprAffinity(p);
140157 if( pCol->affinity<=SQLITE_AFF_NONE ){
140158 pCol->affinity = aff;
140159 }else if( pCol->affinity>=SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140160 pCol->affinity = SQLITE_AFF_FLEXNUM;
 
 
 
 
140161 }
140162 if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140163 int m = 0;
140164 Select *pS2;
140165 for(m=0, pS2=pSelect->pNext; pS2; pS2=pS2->pNext){
@@ -140104,11 +140170,13 @@
140170 }else
140171 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140172 pCol->affinity = SQLITE_AFF_BLOB;
140173 }
140174 }
140175 if( pCol->affinity==SQLITE_AFF_NUMERIC
140176 || pCol->affinity==SQLITE_AFF_FLEXNUM
140177 ){
140178 zType = "NUM";
140179 }else{
140180 zType = 0;
140181 for(j=1; j<SQLITE_N_STDTYPE; j++){
140182 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
@@ -143998,12 +144066,11 @@
144066 assert( pTab!=0 );
144067 if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
144068 /* A sub-query in the FROM clause of a SELECT */
144069 Select *pSel = pFrom->pSelect;
144070 if( pSel ){
144071 sqlite3SubqueryColumnTypes(pParse, pTab, pSel, SQLITE_AFF_NONE);
 
144072 }
144073 }
144074 }
144075 }
144076 #endif
@@ -144073,11 +144140,11 @@
144140 ii>=pAggInfo->nAccumulator ? "" : " Accumulator");
144141 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
144142 }
144143 for(ii=0; ii<pAggInfo->nFunc; ii++){
144144 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
144145 ii, pAggInfo->iFirstReg+pAggInfo->nColumn+ii);
144146 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
144147 }
144148 }
144149 #endif /* TREETRACE_ENABLED */
144150
@@ -145444,10 +145511,13 @@
145511 }
145512 if( db->mallocFailed ){
145513 goto select_end;
145514 }
145515 pAggInfo->selId = p->selId;
145516 #ifdef SQLITE_DEBUG
145517 pAggInfo->pSelect = p;
145518 #endif
145519 memset(&sNC, 0, sizeof(sNC));
145520 sNC.pParse = pParse;
145521 sNC.pSrcList = pTabList;
145522 sNC.uNC.pAggInfo = pAggInfo;
145523 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
@@ -162038,10 +162108,16 @@
162108 }
162109 if( sqlite3ExprIsConstant(pExpr) ) continue;
162110 p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
162111 if( p==0 ) break;
162112 p->pIENext = pParse->pIdxEpr;
162113 #ifdef WHERETRACE_ENABLED
162114 if( sqlite3WhereTrace & 0x200 ){
162115 sqlite3DebugPrintf("New pParse->pIdxEpr term {%d,%d}\n", iIdxCur, i);
162116 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(pExpr);
162117 }
162118 #endif
162119 p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
162120 p->iDataCur = pTabItem->iCursor;
162121 p->iIdxCur = iIdxCur;
162122 p->iIdxCol = i;
162123 p->bMaybeNullRow = bMaybeNullRow;
@@ -163000,10 +163076,17 @@
163076 }
163077 if( pIdx->bHasExpr ){
163078 IndexedExpr *p = pParse->pIdxEpr;
163079 while( p ){
163080 if( p->iIdxCur==pLevel->iIdxCur ){
163081 #ifdef WHERETRACE_ENABLED
163082 if( sqlite3WhereTrace & 0x200 ){
163083 sqlite3DebugPrintf("Disable pParse->pIdxEpr term {%d,%d}\n",
163084 p->iIdxCur, p->iIdxCol);
163085 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(p->pExpr);
163086 }
163087 #endif
163088 p->iDataCur = -1;
163089 p->iIdxCur = -1;
163090 }
163091 p = p->pIENext;
163092 }
@@ -201354,11 +201437,11 @@
201437 */
201438 static int readInt16(u8 *p){
201439 return (p[0]<<8) + p[1];
201440 }
201441 static void readCoord(u8 *p, RtreeCoord *pCoord){
201442 assert( (((sqlite3_uint64)p)&3)==0 ); /* p is always 4-byte aligned */
201443 #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
201444 pCoord->u = _byteswap_ulong(*(u32*)p);
201445 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
201446 pCoord->u = __builtin_bswap32(*(u32*)p);
201447 #elif SQLITE_BYTEORDER==4321
@@ -201408,11 +201491,11 @@
201491 p[0] = (i>> 8)&0xFF;
201492 p[1] = (i>> 0)&0xFF;
201493 }
201494 static int writeCoord(u8 *p, RtreeCoord *pCoord){
201495 u32 i;
201496 assert( (((sqlite3_uint64)p)&3)==0 ); /* p is always 4-byte aligned */
201497 assert( sizeof(RtreeCoord)==4 );
201498 assert( sizeof(u32)==4 );
201499 #if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
201500 i = __builtin_bswap32(pCoord->u);
201501 memcpy(p, &i, 4);
@@ -202136,11 +202219,11 @@
202219 pCellData += 8 + 4*(p->iCoord&0xfe);
202220
202221 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
202222 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
202223 || p->op==RTREE_FALSE );
202224 assert( (((sqlite3_uint64)pCellData)&3)==0 ); /* 4-byte aligned */
202225 switch( p->op ){
202226 case RTREE_TRUE: return; /* Always satisfied */
202227 case RTREE_FALSE: break; /* Never satisfied */
202228 case RTREE_EQ:
202229 RTREE_DECODE_COORD(eInt, pCellData, val);
@@ -202189,11 +202272,11 @@
202272
202273 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
202274 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
202275 || p->op==RTREE_FALSE );
202276 pCellData += 8 + p->iCoord*4;
202277 assert( (((sqlite3_uint64)pCellData)&3)==0 ); /* 4-byte aligned */
202278 RTREE_DECODE_COORD(eInt, pCellData, xN);
202279 switch( p->op ){
202280 case RTREE_TRUE: return; /* Always satisfied */
202281 case RTREE_FALSE: break; /* Never satisfied */
202282 case RTREE_LE: if( xN <= p->u.rValue ) return; break;
@@ -205561,11 +205644,11 @@
205644 ){
205645 GeoPoly *p = 0;
205646 int nByte;
205647 testcase( pCtx==0 );
205648 if( sqlite3_value_type(pVal)==SQLITE_BLOB
205649 && (nByte = sqlite3_value_bytes(pVal))>=(int)(4+6*sizeof(GeoCoord))
205650 ){
205651 const unsigned char *a = sqlite3_value_blob(pVal);
205652 int nVertex;
205653 if( a==0 ){
205654 if( pCtx ) sqlite3_result_error_nomem(pCtx);
@@ -205619,10 +205702,11 @@
205702 sqlite3_context *context,
205703 int argc,
205704 sqlite3_value **argv
205705 ){
205706 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205707 (void)argc;
205708 if( p ){
205709 sqlite3_result_blob(context, p->hdr,
205710 4+8*p->nVertex, SQLITE_TRANSIENT);
205711 sqlite3_free(p);
205712 }
@@ -205638,10 +205722,11 @@
205722 sqlite3_context *context,
205723 int argc,
205724 sqlite3_value **argv
205725 ){
205726 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205727 (void)argc;
205728 if( p ){
205729 sqlite3 *db = sqlite3_context_db_handle(context);
205730 sqlite3_str *x = sqlite3_str_new(db);
205731 int i;
205732 sqlite3_str_append(x, "[", 1);
@@ -205719,10 +205804,11 @@
205804 double D = sqlite3_value_double(argv[4]);
205805 double E = sqlite3_value_double(argv[5]);
205806 double F = sqlite3_value_double(argv[6]);
205807 GeoCoord x1, y1, x0, y0;
205808 int ii;
205809 (void)argc;
205810 if( p ){
205811 for(ii=0; ii<p->nVertex; ii++){
205812 x0 = GeoX(p,ii);
205813 y0 = GeoY(p,ii);
205814 x1 = (GeoCoord)(A*x0 + B*y0 + E);
@@ -205769,10 +205855,11 @@
205855 sqlite3_context *context,
205856 int argc,
205857 sqlite3_value **argv
205858 ){
205859 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205860 (void)argc;
205861 if( p ){
205862 sqlite3_result_double(context, geopolyArea(p));
205863 sqlite3_free(p);
205864 }
205865 }
@@ -205794,10 +205881,11 @@
205881 sqlite3_context *context,
205882 int argc,
205883 sqlite3_value **argv
205884 ){
205885 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
205886 (void)argc;
205887 if( p ){
205888 if( geopolyArea(p)<0.0 ){
205889 int ii, jj;
205890 for(ii=1, jj=p->nVertex-1; ii<jj; ii++, jj--){
205891 GeoCoord t = GeoX(p,ii);
@@ -205848,10 +205936,11 @@
205936 double y = sqlite3_value_double(argv[1]);
205937 double r = sqlite3_value_double(argv[2]);
205938 int n = sqlite3_value_int(argv[3]);
205939 int i;
205940 GeoPoly *p;
205941 (void)argc;
205942
205943 if( n<3 || r<=0.0 ) return;
205944 if( n>1000 ) n = 1000;
205945 p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) );
205946 if( p==0 ){
@@ -205957,10 +206046,11 @@
206046 sqlite3_context *context,
206047 int argc,
206048 sqlite3_value **argv
206049 ){
206050 GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
206051 (void)argc;
206052 if( p ){
206053 sqlite3_result_blob(context, p->hdr,
206054 4+8*p->nVertex, SQLITE_TRANSIENT);
206055 sqlite3_free(p);
206056 }
@@ -205984,10 +206074,11 @@
206074 int argc,
206075 sqlite3_value **argv
206076 ){
206077 RtreeCoord a[4];
206078 int rc = SQLITE_OK;
206079 (void)argc;
206080 (void)geopolyBBox(context, argv[0], a, &rc);
206081 if( rc==SQLITE_OK ){
206082 GeoBBox *pBBox;
206083 pBBox = (GeoBBox*)sqlite3_aggregate_context(context, sizeof(*pBBox));
206084 if( pBBox==0 ) return;
@@ -206072,10 +206163,12 @@
206163 double x0 = sqlite3_value_double(argv[1]);
206164 double y0 = sqlite3_value_double(argv[2]);
206165 int v = 0;
206166 int cnt = 0;
206167 int ii;
206168 (void)argc;
206169
206170 if( p1==0 ) return;
206171 for(ii=0; ii<p1->nVertex-1; ii++){
206172 v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
206173 GeoX(p1,ii+1),GeoY(p1,ii+1));
206174 if( v==2 ) break;
@@ -206111,10 +206204,11 @@
206204 int argc,
206205 sqlite3_value **argv
206206 ){
206207 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
206208 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
206209 (void)argc;
206210 if( p1 && p2 ){
206211 int x = geopolyOverlap(p1, p2);
206212 if( x<0 ){
206213 sqlite3_result_error_nomem(context);
206214 }else{
@@ -206441,10 +206535,11 @@
206535 int argc,
206536 sqlite3_value **argv
206537 ){
206538 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
206539 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
206540 (void)argc;
206541 if( p1 && p2 ){
206542 int x = geopolyOverlap(p1, p2);
206543 if( x<0 ){
206544 sqlite3_result_error_nomem(context);
206545 }else{
@@ -206461,12 +206556,16 @@
206556 static void geopolyDebugFunc(
206557 sqlite3_context *context,
206558 int argc,
206559 sqlite3_value **argv
206560 ){
206561 (void)context;
206562 (void)argc;
206563 #ifdef GEOPOLY_ENABLE_DEBUG
206564 geo_debug = sqlite3_value_int(argv[0]);
206565 #else
206566 (void)argv;
206567 #endif
206568 }
206569
206570 /*
206571 ** This function is the implementation of both the xConnect and xCreate
@@ -206490,10 +206589,11 @@
206589 sqlite3_int64 nDb; /* Length of string argv[1] */
206590 sqlite3_int64 nName; /* Length of string argv[2] */
206591 sqlite3_str *pSql;
206592 char *zSql;
206593 int ii;
206594 (void)pAux;
206595
206596 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
206597
206598 /* Allocate the sqlite3_vtab structure */
206599 nDb = strlen(argv[1]);
@@ -206606,10 +206706,11 @@
206706 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
206707 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
206708 RtreeNode *pRoot = 0;
206709 int rc = SQLITE_OK;
206710 int iCell = 0;
206711 (void)idxStr;
206712
206713 rtreeReference(pRtree);
206714
206715 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
206716 resetCursor(pCsr);
@@ -206732,10 +206833,11 @@
206833 static int geopolyBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
206834 int ii;
206835 int iRowidTerm = -1;
206836 int iFuncTerm = -1;
206837 int idxNum = 0;
206838 (void)tab;
206839
206840 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
206841 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
206842 if( !p->usable ) continue;
206843 if( p->iColumn<0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
@@ -206978,10 +207080,12 @@
207080 int nArg,
207081 const char *zName,
207082 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
207083 void **ppArg
207084 ){
207085 (void)pVtab;
207086 (void)nArg;
207087 if( sqlite3_stricmp(zName, "geopoly_overlap")==0 ){
207088 *pxFunc = geopolyOverlapFunc;
207089 *ppArg = 0;
207090 return SQLITE_INDEX_CONSTRAINT_FUNCTION;
207091 }
@@ -207047,11 +207151,11 @@
207151 void (*xFinal)(sqlite3_context*);
207152 const char *zName;
207153 } aAgg[] = {
207154 { geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" },
207155 };
207156 unsigned int i;
207157 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
207158 int enc;
207159 if( aFunc[i].bPure ){
207160 enc = SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS;
207161 }else{
@@ -214254,10 +214358,11 @@
214358 char **pzErr
214359 ){
214360 StatTable *pTab = 0;
214361 int rc = SQLITE_OK;
214362 int iDb;
214363 (void)pAux;
214364
214365 if( argc>=4 ){
214366 Token nm;
214367 sqlite3TokenInit(&nm, (char*)argv[3]);
214368 iDb = sqlite3FindDb(db, &nm);
@@ -214307,10 +214412,11 @@
214412 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
214413 int i;
214414 int iSchema = -1;
214415 int iName = -1;
214416 int iAgg = -1;
214417 (void)tab;
214418
214419 /* Look for a valid schema=? constraint. If found, change the idxNum to
214420 ** 1 and request the value of that constraint be sent to xFilter. And
214421 ** lower the cost estimate to encourage the constrained version to be
214422 ** used.
@@ -214832,10 +214938,12 @@
214938 sqlite3_str *pSql; /* Query of btrees to analyze */
214939 char *zSql; /* String value of pSql */
214940 int iArg = 0; /* Count of argv[] parameters used so far */
214941 int rc = SQLITE_OK; /* Result of this operation */
214942 const char *zName = 0; /* Only provide analysis of this table */
214943 (void)argc;
214944 (void)idxStr;
214945
214946 statResetCsr(pCsr);
214947 sqlite3_finalize(pCsr->pStmt);
214948 pCsr->pStmt = 0;
214949 if( idxNum & 0x01 ){
@@ -215066,10 +215174,14 @@
215174 sqlite3_vtab **ppVtab,
215175 char **pzErr
215176 ){
215177 DbpageTable *pTab = 0;
215178 int rc = SQLITE_OK;
215179 (void)pAux;
215180 (void)argc;
215181 (void)argv;
215182 (void)pzErr;
215183
215184 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
215185 rc = sqlite3_declare_vtab(db,
215186 "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
215187 if( rc==SQLITE_OK ){
@@ -215104,10 +215216,11 @@
215216 ** 3 schema=?1, pgno=?2
215217 */
215218 static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
215219 int i;
215220 int iPlan = 0;
215221 (void)tab;
215222
215223 /* If there is a schema= constraint, it must be honored. Report a
215224 ** ridiculously large estimated cost if the schema= constraint is
215225 ** unavailable
215226 */
@@ -215218,10 +215331,12 @@
215331 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
215332 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
215333 int rc;
215334 sqlite3 *db = pTab->db;
215335 Btree *pBt;
215336
215337 (void)idxStr;
215338
215339 /* Default setting is no rows of result */
215340 pCsr->pgno = 1;
215341 pCsr->mxPgno = 0;
215342
@@ -215314,10 +215429,11 @@
215429 int iDb;
215430 Btree *pBt;
215431 Pager *pPager;
215432 int szPage;
215433
215434 (void)pRowid;
215435 if( pTab->db->flags & SQLITE_Defensive ){
215436 zErr = "read-only";
215437 goto update_fail;
215438 }
215439 if( argc==1 ){
@@ -216921,10 +217037,12 @@
217037 ){
217038 sqlite3_session *pSession;
217039 int nDb = sqlite3Strlen30(zDb);
217040
217041 assert( sqlite3_mutex_held(db->mutex) );
217042 (void)iKey1;
217043 (void)iKey2;
217044
217045 for(pSession=(sqlite3_session *)pCtx; pSession; pSession=pSession->pNext){
217046 SessionTable *pTab;
217047
217048 /* If this session is attached to a different database ("main", "temp"
@@ -216997,10 +217115,11 @@
217115 static int sessionDiffCount(void *pCtx){
217116 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
217117 return p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt);
217118 }
217119 static int sessionDiffDepth(void *pCtx){
217120 (void)pCtx;
217121 return 0;
217122 }
217123
217124 /*
217125 ** Install the diff hooks on the session object passed as the only
@@ -217070,11 +217189,10 @@
217189
217190 return zRet;
217191 }
217192
217193 static char *sessionSelectFindNew(
 
217194 const char *zDb1, /* Pick rows in this db only */
217195 const char *zDb2, /* But not in this one */
217196 const char *zTbl, /* Table name */
217197 const char *zExpr
217198 ){
@@ -217094,11 +217212,11 @@
217212 const char *zDb1,
217213 const char *zDb2,
217214 char *zExpr
217215 ){
217216 int rc = SQLITE_OK;
217217 char *zStmt = sessionSelectFindNew(zDb1, zDb2, pTab->zName,zExpr);
217218
217219 if( zStmt==0 ){
217220 rc = SQLITE_NOMEM;
217221 }else{
217222 sqlite3_stmt *pStmt;
@@ -219611,11 +219729,10 @@
219729 ** If the iterator currently points to an INSERT record, bind values from the
219730 ** new.* record to the SELECT statement. Or, if it points to a DELETE or
219731 ** UPDATE, bind values from the old.* record.
219732 */
219733 static int sessionSeekToRow(
 
219734 sqlite3_changeset_iter *pIter, /* Changeset iterator */
219735 u8 *abPK, /* Primary key flags array */
219736 sqlite3_stmt *pSelect /* SELECT statement from sessionSelectRow() */
219737 ){
219738 int rc; /* Return code */
@@ -219741,11 +219858,11 @@
219858 assert( SQLITE_CHANGESET_CONFLICT+1==SQLITE_CHANGESET_CONSTRAINT );
219859 assert( SQLITE_CHANGESET_DATA+1==SQLITE_CHANGESET_NOTFOUND );
219860
219861 /* Bind the new.* PRIMARY KEY values to the SELECT statement. */
219862 if( pbReplace ){
219863 rc = sessionSeekToRow(pIter, p->abPK, p->pSelect);
219864 }else{
219865 rc = SQLITE_OK;
219866 }
219867
219868 if( rc==SQLITE_ROW ){
@@ -219915,11 +220032,11 @@
220032 assert( op==SQLITE_INSERT );
220033 if( p->bStat1 ){
220034 /* Check if there is a conflicting row. For sqlite_stat1, this needs
220035 ** to be done using a SELECT, as there is no PRIMARY KEY in the
220036 ** database schema to throw an exception if a duplicate is inserted. */
220037 rc = sessionSeekToRow(pIter, p->abPK, p->pSelect);
220038 if( rc==SQLITE_ROW ){
220039 rc = SQLITE_CONSTRAINT;
220040 sqlite3_reset(p->pSelect);
220041 }
220042 }
@@ -234981,11 +235098,11 @@
235098 i64 iLastRowid = 0;
235099
235100 /* Initialize a doclist-iterator for each input buffer. Arrange them in
235101 ** a linked-list starting at pHead in ascending order of rowid. Avoid
235102 ** linking any iterators already at EOF into the linked list at all. */
235103 assert( nBuf+1<=(int)(sizeof(aMerger)/sizeof(aMerger[0])) );
235104 memset(aMerger, 0, sizeof(PrefixMerger)*(nBuf+1));
235105 pHead = &aMerger[nBuf];
235106 fts5DoclistIterInit(p1, &pHead->iter);
235107 for(i=0; i<nBuf; i++){
235108 fts5DoclistIterInit(&aBuf[i], &aMerger[i].iter);
@@ -236991,11 +237108,11 @@
237108 p->ts.eState = 1;
237109 p->ts.iSavepoint = -1;
237110 break;
237111
237112 case FTS5_SYNC:
237113 assert( p->ts.eState==1 || p->ts.eState==2 );
237114 p->ts.eState = 2;
237115 break;
237116
237117 case FTS5_COMMIT:
237118 assert( p->ts.eState==2 );
@@ -237006,25 +237123,25 @@
237123 assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
237124 p->ts.eState = 0;
237125 break;
237126
237127 case FTS5_SAVEPOINT:
237128 assert( p->ts.eState>=1 );
237129 assert( iSavepoint>=0 );
237130 assert( iSavepoint>=p->ts.iSavepoint );
237131 p->ts.iSavepoint = iSavepoint;
237132 break;
237133
237134 case FTS5_RELEASE:
237135 assert( p->ts.eState>=1 );
237136 assert( iSavepoint>=0 );
237137 assert( iSavepoint<=p->ts.iSavepoint );
237138 p->ts.iSavepoint = iSavepoint-1;
237139 break;
237140
237141 case FTS5_ROLLBACKTO:
237142 assert( p->ts.eState>=1 );
237143 assert( iSavepoint>=-1 );
237144 /* The following assert() can fail if another vtab strikes an error
237145 ** within an xSavepoint() call then SQLite calls xRollbackTo() - without
237146 ** having called xSavepoint() on this vtab. */
237147 /* assert( iSavepoint<=p->ts.iSavepoint ); */
@@ -238356,11 +238473,11 @@
238473 Fts5Config *pConfig = pTab->p.pConfig;
238474 int eType0; /* value_type() of apVal[0] */
238475 int rc = SQLITE_OK; /* Return code */
238476
238477 /* A transaction must be open when this is called. */
238478 assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
238479
238480 assert( pVtab->zErrMsg==0 );
238481 assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
238482 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
238483 || sqlite3_value_type(apVal[0])==SQLITE_NULL
@@ -239524,11 +239641,11 @@
239641 int nArg, /* Number of args */
239642 sqlite3_value **apUnused /* Function arguments */
239643 ){
239644 assert( nArg==0 );
239645 UNUSED_PARAM2(nArg, apUnused);
239646 sqlite3_result_text(pCtx, "fts5: 2022-12-27 22:46:49 e8afad630b085a9208491e0516a6a30c9cda77a20b1aa2cba49b2f44eb9fa2f8", -1, SQLITE_TRANSIENT);
239647 }
239648
239649 /*
239650 ** Return true if zName is the extension on one of the shadow tables used
239651 ** by this module.
@@ -244262,10 +244379,14 @@
244379 #define STMT_COLUMN_REPREP 8 /* SQLITE_STMTSTATUS_REPREPARE */
244380 #define STMT_COLUMN_RUN 9 /* SQLITE_STMTSTATUS_RUN */
244381 #define STMT_COLUMN_MEM 10 /* SQLITE_STMTSTATUS_MEMUSED */
244382
244383
244384 (void)pAux;
244385 (void)argc;
244386 (void)argv;
244387 (void)pzErr;
244388 rc = sqlite3_declare_vtab(db,
244389 "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
244390 "reprep,run,mem)");
244391 if( rc==SQLITE_OK ){
244392 pNew = sqlite3_malloc64( sizeof(*pNew) );
@@ -244381,10 +244502,14 @@
244502 stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
244503 sqlite3_stmt *p = 0;
244504 sqlite3_int64 iRowid = 1;
244505 StmtRow **ppRow = 0;
244506
244507 (void)idxNum;
244508 (void)idxStr;
244509 (void)argc;
244510 (void)argv;
244511 stmtCsrReset(pCur);
244512 ppRow = &pCur->pRow;
244513 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
244514 const char *zSql = sqlite3_sql(p);
244515 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
@@ -244436,10 +244561,11 @@
244561 */
244562 static int stmtBestIndex(
244563 sqlite3_vtab *tab,
244564 sqlite3_index_info *pIdxInfo
244565 ){
244566 (void)tab;
244567 pIdxInfo->estimatedCost = (double)500;
244568 pIdxInfo->estimatedRows = 500;
244569 return SQLITE_OK;
244570 }
244571
244572
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.41.0"
150150
#define SQLITE_VERSION_NUMBER 3041000
151
-#define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
151
+#define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -3296,12 +3296,12 @@
32963296
**
32973297
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
32983298
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
32993299
** information as is provided by the [sqlite3_profile()] callback.
33003300
** ^The P argument is a pointer to the [prepared statement] and the
3301
-** X argument points to a 64-bit integer which is the estimated of
3302
-** the number of nanosecond that the prepared statement took to run.
3301
+** X argument points to a 64-bit integer which is approximately
3302
+** the number of nanoseconds that the prepared statement took to run.
33033303
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
33043304
**
33053305
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
33063306
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
33073307
** statement generates a single row of result.
33083308
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.41.0"
150 #define SQLITE_VERSION_NUMBER 3041000
151 #define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -3296,12 +3296,12 @@
3296 **
3297 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3298 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3299 ** information as is provided by the [sqlite3_profile()] callback.
3300 ** ^The P argument is a pointer to the [prepared statement] and the
3301 ** X argument points to a 64-bit integer which is the estimated of
3302 ** the number of nanosecond that the prepared statement took to run.
3303 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3304 **
3305 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3306 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3307 ** statement generates a single row of result.
3308
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.41.0"
150 #define SQLITE_VERSION_NUMBER 3041000
151 #define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -3296,12 +3296,12 @@
3296 **
3297 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3298 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3299 ** information as is provided by the [sqlite3_profile()] callback.
3300 ** ^The P argument is a pointer to the [prepared statement] and the
3301 ** X argument points to a 64-bit integer which is approximately
3302 ** the number of nanoseconds that the prepared statement took to run.
3303 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3304 **
3305 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3306 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3307 ** statement generates a single row of result.
3308
+29
--- src/db.c
+++ src/db.c
@@ -485,10 +485,28 @@
485485
/*
486486
** Every Fossil database connection automatically registers the following
487487
** overarching authenticator callback, and leaves it registered for the
488488
** duration of the connection. This authenticator will call any
489489
** sub-authenticators that are registered using db_set_authorizer().
490
+**
491
+** == Testing Notes ==
492
+**
493
+** Run Fossil as using a command like this:
494
+**
495
+** ./fossil sql --test --errorlog -
496
+**
497
+** Then enter SQL commands like one of these:
498
+**
499
+** SELECT db_protect('user');
500
+** SELECT db_protect('config');
501
+** SELECT db_protect('sensitive');
502
+** SELECT db_protect('readonly');
503
+** SELECT db_protect('all');
504
+**
505
+** Then try to do SQL statements that would violate the constraints and
506
+** verify that SECURITY warnings appear in the error log output. See
507
+** also the sqlcmd_db_protect() function in sqlcmd.c.
490508
*/
491509
int db_top_authorizer(
492510
void *pNotUsed,
493511
int eCode,
494512
const char *z0,
@@ -501,27 +519,38 @@
501519
case SQLITE_INSERT:
502520
case SQLITE_UPDATE:
503521
case SQLITE_DELETE: {
504522
if( (db.protectMask & PROTECT_USER)!=0
505523
&& sqlite3_stricmp(z0,"user")==0 ){
524
+ fossil_errorlog(
525
+ "SECURITY: authorizer blocks DML on protected USER table\n");
506526
rc = SQLITE_DENY;
507527
}else if( (db.protectMask & PROTECT_CONFIG)!=0 &&
508528
(sqlite3_stricmp(z0,"config")==0 ||
509529
sqlite3_stricmp(z0,"global_config")==0) ){
530
+ fossil_errorlog(
531
+ "SECURITY: authorizer blocks DML on protected table \"%s\"\n", z0);
510532
rc = SQLITE_DENY;
511533
}else if( (db.protectMask & PROTECT_SENSITIVE)!=0 &&
512534
sqlite3_stricmp(z0,"global_config")==0 ){
535
+ fossil_errorlog(
536
+ "SECURITY: authorizer blocks DML on protected GLOBAL_CONFIG table\n");
513537
rc = SQLITE_DENY;
514538
}else if( (db.protectMask & PROTECT_READONLY)!=0
515539
&& sqlite3_stricmp(z2,"temp")!=0 ){
540
+ fossil_errorlog(
541
+ "SECURITY: authorizer blocks DML on table \"%s\" due to the\n"
542
+ "request coming from a different origin\n", z0);
516543
rc = SQLITE_DENY;
517544
}
518545
break;
519546
}
520547
case SQLITE_DROP_TEMP_TRIGGER: {
521548
/* Do not allow the triggers that enforce PROTECT_SENSITIVE
522549
** to be dropped */
550
+ fossil_errorlog(
551
+ "SECURITY: authorizer blocks attempt to drop a temporary trigger\n");
523552
rc = SQLITE_DENY;
524553
break;
525554
}
526555
}
527556
if( db.xAuth && rc==SQLITE_OK ){
528557
--- src/db.c
+++ src/db.c
@@ -485,10 +485,28 @@
485 /*
486 ** Every Fossil database connection automatically registers the following
487 ** overarching authenticator callback, and leaves it registered for the
488 ** duration of the connection. This authenticator will call any
489 ** sub-authenticators that are registered using db_set_authorizer().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490 */
491 int db_top_authorizer(
492 void *pNotUsed,
493 int eCode,
494 const char *z0,
@@ -501,27 +519,38 @@
501 case SQLITE_INSERT:
502 case SQLITE_UPDATE:
503 case SQLITE_DELETE: {
504 if( (db.protectMask & PROTECT_USER)!=0
505 && sqlite3_stricmp(z0,"user")==0 ){
 
 
506 rc = SQLITE_DENY;
507 }else if( (db.protectMask & PROTECT_CONFIG)!=0 &&
508 (sqlite3_stricmp(z0,"config")==0 ||
509 sqlite3_stricmp(z0,"global_config")==0) ){
 
 
510 rc = SQLITE_DENY;
511 }else if( (db.protectMask & PROTECT_SENSITIVE)!=0 &&
512 sqlite3_stricmp(z0,"global_config")==0 ){
 
 
513 rc = SQLITE_DENY;
514 }else if( (db.protectMask & PROTECT_READONLY)!=0
515 && sqlite3_stricmp(z2,"temp")!=0 ){
 
 
 
516 rc = SQLITE_DENY;
517 }
518 break;
519 }
520 case SQLITE_DROP_TEMP_TRIGGER: {
521 /* Do not allow the triggers that enforce PROTECT_SENSITIVE
522 ** to be dropped */
 
 
523 rc = SQLITE_DENY;
524 break;
525 }
526 }
527 if( db.xAuth && rc==SQLITE_OK ){
528
--- src/db.c
+++ src/db.c
@@ -485,10 +485,28 @@
485 /*
486 ** Every Fossil database connection automatically registers the following
487 ** overarching authenticator callback, and leaves it registered for the
488 ** duration of the connection. This authenticator will call any
489 ** sub-authenticators that are registered using db_set_authorizer().
490 **
491 ** == Testing Notes ==
492 **
493 ** Run Fossil as using a command like this:
494 **
495 ** ./fossil sql --test --errorlog -
496 **
497 ** Then enter SQL commands like one of these:
498 **
499 ** SELECT db_protect('user');
500 ** SELECT db_protect('config');
501 ** SELECT db_protect('sensitive');
502 ** SELECT db_protect('readonly');
503 ** SELECT db_protect('all');
504 **
505 ** Then try to do SQL statements that would violate the constraints and
506 ** verify that SECURITY warnings appear in the error log output. See
507 ** also the sqlcmd_db_protect() function in sqlcmd.c.
508 */
509 int db_top_authorizer(
510 void *pNotUsed,
511 int eCode,
512 const char *z0,
@@ -501,27 +519,38 @@
519 case SQLITE_INSERT:
520 case SQLITE_UPDATE:
521 case SQLITE_DELETE: {
522 if( (db.protectMask & PROTECT_USER)!=0
523 && sqlite3_stricmp(z0,"user")==0 ){
524 fossil_errorlog(
525 "SECURITY: authorizer blocks DML on protected USER table\n");
526 rc = SQLITE_DENY;
527 }else if( (db.protectMask & PROTECT_CONFIG)!=0 &&
528 (sqlite3_stricmp(z0,"config")==0 ||
529 sqlite3_stricmp(z0,"global_config")==0) ){
530 fossil_errorlog(
531 "SECURITY: authorizer blocks DML on protected table \"%s\"\n", z0);
532 rc = SQLITE_DENY;
533 }else if( (db.protectMask & PROTECT_SENSITIVE)!=0 &&
534 sqlite3_stricmp(z0,"global_config")==0 ){
535 fossil_errorlog(
536 "SECURITY: authorizer blocks DML on protected GLOBAL_CONFIG table\n");
537 rc = SQLITE_DENY;
538 }else if( (db.protectMask & PROTECT_READONLY)!=0
539 && sqlite3_stricmp(z2,"temp")!=0 ){
540 fossil_errorlog(
541 "SECURITY: authorizer blocks DML on table \"%s\" due to the\n"
542 "request coming from a different origin\n", z0);
543 rc = SQLITE_DENY;
544 }
545 break;
546 }
547 case SQLITE_DROP_TEMP_TRIGGER: {
548 /* Do not allow the triggers that enforce PROTECT_SENSITIVE
549 ** to be dropped */
550 fossil_errorlog(
551 "SECURITY: authorizer blocks attempt to drop a temporary trigger\n");
552 rc = SQLITE_DENY;
553 break;
554 }
555 }
556 if( db.xAuth && rc==SQLITE_OK ){
557

Keyboard Shortcuts

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