Fossil SCM

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

drh 2025-10-02 14:14 trunk
Commit 3ca3a6a667cf23765ec527e00a2898bc94a8d93b95e25add39138d65b485d446
+365 -276
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1495,12 +1495,12 @@
14951495
v = (v<<4) + x;
14961496
zArg++;
14971497
}
14981498
}else{
14991499
while( IsDigit(zArg[0]) ){
1500
- if( v>=922337203685477580 ){
1501
- if( v>922337203685477580 || zArg[0]>='8' ) goto integer_overflow;
1500
+ if( v>=922337203685477580LL ){
1501
+ if( v>922337203685477580LL || zArg[0]>='8' ) goto integer_overflow;
15021502
}
15031503
v = v*10 + (zArg[0] - '0');
15041504
zArg++;
15051505
}
15061506
}
@@ -6125,23 +6125,24 @@
61256125
** Examples:
61266126
**
61276127
** SELECT * FROM generate_series(0,100,5);
61286128
**
61296129
** The query above returns integers from 0 through 100 counting by steps
6130
-** of 5.
6130
+** of 5. In other words, 0, 5, 10, 15, ..., 90, 95, 100. There are a total
6131
+** of 21 rows.
61316132
**
61326133
** SELECT * FROM generate_series(0,100);
61336134
**
6134
-** Integers from 0 through 100 with a step size of 1.
6135
+** Integers from 0 through 100 with a step size of 1. 101 rows.
61356136
**
61366137
** SELECT * FROM generate_series(20) LIMIT 10;
61376138
**
6138
-** Integers 20 through 29.
6139
+** Integers 20 through 29. 10 rows.
61396140
**
61406141
** SELECT * FROM generate_series(0,-100,-5);
61416142
**
6142
-** Integers 0 -5 -10 ... -100.
6143
+** Integers 0 -5 -10 ... -100. 21 rows.
61436144
**
61446145
** SELECT * FROM generate_series(0,-1);
61456146
**
61466147
** Empty sequence.
61476148
**
@@ -6213,143 +6214,92 @@
62136214
#include <string.h>
62146215
#include <limits.h>
62156216
#include <math.h>
62166217
62176218
#ifndef SQLITE_OMIT_VIRTUALTABLE
6218
-/*
6219
-** Return that member of a generate_series(...) sequence whose 0-based
6220
-** index is ix. The 0th member is given by smBase. The sequence members
6221
-** progress per ix increment by smStep.
6222
-*/
6223
-static sqlite3_int64 genSeqMember(
6224
- sqlite3_int64 smBase,
6225
- sqlite3_int64 smStep,
6226
- sqlite3_uint64 ix
6227
-){
6228
- static const sqlite3_uint64 mxI64 =
6229
- ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff;
6230
- if( ix>=mxI64 ){
6231
- /* Get ix into signed i64 range. */
6232
- ix -= mxI64;
6233
- /* With 2's complement ALU, this next can be 1 step, but is split into
6234
- * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
6235
- smBase += (mxI64/2) * smStep;
6236
- smBase += (mxI64 - mxI64/2) * smStep;
6237
- }
6238
- /* Under UBSAN (or on 1's complement machines), must do this last term
6239
- * in steps to avoid the dreaded (and harmless) signed multiply overflow. */
6240
- if( ix>=2 ){
6241
- sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
6242
- smBase += ix2*smStep;
6243
- ix -= ix2;
6244
- }
6245
- return smBase + ((sqlite3_int64)ix)*smStep;
6246
-}
6247
-
6248
-/* typedef unsigned char u8; */
6249
-
6250
-typedef struct SequenceSpec {
6251
- sqlite3_int64 iOBase; /* Original starting value ("start") */
6252
- sqlite3_int64 iOTerm; /* Original terminal value ("stop") */
6253
- sqlite3_int64 iBase; /* Starting value to actually use */
6254
- sqlite3_int64 iTerm; /* Terminal value to actually use */
6255
- sqlite3_int64 iStep; /* Increment ("step") */
6256
- sqlite3_uint64 uSeqIndexMax; /* maximum sequence index (aka "n") */
6257
- sqlite3_uint64 uSeqIndexNow; /* Current index during generation */
6258
- sqlite3_int64 iValueNow; /* Current value during generation */
6259
- u8 isNotEOF; /* Sequence generation not exhausted */
6260
- u8 isReversing; /* Sequence is being reverse generated */
6261
-} SequenceSpec;
6262
-
6263
-/*
6264
-** Prepare a SequenceSpec for use in generating an integer series
6265
-** given initialized iBase, iTerm and iStep values. Sequence is
6266
-** initialized per given isReversing. Other members are computed.
6267
-*/
6268
-static void setupSequence( SequenceSpec *pss ){
6269
- int bSameSigns;
6270
- pss->uSeqIndexMax = 0;
6271
- pss->isNotEOF = 0;
6272
- bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0);
6273
- if( pss->iTerm < pss->iBase ){
6274
- sqlite3_uint64 nuspan = 0;
6275
- if( bSameSigns ){
6276
- nuspan = (sqlite3_uint64)(pss->iBase - pss->iTerm);
6277
- }else{
6278
- /* Under UBSAN (or on 1's complement machines), must do this in steps.
6279
- * In this clause, iBase>=0 and iTerm<0 . */
6280
- nuspan = 1;
6281
- nuspan += pss->iBase;
6282
- nuspan += -(pss->iTerm+1);
6283
- }
6284
- if( pss->iStep<0 ){
6285
- pss->isNotEOF = 1;
6286
- if( nuspan==ULONG_MAX ){
6287
- pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
6288
- }else if( pss->iStep>LLONG_MIN ){
6289
- pss->uSeqIndexMax = nuspan/-pss->iStep;
6290
- }
6291
- }
6292
- }else if( pss->iTerm > pss->iBase ){
6293
- sqlite3_uint64 puspan = 0;
6294
- if( bSameSigns ){
6295
- puspan = (sqlite3_uint64)(pss->iTerm - pss->iBase);
6296
- }else{
6297
- /* Under UBSAN (or on 1's complement machines), must do this in steps.
6298
- * In this clause, iTerm>=0 and iBase<0 . */
6299
- puspan = 1;
6300
- puspan += pss->iTerm;
6301
- puspan += -(pss->iBase+1);
6302
- }
6303
- if( pss->iStep>0 ){
6304
- pss->isNotEOF = 1;
6305
- pss->uSeqIndexMax = puspan/pss->iStep;
6306
- }
6307
- }else if( pss->iTerm == pss->iBase ){
6308
- pss->isNotEOF = 1;
6309
- pss->uSeqIndexMax = 0;
6310
- }
6311
- pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
6312
- pss->iValueNow = (pss->isReversing)
6313
- ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
6314
- : pss->iBase;
6315
-}
6316
-
6317
-/*
6318
-** Progress sequence generator to yield next value, if any.
6319
-** Leave its state to either yield next value or be at EOF.
6320
-** Return whether there is a next value, or 0 at EOF.
6321
-*/
6322
-static int progressSequence( SequenceSpec *pss ){
6323
- if( !pss->isNotEOF ) return 0;
6324
- if( pss->isReversing ){
6325
- if( pss->uSeqIndexNow > 0 ){
6326
- pss->uSeqIndexNow--;
6327
- pss->iValueNow -= pss->iStep;
6328
- }else{
6329
- pss->isNotEOF = 0;
6330
- }
6331
- }else{
6332
- if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
6333
- pss->uSeqIndexNow++;
6334
- pss->iValueNow += pss->iStep;
6335
- }else{
6336
- pss->isNotEOF = 0;
6337
- }
6338
- }
6339
- return pss->isNotEOF;
6340
-}
63416219
63426220
/* series_cursor is a subclass of sqlite3_vtab_cursor which will
63436221
** serve as the underlying representation of a cursor that scans
6344
-** over rows of the result
6222
+** over rows of the result.
6223
+**
6224
+** iOBase, iOTerm, and iOStep are the original values of the
6225
+** start=, stop=, and step= constraints on the query. These are
6226
+** the values reported by the start, stop, and step columns of the
6227
+** virtual table.
6228
+**
6229
+** iBase, iTerm, iStep, and bDescp are the actual values used to generate
6230
+** the sequence. These might be different from the iOxxxx values.
6231
+** For example in
6232
+**
6233
+** SELECT value FROM generate_series(1,11,2)
6234
+** WHERE value BETWEEN 4 AND 8;
6235
+**
6236
+** The iOBase is 1, but the iBase is 5. iOTerm is 11 but iTerm is 7.
6237
+** Another example:
6238
+**
6239
+** SELECT value FROM generate_series(1,15,3) ORDER BY value DESC;
6240
+**
6241
+** The cursor initialization for the above query is:
6242
+**
6243
+** iOBase = 1 iBase = 13
6244
+** iOTerm = 15 iTerm = 1
6245
+** iOStep = 3 iStep = 3 bDesc = 1
6246
+**
6247
+** The actual step size is unsigned so that can have a value of
6248
+** +9223372036854775808 which is needed for querys like this:
6249
+**
6250
+** SELECT value
6251
+** FROM generate_series(9223372036854775807,
6252
+** -9223372036854775808,
6253
+** -9223372036854775808)
6254
+** ORDER BY value ASC;
6255
+**
6256
+** The setup for the previous query will be:
6257
+**
6258
+** iOBase = 9223372036854775807 iBase = -1
6259
+** iOTerm = -9223372036854775808 iTerm = 9223372036854775807
6260
+** iOStep = -9223372036854775808 iStep = 9223372036854775808 bDesc = 0
63456261
*/
6262
+/* typedef unsigned char u8; */
63466263
typedef struct series_cursor series_cursor;
63476264
struct series_cursor {
63486265
sqlite3_vtab_cursor base; /* Base class - must be first */
6349
- SequenceSpec ss; /* (this) Derived class data */
6266
+ sqlite3_int64 iOBase; /* Original starting value ("start") */
6267
+ sqlite3_int64 iOTerm; /* Original terminal value ("stop") */
6268
+ sqlite3_int64 iOStep; /* Original step value */
6269
+ sqlite3_int64 iBase; /* Starting value to actually use */
6270
+ sqlite3_int64 iTerm; /* Terminal value to actually use */
6271
+ sqlite3_uint64 iStep; /* The step size */
6272
+ sqlite3_int64 iValue; /* Current value */
6273
+ u8 bDesc; /* iStep is really negative */
6274
+ u8 bDone; /* True if stepped past last element */
63506275
};
6276
+
6277
+/*
6278
+** Computed the difference between two 64-bit signed integers using a
6279
+** convoluted computation designed to work around the silly restriction
6280
+** against signed integer overflow in C.
6281
+*/
6282
+static sqlite3_uint64 span64(sqlite3_int64 a, sqlite3_int64 b){
6283
+ assert( a>=b );
6284
+ return (*(sqlite3_uint64*)&a) - (*(sqlite3_uint64*)&b);
6285
+}
6286
+
6287
+/*
6288
+** Add or substract an unsigned 64-bit integer from a signed 64-bit integer
6289
+** and return the new signed 64-bit integer.
6290
+*/
6291
+static sqlite3_int64 add64(sqlite3_int64 a, sqlite3_uint64 b){
6292
+ sqlite3_uint64 x = *(sqlite3_uint64*)&a;
6293
+ x += b;
6294
+ return *(sqlite3_int64*)&x;
6295
+}
6296
+static sqlite3_int64 sub64(sqlite3_int64 a, sqlite3_uint64 b){
6297
+ sqlite3_uint64 x = *(sqlite3_uint64*)&a;
6298
+ x -= b;
6299
+ return *(sqlite3_int64*)&x;
6300
+}
63516301
63526302
/*
63536303
** The seriesConnect() method is invoked to create a new
63546304
** series_vtab that describes the generate_series virtual table.
63556305
**
@@ -6427,11 +6377,19 @@
64276377
/*
64286378
** Advance a series_cursor to its next row of output.
64296379
*/
64306380
static int seriesNext(sqlite3_vtab_cursor *cur){
64316381
series_cursor *pCur = (series_cursor*)cur;
6432
- progressSequence( & pCur->ss );
6382
+ if( pCur->iValue==pCur->iTerm ){
6383
+ pCur->bDone = 1;
6384
+ }else if( pCur->bDesc ){
6385
+ pCur->iValue = sub64(pCur->iValue, pCur->iStep);
6386
+ assert( pCur->iValue>=pCur->iTerm );
6387
+ }else{
6388
+ pCur->iValue = add64(pCur->iValue, pCur->iStep);
6389
+ assert( pCur->iValue<=pCur->iTerm );
6390
+ }
64336391
return SQLITE_OK;
64346392
}
64356393
64366394
/*
64376395
** Return values of columns for the row at which the series_cursor
@@ -6443,50 +6401,64 @@
64436401
int i /* Which column to return */
64446402
){
64456403
series_cursor *pCur = (series_cursor*)cur;
64466404
sqlite3_int64 x = 0;
64476405
switch( i ){
6448
- case SERIES_COLUMN_START: x = pCur->ss.iOBase; break;
6449
- case SERIES_COLUMN_STOP: x = pCur->ss.iOTerm; break;
6450
- case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
6451
- default: x = pCur->ss.iValueNow; break;
6406
+ case SERIES_COLUMN_START: x = pCur->iOBase; break;
6407
+ case SERIES_COLUMN_STOP: x = pCur->iOTerm; break;
6408
+ case SERIES_COLUMN_STEP: x = pCur->iOStep; break;
6409
+ default: x = pCur->iValue; break;
64526410
}
64536411
sqlite3_result_int64(ctx, x);
64546412
return SQLITE_OK;
64556413
}
64566414
64576415
#ifndef LARGEST_UINT64
6458
-#define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
6459
-#define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
6460
-#define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
6416
+#define LARGEST_INT64 ((sqlite3_int64)0x7fffffffffffffffLL)
6417
+#define LARGEST_UINT64 ((sqlite3_uint64)0xffffffffffffffffULL)
6418
+#define SMALLEST_INT64 ((sqlite3_int64)0x8000000000000000LL)
64616419
#endif
64626420
64636421
/*
64646422
** The rowid is the same as the value.
64656423
*/
64666424
static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
64676425
series_cursor *pCur = (series_cursor*)cur;
6468
- *pRowid = pCur->ss.iValueNow;
6426
+ *pRowid = pCur->iValue;
64696427
return SQLITE_OK;
64706428
}
64716429
64726430
/*
64736431
** Return TRUE if the cursor has been moved off of the last
64746432
** row of output.
64756433
*/
64766434
static int seriesEof(sqlite3_vtab_cursor *cur){
64776435
series_cursor *pCur = (series_cursor*)cur;
6478
- return !pCur->ss.isNotEOF;
6436
+ return pCur->bDone;
64796437
}
64806438
64816439
/* True to cause run-time checking of the start=, stop=, and/or step=
64826440
** parameters. The only reason to do this is for testing the
64836441
** constraint checking logic for virtual tables in the SQLite core.
64846442
*/
64856443
#ifndef SQLITE_SERIES_CONSTRAINT_VERIFY
64866444
# define SQLITE_SERIES_CONSTRAINT_VERIFY 0
64876445
#endif
6446
+
6447
+/*
6448
+** Return the number of steps between pCur->iBase and pCur->iTerm if
6449
+** the step width is pCur->iStep.
6450
+*/
6451
+static sqlite3_uint64 seriesSteps(series_cursor *pCur){
6452
+ if( pCur->bDesc ){
6453
+ assert( pCur->iBase >= pCur->iTerm );
6454
+ return span64(pCur->iBase, pCur->iTerm)/pCur->iStep;
6455
+ }else{
6456
+ assert( pCur->iBase <= pCur->iTerm );
6457
+ return span64(pCur->iTerm, pCur->iBase)/pCur->iStep;
6458
+ }
6459
+}
64886460
64896461
/*
64906462
** This method is called to "rewind" the series_cursor object back
64916463
** to the first row of output. This method is always called at least
64926464
** once prior to any call to seriesColumn() or seriesRowid() or
@@ -6517,189 +6489,244 @@
65176489
sqlite3_vtab_cursor *pVtabCursor,
65186490
int idxNum, const char *idxStrUnused,
65196491
int argc, sqlite3_value **argv
65206492
){
65216493
series_cursor *pCur = (series_cursor *)pVtabCursor;
6522
- int i = 0;
6523
- int returnNoRows = 0;
6524
- sqlite3_int64 iMin = SMALLEST_INT64;
6525
- sqlite3_int64 iMax = LARGEST_INT64;
6526
- sqlite3_int64 iLimit = 0;
6527
- sqlite3_int64 iOffset = 0;
6494
+ int iArg = 0; /* Arguments used so far */
6495
+ int i; /* Loop counter */
6496
+ sqlite3_int64 iMin = SMALLEST_INT64; /* Smallest allowed output value */
6497
+ sqlite3_int64 iMax = LARGEST_INT64; /* Largest allowed output value */
6498
+ sqlite3_int64 iLimit = 0; /* if >0, the value of the LIMIT */
6499
+ sqlite3_int64 iOffset = 0; /* if >0, the value of the OFFSET */
65286500
65296501
(void)idxStrUnused;
6502
+
6503
+ /* If any constraints have a NULL value, then return no rows.
6504
+ ** See ticket https://sqlite.org/src/info/fac496b61722daf2
6505
+ */
6506
+ for(i=0; i<argc; i++){
6507
+ if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
6508
+ goto series_no_rows;
6509
+ }
6510
+ }
6511
+
6512
+ /* Capture the three HIDDEN parameters to the virtual table and insert
6513
+ ** default values for any parameters that are omitted.
6514
+ */
65306515
if( idxNum & 0x01 ){
6531
- pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
6516
+ pCur->iOBase = sqlite3_value_int64(argv[iArg++]);
65326517
}else{
6533
- pCur->ss.iBase = 0;
6518
+ pCur->iOBase = 0;
65346519
}
65356520
if( idxNum & 0x02 ){
6536
- pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
6521
+ pCur->iOTerm = sqlite3_value_int64(argv[iArg++]);
65376522
}else{
6538
- pCur->ss.iTerm = 0xffffffff;
6523
+ pCur->iOTerm = 0xffffffff;
65396524
}
65406525
if( idxNum & 0x04 ){
6541
- pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
6542
- if( pCur->ss.iStep==0 ){
6543
- pCur->ss.iStep = 1;
6544
- }else if( pCur->ss.iStep<0 ){
6545
- if( (idxNum & 0x10)==0 ) idxNum |= 0x08;
6546
- }
6526
+ pCur->iOStep = sqlite3_value_int64(argv[iArg++]);
6527
+ if( pCur->iOStep==0 ) pCur->iOStep = 1;
65476528
}else{
6548
- pCur->ss.iStep = 1;
6529
+ pCur->iOStep = 1;
65496530
}
65506531
65516532
/* If there are constraints on the value column but there are
65526533
** no constraints on the start, stop, and step columns, then
65536534
** initialize the default range to be the entire range of 64-bit signed
65546535
** integers. This range will contracted by the value column constraints
65556536
** further below.
65566537
*/
65576538
if( (idxNum & 0x05)==0 && (idxNum & 0x0380)!=0 ){
6558
- pCur->ss.iBase = SMALLEST_INT64;
6539
+ pCur->iOBase = SMALLEST_INT64;
65596540
}
65606541
if( (idxNum & 0x06)==0 && (idxNum & 0x3080)!=0 ){
6561
- pCur->ss.iTerm = LARGEST_INT64;
6542
+ pCur->iOTerm = LARGEST_INT64;
65626543
}
6563
- pCur->ss.iOBase = pCur->ss.iBase;
6564
- pCur->ss.iOTerm = pCur->ss.iTerm;
6544
+ pCur->iBase = pCur->iOBase;
6545
+ pCur->iTerm = pCur->iOTerm;
6546
+ if( pCur->iOStep>0 ){
6547
+ pCur->iStep = pCur->iOStep;
6548
+ }else if( pCur->iOStep>SMALLEST_INT64 ){
6549
+ pCur->iStep = -pCur->iOStep;
6550
+ }else{
6551
+ pCur->iStep = LARGEST_INT64;
6552
+ pCur->iStep++;
6553
+ }
6554
+ pCur->bDesc = pCur->iOStep<0;
6555
+ if( pCur->bDesc==0 && pCur->iBase>pCur->iTerm ){
6556
+ goto series_no_rows;
6557
+ }
6558
+ if( pCur->bDesc!=0 && pCur->iBase<pCur->iTerm ){
6559
+ goto series_no_rows;
6560
+ }
65656561
65666562
/* Extract the LIMIT and OFFSET values, but do not apply them yet.
65676563
** The range must first be constrained by the limits on value.
65686564
*/
65696565
if( idxNum & 0x20 ){
6570
- iLimit = sqlite3_value_int64(argv[i++]);
6566
+ iLimit = sqlite3_value_int64(argv[iArg++]);
65716567
if( idxNum & 0x40 ){
6572
- iOffset = sqlite3_value_int64(argv[i++]);
6568
+ iOffset = sqlite3_value_int64(argv[iArg++]);
65736569
}
65746570
}
65756571
6572
+ /* Narrow the range of iMin and iMax (the minimum and maximum outputs)
6573
+ ** based on equality and inequality constraints on the "value" column.
6574
+ */
65766575
if( idxNum & 0x3380 ){
6577
- /* Extract the maximum range of output values determined by
6578
- ** constraints on the "value" column.
6579
- */
6580
- if( idxNum & 0x0080 ){
6581
- if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6582
- double r = sqlite3_value_double(argv[i++]);
6583
- if( r==ceil(r) ){
6576
+ if( idxNum & 0x0080 ){ /* value=X */
6577
+ if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
6578
+ double r = sqlite3_value_double(argv[iArg++]);
6579
+ if( r==ceil(r)
6580
+ && r>=(double)SMALLEST_INT64
6581
+ && r<=(double)LARGEST_INT64
6582
+ ){
65846583
iMin = iMax = (sqlite3_int64)r;
65856584
}else{
6586
- returnNoRows = 1;
6585
+ goto series_no_rows;
65876586
}
65886587
}else{
6589
- iMin = iMax = sqlite3_value_int64(argv[i++]);
6588
+ iMin = iMax = sqlite3_value_int64(argv[iArg++]);
65906589
}
65916590
}else{
6592
- if( idxNum & 0x0300 ){
6593
- if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6594
- double r = sqlite3_value_double(argv[i++]);
6595
- if( idxNum & 0x0200 && r==ceil(r) ){
6591
+ if( idxNum & 0x0300 ){ /* value>X or value>=X */
6592
+ if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
6593
+ double r = sqlite3_value_double(argv[iArg++]);
6594
+ if( r<(double)SMALLEST_INT64 ){
6595
+ iMin = SMALLEST_INT64;
6596
+ }else if( (idxNum & 0x0200)!=0 && r==ceil(r) ){
65966597
iMin = (sqlite3_int64)ceil(r+1.0);
65976598
}else{
65986599
iMin = (sqlite3_int64)ceil(r);
65996600
}
66006601
}else{
6601
- iMin = sqlite3_value_int64(argv[i++]);
6602
- if( idxNum & 0x0200 ){
6602
+ iMin = sqlite3_value_int64(argv[iArg++]);
6603
+ if( (idxNum & 0x0200)!=0 ){
66036604
if( iMin==LARGEST_INT64 ){
6604
- returnNoRows = 1;
6605
+ goto series_no_rows;
66056606
}else{
66066607
iMin++;
66076608
}
66086609
}
66096610
}
66106611
}
6611
- if( idxNum & 0x3000 ){
6612
- if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6613
- double r = sqlite3_value_double(argv[i++]);
6614
- if( (idxNum & 0x2000)!=0 && r==floor(r) ){
6612
+ if( idxNum & 0x3000 ){ /* value<X or value<=X */
6613
+ if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
6614
+ double r = sqlite3_value_double(argv[iArg++]);
6615
+ if( r>(double)LARGEST_INT64 ){
6616
+ iMax = LARGEST_INT64;
6617
+ }else if( (idxNum & 0x2000)!=0 && r==floor(r) ){
66156618
iMax = (sqlite3_int64)(r-1.0);
66166619
}else{
66176620
iMax = (sqlite3_int64)floor(r);
66186621
}
66196622
}else{
6620
- iMax = sqlite3_value_int64(argv[i++]);
6623
+ iMax = sqlite3_value_int64(argv[iArg++]);
66216624
if( idxNum & 0x2000 ){
66226625
if( iMax==SMALLEST_INT64 ){
6623
- returnNoRows = 1;
6626
+ goto series_no_rows;
66246627
}else{
66256628
iMax--;
66266629
}
66276630
}
66286631
}
66296632
}
66306633
if( iMin>iMax ){
6631
- returnNoRows = 1;
6634
+ goto series_no_rows;
66326635
}
66336636
}
66346637
66356638
/* Try to reduce the range of values to be generated based on
66366639
** constraints on the "value" column.
66376640
*/
6638
- if( pCur->ss.iStep>0 ){
6639
- sqlite3_int64 szStep = pCur->ss.iStep;
6640
- if( pCur->ss.iBase<iMin ){
6641
- sqlite3_uint64 d = iMin - pCur->ss.iBase;
6642
- pCur->ss.iBase += ((d+szStep-1)/szStep)*szStep;
6643
- }
6644
- if( pCur->ss.iTerm>iMax ){
6645
- pCur->ss.iTerm = iMax;
6641
+ if( pCur->bDesc==0 ){
6642
+ if( pCur->iBase<iMin ){
6643
+ sqlite3_uint64 span = span64(iMin,pCur->iBase);
6644
+ pCur->iBase = add64(pCur->iBase, (span/pCur->iStep)*pCur->iStep);
6645
+ if( pCur->iBase<iMin ){
6646
+ if( pCur->iBase > sub64(LARGEST_INT64, pCur->iStep) ){
6647
+ goto series_no_rows;
6648
+ }
6649
+ pCur->iBase = add64(pCur->iBase, pCur->iStep);
6650
+ }
6651
+ }
6652
+ if( pCur->iTerm>iMax ){
6653
+ pCur->iTerm = iMax;
66466654
}
66476655
}else{
6648
- sqlite3_int64 szStep = -pCur->ss.iStep;
6649
- assert( szStep>0 );
6650
- if( pCur->ss.iBase>iMax ){
6651
- sqlite3_uint64 d = pCur->ss.iBase - iMax;
6652
- pCur->ss.iBase -= ((d+szStep-1)/szStep)*szStep;
6653
- }
6654
- if( pCur->ss.iTerm<iMin ){
6655
- pCur->ss.iTerm = iMin;
6656
+ if( pCur->iBase>iMax ){
6657
+ sqlite3_uint64 span = span64(pCur->iBase,iMax);
6658
+ pCur->iBase = sub64(pCur->iBase, (span/pCur->iStep)*pCur->iStep);
6659
+ if( pCur->iBase>iMax ){
6660
+ if( pCur->iBase < add64(SMALLEST_INT64, pCur->iStep) ){
6661
+ goto series_no_rows;
6662
+ }
6663
+ pCur->iBase = sub64(pCur->iBase, pCur->iStep);
6664
+ }
6665
+ }
6666
+ if( pCur->iTerm<iMin ){
6667
+ pCur->iTerm = iMin;
66566668
}
66576669
}
66586670
}
6671
+
6672
+ /* Adjust iTerm so that it is exactly the last value of the series.
6673
+ */
6674
+ if( pCur->bDesc==0 ){
6675
+ if( pCur->iBase>pCur->iTerm ){
6676
+ goto series_no_rows;
6677
+ }
6678
+ pCur->iTerm = sub64(pCur->iTerm,
6679
+ span64(pCur->iTerm,pCur->iBase) % pCur->iStep);
6680
+ }else{
6681
+ if( pCur->iBase<pCur->iTerm ){
6682
+ goto series_no_rows;
6683
+ }
6684
+ pCur->iTerm = add64(pCur->iTerm,
6685
+ span64(pCur->iBase,pCur->iTerm) % pCur->iStep);
6686
+ }
6687
+
6688
+ /* Transform the series generator to output values in the requested
6689
+ ** order.
6690
+ */
6691
+ if( ((idxNum & 0x0008)!=0 && pCur->bDesc==0)
6692
+ || ((idxNum & 0x0010)!=0 && pCur->bDesc!=0)
6693
+ ){
6694
+ sqlite3_int64 tmp = pCur->iBase;
6695
+ pCur->iBase = pCur->iTerm;
6696
+ pCur->iTerm = tmp;
6697
+ pCur->bDesc = !pCur->bDesc;
6698
+ }
66596699
66606700
/* Apply LIMIT and OFFSET constraints, if any */
6701
+ assert( pCur->iStep!=0 );
66616702
if( idxNum & 0x20 ){
6703
+ sqlite3_uint64 nStep;
66626704
if( iOffset>0 ){
6663
- pCur->ss.iBase += pCur->ss.iStep*iOffset;
6664
- }
6665
- if( iLimit>=0 ){
6666
- sqlite3_int64 iTerm;
6667
- sqlite3_int64 mxLimit;
6668
- assert( pCur->ss.iStep>0 );
6669
- mxLimit = (LARGEST_INT64 - pCur->ss.iBase)/pCur->ss.iStep;
6670
- if( iLimit>mxLimit ) iLimit = mxLimit;
6671
- iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
6672
- if( pCur->ss.iStep<0 ){
6673
- if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6674
- }else{
6675
- if( iTerm<pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6676
- }
6677
- }
6678
- }
6679
-
6680
-
6681
- for(i=0; i<argc; i++){
6682
- if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
6683
- /* If any of the constraints have a NULL value, then return no rows.
6684
- ** See ticket https://sqlite.org/src/info/fac496b61722daf2 */
6685
- returnNoRows = 1;
6686
- break;
6687
- }
6688
- }
6689
- if( returnNoRows ){
6690
- pCur->ss.iBase = 1;
6691
- pCur->ss.iTerm = 0;
6692
- pCur->ss.iStep = 1;
6693
- }
6694
- if( idxNum & 0x08 ){
6695
- pCur->ss.isReversing = pCur->ss.iStep > 0;
6696
- }else{
6697
- pCur->ss.isReversing = pCur->ss.iStep < 0;
6698
- }
6699
- setupSequence( &pCur->ss );
6705
+ if( seriesSteps(pCur) < (sqlite3_uint64)iOffset ){
6706
+ goto series_no_rows;
6707
+ }else if( pCur->bDesc ){
6708
+ pCur->iBase = sub64(pCur->iBase, pCur->iStep*iOffset);
6709
+ }else{
6710
+ pCur->iBase = add64(pCur->iBase, pCur->iStep*iOffset);
6711
+ }
6712
+ }
6713
+ if( iLimit>=0 && (nStep = seriesSteps(pCur)) > (sqlite3_uint64)iLimit ){
6714
+ pCur->iTerm = add64(pCur->iBase, (iLimit - 1)*pCur->iStep);
6715
+ }
6716
+ }
6717
+ pCur->iValue = pCur->iBase;
6718
+ pCur->bDone = 0;
67006719
return SQLITE_OK;
6720
+
6721
+series_no_rows:
6722
+ pCur->iBase = 0;
6723
+ pCur->iTerm = 0;
6724
+ pCur->iStep = 1;
6725
+ pCur->bDesc = 0;
6726
+ pCur->bDone = 1;
6727
+ return SQLITE_OK;
67016728
}
67026729
67036730
/*
67046731
** SQLite will invoke this method one or more times while planning a query
67056732
** that uses the generate_series virtual table. This routine needs to create
@@ -9384,18 +9411,20 @@
93849411
if( idxNum & 1 ){
93859412
pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
93869413
if( pCur->nPrefix>0 ){
93879414
pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
93889415
if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
9416
+ pCur->nPrefix = (int)strlen(pCur->zPrefix);
93899417
}
93909418
iArg = 1;
93919419
}
93929420
if( idxNum & 2 ){
93939421
pCur->nLine = sqlite3_value_bytes(argv[iArg]);
93949422
if( pCur->nLine>0 ){
93959423
pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
93969424
if( pCur->zLine==0 ) return SQLITE_NOMEM;
9425
+ pCur->nLine = (int)strlen(pCur->zLine);
93979426
}
93989427
}
93999428
if( pCur->zLine!=0 && pCur->zPrefix==0 ){
94009429
int i = pCur->nLine;
94019430
while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
@@ -9403,10 +9432,11 @@
94039432
}
94049433
pCur->nPrefix = pCur->nLine - i;
94059434
if( pCur->nPrefix>0 ){
94069435
pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
94079436
if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
9437
+ pCur->nPrefix = (int)strlen(pCur->zPrefix);
94089438
}
94099439
}
94109440
pCur->iRowid = 0;
94119441
pCur->ePhase = COMPLETION_FIRST_PHASE;
94129442
return completionNext(pVtabCursor);
@@ -10316,13 +10346,18 @@
1031610346
"method," /* 6: Compression method (integer) */
1031710347
"z HIDDEN" /* 7: Name of zip file */
1031810348
") WITHOUT ROWID;";
1031910349
1032010350
#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
10321
-#define ZIPFILE_BUFFER_SIZE (64*1024)
1032210351
#define ZIPFILE_MX_NAME (250) /* Windows limitation on filename size */
1032310352
10353
+/*
10354
+** The buffer should be large enough to contain 3 65536 byte strings - the
10355
+** filename, the extra field and the file comment.
10356
+*/
10357
+#define ZIPFILE_BUFFER_SIZE (200*1024)
10358
+
1032410359
1032510360
/*
1032610361
** Magic numbers used to read and write zip files.
1032710362
**
1032810363
** ZIPFILE_NEWENTRY_MADEBY:
@@ -11000,10 +11035,19 @@
1100011035
|| mUnixTime==zipfileMtime(pCds)
1100111036
|| ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
1100211037
/* || (mUnixTime % 2) */
1100311038
);
1100411039
}
11040
+
11041
+/*
11042
+** Set (*pzErr) to point to a buffer from sqlite3_malloc() containing a
11043
+** generic corruption message and return SQLITE_CORRUPT;
11044
+*/
11045
+static int zipfileCorrupt(char **pzErr){
11046
+ *pzErr = sqlite3_mprintf("zip archive is corrupt");
11047
+ return SQLITE_CORRUPT;
11048
+}
1100511049
1100611050
/*
1100711051
** If aBlob is not NULL, then it is a pointer to a buffer (nBlob bytes in
1100811052
** size) containing an entire zip archive image. Or, if aBlob is NULL,
1100911053
** then pFile is a file-handle open on a zip file. In either case, this
@@ -11023,16 +11067,19 @@
1102311067
ZipfileEntry **ppEntry /* OUT: Pointer to new object */
1102411068
){
1102511069
u8 *aRead;
1102611070
char **pzErr = &pTab->base.zErrMsg;
1102711071
int rc = SQLITE_OK;
11028
- (void)nBlob;
1102911072
1103011073
if( aBlob==0 ){
1103111074
aRead = pTab->aBuffer;
1103211075
rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr);
1103311076
}else{
11077
+ if( (iOff+ZIPFILE_CDS_FIXED_SZ)>nBlob ){
11078
+ /* Not enough data for the CDS structure. Corruption. */
11079
+ return zipfileCorrupt(pzErr);
11080
+ }
1103411081
aRead = (u8*)&aBlob[iOff];
1103511082
}
1103611083
1103711084
if( rc==SQLITE_OK ){
1103811085
sqlite3_int64 nAlloc;
@@ -11059,10 +11106,13 @@
1105911106
rc = zipfileReadData(
1106011107
pFile, aRead, nExtra+nFile, iOff+ZIPFILE_CDS_FIXED_SZ, pzErr
1106111108
);
1106211109
}else{
1106311110
aRead = (u8*)&aBlob[iOff + ZIPFILE_CDS_FIXED_SZ];
11111
+ if( (iOff + ZIPFILE_LFH_FIXED_SZ + nFile + nExtra)>nBlob ){
11112
+ rc = zipfileCorrupt(pzErr);
11113
+ }
1106411114
}
1106511115
}
1106611116
1106711117
if( rc==SQLITE_OK ){
1106811118
u32 *pt = &pNew->mUnixTime;
@@ -11081,19 +11131,22 @@
1108111131
ZipfileLFH lfh;
1108211132
if( pFile ){
1108311133
rc = zipfileReadData(pFile, aRead, szFix, pNew->cds.iOffset, pzErr);
1108411134
}else{
1108511135
aRead = (u8*)&aBlob[pNew->cds.iOffset];
11136
+ if( (pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ)>nBlob ){
11137
+ rc = zipfileCorrupt(pzErr);
11138
+ }
1108611139
}
1108711140
1108811141
if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
1108911142
if( rc==SQLITE_OK ){
1109011143
pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
1109111144
pNew->iDataOff += lfh.nFile + lfh.nExtra;
1109211145
if( aBlob && pNew->cds.szCompressed ){
1109311146
if( pNew->iDataOff + pNew->cds.szCompressed > nBlob ){
11094
- rc = SQLITE_CORRUPT;
11147
+ rc = zipfileCorrupt(pzErr);
1109511148
}else{
1109611149
pNew->aData = &pNew->aExtra[nExtra];
1109711150
memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
1109811151
}
1109911152
}
@@ -12595,10 +12648,11 @@
1259512648
return rc;
1259612649
}
1259712650
1259812651
/************************* End ../ext/misc/sqlar.c ********************/
1259912652
#endif
12653
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
1260012654
/************************* Begin ../ext/expert/sqlite3expert.h ******************/
1260112655
/*
1260212656
** 2017 April 07
1260312657
**
1260412658
** The author disclaims copyright to this source code. In place of
@@ -15003,10 +15057,11 @@
1500315057
}
1500415058
1500515059
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
1500615060
1500715061
/************************* End ../ext/expert/sqlite3expert.c ********************/
15062
+#endif
1500815063
/************************* Begin ../ext/intck/sqlite3intck.h ******************/
1500915064
/*
1501015065
** 2024-02-08
1501115066
**
1501215067
** The author disclaims copyright to this source code. In place of
@@ -21643,15 +21698,17 @@
2164321698
char **azFilter; /* Array of xFilter rejection GLOB patterns */
2164421699
sqlite3_session *p; /* The open session */
2164521700
};
2164621701
#endif
2164721702
21703
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2164821704
typedef struct ExpertInfo ExpertInfo;
2164921705
struct ExpertInfo {
2165021706
sqlite3expert *pExpert;
2165121707
int bVerbose;
2165221708
};
21709
+#endif
2165321710
2165421711
/* A single line in the EQP output */
2165521712
typedef struct EQPGraphRow EQPGraphRow;
2165621713
struct EQPGraphRow {
2165721714
int iEqpId; /* ID for this row */
@@ -21751,11 +21808,13 @@
2175121808
int *aiIndent; /* Array of indents used in MODE_Explain */
2175221809
int nIndent; /* Size of array aiIndent[] */
2175321810
int iIndent; /* Index of current op in aiIndent[] */
2175421811
char *zNonce; /* Nonce for temporary safe-mode escapes */
2175521812
EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
21813
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2175621814
ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
21815
+#endif
2175721816
#ifdef SQLITE_SHELL_FIDDLE
2175821817
struct {
2175921818
const char * zInput; /* Input string from wasm/JS proxy */
2176021819
const char * zPos; /* Cursor pos into zInput */
2176121820
const char * zDefaultDbName; /* Default name for db file */
@@ -21779,13 +21838,12 @@
2177921838
*/
2178021839
#define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
2178121840
#define SHELL_OPEN_NORMAL 1 /* Normal database file */
2178221841
#define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */
2178321842
#define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */
21784
-#define SHELL_OPEN_READONLY 4 /* Open a normal database read-only */
21785
-#define SHELL_OPEN_DESERIALIZE 5 /* Open using sqlite3_deserialize() */
21786
-#define SHELL_OPEN_HEXDB 6 /* Use "dbtotxt" output as data source */
21843
+#define SHELL_OPEN_DESERIALIZE 4 /* Open using sqlite3_deserialize() */
21844
+#define SHELL_OPEN_HEXDB 5 /* Use "dbtotxt" output as data source */
2178721845
2178821846
/* Allowed values for ShellState.eTraceType
2178921847
*/
2179021848
#define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
2179121849
#define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
@@ -24688,11 +24746,11 @@
2468824746
}
2468924747
}
2469024748
}
2469124749
}
2469224750
24693
-#ifndef SQLITE_OMIT_VIRTUALTABLE
24751
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2469424752
/*
2469524753
** This function is called to process SQL if the previous shell command
2469624754
** was ".expert". It passes the SQL in the second argument directly to
2469724755
** the sqlite3expert object.
2469824756
**
@@ -24820,11 +24878,11 @@
2482024878
}
2482124879
sqlite3_free(zErr);
2482224880
2482324881
return rc;
2482424882
}
24825
-#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
24883
+#endif /* !SQLITE_OMIT_VIRTUALTABLE && !SQLITE_OMIT_AUTHORIZATION */
2482624884
2482724885
/*
2482824886
** Execute a statement or set of statements. Print
2482924887
** any result rows/columns depending on the current mode
2483024888
** set via the supplied callback.
@@ -24846,11 +24904,11 @@
2484624904
2484724905
if( pzErrMsg ){
2484824906
*pzErrMsg = NULL;
2484924907
}
2485024908
24851
-#ifndef SQLITE_OMIT_VIRTUALTABLE
24909
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2485224910
if( pArg->expert.pExpert ){
2485324911
rc = expertHandleSQL(pArg, zSql, pzErrMsg);
2485424912
return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
2485524913
}
2485624914
#endif
@@ -25008,11 +25066,11 @@
2500825066
static char **tableColumnList(ShellState *p, const char *zTab){
2500925067
char **azCol = 0;
2501025068
sqlite3_stmt *pStmt;
2501125069
char *zSql;
2501225070
int nCol = 0;
25013
- int nAlloc = 0;
25071
+ i64 nAlloc = 0;
2501425072
int nPK = 0; /* Number of PRIMARY KEY columns seen */
2501525073
int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */
2501625074
int preserveRowid = ShellHasFlag(p, SHFLG_PreserveRowid);
2501725075
int rc;
2501825076
@@ -25022,11 +25080,11 @@
2502225080
sqlite3_free(zSql);
2502325081
if( rc ) return 0;
2502425082
while( sqlite3_step(pStmt)==SQLITE_ROW ){
2502525083
if( nCol>=nAlloc-2 ){
2502625084
nAlloc = nAlloc*2 + nCol + 10;
25027
- azCol = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0]));
25085
+ azCol = sqlite3_realloc64(azCol, nAlloc*sizeof(azCol[0]));
2502825086
shell_check_oom(azCol);
2502925087
}
2503025088
azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
2503125089
shell_check_oom(azCol[nCol]);
2503225090
if( sqlite3_column_int(pStmt, 5) ){
@@ -25352,11 +25410,13 @@
2535225410
" --bom Put a UTF8 byte-order mark on intermediate file",
2535325411
#endif
2535425412
#ifndef SQLITE_SHELL_FIDDLE
2535525413
".exit ?CODE? Exit this program with return-code CODE",
2535625414
#endif
25415
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2535725416
".expert EXPERIMENTAL. Suggest indexes for queries",
25417
+#endif
2535825418
".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
2535925419
".filectrl CMD ... Run various sqlite3_file_control() operations",
2536025420
" --schema SCHEMA Use SCHEMA instead of \"main\"",
2536125421
" --help Show CMD details",
2536225422
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
@@ -25444,11 +25504,17 @@
2544425504
" Options:",
2544525505
" --append Use appendvfs to append database to the end of FILE",
2544625506
#endif
2544725507
#ifndef SQLITE_OMIT_DESERIALIZE
2544825508
" --deserialize Load into memory using sqlite3_deserialize()",
25509
+#endif
25510
+/*" --exclusive Set the SQLITE_OPEN_EXCLUSIVE flag", UNDOCUMENTED */
25511
+#ifndef SQLITE_OMIT_DESERIALIZE
2544925512
" --hexdb Load the output of \"dbtotxt\" as an in-memory db",
25513
+#endif
25514
+ " --ifexist Only open if FILE already exists",
25515
+#ifndef SQLITE_OMIT_DESERIALIZE
2545025516
" --maxsize N Maximum size for --hexdb or --deserialized database",
2545125517
#endif
2545225518
" --new Initialize FILE to an empty database",
2545325519
" --nofollow Do not follow symbolic links",
2545425520
" --readonly Open FILE readonly",
@@ -25865,11 +25931,11 @@
2586525931
if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
2586625932
sqlite3_fputs("invalid pagesize\n", stderr);
2586725933
goto readHexDb_error;
2586825934
}
2586925935
sz = ((i64)n+pgsz-1)&~(pgsz-1); /* Round up to nearest multiple of pgsz */
25870
- a = sqlite3_malloc( sz ? sz : 1 );
25936
+ a = sqlite3_malloc64( sz ? sz : 1 );
2587125937
shell_check_oom(a);
2587225938
memset(a, 0, sz);
2587325939
for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){
2587425940
int j = 0; /* Page number from "| page" line */
2587525941
int k = 0; /* Offset from "| page" line */
@@ -25989,14 +26055,17 @@
2598926055
}else{
2599026056
p->openMode = (u8)deduceDatabaseType(zDbFilename,
2599126057
(openFlags & OPEN_DB_ZIPFILE)!=0);
2599226058
}
2599326059
}
26060
+ if( (p->openFlags & (SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE))==0 ){
26061
+ if( p->openFlags==0 ) p->openFlags = SQLITE_OPEN_CREATE;
26062
+ p->openFlags |= SQLITE_OPEN_READWRITE;
26063
+ }
2599426064
switch( p->openMode ){
2599526065
case SHELL_OPEN_APPENDVFS: {
25996
- sqlite3_open_v2(zDbFilename, &p->db,
25997
- SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
26066
+ sqlite3_open_v2(zDbFilename, &p->db, p->openFlags, "apndvfs");
2599826067
break;
2599926068
}
2600026069
case SHELL_OPEN_HEXDB:
2600126070
case SHELL_OPEN_DESERIALIZE: {
2600226071
sqlite3_open(0, &p->db);
@@ -26004,19 +26073,13 @@
2600426073
}
2600526074
case SHELL_OPEN_ZIPFILE: {
2600626075
sqlite3_open(":memory:", &p->db);
2600726076
break;
2600826077
}
26009
- case SHELL_OPEN_READONLY: {
26010
- sqlite3_open_v2(zDbFilename, &p->db,
26011
- SQLITE_OPEN_READONLY|p->openFlags, 0);
26012
- break;
26013
- }
2601426078
case SHELL_OPEN_UNSPEC:
2601526079
case SHELL_OPEN_NORMAL: {
26016
- sqlite3_open_v2(zDbFilename, &p->db,
26017
- SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
26080
+ sqlite3_open_v2(zDbFilename, &p->db, p->openFlags, 0);
2601826081
break;
2601926082
}
2602026083
}
2602126084
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
2602226085
sqlite3_fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
@@ -26151,13 +26214,15 @@
2615126214
}
2615226215
}
2615326216
#endif
2615426217
}
2615526218
if( p->db!=0 ){
26219
+#ifndef SQLITE_OMIT_AUTHORIZATION
2615626220
if( p->bSafeModePersist ){
2615726221
sqlite3_set_authorizer(p->db, safeModeAuth, p);
2615826222
}
26223
+#endif
2615926224
sqlite3_db_config(
2616026225
p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0
2616126226
);
2616226227
}
2616326228
}
@@ -26466,12 +26531,12 @@
2646626531
struct ImportCtx {
2646726532
const char *zFile; /* Name of the input file */
2646826533
FILE *in; /* Read the CSV text from this input stream */
2646926534
int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close in */
2647026535
char *z; /* Accumulated text for a field */
26471
- int n; /* Number of bytes in z */
26472
- int nAlloc; /* Space allocated for z[] */
26536
+ i64 n; /* Number of bytes in z */
26537
+ i64 nAlloc; /* Space allocated for z[] */
2647326538
int nLine; /* Current line number */
2647426539
int nRow; /* Number of rows imported */
2647526540
int nErr; /* Number of errors encountered */
2647626541
int bNotFirst; /* True if one or more bytes already read */
2647726542
int cTerm; /* Character that terminated the most recent field */
@@ -27091,11 +27156,15 @@
2709127156
if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
2709227157
zTail = strrchr(zFilename, '/');
2709327158
#if defined(_WIN32)
2709427159
if( zTail==0 ) zTail = strrchr(zFilename, '\\');
2709527160
#endif
27096
- if( zTail && zTail[1]!=0 ) zTail++;
27161
+ if( zTail==0 ){
27162
+ zTail = zFilename;
27163
+ }else if( zTail[1]!=0 ){
27164
+ zTail++;
27165
+ }
2709727166
}
2709827167
zName = strdup(zTail);
2709927168
shell_check_oom(zName);
2710027169
sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
2710127170
nPage*pgSz, pgSz, zName);
@@ -28816,11 +28885,11 @@
2881628885
int nArg = 0;
2881728886
int n, c;
2881828887
int rc = 0;
2881928888
char *azArg[52];
2882028889
28821
-#ifndef SQLITE_OMIT_VIRTUALTABLE
28890
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2882228891
if( p->expert.pExpert ){
2882328892
expertFinish(p, 1, 0);
2882428893
}
2882528894
#endif
2882628895
@@ -29117,11 +29186,11 @@
2911729186
}else{
2911829187
while( sqlite3_step(pStmt)==SQLITE_ROW ){
2911929188
const char *zSchema = (const char *)sqlite3_column_text(pStmt,1);
2912029189
const char *zFile = (const char*)sqlite3_column_text(pStmt,2);
2912129190
if( zSchema==0 || zFile==0 ) continue;
29122
- azName = sqlite3_realloc(azName, (nName+1)*2*sizeof(char*));
29191
+ azName = sqlite3_realloc64(azName, (nName+1)*2*sizeof(char*));
2912329192
shell_check_oom(azName);
2912429193
azName[nName*2] = strdup(zSchema);
2912529194
azName[nName*2+1] = strdup(zFile);
2912629195
nName++;
2912729196
}
@@ -29385,11 +29454,11 @@
2938529454
if( p->mode==MODE_Explain ) p->mode = p->normalMode;
2938629455
p->autoExplain = 1;
2938729456
}
2938829457
}else
2938929458
29390
-#ifndef SQLITE_OMIT_VIRTUALTABLE
29459
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
2939129460
if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
2939229461
if( p->bSafeMode ){
2939329462
sqlite3_fprintf(stderr,
2939429463
"Cannot run experimental commands such as \"%s\" in safe mode\n",
2939529464
azArg[0]);
@@ -30385,10 +30454,11 @@
3038530454
const char *zFN = 0; /* Pointer to constant filename */
3038630455
char *zNewFilename = 0; /* Name of the database file to open */
3038730456
int iName = 1; /* Index in azArg[] of the filename */
3038830457
int newFlag = 0; /* True to delete file before opening */
3038930458
int openMode = SHELL_OPEN_UNSPEC;
30459
+ int openFlags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
3039030460
3039130461
/* Check for command-line arguments */
3039230462
for(iName=1; iName<nArg; iName++){
3039330463
const char *z = azArg[iName];
3039430464
#ifndef SQLITE_SHELL_FIDDLE
@@ -30399,13 +30469,18 @@
3039930469
openMode = SHELL_OPEN_ZIPFILE;
3040030470
#endif
3040130471
}else if( optionMatch(z, "append") ){
3040230472
openMode = SHELL_OPEN_APPENDVFS;
3040330473
}else if( optionMatch(z, "readonly") ){
30404
- openMode = SHELL_OPEN_READONLY;
30474
+ openFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
30475
+ openFlags |= SQLITE_OPEN_READONLY;
30476
+ }else if( optionMatch(z, "exclusive") ){
30477
+ openFlags |= SQLITE_OPEN_EXCLUSIVE;
30478
+ }else if( optionMatch(z, "ifexists") ){
30479
+ openFlags &= ~(SQLITE_OPEN_CREATE);
3040530480
}else if( optionMatch(z, "nofollow") ){
30406
- p->openFlags |= SQLITE_OPEN_NOFOLLOW;
30481
+ openFlags |= SQLITE_OPEN_NOFOLLOW;
3040730482
#ifndef SQLITE_OMIT_DESERIALIZE
3040830483
}else if( optionMatch(z, "deserialize") ){
3040930484
openMode = SHELL_OPEN_DESERIALIZE;
3041030485
}else if( optionMatch(z, "hexdb") ){
3041130486
openMode = SHELL_OPEN_HEXDB;
@@ -30433,11 +30508,11 @@
3043330508
p->db = 0;
3043430509
p->pAuxDb->zDbFilename = 0;
3043530510
sqlite3_free(p->pAuxDb->zFreeOnClose);
3043630511
p->pAuxDb->zFreeOnClose = 0;
3043730512
p->openMode = openMode;
30438
- p->openFlags = 0;
30513
+ p->openFlags = openFlags;
3043930514
p->szMax = 0;
3044030515
3044130516
/* If a filename is specified, try to open it first */
3044230517
if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
3044330518
if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
@@ -31175,19 +31250,20 @@
3117531250
3117631251
/* .session filter GLOB ....
3117731252
** Set a list of GLOB patterns of table names to be excluded.
3117831253
*/
3117931254
if( cli_strcmp(azCmd[0], "filter")==0 ){
31180
- int ii, nByte;
31255
+ int ii;
31256
+ i64 nByte;
3118131257
if( nCmd<2 ) goto session_syntax_error;
3118231258
if( pAuxDb->nSession ){
3118331259
for(ii=0; ii<pSession->nFilter; ii++){
3118431260
sqlite3_free(pSession->azFilter[ii]);
3118531261
}
3118631262
sqlite3_free(pSession->azFilter);
3118731263
nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
31188
- pSession->azFilter = sqlite3_malloc( nByte );
31264
+ pSession->azFilter = sqlite3_malloc64( nByte );
3118931265
shell_check_oom( pSession->azFilter );
3119031266
for(ii=1; ii<nCmd; ii++){
3119131267
char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]);
3119231268
shell_check_oom(x);
3119331269
}
@@ -33121,10 +33197,11 @@
3312133197
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
3312233198
" -heap SIZE Size of heap for memsys3 or memsys5\n"
3312333199
#endif
3312433200
" -help show this message\n"
3312533201
" -html set output mode to HTML\n"
33202
+ " -ifexists only open if database already exists\n"
3312633203
" -interactive force interactive I/O\n"
3312733204
" -json set output mode to 'json'\n"
3312833205
" -line set output mode to 'line'\n"
3312933206
" -list set output mode to 'list'\n"
3313033207
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
@@ -33533,13 +33610,19 @@
3353333610
data.openMode = SHELL_OPEN_DESERIALIZE;
3353433611
}else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
3353533612
data.szMax = integerValue(argv[++i]);
3353633613
#endif
3353733614
}else if( cli_strcmp(z,"-readonly")==0 ){
33538
- data.openMode = SHELL_OPEN_READONLY;
33615
+ data.openFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
33616
+ data.openFlags |= SQLITE_OPEN_READONLY;
3353933617
}else if( cli_strcmp(z,"-nofollow")==0 ){
33540
- data.openFlags = SQLITE_OPEN_NOFOLLOW;
33618
+ data.openFlags |= SQLITE_OPEN_NOFOLLOW;
33619
+ }else if( cli_strcmp(z,"-exclusive")==0 ){ /* UNDOCUMENTED */
33620
+ data.openFlags |= SQLITE_OPEN_EXCLUSIVE;
33621
+ }else if( cli_strcmp(z,"-ifexists")==0 ){
33622
+ data.openFlags &= ~(SQLITE_OPEN_CREATE);
33623
+ if( data.openFlags==0 ) data.openFlags = SQLITE_OPEN_READWRITE;
3354133624
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
3354233625
}else if( cli_strncmp(z, "-A",2)==0 ){
3354333626
/* All remaining command-line arguments are passed to the ".archive"
3354433627
** command, so ignore them */
3354533628
break;
@@ -33689,13 +33772,19 @@
3368933772
data.openMode = SHELL_OPEN_DESERIALIZE;
3369033773
}else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
3369133774
data.szMax = integerValue(argv[++i]);
3369233775
#endif
3369333776
}else if( cli_strcmp(z,"-readonly")==0 ){
33694
- data.openMode = SHELL_OPEN_READONLY;
33777
+ data.openFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
33778
+ data.openFlags |= SQLITE_OPEN_READONLY;
3369533779
}else if( cli_strcmp(z,"-nofollow")==0 ){
3369633780
data.openFlags |= SQLITE_OPEN_NOFOLLOW;
33781
+ }else if( cli_strcmp(z,"-exclusive")==0 ){ /* UNDOCUMENTED */
33782
+ data.openFlags |= SQLITE_OPEN_EXCLUSIVE;
33783
+ }else if( cli_strcmp(z,"-ifexists")==0 ){
33784
+ data.openFlags &= ~(SQLITE_OPEN_CREATE);
33785
+ if( data.openFlags==0 ) data.openFlags = SQLITE_OPEN_READWRITE;
3369733786
}else if( cli_strcmp(z,"-ascii")==0 ){
3369833787
data.mode = MODE_Ascii;
3369933788
sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Unit);
3370033789
sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Record);
3370133790
}else if( cli_strcmp(z,"-tabs")==0 ){
@@ -33912,11 +34001,11 @@
3391234001
}
3391334002
}
3391434003
#ifndef SQLITE_SHELL_FIDDLE
3391534004
/* In WASM mode we have to leave the db state in place so that
3391634005
** client code can "push" SQL into it after this call returns. */
33917
-#ifndef SQLITE_OMIT_VIRTUALTABLE
34006
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
3391834007
if( data.expert.pExpert ){
3391934008
expertFinish(&data, 1, 0);
3392034009
}
3392134010
#endif
3392234011
shell_main_exit:
3392334012
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1495,12 +1495,12 @@
1495 v = (v<<4) + x;
1496 zArg++;
1497 }
1498 }else{
1499 while( IsDigit(zArg[0]) ){
1500 if( v>=922337203685477580 ){
1501 if( v>922337203685477580 || zArg[0]>='8' ) goto integer_overflow;
1502 }
1503 v = v*10 + (zArg[0] - '0');
1504 zArg++;
1505 }
1506 }
@@ -6125,23 +6125,24 @@
6125 ** Examples:
6126 **
6127 ** SELECT * FROM generate_series(0,100,5);
6128 **
6129 ** The query above returns integers from 0 through 100 counting by steps
6130 ** of 5.
 
