better-sqlite3-multiple-ciphers 9.4.1 → 9.5.0

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
@@ -17,10 +17,10 @@ The fastest and simplest library for SQLite3 in Node.js. This particular fork su
17
17
  ## Current versions
18
18
 
19
19
  - ### Stable
20
- - **better-sqlite3-multiple-ciphers** - [`9.4.1`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v9.4.1)
21
- - **better-sqlite3** - [`9.4.1`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v9.4.1)
22
- - **SQLite** - [`3.45.1`](https://www.sqlite.org/releaselog/3_45_1.html)
23
- - **SQLite3 Multiple Ciphers** - [`1.8.3`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.8.3)
20
+ - **better-sqlite3-multiple-ciphers** - [`9.5.0`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v9.5.0)
21
+ - **better-sqlite3** - [`9.5.0`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v9.5.0)
22
+ - **SQLite** - [`3.45.2`](https://www.sqlite.org/releaselog/3_45_2.html)
23
+ - **SQLite3 Multiple Ciphers** - [`1.8.4`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.8.4)
24
24
 
25
25
  - ### Beta
26
26
  - **better-sqlite3-multiple-ciphers** - [`v9.1.2-beta.0`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v9.1.2-beta.0)
package/deps/defines.gypi CHANGED
@@ -29,7 +29,6 @@
29
29
  'SQLITE_ENABLE_UPDATE_DELETE_LIMIT',
30
30
  'SQLITE_LIKE_DOESNT_MATCH_BLOBS',
31
31
  'SQLITE_OMIT_DEPRECATED',
32
- 'SQLITE_OMIT_GET_TABLE',
33
32
  'SQLITE_OMIT_PROGRESS_CALLBACK',
34
33
  'SQLITE_OMIT_SHARED_CACHE',
35
34
  'SQLITE_OMIT_TCL_VARIABLE',
package/deps/download.sh CHANGED
@@ -1,113 +1,112 @@
1
- #!/usr/bin/env bash
2
-
3
- # ===
4
- # This script defines and generates the bundled SQLite3 unit (sqlite3.c).
5
- #
6
- # The following steps are taken:
7
- # 1. populate the shell environment with the defined compile-time options.
8
- # 2. download and extract the SQLite3 source code into a temporary directory.
9
- # 3. run "sh configure" and "make sqlite3.c" within the source directory.
10
- # 4. copy the generated amalgamation into the output directory (./sqlite3).
11
- # 5. export the defined compile-time options to a gyp file (./defines.gypi).
12
- # 6. update the docs (../docs/compilation.md) with details of this distribution.
13
- #
14
- # When a user builds better-sqlite3, the following steps are taken:
15
- # 1. node-gyp loads the previously exported compile-time options (defines.gypi).
16
- # 2. the copy.js script copies the bundled amalgamation into the build folder.
17
- # 3. node-gyp compiles the copied sqlite3.c along with better_sqlite3.cpp.
18
- # 4. node-gyp links the two resulting binaries to generate better_sqlite3.node.
19
- # ===
20
-
21
- YEAR="2022"
22
- VERSION="3380200"
23
-
24
- # Defines below are sorted alphabetically
25
- DEFINES="
26
- HAVE_INT16_T=1
27
- HAVE_INT32_T=1
28
- HAVE_INT8_T=1
29
- HAVE_STDINT_H=1
30
- HAVE_UINT16_T=1
31
- HAVE_UINT32_T=1
32
- HAVE_UINT8_T=1
33
- SQLITE_DEFAULT_CACHE_SIZE=-16000
34
- SQLITE_DEFAULT_FOREIGN_KEYS=1
35
- SQLITE_DEFAULT_MEMSTATUS=0
36
- SQLITE_DEFAULT_WAL_SYNCHRONOUS=1
37
- SQLITE_DQS=0
38
- SQLITE_ENABLE_COLUMN_METADATA
39
- SQLITE_ENABLE_DESERIALIZE
40
- SQLITE_ENABLE_FTS3
41
- SQLITE_ENABLE_FTS3_PARENTHESIS
42
- SQLITE_ENABLE_FTS4
43
- SQLITE_ENABLE_FTS5
44
- SQLITE_ENABLE_GEOPOLY
45
- SQLITE_ENABLE_JSON1
46
- SQLITE_ENABLE_MATH_FUNCTIONS
47
- SQLITE_ENABLE_RTREE
48
- SQLITE_ENABLE_STAT4
49
- SQLITE_ENABLE_UPDATE_DELETE_LIMIT
50
- SQLITE_LIKE_DOESNT_MATCH_BLOBS
51
- SQLITE_OMIT_DEPRECATED
52
- SQLITE_OMIT_GET_TABLE
53
- SQLITE_OMIT_PROGRESS_CALLBACK
54
- SQLITE_OMIT_SHARED_CACHE
55
- SQLITE_OMIT_TCL_VARIABLE
56
- SQLITE_SOUNDEX
57
- SQLITE_THREADSAFE=2
58
- SQLITE_TRACE_SIZE_LIMIT=32
59
- SQLITE_USER_AUTHENTICATION=0
60
- SQLITE_USE_URI=0
61
- "
62
-
63
- # ========== START SCRIPT ========== #
64
-
65
- echo "setting up environment..."
66
- DEPS="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
67
- TEMP="$DEPS/temp"
68
- OUTPUT="$DEPS/sqlite3"
69
- rm -rf "$TEMP"
70
- rm -rf "$OUTPUT"
71
- mkdir -p "$TEMP"
72
- mkdir -p "$OUTPUT"
73
- export CFLAGS=`echo $(echo "$DEFINES" | sed -e "/^\s*$/d" -e "s/^/-D/")`
74
-
75
- echo "downloading source..."
76
- curl -#f "https://www.sqlite.org/$YEAR/sqlite-src-$VERSION.zip" > "$TEMP/source.zip" || exit 1
77
-
78
- echo "extracting source..."
79
- unzip "$TEMP/source.zip" -d "$TEMP" > /dev/null || exit 1
80
- cd "$TEMP/sqlite-src-$VERSION" || exit 1
81
-
82
- echo "configuring amalgamation..."
83
- sh configure > /dev/null || exit 1
84
-
85
- echo "building amalgamation..."
86
- make sqlite3.c > /dev/null || exit 1
87
-
88
- echo "copying amalgamation..."
89
- cp sqlite3.c sqlite3.h sqlite3ext.h "$OUTPUT/" || exit 1
90
-
91
- echo "updating gyp configs..."
92
- GYP="$DEPS/defines.gypi"
93
- printf "# THIS FILE IS AUTOMATICALLY GENERATED BY deps/download.sh (DO NOT EDIT)\n\n{\n 'defines': [\n" > "$GYP"
94
- printf "$DEFINES" | sed -e "/^\s*$/d" -e "s/\(.*\)/ '\1',/" >> "$GYP"
95
- printf " ],\n}\n" >> "$GYP"
96
-
97
- echo "updating docs..."
98
- DOCS="$DEPS/../docs/compilation.md"
99
- MAJOR=`expr "${VERSION:0:1}" + 0`
100
- MINOR=`expr "${VERSION:1:2}" + 0`
101
- PATCH=`expr "${VERSION:3:2}" + 0`
102
- sed -Ei.bak -e "s/version [0-9]+\.[0-9]+\.[0-9]+/version $MAJOR.$MINOR.$PATCH/g" "$DOCS"
103
- sed -i.bak -e "/^SQLITE_/,\$d" "$DOCS"
104
- sed -i.bak -e "/^HAVE_/,\$d" "$DOCS"
105
- rm "$DOCS".bak
106
- printf "$DEFINES" | sed -e "/^\s*$/d" >> "$DOCS"
107
- printf "\`\`\`\n" >> "$DOCS"
108
-
109
- echo "cleaning up..."
110
- cd - > /dev/null || exit 1
111
- rm -rf "$TEMP"
112
-
113
- echo "done!"
1
+ #!/usr/bin/env bash
2
+
3
+ # ===
4
+ # This script defines and generates the bundled SQLite3 unit (sqlite3.c).
5
+ #
6
+ # The following steps are taken:
7
+ # 1. populate the shell environment with the defined compile-time options.
8
+ # 2. download and extract the SQLite3 source code into a temporary directory.
9
+ # 3. run "sh configure" and "make sqlite3.c" within the source directory.
10
+ # 4. copy the generated amalgamation into the output directory (./sqlite3).
11
+ # 5. export the defined compile-time options to a gyp file (./defines.gypi).
12
+ # 6. update the docs (../docs/compilation.md) with details of this distribution.
13
+ #
14
+ # When a user builds better-sqlite3, the following steps are taken:
15
+ # 1. node-gyp loads the previously exported compile-time options (defines.gypi).
16
+ # 2. the copy.js script copies the bundled amalgamation into the build folder.
17
+ # 3. node-gyp compiles the copied sqlite3.c along with better_sqlite3.cpp.
18
+ # 4. node-gyp links the two resulting binaries to generate better_sqlite3.node.
19
+ # ===
20
+
21
+ YEAR="2022"
22
+ VERSION="3380200"
23
+
24
+ # Defines below are sorted alphabetically
25
+ DEFINES="
26
+ HAVE_INT16_T=1
27
+ HAVE_INT32_T=1
28
+ HAVE_INT8_T=1
29
+ HAVE_STDINT_H=1
30
+ HAVE_UINT16_T=1
31
+ HAVE_UINT32_T=1
32
+ HAVE_UINT8_T=1
33
+ SQLITE_DEFAULT_CACHE_SIZE=-16000
34
+ SQLITE_DEFAULT_FOREIGN_KEYS=1
35
+ SQLITE_DEFAULT_MEMSTATUS=0
36
+ SQLITE_DEFAULT_WAL_SYNCHRONOUS=1
37
+ SQLITE_DQS=0
38
+ SQLITE_ENABLE_COLUMN_METADATA
39
+ SQLITE_ENABLE_DESERIALIZE
40
+ SQLITE_ENABLE_FTS3
41
+ SQLITE_ENABLE_FTS3_PARENTHESIS
42
+ SQLITE_ENABLE_FTS4
43
+ SQLITE_ENABLE_FTS5
44
+ SQLITE_ENABLE_GEOPOLY
45
+ SQLITE_ENABLE_JSON1
46
+ SQLITE_ENABLE_MATH_FUNCTIONS
47
+ SQLITE_ENABLE_RTREE
48
+ SQLITE_ENABLE_STAT4
49
+ SQLITE_ENABLE_UPDATE_DELETE_LIMIT
50
+ SQLITE_LIKE_DOESNT_MATCH_BLOBS
51
+ SQLITE_OMIT_DEPRECATED
52
+ SQLITE_OMIT_PROGRESS_CALLBACK
53
+ SQLITE_OMIT_SHARED_CACHE
54
+ SQLITE_OMIT_TCL_VARIABLE
55
+ SQLITE_SOUNDEX
56
+ SQLITE_THREADSAFE=2
57
+ SQLITE_TRACE_SIZE_LIMIT=32
58
+ SQLITE_USER_AUTHENTICATION=0
59
+ SQLITE_USE_URI=0
60
+ "
61
+
62
+ # ========== START SCRIPT ========== #
63
+
64
+ echo "setting up environment..."
65
+ DEPS="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
66
+ TEMP="$DEPS/temp"
67
+ OUTPUT="$DEPS/sqlite3"
68
+ rm -rf "$TEMP"
69
+ rm -rf "$OUTPUT"
70
+ mkdir -p "$TEMP"
71
+ mkdir -p "$OUTPUT"
72
+ export CFLAGS=`echo $(echo "$DEFINES" | sed -e "/^\s*$/d" -e "s/^/-D/")`
73
+
74
+ echo "downloading source..."
75
+ curl -#f "https://www.sqlite.org/$YEAR/sqlite-src-$VERSION.zip" > "$TEMP/source.zip" || exit 1
76
+
77
+ echo "extracting source..."
78
+ unzip "$TEMP/source.zip" -d "$TEMP" > /dev/null || exit 1
79
+ cd "$TEMP/sqlite-src-$VERSION" || exit 1
80
+
81
+ echo "configuring amalgamation..."
82
+ sh configure > /dev/null || exit 1
83
+
84
+ echo "building amalgamation..."
85
+ make sqlite3.c > /dev/null || exit 1
86
+
87
+ echo "copying amalgamation..."
88
+ cp sqlite3.c sqlite3.h sqlite3ext.h "$OUTPUT/" || exit 1
89
+
90
+ echo "updating gyp configs..."
91
+ GYP="$DEPS/defines.gypi"
92
+ printf "# THIS FILE IS AUTOMATICALLY GENERATED BY deps/download.sh (DO NOT EDIT)\n\n{\n 'defines': [\n" > "$GYP"
93
+ printf "$DEFINES" | sed -e "/^\s*$/d" -e "s/\(.*\)/ '\1',/" >> "$GYP"
94
+ printf " ],\n}\n" >> "$GYP"
95
+
96
+ echo "updating docs..."
97
+ DOCS="$DEPS/../docs/compilation.md"
98
+ MAJOR=`expr "${VERSION:0:1}" + 0`
99
+ MINOR=`expr "${VERSION:1:2}" + 0`
100
+ PATCH=`expr "${VERSION:3:2}" + 0`
101
+ sed -Ei.bak -e "s/version [0-9]+\.[0-9]+\.[0-9]+/version $MAJOR.$MINOR.$PATCH/g" "$DOCS"
102
+ sed -i.bak -e "/^SQLITE_/,\$d" "$DOCS"
103
+ sed -i.bak -e "/^HAVE_/,\$d" "$DOCS"
104
+ rm "$DOCS".bak
105
+ printf "$DEFINES" | sed -e "/^\s*$/d" >> "$DOCS"
106
+ printf "\`\`\`\n" >> "$DOCS"
107
+
108
+ echo "cleaning up..."
109
+ cd - > /dev/null || exit 1
110
+ rm -rf "$TEMP"
111
+
112
+ echo "done!"
package/deps/setup.ps1 CHANGED
@@ -2,7 +2,7 @@
2
2
  $ErrorActionPreference = "Stop"
3
3
 
4
4
  # SQLite Info
5
- $SQLITEMC_VER = "v1.8.3"
5
+ $SQLITEMC_VER = "v1.8.4"
6
6
  $API_URL = "https://api.github.com/repos/utelle/SQLite3MultipleCiphers/releases/tags/" + $SQLITEMC_VER
7
7
 
8
8
  # Paths
@@ -65,14 +65,10 @@ void sqlite3mc_shutdown(void);
65
65
  */
66
66
 
67
67
  /*
68
- ** Enable the user authentication feature
68
+ ** Disable the user authentication feature by default
69
69
  */
70
+ #ifdef SQLITE_USER_AUTHENTICATION
70
71
  #if !SQLITE_USER_AUTHENTICATION
71
- /* Option not defined or explicitly disabled */
72
- #ifndef SQLITE_USER_AUTHENTICATION
73
- /* Option not defined, therefore enable by default */
74
- #define SQLITE_USER_AUTHENTICATION 1
75
- #else
76
72
  /* Option defined and disabled, therefore undefine option */
77
73
  #undef SQLITE_USER_AUTHENTICATION
78
74
  #endif
@@ -133,7 +129,7 @@ extern SQLITE_API LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
133
129
  /*** Begin of #include "sqlite3patched.c" ***/
134
130
  /******************************************************************************
135
131
  ** This file is an amalgamation of many separate C source files from SQLite
136
- ** version 3.45.1. By combining all the individual C code files into this
132
+ ** version 3.45.2. By combining all the individual C code files into this
137
133
  ** single large file, the entire code can be compiled as a single translation
138
134
  ** unit. This allows many compilers to do optimizations that would not be
139
135
  ** possible if the files were compiled separately. Performance improvements
@@ -151,7 +147,7 @@ extern SQLITE_API LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
151
147
  ** separate file. This file contains only code for the core SQLite library.
152
148
  **
153
149
  ** The content in this amalgamation comes from Fossil check-in
154
- ** e876e51a0ed5c5b3126f52e532044363a014.
150
+ ** d8cd6d49b46a395b13955387d05e9e1a2a47.
155
151
  */
156
152
  #define SQLITE_CORE 1
157
153
  #define SQLITE_AMALGAMATION 1
@@ -592,9 +588,9 @@ extern "C" {
592
588
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
593
589
  ** [sqlite_version()] and [sqlite_source_id()].
594
590
  */
595
- #define SQLITE_VERSION "3.45.1"
596
- #define SQLITE_VERSION_NUMBER 3045001
597
- #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
591
+ #define SQLITE_VERSION "3.45.2"
592
+ #define SQLITE_VERSION_NUMBER 3045002
593
+ #define SQLITE_SOURCE_ID "2024-03-12 11:06:23 d8cd6d49b46a395b13955387d05e9e1a2a47e54fb99f3c9b59835bbefad6af77"
598
594
 
599
595
  /*
600
596
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -866,6 +862,8 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
866
862
  ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
867
863
  ** <li> The application must not modify the SQL statement text passed into
868
864
  ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
865
+ ** <li> The application must not dereference the arrays or string pointers
866
+ ** passed as the 3rd and 4th callback parameters after it returns.
869
867
  ** </ul>
870
868
  */
871
869
  SQLITE_API int sqlite3_exec(
@@ -15241,6 +15239,7 @@ SQLITE_PRIVATE u32 sqlite3TreeTrace;
15241
15239
  ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15242
15240
  ** 0x00020000 Transform DISTINCT into GROUP BY
15243
15241
  ** 0x00040000 SELECT tree dump after all code has been generated
15242
+ ** 0x00080000 NOT NULL strength reduction
15244
15243
  */
15245
15244
 
15246
15245
  /*
@@ -19490,6 +19489,7 @@ struct NameContext {
19490
19489
  #define NC_InAggFunc 0x020000 /* True if analyzing arguments to an agg func */
19491
19490
  #define NC_FromDDL 0x040000 /* SQL text comes from sqlite_schema */
19492
19491
  #define NC_NoSelect 0x080000 /* Do not descend into sub-selects */
19492
+ #define NC_Where 0x100000 /* Processing WHERE clause of a SELECT */
19493
19493
  #define NC_OrderAgg 0x8000000 /* Has an aggregate other than count/min/max */
19494
19494
 
19495
19495
  /*
@@ -19513,6 +19513,7 @@ struct Upsert {
19513
19513
  Expr *pUpsertWhere; /* WHERE clause for the ON CONFLICT UPDATE */
19514
19514
  Upsert *pNextUpsert; /* Next ON CONFLICT clause in the list */
19515
19515
  u8 isDoUpdate; /* True for DO UPDATE. False for DO NOTHING */
19516
+ u8 isDup; /* True if 2nd or later with same pUpsertIdx */
19516
19517
  /* Above this point is the parse tree for the ON CONFLICT clauses.
19517
19518
  ** The next group of fields stores intermediate data. */
19518
19519
  void *pToFree; /* Free memory when deleting the Upsert object */
@@ -21588,7 +21589,7 @@ SQLITE_PRIVATE With *sqlite3WithPush(Parse*, With*, u8);
21588
21589
  SQLITE_PRIVATE Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*);
21589
21590
  SQLITE_PRIVATE void sqlite3UpsertDelete(sqlite3*,Upsert*);
21590
21591
  SQLITE_PRIVATE Upsert *sqlite3UpsertDup(sqlite3*,Upsert*);
21591
- SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*);
21592
+ SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*,Upsert*);
21592
21593
  SQLITE_PRIVATE void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int);
