Fossil SCM

Update the built-in SQLite to the first 3.22.0 beta.

drh 2018-01-15 22:07 trunk
Commit 1a95af721e467a6e3321c1557c4f0cdfa353ef4ac8e310ff393c58aff8ef0849
3 files changed +286 -155 +153 -42 +25 -1
+286 -155
--- src/shell.c
+++ src/shell.c
@@ -4013,11 +4013,11 @@
40134013
"mtime," /* 2: Last modification time (secs since 1970)*/
40144014
"sz," /* 3: Size of object */
40154015
"rawdata," /* 4: Raw data */
40164016
"data," /* 5: Uncompressed data */
40174017
"method," /* 6: Compression method (integer) */
4018
- "file HIDDEN" /* 7: Name of zip file */
4018
+ "z HIDDEN" /* 7: Name of zip file */
40194019
") WITHOUT ROWID;";
40204020
40214021
#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
40224022
#define ZIPFILE_BUFFER_SIZE (64*1024)
40234023
@@ -4184,10 +4184,11 @@
41844184
** Cursor type for recursively iterating through a directory structure.
41854185
*/
41864186
typedef struct ZipfileCsr ZipfileCsr;
41874187
struct ZipfileCsr {
41884188
sqlite3_vtab_cursor base; /* Base class - must be first */
4189
+ i64 iId; /* Cursor ID */
41894190
int bEof; /* True when at EOF */
41904191
41914192
/* Used outside of write transactions */
41924193
FILE *pFile; /* Zip file */
41934194
i64 iNextOff; /* Offset of next record in central directory */
@@ -4213,12 +4214,14 @@
42134214
struct ZipfileTab {
42144215
sqlite3_vtab base; /* Base class - must be first */
42154216
char *zFile; /* Zip file this table accesses (may be NULL) */
42164217
u8 *aBuffer; /* Temporary buffer used for various tasks */
42174218
4218
- /* The following are used by write transactions only */
42194219
ZipfileCsr *pCsrList; /* List of cursors */
4220
+ i64 iNextCsrid;
4221
+
4222
+ /* The following are used by write transactions only */
42204223
ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
42214224
ZipfileEntry *pLastEntry; /* Last element in pFirstEntry list */
42224225
FILE *pWriteFd; /* File handle open on zip archive */
42234226
i64 szCurrent; /* Current size of zip archive */
42244227
i64 szOrig; /* Size of archive at start of transaction */
@@ -4293,33 +4296,29 @@
42934296
42944297
/*
42954298
** Constructor for a new ZipfileCsr object.
42964299
*/
42974300
static int zipfileOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCsr){
4301
+ ZipfileTab *pTab = (ZipfileTab*)p;
42984302
ZipfileCsr *pCsr;
42994303
pCsr = sqlite3_malloc(sizeof(*pCsr));
43004304
*ppCsr = (sqlite3_vtab_cursor*)pCsr;
43014305
if( pCsr==0 ){
43024306
return SQLITE_NOMEM;
43034307
}
43044308
memset(pCsr, 0, sizeof(*pCsr));
4309
+ pCsr->iId = ++pTab->iNextCsrid;
4310
+ pCsr->pCsrNext = pTab->pCsrList;
4311
+ pTab->pCsrList = pCsr;
43054312
return SQLITE_OK;
43064313
}
43074314
43084315
/*
43094316
** Reset a cursor back to the state it was in when first returned
43104317
** by zipfileOpen().
43114318
*/
43124319
static void zipfileResetCursor(ZipfileCsr *pCsr){
4313
- ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab);
4314
- ZipfileCsr **pp;
4315
-
4316
- /* Remove this cursor from the ZipfileTab.pCsrList list. */
4317
- for(pp=&pTab->pCsrList; *pp; pp=&((*pp)->pCsrNext)){
4318
- if( *pp==pCsr ) *pp = pCsr->pCsrNext;
4319
- }
4320
-
43214320
sqlite3_free(pCsr->cds.zFile);
43224321
pCsr->cds.zFile = 0;
43234322
pCsr->bEof = 0;
43244323
if( pCsr->pFile ){
43254324
fclose(pCsr->pFile);
@@ -4330,11 +4329,22 @@
43304329
/*
43314330
** Destructor for an ZipfileCsr.
43324331
*/
43334332
static int zipfileClose(sqlite3_vtab_cursor *cur){
43344333
ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4334
+ ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab);
4335
+ ZipfileCsr **pp;
43354336
zipfileResetCursor(pCsr);
4337
+
4338
+ /* Remove this cursor from the ZipfileTab.pCsrList list. */
4339
+ for(pp=&pTab->pCsrList; *pp; pp=&((*pp)->pCsrNext)){
4340
+ if( *pp==pCsr ){
4341
+ *pp = pCsr->pCsrNext;
4342
+ break;
4343
+ }
4344
+ }
4345
+
43364346
sqlite3_free(pCsr);
43374347
return SQLITE_OK;
43384348
}
43394349
43404350
/*
@@ -4413,14 +4423,51 @@
44134423
}
44144424
44154425
/*
44164426
** Magic numbers used to read CDS records.
44174427
*/
4418
-#define ZIPFILE_CDS_FIXED_SZ 46
4419
-#define ZIPFILE_CDS_NFILE_OFF 28
4428
+#define ZIPFILE_CDS_FIXED_SZ 46
4429
+#define ZIPFILE_CDS_NFILE_OFF 28
44204430
4421
-static int zipfileReadCDS(ZipfileCsr *pCsr){
4431
+/*
4432
+** Decode the CDS record in buffer aBuf into (*pCDS). Return SQLITE_ERROR
4433
+** if the record is not well-formed, or SQLITE_OK otherwise.
4434
+*/
4435
+static int zipfileReadCDS(u8 *aBuf, ZipfileCDS *pCDS){
4436
+ u8 *aRead = aBuf;
4437
+ u32 sig = zipfileRead32(aRead);
4438
+ int rc = SQLITE_OK;
4439
+ if( sig!=ZIPFILE_SIGNATURE_CDS ){
4440
+ rc = SQLITE_ERROR;
4441
+ }else{
4442
+ pCDS->iVersionMadeBy = zipfileRead16(aRead);
4443
+ pCDS->iVersionExtract = zipfileRead16(aRead);
4444
+ pCDS->flags = zipfileRead16(aRead);
4445
+ pCDS->iCompression = zipfileRead16(aRead);
4446
+ pCDS->mTime = zipfileRead16(aRead);
4447
+ pCDS->mDate = zipfileRead16(aRead);
4448
+ pCDS->crc32 = zipfileRead32(aRead);
4449
+ pCDS->szCompressed = zipfileRead32(aRead);
4450
+ pCDS->szUncompressed = zipfileRead32(aRead);
4451
+ assert( aRead==&aBuf[ZIPFILE_CDS_NFILE_OFF] );
4452
+ pCDS->nFile = zipfileRead16(aRead);
4453
+ pCDS->nExtra = zipfileRead16(aRead);
4454
+ pCDS->nComment = zipfileRead16(aRead);
4455
+ pCDS->iDiskStart = zipfileRead16(aRead);
4456
+ pCDS->iInternalAttr = zipfileRead16(aRead);
4457
+ pCDS->iExternalAttr = zipfileRead32(aRead);
4458
+ pCDS->iOffset = zipfileRead32(aRead);
4459
+ assert( aRead==&aBuf[ZIPFILE_CDS_FIXED_SZ] );
4460
+ }
4461
+
4462
+ return rc;
4463
+}
4464
+
4465
+/*
4466
+** Read the CDS record for the current entry from disk into pCsr->cds.
4467
+*/
4468
+static int zipfileCsrReadCDS(ZipfileCsr *pCsr){
44224469
char **pzErr = &pCsr->base.pVtab->zErrMsg;
44234470
u8 *aRead;
44244471
int rc = SQLITE_OK;
44254472
44264473
sqlite3_free(pCsr->cds.zFile);
@@ -4434,45 +4481,23 @@
44344481
}else{
44354482
aRead = pCsr->pCurrent->aCdsEntry;
44364483
}
44374484
44384485
if( rc==SQLITE_OK ){
4439
- u32 sig = zipfileRead32(aRead);
4440
- if( sig!=ZIPFILE_SIGNATURE_CDS ){
4486
+ rc = zipfileReadCDS(aRead, &pCsr->cds);
4487
+ if( rc!=SQLITE_OK ){
44414488
assert( pCsr->pCurrent==0 );
44424489
zipfileSetErrmsg(pCsr,"failed to read CDS at offset %lld",pCsr->iNextOff);
4443
- rc = SQLITE_ERROR;
44444490
}else{
44454491
int nRead;
4446
- pCsr->cds.iVersionMadeBy = zipfileRead16(aRead);
4447
- pCsr->cds.iVersionExtract = zipfileRead16(aRead);
4448
- pCsr->cds.flags = zipfileRead16(aRead);
4449
- pCsr->cds.iCompression = zipfileRead16(aRead);
4450
- pCsr->cds.mTime = zipfileRead16(aRead);
4451
- pCsr->cds.mDate = zipfileRead16(aRead);
4452
- pCsr->cds.crc32 = zipfileRead32(aRead);
4453
- pCsr->cds.szCompressed = zipfileRead32(aRead);
4454
- pCsr->cds.szUncompressed = zipfileRead32(aRead);
4455
- assert( pCsr->pCurrent
4456
- || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_NFILE_OFF
4457
- );
4458
- pCsr->cds.nFile = zipfileRead16(aRead);
4459
- pCsr->cds.nExtra = zipfileRead16(aRead);
4460
- pCsr->cds.nComment = zipfileRead16(aRead);
4461
- pCsr->cds.iDiskStart = zipfileRead16(aRead);
4462
- pCsr->cds.iInternalAttr = zipfileRead16(aRead);
4463
- pCsr->cds.iExternalAttr = zipfileRead32(aRead);
4464
- pCsr->cds.iOffset = zipfileRead32(aRead);
4465
- assert( pCsr->pCurrent
4466
- || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_FIXED_SZ
4467
- );
4468
-
44694492
if( pCsr->pCurrent==0 ){
44704493
nRead = pCsr->cds.nFile + pCsr->cds.nExtra;
44714494
aRead = zipfileCsrBuffer(pCsr);
44724495
pCsr->iNextOff += ZIPFILE_CDS_FIXED_SZ;
44734496
rc = zipfileReadData(pCsr->pFile, aRead, nRead, pCsr->iNextOff, pzErr);
4497
+ }else{
4498
+ aRead = &aRead[ZIPFILE_CDS_FIXED_SZ];
44744499
}
44754500
44764501
if( rc==SQLITE_OK ){
44774502
pCsr->cds.zFile = sqlite3_mprintf("%.*s", (int)pCsr->cds.nFile, aRead);
44784503
pCsr->iNextOff += pCsr->cds.nFile;
@@ -4519,41 +4544,51 @@
45194544
static FILE *zipfileGetFd(ZipfileCsr *pCsr){
45204545
if( pCsr->pFile ) return pCsr->pFile;
45214546
return ((ZipfileTab*)(pCsr->base.pVtab))->pWriteFd;
45224547
}
45234548
4524
-static int zipfileReadLFH(ZipfileCsr *pCsr){
4525
- FILE *pFile = zipfileGetFd(pCsr);
4526
- char **pzErr = &pCsr->base.pVtab->zErrMsg;
4549
+static int zipfileReadLFH(
4550
+ FILE *pFd,
4551
+ i64 iOffset,
4552
+ u8 *aTmp,
4553
+ ZipfileLFH *pLFH,
4554
+ char **pzErr
4555
+){
4556
+ u8 *aRead = aTmp;
45274557
static const int szFix = ZIPFILE_LFH_FIXED_SZ;
4528
- u8 *aRead = zipfileCsrBuffer(pCsr);
45294558
int rc;
45304559
4531
- rc = zipfileReadData(pFile, aRead, szFix, pCsr->cds.iOffset, pzErr);
4560
+ rc = zipfileReadData(pFd, aRead, szFix, iOffset, pzErr);
45324561
if( rc==SQLITE_OK ){
45334562
u32 sig = zipfileRead32(aRead);
45344563
if( sig!=ZIPFILE_SIGNATURE_LFH ){
4535
- zipfileSetErrmsg(pCsr, "failed to read LFH at offset %d",
4536
- (int)pCsr->cds.iOffset
4537
- );
4564
+ *pzErr = sqlite3_mprintf("failed to read LFH at offset %d", (int)iOffset);
45384565
rc = SQLITE_ERROR;
45394566
}else{
4540
- pCsr->lfh.iVersionExtract = zipfileRead16(aRead);
4541
- pCsr->lfh.flags = zipfileRead16(aRead);
4542
- pCsr->lfh.iCompression = zipfileRead16(aRead);
4543
- pCsr->lfh.mTime = zipfileRead16(aRead);
4544
- pCsr->lfh.mDate = zipfileRead16(aRead);
4545
- pCsr->lfh.crc32 = zipfileRead32(aRead);
4546
- pCsr->lfh.szCompressed = zipfileRead32(aRead);
4547
- pCsr->lfh.szUncompressed = zipfileRead32(aRead);
4548
- pCsr->lfh.nFile = zipfileRead16(aRead);
4549
- pCsr->lfh.nExtra = zipfileRead16(aRead);
4550
- assert( aRead==zipfileCsrBuffer(pCsr)+szFix );
4551
- pCsr->iDataOff = pCsr->cds.iOffset+szFix+pCsr->lfh.nFile+pCsr->lfh.nExtra;
4552
- }
4553
- }
4554
-
4567
+ pLFH->iVersionExtract = zipfileRead16(aRead);
4568
+ pLFH->flags = zipfileRead16(aRead);
4569
+ pLFH->iCompression = zipfileRead16(aRead);
4570
+ pLFH->mTime = zipfileRead16(aRead);
4571
+ pLFH->mDate = zipfileRead16(aRead);
4572
+ pLFH->crc32 = zipfileRead32(aRead);
4573
+ pLFH->szCompressed = zipfileRead32(aRead);
4574
+ pLFH->szUncompressed = zipfileRead32(aRead);
4575
+ pLFH->nFile = zipfileRead16(aRead);
4576
+ pLFH->nExtra = zipfileRead16(aRead);
4577
+ assert( aRead==&aTmp[szFix] );
4578
+ }
4579
+ }
4580
+ return rc;
4581
+}
4582
+
4583
+static int zipfileCsrReadLFH(ZipfileCsr *pCsr){
4584
+ FILE *pFile = zipfileGetFd(pCsr);
4585
+ char **pzErr = &pCsr->base.pVtab->zErrMsg;
4586
+ u8 *aRead = zipfileCsrBuffer(pCsr);
4587
+ int rc = zipfileReadLFH(pFile, pCsr->cds.iOffset, aRead, &pCsr->lfh, pzErr);
4588
+ pCsr->iDataOff = pCsr->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
4589
+ pCsr->iDataOff += pCsr->lfh.nFile+pCsr->lfh.nExtra;
45554590
return rc;
45564591
}
45574592
45584593
45594594
/*
@@ -4578,13 +4613,13 @@
45784613
pCsr->bEof = 1;
45794614
}
45804615
}
45814616
45824617
if( pCsr->bEof==0 ){
4583
- rc = zipfileReadCDS(pCsr);
4618
+ rc = zipfileCsrReadCDS(pCsr);
45844619
if( rc==SQLITE_OK ){
4585
- rc = zipfileReadLFH(pCsr);
4620
+ rc = zipfileCsrReadLFH(pCsr);
45864621
}
45874622
}
45884623
45894624
return rc;
45904625
}
@@ -4737,18 +4772,22 @@
47374772
sqlite3_result_int64(ctx, zipfileMtime(pCsr));
47384773
}
47394774
break;
47404775
}
47414776
case 3: { /* sz */
4742
- sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4777
+ if( sqlite3_vtab_nochange(ctx)==0 ){
4778
+ sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4779
+ }
47434780
break;
47444781
}
47454782
case 4: /* rawdata */
4783
+ if( sqlite3_vtab_nochange(ctx) ) break;
47464784
case 5: { /* data */
47474785
if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){
47484786
int sz = pCsr->cds.szCompressed;
4749
- if( sz>0 ){
4787
+ int szFinal = pCsr->cds.szUncompressed;
4788
+ if( szFinal>0 ){
47504789
u8 *aBuf = sqlite3_malloc(sz);
47514790
if( aBuf==0 ){
47524791
rc = SQLITE_NOMEM;
47534792
}else{
47544793
FILE *pFile = zipfileGetFd(pCsr);
@@ -4756,26 +4795,37 @@
47564795
&pCsr->base.pVtab->zErrMsg
47574796
);
47584797
}
47594798
if( rc==SQLITE_OK ){
47604799
if( i==5 && pCsr->cds.iCompression ){
4761
- zipfileInflate(ctx, aBuf, sz, pCsr->cds.szUncompressed);
4800
+ zipfileInflate(ctx, aBuf, sz, szFinal);
47624801
}else{
47634802
sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
47644803
}
47654804
sqlite3_free(aBuf);
47664805
}
4806
+ }else{
4807
+ /* Figure out if this is a directory or a zero-sized file. Consider
4808
+ ** it to be a directory either if the mode suggests so, or if
4809
+ ** the final character in the name is '/'. */
4810
+ u32 mode = pCsr->cds.iExternalAttr >> 16;
4811
+ if( !(mode & S_IFDIR) && pCsr->cds.zFile[pCsr->cds.nFile-1]!='/' ){
4812
+ sqlite3_result_blob(ctx, "", 0, SQLITE_STATIC);
4813
+ }
47674814
}
47684815
}
47694816
break;
47704817
}
47714818
case 6: /* method */
47724819
sqlite3_result_int(ctx, pCsr->cds.iCompression);
47734820
break;
4821
+ case 7: /* z */
4822
+ sqlite3_result_int64(ctx, pCsr->iId);
4823
+ break;
47744824
}
47754825
4776
- return SQLITE_OK;
4826
+ return rc;
47774827
}
47784828
47794829
/*
47804830
** Return the rowid for the current row.
47814831
*/
@@ -4807,11 +4857,12 @@
48074857
int rc;
48084858
48094859
fseek(pFile, 0, SEEK_END);
48104860
szFile = (i64)ftell(pFile);
48114861
if( szFile==0 ){
4812
- return SQLITE_EMPTY;
4862
+ memset(pEOCD, 0, sizeof(ZipfileEOCD));
4863
+ return SQLITE_OK;
48134864
}
48144865
nRead = (int)(MIN(szFile, ZIPFILE_BUFFER_SIZE));
48154866
iOff = szFile - nRead;
48164867
48174868
rc = zipfileReadData(pFile, aRead, nRead, iOff, &pTab->base.zErrMsg);
@@ -4885,15 +4936,16 @@
48854936
zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile);
48864937
rc = SQLITE_ERROR;
48874938
}else{
48884939
rc = zipfileReadEOCD(pTab, pCsr->pFile, &pCsr->eocd);
48894940
if( rc==SQLITE_OK ){
4890
- pCsr->iNextOff = pCsr->eocd.iOffset;
4891
- rc = zipfileNext(cur);
4892
- }else if( rc==SQLITE_EMPTY ){
4893
- rc = SQLITE_OK;
4894
- pCsr->bEof = 1;
4941
+ if( pCsr->eocd.nEntry==0 ){
4942
+ pCsr->bEof = 1;
4943
+ }else{
4944
+ pCsr->iNextOff = pCsr->eocd.iOffset;
4945
+ rc = zipfileNext(cur);
4946
+ }
48954947
}
48964948
}
48974949
}else{
48984950
ZipfileEntry e;
48994951
memset(&e, 0, sizeof(e));
@@ -4938,28 +4990,39 @@
49384990
49394991
/*
49404992
** Add object pNew to the end of the linked list that begins at
49414993
** ZipfileTab.pFirstEntry and ends with pLastEntry.
49424994
*/
4943
-static void zipfileAddEntry(ZipfileTab *pTab, ZipfileEntry *pNew){
4995
+static void zipfileAddEntry(
4996
+ ZipfileTab *pTab,
4997
+ ZipfileEntry *pBefore,
4998
+ ZipfileEntry *pNew
4999
+){
49445000
assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
49455001
assert( pNew->pNext==0 );
4946
- if( pTab->pFirstEntry==0 ){
4947
- pTab->pFirstEntry = pTab->pLastEntry = pNew;
5002
+ if( pBefore==0 ){
5003
+ if( pTab->pFirstEntry==0 ){
5004
+ pTab->pFirstEntry = pTab->pLastEntry = pNew;
5005
+ }else{
5006
+ assert( pTab->pLastEntry->pNext==0 );
5007
+ pTab->pLastEntry->pNext = pNew;
5008
+ pTab->pLastEntry = pNew;
5009
+ }
49485010
}else{
4949
- assert( pTab->pLastEntry->pNext==0 );
4950
- pTab->pLastEntry->pNext = pNew;
4951
- pTab->pLastEntry = pNew;
5011
+ ZipfileEntry **pp;
5012
+ for(pp=&pTab->pFirstEntry; *pp!=pBefore; pp=&((*pp)->pNext));
5013
+ pNew->pNext = pBefore;
5014
+ *pp = pNew;
49525015
}
49535016
}
49545017
49555018
static int zipfileLoadDirectory(ZipfileTab *pTab){
49565019
ZipfileEOCD eocd;
49575020
int rc;
49585021
49595022
rc = zipfileReadEOCD(pTab, pTab->pWriteFd, &eocd);
4960
- if( rc==SQLITE_OK ){
5023
+ if( rc==SQLITE_OK && eocd.nEntry>0 ){
49615024
int i;
49625025
int iOff = 0;
49635026
u8 *aBuf = sqlite3_malloc(eocd.nSize);
49645027
if( aBuf==0 ){
49655028
rc = SQLITE_NOMEM;
@@ -4993,19 +5056,17 @@
49935056
memcpy(pNew->zPath, &aRec[ZIPFILE_CDS_FIXED_SZ], nFile);
49945057
pNew->zPath[nFile] = '\0';
49955058
pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
49965059
pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
49975060
memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
4998
- zipfileAddEntry(pTab, pNew);
5061
+ zipfileAddEntry(pTab, 0, pNew);
49995062
}
50005063
50015064
iOff += ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
50025065
}
50035066
50045067
sqlite3_free(aBuf);
5005
- }else if( rc==SQLITE_EMPTY ){
5006
- rc = SQLITE_OK;
50075068
}
50085069
50095070
return rc;
50105071
}
50115072
@@ -5117,11 +5178,11 @@
51175178
){
51185179
const char *z = (const char*)sqlite3_value_text(pVal);
51195180
u32 mode = 0;
51205181
if( z==0 ){
51215182
mode = defaultMode;
5122
- }else if( z[0]>=0 && z[0]<=9 ){
5183
+ }else if( z[0]>='0' && z[0]<='9' ){
51235184
mode = (unsigned int)sqlite3_value_int(pVal);
51245185
}else{
51255186
const char zTemplate[11] = "-rwxrwxrwx";
51265187
int i;
51275188
if( strlen(z)!=10 ) goto parse_error;
@@ -5180,83 +5241,68 @@
51805241
int nData = 0; /* Size of pData buffer in bytes */
51815242
int iMethod = 0; /* Compression method for new entry */
51825243
u8 *pFree = 0; /* Free this */
51835244
char *zFree = 0; /* Also free this */
51845245
ZipfileCDS cds; /* New Central Directory Structure entry */
5185
-
5246
+ ZipfileEntry *pOld = 0;
51865247
int bIsDir = 0;
5187
-
5188
- int mNull;
5248
+ u32 iCrc32 = 0;
51895249
51905250
assert( pTab->zFile );
51915251
assert( pTab->pWriteFd );
51925252
51935253
if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
5194
- if( nVal>1 ){
5195
- return SQLITE_CONSTRAINT;
5196
- }else{
5197
- const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
5198
- int nDelete = strlen(zDelete);
5199
- ZipfileEntry *p;
5200
- for(p=pTab->pFirstEntry; p; p=p->pNext){
5201
- if( zipfileComparePath(p->zPath, zDelete, nDelete)==0 ){
5202
- p->bDeleted = 1;
5203
- break;
5204
- }
5205
- }
5206
- return SQLITE_OK;
5207
- }
5208
- }
5209
-
5210
- mNull = (sqlite3_value_type(apVal[5])==SQLITE_NULL ? 0x0 : 0x8) /* sz */
5211
- + (sqlite3_value_type(apVal[6])==SQLITE_NULL ? 0x0 : 0x4) /* rawdata */
5212
- + (sqlite3_value_type(apVal[7])==SQLITE_NULL ? 0x0 : 0x2) /* data */
5213
- + (sqlite3_value_type(apVal[8])==SQLITE_NULL ? 0x0 : 0x1); /* method */
5214
- if( mNull==0x00 ){
5215
- /* All four are NULL - this must be a directory */
5216
- bIsDir = 1;
5217
- }
5218
- else if( mNull==0x2 || mNull==0x3 ){
5219
- /* Value specified for "data", and possibly "method". This must be
5220
- ** a regular file or a symlink. */
5221
- const u8 *aIn = sqlite3_value_blob(apVal[7]);
5222
- int nIn = sqlite3_value_bytes(apVal[7]);
5223
- int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
5224
-
5225
- iMethod = sqlite3_value_int(apVal[8]);
5226
- sz = nIn;
5227
- if( iMethod!=0 && iMethod!=8 ){
5228
- rc = SQLITE_CONSTRAINT;
5229
- }else if( bAuto || iMethod ){
5230
- rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nData);
5231
- if( rc==SQLITE_OK ){
5232
- if( iMethod || nData<nIn ){
5233
- iMethod = 8;
5234
- pData = pFree;
5235
- }else{
5236
- pData = aIn;
5237
- nData = nIn;
5238
- }
5239
- }
5240
- }
5241
- }
5242
- else if( mNull==0x0D ){
5243
- /* Values specified for "sz", "rawdata" and "method". In other words,
5244
- ** pre-compressed data is being inserted. */
5245
- pData = sqlite3_value_blob(apVal[6]);
5246
- nData = sqlite3_value_bytes(apVal[6]);
5247
- sz = sqlite3_value_int(apVal[5]);
5248
- iMethod = sqlite3_value_int(apVal[8]);
5249
- if( iMethod<0 || iMethod>65535 ){
5250
- pTab->base.zErrMsg = sqlite3_mprintf(
5251
- "zipfile: invalid compression method: %d", iMethod
5252
- );
5253
- rc = SQLITE_ERROR;
5254
- }
5255
- }
5256
- else{
5257
- rc = SQLITE_CONSTRAINT;
5254
+ const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
5255
+ int nDelete = (int)strlen(zDelete);
5256
+ for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
5257
+ if( pOld->bDeleted ) continue;
5258
+ if( zipfileComparePath(pOld->zPath, zDelete, nDelete)==0 ){
5259
+ pOld->bDeleted = 1;
5260
+ break;
5261
+ }
5262
+ assert( pOld->pNext );
5263
+ }
5264
+ if( nVal==1 ) return SQLITE_OK;
5265
+ }
5266
+
5267
+ /* Check that "sz" and "rawdata" are both NULL: */
5268
+ if( sqlite3_value_type(apVal[5])!=SQLITE_NULL
5269
+ || sqlite3_value_type(apVal[6])!=SQLITE_NULL
5270
+ ){
5271
+ rc = SQLITE_CONSTRAINT;
5272
+ }
5273
+
5274
+ if( rc==SQLITE_OK ){
5275
+ if( sqlite3_value_type(apVal[7])==SQLITE_NULL ){
5276
+ /* data=NULL. A directory */
5277
+ bIsDir = 1;
5278
+ }else{
5279
+ /* Value specified for "data", and possibly "method". This must be
5280
+ ** a regular file or a symlink. */
5281
+ const u8 *aIn = sqlite3_value_blob(apVal[7]);
5282
+ int nIn = sqlite3_value_bytes(apVal[7]);
5283
+ int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
5284
+
5285
+ iMethod = sqlite3_value_int(apVal[8]);
5286
+ sz = nIn;
5287
+ pData = aIn;
5288
+ nData = nIn;
5289
+ if( iMethod!=0 && iMethod!=8 ){
5290
+ rc = SQLITE_CONSTRAINT;
5291
+ }else if( bAuto || iMethod ){
5292
+ int nCmp;
5293
+ rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nCmp);
5294
+ if( rc==SQLITE_OK ){
5295
+ if( iMethod || nCmp<nIn ){
5296
+ iMethod = 8;
5297
+ pData = pFree;
5298
+ nData = nCmp;
5299
+ }
5300
+ }
5301
+ iCrc32 = crc32(0, aIn, nIn);
5302
+ }
5303
+ }
52585304
}
52595305
52605306
if( rc==SQLITE_OK ){
52615307
rc = zipfileGetMode(pTab, apVal[3],
52625308
(bIsDir ? (S_IFDIR + 0755) : (S_IFREG + 0644)), &mode
@@ -5293,10 +5339,11 @@
52935339
52945340
/* Check that we're not inserting a duplicate entry */
52955341
if( rc==SQLITE_OK ){
52965342
ZipfileEntry *p;
52975343
for(p=pTab->pFirstEntry; p; p=p->pNext){
5344
+ if( p->bDeleted ) continue;
52985345
if( zipfileComparePath(p->zPath, zPath, nPath)==0 ){
52995346
rc = SQLITE_CONSTRAINT;
53005347
break;
53015348
}
53025349
}
@@ -5308,28 +5355,31 @@
53085355
cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
53095356
cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;
53105357
cds.flags = ZIPFILE_NEWENTRY_FLAGS;
53115358
cds.iCompression = (u16)iMethod;
53125359
zipfileMtimeToDos(&cds, (u32)mTime);
5313
- cds.crc32 = crc32(0, pData, nData);
5360
+ cds.crc32 = iCrc32;
53145361
cds.szCompressed = nData;
53155362
cds.szUncompressed = (u32)sz;
53165363
cds.iExternalAttr = (mode<<16);
53175364
cds.iOffset = (u32)pTab->szCurrent;
53185365
pNew = zipfileNewEntry(&cds, zPath, nPath, (u32)mTime);
53195366
if( pNew==0 ){
53205367
rc = SQLITE_NOMEM;
53215368
}else{
5322
- zipfileAddEntry(pTab, pNew);
5369
+ zipfileAddEntry(pTab, pOld, pNew);
53235370
}
53245371
}
53255372
53265373
/* Append the new header+file to the archive */
53275374
if( rc==SQLITE_OK ){
53285375
rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
53295376
}
53305377
5378
+ if( rc!=SQLITE_OK && pOld ){
5379
+ pOld->bDeleted = 0;
5380
+ }
53315381
sqlite3_free(pFree);
53325382
sqlite3_free(zFree);
53335383
return rc;
53345384
}
53355385
@@ -5434,10 +5484,88 @@
54345484
}
54355485
54365486
static int zipfileRollback(sqlite3_vtab *pVtab){
54375487
return zipfileCommit(pVtab);
54385488
}
5489
+
5490
+static ZipfileCsr *zipfileFindCursor(ZipfileTab *pTab, i64 iId){
5491
+ ZipfileCsr *pCsr;
5492
+ for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){
5493
+ if( iId==pCsr->iId ) break;
5494
+ }
5495
+ return pCsr;
5496
+}
5497
+
5498
+static void zipfileFunctionCds(
5499
+ sqlite3_context *context,
5500
+ int argc,
5501
+ sqlite3_value **argv
5502
+){
5503
+ ZipfileCsr *pCsr;
5504
+ ZipfileTab *pTab = (ZipfileTab*)sqlite3_user_data(context);
5505
+ assert( argc>0 );
5506
+
5507
+ pCsr = zipfileFindCursor(pTab, sqlite3_value_int64(argv[0]));
5508
+ if( pCsr ){
5509
+ ZipfileCDS *p = &pCsr->cds;
5510
+ char *zRes = sqlite3_mprintf("{"
5511
+ "\"version-made-by\" : %u, "
5512
+ "\"version-to-extract\" : %u, "
5513
+ "\"flags\" : %u, "
5514
+ "\"compression\" : %u, "
5515
+ "\"time\" : %u, "
5516
+ "\"date\" : %u, "
5517
+ "\"crc32\" : %u, "
5518
+ "\"compressed-size\" : %u, "
5519
+ "\"uncompressed-size\" : %u, "
5520
+ "\"file-name-length\" : %u, "
5521
+ "\"extra-field-length\" : %u, "
5522
+ "\"file-comment-length\" : %u, "
5523
+ "\"disk-number-start\" : %u, "
5524
+ "\"internal-attr\" : %u, "
5525
+ "\"external-attr\" : %u, "
5526
+ "\"offset\" : %u }",
5527
+ (u32)p->iVersionMadeBy, (u32)p->iVersionExtract,
5528
+ (u32)p->flags, (u32)p->iCompression,
5529
+ (u32)p->mTime, (u32)p->mDate,
5530
+ (u32)p->crc32, (u32)p->szCompressed,
5531
+ (u32)p->szUncompressed, (u32)p->nFile,
5532
+ (u32)p->nExtra, (u32)p->nComment,
5533
+ (u32)p->iDiskStart, (u32)p->iInternalAttr,
5534
+ (u32)p->iExternalAttr, (u32)p->iOffset
5535
+ );
5536
+
5537
+ if( zRes==0 ){
5538
+ sqlite3_result_error_nomem(context);
5539
+ }else{
5540
+ sqlite3_result_text(context, zRes, -1, SQLITE_TRANSIENT);
5541
+ sqlite3_free(zRes);
5542
+ }
5543
+ }
5544
+}
5545
+
5546
+
5547
+/*
5548
+** xFindFunction method.
5549
+*/
5550
+static int zipfileFindFunction(
5551
+ sqlite3_vtab *pVtab, /* Virtual table handle */
5552
+ int nArg, /* Number of SQL function arguments */
5553
+ const char *zName, /* Name of SQL function */
5554
+ void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
5555
+ void **ppArg /* OUT: User data for *pxFunc */
5556
+){
5557
+ if( nArg>0 ){
5558
+ if( sqlite3_stricmp("zipfile_cds", zName)==0 ){
5559
+ *pxFunc = zipfileFunctionCds;
5560
+ *ppArg = (void*)pVtab;
5561
+ return 1;
5562
+ }
5563
+ }
5564
+
5565
+ return 0;
5566
+}
54395567
54405568
/*
54415569
** Register the "zipfile" virtual table.
54425570
*/
54435571
static int zipfileRegister(sqlite3 *db){
@@ -5458,15 +5586,18 @@
54585586
zipfileUpdate, /* xUpdate */
54595587
zipfileBegin, /* xBegin */
54605588
0, /* xSync */
54615589
zipfileCommit, /* xCommit */
54625590
zipfileRollback, /* xRollback */
5463
- 0, /* xFindMethod */
5591
+ zipfileFindFunction, /* xFindMethod */
54645592
0, /* xRename */
54655593
};
54665594
54675595
int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
5596
+ if( rc==SQLITE_OK ){
5597
+ rc = sqlite3_overload_function(db, "zipfile_cds", -1);
5598
+ }
54685599
return rc;
54695600
}
54705601
#else /* SQLITE_OMIT_VIRTUALTABLE */
54715602
# define zipfileRegister(x) SQLITE_OK
54725603
#endif
54735604
--- src/shell.c
+++ src/shell.c
@@ -4013,11 +4013,11 @@
4013 "mtime," /* 2: Last modification time (secs since 1970)*/
4014 "sz," /* 3: Size of object */
4015 "rawdata," /* 4: Raw data */
4016 "data," /* 5: Uncompressed data */
4017 "method," /* 6: Compression method (integer) */
4018 "file HIDDEN" /* 7: Name of zip file */
4019 ") WITHOUT ROWID;";
4020
4021 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
4022 #define ZIPFILE_BUFFER_SIZE (64*1024)
4023
@@ -4184,10 +4184,11 @@
4184 ** Cursor type for recursively iterating through a directory structure.
4185 */
4186 typedef struct ZipfileCsr ZipfileCsr;
4187 struct ZipfileCsr {
4188 sqlite3_vtab_cursor base; /* Base class - must be first */
 
4189 int bEof; /* True when at EOF */
4190
4191 /* Used outside of write transactions */
4192 FILE *pFile; /* Zip file */
4193 i64 iNextOff; /* Offset of next record in central directory */
@@ -4213,12 +4214,14 @@
4213 struct ZipfileTab {
4214 sqlite3_vtab base; /* Base class - must be first */
4215 char *zFile; /* Zip file this table accesses (may be NULL) */
4216 u8 *aBuffer; /* Temporary buffer used for various tasks */
4217
4218 /* The following are used by write transactions only */
4219 ZipfileCsr *pCsrList; /* List of cursors */
 
 
 
4220 ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
4221 ZipfileEntry *pLastEntry; /* Last element in pFirstEntry list */
4222 FILE *pWriteFd; /* File handle open on zip archive */
4223 i64 szCurrent; /* Current size of zip archive */
4224 i64 szOrig; /* Size of archive at start of transaction */
@@ -4293,33 +4296,29 @@
4293
4294 /*
4295 ** Constructor for a new ZipfileCsr object.
4296 */
4297 static int zipfileOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCsr){
 
4298 ZipfileCsr *pCsr;
4299 pCsr = sqlite3_malloc(sizeof(*pCsr));
4300 *ppCsr = (sqlite3_vtab_cursor*)pCsr;
4301 if( pCsr==0 ){
4302 return SQLITE_NOMEM;
4303 }
4304 memset(pCsr, 0, sizeof(*pCsr));
 
 
 
4305 return SQLITE_OK;
4306 }
4307
4308 /*
4309 ** Reset a cursor back to the state it was in when first returned
4310 ** by zipfileOpen().
4311 */
4312 static void zipfileResetCursor(ZipfileCsr *pCsr){
4313 ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab);
4314 ZipfileCsr **pp;
4315
4316 /* Remove this cursor from the ZipfileTab.pCsrList list. */
4317 for(pp=&pTab->pCsrList; *pp; pp=&((*pp)->pCsrNext)){
4318 if( *pp==pCsr ) *pp = pCsr->pCsrNext;
4319 }
4320
4321 sqlite3_free(pCsr->cds.zFile);
4322 pCsr->cds.zFile = 0;
4323 pCsr->bEof = 0;
4324 if( pCsr->pFile ){
4325 fclose(pCsr->pFile);
@@ -4330,11 +4329,22 @@
4330 /*
4331 ** Destructor for an ZipfileCsr.
4332 */
4333 static int zipfileClose(sqlite3_vtab_cursor *cur){
4334 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
 
 
4335 zipfileResetCursor(pCsr);
 
 
 
 
 
 
 
 
 
4336 sqlite3_free(pCsr);
4337 return SQLITE_OK;
4338 }
4339
4340 /*
@@ -4413,14 +4423,51 @@
4413 }
4414
4415 /*
4416 ** Magic numbers used to read CDS records.
4417 */
4418 #define ZIPFILE_CDS_FIXED_SZ 46
4419 #define ZIPFILE_CDS_NFILE_OFF 28
4420
4421 static int zipfileReadCDS(ZipfileCsr *pCsr){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4422 char **pzErr = &pCsr->base.pVtab->zErrMsg;
4423 u8 *aRead;
4424 int rc = SQLITE_OK;
4425
4426 sqlite3_free(pCsr->cds.zFile);
@@ -4434,45 +4481,23 @@
4434 }else{
4435 aRead = pCsr->pCurrent->aCdsEntry;
4436 }
4437
4438 if( rc==SQLITE_OK ){
4439 u32 sig = zipfileRead32(aRead);
4440 if( sig!=ZIPFILE_SIGNATURE_CDS ){
4441 assert( pCsr->pCurrent==0 );
4442 zipfileSetErrmsg(pCsr,"failed to read CDS at offset %lld",pCsr->iNextOff);
4443 rc = SQLITE_ERROR;
4444 }else{
4445 int nRead;
4446 pCsr->cds.iVersionMadeBy = zipfileRead16(aRead);
4447 pCsr->cds.iVersionExtract = zipfileRead16(aRead);
4448 pCsr->cds.flags = zipfileRead16(aRead);
4449 pCsr->cds.iCompression = zipfileRead16(aRead);
4450 pCsr->cds.mTime = zipfileRead16(aRead);
4451 pCsr->cds.mDate = zipfileRead16(aRead);
4452 pCsr->cds.crc32 = zipfileRead32(aRead);
4453 pCsr->cds.szCompressed = zipfileRead32(aRead);
4454 pCsr->cds.szUncompressed = zipfileRead32(aRead);
4455 assert( pCsr->pCurrent
4456 || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_NFILE_OFF
4457 );
4458 pCsr->cds.nFile = zipfileRead16(aRead);
4459 pCsr->cds.nExtra = zipfileRead16(aRead);
4460 pCsr->cds.nComment = zipfileRead16(aRead);
4461 pCsr->cds.iDiskStart = zipfileRead16(aRead);
4462 pCsr->cds.iInternalAttr = zipfileRead16(aRead);
4463 pCsr->cds.iExternalAttr = zipfileRead32(aRead);
4464 pCsr->cds.iOffset = zipfileRead32(aRead);
4465 assert( pCsr->pCurrent
4466 || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_FIXED_SZ
4467 );
4468
4469 if( pCsr->pCurrent==0 ){
4470 nRead = pCsr->cds.nFile + pCsr->cds.nExtra;
4471 aRead = zipfileCsrBuffer(pCsr);
4472 pCsr->iNextOff += ZIPFILE_CDS_FIXED_SZ;
4473 rc = zipfileReadData(pCsr->pFile, aRead, nRead, pCsr->iNextOff, pzErr);
 
 
4474 }
4475
4476 if( rc==SQLITE_OK ){
4477 pCsr->cds.zFile = sqlite3_mprintf("%.*s", (int)pCsr->cds.nFile, aRead);
4478 pCsr->iNextOff += pCsr->cds.nFile;
@@ -4519,41 +4544,51 @@
4519 static FILE *zipfileGetFd(ZipfileCsr *pCsr){
4520 if( pCsr->pFile ) return pCsr->pFile;
4521 return ((ZipfileTab*)(pCsr->base.pVtab))->pWriteFd;
4522 }
4523
4524 static int zipfileReadLFH(ZipfileCsr *pCsr){
4525 FILE *pFile = zipfileGetFd(pCsr);
4526 char **pzErr = &pCsr->base.pVtab->zErrMsg;
 
 
 
 
 
4527 static const int szFix = ZIPFILE_LFH_FIXED_SZ;
4528 u8 *aRead = zipfileCsrBuffer(pCsr);
4529 int rc;
4530
4531 rc = zipfileReadData(pFile, aRead, szFix, pCsr->cds.iOffset, pzErr);
4532 if( rc==SQLITE_OK ){
4533 u32 sig = zipfileRead32(aRead);
4534 if( sig!=ZIPFILE_SIGNATURE_LFH ){
4535 zipfileSetErrmsg(pCsr, "failed to read LFH at offset %d",
4536 (int)pCsr->cds.iOffset
4537 );
4538 rc = SQLITE_ERROR;
4539 }else{
4540 pCsr->lfh.iVersionExtract = zipfileRead16(aRead);
4541 pCsr->lfh.flags = zipfileRead16(aRead);
4542 pCsr->lfh.iCompression = zipfileRead16(aRead);
4543 pCsr->lfh.mTime = zipfileRead16(aRead);
4544 pCsr->lfh.mDate = zipfileRead16(aRead);
4545 pCsr->lfh.crc32 = zipfileRead32(aRead);
4546 pCsr->lfh.szCompressed = zipfileRead32(aRead);
4547 pCsr->lfh.szUncompressed = zipfileRead32(aRead);
4548 pCsr->lfh.nFile = zipfileRead16(aRead);
4549 pCsr->lfh.nExtra = zipfileRead16(aRead);
4550 assert( aRead==zipfileCsrBuffer(pCsr)+szFix );
4551 pCsr->iDataOff = pCsr->cds.iOffset+szFix+pCsr->lfh.nFile+pCsr->lfh.nExtra;
4552 }
4553 }
4554
 
 
 
 
 
 
 
 
4555 return rc;
4556 }
4557
4558
4559 /*
@@ -4578,13 +4613,13 @@
4578 pCsr->bEof = 1;
4579 }
4580 }
4581
4582 if( pCsr->bEof==0 ){
4583 rc = zipfileReadCDS(pCsr);
4584 if( rc==SQLITE_OK ){
4585 rc = zipfileReadLFH(pCsr);
4586 }
4587 }
4588
4589 return rc;
4590 }
@@ -4737,18 +4772,22 @@
4737 sqlite3_result_int64(ctx, zipfileMtime(pCsr));
4738 }
4739 break;
4740 }
4741 case 3: { /* sz */
4742 sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
 
 
4743 break;
4744 }
4745 case 4: /* rawdata */
 
4746 case 5: { /* data */
4747 if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){
4748 int sz = pCsr->cds.szCompressed;
4749 if( sz>0 ){
 
4750 u8 *aBuf = sqlite3_malloc(sz);
4751 if( aBuf==0 ){
4752 rc = SQLITE_NOMEM;
4753 }else{
4754 FILE *pFile = zipfileGetFd(pCsr);
@@ -4756,26 +4795,37 @@
4756 &pCsr->base.pVtab->zErrMsg
4757 );
4758 }
4759 if( rc==SQLITE_OK ){
4760 if( i==5 && pCsr->cds.iCompression ){
4761 zipfileInflate(ctx, aBuf, sz, pCsr->cds.szUncompressed);
4762 }else{
4763 sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4764 }
4765 sqlite3_free(aBuf);
4766 }
 
 
 
 
 
 
 
 
4767 }
4768 }
4769 break;
4770 }
4771 case 6: /* method */
4772 sqlite3_result_int(ctx, pCsr->cds.iCompression);
4773 break;
 
 
 
4774 }
4775
4776 return SQLITE_OK;
4777 }
4778
4779 /*
4780 ** Return the rowid for the current row.
4781 */
@@ -4807,11 +4857,12 @@
4807 int rc;
4808
4809 fseek(pFile, 0, SEEK_END);
4810 szFile = (i64)ftell(pFile);
4811 if( szFile==0 ){
4812 return SQLITE_EMPTY;
 
4813 }
4814 nRead = (int)(MIN(szFile, ZIPFILE_BUFFER_SIZE));
4815 iOff = szFile - nRead;
4816
4817 rc = zipfileReadData(pFile, aRead, nRead, iOff, &pTab->base.zErrMsg);
@@ -4885,15 +4936,16 @@
4885 zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile);
4886 rc = SQLITE_ERROR;
4887 }else{
4888 rc = zipfileReadEOCD(pTab, pCsr->pFile, &pCsr->eocd);
4889 if( rc==SQLITE_OK ){
4890 pCsr->iNextOff = pCsr->eocd.iOffset;
4891 rc = zipfileNext(cur);
4892 }else if( rc==SQLITE_EMPTY ){
4893 rc = SQLITE_OK;
4894 pCsr->bEof = 1;
 
4895 }
4896 }
4897 }else{
4898 ZipfileEntry e;
4899 memset(&e, 0, sizeof(e));
@@ -4938,28 +4990,39 @@
4938
4939 /*
4940 ** Add object pNew to the end of the linked list that begins at
4941 ** ZipfileTab.pFirstEntry and ends with pLastEntry.
4942 */
4943 static void zipfileAddEntry(ZipfileTab *pTab, ZipfileEntry *pNew){
 
 
 
 
4944 assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
4945 assert( pNew->pNext==0 );
4946 if( pTab->pFirstEntry==0 ){
4947 pTab->pFirstEntry = pTab->pLastEntry = pNew;
 
 
 
 
 
 
4948 }else{
4949 assert( pTab->pLastEntry->pNext==0 );
4950 pTab->pLastEntry->pNext = pNew;
4951 pTab->pLastEntry = pNew;
 
4952 }
4953 }
4954
4955 static int zipfileLoadDirectory(ZipfileTab *pTab){
4956 ZipfileEOCD eocd;
4957 int rc;
4958
4959 rc = zipfileReadEOCD(pTab, pTab->pWriteFd, &eocd);
4960 if( rc==SQLITE_OK ){
4961 int i;
4962 int iOff = 0;
4963 u8 *aBuf = sqlite3_malloc(eocd.nSize);
4964 if( aBuf==0 ){
4965 rc = SQLITE_NOMEM;
@@ -4993,19 +5056,17 @@
4993 memcpy(pNew->zPath, &aRec[ZIPFILE_CDS_FIXED_SZ], nFile);
4994 pNew->zPath[nFile] = '\0';
4995 pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
4996 pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4997 memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
4998 zipfileAddEntry(pTab, pNew);
4999 }
5000
5001 iOff += ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
5002 }
5003
5004 sqlite3_free(aBuf);
5005 }else if( rc==SQLITE_EMPTY ){
5006 rc = SQLITE_OK;
5007 }
5008
5009 return rc;
5010 }
5011
@@ -5117,11 +5178,11 @@
5117 ){
5118 const char *z = (const char*)sqlite3_value_text(pVal);
5119 u32 mode = 0;
5120 if( z==0 ){
5121 mode = defaultMode;
5122 }else if( z[0]>=0 && z[0]<=9 ){
5123 mode = (unsigned int)sqlite3_value_int(pVal);
5124 }else{
5125 const char zTemplate[11] = "-rwxrwxrwx";
5126 int i;
5127 if( strlen(z)!=10 ) goto parse_error;
@@ -5180,83 +5241,68 @@
5180 int nData = 0; /* Size of pData buffer in bytes */
5181 int iMethod = 0; /* Compression method for new entry */
5182 u8 *pFree = 0; /* Free this */
5183 char *zFree = 0; /* Also free this */
5184 ZipfileCDS cds; /* New Central Directory Structure entry */
5185
5186 int bIsDir = 0;
5187
5188 int mNull;
5189
5190 assert( pTab->zFile );
5191 assert( pTab->pWriteFd );
5192
5193 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
5194 if( nVal>1 ){
5195 return SQLITE_CONSTRAINT;
5196 }else{
5197 const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
5198 int nDelete = strlen(zDelete);
5199 ZipfileEntry *p;
5200 for(p=pTab->pFirstEntry; p; p=p->pNext){
5201 if( zipfileComparePath(p->zPath, zDelete, nDelete)==0 ){
5202 p->bDeleted = 1;
5203 break;
5204 }
5205 }
5206 return SQLITE_OK;
5207 }
5208 }
5209
5210 mNull = (sqlite3_value_type(apVal[5])==SQLITE_NULL ? 0x0 : 0x8) /* sz */
5211 + (sqlite3_value_type(apVal[6])==SQLITE_NULL ? 0x0 : 0x4) /* rawdata */
5212 + (sqlite3_value_type(apVal[7])==SQLITE_NULL ? 0x0 : 0x2) /* data */
5213 + (sqlite3_value_type(apVal[8])==SQLITE_NULL ? 0x0 : 0x1); /* method */
5214 if( mNull==0x00 ){
5215 /* All four are NULL - this must be a directory */
5216 bIsDir = 1;
5217 }
5218 else if( mNull==0x2 || mNull==0x3 ){
5219 /* Value specified for "data", and possibly "method". This must be
5220 ** a regular file or a symlink. */
5221 const u8 *aIn = sqlite3_value_blob(apVal[7]);
5222 int nIn = sqlite3_value_bytes(apVal[7]);
5223 int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
5224
5225 iMethod = sqlite3_value_int(apVal[8]);
5226 sz = nIn;
5227 if( iMethod!=0 && iMethod!=8 ){
5228 rc = SQLITE_CONSTRAINT;
5229 }else if( bAuto || iMethod ){
5230 rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nData);
5231 if( rc==SQLITE_OK ){
5232 if( iMethod || nData<nIn ){
5233 iMethod = 8;
5234 pData = pFree;
5235 }else{
5236 pData = aIn;
5237 nData = nIn;
5238 }
5239 }
5240 }
5241 }
5242 else if( mNull==0x0D ){
5243 /* Values specified for "sz", "rawdata" and "method". In other words,
5244 ** pre-compressed data is being inserted. */
5245 pData = sqlite3_value_blob(apVal[6]);
5246 nData = sqlite3_value_bytes(apVal[6]);
5247 sz = sqlite3_value_int(apVal[5]);
5248 iMethod = sqlite3_value_int(apVal[8]);
5249 if( iMethod<0 || iMethod>65535 ){
5250 pTab->base.zErrMsg = sqlite3_mprintf(
5251 "zipfile: invalid compression method: %d", iMethod
5252 );
5253 rc = SQLITE_ERROR;
5254 }
5255 }
5256 else{
5257 rc = SQLITE_CONSTRAINT;
5258 }
5259
5260 if( rc==SQLITE_OK ){
5261 rc = zipfileGetMode(pTab, apVal[3],
5262 (bIsDir ? (S_IFDIR + 0755) : (S_IFREG + 0644)), &mode
@@ -5293,10 +5339,11 @@
5293
5294 /* Check that we're not inserting a duplicate entry */
5295 if( rc==SQLITE_OK ){
5296 ZipfileEntry *p;
5297 for(p=pTab->pFirstEntry; p; p=p->pNext){
 
5298 if( zipfileComparePath(p->zPath, zPath, nPath)==0 ){
5299 rc = SQLITE_CONSTRAINT;
5300 break;
5301 }
5302 }
@@ -5308,28 +5355,31 @@
5308 cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
5309 cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;
5310 cds.flags = ZIPFILE_NEWENTRY_FLAGS;
5311 cds.iCompression = (u16)iMethod;
5312 zipfileMtimeToDos(&cds, (u32)mTime);
5313 cds.crc32 = crc32(0, pData, nData);
5314 cds.szCompressed = nData;
5315 cds.szUncompressed = (u32)sz;
5316 cds.iExternalAttr = (mode<<16);
5317 cds.iOffset = (u32)pTab->szCurrent;
5318 pNew = zipfileNewEntry(&cds, zPath, nPath, (u32)mTime);
5319 if( pNew==0 ){
5320 rc = SQLITE_NOMEM;
5321 }else{
5322 zipfileAddEntry(pTab, pNew);
5323 }
5324 }
5325
5326 /* Append the new header+file to the archive */
5327 if( rc==SQLITE_OK ){
5328 rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
5329 }
5330
 
 
 
5331 sqlite3_free(pFree);
5332 sqlite3_free(zFree);
5333 return rc;
5334 }
5335
@@ -5434,10 +5484,88 @@
5434 }
5435
5436 static int zipfileRollback(sqlite3_vtab *pVtab){
5437 return zipfileCommit(pVtab);
5438 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5439
5440 /*
5441 ** Register the "zipfile" virtual table.
5442 */
5443 static int zipfileRegister(sqlite3 *db){
@@ -5458,15 +5586,18 @@
5458 zipfileUpdate, /* xUpdate */
5459 zipfileBegin, /* xBegin */
5460 0, /* xSync */
5461 zipfileCommit, /* xCommit */
5462 zipfileRollback, /* xRollback */
5463 0, /* xFindMethod */
5464 0, /* xRename */
5465 };
5466
5467 int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
 
 
 
5468 return rc;
5469 }
5470 #else /* SQLITE_OMIT_VIRTUALTABLE */
5471 # define zipfileRegister(x) SQLITE_OK
5472 #endif
5473
--- src/shell.c
+++ src/shell.c
@@ -4013,11 +4013,11 @@
4013 "mtime," /* 2: Last modification time (secs since 1970)*/
4014 "sz," /* 3: Size of object */
4015 "rawdata," /* 4: Raw data */
4016 "data," /* 5: Uncompressed data */
4017 "method," /* 6: Compression method (integer) */
4018 "z HIDDEN" /* 7: Name of zip file */
4019 ") WITHOUT ROWID;";
4020
4021 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
4022 #define ZIPFILE_BUFFER_SIZE (64*1024)
4023
@@ -4184,10 +4184,11 @@
4184 ** Cursor type for recursively iterating through a directory structure.
4185 */
4186 typedef struct ZipfileCsr ZipfileCsr;
4187 struct ZipfileCsr {
4188 sqlite3_vtab_cursor base; /* Base class - must be first */
4189 i64 iId; /* Cursor ID */
4190 int bEof; /* True when at EOF */
4191
4192 /* Used outside of write transactions */
4193 FILE *pFile; /* Zip file */
4194 i64 iNextOff; /* Offset of next record in central directory */
@@ -4213,12 +4214,14 @@
4214 struct ZipfileTab {
4215 sqlite3_vtab base; /* Base class - must be first */
4216 char *zFile; /* Zip file this table accesses (may be NULL) */
4217 u8 *aBuffer; /* Temporary buffer used for various tasks */
4218
 
4219 ZipfileCsr *pCsrList; /* List of cursors */
4220 i64 iNextCsrid;
4221
4222 /* The following are used by write transactions only */
4223 ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
4224 ZipfileEntry *pLastEntry; /* Last element in pFirstEntry list */
4225 FILE *pWriteFd; /* File handle open on zip archive */
4226 i64 szCurrent; /* Current size of zip archive */
4227 i64 szOrig; /* Size of archive at start of transaction */
@@ -4293,33 +4296,29 @@
4296
4297 /*
4298 ** Constructor for a new ZipfileCsr object.
4299 */
4300 static int zipfileOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCsr){
4301 ZipfileTab *pTab = (ZipfileTab*)p;
4302 ZipfileCsr *pCsr;
4303 pCsr = sqlite3_malloc(sizeof(*pCsr));
4304 *ppCsr = (sqlite3_vtab_cursor*)pCsr;
4305 if( pCsr==0 ){
4306 return SQLITE_NOMEM;
4307 }
4308 memset(pCsr, 0, sizeof(*pCsr));
4309 pCsr->iId = ++pTab->iNextCsrid;
4310 pCsr->pCsrNext = pTab->pCsrList;
4311 pTab->pCsrList = pCsr;
4312 return SQLITE_OK;
4313 }
4314
4315 /*
4316 ** Reset a cursor back to the state it was in when first returned
4317 ** by zipfileOpen().
4318 */
4319 static void zipfileResetCursor(ZipfileCsr *pCsr){
 
 
 
 
 
 
 
 
4320 sqlite3_free(pCsr->cds.zFile);
4321 pCsr->cds.zFile = 0;
4322 pCsr->bEof = 0;
4323 if( pCsr->pFile ){
4324 fclose(pCsr->pFile);
@@ -4330,11 +4329,22 @@
4329 /*
4330 ** Destructor for an ZipfileCsr.
4331 */
4332 static int zipfileClose(sqlite3_vtab_cursor *cur){
4333 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4334 ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab);
4335 ZipfileCsr **pp;
4336 zipfileResetCursor(pCsr);
4337
4338 /* Remove this cursor from the ZipfileTab.pCsrList list. */
4339 for(pp=&pTab->pCsrList; *pp; pp=&((*pp)->pCsrNext)){
4340 if( *pp==pCsr ){
4341 *pp = pCsr->pCsrNext;
4342 break;
4343 }
4344 }
4345
4346 sqlite3_free(pCsr);
4347 return SQLITE_OK;
4348 }
4349
4350 /*
@@ -4413,14 +4423,51 @@
4423 }
4424
4425 /*
4426 ** Magic numbers used to read CDS records.
4427 */
4428 #define ZIPFILE_CDS_FIXED_SZ 46
4429 #define ZIPFILE_CDS_NFILE_OFF 28
4430
4431 /*
4432 ** Decode the CDS record in buffer aBuf into (*pCDS). Return SQLITE_ERROR
4433 ** if the record is not well-formed, or SQLITE_OK otherwise.
4434 */
4435 static int zipfileReadCDS(u8 *aBuf, ZipfileCDS *pCDS){
4436 u8 *aRead = aBuf;
4437 u32 sig = zipfileRead32(aRead);
4438 int rc = SQLITE_OK;
4439 if( sig!=ZIPFILE_SIGNATURE_CDS ){
4440 rc = SQLITE_ERROR;
4441 }else{
4442 pCDS->iVersionMadeBy = zipfileRead16(aRead);
4443 pCDS->iVersionExtract = zipfileRead16(aRead);
4444 pCDS->flags = zipfileRead16(aRead);
4445 pCDS->iCompression = zipfileRead16(aRead);
4446 pCDS->mTime = zipfileRead16(aRead);
4447 pCDS->mDate = zipfileRead16(aRead);
4448 pCDS->crc32 = zipfileRead32(aRead);
4449 pCDS->szCompressed = zipfileRead32(aRead);
4450 pCDS->szUncompressed = zipfileRead32(aRead);
4451 assert( aRead==&aBuf[ZIPFILE_CDS_NFILE_OFF] );
4452 pCDS->nFile = zipfileRead16(aRead);
4453 pCDS->nExtra = zipfileRead16(aRead);
4454 pCDS->nComment = zipfileRead16(aRead);
4455 pCDS->iDiskStart = zipfileRead16(aRead);
4456 pCDS->iInternalAttr = zipfileRead16(aRead);
4457 pCDS->iExternalAttr = zipfileRead32(aRead);
4458 pCDS->iOffset = zipfileRead32(aRead);
4459 assert( aRead==&aBuf[ZIPFILE_CDS_FIXED_SZ] );
4460 }
4461
4462 return rc;
4463 }
4464
4465 /*
4466 ** Read the CDS record for the current entry from disk into pCsr->cds.
4467 */
4468 static int zipfileCsrReadCDS(ZipfileCsr *pCsr){
4469 char **pzErr = &pCsr->base.pVtab->zErrMsg;
4470 u8 *aRead;
4471 int rc = SQLITE_OK;
4472
4473 sqlite3_free(pCsr->cds.zFile);
@@ -4434,45 +4481,23 @@
4481 }else{
4482 aRead = pCsr->pCurrent->aCdsEntry;
4483 }
4484
4485 if( rc==SQLITE_OK ){
4486 rc = zipfileReadCDS(aRead, &pCsr->cds);
4487 if( rc!=SQLITE_OK ){
4488 assert( pCsr->pCurrent==0 );
4489 zipfileSetErrmsg(pCsr,"failed to read CDS at offset %lld",pCsr->iNextOff);
 
4490 }else{
4491 int nRead;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4492 if( pCsr->pCurrent==0 ){
4493 nRead = pCsr->cds.nFile + pCsr->cds.nExtra;
4494 aRead = zipfileCsrBuffer(pCsr);
4495 pCsr->iNextOff += ZIPFILE_CDS_FIXED_SZ;
4496 rc = zipfileReadData(pCsr->pFile, aRead, nRead, pCsr->iNextOff, pzErr);
4497 }else{
4498 aRead = &aRead[ZIPFILE_CDS_FIXED_SZ];
4499 }
4500
4501 if( rc==SQLITE_OK ){
4502 pCsr->cds.zFile = sqlite3_mprintf("%.*s", (int)pCsr->cds.nFile, aRead);
4503 pCsr->iNextOff += pCsr->cds.nFile;
@@ -4519,41 +4544,51 @@
4544 static FILE *zipfileGetFd(ZipfileCsr *pCsr){
4545 if( pCsr->pFile ) return pCsr->pFile;
4546 return ((ZipfileTab*)(pCsr->base.pVtab))->pWriteFd;
4547 }
4548
4549 static int zipfileReadLFH(
4550 FILE *pFd,
4551 i64 iOffset,
4552 u8 *aTmp,
4553 ZipfileLFH *pLFH,
4554 char **pzErr
4555 ){
4556 u8 *aRead = aTmp;
4557 static const int szFix = ZIPFILE_LFH_FIXED_SZ;
 
4558 int rc;
4559
4560 rc = zipfileReadData(pFd, aRead, szFix, iOffset, pzErr);
4561 if( rc==SQLITE_OK ){
4562 u32 sig = zipfileRead32(aRead);
4563 if( sig!=ZIPFILE_SIGNATURE_LFH ){
4564 *pzErr = sqlite3_mprintf("failed to read LFH at offset %d", (int)iOffset);
 
 
4565 rc = SQLITE_ERROR;
4566 }else{
4567 pLFH->iVersionExtract = zipfileRead16(aRead);
4568 pLFH->flags = zipfileRead16(aRead);
4569 pLFH->iCompression = zipfileRead16(aRead);
4570 pLFH->mTime = zipfileRead16(aRead);
4571 pLFH->mDate = zipfileRead16(aRead);
4572 pLFH->crc32 = zipfileRead32(aRead);
4573 pLFH->szCompressed = zipfileRead32(aRead);
4574 pLFH->szUncompressed = zipfileRead32(aRead);
4575 pLFH->nFile = zipfileRead16(aRead);
4576 pLFH->nExtra = zipfileRead16(aRead);
4577 assert( aRead==&aTmp[szFix] );
4578 }
4579 }
4580 return rc;
4581 }
4582
4583 static int zipfileCsrReadLFH(ZipfileCsr *pCsr){
4584 FILE *pFile = zipfileGetFd(pCsr);
4585 char **pzErr = &pCsr->base.pVtab->zErrMsg;
4586 u8 *aRead = zipfileCsrBuffer(pCsr);
4587 int rc = zipfileReadLFH(pFile, pCsr->cds.iOffset, aRead, &pCsr->lfh, pzErr);
4588 pCsr->iDataOff = pCsr->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
4589 pCsr->iDataOff += pCsr->lfh.nFile+pCsr->lfh.nExtra;
4590 return rc;
4591 }
4592
4593
4594 /*
@@ -4578,13 +4613,13 @@
4613 pCsr->bEof = 1;
4614 }
4615 }
4616
4617 if( pCsr->bEof==0 ){
4618 rc = zipfileCsrReadCDS(pCsr);
4619 if( rc==SQLITE_OK ){
4620 rc = zipfileCsrReadLFH(pCsr);
4621 }
4622 }
4623
4624 return rc;
4625 }
@@ -4737,18 +4772,22 @@
4772 sqlite3_result_int64(ctx, zipfileMtime(pCsr));
4773 }
4774 break;
4775 }
4776 case 3: { /* sz */
4777 if( sqlite3_vtab_nochange(ctx)==0 ){
4778 sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4779 }
4780 break;
4781 }
4782 case 4: /* rawdata */
4783 if( sqlite3_vtab_nochange(ctx) ) break;
4784 case 5: { /* data */
4785 if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){
4786 int sz = pCsr->cds.szCompressed;
4787 int szFinal = pCsr->cds.szUncompressed;
4788 if( szFinal>0 ){
4789 u8 *aBuf = sqlite3_malloc(sz);
4790 if( aBuf==0 ){
4791 rc = SQLITE_NOMEM;
4792 }else{
4793 FILE *pFile = zipfileGetFd(pCsr);
@@ -4756,26 +4795,37 @@
4795 &pCsr->base.pVtab->zErrMsg
4796 );
4797 }
4798 if( rc==SQLITE_OK ){
4799 if( i==5 && pCsr->cds.iCompression ){
4800 zipfileInflate(ctx, aBuf, sz, szFinal);
4801 }else{
4802 sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4803 }
4804 sqlite3_free(aBuf);
4805 }
4806 }else{
4807 /* Figure out if this is a directory or a zero-sized file. Consider
4808 ** it to be a directory either if the mode suggests so, or if
4809 ** the final character in the name is '/'. */
4810 u32 mode = pCsr->cds.iExternalAttr >> 16;
4811 if( !(mode & S_IFDIR) && pCsr->cds.zFile[pCsr->cds.nFile-1]!='/' ){
4812 sqlite3_result_blob(ctx, "", 0, SQLITE_STATIC);
4813 }
4814 }
4815 }
4816 break;
4817 }
4818 case 6: /* method */
4819 sqlite3_result_int(ctx, pCsr->cds.iCompression);
4820 break;
4821 case 7: /* z */
4822 sqlite3_result_int64(ctx, pCsr->iId);
4823 break;
4824 }
4825
4826 return rc;
4827 }
4828
4829 /*
4830 ** Return the rowid for the current row.
4831 */
@@ -4807,11 +4857,12 @@
4857 int rc;
4858
4859 fseek(pFile, 0, SEEK_END);
4860 szFile = (i64)ftell(pFile);
4861 if( szFile==0 ){
4862 memset(pEOCD, 0, sizeof(ZipfileEOCD));
4863 return SQLITE_OK;
4864 }
4865 nRead = (int)(MIN(szFile, ZIPFILE_BUFFER_SIZE));
4866 iOff = szFile - nRead;
4867
4868 rc = zipfileReadData(pFile, aRead, nRead, iOff, &pTab->base.zErrMsg);
@@ -4885,15 +4936,16 @@
4936 zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile);
4937 rc = SQLITE_ERROR;
4938 }else{
4939 rc = zipfileReadEOCD(pTab, pCsr->pFile, &pCsr->eocd);
4940 if( rc==SQLITE_OK ){
4941 if( pCsr->eocd.nEntry==0 ){
4942 pCsr->bEof = 1;
4943 }else{
4944 pCsr->iNextOff = pCsr->eocd.iOffset;
4945 rc = zipfileNext(cur);
4946 }
4947 }
4948 }
4949 }else{
4950 ZipfileEntry e;
4951 memset(&e, 0, sizeof(e));
@@ -4938,28 +4990,39 @@
4990
4991 /*
4992 ** Add object pNew to the end of the linked list that begins at
4993 ** ZipfileTab.pFirstEntry and ends with pLastEntry.
4994 */
4995 static void zipfileAddEntry(
4996 ZipfileTab *pTab,
4997 ZipfileEntry *pBefore,
4998 ZipfileEntry *pNew
4999 ){
5000 assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
5001 assert( pNew->pNext==0 );
5002 if( pBefore==0 ){
5003 if( pTab->pFirstEntry==0 ){
5004 pTab->pFirstEntry = pTab->pLastEntry = pNew;
5005 }else{
5006 assert( pTab->pLastEntry->pNext==0 );
5007 pTab->pLastEntry->pNext = pNew;
5008 pTab->pLastEntry = pNew;
5009 }
5010 }else{
5011 ZipfileEntry **pp;
5012 for(pp=&pTab->pFirstEntry; *pp!=pBefore; pp=&((*pp)->pNext));
5013 pNew->pNext = pBefore;
5014 *pp = pNew;
5015 }
5016 }
5017
5018 static int zipfileLoadDirectory(ZipfileTab *pTab){
5019 ZipfileEOCD eocd;
5020 int rc;
5021
5022 rc = zipfileReadEOCD(pTab, pTab->pWriteFd, &eocd);
5023 if( rc==SQLITE_OK && eocd.nEntry>0 ){
5024 int i;
5025 int iOff = 0;
5026 u8 *aBuf = sqlite3_malloc(eocd.nSize);
5027 if( aBuf==0 ){
5028 rc = SQLITE_NOMEM;
@@ -4993,19 +5056,17 @@
5056 memcpy(pNew->zPath, &aRec[ZIPFILE_CDS_FIXED_SZ], nFile);
5057 pNew->zPath[nFile] = '\0';
5058 pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
5059 pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
5060 memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
5061 zipfileAddEntry(pTab, 0, pNew);
5062 }
5063
5064 iOff += ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
5065 }
5066
5067 sqlite3_free(aBuf);
 
 
5068 }
5069
5070 return rc;
5071 }
5072
@@ -5117,11 +5178,11 @@
5178 ){
5179 const char *z = (const char*)sqlite3_value_text(pVal);
5180 u32 mode = 0;
5181 if( z==0 ){
5182 mode = defaultMode;
5183 }else if( z[0]>='0' && z[0]<='9' ){
5184 mode = (unsigned int)sqlite3_value_int(pVal);
5185 }else{
5186 const char zTemplate[11] = "-rwxrwxrwx";
5187 int i;
5188 if( strlen(z)!=10 ) goto parse_error;
@@ -5180,83 +5241,68 @@
5241 int nData = 0; /* Size of pData buffer in bytes */
5242 int iMethod = 0; /* Compression method for new entry */
5243 u8 *pFree = 0; /* Free this */
5244 char *zFree = 0; /* Also free this */
5245 ZipfileCDS cds; /* New Central Directory Structure entry */
5246 ZipfileEntry *pOld = 0;
5247 int bIsDir = 0;
5248 u32 iCrc32 = 0;
 
5249
5250 assert( pTab->zFile );
5251 assert( pTab->pWriteFd );
5252
5253 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
5254 const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
5255 int nDelete = (int)strlen(zDelete);
5256 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
5257 if( pOld->bDeleted ) continue;
5258 if( zipfileComparePath(pOld->zPath, zDelete, nDelete)==0 ){
5259 pOld->bDeleted = 1;
5260 break;
5261 }
5262 assert( pOld->pNext );
5263 }
5264 if( nVal==1 ) return SQLITE_OK;
5265 }
5266
5267 /* Check that "sz" and "rawdata" are both NULL: */
5268 if( sqlite3_value_type(apVal[5])!=SQLITE_NULL
5269 || sqlite3_value_type(apVal[6])!=SQLITE_NULL
5270 ){
5271 rc = SQLITE_CONSTRAINT;
5272 }
5273
5274 if( rc==SQLITE_OK ){
5275 if( sqlite3_value_type(apVal[7])==SQLITE_NULL ){
5276 /* data=NULL. A directory */
5277 bIsDir = 1;
5278 }else{
5279 /* Value specified for "data", and possibly "method". This must be
5280 ** a regular file or a symlink. */
5281 const u8 *aIn = sqlite3_value_blob(apVal[7]);
5282 int nIn = sqlite3_value_bytes(apVal[7]);
5283 int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
5284
5285 iMethod = sqlite3_value_int(apVal[8]);
5286 sz = nIn;
5287 pData = aIn;
5288 nData = nIn;
5289 if( iMethod!=0 && iMethod!=8 ){
5290 rc = SQLITE_CONSTRAINT;
5291 }else if( bAuto || iMethod ){
5292 int nCmp;
5293 rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nCmp);
5294 if( rc==SQLITE_OK ){
5295 if( iMethod || nCmp<nIn ){
5296 iMethod = 8;
5297 pData = pFree;
5298 nData = nCmp;
5299 }
5300 }
5301 iCrc32 = crc32(0, aIn, nIn);
5302 }
5303 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5304 }
5305
5306 if( rc==SQLITE_OK ){
5307 rc = zipfileGetMode(pTab, apVal[3],
5308 (bIsDir ? (S_IFDIR + 0755) : (S_IFREG + 0644)), &mode
@@ -5293,10 +5339,11 @@
5339
5340 /* Check that we're not inserting a duplicate entry */
5341 if( rc==SQLITE_OK ){
5342 ZipfileEntry *p;
5343 for(p=pTab->pFirstEntry; p; p=p->pNext){
5344 if( p->bDeleted ) continue;
5345 if( zipfileComparePath(p->zPath, zPath, nPath)==0 ){
5346 rc = SQLITE_CONSTRAINT;
5347 break;
5348 }
5349 }
@@ -5308,28 +5355,31 @@
5355 cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
5356 cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;
5357 cds.flags = ZIPFILE_NEWENTRY_FLAGS;
5358 cds.iCompression = (u16)iMethod;
5359 zipfileMtimeToDos(&cds, (u32)mTime);
5360 cds.crc32 = iCrc32;
5361 cds.szCompressed = nData;
5362 cds.szUncompressed = (u32)sz;
5363 cds.iExternalAttr = (mode<<16);
5364 cds.iOffset = (u32)pTab->szCurrent;
5365 pNew = zipfileNewEntry(&cds, zPath, nPath, (u32)mTime);
5366 if( pNew==0 ){
5367 rc = SQLITE_NOMEM;
5368 }else{
5369 zipfileAddEntry(pTab, pOld, pNew);
5370 }
5371 }
5372
5373 /* Append the new header+file to the archive */
5374 if( rc==SQLITE_OK ){
5375 rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
5376 }
5377
5378 if( rc!=SQLITE_OK && pOld ){
5379 pOld->bDeleted = 0;
5380 }
5381 sqlite3_free(pFree);
5382 sqlite3_free(zFree);
5383 return rc;
5384 }
5385
@@ -5434,10 +5484,88 @@
5484 }
5485
5486 static int zipfileRollback(sqlite3_vtab *pVtab){
5487 return zipfileCommit(pVtab);
5488 }
5489
5490 static ZipfileCsr *zipfileFindCursor(ZipfileTab *pTab, i64 iId){
5491 ZipfileCsr *pCsr;
5492 for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){
5493 if( iId==pCsr->iId ) break;
5494 }
5495 return pCsr;
5496 }
5497
5498 static void zipfileFunctionCds(
5499 sqlite3_context *context,
5500 int argc,
5501 sqlite3_value **argv
5502 ){
5503 ZipfileCsr *pCsr;
5504 ZipfileTab *pTab = (ZipfileTab*)sqlite3_user_data(context);
5505 assert( argc>0 );
5506
5507 pCsr = zipfileFindCursor(pTab, sqlite3_value_int64(argv[0]));
5508 if( pCsr ){
5509 ZipfileCDS *p = &pCsr->cds;
5510 char *zRes = sqlite3_mprintf("{"
5511 "\"version-made-by\" : %u, "
5512 "\"version-to-extract\" : %u, "
5513 "\"flags\" : %u, "
5514 "\"compression\" : %u, "
5515 "\"time\" : %u, "
5516 "\"date\" : %u, "
5517 "\"crc32\" : %u, "
5518 "\"compressed-size\" : %u, "
5519 "\"uncompressed-size\" : %u, "
5520 "\"file-name-length\" : %u, "
5521 "\"extra-field-length\" : %u, "
5522 "\"file-comment-length\" : %u, "
5523 "\"disk-number-start\" : %u, "
5524 "\"internal-attr\" : %u, "
5525 "\"external-attr\" : %u, "
5526 "\"offset\" : %u }",
5527 (u32)p->iVersionMadeBy, (u32)p->iVersionExtract,
5528 (u32)p->flags, (u32)p->iCompression,
5529 (u32)p->mTime, (u32)p->mDate,
5530 (u32)p->crc32, (u32)p->szCompressed,
5531 (u32)p->szUncompressed, (u32)p->nFile,
5532 (u32)p->nExtra, (u32)p->nComment,
5533 (u32)p->iDiskStart, (u32)p->iInternalAttr,
5534 (u32)p->iExternalAttr, (u32)p->iOffset
5535 );
5536
5537 if( zRes==0 ){
5538 sqlite3_result_error_nomem(context);
5539 }else{
5540 sqlite3_result_text(context, zRes, -1, SQLITE_TRANSIENT);
5541 sqlite3_free(zRes);
5542 }
5543 }
5544 }
5545
5546
5547 /*
5548 ** xFindFunction method.
5549 */
5550 static int zipfileFindFunction(
5551 sqlite3_vtab *pVtab, /* Virtual table handle */
5552 int nArg, /* Number of SQL function arguments */
5553 const char *zName, /* Name of SQL function */
5554 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
5555 void **ppArg /* OUT: User data for *pxFunc */
5556 ){
5557 if( nArg>0 ){
5558 if( sqlite3_stricmp("zipfile_cds", zName)==0 ){
5559 *pxFunc = zipfileFunctionCds;
5560 *ppArg = (void*)pVtab;
5561 return 1;
5562 }
5563 }
5564
5565 return 0;
5566 }
5567
5568 /*
5569 ** Register the "zipfile" virtual table.
5570 */
5571 static int zipfileRegister(sqlite3 *db){
@@ -5458,15 +5586,18 @@
5586 zipfileUpdate, /* xUpdate */
5587 zipfileBegin, /* xBegin */
5588 0, /* xSync */
5589 zipfileCommit, /* xCommit */
5590 zipfileRollback, /* xRollback */
5591 zipfileFindFunction, /* xFindMethod */
5592 0, /* xRename */
5593 };
5594
5595 int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
5596 if( rc==SQLITE_OK ){
5597 rc = sqlite3_overload_function(db, "zipfile_cds", -1);
5598 }
5599 return rc;
5600 }
5601 #else /* SQLITE_OMIT_VIRTUALTABLE */
5602 # define zipfileRegister(x) SQLITE_OK
5603 #endif
5604
+153 -42
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
11471147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11481148
** [sqlite_version()] and [sqlite_source_id()].
11491149
*/
11501150
#define SQLITE_VERSION "3.22.0"
11511151
#define SQLITE_VERSION_NUMBER 3022000
1152
-#define SQLITE_SOURCE_ID "2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7148c"
1152
+#define SQLITE_SOURCE_ID "2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4356b"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -5821,10 +5821,13 @@
58215821
** TEXT in bytes
58225822
** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
58235823
** datatype of the value
58245824
** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
58255825
** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
5826
+** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
5827
+** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
5828
+** against a virtual table.
58265829
** </table></blockquote>
58275830
**
58285831
** <b>Details:</b>
58295832
**
58305833
** These routines extract type, size, and content information from
@@ -5868,10 +5871,23 @@
58685871
** made to convert the value to an integer or floating point. If
58695872
** such a conversion is possible without loss of information (in other
58705873
** words, if the value is a string that looks like a number)
58715874
** then the conversion is performed. Otherwise no conversion occurs.
58725875
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5876
+**
5877
+** ^Within the [xUpdate] method of a [virtual table], the
5878
+** sqlite3_value_nochange(X) interface returns true if and only if
5879
+** the column corresponding to X is unchanged by the UPDATE operation
5880
+** that the xUpdate method call was invoked to implement and if
5881
+** and the prior [xColumn] method call that was invoked to extracted
5882
+** the value for that column returned without setting a result (probably
5883
+** because it queried [sqlite3_vtab_nochange()] and found that the column
5884
+** was unchanging). ^Within an [xUpdate] method, any value for which
5885
+** sqlite3_value_nochange(X) is true will in all other respects appear
5886
+** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
5887
+** than within an [xUpdate] method call for an UPDATE statement, then
5888
+** the return value is arbitrary and meaningless.
58735889
**
58745890
** Please pay particular attention to the fact that the pointer returned
58755891
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
58765892
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
58775893
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5891,10 +5907,11 @@
58915907
SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
58925908
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
58935909
SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
58945910
SQLITE_API int sqlite3_value_type(sqlite3_value*);
58955911
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5912
+SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
58965913
58975914
/*
58985915
** CAPI3REF: Finding The Subtype Of SQL Values
58995916
** METHOD: sqlite3_value
59005917
**
@@ -9328,10 +9345,17 @@
93289345
** method of a [virtual table], then it returns true if and only if the
93299346
** column is being fetched as part of an UPDATE operation during which the
93309347
** column value will not change. Applications might use this to substitute
93319348
** a lighter-weight value to return that the corresponding [xUpdate] method
93329349
** understands as a "no-change" value.
9350
+**
9351
+** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
9352
+** the column is not changed by the UPDATE statement, they the xColumn
9353
+** method can optionally return without setting a result, without calling
9354
+** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
9355
+** In that case, [sqlite3_value_nochange(X)] will return true for the
9356
+** same column in the [xUpdate] method.
93339357
*/
93349358
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
93359359
93369360
/*
93379361
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
@@ -13742,10 +13766,11 @@
1374213766
#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
1374313767
#define P4_REAL (-13) /* P4 is a 64-bit floating point value */
1374413768
#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
1374513769
#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
1374613770
#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
13771
+#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */
1374713772
1374813773
/* Error message codes for OP_Halt */
1374913774
#define P5_ConstraintNotNull 1
1375013775
#define P5_ConstraintUnique 2
1375113776
#define P5_ConstraintCheck 3
@@ -16945,10 +16970,11 @@
1694516970
#define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
1694616971
#define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
1694716972
#define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
1694816973
#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
1694916974
#define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
16975
+#define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */
1695016976
1695116977
/*
1695216978
* Each trigger present in the database schema is stored as an instance of
1695316979
* struct Trigger.
1695416980
*
@@ -18801,10 +18827,12 @@
1880118827
** representations of the value stored in the Mem struct.
1880218828
**
1880318829
** If the MEM_Null flag is set, then the value is an SQL NULL value.
1880418830
** For a pointer type created using sqlite3_bind_pointer() or
1880518831
** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
18832
+** If both MEM_Null and MEM_Zero are set, that means that the value is
18833
+** an unchanging column value from VColumn.
1880618834
**
1880718835
** If the MEM_Str flag is set then Mem.z points at a string representation.
1880818836
** Usually this is encoded in the same unicode encoding as the main
1880918837
** database (see below for exceptions). If the MEM_Term flag is also
1881018838
** set, then the string is nul terminated. The MEM_Int and MEM_Real
@@ -34616,11 +34644,11 @@
3461634644
3461734645
/* Set defaults for non-supported filesystems */
3461834646
pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
3461934647
pFile->deviceCharacteristics = 0;
3462034648
if( fstatvfs(pFile->h, &fsInfo) == -1 ) {
34621
- return pFile->sectorSize;
34649
+ return;
3462234650
}
3462334651
3462434652
if( !strcmp(fsInfo.f_basetype, "tmp") ) {
3462534653
pFile->sectorSize = fsInfo.f_bsize;
3462634654
pFile->deviceCharacteristics =
@@ -71150,11 +71178,11 @@
7115071178
assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
7115171179
7115271180
if( p->flags & MEM_Null ){
7115371181
/* Cannot be both MEM_Null and some other type */
7115471182
assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob
71155
- |MEM_RowSet|MEM_Frame|MEM_Agg|MEM_Zero))==0 );
71183
+ |MEM_RowSet|MEM_Frame|MEM_Agg))==0 );
7115671184
7115771185
/* If MEM_Null is set, then either the value is a pure NULL (the usual
7115871186
** case) or it is a pointer set using sqlite3_bind_pointer() or
7115971187
** sqlite3_result_pointer(). If a pointer, then MEM_Term must also be
7116071188
** set.
@@ -73743,10 +73771,11 @@
7374373771
break;
7374473772
}
7374573773
case P4_REAL:
7374673774
case P4_INT64:
7374773775
case P4_DYNAMIC:
73776
+ case P4_DYNBLOB:
7374873777
case P4_INTARRAY: {
7374973778
sqlite3DbFree(db, p4);
7375073779
break;
7375173780
}
7375273781
case P4_KEYINFO: {
@@ -74284,10 +74313,11 @@
7428474313
}
7428574314
case P4_SUBPROGRAM: {
7428674315
sqlite3XPrintf(&x, "program");
7428774316
break;
7428874317
}
74318
+ case P4_DYNBLOB:
7428974319
case P4_ADVANCE: {
7429074320
zTemp[0] = 0;
7429174321
break;
7429274322
}
7429374323
case P4_TABLE: {
@@ -76329,11 +76359,17 @@
7632976359
const unsigned char *buf, /* Buffer to deserialize from */
7633076360
u32 serial_type, /* Serial type to deserialize */
7633176361
Mem *pMem /* Memory cell to write value into */
7633276362
){
7633376363
switch( serial_type ){
76334
- case 10: /* Reserved for future use */
76364
+ case 10: { /* Internal use only: NULL with virtual table
76365
+ ** UPDATE no-change flag set */
76366
+ pMem->flags = MEM_Null|MEM_Zero;
76367
+ pMem->n = 0;
76368
+ pMem->u.nZero = 0;
76369
+ break;
76370
+ }
7633576371
case 11: /* Reserved for future use */
7633676372
case 0: { /* Null */
7633776373
/* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
7633876374
pMem->flags = MEM_Null;
7633976375
break;
@@ -77881,10 +77917,15 @@
7788177917
SQLITE_INTEGER, /* 0x1e */
7788277918
SQLITE_NULL, /* 0x1f */
7788377919
};
7788477920
return aType[pVal->flags&MEM_AffMask];
7788577921
}
77922
+
77923
+/* Return true if a parameter to xUpdate represents an unchanged column */
77924
+SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){
77925
+ return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
77926
+}
7788677927
7788777928
/* Make a copy of an sqlite3_value object
7788877929
*/
7788977930
SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
7789077931
sqlite3_value *pNew;
@@ -78375,11 +78416,11 @@
7837578416
** performance by substituting a NULL result, or some other light-weight
7837678417
** value, as a signal to the xUpdate routine that the column is unchanged.
7837778418
*/
7837878419
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
7837978420
assert( p );
78380
- return p->bVtabNoChng;
78421
+ return sqlite3_value_nochange(p->pOut);
7838178422
}
7838278423
7838378424
/*
7838478425
** Return the current time for a statement. If the current time
7838578426
** is requested more than once within the same run of a single prepared
@@ -80259,11 +80300,11 @@
8025980300
*/
8026080301
static void memTracePrint(Mem *p){
8026180302
if( p->flags & MEM_Undefined ){
8026280303
printf(" undefined");
8026380304
}else if( p->flags & MEM_Null ){
80264
- printf(" NULL");
80305
+ printf(p->flags & MEM_Zero ? " NULL-nochng" : " NULL");
8026580306
}else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
8026680307
printf(" si:%lld", p->u.i);
8026780308
}else if( p->flags & MEM_Int ){
8026880309
printf(" i:%lld", p->u.i);
8026980310
#ifndef SQLITE_OMIT_FLOATING_POINT
@@ -82676,13 +82717,22 @@
8267682717
** out how much space is required for the new record.
8267782718
*/
8267882719
pRec = pLast;
8267982720
do{
8268082721
assert( memIsValid(pRec) );
82681
- pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format, &len);
82722
+ serial_type = sqlite3VdbeSerialType(pRec, file_format, &len);
8268282723
if( pRec->flags & MEM_Zero ){
82683
- if( nData ){
82724
+ if( serial_type==0 ){
82725
+ /* Values with MEM_Null and MEM_Zero are created by xColumn virtual
82726
+ ** table methods that never invoke sqlite3_result_xxxxx() while
82727
+ ** computing an unchanging column value in an UPDATE statement.
82728
+ ** Give such values a special internal-use-only serial-type of 10
82729
+ ** so that they can be passed through to xUpdate and have
82730
+ ** a true sqlite3_value_nochange(). */
82731
+ assert( pOp->p5==OPFLAG_NOCHNG_MAGIC || CORRUPT_DB );
82732
+ serial_type = 10;
82733
+ }else if( nData ){
8268482734
if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem;
8268582735
}else{
8268682736
nZero += pRec->u.nZero;
8268782737
len -= pRec->u.nZero;
8268882738
}
@@ -82689,10 +82739,11 @@
8268982739
}
8269082740
nData += len;
8269182741
testcase( serial_type==127 );
8269282742
testcase( serial_type==128 );
8269382743
nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
82744
+ pRec->uTemp = serial_type;
8269482745
if( pRec==pData0 ) break;
8269582746
pRec--;
8269682747
}while(1);
8269782748
8269882749
/* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
@@ -84299,14 +84350,12 @@
8429984350
Mem *pKey; /* MEM cell holding key for the record */
8430084351
VdbeCursor *pC; /* Cursor to table into which insert is written */
8430184352
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
8430284353
const char *zDb; /* database name - used by the update hook */
8430384354
Table *pTab; /* Table structure - used by update and pre-update hooks */
84304
- int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
8430584355
BtreePayload x; /* Payload to be inserted */
8430684356
84307
- op = 0;
8430884357
pData = &aMem[pOp->p2];
8430984358
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8431084359
assert( memIsValid(pData) );
8431184360
pC = p->apCsr[pOp->p1];
8431284361
assert( pC!=0 );
@@ -84330,23 +84379,25 @@
8433084379
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
8433184380
assert( pC->iDb>=0 );
8433284381
zDb = db->aDb[pC->iDb].zDbSName;
8433384382
pTab = pOp->p4.pTab;
8433484383
assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
84335
- op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
8433684384
}else{
84337
- pTab = 0; /* Not needed. Silence a compiler warning. */
84385
+ pTab = 0;
8433884386
zDb = 0; /* Not needed. Silence a compiler warning. */
8433984387
}
8434084388
8434184389
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
8434284390
/* Invoke the pre-update hook, if any */
84343
- if( db->xPreUpdateCallback
84344
- && pOp->p4type==P4_TABLE
84345
- && !(pOp->p5 & OPFLAG_ISUPDATE)
84346
- ){
84347
- sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
84391
+ if( pTab ){
84392
+ if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){
84393
+ sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2);
84394
+ }
84395
+ if( db->xUpdateCallback==0 || pTab->aCol==0 ){
84396
+ /* Prevent post-update hook from running in cases when it should not */
84397
+ pTab = 0;
84398
+ }
8434884399
}
8434984400
if( pOp->p5 & OPFLAG_ISNOOP ) break;
8435084401
#endif
8435184402
8435284403
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
@@ -84367,12 +84418,16 @@
8436784418
pC->deferredMoveto = 0;
8436884419
pC->cacheStatus = CACHE_STALE;
8436984420
8437084421
/* Invoke the update-hook if required. */
8437184422
if( rc ) goto abort_due_to_error;
84372
- if( db->xUpdateCallback && op ){
84373
- db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, x.nKey);
84423
+ if( pTab ){
84424
+ assert( db->xUpdateCallback!=0 );
84425
+ assert( pTab->aCol!=0 );
84426
+ db->xUpdateCallback(db->pUpdateArg,
84427
+ (pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT,
84428
+ zDb, pTab->zName, x.nKey);
8437484429
}
8437584430
break;
8437684431
}
8437784432
8437884433
/* Opcode: Delete P1 P2 P3 P4 P5
@@ -86577,19 +86632,19 @@
8657786632
break;
8657886633
}
8657986634
#endif /* SQLITE_OMIT_VIRTUALTABLE */
8658086635
8658186636
#ifndef SQLITE_OMIT_VIRTUALTABLE
86582
-/* Opcode: VColumn P1 P2 P3 P4 *
86637
+/* Opcode: VColumn P1 P2 P3 * P5
8658386638
** Synopsis: r[P3]=vcolumn(P2)
8658486639
**
8658586640
** Store in register P3 the value of the P2-th column of
8658686641
** the current row of the virtual-table of cursor P1.
8658786642
**
8658886643
** If the VColumn opcode is being used to fetch the value of
86589
-** an unchanging column during an UPDATE operation, then the P4
86590
-** value is 1. Otherwise, P4 is 0. The P4 value is returned
86644
+** an unchanging column during an UPDATE operation, then the P5
86645
+** value is 1. Otherwise, P5 is 0. The P5 value is returned
8659186646
** by sqlite3_vtab_nochange() routine can can be used
8659286647
** by virtual table implementations to return special "no-change"
8659386648
** marks which can be more efficient, depending on the virtual table.
8659486649
*/
8659586650
case OP_VColumn: {
@@ -86610,12 +86665,17 @@
8661086665
pVtab = pCur->uc.pVCur->pVtab;
8661186666
pModule = pVtab->pModule;
8661286667
assert( pModule->xColumn );
8661386668
memset(&sContext, 0, sizeof(sContext));
8661486669
sContext.pOut = pDest;
86615
- sContext.bVtabNoChng = pOp->p4.i!=0;
86616
- MemSetTypeFlag(pDest, MEM_Null);
86670
+ if( pOp->p5 ){
86671
+ sqlite3VdbeMemSetNull(pDest);
86672
+ pDest->flags = MEM_Null|MEM_Zero;
86673
+ pDest->u.nZero = 0;
86674
+ }else{
86675
+ MemSetTypeFlag(pDest, MEM_Null);
86676
+ }
8661786677
rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2);
8661886678
sqlite3VtabImportErrmsg(p, pVtab);
8661986679
if( sContext.isError ){
8662086680
rc = sContext.isError;
8662186681
}
@@ -95336,11 +95396,10 @@
9533695396
pSel->pLimit->pLeft = pLimit;
9533795397
}else{
9533895398
pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
9533995399
}
9534095400
pSel->iLimit = 0;
95341
- pSel->selFlags &= ~SF_MultiValue;
9534295401
if( sqlite3Select(pParse, pSel, &dest) ){
9534395402
return 0;
9534495403
}
9534595404
rReg = dest.iSDParm;
9534695405
ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -98950,10 +99009,14 @@
9895099009
if( zWhere ){
9895199010
sqlite3NestedParse(pParse,
9895299011
"DELETE FROM %Q.%s WHERE %s=%Q",
9895399012
pDb->zDbSName, zTab, zWhereType, zWhere
9895499013
);
99014
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
99015
+ }else if( db->xPreUpdateCallback ){
99016
+ sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
99017
+#endif
9895599018
}else{
9895699019
/* The sqlite_stat[134] table already exists. Delete all rows. */
9895799020
sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
9895899021
}
9895999022
}
@@ -99714,10 +99777,13 @@
9971499777
int regTemp = iMem++; /* Temporary use register */
9971599778
int regTabname = iMem++; /* Register containing table name */
9971699779
int regIdxname = iMem++; /* Register containing index name */
9971799780
int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */
9971899781
int regPrev = iMem; /* MUST BE LAST (see below) */
99782
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
99783
+ Table *pStat1 = 0;
99784
+#endif
9971999785
9972099786
pParse->nMem = MAX(pParse->nMem, iMem);
9972199787
v = sqlite3GetVdbe(pParse);
9972299788
if( v==0 || NEVER(pTab==0) ){
9972399789
return;
@@ -99738,10 +99804,22 @@
9973899804
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
9973999805
db->aDb[iDb].zDbSName ) ){
9974099806
return;
9974199807
}
9974299808
#endif
99809
+
99810
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
99811
+ if( db->xPreUpdateCallback ){
99812
+ pStat1 = (Table*)sqlite3DbMallocZero(db, sizeof(Table) + 13);
99813
+ if( pStat1==0 ) return;
99814
+ pStat1->zName = (char*)&pStat1[1];
99815
+ memcpy(pStat1->zName, "sqlite_stat1", 13);
99816
+ pStat1->nCol = 3;
99817
+ pStat1->iPKey = -1;
99818
+ sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB);
99819
+ }
99820
+#endif
9974399821
9974499822
/* Establish a read-lock on the table at the shared-cache level.
9974599823
** Open a read-only cursor on the table. Also allocate a cursor number
9974699824
** to use for scanning indexes (iIdxCur). No index cursor is opened at
9974799825
** this time though. */
@@ -99940,10 +100018,13 @@
99940100018
callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
99941100019
assert( "BBB"[0]==SQLITE_AFF_TEXT );
99942100020
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
99943100021
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
99944100022
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
100023
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
100024
+ sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE);
100025
+#endif
99945100026
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
99946100027
99947100028
/* Add the entries to the stat3 or stat4 table. */
99948100029
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
99949100030
{
@@ -107188,11 +107269,11 @@
107188107269
*/
107189107270
if( pTab->pSelect==0 ){
107190107271
u8 p5 = 0;
107191107272
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
107192107273
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
107193
- if( pParse->nested==0 ){
107274
+ if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
107194107275
sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
107195107276
}
107196107277
if( eMode!=ONEPASS_OFF ){
107197107278
sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
107198107279
}
@@ -113418,10 +113499,12 @@
113418113499
int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
113419113500
sqlite3_stmt**,const void**);
113420113501
int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
113421113502
void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
113422113503
void *(*value_pointer)(sqlite3_value*,const char*);
113504
+ int (*vtab_nochange)(sqlite3_context*);
113505
+ int (*value_nochange)(sqlite3_value*);
113423113506
};
113424113507
113425113508
/*
113426113509
** This is the function signature used for all extension entry points. It
113427113510
** is also defined in the file "loadext.c".
@@ -113684,10 +113767,13 @@
113684113767
#define sqlite3_prepare_v3 sqlite3_api->prepare_v3
113685113768
#define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3
113686113769
#define sqlite3_bind_pointer sqlite3_api->bind_pointer
113687113770
#define sqlite3_result_pointer sqlite3_api->result_pointer
113688113771
#define sqlite3_value_pointer sqlite3_api->value_pointer
113772
+/* Version 3.22.0 and later */
113773
+#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
113774
+#define sqlite3_value_nochange sqltie3_api->value_nochange
113689113775
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
113690113776
113691113777
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
113692113778
/* This case when the file really is being compiled as a loadable
113693113779
** extension */
@@ -114118,11 +114204,14 @@
114118114204
/* Version 3.20.0 and later */
114119114205
sqlite3_prepare_v3,
114120114206
sqlite3_prepare16_v3,
114121114207
sqlite3_bind_pointer,
114122114208
sqlite3_result_pointer,
114123
- sqlite3_value_pointer
114209
+ sqlite3_value_pointer,
114210
+ /* Version 3.22.0 and later */
114211
+ sqlite3_vtab_nochange,
114212
+ sqlite3_value_nochange
114124114213
};
114125114214
114126114215
/*
114127114216
** Attempt to load an SQLite extension library contained in the file
114128114217
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -120720,27 +120809,32 @@
120720120809
** VALUES clause. By handling this as a special case, we avoid deep
120721120810
** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
120722120811
** on a VALUES clause.
120723120812
**
120724120813
** Because the Select object originates from a VALUES clause:
120725
-** (1) It has no LIMIT or OFFSET
120814
+** (1) There is no LIMIT or OFFSET or else there is a LIMIT of exactly 1
120726120815
** (2) All terms are UNION ALL
120727120816
** (3) There is no ORDER BY clause
120817
+**
120818
+** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
120819
+** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
120820
+** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
120821
+** Since the limit is exactly 1, we only need to evalutes the left-most VALUES.
120728120822
*/
120729120823
static int multiSelectValues(
120730120824
Parse *pParse, /* Parsing context */
120731120825
Select *p, /* The right-most of SELECTs to be coded */
120732120826
SelectDest *pDest /* What to do with query results */
120733120827
){
120734120828
Select *pPrior;
120829
+ Select *pRightmost = p;
120735120830
int nRow = 1;
120736120831
int rc = 0;
120737120832
assert( p->selFlags & SF_MultiValue );
120738120833
do{
120739120834
assert( p->selFlags & SF_Values );
120740120835
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
120741
- assert( p->pLimit==0 );
120742120836
assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
120743120837
if( p->pPrior==0 ) break;
120744120838
assert( p->pPrior->pNext==p );
120745120839
p = p->pPrior;
120746120840
nRow++;
@@ -120748,11 +120842,11 @@
120748120842
while( p ){
120749120843
pPrior = p->pPrior;
120750120844
p->pPrior = 0;
120751120845
rc = sqlite3Select(pParse, p, pDest);
120752120846
p->pPrior = pPrior;
120753
- if( rc ) break;
120847
+ if( rc || pRightmost->pLimit ) break;
120754120848
p->nSelectRow = nRow;
120755120849
p = p->pNext;
120756120850
}
120757120851
return rc;
120758120852
}
@@ -126750,11 +126844,12 @@
126750126844
/* Populate the argument registers. */
126751126845
for(i=0; i<pTab->nCol; i++){
126752126846
if( aXRef[i]>=0 ){
126753126847
sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
126754126848
}else{
126755
- sqlite3VdbeAddOp4Int(v, OP_VColumn, iCsr, i, regArg+2+i, 1);
126849
+ sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
126850
+ sqlite3VdbeChangeP5(v, 1); /* Enable sqlite3_vtab_nochange() */
126756126851
}
126757126852
}
126758126853
if( HasRowid(pTab) ){
126759126854
sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
126760126855
if( pRowid ){
@@ -126785,10 +126880,15 @@
126785126880
}
126786126881
}else{
126787126882
/* Create a record from the argument register contents and insert it into
126788126883
** the ephemeral table. */
126789126884
sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);
126885
+#ifdef SQLITE_DEBUG
126886
+ /* Signal an assert() within OP_MakeRecord that it is allowed to
126887
+ ** accept no-change records with serial_type 10 */
126888
+ sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG_MAGIC);
126889
+#endif
126790126890
sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);
126791126891
sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);
126792126892
}
126793126893
126794126894
@@ -179419,13 +179519,11 @@
179419179519
return SQLITE_OK;
179420179520
}
179421179521
179422179522
/*
179423179523
** This function queries the database for the names of the columns of table
179424
-** zThis, in schema zDb. It is expected that the table has nCol columns. If
179425
-** not, SQLITE_SCHEMA is returned and none of the output variables are
179426
-** populated.
179524
+** zThis, in schema zDb.
179427179525
**
179428179526
** Otherwise, if they are not NULL, variable *pnCol is set to the number
179429179527
** of columns in the database table and variable *pzTab is set to point to a
179430179528
** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
179431179529
** point to an array of pointers to column names. And *pabPK (again, if not
@@ -179442,13 +179540,11 @@
179442179540
** *pzTab = "tbl1"
179443179541
** *pazCol = {"w", "x", "y", "z"}
179444179542
** *pabPK = {1, 0, 0, 1}
179445179543
**
179446179544
** All returned buffers are part of the same single allocation, which must
179447
-** be freed using sqlite3_free() by the caller. If pazCol was not NULL, then
179448
-** pointer *pazCol should be freed to release all memory. Otherwise, pointer
179449
-** *pabPK. It is illegal for both pazCol and pabPK to be NULL.
179545
+** be freed using sqlite3_free() by the caller
179450179546
*/
179451179547
static int sessionTableInfo(
179452179548
sqlite3 *db, /* Database connection */
179453179549
const char *zDb, /* Name of attached database (e.g. "main") */
179454179550
const char *zThis, /* Table name */
@@ -179469,11 +179565,27 @@
179469179565
u8 *abPK = 0;
179470179566
179471179567
assert( pazCol && pabPK );
179472179568
179473179569
nThis = sqlite3Strlen30(zThis);
179474
- zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
179570
+ if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
179571
+ rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
179572
+ if( rc==SQLITE_OK ){
179573
+ /* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
179574
+ zPragma = sqlite3_mprintf(
179575
+ "SELECT 0, 'tbl', '', 0, '', 1 UNION ALL "
179576
+ "SELECT 1, 'idx', '', 0, '', 2 UNION ALL "
179577
+ "SELECT 2, 'stat', '', 0, '', 0"
179578
+ );
179579
+ }else if( rc==SQLITE_ERROR ){
179580
+ zPragma = sqlite3_mprintf("");
179581
+ }else{
179582
+ return rc;
179583
+ }
179584
+ }else{
179585
+ zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
179586
+ }
179475179587
if( !zPragma ) return SQLITE_NOMEM;
179476179588
179477179589
rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
179478179590
sqlite3_free(zPragma);
179479179591
if( rc!=SQLITE_OK ) return rc;
@@ -180026,11 +180138,10 @@
180026180138
if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
180027180139
if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
180028180140
if( abPK[i] ) bHasPk = 1;
180029180141
}
180030180142
}
180031
-
180032180143
}
180033180144
sqlite3_free((char*)azCol);
180034180145
if( bMismatch ){
180035180146
*pzErrMsg = sqlite3_mprintf("table schemas do not match");
180036180147
rc = SQLITE_SCHEMA;
@@ -202988,11 +203099,11 @@
202988203099
int nArg, /* Number of args */
202989203100
sqlite3_value **apUnused /* Function arguments */
202990203101
){
202991203102
assert( nArg==0 );
202992203103
UNUSED_PARAM2(nArg, apUnused);
202993
- sqlite3_result_text(pCtx, "fts5: 2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7148c", -1, SQLITE_TRANSIENT);
203104
+ sqlite3_result_text(pCtx, "fts5: 2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4356b", -1, SQLITE_TRANSIENT);
202994203105
}
202995203106
202996203107
static int fts5Init(sqlite3 *db){
202997203108
static const sqlite3_module fts5Mod = {
202998203109
/* iVersion */ 2,
@@ -207256,12 +207367,12 @@
207256207367
}
207257207368
#endif /* SQLITE_CORE */
207258207369
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207259207370
207260207371
/************** End of stmt.c ************************************************/
207261
-#if __LINE__!=207261
207372
+#if __LINE__!=207372
207262207373
#undef SQLITE_SOURCE_ID
207263
-#define SQLITE_SOURCE_ID "2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7alt2"
207374
+#define SQLITE_SOURCE_ID "2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4alt2"
207264207375
#endif
207265207376
/* Return the source-id for this library */
207266207377
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207267207378
/************************** End of sqlite3.c ******************************/
207268207379
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7148c"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -5821,10 +5821,13 @@
5821 ** TEXT in bytes
5822 ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
5823 ** datatype of the value
5824 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
5825 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
 
 
 
5826 ** </table></blockquote>
5827 **
5828 ** <b>Details:</b>
5829 **
5830 ** These routines extract type, size, and content information from
@@ -5868,10 +5871,23 @@
5868 ** made to convert the value to an integer or floating point. If
5869 ** such a conversion is possible without loss of information (in other
5870 ** words, if the value is a string that looks like a number)
5871 ** then the conversion is performed. Otherwise no conversion occurs.
5872 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
 
 
 
 
 
 
 
 
 
 
 
 
 
5873 **
5874 ** Please pay particular attention to the fact that the pointer returned
5875 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5876 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5877 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5891,10 +5907,11 @@
5891 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
5892 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
5893 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
5894 SQLITE_API int sqlite3_value_type(sqlite3_value*);
5895 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
 
5896
5897 /*
5898 ** CAPI3REF: Finding The Subtype Of SQL Values
5899 ** METHOD: sqlite3_value
5900 **
@@ -9328,10 +9345,17 @@
9328 ** method of a [virtual table], then it returns true if and only if the
9329 ** column is being fetched as part of an UPDATE operation during which the
9330 ** column value will not change. Applications might use this to substitute
9331 ** a lighter-weight value to return that the corresponding [xUpdate] method
9332 ** understands as a "no-change" value.
 
 
 
 
 
 
 
9333 */
9334 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9335
9336 /*
9337 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
@@ -13742,10 +13766,11 @@
13742 #define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
13743 #define P4_REAL (-13) /* P4 is a 64-bit floating point value */
13744 #define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
13745 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
13746 #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
 
13747
13748 /* Error message codes for OP_Halt */
13749 #define P5_ConstraintNotNull 1
13750 #define P5_ConstraintUnique 2
13751 #define P5_ConstraintCheck 3
@@ -16945,10 +16970,11 @@
16945 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
16946 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
16947 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
16948 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
16949 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
 
16950
16951 /*
16952 * Each trigger present in the database schema is stored as an instance of
16953 * struct Trigger.
16954 *
@@ -18801,10 +18827,12 @@
18801 ** representations of the value stored in the Mem struct.
18802 **
18803 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
18804 ** For a pointer type created using sqlite3_bind_pointer() or
18805 ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
 
 
18806 **
18807 ** If the MEM_Str flag is set then Mem.z points at a string representation.
18808 ** Usually this is encoded in the same unicode encoding as the main
18809 ** database (see below for exceptions). If the MEM_Term flag is also
18810 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
@@ -34616,11 +34644,11 @@
34616
34617 /* Set defaults for non-supported filesystems */
34618 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
34619 pFile->deviceCharacteristics = 0;
34620 if( fstatvfs(pFile->h, &fsInfo) == -1 ) {
34621 return pFile->sectorSize;
34622 }
34623
34624 if( !strcmp(fsInfo.f_basetype, "tmp") ) {
34625 pFile->sectorSize = fsInfo.f_bsize;
34626 pFile->deviceCharacteristics =
@@ -71150,11 +71178,11 @@
71150 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
71151
71152 if( p->flags & MEM_Null ){
71153 /* Cannot be both MEM_Null and some other type */
71154 assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob
71155 |MEM_RowSet|MEM_Frame|MEM_Agg|MEM_Zero))==0 );
71156
71157 /* If MEM_Null is set, then either the value is a pure NULL (the usual
71158 ** case) or it is a pointer set using sqlite3_bind_pointer() or
71159 ** sqlite3_result_pointer(). If a pointer, then MEM_Term must also be
71160 ** set.
@@ -73743,10 +73771,11 @@
73743 break;
73744 }
73745 case P4_REAL:
73746 case P4_INT64:
73747 case P4_DYNAMIC:
 
73748 case P4_INTARRAY: {
73749 sqlite3DbFree(db, p4);
73750 break;
73751 }
73752 case P4_KEYINFO: {
@@ -74284,10 +74313,11 @@
74284 }
74285 case P4_SUBPROGRAM: {
74286 sqlite3XPrintf(&x, "program");
74287 break;
74288 }
 
74289 case P4_ADVANCE: {
74290 zTemp[0] = 0;
74291 break;
74292 }
74293 case P4_TABLE: {
@@ -76329,11 +76359,17 @@
76329 const unsigned char *buf, /* Buffer to deserialize from */
76330 u32 serial_type, /* Serial type to deserialize */
76331 Mem *pMem /* Memory cell to write value into */
76332 ){
76333 switch( serial_type ){
76334 case 10: /* Reserved for future use */
 
 
 
 
 
 
76335 case 11: /* Reserved for future use */
76336 case 0: { /* Null */
76337 /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
76338 pMem->flags = MEM_Null;
76339 break;
@@ -77881,10 +77917,15 @@
77881 SQLITE_INTEGER, /* 0x1e */
77882 SQLITE_NULL, /* 0x1f */
77883 };
77884 return aType[pVal->flags&MEM_AffMask];
77885 }
 
 
 
 
 
77886
77887 /* Make a copy of an sqlite3_value object
77888 */
77889 SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
77890 sqlite3_value *pNew;
@@ -78375,11 +78416,11 @@
78375 ** performance by substituting a NULL result, or some other light-weight
78376 ** value, as a signal to the xUpdate routine that the column is unchanged.
78377 */
78378 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
78379 assert( p );
78380 return p->bVtabNoChng;
78381 }
78382
78383 /*
78384 ** Return the current time for a statement. If the current time
78385 ** is requested more than once within the same run of a single prepared
@@ -80259,11 +80300,11 @@
80259 */
80260 static void memTracePrint(Mem *p){
80261 if( p->flags & MEM_Undefined ){
80262 printf(" undefined");
80263 }else if( p->flags & MEM_Null ){
80264 printf(" NULL");
80265 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
80266 printf(" si:%lld", p->u.i);
80267 }else if( p->flags & MEM_Int ){
80268 printf(" i:%lld", p->u.i);
80269 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -82676,13 +82717,22 @@
82676 ** out how much space is required for the new record.
82677 */
82678 pRec = pLast;
82679 do{
82680 assert( memIsValid(pRec) );
82681 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format, &len);
82682 if( pRec->flags & MEM_Zero ){
82683 if( nData ){
 
 
 
 
 
 
 
 
 
82684 if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem;
82685 }else{
82686 nZero += pRec->u.nZero;
82687 len -= pRec->u.nZero;
82688 }
@@ -82689,10 +82739,11 @@
82689 }
82690 nData += len;
82691 testcase( serial_type==127 );
82692 testcase( serial_type==128 );
82693 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
 
82694 if( pRec==pData0 ) break;
82695 pRec--;
82696 }while(1);
82697
82698 /* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
@@ -84299,14 +84350,12 @@
84299 Mem *pKey; /* MEM cell holding key for the record */
84300 VdbeCursor *pC; /* Cursor to table into which insert is written */
84301 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
84302 const char *zDb; /* database name - used by the update hook */
84303 Table *pTab; /* Table structure - used by update and pre-update hooks */
84304 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
84305 BtreePayload x; /* Payload to be inserted */
84306
84307 op = 0;
84308 pData = &aMem[pOp->p2];
84309 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
84310 assert( memIsValid(pData) );
84311 pC = p->apCsr[pOp->p1];
84312 assert( pC!=0 );
@@ -84330,23 +84379,25 @@
84330 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
84331 assert( pC->iDb>=0 );
84332 zDb = db->aDb[pC->iDb].zDbSName;
84333 pTab = pOp->p4.pTab;
84334 assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
84335 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
84336 }else{
84337 pTab = 0; /* Not needed. Silence a compiler warning. */
84338 zDb = 0; /* Not needed. Silence a compiler warning. */
84339 }
84340
84341 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
84342 /* Invoke the pre-update hook, if any */
84343 if( db->xPreUpdateCallback
84344 && pOp->p4type==P4_TABLE
84345 && !(pOp->p5 & OPFLAG_ISUPDATE)
84346 ){
84347 sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
 
 
 
84348 }
84349 if( pOp->p5 & OPFLAG_ISNOOP ) break;
84350 #endif
84351
84352 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
@@ -84367,12 +84418,16 @@
84367 pC->deferredMoveto = 0;
84368 pC->cacheStatus = CACHE_STALE;
84369
84370 /* Invoke the update-hook if required. */
84371 if( rc ) goto abort_due_to_error;
84372 if( db->xUpdateCallback && op ){
84373 db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, x.nKey);
 
 
 
 
84374 }
84375 break;
84376 }
84377
84378 /* Opcode: Delete P1 P2 P3 P4 P5
@@ -86577,19 +86632,19 @@
86577 break;
86578 }
86579 #endif /* SQLITE_OMIT_VIRTUALTABLE */
86580
86581 #ifndef SQLITE_OMIT_VIRTUALTABLE
86582 /* Opcode: VColumn P1 P2 P3 P4 *
86583 ** Synopsis: r[P3]=vcolumn(P2)
86584 **
86585 ** Store in register P3 the value of the P2-th column of
86586 ** the current row of the virtual-table of cursor P1.
86587 **
86588 ** If the VColumn opcode is being used to fetch the value of
86589 ** an unchanging column during an UPDATE operation, then the P4
86590 ** value is 1. Otherwise, P4 is 0. The P4 value is returned
86591 ** by sqlite3_vtab_nochange() routine can can be used
86592 ** by virtual table implementations to return special "no-change"
86593 ** marks which can be more efficient, depending on the virtual table.
86594 */
86595 case OP_VColumn: {
@@ -86610,12 +86665,17 @@
86610 pVtab = pCur->uc.pVCur->pVtab;
86611 pModule = pVtab->pModule;
86612 assert( pModule->xColumn );
86613 memset(&sContext, 0, sizeof(sContext));
86614 sContext.pOut = pDest;
86615 sContext.bVtabNoChng = pOp->p4.i!=0;
86616 MemSetTypeFlag(pDest, MEM_Null);
 
 
 
 
 
86617 rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2);
86618 sqlite3VtabImportErrmsg(p, pVtab);
86619 if( sContext.isError ){
86620 rc = sContext.isError;
86621 }
@@ -95336,11 +95396,10 @@
95336 pSel->pLimit->pLeft = pLimit;
95337 }else{
95338 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
95339 }
95340 pSel->iLimit = 0;
95341 pSel->selFlags &= ~SF_MultiValue;
95342 if( sqlite3Select(pParse, pSel, &dest) ){
95343 return 0;
95344 }
95345 rReg = dest.iSDParm;
95346 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -98950,10 +99009,14 @@
98950 if( zWhere ){
98951 sqlite3NestedParse(pParse,
98952 "DELETE FROM %Q.%s WHERE %s=%Q",
98953 pDb->zDbSName, zTab, zWhereType, zWhere
98954 );
 
 
 
 
98955 }else{
98956 /* The sqlite_stat[134] table already exists. Delete all rows. */
98957 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
98958 }
98959 }
@@ -99714,10 +99777,13 @@
99714 int regTemp = iMem++; /* Temporary use register */
99715 int regTabname = iMem++; /* Register containing table name */
99716 int regIdxname = iMem++; /* Register containing index name */
99717 int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */
99718 int regPrev = iMem; /* MUST BE LAST (see below) */
 
 
 