6131 **
6132 ** SELECT * FROM generate_series(0,100);
6133 **
6134 ** Integers from 0 through 100 with a step size of 1.
6135 **
6136 ** SELECT * FROM generate_series(20) LIMIT 10;
6137 **
6138 ** Integers 20 through 29.
6139 **
6140 ** SELECT * FROM generate_series(0,-100,-5);
6141 **
6142 ** Integers 0 -5 -10 ... -100.
6143 **
6144 ** SELECT * FROM generate_series(0,-1);
6145 **
6146 ** Empty sequence.
6147 **
@@ -6213,143 +6214,92 @@
6213 #include <string.h>
6214 #include <limits.h>
6215 #include <math.h>
6216
6217 #ifndef SQLITE_OMIT_VIRTUALTABLE
6218 /*
6219 ** Return that member of a generate_series(...) sequence whose 0-based
6220 ** index is ix. The 0th member is given by smBase. The sequence members
6221 ** progress per ix increment by smStep.
6222 */
6223 static sqlite3_int64 genSeqMember(
6224 sqlite3_int64 smBase,
6225 sqlite3_int64 smStep,
6226 sqlite3_uint64 ix
6227 ){
6228 static const sqlite3_uint64 mxI64 =
6229 ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff;
6230 if( ix>=mxI64 ){
6231 /* Get ix into signed i64 range. */
6232 ix -= mxI64;
6233 /* With 2's complement ALU, this next can be 1 step, but is split into
6234 * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
6235 smBase += (mxI64/2) * smStep;
6236 smBase += (mxI64 - mxI64/2) * smStep;
6237 }
6238 /* Under UBSAN (or on 1's complement machines), must do this last term
6239 * in steps to avoid the dreaded (and harmless) signed multiply overflow. */
6240 if( ix>=2 ){
6241 sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
6242 smBase += ix2*smStep;
6243 ix -= ix2;
6244 }
6245 return smBase + ((sqlite3_int64)ix)*smStep;
6246 }
6247
6248 /* typedef unsigned char u8; */
6249
6250 typedef struct SequenceSpec {
6251 sqlite3_int64 iOBase; /* Original starting value ("start") */
6252 sqlite3_int64 iOTerm; /* Original terminal value ("stop") */
6253 sqlite3_int64 iBase; /* Starting value to actually use */
6254 sqlite3_int64 iTerm; /* Terminal value to actually use */
6255 sqlite3_int64 iStep; /* Increment ("step") */
6256 sqlite3_uint64 uSeqIndexMax; /* maximum sequence index (aka "n") */
6257 sqlite3_uint64 uSeqIndexNow; /* Current index during generation */
6258 sqlite3_int64 iValueNow; /* Current value during generation */
6259 u8 isNotEOF; /* Sequence generation not exhausted */
6260 u8 isReversing; /* Sequence is being reverse generated */
6261 } SequenceSpec;
6262
6263 /*
6264 ** Prepare a SequenceSpec for use in generating an integer series
6265 ** given initialized iBase, iTerm and iStep values. Sequence is
6266 ** initialized per given isReversing. Other members are computed.
6267 */
6268 static void setupSequence( SequenceSpec *pss ){
6269 int bSameSigns;
6270 pss->uSeqIndexMax = 0;
6271 pss->isNotEOF = 0;
6272 bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0);
6273 if( pss->iTerm < pss->iBase ){
6274 sqlite3_uint64 nuspan = 0;
6275 if( bSameSigns ){
6276 nuspan = (sqlite3_uint64)(pss->iBase - pss->iTerm);
6277 }else{
6278 /* Under UBSAN (or on 1's complement machines), must do this in steps.
6279 * In this clause, iBase>=0 and iTerm<0 . */
6280 nuspan = 1;
6281 nuspan += pss->iBase;
6282 nuspan += -(pss->iTerm+1);
6283 }
6284 if( pss->iStep<0 ){
6285 pss->isNotEOF = 1;
6286 if( nuspan==ULONG_MAX ){
6287 pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
6288 }else if( pss->iStep>LLONG_MIN ){
6289 pss->uSeqIndexMax = nuspan/-pss->iStep;
6290 }
6291 }
6292 }else if( pss->iTerm > pss->iBase ){
6293 sqlite3_uint64 puspan = 0;
6294 if( bSameSigns ){
6295 puspan = (sqlite3_uint64)(pss->iTerm - pss->iBase);
6296 }else{
6297 /* Under UBSAN (or on 1's complement machines), must do this in steps.
6298 * In this clause, iTerm>=0 and iBase<0 . */
6299 puspan = 1;
6300 puspan += pss->iTerm;
6301 puspan += -(pss->iBase+1);
6302 }
6303 if( pss->iStep>0 ){
6304 pss->isNotEOF = 1;
6305 pss->uSeqIndexMax = puspan/pss->iStep;
6306 }
6307 }else if( pss->iTerm == pss->iBase ){
6308 pss->isNotEOF = 1;
6309 pss->uSeqIndexMax = 0;
6310 }
6311 pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
6312 pss->iValueNow = (pss->isReversing)
6313 ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
6314 : pss->iBase;
6315 }
6316
6317 /*
6318 ** Progress sequence generator to yield next value, if any.
6319 ** Leave its state to either yield next value or be at EOF.
6320 ** Return whether there is a next value, or 0 at EOF.
6321 */
6322 static int progressSequence( SequenceSpec *pss ){
6323 if( !pss->isNotEOF ) return 0;
6324 if( pss->isReversing ){
6325 if( pss->uSeqIndexNow > 0 ){
6326 pss->uSeqIndexNow--;
6327 pss->iValueNow -= pss->iStep;
6328 }else{
6329 pss->isNotEOF = 0;
6330 }
6331 }else{
6332 if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
6333 pss->uSeqIndexNow++;
6334 pss->iValueNow += pss->iStep;
6335 }else{
6336 pss->isNotEOF = 0;
6337 }
6338 }
6339 return pss->isNotEOF;
6340 }
6341
6342 /* series_cursor is a subclass of sqlite3_vtab_cursor which will
6343 ** serve as the underlying representation of a cursor that scans
6344 ** over rows of the result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6345 */
 