21593
21594
  SQLITE_PRIVATE Upsert *sqlite3UpsertOfIndex(Upsert*,Index*);
21594
21595
  SQLITE_PRIVATE int sqlite3UpsertNextIsIPK(Upsert*);
@@ -31459,6 +31460,7 @@ SQLITE_API void sqlite3_str_vappendf(
31459
31460
  if( xtype==etFLOAT ){
31460
31461
  iRound = -precision;
31461
31462
  }else if( xtype==etGENERIC ){
31463
+ if( precision==0 ) precision = 1;
31462
31464
  iRound = precision;
31463
31465
  }else{
31464
31466
  iRound = precision+1;
@@ -35349,6 +35351,9 @@ do_atof_calc:
35349
35351
  u64 s2;
35350
35352
  rr[0] = (double)s;
35351
35353
  s2 = (u64)rr[0];
35354
+ #if defined(_MSC_VER) && _MSC_VER<1700
35355
+ if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); }
35356
+ #endif
35352
35357
  rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s);
35353
35358
  if( e>0 ){
35354
35359
  while( e>=100 ){
@@ -35791,7 +35796,7 @@ SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRou
35791
35796
  assert( p->n>0 );
35792
35797
  assert( p->n<sizeof(p->zBuf) );
35793
35798
  p->iDP = p->n + exp;
35794
- if( iRound<0 ){
35799
+ if( iRound<=0 ){
35795
35800
  iRound = p->iDP - iRound;
35796
35801
  if( iRound==0 && p->zBuf[i+1]>='5' ){
35797
35802
  iRound = 1;
@@ -53416,6 +53421,14 @@ SQLITE_API unsigned char *sqlite3_serialize(
53416
53421
  pOut = 0;
53417
53422
  }else{
53418
53423
  sz = sqlite3_column_int64(pStmt, 0)*szPage;
53424
+ if( sz==0 ){
53425
+ sqlite3_reset(pStmt);
53426
+ sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
53427
+ rc = sqlite3_step(pStmt);
53428
+ if( rc==SQLITE_ROW ){
53429
+ sz = sqlite3_column_int64(pStmt, 0)*szPage;
53430
+ }
53431
+ }
53419
53432
  if( piSize ) *piSize = sz;
53420
53433
  if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
53421
53434
  pOut = 0;
@@ -77243,7 +77256,10 @@ static int fillInCell(
77243
77256
  n = nHeader + nPayload;
77244
77257
  testcase( n==3 );
77245
77258
  testcase( n==4 );
77246
- if( n<4 ) n = 4;
77259
+ if( n<4 ){
77260
+ n = 4;
77261
+ pPayload[nPayload] = 0;
77262
+ }
77247
77263
  *pnSize = n;
77248
77264
  assert( nSrc<=nPayload );
77249
77265
  testcase( nSrc<nPayload );
@@ -79689,7 +79705,10 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
79689
79705
  if( flags & BTREE_PREFORMAT ){
79690
79706
  rc = SQLITE_OK;
79691
79707
  szNew = p->pBt->nPreformatSize;
79692
- if( szNew<4 ) szNew = 4;
79708
+ if( szNew<4 ){
79709
+ szNew = 4;
79710
+ newCell[3] = 0;
79711
+ }
79693
79712
  if( ISAUTOVACUUM(p->pBt) && szNew>pPage->maxLocal ){
79694
79713
  CellInfo info;
79695
79714
  pPage->xParseCell(pPage, newCell, &info);
@@ -88534,6 +88553,23 @@ static void serialGet(
88534
88553
  pMem->flags = IsNaN(x) ? MEM_Null : MEM_Real;
88535
88554
  }
88536
88555
  }
88556
+ static int serialGet7(
88557
+ const unsigned char *buf, /* Buffer to deserialize from */
88558
+ Mem *pMem /* Memory cell to write value into */
88559
+ ){
88560
+ u64 x = FOUR_BYTE_UINT(buf);
88561
+ u32 y = FOUR_BYTE_UINT(buf+4);
88562
+ x = (x<<32) + y;
88563
+ assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 );
88564
+ swapMixedEndianFloat(x);
88565
+ memcpy(&pMem->u.r, &x, sizeof(x));
88566
+ if( IsNaN(x) ){
88567
+ pMem->flags = MEM_Null;
88568
+ return 1;
88569
+ }
88570
+ pMem->flags = MEM_Real;
88571
+ return 0;
88572
+ }
88537
88573
  SQLITE_PRIVATE void sqlite3VdbeSerialGet(
88538
88574
  const unsigned char *buf, /* Buffer to deserialize from */
88539
88575
  u32 serial_type, /* Serial type to deserialize */
@@ -89213,7 +89249,7 @@ SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
89213
89249
  }else if( serial_type==0 ){
89214
89250
  rc = -1;
89215
89251
  }else if( serial_type==7 ){
89216
- sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
89252
+ serialGet7(&aKey1[d1], &mem1);
89217
89253
  rc = -sqlite3IntFloatCompare(pRhs->u.i, mem1.u.r);
89218
89254
  }else{
89219
89255
  i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
@@ -89238,14 +89274,18 @@ SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
89238
89274
  }else if( serial_type==0 ){
89239
89275
  rc = -1;
89240
89276
  }else{
89241
- sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
89242
89277
  if( serial_type==7 ){
89243
- if( mem1.u.r<pRhs->u.r ){
89278
+ if( serialGet7(&aKey1[d1], &mem1) ){
89279
+ rc = -1; /* mem1 is a NaN */
89280
+ }else if( mem1.u.r<pRhs->u.r ){
89244
89281
  rc = -1;
89245
89282
  }else if( mem1.u.r>pRhs->u.r ){
89246
89283
  rc = +1;
89284
+ }else{
89285
+ assert( rc==0 );
89247
89286
  }
89248
89287
  }else{
89288
+ sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
89249
89289
  rc = sqlite3IntFloatCompare(mem1.u.i, pRhs->u.r);
89250
89290
  }
89251
89291
  }
@@ -89315,7 +89355,14 @@ SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
89315
89355
  /* RHS is null */
89316
89356
  else{
89317
89357
  serial_type = aKey1[idx1];
89318
- rc = (serial_type!=0 && serial_type!=10);
89358
+ if( serial_type==0
89359
+ || serial_type==10
89360
+ || (serial_type==7 && serialGet7(&aKey1[d1], &mem1)!=0)
89361
+ ){
89362
+ assert( rc==0 );
89363
+ }else{
89364
+ rc = 1;
89365
+ }
89319
89366
  }
89320
89367
 
89321
89368
  if( rc!=0 ){
@@ -95013,7 +95060,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
95013
95060
  }
95014
95061
  }
95015
95062
  }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
95016
- if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95063
+ if( (flags1 & MEM_Str)!=0 ){
95064
+ pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
95065
+ }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95017
95066
  testcase( pIn1->flags & MEM_Int );
95018
95067
  testcase( pIn1->flags & MEM_Real );
95019
95068
  testcase( pIn1->flags & MEM_IntReal );
@@ -95022,7 +95071,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
95022
95071
  flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
95023
95072
  if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
95024
95073
  }
95025
- if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95074
+ if( (flags3 & MEM_Str)!=0 ){
95075
+ pIn3->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
95076
+ }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95026
95077
  testcase( pIn3->flags & MEM_Int );
95027
95078
  testcase( pIn3->flags & MEM_Real );
95028
95079
  testcase( pIn3->flags & MEM_IntReal );
@@ -106367,6 +106418,8 @@ static void resolveAlias(
106367
106418
  assert( iCol>=0 && iCol<pEList->nExpr );
106368
106419
  pOrig = pEList->a[iCol].pExpr;
106369
106420
  assert( pOrig!=0 );
106421
+ assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
106422
+ if( pExpr->pAggInfo ) return;
106370
106423
  db = pParse->db;
106371
106424
  pDup = sqlite3ExprDup(db, pOrig, 0);
106372
106425
  if( db->mallocFailed ){
@@ -107252,6 +107305,19 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
107252
107305
  ** resolved. This prevents "column" from being counted as having been
107253
107306
  ** referenced, which might prevent a SELECT from being erroneously
107254
107307
  ** marked as correlated.
107308
+ **
107309
+ ** 2024-03-28: Beware of aggregates. A bare column of aggregated table
107310
+ ** can still evaluate to NULL even though it is marked as NOT NULL.
107311
+ ** Example:
107312
+ **
107313
+ ** CREATE TABLE t1(a INT NOT NULL);
107314
+ ** SELECT a, a IS NULL, a IS NOT NULL, count(*) FROM t1;
107315
+ **
107316
+ ** The "a IS NULL" and "a IS NOT NULL" expressions cannot be optimized
107317
+ ** here because at the time this case is hit, we do not yet know whether
107318
+ ** or not t1 is being aggregated. We have to assume the worst and omit
107319
+ ** the optimization. The only time it is safe to apply this optimization
107320
+ ** is within the WHERE clause.
107255
107321
  */
107256
107322
  case TK_NOTNULL:
107257
107323
  case TK_ISNULL: {
@@ -107262,19 +107328,36 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
107262
107328
  anRef[i] = p->nRef;
107263
107329
  }
107264
107330
  sqlite3WalkExpr(pWalker, pExpr->pLeft);
107265
- if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
107266
- testcase( ExprHasProperty(pExpr, EP_OuterON) );
107267
- assert( !ExprHasProperty(pExpr, EP_IntValue) );
107268
- pExpr->u.iValue = (pExpr->op==TK_NOTNULL);
107269
- pExpr->flags |= EP_IntValue;
107270
- pExpr->op = TK_INTEGER;
107331
+ if( IN_RENAME_OBJECT ) return WRC_Prune;
107332
+ if( sqlite3ExprCanBeNull(pExpr->pLeft) ){
107333
+ /* The expression can be NULL. So the optimization does not apply */
107334
+ return WRC_Prune;
107335
+ }
107271
107336
 
107272
- for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
107273
- p->nRef = anRef[i];
107337
+ for(i=0, p=pNC; p; p=p->pNext, i++){
107338
+ if( (p->ncFlags & NC_Where)==0 ){
107339
+ return WRC_Prune; /* Not in a WHERE clause. Unsafe to optimize. */
107274
107340
  }
107275
- sqlite3ExprDelete(pParse->db, pExpr->pLeft);
107276
- pExpr->pLeft = 0;
107277
107341
  }
107342
+ testcase( ExprHasProperty(pExpr, EP_OuterON) );
107343
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
107344
+ #if TREETRACE_ENABLED
107345
+ if( sqlite3TreeTrace & 0x80000 ){
107346
+ sqlite3DebugPrintf(
107347
+ "NOT NULL strength reduction converts the following to %d:\n",
107348
+ pExpr->op==TK_NOTNULL
107349
+ );
107350
+ sqlite3ShowExpr(pExpr);
107351
+ }
107352
+ #endif /* TREETRACE_ENABLED */
107353
+ pExpr->u.iValue = (pExpr->op==TK_NOTNULL);
107354
+ pExpr->flags |= EP_IntValue;
107355
+ pExpr->op = TK_INTEGER;
107356
+ for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
107357
+ p->nRef = anRef[i];
107358
+ }
107359
+ sqlite3ExprDelete(pParse->db, pExpr->pLeft);
107360
+ pExpr->pLeft = 0;
107278
107361
  return WRC_Prune;
107279
107362
  }
107280
107363
 
@@ -108174,7 +108257,9 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
108174
108257
  }
108175
108258
  if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
108176
108259
  }
108260
+ sNC.ncFlags |= NC_Where;
108177
108261
  if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
108262
+ sNC.ncFlags &= ~NC_Where;
108178
108263
 
108179
108264
  /* Resolve names in table-valued-function arguments */
108180
108265
  for(i=0; i<p->pSrc->nSrc; i++){
@@ -129107,13 +129192,13 @@ SQLITE_PRIVATE void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue){
129107
129192
  double r1, r2;
129108
129193
  const char *zVal;
129109
129194
  r1 = sqlite3_value_double(pValue);
129110
- sqlite3_str_appendf(pStr, "%!.15g", r1);
129195
+ sqlite3_str_appendf(pStr, "%!0.15g", r1);
129111
129196
  zVal = sqlite3_str_value(pStr);
129112
129197
  if( zVal ){
129113
129198
  sqlite3AtoF(zVal, &r2, pStr->nChar, SQLITE_UTF8);
129114
129199
  if( r1!=r2 ){
129115
129200
  sqlite3_str_reset(pStr);
129116
- sqlite3_str_appendf(pStr, "%!.20e", r1);
129201
+ sqlite3_str_appendf(pStr, "%!0.20e", r1);
129117
129202
  }
129118
129203
  }
129119
129204
  break;
@@ -129415,7 +129500,7 @@ static void replaceFunc(
129415
129500
  }
129416
129501
  if( zPattern[0]==0 ){
129417
129502
  assert( sqlite3_value_type(argv[1])!=SQLITE_NULL );
129418
- sqlite3_result_value(context, argv[0]);
129503
+ sqlite3_result_text(context, (const char*)zStr, nStr, SQLITE_TRANSIENT);
129419
129504
  return;
129420
129505
  }
129421
129506
  nPattern = sqlite3_value_bytes(argv[1]);
@@ -133335,7 +133420,7 @@ SQLITE_PRIVATE void sqlite3Insert(
133335
133420
  pNx->iDataCur = iDataCur;
133336
133421
  pNx->iIdxCur = iIdxCur;
133337
133422
  if( pNx->pUpsertTarget ){
133338
- if( sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx) ){
133423
+ if( sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx, pUpsert) ){
133339
133424
  goto insert_cleanup;
133340
133425
  }
133341
133426
  }
@@ -139634,31 +139719,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
139634
139719
  int mxCol; /* Maximum non-virtual column number */
139635
139720
 
139636
139721
  if( pObjTab && pObjTab!=pTab ) continue;
139637
- if( !IsOrdinaryTable(pTab) ){
139638
- #ifndef SQLITE_OMIT_VIRTUALTABLE
139639
- sqlite3_vtab *pVTab;
139640
- int a1;
139641
- if( !IsVirtual(pTab) ) continue;
139642
- if( pTab->nCol<=0 ){
139643
- const char *zMod = pTab->u.vtab.azArg[0];
139644
- if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
139645
- }
139646
- sqlite3ViewGetColumnNames(pParse, pTab);
139647
- if( pTab->u.vtab.p==0 ) continue;
139648
- pVTab = pTab->u.vtab.p->pVtab;
139649
- if( NEVER(pVTab==0) ) continue;
139650
- if( NEVER(pVTab->pModule==0) ) continue;
139651
- if( pVTab->pModule->iVersion<4 ) continue;
139652
- if( pVTab->pModule->xIntegrity==0 ) continue;
139653
- sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
139654
- pTab->nTabRef++;
139655
- sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF);
139656
- a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
139657
- integrityCheckResultRow(v);
139658
- sqlite3VdbeJumpHere(v, a1);
139659
- #endif
139660
- continue;
139661
- }
139722
+ if( !IsOrdinaryTable(pTab) ) continue;
139662
139723
  if( isQuick || HasRowid(pTab) ){
139663
139724
  pPk = 0;
139664
139725
  r2 = 0;
@@ -139793,6 +139854,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
139793
139854
  ** is REAL, we have to load the actual data using OP_Column
139794
139855
  ** to reliably determine if the value is a NULL. */
139795
139856
  sqlite3VdbeAddOp3(v, OP_Column, p1, p3, 3);
139857
+ sqlite3ColumnDefault(v, pTab, j, 3);
139796
139858
  jmp3 = sqlite3VdbeAddOp2(v, OP_NotNull, 3, labelOk);
139797
139859
  VdbeCoverage(v);
139798
139860
  }
@@ -139983,6 +140045,38 @@ SQLITE_PRIVATE void sqlite3Pragma(
139983
140045
  }
139984
140046
  }
139985
140047
  }
140048
+
140049
+ #ifndef SQLITE_OMIT_VIRTUALTABLE
140050
+ /* Second pass to invoke the xIntegrity method on all virtual
140051
+ ** tables.
140052
+ */
140053
+ for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
140054
+ Table *pTab = sqliteHashData(x);
140055
+ sqlite3_vtab *pVTab;
140056
+ int a1;
140057
+ if( pObjTab && pObjTab!=pTab ) continue;
140058
+ if( IsOrdinaryTable(pTab) ) continue;
140059
+ if( !IsVirtual(pTab) ) continue;
140060
+ if( pTab->nCol<=0 ){
140061
+ const char *zMod = pTab->u.vtab.azArg[0];
140062
+ if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
140063
+ }
140064
+ sqlite3ViewGetColumnNames(pParse, pTab);
140065
+ if( pTab->u.vtab.p==0 ) continue;
140066
+ pVTab = pTab->u.vtab.p->pVtab;
140067
+ if( NEVER(pVTab==0) ) continue;
140068
+ if( NEVER(pVTab->pModule==0) ) continue;
140069
+ if( pVTab->pModule->iVersion<4 ) continue;
140070
+ if( pVTab->pModule->xIntegrity==0 ) continue;
140071
+ sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
140072
+ pTab->nTabRef++;
140073
+ sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF);
140074
+ a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
140075
+ integrityCheckResultRow(v);
140076
+ sqlite3VdbeJumpHere(v, a1);
140077
+ continue;
140078
+ }
140079
+ #endif
139986
140080
  }