99719
99720 pParse->nMem = MAX(pParse->nMem, iMem);
99721 v = sqlite3GetVdbe(pParse);
99722 if( v==0 || NEVER(pTab==0) ){
99723 return;
@@ -99738,10 +99804,22 @@
99738 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
99739 db->aDb[iDb].zDbSName ) ){
99740 return;
99741 }
99742 #endif
 
 
 
 
 
 
 
 
 
 
 
 
99743
99744 /* Establish a read-lock on the table at the shared-cache level.
99745 ** Open a read-only cursor on the table. Also allocate a cursor number
99746 ** to use for scanning indexes (iIdxCur). No index cursor is opened at
99747 ** this time though. */
@@ -99940,10 +100018,13 @@
99940 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
99941 assert( "BBB"[0]==SQLITE_AFF_TEXT );
99942 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
99943 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
99944 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
 
 
 
99945 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
99946
99947 /* Add the entries to the stat3 or stat4 table. */
99948 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
99949 {
@@ -107188,11 +107269,11 @@
107188 */
107189 if( pTab->pSelect==0 ){
107190 u8 p5 = 0;
107191 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
107192 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
107193 if( pParse->nested==0 ){
107194 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
107195 }
107196 if( eMode!=ONEPASS_OFF ){
107197 sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
107198 }
@@ -113418,10 +113499,12 @@
113418 int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
113419 sqlite3_stmt**,const void**);
113420 int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
113421 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
113422 void *(*value_pointer)(sqlite3_value*,const char*);
 
 
113423 };
113424
113425 /*
113426 ** This is the function signature used for all extension entry points. It
113427 ** is also defined in the file "loadext.c".
@@ -113684,10 +113767,13 @@
113684 #define sqlite3_prepare_v3 sqlite3_api->prepare_v3
113685 #define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3
113686 #define sqlite3_bind_pointer sqlite3_api->bind_pointer
113687 #define sqlite3_result_pointer sqlite3_api->result_pointer
113688 #define sqlite3_value_pointer sqlite3_api->value_pointer
 
 
 
113689 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
113690
113691 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
113692 /* This case when the file really is being compiled as a loadable
113693 ** extension */
@@ -114118,11 +114204,14 @@
114118 /* Version 3.20.0 and later */
114119 sqlite3_prepare_v3,
114120 sqlite3_prepare16_v3,
114121 sqlite3_bind_pointer,
114122 sqlite3_result_pointer,
114123 sqlite3_value_pointer
 
 
 