6346 typedef struct series_cursor series_cursor;
6347 struct series_cursor {
6348 sqlite3_vtab_cursor base; /* Base class - must be first */
6349 SequenceSpec ss; /* (this) Derived class data */
 
 
 
 
 
 
 
 
6350 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6351
6352 /*
6353 ** The seriesConnect() method is invoked to create a new
6354 ** series_vtab that describes the generate_series virtual table.
6355 **
@@ -6427,11 +6377,19 @@
6427 /*
6428 ** Advance a series_cursor to its next row of output.
6429 */
6430 static int seriesNext(sqlite3_vtab_cursor *cur){
6431 series_cursor *pCur = (series_cursor*)cur;
6432 progressSequence( & pCur->ss );
 
 
 
 
 
 
 
 
6433 return SQLITE_OK;
6434 }
6435
6436 /*
6437 ** Return values of columns for the row at which the series_cursor
@@ -6443,50 +6401,64 @@
6443 int i /* Which column to return */
6444 ){
6445 series_cursor *pCur = (series_cursor*)cur;
6446 sqlite3_int64 x = 0;
6447 switch( i ){
6448 case SERIES_COLUMN_START: x = pCur->ss.iOBase; break;
6449 case SERIES_COLUMN_STOP: x = pCur->ss.iOTerm; break;
6450 case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
6451 default: x = pCur->ss.iValueNow; break;
6452 }
6453 sqlite3_result_int64(ctx, x);
6454 return SQLITE_OK;
6455 }
6456
6457 #ifndef LARGEST_UINT64
6458 #define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
6459 #define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
6460 #define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
6461 #endif
6462
6463 /*
6464 ** The rowid is the same as the value.
6465 */
6466 static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
6467 series_cursor *pCur = (series_cursor*)cur;
6468 *pRowid = pCur->ss.iValueNow;
6469 return SQLITE_OK;
6470 }
6471
6472 /*
6473 ** Return TRUE if the cursor has been moved off of the last
6474 ** row of output.
6475 */
6476 static int seriesEof(sqlite3_vtab_cursor *cur){
6477 series_cursor *pCur = (series_cursor*)cur;
6478 return !pCur->ss.isNotEOF;
6479 }
6480
6481 /* True to cause run-time checking of the start=, stop=, and/or step=
6482 ** parameters. The only reason to do this is for testing the
6483 ** constraint checking logic for virtual tables in the SQLite core.
6484 */
6485 #ifndef SQLITE_SERIES_CONSTRAINT_VERIFY
6486 # define SQLITE_SERIES_CONSTRAINT_VERIFY 0
6487 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6488
6489 /*
6490 ** This method is called to "rewind" the series_cursor object back
6491 ** to the first row of output. This method is always called at least
6492 ** once prior to any call to seriesColumn() or seriesRowid() or
@@ -6517,189 +6489,244 @@
6517 sqlite3_vtab_cursor *pVtabCursor,
6518 int idxNum, const char *idxStrUnused,
6519 int argc, sqlite3_value **argv
6520 ){
6521 series_cursor *pCur = (series_cursor *)pVtabCursor;
6522 int i = 0;
6523 int returnNoRows = 0;
6524 sqlite3_int64 iMin = SMALLEST_INT64;
6525 sqlite3_int64 iMax = LARGEST_INT64;
6526 sqlite3_int64 iLimit = 0;
6527 sqlite3_int64 iOffset = 0;
6528
6529 (void)idxStrUnused;
 
 
 
 
 
 
 
 
 
 
 
 
 
6530 if( idxNum & 0x01 ){
6531 pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
6532 }else{
6533 pCur->ss.iBase = 0;
6534 }
6535 if( idxNum & 0x02 ){
6536 pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
6537 }else{
6538 pCur->ss.iTerm = 0xffffffff;
6539 }
6540 if( idxNum & 0x04 ){
6541 pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
6542 if( pCur->ss.iStep==0 ){
6543 pCur->ss.iStep = 1;
6544 }else if( pCur->ss.iStep<0 ){
6545 if( (idxNum & 0x10)==0 ) idxNum |= 0x08;
6546 }
6547 }else{
6548 pCur->ss.iStep = 1;
6549 }
6550
6551 /* If there are constraints on the value column but there are
6552 ** no constraints on the start, stop, and step columns, then
6553 ** initialize the default range to be the entire range of 64-bit signed
6554 ** integers. This range will contracted by the value column constraints
6555 ** further below.
6556 */
6557 if( (idxNum & 0x05)==0 && (idxNum & 0x0380)!=0 ){
6558 pCur->ss.iBase = SMALLEST_INT64;
6559 }
6560 if( (idxNum & 0x06)==0 && (idxNum & 0x3080)!=0 ){
6561 pCur->ss.iTerm = LARGEST_INT64;
6562 }
6563 pCur->ss.iOBase = pCur->ss.iBase;
6564 pCur->ss.iOTerm = pCur->ss.iTerm;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6565
6566 /* Extract the LIMIT and OFFSET values, but do not apply them yet.
6567 ** The range must first be constrained by the limits on value.
6568 */
6569 if( idxNum & 0x20 ){
6570 iLimit = sqlite3_value_int64(argv[i++]);
6571 if( idxNum & 0x40 ){
6572 iOffset = sqlite3_value_int64(argv[i++]);
6573 }
6574 }
6575
 
 
 
