better-sqlite3-multiple-ciphers 7.5.1 → 7.5.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,14 +19,14 @@ The fastest and simplest library for SQLite3 in Node.js. This particular fork su
19
19
  - ### Stable
20
20
  - **better-sqlite3-multiple-ciphers** - [`7.5.1`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v7.5.1)
21
21
  - **better-sqlite3** - [`7.5.1`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.5.1)
22
- - **SQLite** - [`3.38.2`](https://www.sqlite.org/draft/releaselog/3_38_2.html)
22
+ - **SQLite** - [`3.38.2`](https://www.sqlite.org/releaselog/3_38_2.html)
23
23
  - **SQLite3 Multiple Ciphers** - [`1.3.10`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.3.10)
24
24
 
25
25
  - ### Beta
26
- - **better-sqlite3-multiple-ciphers** - [`7.5.1-beta.3`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v7.5.1-beta.3)
27
- - **better-sqlite3** - [`7.5.0`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.5.0)
28
- - **SQLite** - [`3.38.1`](https://www.sqlite.org/draft/releaselog/3_38_1.html)
29
- - **SQLite3 Multiple Ciphers** - [`1.3.9`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.3.9)
26
+ - **better-sqlite3-multiple-ciphers** - [`7.5.2-beta.2`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v7.5.2-beta.2)
27
+ - **better-sqlite3** - [`7.5.1`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.5.1)
28
+ - **SQLite** - [`3.38.3`](https://www.sqlite.org/releaselog/3_38_3.html)
29
+ - **SQLite3 Multiple Ciphers** - [`1.4.2`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.4.2)
30
30
 
31
31
  ## Help this project stay strong! 💪
32
32
 
package/deps/setup.ps1 CHANGED
@@ -2,7 +2,7 @@
2
2
  $ErrorActionPreference = "Stop"
3
3
 
4
4
  # SQLite Info
5
- $SQLITEMC_VER = "v1.3.10"
5
+ $SQLITEMC_VER = "v1.4.2"
6
6
  $API_URL = "https://api.github.com/repos/utelle/SQLite3MultipleCiphers/releases/tags/" + $SQLITEMC_VER
7
7
 
8
8
  # Paths
@@ -92,7 +92,7 @@ extern SQLITE_API LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
92
92
  /*** Begin of #include "sqlite3patched.c" ***/
93
93
  /******************************************************************************
94
94
  ** This file is an amalgamation of many separate C source files from SQLite
95
- ** version 3.38.2. By combining all the individual C code files into this
95
+ ** version 3.38.3. By combining all the individual C code files into this
96
96
  ** single large file, the entire code can be compiled as a single translation
97
97
  ** unit. This allows many compilers to do optimizations that would not be
98
98
  ** possible if the files were compiled separately. Performance improvements
@@ -544,9 +544,9 @@ extern "C" {
544
544
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
545
545
  ** [sqlite_version()] and [sqlite_source_id()].
546
546
  */
547
- #define SQLITE_VERSION "3.38.2"
548
- #define SQLITE_VERSION_NUMBER 3038002
549
- #define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f"
547
+ #define SQLITE_VERSION "3.38.3"
548
+ #define SQLITE_VERSION_NUMBER 3038003
549
+ #define SQLITE_SOURCE_ID "2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4"
550
550
 
551
551
  /*
552
552
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -20028,6 +20028,7 @@ SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20028
20028
  SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20029
20029
  SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20030
20030
  SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20031
+ SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
20031
20032
  #ifdef SQLITE_ENABLE_CURSOR_HINTS
20032
20033
  SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20033
20034
  #endif
@@ -29436,8 +29437,9 @@ SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const cha
29436
29437
  ** Free any prior content in *pz and replace it with a copy of zNew.
29437
29438
  */
29438
29439
  SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
29440
+ char *z = sqlite3DbStrDup(db, zNew);
29439
29441
  sqlite3DbFree(db, *pz);
29440
- *pz = sqlite3DbStrDup(db, zNew);
29442
+ *pz = z;
29441
29443
  }
29442
29444
 
29443
29445
  /*
@@ -67863,6 +67865,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
67863
67865
  ** fragmented bytes within the page. */
67864
67866
  memcpy(&aData[iAddr], &aData[pc], 2);
67865
67867
  aData[hdr+7] += (u8)x;
67868
+ testcase( pc+x>maxPC );
67869
+ return &aData[pc];
67866
67870
  }else if( x+pc > maxPC ){
67867
67871
  /* This slot extends off the end of the usable part of the page */
67868
67872
  *pRc = SQLITE_CORRUPT_PAGE(pPg);
@@ -72062,7 +72066,7 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
72062
72066
  assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
72063
72067
  assert( pPage->isInit );
72064
72068
  if( pPage->leaf ){
72065
- assert( pCur->ix<pCur->pPage->nCell );
72069
+ assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
72066
72070
  pCur->ix = (u16)idx;
72067
72071
  *pRes = c;
72068
72072
  rc = SQLITE_OK;
@@ -74586,7 +74590,7 @@ static int balance_nonroot(
74586
74590
  iOvflSpace += sz;
74587
74591
  assert( sz<=pBt->maxLocal+23 );
74588
74592
  assert( iOvflSpace <= (int)pBt->pageSize );
74589
- for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
74593
+ for(k=0; b.ixNx[k]<=j && ALWAYS(k<NB*2); k++){}
74590
74594
  pSrcEnd = b.apEnd[k];
74591
74595
  if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
74592
74596
  rc = SQLITE_CORRUPT_BKPT;
@@ -78151,7 +78155,11 @@ SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
78151
78155
  assert( !sqlite3VdbeMemIsRowSet(pMem) );
78152
78156
  assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
78153
78157
  || desiredEnc==SQLITE_UTF16BE );
78154
- if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
78158
+ if( !(pMem->flags&MEM_Str) ){
78159
+ pMem->enc = desiredEnc;
78160
+ return SQLITE_OK;
78161
+ }
78162
+ if( pMem->enc==desiredEnc ){
78155
78163
  return SQLITE_OK;
78156
78164
  }
78157
78165
  assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
@@ -104858,6 +104866,38 @@ SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
104858
104866
  return exprIsConst(p, 3, iCur);
104859
104867
  }
104860
104868
 
104869
+ /*
104870
+ ** Check pExpr to see if it is an invariant constraint on data source pSrc.
104871
+ ** This is an optimization. False negatives will perhaps cause slower
104872
+ ** queries, but false positives will yield incorrect answers. So when in
104873
+ ** double, return 0.
104874
+ **
104875
+ ** To be an invariant constraint, the following must be true:
104876
+ **
104877
+ ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
104878
+ **
104879
+ ** (2) pExpr cannot use subqueries or non-deterministic functions.
104880
+ **
104881
+ ** (*) ** Not applicable to this branch **
104882
+ **
104883
+ ** (4) If pSrc is the right operand of a LEFT JOIN, then...
104884
+ ** (4a) pExpr must come from an ON clause..
104885
+ ** (4b) and specifically the ON clause associated with the LEFT JOIN.
104886
+ **
104887
+ ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
104888
+ ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
104889
+ ** clause, not an ON clause.
104890
+ */
104891
+ SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
104892
+ if( pSrc->fg.jointype & JT_LEFT ){
104893
+ if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */
104894
+ if( pExpr->w.iRightJoinTable!=pSrc->iCursor ) return 0; /* rule (4b) */
104895
+ }else{
104896
+ if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */
104897
+ }
104898
+ return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
104899
+ }
104900
+
104861
104901
 
104862
104902
  /*
104863
104903
  ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
@@ -139146,8 +139186,7 @@ static int pushDownWhereTerms(
139146
139186
  Parse *pParse, /* Parse context (for malloc() and error reporting) */
139147
139187
  Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
139148
139188
  Expr *pWhere, /* The WHERE clause of the outer query */
139149
- int iCursor, /* Cursor number of the subquery */
139150
- int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
139189
+ SrcItem *pSrc /* The subquery term of the outer FROM clause */
139151
139190
  ){
139152
139191
  Expr *pNew;
139153
139192
  int nChng = 0;
@@ -139182,10 +139221,11 @@ static int pushDownWhereTerms(
139182
139221
  return 0; /* restriction (3) */
139183
139222
  }
139184
139223
  while( pWhere->op==TK_AND ){
139185
- nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
139186
- iCursor, isLeftJoin);
139224
+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
139187
139225
  pWhere = pWhere->pLeft;
139188
139226
  }
139227
+
139228
+ #if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
139189
139229
  if( isLeftJoin
139190
139230
  && (ExprHasProperty(pWhere,EP_FromJoin)==0
139191
139231
  || pWhere->w.iRightJoinTable!=iCursor)
@@ -139197,7 +139237,9 @@ static int pushDownWhereTerms(
139197
139237
  ){
139198
139238
  return 0; /* restriction (5) */
139199
139239
  }
139200
- if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
139240
+ #endif
139241
+
139242
+ if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
139201
139243
  nChng++;
139202
139244
  pSubq->selFlags |= SF_PushDown;
139203
139245
  while( pSubq ){
@@ -139205,8 +139247,8 @@ static int pushDownWhereTerms(
139205
139247
  pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
139206
139248
  unsetJoinExpr(pNew, -1);
139207
139249
  x.pParse = pParse;
139208
- x.iTable = iCursor;
139209
- x.iNewTable = iCursor;
139250
+ x.iTable = pSrc->iCursor;
139251
+ x.iNewTable = pSrc->iCursor;
139210
139252
  x.isLeftJoin = 0;
139211
139253
  x.pEList = pSubq->pEList;
139212
139254
  pNew = substExpr(&x, pNew);
@@ -140988,8 +141030,7 @@ SQLITE_PRIVATE int sqlite3Select(
140988
141030
  if( OptimizationEnabled(db, SQLITE_PushDown)
140989
141031
  && (pItem->fg.isCte==0
140990
141032
  || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
140991
- && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
140992
- (pItem->fg.jointype & JT_OUTER)!=0)
141033
+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
140993
141034
  ){
140994
141035
  #if SELECTTRACE_ENABLED
140995
141036
  if( sqlite3SelectTrace & 0x100 ){
@@ -152914,8 +152955,7 @@ static SQLITE_NOINLINE void constructAutomaticIndex(
152914
152955
  ** WHERE clause (or the ON clause of a LEFT join) that constrain which
152915
152956
  ** rows of the target table (pSrc) that can be used. */
152916
152957
  if( (pTerm->wtFlags & TERM_VIRTUAL)==0
152917
- && ((pSrc->fg.jointype&JT_LEFT)==0 || ExprHasProperty(pExpr,EP_FromJoin))
152918
- && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
152958
+ && sqlite3ExprIsTableConstraint(pExpr, pSrc)
152919
152959
  ){
152920
152960
  pPartial = sqlite3ExprAnd(pParse, pPartial,
152921
152961
  sqlite3ExprDup(pParse->db, pExpr, 0));
@@ -153154,7 +153194,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
153154
153194
  for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
153155
153195
  Expr *pExpr = pTerm->pExpr;
153156
153196
  if( (pTerm->wtFlags & TERM_VIRTUAL)==0
153157
- && sqlite3ExprIsTableConstant(pExpr, iCur)
153197
+ && sqlite3ExprIsTableConstraint(pExpr, pItem)
153158
153198
  ){
153159
153199
  sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
153160
153200
  }
@@ -160074,7 +160114,7 @@ static void windowAggStep(
160074
160114
 
160075
160115
  for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
160076
160116
  VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp);
160077
- if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
160117
+ if( pOp->opcode==OP_Column && pOp->p1==pMWin->iEphCsr ){
160078
160118
  pOp->p1 = csr;
160079
160119
  }
160080
160120
  }
@@ -194397,14 +194437,15 @@ static JsonNode *jsonLookupStep(
194397
194437
  *pzErr = zPath;
194398
194438
  return 0;
194399
194439
  }
194440
+ testcase( nKey==0 );
194400
194441
  }else{
194401
194442
  zKey = zPath;
194402
194443
  for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
194403
194444
  nKey = i;
194404
- }
194405
- if( nKey==0 ){
194406
- *pzErr = zPath;
194407
- return 0;
194445
+ if( nKey==0 ){
194446
+ *pzErr = zPath;
194447
+ return 0;
194448
+ }
194408
194449
  }
194409
194450
  j = 1;
194410
194451
  for(;;){
@@ -195552,6 +195593,33 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
195552
195593
  return SQLITE_OK;
195553
195594
  }
195554
195595
 
195596
+ /* Append an object label to the JSON Path being constructed
195597
+ ** in pStr.
195598
+ */
195599
+ static void jsonAppendObjectPathElement(
195600
+ JsonString *pStr,
195601
+ JsonNode *pNode
195602
+ ){
195603
+ int jj, nn;
195604
+ const char *z;
195605
+ assert( pNode->eType==JSON_STRING );
195606
+ assert( pNode->jnFlags & JNODE_LABEL );
195607
+ assert( pNode->eU==1 );
195608
+ z = pNode->u.zJContent;
195609
+ nn = pNode->n;
195610
+ assert( nn>=2 );
195611
+ assert( z[0]=='"' );
195612
+ assert( z[nn-1]=='"' );
195613
+ if( nn>2 && sqlite3Isalpha(z[1]) ){
195614
+ for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
195615
+ if( jj==nn-1 ){
195616
+ z++;
195617
+ nn -= 2;
195618
+ }
195619
+ }
195620
+ jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
195621
+ }
195622
+
195555
195623
  /* Append the name of the path for element i to pStr
195556
195624
  */
195557
195625
  static void jsonEachComputePath(
@@ -195576,10 +195644,7 @@ static void jsonEachComputePath(
195576
195644
  }else{
195577
195645
  assert( pUp->eType==JSON_OBJECT );
195578
195646
  if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
195579
- assert( pNode->eType==JSON_STRING );
195580
- assert( pNode->jnFlags & JNODE_LABEL );
195581
- assert( pNode->eU==1 );
195582
- jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
195647
+ jsonAppendObjectPathElement(pStr, pNode);
195583
195648
  }
195584
195649
  }
195585
195650
 
@@ -195650,8 +195715,7 @@ static int jsonEachColumn(
195650
195715
  if( p->eType==JSON_ARRAY ){
195651
195716
  jsonPrintf(30, &x, "[%d]", p->iRowid);
195652
195717
  }else if( p->eType==JSON_OBJECT ){
195653
- assert( pThis->eU==1 );
195654
- jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
195718
+ jsonAppendObjectPathElement(&x, pThis);
195655
195719
  }
195656
195720
  }
195657
195721
  jsonResult(&x);
@@ -234542,7 +234606,7 @@ static void fts5SourceIdFunc(
234542
234606
  ){
234543
234607
  assert( nArg==0 );
234544
234608
  UNUSED_PARAM2(nArg, apUnused);
234545
- sqlite3_result_text(pCtx, "fts5: 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f", -1, SQLITE_TRANSIENT);
234609
+ sqlite3_result_text(pCtx, "fts5: 2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4", -1, SQLITE_TRANSIENT);
234546
234610
  }
234547
234611
 
234548
234612
  /*
@@ -239670,10 +239734,10 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
239670
239734
  #define SQLITE3MC_VERSION_H_
239671
239735
 
239672
239736
  #define SQLITE3MC_VERSION_MAJOR 1
239673
- #define SQLITE3MC_VERSION_MINOR 3
239674
- #define SQLITE3MC_VERSION_RELEASE 10
239737
+ #define SQLITE3MC_VERSION_MINOR 4
239738
+ #define SQLITE3MC_VERSION_RELEASE 2
239675
239739
  #define SQLITE3MC_VERSION_SUBRELEASE 0
239676
- #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.3.10"
239740
+ #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.4.2"
239677
239741
 
239678
239742
  #endif /* SQLITE3MC_VERSION_H_ */
239679
239743
  /*** End of #include "sqlite3mc_version.h" ***/
@@ -239832,9 +239896,9 @@ extern "C" {
239832
239896
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
239833
239897
  ** [sqlite_version()] and [sqlite_source_id()].
239834
239898
  */
239835
- #define SQLITE_VERSION "3.38.2"
239836
- #define SQLITE_VERSION_NUMBER 3038002
239837
- #define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f"
239899
+ #define SQLITE_VERSION "3.38.3"
239900
+ #define SQLITE_VERSION_NUMBER 3038003
239901
+ #define SQLITE_SOURCE_ID "2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4"
239838
239902
 
239839
239903
  /*
239840
239904
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -262581,7 +262645,7 @@ sqlite3mcHandleMainKey(sqlite3* db, const char* zPath)
262581
262645
  ** Purpose: Implementation of SQLite codec API
262582
262646
  ** Author: Ulrich Telle
262583
262647
  ** Created: 2006-12-06
262584
- ** Copyright: (c) 2006-2021 Ulrich Telle
262648
+ ** Copyright: (c) 2006-2022 Ulrich Telle
262585
262649
  ** License: MIT
262586
262650
  */
262587
262651
 
@@ -262657,7 +262721,7 @@ sqlite3mcBtreeSetPageSize(Btree* p, int pageSize, int nReserve, int iFix)
262657
262721
  ** Change 4: Call sqlite3mcBtreeSetPageSize instead of sqlite3BtreeSetPageSize for main database
262658
262722
  ** (sqlite3mcBtreeSetPageSize allows to reduce the number of reserved bytes)
262659
262723
  **
262660
- ** This code is generated by the script rekeyvacuum.sh from SQLite version 3.38.2 amalgamation.
262724
+ ** This code is generated by the script rekeyvacuum.sh from SQLite version 3.38.3 amalgamation.
262661
262725
  */
262662
262726
  SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(
262663
262727
  char **pzErrMsg, /* Write error message here */
@@ -263049,7 +263113,7 @@ SQLITE_PRIVATE Codec*
263049
263113
  sqlite3mcGetMainCodec(sqlite3* db);
263050
263114
 
263051
263115
  SQLITE_PRIVATE void
263052
- sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec* codec);
263116
+ sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec);
263053
263117
 
263054
263118
  static int
263055
263119
  mcAdjustBtree(Btree* pBt, int nPageSize, int nReserved, int isLegacy)
@@ -263111,7 +263175,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
263111
263175
  sqlite3mcSetBtree(codec, db->aDb[nDb].pBt);
263112
263176
  mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
263113
263177
  sqlite3mcCodecSizeChange(codec, pageSize, reserved);
263114
- sqlite3mcSetCodec(db, dbFileName, codec);
263178
+ sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
263115
263179
  }
263116
263180
  else
263117
263181
  {
@@ -263132,7 +263196,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
263132
263196
  /* Remove codec for main database */
263133
263197
  if (nDb == 0 && nKey == 0)
263134
263198
  {
263135
- sqlite3mcSetCodec(db, dbFileName, NULL);
263199
+ sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
263136
263200
  }
263137
263201
  }
263138
263202
  }
@@ -263167,7 +263231,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
263167
263231
  int reserved = sqlite3mcGetReservedWriteCipher(codec);
263168
263232
  mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
263169
263233
  sqlite3mcCodecSizeChange(codec, pageSize, reserved);
263170
- sqlite3mcSetCodec(db, dbFileName, codec);
263234
+ sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
263171
263235
  }
263172
263236
  else
263173
263237
  {
@@ -263314,7 +263378,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
263314
263378
  int nReservedWriteCipher;
263315
263379
  sqlite3mcSetHasReadCipher(codec, 0); /* Original database is not encrypted */
263316
263380
  mcAdjustBtree(pBt, sqlite3mcGetPageSizeWriteCipher(codec), sqlite3mcGetReservedWriteCipher(codec), sqlite3mcGetLegacyWriteCipher(codec));
263317
- sqlite3mcSetCodec(db, dbFileName, codec);
263381
+ sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
263318
263382
  nReservedWriteCipher = sqlite3mcGetReservedWriteCipher(codec);
263319
263383
  sqlite3mcCodecSizeChange(codec, nPagesize, nReservedWriteCipher);
263320
263384
  if (nReserved != nReservedWriteCipher)
@@ -263465,7 +263529,7 @@ leave_rekey:
263465
263529
  if (!sqlite3mcIsEncrypted(codec))
263466
263530
  {
263467
263531
  /* Remove codec for unencrypted database */
263468
- sqlite3mcSetCodec(db, dbFileName, NULL);
263532
+ sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
263469
263533
  }
263470
263534
  return rc;
263471
263535
  }
@@ -273367,7 +273431,7 @@ int sqlite3_regexp_init(
273367
273431
  ** Purpose: Implementation of SQLite VFS for Multiple Ciphers
273368
273432
  ** Author: Ulrich Telle
273369
273433
  ** Created: 2020-02-28
273370
- ** Copyright: (c) 2020-2021 Ulrich Telle
273434
+ ** Copyright: (c) 2020-2022 Ulrich Telle
273371
273435
  ** License: MIT
273372
273436
  */
273373
273437
 
@@ -273396,6 +273460,7 @@ struct sqlite3mc_file
273396
273460
  {
273397
273461
  sqlite3_file base; /* sqlite3_file I/O methods */
273398
273462
  sqlite3_file* pFile; /* Real underlying OS file */
273463
+ sqlite3mc_vfs* pVfsMC; /* Pointer to the sqlite3mc_vfs object */
273399
273464
  const char* zFileName; /* File name */
273400
273465
  int openFlags; /* Open flags */
273401
273466
  sqlite3mc_file* pMainNext; /* Next main db file */
@@ -273418,9 +273483,6 @@ struct sqlite3mc_vfs
273418
273483
  #define REALVFS(p) ((sqlite3_vfs*)(((sqlite3mc_vfs*)(p))->base.pAppData))
273419
273484
  #define REALFILE(p) (((sqlite3mc_file*)(p))->pFile)
273420
273485
 
273421
- #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
273422
- #define ORIGFILE(p) ((sqlite3_file*)(((CksmFile*)(p))+1))
273423
-
273424
273486
  /*
273425
273487
  ** Prototypes for VFS methods
273426
273488
  */
@@ -273474,37 +273536,8 @@ static const int walFrameHeaderSize = 24;
273474
273536
  static const int walFileHeaderSize = 32;
273475
273537
 
273476
273538
  /*
273477
- ** Global VFS structure of SQLite3 Multiple Ciphers VFS
273539
+ ** Global I/O method structure of SQLite3 Multiple Ciphers VFS
273478
273540
  */
273479
- static sqlite3mc_vfs mcVfsGlobal =
273480
- {
273481
- {
273482
- 3, /* iVersion */
273483
- 0, /* szOsFile */
273484
- 1024, /* mxPathname */
273485
- 0, /* pNext */
273486
- SQLITE3MC_VFS_NAME, /* zName */
273487
- 0, /* pAppData */
273488
- mcVfsOpen, /* xOpen */
273489
- mcVfsDelete, /* xDelete */
273490
- mcVfsAccess, /* xAccess */
273491
- mcVfsFullPathname, /* xFullPathname */
273492
- mcVfsDlOpen, /* xDlOpen */
273493
- mcVfsDlError, /* xDlError */
273494
- mcVfsDlSym, /* xDlSym */
273495
- mcVfsDlClose, /* xDlClose */
273496
- mcVfsRandomness, /* xRandomness */
273497
- mcVfsSleep, /* xSleep */
273498
- mcVfsCurrentTime, /* xCurrentTime */
273499
- mcVfsGetLastError, /* xGetLastError */
273500
- mcVfsCurrentTimeInt64, /* xCurrentTimeInt64 */
273501
- mcVfsSetSystemCall, /* xSetSystemCall */
273502
- mcVfsGetSystemCall, /* xGetSystemCall */
273503
- mcVfsNextSystemCall /* xNextSystemCall */
273504
- },
273505
- NULL
273506
- };
273507
-
273508
273541
  static sqlite3_io_methods mcIoMethodsGlobal =
273509
273542
  {
273510
273543
  3, /* iVersion */
@@ -273538,10 +273571,10 @@ static sqlite3_io_methods mcIoMethodsGlobal =
273538
273571
  static void mcMainListAdd(sqlite3mc_file* pFile)
273539
273572
  {
273540
273573
  assert( (pFile->openFlags & SQLITE_OPEN_MAIN_DB) );
273541
- sqlite3_mutex_enter(mcVfsGlobal.mutex);
273542
- pFile->pMainNext = mcVfsGlobal.pMain;
273543
- mcVfsGlobal.pMain = pFile;
273544
- sqlite3_mutex_leave(mcVfsGlobal.mutex);
273574
+ sqlite3_mutex_enter(pFile->pVfsMC->mutex);
273575
+ pFile->pMainNext = pFile->pVfsMC->pMain;
273576
+ pFile->pVfsMC->pMain = pFile;
273577
+ sqlite3_mutex_leave(pFile->pVfsMC->mutex);
273545
273578
  }
273546
273579
 
273547
273580
  /*
@@ -273550,11 +273583,11 @@ static void mcMainListAdd(sqlite3mc_file* pFile)
273550
273583
  static void mcMainListRemove(sqlite3mc_file* pFile)
273551
273584
  {
273552
273585
  sqlite3mc_file** pMainPrev;
273553
- sqlite3_mutex_enter(mcVfsGlobal.mutex);
273554
- for (pMainPrev = &mcVfsGlobal.pMain; *pMainPrev && *pMainPrev != pFile; pMainPrev = &((*pMainPrev)->pMainNext)){}
273586
+ sqlite3_mutex_enter(pFile->pVfsMC->mutex);
273587
+ for (pMainPrev = &pFile->pVfsMC->pMain; *pMainPrev && *pMainPrev != pFile; pMainPrev = &((*pMainPrev)->pMainNext)){}
273555
273588
  if (*pMainPrev) *pMainPrev = pFile->pMainNext;
273556
273589
  pFile->pMainNext = 0;
273557
- sqlite3_mutex_leave(mcVfsGlobal.mutex);
273590
+ sqlite3_mutex_leave(pFile->pVfsMC->mutex);
273558
273591
  }
273559
273592
 
273560
273593
  /*
@@ -273572,6 +273605,51 @@ static sqlite3mc_file* mcFindDbMainFileName(sqlite3mc_vfs* mcVfs, const char* zF
273572
273605
  return pDb;
273573
273606
  }
273574
273607
 
273608
+ /*
273609
+ ** Find a pointer to the Multiple Ciphers VFS in use for a database connection.
273610
+ */
273611
+ static sqlite3mc_vfs* mcFindVfs(sqlite3* db, const char* zDbName)
273612
+ {
273613
+ sqlite3mc_vfs* pVfsMC = NULL;
273614
+ if (db->pVfs && db->pVfs->xOpen == mcVfsOpen)
273615
+ {
273616
+ /* The top level VFS is a Multiple Ciphers VFS */
273617
+ pVfsMC = (sqlite3mc_vfs*)(db->pVfs);
273618
+ }
273619
+ else
273620
+ {
273621
+ /*
273622
+ ** The top level VFS is not a Multiple Ciphers VFS.
273623
+ ** Retrieve the VFS names stack.
273624
+ */
273625
+ char* zVfsNameStack = 0;
273626
+ if ((sqlite3_file_control(db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsNameStack) == SQLITE_OK) && (zVfsNameStack != NULL))
273627
+ {
273628
+ /* Search for the name prefix of a Multiple Ciphers VFS. */
273629
+ char* zVfsName = strstr(zVfsNameStack, SQLITE3MC_VFS_NAME);
273630
+ if (zVfsName != NULL)
273631
+ {
273632
+ /* The prefix was found, now determine the full VFS name. */
273633
+ char* zVfsNameEnd = zVfsName + strlen(SQLITE3MC_VFS_NAME);
273634
+ if (*zVfsNameEnd == '-')
273635
+ {
273636
+ for (++zVfsNameEnd; *zVfsNameEnd != '/' && *zVfsNameEnd != 0; ++zVfsNameEnd);
273637
+ if (*zVfsNameEnd == '/') *zVfsNameEnd = 0;
273638
+
273639
+ /* Find a pointer to the VFS with the determined name. */
273640
+ sqlite3_vfs* pVfs = sqlite3_vfs_find(zVfsName);
273641
+ if (pVfs && pVfs->xOpen == mcVfsOpen)
273642
+ {
273643
+ pVfsMC = (sqlite3mc_vfs*) pVfs;
273644
+ }
273645
+ }
273646
+ }
273647
+ sqlite3_free(zVfsNameStack);
273648
+ }
273649
+ }
273650
+ return pVfsMC;
273651
+ }
273652
+
273575
273653
  /*
273576
273654
  ** Find the codec of the database file
273577
273655
  ** corresponding to the database schema name.
@@ -273579,11 +273657,16 @@ static sqlite3mc_file* mcFindDbMainFileName(sqlite3mc_vfs* mcVfs, const char* zF
273579
273657
  SQLITE_PRIVATE Codec* sqlite3mcGetCodec(sqlite3* db, const char* zDbName)
273580
273658
  {
273581
273659
  Codec* codec = NULL;
273582
- const char* dbFileName = sqlite3_db_filename(db, zDbName);
273583
- sqlite3mc_file* pDbMain = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273584
- if (pDbMain)
273660
+ sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
273661
+
273662
+ if (pVfsMC)
273585
273663
  {
273586
- codec = pDbMain->codec;
273664
+ const char* dbFileName = sqlite3_db_filename(db, zDbName);
273665
+ sqlite3mc_file* pDbMain = mcFindDbMainFileName(pVfsMC, dbFileName);
273666
+ if (pDbMain)
273667
+ {
273668
+ codec = pDbMain->codec;
273669
+ }
273587
273670
  }
273588
273671
  return codec;
273589
273672
  }
@@ -273606,9 +273689,14 @@ SQLITE_PRIVATE Codec* sqlite3mcGetMainCodec(sqlite3* db)
273606
273689
  ** connection handle is actually valid, because the association between
273607
273690
  ** connection handles and database file handles is not maintained properly.
273608
273691
  */
273609
- SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec* codec)
273692
+ SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec)
273610
273693
  {
273611
- sqlite3mc_file* pDbMain = mcFindDbMainFileName(&mcVfsGlobal, zFileName);
273694
+ sqlite3mc_file* pDbMain = NULL;
273695
+ sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
273696
+ if (pVfsMC)
273697
+ {
273698
+ pDbMain = mcFindDbMainFileName((sqlite3mc_vfs*)(db->pVfs), zFileName);
273699
+ }
273612
273700
  if (pDbMain)
273613
273701
  {
273614
273702
  Codec* prevCodec = pDbMain->codec;
@@ -273677,6 +273765,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273677
273765
  sqlite3mc_vfs* mcVfs = (sqlite3mc_vfs*) pVfs;
273678
273766
  sqlite3mc_file* mcFile = (sqlite3mc_file*) pFile;
273679
273767
  mcFile->pFile = (sqlite3_file*) &mcFile[1];
273768
+ mcFile->pVfsMC = mcVfs;
273680
273769
  mcFile->openFlags = flags;
273681
273770
  mcFile->zFileName = zName;
273682
273771
  mcFile->codec = 0;
@@ -273707,7 +273796,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273707
273796
  else if (flags & SQLITE_OPEN_MAIN_JOURNAL)
273708
273797
  {
273709
273798
  const char* dbFileName = sqlite3_filename_database(zName);
273710
- mcFile->pMainDb = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273799
+ mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
273711
273800
  mcFile->zFileName = zName;
273712
273801
  SQLITE3MC_DEBUG_LOG("mcVfsOpen MAIN Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
273713
273802
  }
@@ -273722,7 +273811,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273722
273811
  else if (flags & SQLITE_OPEN_SUBJOURNAL)
273723
273812
  {
273724
273813
  const char* dbFileName = sqlite3_filename_database(zName);
273725
- mcFile->pMainDb = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273814
+ mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
273726
273815
  mcFile->zFileName = zName;
273727
273816
  SQLITE3MC_DEBUG_LOG("mcVfsOpen SUB Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
273728
273817
  }
@@ -273738,7 +273827,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273738
273827
  else if (flags & SQLITE_OPEN_WAL)
273739
273828
  {
273740
273829
  const char* dbFileName = sqlite3_filename_database(zName);
273741
- mcFile->pMainDb = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273830
+ mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
273742
273831
  mcFile->zFileName = zName;
273743
273832
  SQLITE3MC_DEBUG_LOG("mcVfsOpen WAL Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
273744
273833
  }
@@ -273860,7 +273949,7 @@ static int mcIoClose(sqlite3_file* pFile)
273860
273949
  p->codec = 0;
273861
273950
  }
273862
273951
 
273863
- assert(p->pMainNext == 0 && mcVfsGlobal.pMain != p);
273952
+ assert(p->pMainNext == 0 && p->pVfsMC->pMain != p);
273864
273953
  rc = REALFILE(pFile)->pMethods->xClose(REALFILE(pFile));
273865
273954
  return rc;
273866
273955
  }
@@ -274522,6 +274611,14 @@ static int mcIoFileControl(sqlite3_file* pFile, int op, void* pArg)
274522
274611
  if (doReal)
274523
274612
  {
274524
274613
  rc = REALFILE(pFile)->pMethods->xFileControl(REALFILE(pFile), op, pArg);
274614
+ if (rc == SQLITE_OK && op == SQLITE_FCNTL_VFSNAME)
274615
+ {
274616
+ sqlite3mc_vfs* pVfsMC = p->pVfsMC;
274617
+ char* zIn = *(char**)pArg;
274618
+ char* zOut = sqlite3_mprintf("%s/%z", pVfsMC->base.zName, zIn);
274619
+ *(char**)pArg = zOut;
274620
+ if (zOut == 0) rc = SQLITE_NOMEM;
274621
+ }
274525
274622
  }
274526
274623
  return rc;
274527
274624
  }
@@ -30,10 +30,10 @@
30
30
  #define SQLITE3MC_VERSION_H_
31
31
 
32
32
  #define SQLITE3MC_VERSION_MAJOR 1
33
- #define SQLITE3MC_VERSION_MINOR 3
34
- #define SQLITE3MC_VERSION_RELEASE 10
33
+ #define SQLITE3MC_VERSION_MINOR 4
34
+ #define SQLITE3MC_VERSION_RELEASE 2
35
35
  #define SQLITE3MC_VERSION_SUBRELEASE 0
36
- #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.3.10"
36
+ #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.4.2"
37
37
 
38
38
  #endif /* SQLITE3MC_VERSION_H_ */
39
39
  /*** End of #include "sqlite3mc_version.h" ***/
@@ -192,9 +192,9 @@ extern "C" {
192
192
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
193
193
  ** [sqlite_version()] and [sqlite_source_id()].
194
194
  */
195
- #define SQLITE_VERSION "3.38.2"
196
- #define SQLITE_VERSION_NUMBER 3038002
197
- #define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f"
195
+ #define SQLITE_VERSION "3.38.3"
196
+ #define SQLITE_VERSION_NUMBER 3038003
197
+ #define SQLITE_SOURCE_ID "2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4"
198
198
 
199
199
  /*
200
200
  ** CAPI3REF: Run-Time Library Version Numbers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-sqlite3-multiple-ciphers",
3
- "version": "7.5.1",
3
+ "version": "7.5.2-beta.2",
4
4
  "description": "better-sqlite3 with multiple-cipher encryption support",
5
5
  "homepage": "https://github.com/m4heshd/better-sqlite3-multiple-ciphers",
6
6
  "author": "Mahesh Bandara Wijerathna (m4heshd) <m4heshd@gmail.com>",