114124 };
114125
114126 /*
114127 ** Attempt to load an SQLite extension library contained in the file
114128 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -120720,27 +120809,32 @@
120720 ** VALUES clause. By handling this as a special case, we avoid deep
120721 ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
120722 ** on a VALUES clause.
120723 **
120724 ** Because the Select object originates from a VALUES clause:
120725 ** (1) It has no LIMIT or OFFSET
120726 ** (2) All terms are UNION ALL
120727 ** (3) There is no ORDER BY clause
 
 
 
 
 
120728 */
120729 static int multiSelectValues(
120730 Parse *pParse, /* Parsing context */
120731 Select *p, /* The right-most of SELECTs to be coded */
120732 SelectDest *pDest /* What to do with query results */
120733 ){
120734 Select *pPrior;
 
120735 int nRow = 1;
120736 int rc = 0;
120737 assert( p->selFlags & SF_MultiValue );
120738 do{
120739 assert( p->selFlags & SF_Values );
120740 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
120741 assert( p->pLimit==0 );
120742 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
120743 if( p->pPrior==0 ) break;
120744 assert( p->pPrior->pNext==p );
120745 p = p->pPrior;
120746 nRow++;
@@ -120748,11 +120842,11 @@
120748 while( p ){
120749 pPrior = p->pPrior;
120750 p->pPrior = 0;
120751 rc = sqlite3Select(pParse, p, pDest);
120752 p->pPrior = pPrior;
120753 if( rc ) break;
120754 p->nSelectRow = nRow;
120755 p = p->pNext;
120756 }
120757 return rc;
120758 }
@@ -126750,11 +126844,12 @@
126750 /* Populate the argument registers. */
126751 for(i=0; i<pTab->nCol; i++){
126752 if( aXRef[i]>=0 ){
126753 sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
126754 }else{
126755 sqlite3VdbeAddOp4Int(v, OP_VColumn, iCsr, i, regArg+2+i, 1);
 
126756 }
126757 }
126758 if( HasRowid(pTab) ){
126759 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
126760 if( pRowid ){
@@ -126785,10 +126880,15 @@
126785 }
126786 }else{
126787 /* Create a record from the argument register contents and insert it into
126788 ** the ephemeral table. */
126789 sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);
 
 
 
 
 
126790 sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);
126791 sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);
126792 }
126793
126794
@@ -179419,13 +179519,11 @@
179419 return SQLITE_OK;
179420 }
179421
179422 /*
179423 ** This function queries the database for the names of the columns of table
179424 ** zThis, in schema zDb. It is expected that the table has nCol columns. If
179425 ** not, SQLITE_SCHEMA is returned and none of the output variables are
179426 ** populated.
179427 **
179428 ** Otherwise, if they are not NULL, variable *pnCol is set to the number
179429 ** of columns in the database table and variable *pzTab is set to point to a
179430 ** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
179431 ** point to an array of pointers to column names. And *pabPK (again, if not
@@ -179442,13 +179540,11 @@
179442 ** *pzTab = "tbl1"
179443 ** *pazCol = {"w", "x", "y", "z"}
179444 ** *pabPK = {1, 0, 0, 1}
179445 **
179446 ** All returned buffers are part of the same single allocation, which must
179447 ** be freed using sqlite3_free() by the caller. If pazCol was not NULL, then
179448 ** pointer *pazCol should be freed to release all memory. Otherwise, pointer
179449 ** *pabPK. It is illegal for both pazCol and pabPK to be NULL.
179450 */
179451 static int sessionTableInfo(
179452 sqlite3 *db, /* Database connection */
179453 const char *zDb, /* Name of attached database (e.g. "main") */
179454 const char *zThis, /* Table name */
@@ -179469,11 +179565,27 @@
179469 u8 *abPK = 0;
179470
179471 assert( pazCol && pabPK );
179472
179473 nThis = sqlite3Strlen30(zThis);
179474 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179475 if( !zPragma ) return SQLITE_NOMEM;
179476
179477 rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
179478 sqlite3_free(zPragma);
179479 if( rc!=SQLITE_OK ) return rc;
@@ -180026,11 +180138,10 @@
180026 if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
180027 if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
180028 if( abPK[i] ) bHasPk = 1;
180029 }
180030 }
180031
180032 }
180033 sqlite3_free((char*)azCol);
180034 if( bMismatch ){
180035 *pzErrMsg = sqlite3_mprintf("table schemas do not match");
180036 rc = SQLITE_SCHEMA;
@@ -202988,11 +203099,11 @@
202988 int nArg, /* Number of args */
202989 sqlite3_value **apUnused /* Function arguments */
202990 ){
202991 assert( nArg==0 );
202992 UNUSED_PARAM2(nArg, apUnused);
202993 sqlite3_result_text(pCtx, "fts5: 2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7148c", -1, SQLITE_TRANSIENT);
202994 }
202995
202996 static int fts5Init(sqlite3 *db){
202997 static const sqlite3_module fts5Mod = {
202998 /* iVersion */ 2,
@@ -207256,12 +207367,12 @@
207256 }
207257 #endif /* SQLITE_CORE */
207258 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207259
207260 /************** End of stmt.c ************************************************/
207261 #if __LINE__!=207261
207262 #undef SQLITE_SOURCE_ID
207263 #define SQLITE_SOURCE_ID "2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7alt2"
207264 #endif
207265 /* Return the source-id for this library */
207266 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207267 /************************** End of sqlite3.c ******************************/
207268
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4356b"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -5821,10 +5821,13 @@
5821 ** TEXT in bytes
5822 ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
5823 ** datatype of the value
5824 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
5825 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
5826 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
5827 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
5828 ** against a virtual table.
5829 ** </table></blockquote>
5830 **
5831 ** <b>Details:</b>
5832 **
5833 ** These routines extract type, size, and content information from
@@ -5868,10 +5871,23 @@
5871 ** made to convert the value to an integer or floating point. If
5872 ** such a conversion is possible without loss of information (in other
5873 ** words, if the value is a string that looks like a number)
5874 ** then the conversion is performed. Otherwise no conversion occurs.
5875 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5876 **
5877 ** ^Within the [xUpdate] method of a [virtual table], the
5878 ** sqlite3_value_nochange(X) interface returns true if and only if
5879 ** the column corresponding to X is unchanged by the UPDATE operation
5880 ** that the xUpdate method call was invoked to implement and if
5881 ** and the prior [xColumn] method call that was invoked to extracted
5882 ** the value for that column returned without setting a result (probably
5883 ** because it queried [sqlite3_vtab_nochange()] and found that the column
5884 ** was unchanging). ^Within an [xUpdate] method, any value for which
5885 ** sqlite3_value_nochange(X) is true will in all other respects appear
5886 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
5887 ** than within an [xUpdate] method call for an UPDATE statement, then
5888 ** the return value is arbitrary and meaningless.
5889 **
5890 ** Please pay particular attention to the fact that the pointer returned
5891 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5892 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5893 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5891,10 +5907,11 @@
5907 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
5908 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
5909 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
5910 SQLITE_API int sqlite3_value_type(sqlite3_value*);
5911 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5912 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5913
5914 /*
5915 ** CAPI3REF: Finding The Subtype Of SQL Values
5916 ** METHOD: sqlite3_value
5917 **
@@ -9328,10 +9345,17 @@
9345 ** method of a [virtual table], then it returns true if and only if the
9346 ** column is being fetched as part of an UPDATE operation during which the
9347 ** column value will not change. Applications might use this to substitute
9348 ** a lighter-weight value to return that the corresponding [xUpdate] method
9349 ** understands as a "no-change" value.
9350 **
9351 ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
9352 ** the column is not changed by the UPDATE statement, they the xColumn
9353 ** method can optionally return without setting a result, without calling
9354 ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
9355 ** In that case, [sqlite3_value_nochange(X)] will return true for the
9356 ** same column in the [xUpdate] method.
9357 */
9358 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9359
9360 /*
9361 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
@@ -13742,10 +13766,11 @@
13766 #define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
13767 #define P4_REAL (-13) /* P4 is a 64-bit floating point value */
13768 #define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
13769 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
13770 #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
13771 #define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */
13772
13773 /* Error message codes for OP_Halt */
13774 #define P5_ConstraintNotNull 1
13775 #define P5_ConstraintUnique 2
13776 #define P5_ConstraintCheck 3
@@ -16945,10 +16970,11 @@
16970 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
16971 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
16972 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
16973 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
16974 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
16975 #define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */
16976
16977 /*
16978 * Each trigger present in the database schema is stored as an instance of
16979 * struct Trigger.
16980 *
@@ -18801,10 +18827,12 @@
18827 ** representations of the value stored in the Mem struct.
18828 **
18829 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
18830 ** For a pointer type created using sqlite3_bind_pointer() or
18831 ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
18832 ** If both MEM_Null and MEM_Zero are set, that means that the value is
18833 ** an unchanging column value from VColumn.
18834 **
18835 ** If the MEM_Str flag is set then Mem.z points at a string representation.
18836 ** Usually this is encoded in the same unicode encoding as the main
18837 ** database (see below for exceptions). If the MEM_Term flag is also
18838 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
@@ -34616,11 +34644,11 @@
34644
34645 /* Set defaults for non-supported filesystems */
34646 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
34647 pFile->deviceCharacteristics = 0;
34648 if( fstatvfs(pFile->h, &fsInfo) == -1 ) {
34649 return;
34650 }
34651
34652 if( !strcmp(fsInfo.f_basetype, "tmp") ) {
34653 pFile->sectorSize = fsInfo.f_bsize;
34654 pFile->deviceCharacteristics =
@@ -71150,11 +71178,11 @@
71178 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
71179
71180 if( p->flags & MEM_Null ){
71181 /* Cannot be both MEM_Null and some other type */
71182 assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob
71183 |MEM_RowSet|MEM_Frame|MEM_Agg))==0 );
71184
71185 /* If MEM_Null is set, then either the value is a pure NULL (the usual
71186 ** case) or it is a pointer set using sqlite3_bind_pointer() or
71187 ** sqlite3_result_pointer(). If a pointer, then MEM_Term must also be
71188 ** set.
@@ -73743,10 +73771,11 @@
73771 break;
73772 }
73773 case P4_REAL:
73774 case P4_INT64:
73775 case P4_DYNAMIC:
73776 case P4_DYNBLOB:
73777 case P4_INTARRAY: {
73778 sqlite3DbFree(db, p4);
73779 break;
73780 }
73781 case P4_KEYINFO: {
@@ -74284,10 +74313,11 @@
74313 }
74314 case P4_SUBPROGRAM: {
74315 sqlite3XPrintf(&x, "program");
74316 break;
74317 }
74318 case P4_DYNBLOB:
74319 case P4_ADVANCE: {
74320 zTemp[0] = 0;
74321 break;
74322 }
74323 case P4_TABLE: {
@@ -76329,11 +76359,17 @@
76359 const unsigned char *buf, /* Buffer to deserialize from */
76360 u32 serial_type, /* Serial type to deserialize */
76361 Mem *pMem /* Memory cell to write value into */
76362 ){
76363 switch( serial_type ){
76364 case 10: { /* Internal use only: NULL with virtual table
76365 ** UPDATE no-change flag set */
76366 pMem->flags = MEM_Null|MEM_Zero;
76367 pMem->n = 0;
76368 pMem->u.nZero = 0;
76369 break;
76370 }
76371 case 11: /* Reserved for future use */
76372 case 0: { /* Null */
76373 /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
76374 pMem->flags = MEM_Null;
76375 break;
@@ -77881,10 +77917,15 @@
77917 SQLITE_INTEGER, /* 0x1e */
77918 SQLITE_NULL, /* 0x1f */
77919 };
77920 return aType[pVal->flags&MEM_AffMask];
77921 }
77922
77923 /* Return true if a parameter to xUpdate represents an unchanged column */
77924 SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){
77925 return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
77926 }
77927
77928 /* Make a copy of an sqlite3_value object
77929 */
77930 SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
77931 sqlite3_value *pNew;
@@ -78375,11 +78416,11 @@
78416 ** performance by substituting a NULL result, or some other light-weight
78417 ** value, as a signal to the xUpdate routine that the column is unchanged.
78418 */
78419 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
78420 assert( p );
78421 return sqlite3_value_nochange(p->pOut);
78422 }
78423
78424 /*
78425 ** Return the current time for a statement. If the current time
78426 ** is requested more than once within the same run of a single prepared
@@ -80259,11 +80300,11 @@
80300 */
80301 static void memTracePrint(Mem *p){
80302 if( p->flags & MEM_Undefined ){
80303 printf(" undefined");
80304 }else if( p->flags & MEM_Null ){
80305 printf(p->flags & MEM_Zero ? " NULL-nochng" : " NULL");
80306 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
80307 printf(" si:%lld", p->u.i);
80308 }else if( p->flags & MEM_Int ){
80309 printf(" i:%lld", p->u.i);
80310 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -82676,13 +82717,22 @@
82717 ** out how much space is required for the new record.
82718 */
82719 pRec = pLast;
82720 do{
82721 assert( memIsValid(pRec) );
82722 serial_type = sqlite3VdbeSerialType(pRec, file_format, &len);
82723 if( pRec->flags & MEM_Zero ){
82724 if( serial_type==0 ){
82725 /* Values with MEM_Null and MEM_Zero are created by xColumn virtual
82726 ** table methods that never invoke sqlite3_result_xxxxx() while
82727 ** computing an unchanging column value in an UPDATE statement.
82728 ** Give such values a special internal-use-only serial-type of 10
82729 ** so that they can be passed through to xUpdate and have
82730 ** a true sqlite3_value_nochange(). */
82731 assert( pOp->p5==OPFLAG_NOCHNG_MAGIC || CORRUPT_DB );
82732 serial_type = 10;
82733 }else if( nData ){
82734 if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem;
82735 }else{
82736 nZero += pRec->u.nZero;
82737 len -= pRec->u.nZero;
82738 }
@@ -82689,10 +82739,11 @@
82739 }
82740 nData += len;
82741 testcase( serial_type==127 );
82742 testcase( serial_type==128 );
82743 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
82744 pRec->uTemp = serial_type;
82745 if( pRec==pData0 ) break;
82746 pRec--;
82747 }while(1);
82748
82749 /* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
@@ -84299,14 +84350,12 @@
84350 Mem *pKey; /* MEM cell holding key for the record */
84351 VdbeCursor *pC; /* Cursor to table into which insert is written */
84352 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
84353 const char *zDb; /* database name - used by the update hook */
84354 Table *pTab; /* Table structure - used by update and pre-update hooks */
 
84355 BtreePayload x; /* Payload to be inserted */
84356
 
84357 pData = &aMem[pOp->p2];
84358 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
84359 assert( memIsValid(pData) );
84360 pC = p->apCsr[pOp->p1];
84361 assert( pC!=0 );
@@ -84330,23 +84379,25 @@
84379 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
84380 assert( pC->iDb>=0 );
84381 zDb = db->aDb[pC->iDb].zDbSName;
84382 pTab = pOp->p4.pTab;
84383 assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
 
84384 }else{
84385 pTab = 0;
84386 zDb = 0; /* Not needed. Silence a compiler warning. */
84387 }
84388
84389 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
84390 /* Invoke the pre-update hook, if any */
84391 if( pTab ){
84392 if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){
84393 sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2);
84394 }
84395 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
84396 /* Prevent post-update hook from running in cases when it should not */
84397 pTab = 0;
84398 }
84399 }
84400 if( pOp->p5 & OPFLAG_ISNOOP ) break;
84401 #endif
84402
84403 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
@@ -84367,12 +84418,16 @@
84418 pC->deferredMoveto = 0;
84419 pC->cacheStatus = CACHE_STALE;
84420
84421 /* Invoke the update-hook if required. */
84422 if( rc ) goto abort_due_to_error;
84423 if( pTab ){
84424 assert( db->xUpdateCallback!=0 );
84425 assert( pTab->aCol!=0 );
84426 db->xUpdateCallback(db->pUpdateArg,
84427 (pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT,
84428 zDb, pTab->zName, x.nKey);
84429 }
84430 break;
84431 }
84432
84433 /* Opcode: Delete P1 P2 P3 P4 P5
@@ -86577,19 +86632,19 @@
86632 break;
86633 }
86634 #endif /* SQLITE_OMIT_VIRTUALTABLE */
86635
86636 #ifndef SQLITE_OMIT_VIRTUALTABLE
86637 /* Opcode: VColumn P1 P2 P3 * P5
86638 ** Synopsis: r[P3]=vcolumn(P2)
86639 **
86640 ** Store in register P3 the value of the P2-th column of
86641 ** the current row of the virtual-table of cursor P1.
86642 **
86643 ** If the VColumn opcode is being used to fetch the value of
86644 ** an unchanging column during an UPDATE operation, then the P5
86645 ** value is 1. Otherwise, P5 is 0. The P5 value is returned
86646 ** by sqlite3_vtab_nochange() routine can can be used
86647 ** by virtual table implementations to return special "no-change"
86648 ** marks which can be more efficient, depending on the virtual table.
86649 */
86650 case OP_VColumn: {
@@ -86610,12 +86665,17 @@
86665 pVtab = pCur->uc.pVCur->pVtab;
86666 pModule = pVtab->pModule;
86667 assert( pModule->xColumn );
86668 memset(&sContext, 0, sizeof(sContext));
86669 sContext.pOut = pDest;
86670 if( pOp->p5 ){
86671 sqlite3VdbeMemSetNull(pDest);
86672 pDest->flags = MEM_Null|MEM_Zero;
86673 pDest->u.nZero = 0;
86674 }else{
86675 MemSetTypeFlag(pDest, MEM_Null);
86676 }
86677 rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2);
86678 sqlite3VtabImportErrmsg(p, pVtab);
86679 if( sContext.isError ){
86680 rc = sContext.isError;
86681 }
@@ -95336,11 +95396,10 @@
95396 pSel->pLimit->pLeft = pLimit;
95397 }else{
95398 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
95399 }
95400 pSel->iLimit = 0;
 