6576 if( idxNum & 0x3380 ){
6577 /* Extract the maximum range of output values determined by
6578 ** constraints on the "value" column.
6579 */
6580 if( idxNum & 0x0080 ){
6581 if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6582 double r = sqlite3_value_double(argv[i++]);
6583 if( r==ceil(r) ){
6584 iMin = iMax = (sqlite3_int64)r;
6585 }else{
6586 returnNoRows = 1;
6587 }
6588 }else{
6589 iMin = iMax = sqlite3_value_int64(argv[i++]);
6590 }
6591 }else{
6592 if( idxNum & 0x0300 ){
6593 if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6594 double r = sqlite3_value_double(argv[i++]);
6595 if( idxNum & 0x0200 && r==ceil(r) ){
 
 
6596 iMin = (sqlite3_int64)ceil(r+1.0);
6597 }else{
6598 iMin = (sqlite3_int64)ceil(r);
6599 }
6600 }else{
6601 iMin = sqlite3_value_int64(argv[i++]);
6602 if( idxNum & 0x0200 ){
6603 if( iMin==LARGEST_INT64 ){
6604 returnNoRows = 1;
6605 }else{
6606 iMin++;
6607 }
6608 }
6609 }
6610 }
6611 if( idxNum & 0x3000 ){
6612 if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6613 double r = sqlite3_value_double(argv[i++]);
6614 if( (idxNum & 0x2000)!=0 && r==floor(r) ){
 
 
6615 iMax = (sqlite3_int64)(r-1.0);
6616 }else{
6617 iMax = (sqlite3_int64)floor(r);
6618 }
6619 }else{
6620 iMax = sqlite3_value_int64(argv[i++]);
6621 if( idxNum & 0x2000 ){
6622 if( iMax==SMALLEST_INT64 ){
6623 returnNoRows = 1;
6624 }else{
6625 iMax--;
6626 }
6627 }
6628 }
6629 }
6630 if( iMin>iMax ){
6631 returnNoRows = 1;
6632 }
6633 }
6634
6635 /* Try to reduce the range of values to be generated based on
6636 ** constraints on the "value" column.
6637 */
6638 if( pCur->ss.iStep>0 ){
6639 sqlite3_int64 szStep = pCur->ss.iStep;
6640 if( pCur->ss.iBase<iMin ){
6641 sqlite3_uint64 d = iMin - pCur->ss.iBase;
6642 pCur->ss.iBase += ((d+szStep-1)/szStep)*szStep;
6643 }
6644 if( pCur->ss.iTerm>iMax ){
6645 pCur->ss.iTerm = iMax;
 
 
 
 
 
6646 }
6647 }else{
6648 sqlite3_int64 szStep = -pCur->ss.iStep;
6649 assert( szStep>0 );
6650 if( pCur->ss.iBase>iMax ){
6651 sqlite3_uint64 d = pCur->ss.iBase - iMax;
6652 pCur->ss.iBase -= ((d+szStep-1)/szStep)*szStep;
6653 }
6654 if( pCur->ss.iTerm<iMin ){
6655 pCur->ss.iTerm = iMin;
 
 
 
 
6656 }
6657 }
6658 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6659
6660 /* Apply LIMIT and OFFSET constraints, if any */
 
6661 if( idxNum & 0x20 ){
 
6662 if( iOffset>0 ){
6663 pCur->ss.iBase += pCur->ss.iStep*iOffset;
6664 }
6665 if( iLimit>=0 ){
6666 sqlite3_int64 iTerm;
6667 sqlite3_int64 mxLimit;
6668 assert( pCur->ss.iStep>0 );
6669 mxLimit = (LARGEST_INT64 - pCur->ss.iBase)/pCur->ss.iStep;
6670 if( iLimit>mxLimit ) iLimit = mxLimit;
6671 iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
6672 if( pCur->ss.iStep<0 ){
6673 if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6674 }else{
6675 if( iTerm<pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6676 }
6677 }
6678 }
6679
6680
6681 for(i=0; i<argc; i++){
6682 if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
6683 /* If any of the constraints have a NULL value, then return no rows.
6684 ** See ticket https://sqlite.org/src/info/fac496b61722daf2 */
6685 returnNoRows = 1;
6686 break;
6687 }
6688 }
6689 if( returnNoRows ){
6690 pCur->ss.iBase = 1;
6691 pCur->ss.iTerm = 0;
6692 pCur->ss.iStep = 1;
6693 }
6694 if( idxNum & 0x08 ){
6695 pCur->ss.isReversing = pCur->ss.iStep > 0;
6696 }else{
6697 pCur->ss.isReversing = pCur->ss.iStep < 0;
6698 }
6699 setupSequence( &pCur->ss );
6700 return SQLITE_OK;
 
 
 
 
 
 
 
 
6701 }
6702
6703 /*
6704 ** SQLite will invoke this method one or more times while planning a query
6705 ** that uses the generate_series virtual table. This routine needs to create
@@ -9384,18 +9411,20 @@
9384 if( idxNum & 1 ){
9385 pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
9386 if( pCur->nPrefix>0 ){
9387 pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
9388 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
 
9389 }
9390 iArg = 1;
9391 }
9392 if( idxNum & 2 ){
9393 pCur->nLine = sqlite3_value_bytes(argv[iArg]);
9394 if( pCur->nLine>0 ){
9395 pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
9396 if( pCur->zLine==0 ) return SQLITE_NOMEM;
 
9397 }
9398 }
9399 if( pCur->zLine!=0 && pCur->zPrefix==0 ){
9400 int i = pCur->nLine;
9401 while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
@@ -9403,10 +9432,11 @@
9403 }
9404 pCur->nPrefix = pCur->nLine - i;
9405 if( pCur->nPrefix>0 ){
9406 pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
9407 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
 
9408 }
9409 }
9410 pCur->iRowid = 0;
9411 pCur->ePhase = COMPLETION_FIRST_PHASE;
9412 return completionNext(pVtabCursor);
@@ -10316,13 +10346,18 @@
10316 "method," /* 6: Compression method (integer) */
10317 "z HIDDEN" /* 7: Name of zip file */
10318 ") WITHOUT ROWID;";
10319
10320 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
10321 #define ZIPFILE_BUFFER_SIZE (64*1024)
10322 #define ZIPFILE_MX_NAME (250) /* Windows limitation on filename size */
10323
 
 
 
 
 
 
10324
10325 /*
10326 ** Magic numbers used to read and write zip files.
10327 **
10328 ** ZIPFILE_NEWENTRY_MADEBY:
@@ -11000,10 +11035,19 @@
11000 || mUnixTime==zipfileMtime(pCds)
11001 || ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
11002 /* || (mUnixTime % 2) */
11003 );
11004 }
 
 
 
 
 
 
 
 
 