139987
140081
  {
139988
140082
  static const int iLn = VDBE_OFFSET_LINENO(2);
@@ -153620,7 +153714,8 @@ SQLITE_PRIVATE Upsert *sqlite3UpsertNew(
153620
153714
  SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(
153621
153715
  Parse *pParse, /* The parsing context */
153622
153716
  SrcList *pTabList, /* Table into which we are inserting */
153623
- Upsert *pUpsert /* The ON CONFLICT clauses */
153717
+ Upsert *pUpsert, /* The ON CONFLICT clauses */
153718
+ Upsert *pAll /* Complete list of all ON CONFLICT clauses */
153624
153719
  ){
153625
153720
  Table *pTab; /* That table into which we are inserting */
153626
153721
  int rc; /* Result code */
@@ -153723,6 +153818,14 @@ SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(
153723
153818
  continue;
153724
153819
  }
153725
153820
  pUpsert->pUpsertIdx = pIdx;
153821
+ if( sqlite3UpsertOfIndex(pAll,pIdx)!=pUpsert ){
153822
+ /* Really this should be an error. The isDup ON CONFLICT clause will
153823
+ ** never fire. But this problem was not discovered until three years
153824
+ ** after multi-CONFLICT upsert was added, and so we silently ignore
153825
+ ** the problem to prevent breaking applications that might actually
153826
+ ** have redundant ON CONFLICT clauses. */
153827
+ pUpsert->isDup = 1;
153828
+ }
153726
153829
  break;
153727
153830
  }
153728
153831
  if( pUpsert->pUpsertIdx==0 ){
@@ -153749,9 +153852,13 @@ SQLITE_PRIVATE int sqlite3UpsertNextIsIPK(Upsert *pUpsert){
153749
153852
  Upsert *pNext;
153750
153853
  if( NEVER(pUpsert==0) ) return 0;
153751
153854
  pNext = pUpsert->pNextUpsert;
153752
- if( pNext==0 ) return 1;
153753
- if( pNext->pUpsertTarget==0 ) return 1;
153754
- if( pNext->pUpsertIdx==0 ) return 1;
153855
+ while( 1 /*exit-by-return*/ ){
153856
+ if( pNext==0 ) return 1;
153857
+ if( pNext->pUpsertTarget==0 ) return 1;
153858
+ if( pNext->pUpsertIdx==0 ) return 1;
153859
+ if( !pNext->isDup ) return 0;
153860
+ pNext = pNext->pNextUpsert;
153861
+ }
153755
153862
  return 0;
153756
153863
  }
153757
153864
 
@@ -204953,6 +205060,7 @@ json_parse_restart:
204953
205060
  case '[': {
204954
205061
  /* Parse array */
204955
205062
  iThis = pParse->nBlob;
205063
+ assert( i<=(u32)pParse->nJson );
204956
205064
  jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
204957
205065
  iStart = pParse->nBlob;
204958
205066
  if( pParse->oom ) return -1;
@@ -205351,6 +205459,10 @@ static void jsonReturnStringAsBlob(JsonString *pStr){
205351
205459
  JsonParse px;
205352
205460
  memset(&px, 0, sizeof(px));
205353
205461
  jsonStringTerminate(pStr);
205462
+ if( pStr->eErr ){
205463
+ sqlite3_result_error_nomem(pStr->pCtx);
205464
+ return;
205465
+ }
205354
205466
  px.zJson = pStr->zBuf;
205355
205467
  px.nJson = pStr->nUsed;
205356
205468
  px.db = sqlite3_context_db_handle(pStr->pCtx);
@@ -206676,8 +206788,9 @@ rebuild_from_cache:
206676
206788
  }
206677
206789
  p->zJson = (char*)sqlite3_value_text(pArg);
206678
206790
  p->nJson = sqlite3_value_bytes(pArg);
206791
+ if( db->mallocFailed ) goto json_pfa_oom;
206679
206792
  if( p->nJson==0 ) goto json_pfa_malformed;
206680
- if( NEVER(p->zJson==0) ) goto json_pfa_oom;
206793
+ assert( p->zJson!=0 );
206681
206794
  if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
206682
206795
  if( flgs & JSON_KEEPERROR ){
206683
206796
  p->nErr = 1;
@@ -206843,10 +206956,10 @@ static void jsonDebugPrintBlob(
206843
206956
  if( sz==0 && x<=JSONB_FALSE ){
206844
206957
  sqlite3_str_append(pOut, "\n", 1);
206845
206958
  }else{
206846
- u32 i;
206959
+ u32 j;
206847
206960
  sqlite3_str_appendall(pOut, ": \"");
206848
- for(i=iStart+n; i<iStart+n+sz; i++){
206849
- u8 c = pParse->aBlob[i];
206961
+ for(j=iStart+n; j<iStart+n+sz; j++){
206962
+ u8 c = pParse->aBlob[j];
206850
206963
  if( c<0x20 || c>=0x7f ) c = '.';
206851
206964
  sqlite3_str_append(pOut, (char*)&c, 1);
206852
206965
  }
@@ -208254,6 +208367,9 @@ static int jsonEachColumn(
208254
208367
  case JEACH_VALUE: {
208255
208368
  u32 i = jsonSkipLabel(p);
208256
208369
  jsonReturnFromBlob(&p->sParse, i, ctx, 1);
208370
+ if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){
208371
+ sqlite3_result_subtype(ctx, JSON_SUBTYPE);
208372
+ }
208257
208373
  break;
208258
208374
  }
208259
208375
  case JEACH_TYPE: {
@@ -208300,9 +208416,9 @@ static int jsonEachColumn(
208300
208416
  case JEACH_JSON: {
208301
208417
  if( p->sParse.zJson==0 ){
208302
208418
  sqlite3_result_blob(ctx, p->sParse.aBlob, p->sParse.nBlob,
208303
- SQLITE_STATIC);
208419
+ SQLITE_TRANSIENT);
208304
208420
  }else{
208305
- sqlite3_result_text(ctx, p->sParse.zJson, -1, SQLITE_STATIC);
208421
+ sqlite3_result_text(ctx, p->sParse.zJson, -1, SQLITE_TRANSIENT);
208306
208422
  }
208307
208423
  break;
208308
208424
  }
@@ -209328,11 +209444,9 @@ static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){
209328
209444
  ** Clear the Rtree.pNodeBlob object
209329
209445
  */
209330
209446
  static void nodeBlobReset(Rtree *pRtree){
209331
- if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
209332
- sqlite3_blob *pBlob = pRtree->pNodeBlob;
209333
- pRtree->pNodeBlob = 0;
209334
- sqlite3_blob_close(pBlob);
209335
- }
209447
+ sqlite3_blob *pBlob = pRtree->pNodeBlob;
209448
+ pRtree->pNodeBlob = 0;
209449
+ sqlite3_blob_close(pBlob);
209336
209450
  }
209337
209451
 
209338
209452
  /*
@@ -209376,7 +209490,6 @@ static int nodeAcquire(
209376
209490
  &pRtree->pNodeBlob);
209377
209491
  }
209378
209492
  if( rc ){
209379
- nodeBlobReset(pRtree);
209380
209493
  *ppNode = 0;
209381
209494
  /* If unable to open an sqlite3_blob on the desired row, that can only
209382
209495
  ** be because the shadow tables hold erroneous data. */
@@ -209436,6 +209549,7 @@ static int nodeAcquire(
209436
209549
  }
209437
209550
  *ppNode = pNode;
209438
209551
  }else{
209552
+ nodeBlobReset(pRtree);
209439
209553
  if( pNode ){
209440
209554
  pRtree->nNodeRef--;
209441
209555
  sqlite3_free(pNode);
@@ -209580,6 +209694,7 @@ static void nodeGetCoord(
209580
209694
  int iCoord, /* Which coordinate to extract */
209581
209695
  RtreeCoord *pCoord /* OUT: Space to write result to */
209582
209696
  ){
209697
+ assert( iCell<NCELL(pNode) );
209583
209698
  readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
209584
209699
  }
209585
209700
 
@@ -209769,7 +209884,9 @@ static int rtreeClose(sqlite3_vtab_cursor *cur){
209769
209884
  sqlite3_finalize(pCsr->pReadAux);
209770
209885
  sqlite3_free(pCsr);
209771
209886
  pRtree->nCursor--;
209772
- nodeBlobReset(pRtree);
209887
+ if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
209888
+ nodeBlobReset(pRtree);
209889
+ }
209773
209890
  return SQLITE_OK;
209774
209891
  }
209775
209892
 
@@ -210354,7 +210471,11 @@ static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
210354
210471
  int rc = SQLITE_OK;
210355
210472
  RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210356
210473
  if( rc==SQLITE_OK && ALWAYS(p) ){
210357
- *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
210474
+ if( p->iCell>=NCELL(pNode) ){
210475
+ rc = SQLITE_ABORT;
210476
+ }else{
210477
+ *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
210478
+ }
210358
210479
  }
210359
210480
  return rc;
210360
210481
  }
@@ -210372,6 +210493,7 @@ static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
210372
210493
 
210373
210494
  if( rc ) return rc;
210374
210495
  if( NEVER(p==0) ) return SQLITE_OK;
210496
+ if( p->iCell>=NCELL(pNode) ) return SQLITE_ABORT;
210375
210497
  if( i==0 ){
210376
210498
  sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
210377
210499
  }else if( i<=pRtree->nDim2 ){
@@ -211853,8 +211975,7 @@ constraint:
211853
211975
  */
211854
211976
  static int rtreeBeginTransaction(sqlite3_vtab *pVtab){
211855
211977
  Rtree *pRtree = (Rtree *)pVtab;
211856
- assert( pRtree->inWrTrans==0 );
211857
- pRtree->inWrTrans++;
211978
+ pRtree->inWrTrans = 1;
211858
211979
  return SQLITE_OK;
211859
211980
  }
211860
211981
 
@@ -211868,6 +211989,9 @@ static int rtreeEndTransaction(sqlite3_vtab *pVtab){
211868
211989
  nodeBlobReset(pRtree);
211869
211990
  return SQLITE_OK;
211870
211991
  }
211992
+ static int rtreeRollback(sqlite3_vtab *pVtab){
211993
+ return rtreeEndTransaction(pVtab);
211994
+ }
211871
211995
 
211872
211996
  /*
211873
211997
  ** The xRename method for rtree module virtual tables.
@@ -211986,7 +212110,7 @@ static sqlite3_module rtreeModule = {
211986
212110
  rtreeBeginTransaction, /* xBegin - begin transaction */
211987
212111
  rtreeEndTransaction, /* xSync - sync transaction */
211988
212112
  rtreeEndTransaction, /* xCommit - commit transaction */
211989
- rtreeEndTransaction, /* xRollback - rollback transaction */
212113
+ rtreeRollback, /* xRollback - rollback transaction */
211990
212114
  0, /* xFindFunction - function overloading */
211991
212115
  rtreeRename, /* xRename - rename the table */
211992
212116
  rtreeSavepoint, /* xSavepoint */
@@ -245545,23 +245669,26 @@ static void fts5IterSetOutputsTokendata(Fts5Iter *pIter){
245545
245669
  static void fts5TokendataIterNext(Fts5Iter *pIter, int bFrom, i64 iFrom){
245546
245670
  int ii;
245547
245671
  Fts5TokenDataIter *pT = pIter->pTokenDataIter;
245672
+ Fts5Index *pIndex = pIter->pIndex;
245548
245673
 
245549
245674
  for(ii=0; ii<pT->nIter; ii++){
245550
245675
  Fts5Iter *p = pT->apIter[ii];
245551
245676
  if( p->base.bEof==0
245552
245677
  && (p->base.iRowid==pIter->base.iRowid || (bFrom && p->base.iRowid<iFrom))
245553
245678
  ){
245554
- fts5MultiIterNext(p->pIndex, p, bFrom, iFrom);
245679
+ fts5MultiIterNext(pIndex, p, bFrom, iFrom);
245555
245680
  while( bFrom && p->base.bEof==0
245556
245681
  && p->base.iRowid<iFrom
245557
- && p->pIndex->rc==SQLITE_OK
245682
+ && pIndex->rc==SQLITE_OK
245558
245683
  ){
245559
- fts5MultiIterNext(p->pIndex, p, 0, 0);
245684
+ fts5MultiIterNext(pIndex, p, 0, 0);
245560
245685
  }
245561
245686
  }
245562
245687
  }
245563
245688
 
245564
- fts5IterSetOutputsTokendata(pIter);
245689
+ if( pIndex->rc==SQLITE_OK ){
245690
+ fts5IterSetOutputsTokendata(pIter);
245691
+ }
245565
245692
  }
245566
245693
 
245567
245694
  /*
@@ -250715,7 +250842,7 @@ static void fts5SourceIdFunc(
250715
250842
  ){
250716
250843
  assert( nArg==0 );
250717
250844
  UNUSED_PARAM2(nArg, apUnused);
250718
- sqlite3_result_text(pCtx, "fts5: 2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a", -1, SQLITE_TRANSIENT);
250845
+ sqlite3_result_text(pCtx, "fts5: 2024-03-12 11:06:23 d8cd6d49b46a395b13955387d05e9e1a2a47e54fb99f3c9b59835bbefad6af77", -1, SQLITE_TRANSIENT);
250719
250846
  }
250720
250847
 
250721
250848
  /*
@@ -256062,9 +256189,9 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
256062
256189
 
256063
256190
  #define SQLITE3MC_VERSION_MAJOR 1
256064
256191
  #define SQLITE3MC_VERSION_MINOR 8
256065
- #define SQLITE3MC_VERSION_RELEASE 3
256192
+ #define SQLITE3MC_VERSION_RELEASE 4
256066
256193
  #define SQLITE3MC_VERSION_SUBRELEASE 0
256067
- #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.8.3"
256194
+ #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.8.4"
256068
256195
 
256069
256196
  #endif /* SQLITE3MC_VERSION_H_ */
256070
256197
  /*** End of #include "sqlite3mc_version.h" ***/
@@ -256223,9 +256350,9 @@ extern "C" {
256223
256350
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
256224
256351
  ** [sqlite_version()] and [sqlite_source_id()].
256225
256352
  */
256226
- #define SQLITE_VERSION "3.45.1"
256227
- #define SQLITE_VERSION_NUMBER 3045001
256228
- #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
256353
+ #define SQLITE_VERSION "3.45.2"
256354
+ #define SQLITE_VERSION_NUMBER 3045002
256355
+ #define SQLITE_SOURCE_ID "2024-03-12 11:06:23 d8cd6d49b46a395b13955387d05e9e1a2a47e54fb99f3c9b59835bbefad6af77"
256229
256356
 
256230
256357
  /*
256231
256358
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -256497,6 +256624,8 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
256497
256624
  ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
256498
256625
  ** <li> The application must not modify the SQL statement text passed into
256499
256626
  ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
256627
+ ** <li> The application must not dereference the arrays or string pointers
256628
+ ** passed as the 3rd and 4th callback parameters after it returns.
256500
256629
  ** </ul>
256501
256630
  */
256502
256631
  SQLITE_API int sqlite3_exec(
@@ -281423,7 +281552,7 @@ sqlite3mcBtreeSetPageSize(Btree* p, int pageSize, int nReserve, int iFix)
281423
281552
  ** Change 4: Call sqlite3mcBtreeSetPageSize instead of sqlite3BtreeSetPageSize for main database
281424
281553
  ** (sqlite3mcBtreeSetPageSize allows to reduce the number of reserved bytes)
281425
281554
  **
281426
- ** This code is generated by the script rekeyvacuum.sh from SQLite version 3.45.1 amalgamation.
281555
+ ** This code is generated by the script rekeyvacuum.sh from SQLite version 3.45.2 amalgamation.
281427
281556
  */
281428
281557
  SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(
281429
281558
  char **pzErrMsg, /* Write error message here */
@@ -31,9 +31,9 @@
31
31
 
32
32
  #define SQLITE3MC_VERSION_MAJOR 1
33
33
  #define SQLITE3MC_VERSION_MINOR 8
34
- #define SQLITE3MC_VERSION_RELEASE 3
34
+ #define SQLITE3MC_VERSION_RELEASE 4
35
35
  #define SQLITE3MC_VERSION_SUBRELEASE 0
36
- #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.8.3"
36
+ #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.8.4"
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.45.1"
196
- #define SQLITE_VERSION_NUMBER 3045001
197
- #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
195
+ #define SQLITE_VERSION "3.45.2"
196
+ #define SQLITE_VERSION_NUMBER 3045002
197
+ #define SQLITE_SOURCE_ID "2024-03-12 11:06:23 d8cd6d49b46a395b13955387d05e9e1a2a47e54fb99f3c9b59835bbefad6af77"
198
198
 
199
199
  /*
200
200
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -466,6 +466,8 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
466
466
  ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
467
467
  ** <li> The application must not modify the SQL statement text passed into
468
468
  ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
469
+ ** <li> The application must not dereference the arrays or string pointers
470
+ ** passed as the 3rd and 4th callback parameters after it returns.
469
471
  ** </ul>
470
472
  */
471
473
  SQLITE_API int sqlite3_exec(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-sqlite3-multiple-ciphers",
3
- "version": "9.4.1",
3
+ "version": "9.5.0",
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>",
@@ -28,7 +28,7 @@
28
28
  "fs-extra": "^11.1.1",
29
29
  "mocha": "^10.2.0",
30
30
  "nodemark": "^0.3.0",
31
- "prebuild": "^12.0.0",
31
+ "prebuild": "^13.0.0",
32
32
  "sqlite": "^5.0.1",
33
33
  "sqlite3": "^5.1.6"
34
34
  },
@@ -2,7 +2,35 @@
2
2
  //
3
3
 
4
4
  #include "better_sqlite3.hpp"
5
- #line 161 "./src/util/macros.lzz"
5
+ #line 153 "./src/util/macros.lzz"
6
+ void SetPrototypeGetter(
7
+ v8::Isolate* isolate,
8
+ v8::Local<v8::External> data,
9
+ v8::Local<v8::FunctionTemplate> recv,
10
+ const char* name,
11
+ v8::AccessorGetterCallback func
12
+ ) {
13
+ v8::HandleScope scope(isolate);
14
+
15
+ #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 121
16
+ recv->InstanceTemplate()->SetAccessor(
17
+ InternalizedFromLatin1(isolate, name),
18
+ func,
19
+ 0,
20
+ data,
21
+ v8::AccessControl::DEFAULT,
22
+ v8::PropertyAttribute::None
23
+ );
24
+ #else
25
+ recv->InstanceTemplate()->SetAccessor(
26
+ InternalizedFromLatin1(isolate, name),
27
+ func,
28
+ 0,
29
+ data
30
+ );
31
+ #endif
32
+ }
33
+ #line 183 "./src/util/macros.lzz"
6
34
  #ifndef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
7
35
  #define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) node::Buffer::New(env, data, length, finalizeCallback, finalizeHint)
8
36
  #else
@@ -119,20 +147,6 @@ void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local <v8::External> d
119
147
  v8::FunctionTemplate::New(isolate, func, data, v8::Signature::New(isolate, recv))
120
148
  );
121
149
  }
122
- #line 142 "./src/util/macros.lzz"
123
- void SetPrototypeGetter (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::AccessorGetterCallback func)
124
- #line 148 "./src/util/macros.lzz"
125
- {
126
- v8::HandleScope scope(isolate);
127
- recv->InstanceTemplate()->SetAccessor(
128
- InternalizedFromLatin1(isolate, name),
129
- func,
130
- 0,
131
- data,
132
- v8::AccessControl::DEFAULT,
133
- v8::PropertyAttribute::None
134
- );
135
- }
136
150
  #line 4 "./src/util/constants.lzz"
137
151
  v8::Local <v8::String> CS::Code (v8::Isolate * isolate, int code)
138
152
  #line 4 "./src/util/constants.lzz"
@@ -18,6 +18,14 @@
18
18
  #include <node_buffer.h>
19
19
  #line 31 "./src/util/macros.lzz"
20
20
  template <class T> using CopyablePersistent = v8::Persistent<T, v8::CopyablePersistentTraits<T>>;
21
+ #line 144 "./src/util/macros.lzz"
22
+ void SetPrototypeGetter(
23
+ v8::Isolate* isolate,
24
+ v8::Local<v8::External> data,
25
+ v8::Local<v8::FunctionTemplate> recv,
26
+ const char* name,
27
+ v8::AccessorGetterCallback func
28
+ );
21
29
  #line 36 "./src/util/binder.lzz"
22
30
  static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj);
23
31
  #define LZZ_INLINE inline
@@ -53,8 +61,6 @@ v8::Local <v8::FunctionTemplate> NewConstructorTemplate (v8::Isolate * isolate,
53
61
  void SetPrototypeMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::FunctionCallback func);
54
62
  #line 129 "./src/util/macros.lzz"
55
63
  void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, v8::Local <v8::Symbol> symbol, v8::FunctionCallback func);
56
- #line 142 "./src/util/macros.lzz"
57
- void SetPrototypeGetter (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::AccessorGetterCallback func);
58
64
  #line 1 "./src/util/constants.lzz"
59
65
  class CS
60
66
  {