95401 if( sqlite3Select(pParse, pSel, &dest) ){
95402 return 0;
95403 }
95404 rReg = dest.iSDParm;
95405 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -98950,10 +99009,14 @@
99009 if( zWhere ){
99010 sqlite3NestedParse(pParse,
99011 "DELETE FROM %Q.%s WHERE %s=%Q",
99012 pDb->zDbSName, zTab, zWhereType, zWhere
99013 );
99014 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
99015 }else if( db->xPreUpdateCallback ){
99016 sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
99017 #endif
99018 }else{
99019 /* The sqlite_stat[134] table already exists. Delete all rows. */
99020 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
99021 }
99022 }
@@ -99714,10 +99777,13 @@
99777 int regTemp = iMem++; /* Temporary use register */
99778 int regTabname = iMem++; /* Register containing table name */
99779 int regIdxname = iMem++; /* Register containing index name */
99780 int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */
99781 int regPrev = iMem; /* MUST BE LAST (see below) */
99782 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
99783 Table *pStat1 = 0;
99784 #endif
99785
99786 pParse->nMem = MAX(pParse->nMem, iMem);
99787 v = sqlite3GetVdbe(pParse);
99788 if( v==0 || NEVER(pTab==0) ){
99789 return;
@@ -99738,10 +99804,22 @@
99804 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
99805 db->aDb[iDb].zDbSName ) ){
99806 return;
99807 }
99808 #endif
99809
99810 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
99811 if( db->xPreUpdateCallback ){
99812 pStat1 = (Table*)sqlite3DbMallocZero(db, sizeof(Table) + 13);
99813 if( pStat1==0 ) return;
99814 pStat1->zName = (char*)&pStat1[1];
99815 memcpy(pStat1->zName, "sqlite_stat1", 13);
99816 pStat1->nCol = 3;
99817 pStat1->iPKey = -1;
99818 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB);
99819 }
99820 #endif
99821
99822 /* Establish a read-lock on the table at the shared-cache level.
99823 ** Open a read-only cursor on the table. Also allocate a cursor number
99824 ** to use for scanning indexes (iIdxCur). No index cursor is opened at
99825 ** this time though. */
@@ -99940,10 +100018,13 @@
100018 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
100019 assert( "BBB"[0]==SQLITE_AFF_TEXT );
100020 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
100021 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
100022 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
100023 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
100024 sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE);
100025 #endif
100026 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
100027
100028 /* Add the entries to the stat3 or stat4 table. */
100029 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
100030 {
@@ -107188,11 +107269,11 @@
107269 */
107270 if( pTab->pSelect==0 ){
107271 u8 p5 = 0;
107272 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
107273 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
107274 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
107275 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
107276 }
107277 if( eMode!=ONEPASS_OFF ){
107278 sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
107279 }
@@ -113418,10 +113499,12 @@
113499 int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
113500 sqlite3_stmt**,const void**);
113501 int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
113502 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
113503 void *(*value_pointer)(sqlite3_value*,const char*);
113504 int (*vtab_nochange)(sqlite3_context*);
113505 int (*value_nochange)(sqlite3_value*);
113506 };
113507
113508 /*
113509 ** This is the function signature used for all extension entry points. It
113510 ** is also defined in the file "loadext.c".
@@ -113684,10 +113767,13 @@
113767 #define sqlite3_prepare_v3 sqlite3_api->prepare_v3
113768 #define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3
113769 #define sqlite3_bind_pointer sqlite3_api->bind_pointer
113770 #define sqlite3_result_pointer sqlite3_api->result_pointer
113771 #define sqlite3_value_pointer sqlite3_api->value_pointer
113772 /* Version 3.22.0 and later */
113773 #define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
113774 #define sqlite3_value_nochange sqltie3_api->value_nochange
113775 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
113776
113777 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
113778 /* This case when the file really is being compiled as a loadable
113779 ** extension */
@@ -114118,11 +114204,14 @@
114204 /* Version 3.20.0 and later */
114205 sqlite3_prepare_v3,
114206 sqlite3_prepare16_v3,
114207 sqlite3_bind_pointer,
114208 sqlite3_result_pointer,
114209 sqlite3_value_pointer,
114210 /* Version 3.22.0 and later */
114211 sqlite3_vtab_nochange,
114212 sqlite3_value_nochange
114213 };
114214
114215 /*
114216 ** Attempt to load an SQLite extension library contained in the file
114217 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -120720,27 +120809,32 @@
120809 ** VALUES clause. By handling this as a special case, we avoid deep
120810 ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
120811 ** on a VALUES clause.
120812 **
120813 ** Because the Select object originates from a VALUES clause:
120814 ** (1) There is no LIMIT or OFFSET or else there is a LIMIT of exactly 1
120815 ** (2) All terms are UNION ALL
120816 ** (3) There is no ORDER BY clause
120817 **
120818 ** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
120819 ** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
120820 ** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
120821 ** Since the limit is exactly 1, we only need to evalutes the left-most VALUES.
120822 */
120823 static int multiSelectValues(
120824 Parse *pParse, /* Parsing context */
120825 Select *p, /* The right-most of SELECTs to be coded */
120826 SelectDest *pDest /* What to do with query results */
120827 ){
120828 Select *pPrior;
120829 Select *pRightmost = p;
120830 int nRow = 1;
120831 int rc = 0;
120832 assert( p->selFlags & SF_MultiValue );
120833 do{
120834 assert( p->selFlags & SF_Values );
120835 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
 
120836 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
120837 if( p->pPrior==0 ) break;
120838 assert( p->pPrior->pNext==p );
120839 p = p->pPrior;
120840 nRow++;
@@ -120748,11 +120842,11 @@
120842 while( p ){
120843 pPrior = p->pPrior;
120844 p->pPrior = 0;
120845 rc = sqlite3Select(pParse, p, pDest);
120846 p->pPrior = pPrior;
120847 if( rc || pRightmost->pLimit ) break;
120848 p->nSelectRow = nRow;
120849 p = p->pNext;
120850 }
120851 return rc;
120852 }
@@ -126750,11 +126844,12 @@
126844 /* Populate the argument registers. */
126845 for(i=0; i<pTab->nCol; i++){
126846 if( aXRef[i]>=0 ){
126847 sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
126848 }else{
126849 sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
126850 sqlite3VdbeChangeP5(v, 1); /* Enable sqlite3_vtab_nochange() */
126851 }
126852 }
126853 if( HasRowid(pTab) ){
126854 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
126855 if( pRowid ){
@@ -126785,10 +126880,15 @@
126880 }
126881 }else{
126882 /* Create a record from the argument register contents and insert it into
126883 ** the ephemeral table. */
126884 sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);
126885 #ifdef SQLITE_DEBUG
126886 /* Signal an assert() within OP_MakeRecord that it is allowed to
126887 ** accept no-change records with serial_type 10 */
126888 sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG_MAGIC);
126889 #endif
126890 sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);
126891 sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);
126892 }
126893
126894
@@ -179419,13 +179519,11 @@
179519 return SQLITE_OK;
179520 }
179521
179522 /*
179523 ** This function queries the database for the names of the columns of table
179524 ** zThis, in schema zDb.
 
 
179525 **
179526 ** Otherwise, if they are not NULL, variable *pnCol is set to the number
179527 ** of columns in the database table and variable *pzTab is set to point to a
179528 ** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
179529 ** point to an array of pointers to column names. And *pabPK (again, if not
@@ -179442,13 +179540,11 @@
179540 ** *pzTab = "tbl1"
179541 ** *pazCol = {"w", "x", "y", "z"}
179542 ** *pabPK = {1, 0, 0, 1}
179543 **
179544 ** All returned buffers are part of the same single allocation, which must
179545 ** be freed using sqlite3_free() by the caller
 
 
179546 */
179547 static int sessionTableInfo(
179548 sqlite3 *db, /* Database connection */
179549 const char *zDb, /* Name of attached database (e.g. "main") */
179550 const char *zThis, /* Table name */
@@ -179469,11 +179565,27 @@
179565 u8 *abPK = 0;
179566
179567 assert( pazCol && pabPK );
179568
179569 nThis = sqlite3Strlen30(zThis);
179570 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
179571 rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
179572 if( rc==SQLITE_OK ){
179573 /* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
179574 zPragma = sqlite3_mprintf(
179575 "SELECT 0, 'tbl', '', 0, '', 1 UNION ALL "
179576 "SELECT 1, 'idx', '', 0, '', 2 UNION ALL "
179577 "SELECT 2, 'stat', '', 0, '', 0"
179578 );
179579 }else if( rc==SQLITE_ERROR ){
179580 zPragma = sqlite3_mprintf("");
179581 }else{
179582 return rc;
179583 }
179584 }else{
179585 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
179586 }
179587 if( !zPragma ) return SQLITE_NOMEM;
179588
179589 rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
179590 sqlite3_free(zPragma);
179591 if( rc!=SQLITE_OK ) return rc;
@@ -180026,11 +180138,10 @@
180138 if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
180139 if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
180140 if( abPK[i] ) bHasPk = 1;
180141 }
180142 }
 
180143 }
180144 sqlite3_free((char*)azCol);
180145 if( bMismatch ){
180146 *pzErrMsg = sqlite3_mprintf("table schemas do not match");
180147 rc = SQLITE_SCHEMA;
@@ -202988,11 +203099,11 @@
203099 int nArg, /* Number of args */
203100 sqlite3_value **apUnused /* Function arguments */
203101 ){
203102 assert( nArg==0 );
203103 UNUSED_PARAM2(nArg, apUnused);
203104 sqlite3_result_text(pCtx, "fts5: 2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4356b", -1, SQLITE_TRANSIENT);
203105 }
203106
203107 static int fts5Init(sqlite3 *db){
203108 static const sqlite3_module fts5Mod = {
203109 /* iVersion */ 2,
@@ -207256,12 +207367,12 @@
207367 }
207368 #endif /* SQLITE_CORE */
207369 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207370
207371 /************** End of stmt.c ************************************************/
207372 #if __LINE__!=207372
207373 #undef SQLITE_SOURCE_ID
207374 #define SQLITE_SOURCE_ID "2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4alt2"
207375 #endif
207376 /* Return the source-id for this library */
207377 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207378 /************************** End of sqlite3.c ******************************/
207379
+25 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.22.0"
127127
#define SQLITE_VERSION_NUMBER 3022000
128
-#define SQLITE_SOURCE_ID "2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7148c"
128
+#define SQLITE_SOURCE_ID "2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4356b"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -4797,10 +4797,13 @@
47974797
** TEXT in bytes
47984798
** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
47994799
** datatype of the value
48004800
** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
48014801
** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
4802
+** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
4803
+** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
4804
+** against a virtual table.
48024805
** </table></blockquote>
48034806
**
48044807
** <b>Details:</b>
48054808
**
48064809
** These routines extract type, size, and content information from
@@ -4844,10 +4847,23 @@
48444847
** made to convert the value to an integer or floating point. If
48454848
** such a conversion is possible without loss of information (in other
48464849
** words, if the value is a string that looks like a number)
48474850
** then the conversion is performed. Otherwise no conversion occurs.
48484851
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
4852
+**
4853
+** ^Within the [xUpdate] method of a [virtual table], the
4854
+** sqlite3_value_nochange(X) interface returns true if and only if
4855
+** the column corresponding to X is unchanged by the UPDATE operation
4856
+** that the xUpdate method call was invoked to implement and if
4857
+** and the prior [xColumn] method call that was invoked to extracted
4858
+** the value for that column returned without setting a result (probably
4859
+** because it queried [sqlite3_vtab_nochange()] and found that the column
4860
+** was unchanging). ^Within an [xUpdate] method, any value for which
4861
+** sqlite3_value_nochange(X) is true will in all other respects appear
4862
+** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
4863
+** than within an [xUpdate] method call for an UPDATE statement, then
4864
+** the return value is arbitrary and meaningless.
48494865
**
48504866
** Please pay particular attention to the fact that the pointer returned
48514867
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
48524868
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
48534869
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -4867,10 +4883,11 @@
48674883
SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
48684884
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
48694885
SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
48704886
SQLITE_API int sqlite3_value_type(sqlite3_value*);
48714887
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
4888
+SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
48724889
48734890
/*
48744891
** CAPI3REF: Finding The Subtype Of SQL Values
48754892
** METHOD: sqlite3_value
48764893
**
@@ -8304,10 +8321,17 @@
83048321
** method of a [virtual table], then it returns true if and only if the
83058322
** column is being fetched as part of an UPDATE operation during which the
83068323
** column value will not change. Applications might use this to substitute
83078324
** a lighter-weight value to return that the corresponding [xUpdate] method
83088325
** understands as a "no-change" value.
8326
+**
8327
+** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
8328
+** the column is not changed by the UPDATE statement, they the xColumn
8329
+** method can optionally return without setting a result, without calling
8330
+** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
8331
+** In that case, [sqlite3_value_nochange(X)] will return true for the
8332
+** same column in the [xUpdate] method.
83098333
*/
83108334
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
83118335
83128336
/*
83138337
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
83148338
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-12 14:34:45 30ed7a4b6408f0ca921abc4d8b7bb5404fc7708cedcd104b017b361054e7148c"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -4797,10 +4797,13 @@
4797 ** TEXT in bytes
4798 ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
4799 ** datatype of the value
4800 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
4801 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
 
 
 
4802 ** </table></blockquote>
4803 **
4804 ** <b>Details:</b>
4805 **
4806 ** These routines extract type, size, and content information from
@@ -4844,10 +4847,23 @@
4844 ** made to convert the value to an integer or floating point. If
4845 ** such a conversion is possible without loss of information (in other
4846 ** words, if the value is a string that looks like a number)
4847 ** then the conversion is performed. Otherwise no conversion occurs.
4848 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
 
 
 
 
 
 
 
 
 
 
 
 
 
4849 **
4850 ** Please pay particular attention to the fact that the pointer returned
4851 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
4852 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
4853 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -4867,10 +4883,11 @@
4867 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
4868 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
4869 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
4870 SQLITE_API int sqlite3_value_type(sqlite3_value*);
4871 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
 
4872
4873 /*
4874 ** CAPI3REF: Finding The Subtype Of SQL Values
4875 ** METHOD: sqlite3_value
4876 **
@@ -8304,10 +8321,17 @@
8304 ** method of a [virtual table], then it returns true if and only if the
8305 ** column is being fetched as part of an UPDATE operation during which the
8306 ** column value will not change. Applications might use this to substitute
8307 ** a lighter-weight value to return that the corresponding [xUpdate] method
8308 ** understands as a "no-change" value.
 
 
 
 
 
 
 
8309 */
8310 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
8311
8312 /*
8313 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
8314
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-15 19:00:35 b0b7d0363acf38c2178e2d3041d8ce2a0de061a51caa64670dbf539ee6d4356b"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -4797,10 +4797,13 @@
4797 ** TEXT in bytes
4798 ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
4799 ** datatype of the value
4800 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
4801 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
4802 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
4803 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
4804 ** against a virtual table.
4805 ** </table></blockquote>
4806 **
4807 ** <b>Details:</b>
4808 **
4809 ** These routines extract type, size, and content information from
@@ -4844,10 +4847,23 @@
4847 ** made to convert the value to an integer or floating point. If
4848 ** such a conversion is possible without loss of information (in other
4849 ** words, if the value is a string that looks like a number)
4850 ** then the conversion is performed. Otherwise no conversion occurs.
4851 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
4852 **
4853 ** ^Within the [xUpdate] method of a [virtual table], the
4854 ** sqlite3_value_nochange(X) interface returns true if and only if
4855 ** the column corresponding to X is unchanged by the UPDATE operation
4856 ** that the xUpdate method call was invoked to implement and if
4857 ** and the prior [xColumn] method call that was invoked to extracted
4858 ** the value for that column returned without setting a result (probably
4859 ** because it queried [sqlite3_vtab_nochange()] and found that the column
4860 ** was unchanging). ^Within an [xUpdate] method, any value for which
4861 ** sqlite3_value_nochange(X) is true will in all other respects appear
4862 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
4863 ** than within an [xUpdate] method call for an UPDATE statement, then
4864 ** the return value is arbitrary and meaningless.
4865 **
4866 ** Please pay particular attention to the fact that the pointer returned
4867 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
4868 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
4869 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -4867,10 +4883,11 @@
4883 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
4884 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
4885 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
4886 SQLITE_API int sqlite3_value_type(sqlite3_value*);
4887 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
4888 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
4889
4890 /*
4891 ** CAPI3REF: Finding The Subtype Of SQL Values
4892 ** METHOD: sqlite3_value
4893 **
@@ -8304,10 +8321,17 @@
8321 ** method of a [virtual table], then it returns true if and only if the
8322 ** column is being fetched as part of an UPDATE operation during which the
8323 ** column value will not change. Applications might use this to substitute
8324 ** a lighter-weight value to return that the corresponding [xUpdate] method
8325 ** understands as a "no-change" value.
8326 **
8327 ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
8328 ** the column is not changed by the UPDATE statement, they the xColumn
8329 ** method can optionally return without setting a result, without calling
8330 ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
8331 ** In that case, [sqlite3_value_nochange(X)] will return true for the
8332 ** same column in the [xUpdate] method.
8333 */
8334 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
8335
8336 /*
8337 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
8338

Keyboard Shortcuts

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