11005
11006 /*
11007 ** If aBlob is not NULL, then it is a pointer to a buffer (nBlob bytes in
11008 ** size) containing an entire zip archive image. Or, if aBlob is NULL,
11009 ** then pFile is a file-handle open on a zip file. In either case, this
@@ -11023,16 +11067,19 @@
11023 ZipfileEntry **ppEntry /* OUT: Pointer to new object */
11024 ){
11025 u8 *aRead;
11026 char **pzErr = &pTab->base.zErrMsg;
11027 int rc = SQLITE_OK;
11028 (void)nBlob;
11029
11030 if( aBlob==0 ){
11031 aRead = pTab->aBuffer;
11032 rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr);
11033 }else{
 
 
 
 
11034 aRead = (u8*)&aBlob[iOff];
11035 }
11036
11037 if( rc==SQLITE_OK ){
11038 sqlite3_int64 nAlloc;
@@ -11059,10 +11106,13 @@
11059 rc = zipfileReadData(
11060 pFile, aRead, nExtra+nFile, iOff+ZIPFILE_CDS_FIXED_SZ, pzErr
11061 );
11062 }else{
11063 aRead = (u8*)&aBlob[iOff + ZIPFILE_CDS_FIXED_SZ];
 
 
 
11064 }
11065 }
11066
11067 if( rc==SQLITE_OK ){
11068 u32 *pt = &pNew->mUnixTime;
@@ -11081,19 +11131,22 @@
11081 ZipfileLFH lfh;
11082 if( pFile ){
11083 rc = zipfileReadData(pFile, aRead, szFix, pNew->cds.iOffset, pzErr);
11084 }else{
11085 aRead = (u8*)&aBlob[pNew->cds.iOffset];
 
 
 
11086 }
11087
11088 if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
11089 if( rc==SQLITE_OK ){
11090 pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
11091 pNew->iDataOff += lfh.nFile + lfh.nExtra;
11092 if( aBlob && pNew->cds.szCompressed ){
11093 if( pNew->iDataOff + pNew->cds.szCompressed > nBlob ){
11094 rc = SQLITE_CORRUPT;
11095 }else{
11096 pNew->aData = &pNew->aExtra[nExtra];
11097 memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
11098 }
11099 }
@@ -12595,10 +12648,11 @@
12595 return rc;
12596 }
12597
12598 /************************* End ../ext/misc/sqlar.c ********************/
12599 #endif
 
12600 /************************* Begin ../ext/expert/sqlite3expert.h ******************/
12601 /*
12602 ** 2017 April 07
12603 **
12604 ** The author disclaims copyright to this source code. In place of
@@ -15003,10 +15057,11 @@
15003 }
15004
15005 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
15006
15007 /************************* End ../ext/expert/sqlite3expert.c ********************/
 
15008 /************************* Begin ../ext/intck/sqlite3intck.h ******************/
15009 /*
15010 ** 2024-02-08
15011 **
15012 ** The author disclaims copyright to this source code. In place of
@@ -21643,15 +21698,17 @@
21643 char **azFilter; /* Array of xFilter rejection GLOB patterns */
21644 sqlite3_session *p; /* The open session */
21645 };
21646 #endif
21647
 
21648 typedef struct ExpertInfo ExpertInfo;
21649 struct ExpertInfo {
21650 sqlite3expert *pExpert;
21651 int bVerbose;
21652 };
 
21653
21654 /* A single line in the EQP output */
21655 typedef struct EQPGraphRow EQPGraphRow;
21656 struct EQPGraphRow {
21657 int iEqpId; /* ID for this row */
@@ -21751,11 +21808,13 @@
21751 int *aiIndent; /* Array of indents used in MODE_Explain */
21752 int nIndent; /* Size of array aiIndent[] */
21753 int iIndent; /* Index of current op in aiIndent[] */
21754 char *zNonce; /* Nonce for temporary safe-mode escapes */
21755 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
 
21756 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
 
21757 #ifdef SQLITE_SHELL_FIDDLE
21758 struct {
21759 const char * zInput; /* Input string from wasm/JS proxy */
21760 const char * zPos; /* Cursor pos into zInput */
21761 const char * zDefaultDbName; /* Default name for db file */
@@ -21779,13 +21838,12 @@
21779 */
21780 #define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
21781 #define SHELL_OPEN_NORMAL 1 /* Normal database file */
21782 #define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */
21783 #define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */
21784 #define SHELL_OPEN_READONLY 4 /* Open a normal database read-only */
21785 #define SHELL_OPEN_DESERIALIZE 5 /* Open using sqlite3_deserialize() */
21786 #define SHELL_OPEN_HEXDB 6 /* Use "dbtotxt" output as data source */
21787
21788 /* Allowed values for ShellState.eTraceType
21789 */
21790 #define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
21791 #define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
@@ -24688,11 +24746,11 @@
24688 }
24689 }
24690 }
24691 }
24692
24693 #ifndef SQLITE_OMIT_VIRTUALTABLE
24694 /*
24695 ** This function is called to process SQL if the previous shell command
24696 ** was ".expert". It passes the SQL in the second argument directly to
24697 ** the sqlite3expert object.
24698 **
@@ -24820,11 +24878,11 @@
24820 }
24821 sqlite3_free(zErr);
24822
24823 return rc;
24824 }
24825 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
24826
24827 /*
24828 ** Execute a statement or set of statements. Print
24829 ** any result rows/columns depending on the current mode
24830 ** set via the supplied callback.
@@ -24846,11 +24904,11 @@
24846
24847 if( pzErrMsg ){
24848 *pzErrMsg = NULL;
24849 }
24850
24851 #ifndef SQLITE_OMIT_VIRTUALTABLE
24852 if( pArg->expert.pExpert ){
24853 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
24854 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
24855 }
24856 #endif
@@ -25008,11 +25066,11 @@
25008 static char **tableColumnList(ShellState *p, const char *zTab){
25009 char **azCol = 0;
25010 sqlite3_stmt *pStmt;
25011 char *zSql;
25012 int nCol = 0;
25013 int nAlloc = 0;
25014 int nPK = 0; /* Number of PRIMARY KEY columns seen */
25015 int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */
25016 int preserveRowid = ShellHasFlag(p, SHFLG_PreserveRowid);
25017 int rc;
25018
@@ -25022,11 +25080,11 @@
25022 sqlite3_free(zSql);
25023 if( rc ) return 0;
25024 while( sqlite3_step(pStmt)==SQLITE_ROW ){
25025 if( nCol>=nAlloc-2 ){
25026 nAlloc = nAlloc*2 + nCol + 10;
25027 azCol = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0]));
25028 shell_check_oom(azCol);
25029 }
25030 azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
25031 shell_check_oom(azCol[nCol]);
25032 if( sqlite3_column_int(pStmt, 5) ){
@@ -25352,11 +25410,13 @@
25352 " --bom Put a UTF8 byte-order mark on intermediate file",
25353 #endif
25354 #ifndef SQLITE_SHELL_FIDDLE
25355 ".exit ?CODE? Exit this program with return-code CODE",
25356 #endif
 
25357 ".expert EXPERIMENTAL. Suggest indexes for queries",
 
25358 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
25359 ".filectrl CMD ... Run various sqlite3_file_control() operations",
25360 " --schema SCHEMA Use SCHEMA instead of \"main\"",
25361 " --help Show CMD details",
25362 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
@@ -25444,11 +25504,17 @@
25444 " Options:",
25445 " --append Use appendvfs to append database to the end of FILE",
25446 #endif
25447 #ifndef SQLITE_OMIT_DESERIALIZE
25448 " --deserialize Load into memory using sqlite3_deserialize()",
 
 
 
25449 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
 
 
 
25450 " --maxsize N Maximum size for --hexdb or --deserialized database",
25451 #endif
25452 " --new Initialize FILE to an empty database",
25453 " --nofollow Do not follow symbolic links",
25454 " --readonly Open FILE readonly",
@@ -25865,11 +25931,11 @@
25865 if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
25866 sqlite3_fputs("invalid pagesize\n", stderr);
25867 goto readHexDb_error;
25868 }
25869 sz = ((i64)n+pgsz-1)&~(pgsz-1); /* Round up to nearest multiple of pgsz */
25870 a = sqlite3_malloc( sz ? sz : 1 );
25871 shell_check_oom(a);
25872 memset(a, 0, sz);
25873 for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){
25874 int j = 0; /* Page number from "| page" line */
25875 int k = 0; /* Offset from "| page" line */
@@ -25989,14 +26055,17 @@
25989 }else{
25990 p->openMode = (u8)deduceDatabaseType(zDbFilename,
25991 (openFlags & OPEN_DB_ZIPFILE)!=0);
25992 }
25993 }
 
 
 
 
25994 switch( p->openMode ){
25995 case SHELL_OPEN_APPENDVFS: {
25996 sqlite3_open_v2(zDbFilename, &p->db,
25997 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
25998 break;
25999 }
26000 case SHELL_OPEN_HEXDB:
26001 case SHELL_OPEN_DESERIALIZE: {
26002 sqlite3_open(0, &p->db);
@@ -26004,19 +26073,13 @@
26004 }
26005 case SHELL_OPEN_ZIPFILE: {
26006 sqlite3_open(":memory:", &p->db);
26007 break;
26008 }
26009 case SHELL_OPEN_READONLY: {
26010 sqlite3_open_v2(zDbFilename, &p->db,
26011 SQLITE_OPEN_READONLY|p->openFlags, 0);
26012 break;
26013 }
26014 case SHELL_OPEN_UNSPEC:
26015 case SHELL_OPEN_NORMAL: {
26016 sqlite3_open_v2(zDbFilename, &p->db,
26017 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
26018 break;
26019 }
26020 }
26021 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
26022 sqlite3_fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
@@ -26151,13 +26214,15 @@
26151 }
26152 }
26153 #endif
26154 }
26155 if( p->db!=0 ){
 
26156 if( p->bSafeModePersist ){
26157 sqlite3_set_authorizer(p->db, safeModeAuth, p);
26158 }
 
26159 sqlite3_db_config(
26160 p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0
26161 );
26162 }
26163 }
@@ -26466,12 +26531,12 @@
26466 struct ImportCtx {
26467 const char *zFile; /* Name of the input file */
26468 FILE *in; /* Read the CSV text from this input stream */
26469 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close in */
26470 char *z; /* Accumulated text for a field */
26471 int n; /* Number of bytes in z */
26472 int nAlloc; /* Space allocated for z[] */
26473 int nLine; /* Current line number */
26474 int nRow; /* Number of rows imported */
26475 int nErr; /* Number of errors encountered */
26476 int bNotFirst; /* True if one or more bytes already read */
26477 int cTerm; /* Character that terminated the most recent field */
@@ -27091,11 +27156,15 @@
27091 if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
27092 zTail = strrchr(zFilename, '/');
27093 #if defined(_WIN32)
27094 if( zTail==0 ) zTail = strrchr(zFilename, '\\');
27095 #endif
27096 if( zTail && zTail[1]!=0 ) zTail++;
 
 
 
 
27097 }
27098 zName = strdup(zTail);
27099 shell_check_oom(zName);
27100 sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
27101 nPage*pgSz, pgSz, zName);
@@ -28816,11 +28885,11 @@
28816 int nArg = 0;
28817 int n, c;
28818 int rc = 0;
28819 char *azArg[52];
28820
28821 #ifndef SQLITE_OMIT_VIRTUALTABLE
28822 if( p->expert.pExpert ){
28823 expertFinish(p, 1, 0);
28824 }
28825 #endif
28826
@@ -29117,11 +29186,11 @@
29117 }else{
29118 while( sqlite3_step(pStmt)==SQLITE_ROW ){
29119 const char *zSchema = (const char *)sqlite3_column_text(pStmt,1);
29120 const char *zFile = (const char*)sqlite3_column_text(pStmt,2);
29121 if( zSchema==0 || zFile==0 ) continue;
29122 azName = sqlite3_realloc(azName, (nName+1)*2*sizeof(char*));
29123 shell_check_oom(azName);
29124 azName[nName*2] = strdup(zSchema);
29125 azName[nName*2+1] = strdup(zFile);
29126 nName++;
29127 }
@@ -29385,11 +29454,11 @@
29385 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
29386 p->autoExplain = 1;
29387 }
29388 }else
29389
29390 #ifndef SQLITE_OMIT_VIRTUALTABLE
29391 if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
29392 if( p->bSafeMode ){
29393 sqlite3_fprintf(stderr,
29394 "Cannot run experimental commands such as \"%s\" in safe mode\n",
29395 azArg[0]);
@@ -30385,10 +30454,11 @@
30385 const char *zFN = 0; /* Pointer to constant filename */
30386 char *zNewFilename = 0; /* Name of the database file to open */
30387 int iName = 1; /* Index in azArg[] of the filename */
30388 int newFlag = 0; /* True to delete file before opening */
30389 int openMode = SHELL_OPEN_UNSPEC;
 
30390
30391 /* Check for command-line arguments */
30392 for(iName=1; iName<nArg; iName++){
30393 const char *z = azArg[iName];
30394 #ifndef SQLITE_SHELL_FIDDLE
@@ -30399,13 +30469,18 @@
30399 openMode = SHELL_OPEN_ZIPFILE;
30400 #endif
30401 }else if( optionMatch(z, "append") ){
30402 openMode = SHELL_OPEN_APPENDVFS;
30403 }else if( optionMatch(z, "readonly") ){
30404 openMode = SHELL_OPEN_READONLY;
 
 
 
 
 
30405 }else if( optionMatch(z, "nofollow") ){
30406 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
30407 #ifndef SQLITE_OMIT_DESERIALIZE
30408 }else if( optionMatch(z, "deserialize") ){
30409 openMode = SHELL_OPEN_DESERIALIZE;
30410 }else if( optionMatch(z, "hexdb") ){
30411 openMode = SHELL_OPEN_HEXDB;
@@ -30433,11 +30508,11 @@
30433 p->db = 0;
30434 p->pAuxDb->zDbFilename = 0;
30435 sqlite3_free(p->pAuxDb->zFreeOnClose);
30436 p->pAuxDb->zFreeOnClose = 0;
30437 p->openMode = openMode;
30438 p->openFlags = 0;
30439 p->szMax = 0;
30440
30441 /* If a filename is specified, try to open it first */
30442 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
30443 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
@@ -31175,19 +31250,20 @@
31175
31176 /* .session filter GLOB ....
31177 ** Set a list of GLOB patterns of table names to be excluded.
31178 */
31179 if( cli_strcmp(azCmd[0], "filter")==0 ){
31180 int ii, nByte;
 
31181 if( nCmd<2 ) goto session_syntax_error;
31182 if( pAuxDb->nSession ){
31183 for(ii=0; ii<pSession->nFilter; ii++){
31184 sqlite3_free(pSession->azFilter[ii]);
31185 }
31186 sqlite3_free(pSession->azFilter);
31187 nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
31188 pSession->azFilter = sqlite3_malloc( nByte );
31189 shell_check_oom( pSession->azFilter );
31190 for(ii=1; ii<nCmd; ii++){
31191 char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]);
31192 shell_check_oom(x);
31193 }
@@ -33121,10 +33197,11 @@
33121 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
33122 " -heap SIZE Size of heap for memsys3 or memsys5\n"
33123 #endif
33124 " -help show this message\n"
33125 " -html set output mode to HTML\n"
 
33126 " -interactive force interactive I/O\n"
33127 " -json set output mode to 'json'\n"
33128 " -line set output mode to 'line'\n"
33129 " -list set output mode to 'list'\n"
33130 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
@@ -33533,13 +33610,19 @@
33533 data.openMode = SHELL_OPEN_DESERIALIZE;
33534 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33535 data.szMax = integerValue(argv[++i]);
33536 #endif
33537 }else if( cli_strcmp(z,"-readonly")==0 ){
33538 data.openMode = SHELL_OPEN_READONLY;
 
33539 }else if( cli_strcmp(z,"-nofollow")==0 ){
33540 data.openFlags = SQLITE_OPEN_NOFOLLOW;
 
 
 
 
 
33541 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
33542 }else if( cli_strncmp(z, "-A",2)==0 ){
33543 /* All remaining command-line arguments are passed to the ".archive"
33544 ** command, so ignore them */
33545 break;
@@ -33689,13 +33772,19 @@
33689 data.openMode = SHELL_OPEN_DESERIALIZE;
33690 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33691 data.szMax = integerValue(argv[++i]);
33692 #endif
33693 }else if( cli_strcmp(z,"-readonly")==0 ){
33694 data.openMode = SHELL_OPEN_READONLY;
 
33695 }else if( cli_strcmp(z,"-nofollow")==0 ){
33696 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
 
 
 
 
 
33697 }else if( cli_strcmp(z,"-ascii")==0 ){
33698 data.mode = MODE_Ascii;
33699 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Unit);
33700 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Record);
33701 }else if( cli_strcmp(z,"-tabs")==0 ){
@@ -33912,11 +34001,11 @@
33912 }
33913 }
33914 #ifndef SQLITE_SHELL_FIDDLE
33915 /* In WASM mode we have to leave the db state in place so that
33916 ** client code can "push" SQL into it after this call returns. */
33917 #ifndef SQLITE_OMIT_VIRTUALTABLE
33918 if( data.expert.pExpert ){
33919 expertFinish(&data, 1, 0);
33920 }
33921 #endif
33922 shell_main_exit:
33923
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1495,12 +1495,12 @@
1495 v = (v<<4) + x;
1496 zArg++;
1497 }
1498 }else{
1499 while( IsDigit(zArg[0]) ){
1500 if( v>=922337203685477580LL ){
1501 if( v>922337203685477580LL || zArg[0]>='8' ) goto integer_overflow;
1502 }
1503 v = v*10 + (zArg[0] - '0');
1504 zArg++;
1505 }
1506 }
@@ -6125,23 +6125,24 @@
6125 ** Examples:
6126 **
6127 ** SELECT * FROM generate_series(0,100,5);
6128 **
6129 ** The query above returns integers from 0 through 100 counting by steps
6130 ** of 5. In other words, 0, 5, 10, 15, ..., 90, 95, 100. There are a total
6131 ** of 21 rows.
6132 **
6133 ** SELECT * FROM generate_series(0,100);
6134 **
6135 ** Integers from 0 through 100 with a step size of 1. 101 rows.
6136 **
6137 ** SELECT * FROM generate_series(20) LIMIT 10;
6138 **
6139 ** Integers 20 through 29. 10 rows.
6140 **
6141 ** SELECT * FROM generate_series(0,-100,-5);
6142 **
6143 ** Integers 0 -5 -10 ... -100. 21 rows.
6144 **
6145 ** SELECT * FROM generate_series(0,-1);
6146 **
6147 ** Empty sequence.
6148 **
@@ -6213,143 +6214,92 @@
6214 #include <string.h>
6215 #include <limits.h>
6216 #include <math.h>
6217
6218 #ifndef SQLITE_OMIT_VIRTUALTABLE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6219
6220 /* series_cursor is a subclass of sqlite3_vtab_cursor which will
6221 ** serve as the underlying representation of a cursor that scans
6222 ** over rows of the result.
6223 **
6224 ** iOBase, iOTerm, and iOStep are the original values of the
6225 ** start=, stop=, and step= constraints on the query. These are
6226 ** the values reported by the start, stop, and step columns of the
6227 ** virtual table.
6228 **
6229 ** iBase, iTerm, iStep, and bDescp are the actual values used to generate
6230 ** the sequence. These might be different from the iOxxxx values.
6231 ** For example in
6232 **
6233 ** SELECT value FROM generate_series(1,11,2)
6234 ** WHERE value BETWEEN 4 AND 8;
6235 **
6236 ** The iOBase is 1, but the iBase is 5. iOTerm is 11 but iTerm is 7.
6237 ** Another example:
6238 **
6239 ** SELECT value FROM generate_series(1,15,3) ORDER BY value DESC;
6240 **
6241 ** The cursor initialization for the above query is:
6242 **
6243 ** iOBase = 1 iBase = 13
6244 ** iOTerm = 15 iTerm = 1
6245 ** iOStep = 3 iStep = 3 bDesc = 1
6246 **
6247 ** The actual step size is unsigned so that can have a value of
6248 ** +9223372036854775808 which is needed for querys like this:
6249 **
6250 ** SELECT value
6251 ** FROM generate_series(9223372036854775807,
6252 ** -9223372036854775808,
6253 ** -9223372036854775808)
6254 ** ORDER BY value ASC;
6255 **
6256 ** The setup for the previous query will be:
6257 **
6258 ** iOBase = 9223372036854775807 iBase = -1
6259 ** iOTerm = -9223372036854775808 iTerm = 9223372036854775807
6260 ** iOStep = -9223372036854775808 iStep = 9223372036854775808 bDesc = 0
6261 */
6262 /* typedef unsigned char u8; */
6263 typedef struct series_cursor series_cursor;
6264 struct series_cursor {
6265 sqlite3_vtab_cursor base; /* Base class - must be first */
6266 sqlite3_int64 iOBase; /* Original starting value ("start") */
6267 sqlite3_int64 iOTerm; /* Original terminal value ("stop") */
6268 sqlite3_int64 iOStep; /* Original step value */
6269 sqlite3_int64 iBase; /* Starting value to actually use */
6270 sqlite3_int64 iTerm; /* Terminal value to actually use */
6271 sqlite3_uint64 iStep; /* The step size */
6272 sqlite3_int64 iValue; /* Current value */
6273 u8 bDesc; /* iStep is really negative */
6274 u8 bDone; /* True if stepped past last element */
6275 };
6276
6277 /*
6278 ** Computed the difference between two 64-bit signed integers using a
6279 ** convoluted computation designed to work around the silly restriction
6280 ** against signed integer overflow in C.
6281 */
6282 static sqlite3_uint64 span64(sqlite3_int64 a, sqlite3_int64 b){
6283 assert( a>=b );
6284 return (*(sqlite3_uint64*)&a) - (*(sqlite3_uint64*)&b);
6285 }
6286
6287 /*
6288 ** Add or substract an unsigned 64-bit integer from a signed 64-bit integer
6289 ** and return the new signed 64-bit integer.
6290 */
6291 static sqlite3_int64 add64(sqlite3_int64 a, sqlite3_uint64 b){
6292 sqlite3_uint64 x = *(sqlite3_uint64*)&a;
6293 x += b;
6294 return *(sqlite3_int64*)&x;
6295 }
6296 static sqlite3_int64 sub64(sqlite3_int64 a, sqlite3_uint64 b){
6297 sqlite3_uint64 x = *(sqlite3_uint64*)&a;
6298 x -= b;
6299 return *(sqlite3_int64*)&x;
6300 }
6301
6302 /*
6303 ** The seriesConnect() method is invoked to create a new
6304 ** series_vtab that describes the generate_series virtual table.
6305 **
@@ -6427,11 +6377,19 @@
6377 /*
6378 ** Advance a series_cursor to its next row of output.
6379 */
6380 static int seriesNext(sqlite3_vtab_cursor *cur){
6381 series_cursor *pCur = (series_cursor*)cur;
6382 if( pCur->iValue==pCur->iTerm ){
6383 pCur->bDone = 1;
6384 }else if( pCur->bDesc ){
6385 pCur->iValue = sub64(pCur->iValue, pCur->iStep);
6386 assert( pCur->iValue>=pCur->iTerm );
6387 }else{
6388 pCur->iValue = add64(pCur->iValue, pCur->iStep);
6389 assert( pCur->iValue<=pCur->iTerm );
6390 }
6391 return SQLITE_OK;
6392 }
6393
6394 /*
6395 ** Return values of columns for the row at which the series_cursor
@@ -6443,50 +6401,64 @@
6401 int i /* Which column to return */
6402 ){
6403 series_cursor *pCur = (series_cursor*)cur;
6404 sqlite3_int64 x = 0;
6405 switch( i ){
6406 case SERIES_COLUMN_START: x = pCur->iOBase; break;
6407 case SERIES_COLUMN_STOP: x = pCur->iOTerm; break;
6408 case SERIES_COLUMN_STEP: x = pCur->iOStep; break;
6409 default: x = pCur->iValue; break;
6410 }
6411 sqlite3_result_int64(ctx, x);
6412 return SQLITE_OK;
6413 }
6414
6415 #ifndef LARGEST_UINT64
6416 #define LARGEST_INT64 ((sqlite3_int64)0x7fffffffffffffffLL)
6417 #define LARGEST_UINT64 ((sqlite3_uint64)0xffffffffffffffffULL)
6418 #define SMALLEST_INT64 ((sqlite3_int64)0x8000000000000000LL)
6419 #endif
6420
6421 /*
6422 ** The rowid is the same as the value.
6423 */
6424 static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
6425 series_cursor *pCur = (series_cursor*)cur;
6426 *pRowid = pCur->iValue;
6427 return SQLITE_OK;
6428 }
6429
6430 /*
6431 ** Return TRUE if the cursor has been moved off of the last
6432 ** row of output.
6433 */
6434 static int seriesEof(sqlite3_vtab_cursor *cur){
6435 series_cursor *pCur = (series_cursor*)cur;
6436 return pCur->bDone;
6437 }
6438
6439 /* True to cause run-time checking of the start=, stop=, and/or step=
6440 ** parameters. The only reason to do this is for testing the
6441 ** constraint checking logic for virtual tables in the SQLite core.
6442 */
6443 #ifndef SQLITE_SERIES_CONSTRAINT_VERIFY
6444 # define SQLITE_SERIES_CONSTRAINT_VERIFY 0
6445 #endif
6446
6447 /*
6448 ** Return the number of steps between pCur->iBase and pCur->iTerm if
6449 ** the step width is pCur->iStep.
6450 */
6451 static sqlite3_uint64 seriesSteps(series_cursor *pCur){
6452 if( pCur->bDesc ){
6453 assert( pCur->iBase >= pCur->iTerm );
6454 return span64(pCur->iBase, pCur->iTerm)/pCur->iStep;
6455 }else{
6456 assert( pCur->iBase <= pCur->iTerm );
6457 return span64(pCur->iTerm, pCur->iBase)/pCur->iStep;
6458 }
6459 }
6460
6461 /*
6462 ** This method is called to "rewind" the series_cursor object back
6463 ** to the first row of output. This method is always called at least
6464 ** once prior to any call to seriesColumn() or seriesRowid() or
@@ -6517,189 +6489,244 @@
6489 sqlite3_vtab_cursor *pVtabCursor,
6490 int idxNum, const char *idxStrUnused,
6491 int argc, sqlite3_value **argv
6492 ){
6493 series_cursor *pCur = (series_cursor *)pVtabCursor;
6494 int iArg = 0; /* Arguments used so far */
6495 int i; /* Loop counter */
6496 sqlite3_int64 iMin = SMALLEST_INT64; /* Smallest allowed output value */
6497 sqlite3_int64 iMax = LARGEST_INT64; /* Largest allowed output value */
6498 sqlite3_int64 iLimit = 0; /* if >0, the value of the LIMIT */
6499 sqlite3_int64 iOffset = 0; /* if >0, the value of the OFFSET */
6500
6501 (void)idxStrUnused;
6502
6503 /* If any constraints have a NULL value, then return no rows.
6504 ** See ticket https://sqlite.org/src/info/fac496b61722daf2
6505 */
6506 for(i=0; i<argc; i++){
6507 if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
6508 goto series_no_rows;
6509 }
6510 }
6511
6512 /* Capture the three HIDDEN parameters to the virtual table and insert
6513 ** default values for any parameters that are omitted.
6514 */
6515 if( idxNum & 0x01 ){
6516 pCur->iOBase = sqlite3_value_int64(argv[iArg++]);
6517 }else{
6518 pCur->iOBase = 0;
6519 }
6520 if( idxNum & 0x02 ){
6521 pCur->iOTerm = sqlite3_value_int64(argv[iArg++]);
6522 }else{
6523 pCur->iOTerm = 0xffffffff;
6524 }
6525 if( idxNum & 0x04 ){
6526 pCur->iOStep = sqlite3_value_int64(argv[iArg++]);
6527 if( pCur->iOStep==0 ) pCur->iOStep = 1;
 
 
 
 
6528 }else{
6529 pCur->iOStep = 1;
6530 }
6531
6532 /* If there are constraints on the value column but there are
6533 ** no constraints on the start, stop, and step columns, then
6534 ** initialize the default range to be the entire range of 64-bit signed
6535 ** integers. This range will contracted by the value column constraints
6536 ** further below.
6537 */
6538 if( (idxNum & 0x05)==0 && (idxNum & 0x0380)!=0 ){
6539 pCur->iOBase = SMALLEST_INT64;
6540 }
6541 if( (idxNum & 0x06)==0 && (idxNum & 0x3080)!=0 ){
6542 pCur->iOTerm = LARGEST_INT64;
6543 }
6544 pCur->iBase = pCur->iOBase;
6545 pCur->iTerm = pCur->iOTerm;
6546 if( pCur->iOStep>0 ){
6547 pCur->iStep = pCur->iOStep;
6548 }else if( pCur->iOStep>SMALLEST_INT64 ){
6549 pCur->iStep = -pCur->iOStep;
6550 }else{
6551 pCur->iStep = LARGEST_INT64;
6552 pCur->iStep++;
6553 }
6554 pCur->bDesc = pCur->iOStep<0;
6555 if( pCur->bDesc==0 && pCur->iBase>pCur->iTerm ){
6556 goto series_no_rows;
6557 }
6558 if( pCur->bDesc!=0 && pCur->iBase<pCur->iTerm ){
6559 goto series_no_rows;
6560 }
6561
6562 /* Extract the LIMIT and OFFSET values, but do not apply them yet.
6563 ** The range must first be constrained by the limits on value.
6564 */
6565 if( idxNum & 0x20 ){
6566 iLimit = sqlite3_value_int64(argv[iArg++]);
6567 if( idxNum & 0x40 ){
6568 iOffset = sqlite3_value_int64(argv[iArg++]);
6569 }
6570 }
6571
6572 /* Narrow the range of iMin and iMax (the minimum and maximum outputs)
6573 ** based on equality and inequality constraints on the "value" column.
6574 */
6575 if( idxNum & 0x3380 ){
6576 if( idxNum & 0x0080 ){ /* value=X */
6577 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
6578 double r = sqlite3_value_double(argv[iArg++]);
6579 if( r==ceil(r)
6580 && r>=(double)SMALLEST_INT64
6581 && r<=(double)LARGEST_INT64
6582 ){
6583 iMin = iMax = (sqlite3_int64)r;
6584 }else{
6585 goto series_no_rows;
6586 }
6587 }else{
6588 iMin = iMax = sqlite3_value_int64(argv[iArg++]);
6589 }
6590 }else{
6591 if( idxNum & 0x0300 ){ /* value>X or value>=X */
6592 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
6593 double r = sqlite3_value_double(argv[iArg++]);
6594 if( r<(double)SMALLEST_INT64 ){
6595 iMin = SMALLEST_INT64;
6596 }else if( (idxNum & 0x0200)!=0 && r==ceil(r) ){
6597 iMin = (sqlite3_int64)ceil(r+1.0);
6598 }else{
6599 iMin = (sqlite3_int64)ceil(r);
6600 }
6601 }else{
6602 iMin = sqlite3_value_int64(argv[iArg++]);
6603 if( (idxNum & 0x0200)!=0 ){
6604 if( iMin==LARGEST_INT64 ){
6605 goto series_no_rows;
6606 }else{
6607 iMin++;
6608 }
6609 }
6610 }
6611 }
6612 if( idxNum & 0x3000 ){ /* value<X or value<=X */
6613 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
6614 double r = sqlite3_value_double(argv[iArg++]);
6615 if( r>(double)LARGEST_INT64 ){
6616 iMax = LARGEST_INT64;
6617 }else if( (idxNum & 0x2000)!=0 && r==floor(r) ){
6618 iMax = (sqlite3_int64)(r-1.0);
6619 }else{
6620 iMax = (sqlite3_int64)floor(r);
6621 }
6622 }else{
6623 iMax = sqlite3_value_int64(argv[iArg++]);
6624 if( idxNum & 0x2000 ){
6625 if( iMax==SMALLEST_INT64 ){
6626 goto series_no_rows;
6627 }else{
6628 iMax--;
6629 }
6630 }
6631 }
6632 }
6633 if( iMin>iMax ){
6634 goto series_no_rows;
6635 }
6636 }
6637
6638 /* Try to reduce the range of values to be generated based on
6639 ** constraints on the "value" column.
6640 */
6641 if( pCur->bDesc==0 ){
6642 if( pCur->iBase<iMin ){
6643 sqlite3_uint64 span = span64(iMin,pCur->iBase);
6644 pCur->iBase = add64(pCur->iBase, (span/pCur->iStep)*pCur->iStep);
6645 if( pCur->iBase<iMin ){
6646 if( pCur->iBase > sub64(LARGEST_INT64, pCur->iStep) ){
6647 goto series_no_rows;
6648 }
6649 pCur->iBase = add64(pCur->iBase, pCur->iStep);
6650 }
6651 }
6652 if( pCur->iTerm>iMax ){
6653 pCur->iTerm = iMax;
6654 }
6655 }else{
6656 if( pCur->iBase>iMax ){
6657 sqlite3_uint64 span = span64(pCur->iBase,iMax);
6658 pCur->iBase = sub64(pCur->iBase, (span/pCur->iStep)*pCur->iStep);
6659 if( pCur->iBase>iMax ){
6660 if( pCur->iBase < add64(SMALLEST_INT64, pCur->iStep) ){
6661 goto series_no_rows;
6662 }
6663 pCur->iBase = sub64(pCur->iBase, pCur->iStep);
6664 }
6665 }
6666 if( pCur->iTerm<iMin ){
6667 pCur->iTerm = iMin;
6668 }
6669 }
6670 }
6671
6672 /* Adjust iTerm so that it is exactly the last value of the series.
6673 */
6674 if( pCur->bDesc==0 ){
6675 if( pCur->iBase>pCur->iTerm ){
6676 goto series_no_rows;
6677 }
6678 pCur->iTerm = sub64(pCur->iTerm,
6679 span64(pCur->iTerm,pCur->iBase) % pCur->iStep);
6680 }else{
6681 if( pCur->iBase<pCur->iTerm ){
6682 goto series_no_rows;
6683 }
6684 pCur->iTerm = add64(pCur->iTerm,
6685 span64(pCur->iBase,pCur->iTerm) % pCur->iStep);
6686 }
6687
6688 /* Transform the series generator to output values in the requested
6689 ** order.
6690 */
6691 if( ((idxNum & 0x0008)!=0 && pCur->bDesc==0)
6692 || ((idxNum & 0x0010)!=0 && pCur->bDesc!=0)
6693 ){
6694 sqlite3_int64 tmp = pCur->iBase;
6695 pCur->iBase = pCur->iTerm;
6696 pCur->iTerm = tmp;
6697 pCur->bDesc = !pCur->bDesc;
6698 }
6699
6700 /* Apply LIMIT and OFFSET constraints, if any */
6701 assert( pCur->iStep!=0 );
6702 if( idxNum & 0x20 ){
6703 sqlite3_uint64 nStep;
6704 if( iOffset>0 ){
6705 if( seriesSteps(pCur) < (sqlite3_uint64)iOffset ){
6706 goto series_no_rows;
6707 }else if( pCur->bDesc ){
6708 pCur->iBase = sub64(pCur->iBase, pCur->iStep*iOffset);
6709 }else{
6710 pCur->iBase = add64(pCur->iBase, pCur->iStep*iOffset);
6711 }
6712 }
6713 if( iLimit>=0 && (nStep = seriesSteps(pCur)) > (sqlite3_uint64)iLimit ){
6714 pCur->iTerm = add64(pCur->iBase, (iLimit - 1)*pCur->iStep);
6715 }
6716 }
6717 pCur->iValue = pCur->iBase;
6718 pCur->bDone = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6719 return SQLITE_OK;
6720
6721 series_no_rows:
6722 pCur->iBase = 0;
6723 pCur->iTerm = 0;
6724 pCur->iStep = 1;
6725 pCur->bDesc = 0;
6726 pCur->bDone = 1;
6727 return SQLITE_OK;
6728 }
6729
6730 /*
6731 ** SQLite will invoke this method one or more times while planning a query
6732 ** that uses the generate_series virtual table. This routine needs to create
@@ -9384,18 +9411,20 @@
9411 if( idxNum & 1 ){
9412 pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
9413 if( pCur->nPrefix>0 ){
9414 pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
9415 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
9416 pCur->nPrefix = (int)strlen(pCur->zPrefix);
9417 }
9418 iArg = 1;
9419 }
9420 if( idxNum & 2 ){
9421 pCur->nLine = sqlite3_value_bytes(argv[iArg]);
9422 if( pCur->nLine>0 ){
9423 pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
9424 if( pCur->zLine==0 ) return SQLITE_NOMEM;
9425 pCur->nLine = (int)strlen(pCur->zLine);
9426 }
9427 }
9428 if( pCur->zLine!=0 && pCur->zPrefix==0 ){
9429 int i = pCur->nLine;
9430 while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
@@ -9403,10 +9432,11 @@
9432 }
9433 pCur->nPrefix = pCur->nLine - i;
9434 if( pCur->nPrefix>0 ){
9435 pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
9436 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
9437 pCur->nPrefix = (int)strlen(pCur->zPrefix);
9438 }
9439 }
9440 pCur->iRowid = 0;
9441 pCur->ePhase = COMPLETION_FIRST_PHASE;
9442 return completionNext(pVtabCursor);
@@ -10316,13 +10346,18 @@
10346 "method," /* 6: Compression method (integer) */
10347 "z HIDDEN" /* 7: Name of zip file */
10348 ") WITHOUT ROWID;";
10349
10350 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
 
10351 #define ZIPFILE_MX_NAME (250) /* Windows limitation on filename size */
10352
10353 /*
10354 ** The buffer should be large enough to contain 3 65536 byte strings - the
10355 ** filename, the extra field and the file comment.
10356 */
10357 #define ZIPFILE_BUFFER_SIZE (200*1024)
10358
10359
10360 /*
10361 ** Magic numbers used to read and write zip files.
10362 **
10363 ** ZIPFILE_NEWENTRY_MADEBY:
@@ -11000,10 +11035,19 @@
11035 || mUnixTime==zipfileMtime(pCds)
11036 || ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
11037 /* || (mUnixTime % 2) */
11038 );
11039 }
11040
11041 /*
11042 ** Set (*pzErr) to point to a buffer from sqlite3_malloc() containing a
11043 ** generic corruption message and return SQLITE_CORRUPT;
11044 */
11045 static int zipfileCorrupt(char **pzErr){
11046 *pzErr = sqlite3_mprintf("zip archive is corrupt");
11047 return SQLITE_CORRUPT;
11048 }
11049
11050 /*
11051 ** If aBlob is not NULL, then it is a pointer to a buffer (nBlob bytes in
11052 ** size) containing an entire zip archive image. Or, if aBlob is NULL,
11053 ** then pFile is a file-handle open on a zip file. In either case, this
@@ -11023,16 +11067,19 @@
11067 ZipfileEntry **ppEntry /* OUT: Pointer to new object */
11068 ){
11069 u8 *aRead;
11070 char **pzErr = &pTab->base.zErrMsg;
11071 int rc = SQLITE_OK;
 
11072
11073 if( aBlob==0 ){
11074 aRead = pTab->aBuffer;
11075 rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr);
11076 }else{
11077 if( (iOff+ZIPFILE_CDS_FIXED_SZ)>nBlob ){
11078 /* Not enough data for the CDS structure. Corruption. */
11079 return zipfileCorrupt(pzErr);
11080 }
11081 aRead = (u8*)&aBlob[iOff];
11082 }
11083
11084 if( rc==SQLITE_OK ){
11085 sqlite3_int64 nAlloc;
@@ -11059,10 +11106,13 @@
11106 rc = zipfileReadData(
11107 pFile, aRead, nExtra+nFile, iOff+ZIPFILE_CDS_FIXED_SZ, pzErr
11108 );
11109 }else{
11110 aRead = (u8*)&aBlob[iOff + ZIPFILE_CDS_FIXED_SZ];
11111 if( (iOff + ZIPFILE_LFH_FIXED_SZ + nFile + nExtra)>nBlob ){
11112 rc = zipfileCorrupt(pzErr);
11113 }
11114 }
11115 }
11116
11117 if( rc==SQLITE_OK ){
11118 u32 *pt = &pNew->mUnixTime;
@@ -11081,19 +11131,22 @@
11131 ZipfileLFH lfh;
11132 if( pFile ){
11133 rc = zipfileReadData(pFile, aRead, szFix, pNew->cds.iOffset, pzErr);
11134 }else{
11135 aRead = (u8*)&aBlob[pNew->cds.iOffset];
11136 if( (pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ)>nBlob ){
11137 rc = zipfileCorrupt(pzErr);
11138 }
11139 }
11140
11141 if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
11142 if( rc==SQLITE_OK ){
11143 pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
11144 pNew->iDataOff += lfh.nFile + lfh.nExtra;
11145 if( aBlob && pNew->cds.szCompressed ){
11146 if( pNew->iDataOff + pNew->cds.szCompressed > nBlob ){
11147 rc = zipfileCorrupt(pzErr);
11148 }else{
11149 pNew->aData = &pNew->aExtra[nExtra];
11150 memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
11151 }
11152 }
@@ -12595,10 +12648,11 @@
12648 return rc;
12649 }
12650
12651 /************************* End ../ext/misc/sqlar.c ********************/
12652 #endif
12653 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
12654 /************************* Begin ../ext/expert/sqlite3expert.h ******************/
12655 /*
12656 ** 2017 April 07
12657 **
12658 ** The author disclaims copyright to this source code. In place of
@@ -15003,10 +15057,11 @@
15057 }
15058
15059 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
15060
15061 /************************* End ../ext/expert/sqlite3expert.c ********************/
15062 #endif
15063 /************************* Begin ../ext/intck/sqlite3intck.h ******************/
15064 /*
15065 ** 2024-02-08
15066 **
15067 ** The author disclaims copyright to this source code. In place of
@@ -21643,15 +21698,17 @@
21698 char **azFilter; /* Array of xFilter rejection GLOB patterns */
21699 sqlite3_session *p; /* The open session */
21700 };
21701 #endif
21702
21703 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
21704 typedef struct ExpertInfo ExpertInfo;
21705 struct ExpertInfo {
21706 sqlite3expert *pExpert;
21707 int bVerbose;
21708 };
21709 #endif
21710
21711 /* A single line in the EQP output */
21712 typedef struct EQPGraphRow EQPGraphRow;
21713 struct EQPGraphRow {
21714 int iEqpId; /* ID for this row */
@@ -21751,11 +21808,13 @@
21808 int *aiIndent; /* Array of indents used in MODE_Explain */
21809 int nIndent; /* Size of array aiIndent[] */
21810 int iIndent; /* Index of current op in aiIndent[] */
21811 char *zNonce; /* Nonce for temporary safe-mode escapes */
21812 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
21813 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
21814 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
21815 #endif
21816 #ifdef SQLITE_SHELL_FIDDLE
21817 struct {
21818 const char * zInput; /* Input string from wasm/JS proxy */
21819 const char * zPos; /* Cursor pos into zInput */
21820 const char * zDefaultDbName; /* Default name for db file */
@@ -21779,13 +21838,12 @@
21838 */
21839 #define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
21840 #define SHELL_OPEN_NORMAL 1 /* Normal database file */
21841 #define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */
21842 #define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */
21843 #define SHELL_OPEN_DESERIALIZE 4 /* Open using sqlite3_deserialize() */
21844 #define SHELL_OPEN_HEXDB 5 /* Use "dbtotxt" output as data source */
 
21845
21846 /* Allowed values for ShellState.eTraceType
21847 */
21848 #define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
21849 #define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
@@ -24688,11 +24746,11 @@
24746 }
24747 }
24748 }
24749 }
24750
24751 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
24752 /*
24753 ** This function is called to process SQL if the previous shell command
24754 ** was ".expert". It passes the SQL in the second argument directly to
24755 ** the sqlite3expert object.
24756 **
@@ -24820,11 +24878,11 @@
24878 }
24879 sqlite3_free(zErr);
24880
24881 return rc;
24882 }
24883 #endif /* !SQLITE_OMIT_VIRTUALTABLE && !SQLITE_OMIT_AUTHORIZATION */
24884
24885 /*
24886 ** Execute a statement or set of statements. Print
24887 ** any result rows/columns depending on the current mode
24888 ** set via the supplied callback.
@@ -24846,11 +24904,11 @@
24904
24905 if( pzErrMsg ){
24906 *pzErrMsg = NULL;
24907 }
24908
24909 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
24910 if( pArg->expert.pExpert ){
24911 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
24912 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
24913 }
24914 #endif
@@ -25008,11 +25066,11 @@
25066 static char **tableColumnList(ShellState *p, const char *zTab){
25067 char **azCol = 0;
25068 sqlite3_stmt *pStmt;
25069 char *zSql;
25070 int nCol = 0;
25071 i64 nAlloc = 0;
25072 int nPK = 0; /* Number of PRIMARY KEY columns seen */
25073 int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */
25074 int preserveRowid = ShellHasFlag(p, SHFLG_PreserveRowid);
25075 int rc;
25076
@@ -25022,11 +25080,11 @@
25080 sqlite3_free(zSql);
25081 if( rc ) return 0;
25082 while( sqlite3_step(pStmt)==SQLITE_ROW ){
25083 if( nCol>=nAlloc-2 ){
25084 nAlloc = nAlloc*2 + nCol + 10;
25085 azCol = sqlite3_realloc64(azCol, nAlloc*sizeof(azCol[0]));
25086 shell_check_oom(azCol);
25087 }
25088 azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
25089 shell_check_oom(azCol[nCol]);
25090 if( sqlite3_column_int(pStmt, 5) ){
@@ -25352,11 +25410,13 @@
25410 " --bom Put a UTF8 byte-order mark on intermediate file",
25411 #endif
25412 #ifndef SQLITE_SHELL_FIDDLE
25413 ".exit ?CODE? Exit this program with return-code CODE",
25414 #endif
25415 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
25416 ".expert EXPERIMENTAL. Suggest indexes for queries",
25417 #endif
25418 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
25419 ".filectrl CMD ... Run various sqlite3_file_control() operations",
25420 " --schema SCHEMA Use SCHEMA instead of \"main\"",
25421 " --help Show CMD details",
25422 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
@@ -25444,11 +25504,17 @@
25504 " Options:",
25505 " --append Use appendvfs to append database to the end of FILE",
25506 #endif
25507 #ifndef SQLITE_OMIT_DESERIALIZE
25508 " --deserialize Load into memory using sqlite3_deserialize()",
25509 #endif
25510 /*" --exclusive Set the SQLITE_OPEN_EXCLUSIVE flag", UNDOCUMENTED */
25511 #ifndef SQLITE_OMIT_DESERIALIZE
25512 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
25513 #endif
25514 " --ifexist Only open if FILE already exists",
25515 #ifndef SQLITE_OMIT_DESERIALIZE
25516 " --maxsize N Maximum size for --hexdb or --deserialized database",
25517 #endif
25518 " --new Initialize FILE to an empty database",
25519 " --nofollow Do not follow symbolic links",
25520 " --readonly Open FILE readonly",
@@ -25865,11 +25931,11 @@
25931 if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
25932 sqlite3_fputs("invalid pagesize\n", stderr);
25933 goto readHexDb_error;
25934 }
25935 sz = ((i64)n+pgsz-1)&~(pgsz-1); /* Round up to nearest multiple of pgsz */
25936 a = sqlite3_malloc64( sz ? sz : 1 );
25937 shell_check_oom(a);
25938 memset(a, 0, sz);
25939 for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){
25940 int j = 0; /* Page number from "| page" line */
25941 int k = 0; /* Offset from "| page" line */
@@ -25989,14 +26055,17 @@
26055 }else{
26056 p->openMode = (u8)deduceDatabaseType(zDbFilename,
26057 (openFlags & OPEN_DB_ZIPFILE)!=0);
26058 }
26059 }
26060 if( (p->openFlags & (SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE))==0 ){
26061 if( p->openFlags==0 ) p->openFlags = SQLITE_OPEN_CREATE;
26062 p->openFlags |= SQLITE_OPEN_READWRITE;
26063 }
26064 switch( p->openMode ){
26065 case SHELL_OPEN_APPENDVFS: {
26066 sqlite3_open_v2(zDbFilename, &p->db, p->openFlags, "apndvfs");
 
26067 break;
26068 }
26069 case SHELL_OPEN_HEXDB:
26070 case SHELL_OPEN_DESERIALIZE: {
26071 sqlite3_open(0, &p->db);
@@ -26004,19 +26073,13 @@
26073 }
26074 case SHELL_OPEN_ZIPFILE: {
26075 sqlite3_open(":memory:", &p->db);
26076 break;
26077 }
 
 
 
 
 
26078 case SHELL_OPEN_UNSPEC:
26079 case SHELL_OPEN_NORMAL: {
26080 sqlite3_open_v2(zDbFilename, &p->db, p->openFlags, 0);
 
26081 break;
26082 }
26083 }
26084 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
26085 sqlite3_fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
@@ -26151,13 +26214,15 @@
26214 }
26215 }
26216 #endif
26217 }
26218 if( p->db!=0 ){
26219 #ifndef SQLITE_OMIT_AUTHORIZATION
26220 if( p->bSafeModePersist ){
26221 sqlite3_set_authorizer(p->db, safeModeAuth, p);
26222 }
26223 #endif
26224 sqlite3_db_config(
26225 p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0
26226 );
26227 }
26228 }
@@ -26466,12 +26531,12 @@
26531 struct ImportCtx {
26532 const char *zFile; /* Name of the input file */
26533 FILE *in; /* Read the CSV text from this input stream */
26534 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close in */
26535 char *z; /* Accumulated text for a field */
26536 i64 n; /* Number of bytes in z */
26537 i64 nAlloc; /* Space allocated for z[] */
26538 int nLine; /* Current line number */
26539 int nRow; /* Number of rows imported */
26540 int nErr; /* Number of errors encountered */
26541 int bNotFirst; /* True if one or more bytes already read */
26542 int cTerm; /* Character that terminated the most recent field */
@@ -27091,11 +27156,15 @@
27156 if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
27157 zTail = strrchr(zFilename, '/');
27158 #if defined(_WIN32)
27159 if( zTail==0 ) zTail = strrchr(zFilename, '\\');
27160 #endif
27161 if( zTail==0 ){
27162 zTail = zFilename;
27163 }else if( zTail[1]!=0 ){
27164 zTail++;
27165 }
27166 }
27167 zName = strdup(zTail);
27168 shell_check_oom(zName);
27169 sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
27170 nPage*pgSz, pgSz, zName);
@@ -28816,11 +28885,11 @@
28885 int nArg = 0;
28886 int n, c;
28887 int rc = 0;
28888 char *azArg[52];
28889
28890 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
28891 if( p->expert.pExpert ){
28892 expertFinish(p, 1, 0);
28893 }
28894 #endif
28895
@@ -29117,11 +29186,11 @@
29186 }else{
29187 while( sqlite3_step(pStmt)==SQLITE_ROW ){
29188 const char *zSchema = (const char *)sqlite3_column_text(pStmt,1);
29189 const char *zFile = (const char*)sqlite3_column_text(pStmt,2);
29190 if( zSchema==0 || zFile==0 ) continue;
29191 azName = sqlite3_realloc64(azName, (nName+1)*2*sizeof(char*));
29192 shell_check_oom(azName);
29193 azName[nName*2] = strdup(zSchema);
29194 azName[nName*2+1] = strdup(zFile);
29195 nName++;
29196 }
@@ -29385,11 +29454,11 @@
29454 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
29455 p->autoExplain = 1;
29456 }
29457 }else
29458
29459 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
29460 if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
29461 if( p->bSafeMode ){
29462 sqlite3_fprintf(stderr,
29463 "Cannot run experimental commands such as \"%s\" in safe mode\n",
29464 azArg[0]);
@@ -30385,10 +30454,11 @@
30454 const char *zFN = 0; /* Pointer to constant filename */
30455 char *zNewFilename = 0; /* Name of the database file to open */
30456 int iName = 1; /* Index in azArg[] of the filename */
30457 int newFlag = 0; /* True to delete file before opening */
30458 int openMode = SHELL_OPEN_UNSPEC;
30459 int openFlags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
30460
30461 /* Check for command-line arguments */
30462 for(iName=1; iName<nArg; iName++){
30463 const char *z = azArg[iName];
30464 #ifndef SQLITE_SHELL_FIDDLE
@@ -30399,13 +30469,18 @@
30469 openMode = SHELL_OPEN_ZIPFILE;
30470 #endif
30471 }else if( optionMatch(z, "append") ){
30472 openMode = SHELL_OPEN_APPENDVFS;
30473 }else if( optionMatch(z, "readonly") ){
30474 openFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
30475 openFlags |= SQLITE_OPEN_READONLY;
30476 }else if( optionMatch(z, "exclusive") ){
30477 openFlags |= SQLITE_OPEN_EXCLUSIVE;
30478 }else if( optionMatch(z, "ifexists") ){
30479 openFlags &= ~(SQLITE_OPEN_CREATE);
30480 }else if( optionMatch(z, "nofollow") ){
30481 openFlags |= SQLITE_OPEN_NOFOLLOW;
30482 #ifndef SQLITE_OMIT_DESERIALIZE
30483 }else if( optionMatch(z, "deserialize") ){
30484 openMode = SHELL_OPEN_DESERIALIZE;
30485 }else if( optionMatch(z, "hexdb") ){
30486 openMode = SHELL_OPEN_HEXDB;
@@ -30433,11 +30508,11 @@
30508 p->db = 0;
30509 p->pAuxDb->zDbFilename = 0;
30510 sqlite3_free(p->pAuxDb->zFreeOnClose);
30511 p->pAuxDb->zFreeOnClose = 0;
30512 p->openMode = openMode;
30513 p->openFlags = openFlags;
30514 p->szMax = 0;
30515
30516 /* If a filename is specified, try to open it first */
30517 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
30518 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
@@ -31175,19 +31250,20 @@
31250
31251 /* .session filter GLOB ....
31252 ** Set a list of GLOB patterns of table names to be excluded.
31253 */
31254 if( cli_strcmp(azCmd[0], "filter")==0 ){
31255 int ii;
31256 i64 nByte;
31257 if( nCmd<2 ) goto session_syntax_error;
31258 if( pAuxDb->nSession ){
31259 for(ii=0; ii<pSession->nFilter; ii++){
31260 sqlite3_free(pSession->azFilter[ii]);
31261 }
31262 sqlite3_free(pSession->azFilter);
31263 nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
31264 pSession->azFilter = sqlite3_malloc64( nByte );
31265 shell_check_oom( pSession->azFilter );
31266 for(ii=1; ii<nCmd; ii++){
31267 char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]);
31268 shell_check_oom(x);
31269 }
@@ -33121,10 +33197,11 @@
33197 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
33198 " -heap SIZE Size of heap for memsys3 or memsys5\n"
33199 #endif
33200 " -help show this message\n"
33201 " -html set output mode to HTML\n"
33202 " -ifexists only open if database already exists\n"
33203 " -interactive force interactive I/O\n"
33204 " -json set output mode to 'json'\n"
33205 " -line set output mode to 'line'\n"
33206 " -list set output mode to 'list'\n"
33207 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
@@ -33533,13 +33610,19 @@
33610 data.openMode = SHELL_OPEN_DESERIALIZE;
33611 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33612 data.szMax = integerValue(argv[++i]);
33613 #endif
33614 }else if( cli_strcmp(z,"-readonly")==0 ){
33615 data.openFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
33616 data.openFlags |= SQLITE_OPEN_READONLY;
33617 }else if( cli_strcmp(z,"-nofollow")==0 ){
33618 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
33619 }else if( cli_strcmp(z,"-exclusive")==0 ){ /* UNDOCUMENTED */
33620 data.openFlags |= SQLITE_OPEN_EXCLUSIVE;
33621 }else if( cli_strcmp(z,"-ifexists")==0 ){
33622 data.openFlags &= ~(SQLITE_OPEN_CREATE);
33623 if( data.openFlags==0 ) data.openFlags = SQLITE_OPEN_READWRITE;
33624 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
33625 }else if( cli_strncmp(z, "-A",2)==0 ){
33626 /* All remaining command-line arguments are passed to the ".archive"
33627 ** command, so ignore them */
33628 break;
@@ -33689,13 +33772,19 @@
33772 data.openMode = SHELL_OPEN_DESERIALIZE;
33773 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33774 data.szMax = integerValue(argv[++i]);
33775 #endif
33776 }else if( cli_strcmp(z,"-readonly")==0 ){
33777 data.openFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
33778 data.openFlags |= SQLITE_OPEN_READONLY;
33779 }else if( cli_strcmp(z,"-nofollow")==0 ){
33780 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
33781 }else if( cli_strcmp(z,"-exclusive")==0 ){ /* UNDOCUMENTED */
33782 data.openFlags |= SQLITE_OPEN_EXCLUSIVE;
33783 }else if( cli_strcmp(z,"-ifexists")==0 ){
33784 data.openFlags &= ~(SQLITE_OPEN_CREATE);
33785 if( data.openFlags==0 ) data.openFlags = SQLITE_OPEN_READWRITE;
33786 }else if( cli_strcmp(z,"-ascii")==0 ){
33787 data.mode = MODE_Ascii;
33788 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,SEP_Unit);
33789 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,SEP_Record);
33790 }else if( cli_strcmp(z,"-tabs")==0 ){
@@ -33912,11 +34001,11 @@
34001 }
34002 }
34003 #ifndef SQLITE_SHELL_FIDDLE
34004 /* In WASM mode we have to leave the db state in place so that
34005 ** client code can "push" SQL into it after this call returns. */
34006 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_AUTHORIZATION)
34007 if( data.expert.pExpert ){
34008 expertFinish(&data, 1, 0);
34009 }
34010 #endif
34011 shell_main_exit:
34012
+37 -19
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 2b34b750b5528b6dda195bc1a3895dc3fe46 with changes in files:
21
+** 22b2700ac20bb8e5883d484bfd0aee7a0fbc with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.51.0"
471471
#define SQLITE_VERSION_NUMBER 3051000
472
-#define SQLITE_SOURCE_ID "2025-09-27 11:54:49 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade"
472
+#define SQLITE_SOURCE_ID "2025-10-02 11:28:27 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2025-09-27T11:54:49.147Z"
475
+#define SQLITE_SCM_DATETIME "2025-10-02T11:28:27.740Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -26242,12 +26242,12 @@
2624226242
** %j day of year 001-366
2624326243
** %J ** julian day number
2624426244
** %l hour 1-12 (leading zero converted to space)
2624526245
** %m month 01-12
2624626246
** %M minute 00-59
26247
-** %p "am" or "pm"
26248
-** %P "AM" or "PM"
26247
+** %p "AM" or "PM"
26248
+** %P "am" or "pm"
2624926249
** %R time as HH:MM
2625026250
** %s seconds since 1970-01-01
2625126251
** %S seconds 00-59
2625226252
** %T time as HH:MM:SS
2625326253
** %u day of week 1-7 Monday==1, Sunday==7
@@ -171442,21 +171442,28 @@
171442171442
171443171443
/* Check to see if pWLoop should be added to the set of
171444171444
** mxChoice best-so-far paths.
171445171445
**
171446171446
** First look for an existing path among best-so-far paths
171447
- ** that covers the same set of loops and has the same isOrdered
171448
- ** setting as the current path candidate.
171447
+ ** that:
171448
+ ** (1) covers the same set of loops, and
171449
+ ** (2) has a compatible isOrdered value.
171450
+ **
171451
+ ** "Compatible isOrdered value" means either
171452
+ ** (A) both have isOrdered==-1, or
171453
+ ** (B) both have isOrder>=0, or
171454
+ ** (C) ordering does not matter because this is the last round
171455
+ ** of the solver.
171449171456
**
171450171457
** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
171451171458
** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
171452171459
** of legal values for isOrdered, -1..64.
171453171460
*/
171454171461
testcase( nTo==0 );
171455171462
for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
171456171463
if( pTo->maskLoop==maskNew
171457
- && ((pTo->isOrdered^isOrdered)&0x80)==0
171464
+ && ( ((pTo->isOrdered^isOrdered)&0x80)==0 || iLoop==nLoop-1 )
171458171465
){
171459171466
testcase( jj==nTo-1 );
171460171467
break;
171461171468
}
171462171469
}
@@ -171600,18 +171607,21 @@
171600171607
pFrom = aTo;
171601171608
aTo = aFrom;
171602171609
aFrom = pFrom;
171603171610
nFrom = nTo;
171604171611
}
171605
- assert( nFrom==0 || nFrom==1 );
171606171612
171607171613
if( nFrom==0 ){
171608171614
sqlite3ErrorMsg(pParse, "no query solution");
171609171615
sqlite3StackFreeNN(pParse->db, pSpace);
171610171616
return SQLITE_ERROR;
171611171617
}
171618
+
171619
+ /* Only one path is available, which is the best path */
171620
+ assert( nFrom==1 );
171612171621
pFrom = aFrom;
171622
+
171613171623
assert( pWInfo->nLevel==nLoop );
171614171624
/* Load the lowest cost path into pWInfo */
171615171625
for(iLoop=0; iLoop<nLoop; iLoop++){
171616171626
WhereLevel *pLevel = pWInfo->a + iLoop;
171617171627
pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -206468,14 +206478,10 @@
206468206478
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
206469206479
206470206480
/* #include <string.h> */
206471206481
/* #include <assert.h> */
206472206482
206473
-#ifndef SQLITE_AMALGAMATION
206474
-typedef sqlite3_int64 i64;
206475
-#endif
206476
-
206477206483
/*
206478206484
** Characters that may appear in the second argument to matchinfo().
206479206485
*/
206480206486
#define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */
206481206487
#define FTS3_MATCHINFO_NCOL 'c' /* 1 value */
@@ -212236,11 +212242,23 @@
212236212242
z = sqlite3DbStrNDup(db, (const char*)&pParse->aBlob[i+n], (int)sz);
212237212243
if( z==0 ) goto returnfromblob_oom;
212238212244
rc = sqlite3DecOrHexToI64(z, &iRes);
212239212245
sqlite3DbFree(db, z);
212240212246
if( rc==0 ){
212241
- sqlite3_result_int64(pCtx, bNeg ? -iRes : iRes);
212247
+ if( iRes<0 ){
212248
+ /* A hexadecimal literal with 16 significant digits and with the
212249
+ ** high-order bit set is a negative integer in SQLite (and hence
212250
+ ** iRes comes back as negative) but should be interpreted as a
212251
+ ** positive value if it occurs within JSON. The value is too
212252
+ ** large to appear as an SQLite integer so it must be converted
212253
+ ** into floating point. */
212254
+ double r;
212255
+ r = (double)*(sqlite3_uint64*)&iRes;
212256
+ sqlite3_result_double(pCtx, bNeg ? -r : r);
212257
+ }else{
212258
+ sqlite3_result_int64(pCtx, bNeg ? -iRes : iRes);
212259
+ }
212242212260
}else if( rc==3 && bNeg ){
212243212261
sqlite3_result_int64(pCtx, SMALLEST_INT64);
212244212262
}else if( rc==1 ){
212245212263
goto returnfromblob_malformed;
212246212264
}else{
@@ -258706,11 +258724,11 @@
258706258724
int nArg, /* Number of args */
258707258725
sqlite3_value **apUnused /* Function arguments */
258708258726
){
258709258727
assert( nArg==0 );
258710258728
UNUSED_PARAM2(nArg, apUnused);
258711
- sqlite3_result_text(pCtx, "fts5: 2025-09-27 11:54:49 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade", -1, SQLITE_TRANSIENT);
258729
+ sqlite3_result_text(pCtx, "fts5: 2025-10-02 11:28:27 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43", -1, SQLITE_TRANSIENT);
258712258730
}
258713258731
258714258732
/*
258715258733
** Implementation of fts5_locale(LOCALE, TEXT) function.
258716258734
**
@@ -258729,13 +258747,13 @@
258729258747
sqlite3_context *pCtx, /* Function call context */
258730258748
int nArg, /* Number of args */
258731258749
sqlite3_value **apArg /* Function arguments */
258732258750
){
258733258751
const char *zLocale = 0;
258734
- int nLocale = 0;
258752
+ i64 nLocale = 0;
258735258753
const char *zText = 0;
258736
- int nText = 0;
258754
+ i64 nText = 0;
258737258755
258738258756
assert( nArg==2 );
258739258757
UNUSED_PARAM(nArg);
258740258758
258741258759
zLocale = (const char*)sqlite3_value_text(apArg[0]);
@@ -258748,14 +258766,14 @@
258748258766
sqlite3_result_text(pCtx, zText, nText, SQLITE_TRANSIENT);
258749258767
}else{
258750258768
Fts5Global *p = (Fts5Global*)sqlite3_user_data(pCtx);
258751258769
u8 *pBlob = 0;
258752258770
u8 *pCsr = 0;
258753
- int nBlob = 0;
258771
+ i64 nBlob = 0;
258754258772
258755258773
nBlob = FTS5_LOCALE_HDR_SIZE + nLocale + 1 + nText;
258756
- pBlob = (u8*)sqlite3_malloc(nBlob);
258774
+ pBlob = (u8*)sqlite3_malloc64(nBlob);
258757258775
if( pBlob==0 ){
258758258776
sqlite3_result_error_nomem(pCtx);
258759258777
return;
258760258778
}
258761258779
258762258780
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 2b34b750b5528b6dda195bc1a3895dc3fe46 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.51.0"
471 #define SQLITE_VERSION_NUMBER 3051000
472 #define SQLITE_SOURCE_ID "2025-09-27 11:54:49 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-09-27T11:54:49.147Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -26242,12 +26242,12 @@
26242 ** %j day of year 001-366
26243 ** %J ** julian day number
26244 ** %l hour 1-12 (leading zero converted to space)
26245 ** %m month 01-12
26246 ** %M minute 00-59
26247 ** %p "am" or "pm"
26248 ** %P "AM" or "PM"
26249 ** %R time as HH:MM
26250 ** %s seconds since 1970-01-01
26251 ** %S seconds 00-59
26252 ** %T time as HH:MM:SS
26253 ** %u day of week 1-7 Monday==1, Sunday==7
@@ -171442,21 +171442,28 @@
171442
171443 /* Check to see if pWLoop should be added to the set of
171444 ** mxChoice best-so-far paths.
171445 **
171446 ** First look for an existing path among best-so-far paths
171447 ** that covers the same set of loops and has the same isOrdered
171448 ** setting as the current path candidate.
 
 
 
 
 
 
 
171449 **
171450 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
171451 ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
171452 ** of legal values for isOrdered, -1..64.
171453 */
171454 testcase( nTo==0 );
171455 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
171456 if( pTo->maskLoop==maskNew
171457 && ((pTo->isOrdered^isOrdered)&0x80)==0
171458 ){
171459 testcase( jj==nTo-1 );
171460 break;
171461 }
171462 }
@@ -171600,18 +171607,21 @@
171600 pFrom = aTo;
171601 aTo = aFrom;
171602 aFrom = pFrom;
171603 nFrom = nTo;
171604 }
171605 assert( nFrom==0 || nFrom==1 );
171606
171607 if( nFrom==0 ){
171608 sqlite3ErrorMsg(pParse, "no query solution");
171609 sqlite3StackFreeNN(pParse->db, pSpace);
171610 return SQLITE_ERROR;
171611 }
 
 
 
171612 pFrom = aFrom;
 
171613 assert( pWInfo->nLevel==nLoop );
171614 /* Load the lowest cost path into pWInfo */
171615 for(iLoop=0; iLoop<nLoop; iLoop++){
171616 WhereLevel *pLevel = pWInfo->a + iLoop;
171617 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -206468,14 +206478,10 @@
206468 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
206469
206470 /* #include <string.h> */
206471 /* #include <assert.h> */
206472
206473 #ifndef SQLITE_AMALGAMATION
206474 typedef sqlite3_int64 i64;
206475 #endif
206476
206477 /*
206478 ** Characters that may appear in the second argument to matchinfo().
206479 */
206480 #define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */
206481 #define FTS3_MATCHINFO_NCOL 'c' /* 1 value */
@@ -212236,11 +212242,23 @@
212236 z = sqlite3DbStrNDup(db, (const char*)&pParse->aBlob[i+n], (int)sz);
212237 if( z==0 ) goto returnfromblob_oom;
212238 rc = sqlite3DecOrHexToI64(z, &iRes);
212239 sqlite3DbFree(db, z);
212240 if( rc==0 ){
212241 sqlite3_result_int64(pCtx, bNeg ? -iRes : iRes);
 
 
 
 
 
 
 
 
 
 
 
 
212242 }else if( rc==3 && bNeg ){
212243 sqlite3_result_int64(pCtx, SMALLEST_INT64);
212244 }else if( rc==1 ){
212245 goto returnfromblob_malformed;
212246 }else{
@@ -258706,11 +258724,11 @@
258706 int nArg, /* Number of args */
258707 sqlite3_value **apUnused /* Function arguments */
258708 ){
258709 assert( nArg==0 );
258710 UNUSED_PARAM2(nArg, apUnused);
258711 sqlite3_result_text(pCtx, "fts5: 2025-09-27 11:54:49 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade", -1, SQLITE_TRANSIENT);
258712 }
258713
258714 /*
258715 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258716 **
@@ -258729,13 +258747,13 @@
258729 sqlite3_context *pCtx, /* Function call context */
258730 int nArg, /* Number of args */
258731 sqlite3_value **apArg /* Function arguments */
258732 ){
258733 const char *zLocale = 0;
258734 int nLocale = 0;
258735 const char *zText = 0;
258736 int nText = 0;
258737
258738 assert( nArg==2 );
258739 UNUSED_PARAM(nArg);
258740
258741 zLocale = (const char*)sqlite3_value_text(apArg[0]);
@@ -258748,14 +258766,14 @@
258748 sqlite3_result_text(pCtx, zText, nText, SQLITE_TRANSIENT);
258749 }else{
258750 Fts5Global *p = (Fts5Global*)sqlite3_user_data(pCtx);
258751 u8 *pBlob = 0;
258752 u8 *pCsr = 0;
258753 int nBlob = 0;
258754
258755 nBlob = FTS5_LOCALE_HDR_SIZE + nLocale + 1 + nText;
258756 pBlob = (u8*)sqlite3_malloc(nBlob);
258757 if( pBlob==0 ){
258758 sqlite3_result_error_nomem(pCtx);
258759 return;
258760 }
258761
258762
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 22b2700ac20bb8e5883d484bfd0aee7a0fbc with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.51.0"
471 #define SQLITE_VERSION_NUMBER 3051000
472 #define SQLITE_SOURCE_ID "2025-10-02 11:28:27 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-10-02T11:28:27.740Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -26242,12 +26242,12 @@
26242 ** %j day of year 001-366
26243 ** %J ** julian day number
26244 ** %l hour 1-12 (leading zero converted to space)
26245 ** %m month 01-12
26246 ** %M minute 00-59
26247 ** %p "AM" or "PM"
26248 ** %P "am" or "pm"
26249 ** %R time as HH:MM
26250 ** %s seconds since 1970-01-01
26251 ** %S seconds 00-59
26252 ** %T time as HH:MM:SS
26253 ** %u day of week 1-7 Monday==1, Sunday==7
@@ -171442,21 +171442,28 @@
171442
171443 /* Check to see if pWLoop should be added to the set of
171444 ** mxChoice best-so-far paths.
171445 **
171446 ** First look for an existing path among best-so-far paths
171447 ** that:
171448 ** (1) covers the same set of loops, and
171449 ** (2) has a compatible isOrdered value.
171450 **
171451 ** "Compatible isOrdered value" means either
171452 ** (A) both have isOrdered==-1, or
171453 ** (B) both have isOrder>=0, or
171454 ** (C) ordering does not matter because this is the last round
171455 ** of the solver.
171456 **
171457 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
171458 ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
171459 ** of legal values for isOrdered, -1..64.
171460 */
171461 testcase( nTo==0 );
171462 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
171463 if( pTo->maskLoop==maskNew
171464 && ( ((pTo->isOrdered^isOrdered)&0x80)==0 || iLoop==nLoop-1 )
171465 ){
171466 testcase( jj==nTo-1 );
171467 break;
171468 }
171469 }
@@ -171600,18 +171607,21 @@
171607 pFrom = aTo;
171608 aTo = aFrom;
171609 aFrom = pFrom;
171610 nFrom = nTo;
171611 }
 
171612
171613 if( nFrom==0 ){
171614 sqlite3ErrorMsg(pParse, "no query solution");
171615 sqlite3StackFreeNN(pParse->db, pSpace);
171616 return SQLITE_ERROR;
171617 }
171618
171619 /* Only one path is available, which is the best path */
171620 assert( nFrom==1 );
171621 pFrom = aFrom;
171622
171623 assert( pWInfo->nLevel==nLoop );
171624 /* Load the lowest cost path into pWInfo */
171625 for(iLoop=0; iLoop<nLoop; iLoop++){
171626 WhereLevel *pLevel = pWInfo->a + iLoop;
171627 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -206468,14 +206478,10 @@
206478 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
206479
206480 /* #include <string.h> */
206481 /* #include <assert.h> */
206482
 
 
 
 
206483 /*
206484 ** Characters that may appear in the second argument to matchinfo().
206485 */
206486 #define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */
206487 #define FTS3_MATCHINFO_NCOL 'c' /* 1 value */
@@ -212236,11 +212242,23 @@
212242 z = sqlite3DbStrNDup(db, (const char*)&pParse->aBlob[i+n], (int)sz);
212243 if( z==0 ) goto returnfromblob_oom;
212244 rc = sqlite3DecOrHexToI64(z, &iRes);
212245 sqlite3DbFree(db, z);
212246 if( rc==0 ){
212247 if( iRes<0 ){
212248 /* A hexadecimal literal with 16 significant digits and with the
212249 ** high-order bit set is a negative integer in SQLite (and hence
212250 ** iRes comes back as negative) but should be interpreted as a
212251 ** positive value if it occurs within JSON. The value is too
212252 ** large to appear as an SQLite integer so it must be converted
212253 ** into floating point. */
212254 double r;
212255 r = (double)*(sqlite3_uint64*)&iRes;
212256 sqlite3_result_double(pCtx, bNeg ? -r : r);
212257 }else{
212258 sqlite3_result_int64(pCtx, bNeg ? -iRes : iRes);
212259 }
212260 }else if( rc==3 && bNeg ){
212261 sqlite3_result_int64(pCtx, SMALLEST_INT64);
212262 }else if( rc==1 ){
212263 goto returnfromblob_malformed;
212264 }else{
@@ -258706,11 +258724,11 @@
258724 int nArg, /* Number of args */
258725 sqlite3_value **apUnused /* Function arguments */
258726 ){
258727 assert( nArg==0 );
258728 UNUSED_PARAM2(nArg, apUnused);
258729 sqlite3_result_text(pCtx, "fts5: 2025-10-02 11:28:27 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43", -1, SQLITE_TRANSIENT);
258730 }
258731
258732 /*
258733 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258734 **
@@ -258729,13 +258747,13 @@
258747 sqlite3_context *pCtx, /* Function call context */
258748 int nArg, /* Number of args */
258749 sqlite3_value **apArg /* Function arguments */
258750 ){
258751 const char *zLocale = 0;
258752 i64 nLocale = 0;
258753 const char *zText = 0;
258754 i64 nText = 0;
258755
258756 assert( nArg==2 );
258757 UNUSED_PARAM(nArg);
258758
258759 zLocale = (const char*)sqlite3_value_text(apArg[0]);
@@ -258748,14 +258766,14 @@
258766 sqlite3_result_text(pCtx, zText, nText, SQLITE_TRANSIENT);
258767 }else{
258768 Fts5Global *p = (Fts5Global*)sqlite3_user_data(pCtx);
258769 u8 *pBlob = 0;
258770 u8 *pCsr = 0;
258771 i64 nBlob = 0;
258772
258773 nBlob = FTS5_LOCALE_HDR_SIZE + nLocale + 1 + nText;
258774 pBlob = (u8*)sqlite3_malloc64(nBlob);
258775 if( pBlob==0 ){
258776 sqlite3_result_error_nomem(pCtx);
258777 return;
258778 }
258779
258780
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.51.0"
150150
#define SQLITE_VERSION_NUMBER 3051000
151
-#define SQLITE_SOURCE_ID "2025-09-27 11:54:49 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade"
151
+#define SQLITE_SOURCE_ID "2025-10-02 11:28:27 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2025-09-27T11:54:49.147Z"
154
+#define SQLITE_SCM_DATETIME "2025-10-02T11:28:27.740Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
160160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-09-27 11:54:49 2b34b750b5528b6dda195bc1a3895dc3fe46e70cbf992a78111316e2726c1ade"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-09-27T11:54:49.147Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-10-02 11:28:27 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-10-02T11:28:27.740Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160

Keyboard Shortcuts

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