Skip to content

Commit c9aeba0

Browse files
committed
Upgrade to latest SQLite development snapshot (August 7, 2020)
1 parent 7cd13e3 commit c9aeba0

File tree

7 files changed

+184
-40
lines changed

7 files changed

+184
-40
lines changed

src/shell.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12636,25 +12636,38 @@ static void exec_prepared_stmt_columnar(
1263612636
ShellState *p, /* Pointer to ShellState */
1263712637
sqlite3_stmt *pStmt /* Statment to run */
1263812638
){
12639-
int nRow = 0;
12639+
sqlite3_int64 nRow = 0;
1264012640
int nColumn = 0;
1264112641
char **azData = 0;
12642-
char *zMsg = 0;
12642+
sqlite3_int64 nAlloc = 0;
1264312643
const char *z;
1264412644
int rc;
12645-
int i, j, nTotal, w, n;
12645+
sqlite3_int64 i, nData;
12646+
int j, nTotal, w, n;
1264612647
const char *colSep = 0;
1264712648
const char *rowSep = 0;
1264812649

12649-
rc = sqlite3_get_table(p->db, sqlite3_sql(pStmt),
12650-
&azData, &nRow, &nColumn, &zMsg);
12651-
if( rc ){
12652-
utf8_printf(p->out, "ERROR: %s\n", zMsg);
12653-
sqlite3_free(zMsg);
12654-
sqlite3_free_table(azData);
12655-
return;
12650+
rc = sqlite3_step(pStmt);
12651+
if( rc!=SQLITE_ROW ) return;
12652+
nColumn = sqlite3_column_count(pStmt);
12653+
nAlloc = nColumn*4;
12654+
azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
12655+
if( azData==0 ) shell_out_of_memory();
12656+
for(i=0; i<nColumn; i++){
12657+
azData[i] = strdup(sqlite3_column_name(pStmt,i));
1265612658
}
12657-
if( nRow==0 || nColumn==0 ) goto columnar_end;
12659+
do{
12660+
if( (nRow+2)*nColumn >= nAlloc ){
12661+
nAlloc *= 2;
12662+
azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
12663+
if( azData==0 ) shell_out_of_memory();
12664+
}
12665+
nRow++;
12666+
for(i=0; i<nColumn; i++){
12667+
z = (const char*)sqlite3_column_text(pStmt,i);
12668+
azData[nRow*nColumn + i] = z ? strdup(z) : 0;
12669+
}
12670+
}while( (rc = sqlite3_step(pStmt))==SQLITE_ROW );
1265812671
if( nColumn>p->nWidth ){
1265912672
p->colWidth = realloc(p->colWidth, nColumn*2*sizeof(int));
1266012673
if( p->colWidth==0 ) shell_out_of_memory();
@@ -12764,7 +12777,9 @@ static void exec_prepared_stmt_columnar(
1276412777
if( seenInterrupt ){
1276512778
utf8_printf(p->out, "Interrupt\n");
1276612779
}
12767-
sqlite3_free_table(azData);
12780+
nData = (nRow+1)*nColumn;
12781+
for(i=0; i<nData; i++) free(azData[i]);
12782+
sqlite3_free(azData);
1276812783
}
1276912784

1277012785
/*

src/sqlite3.c

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ extern "C" {
11641164
*/
11651165
#define SQLITE_VERSION "3.33.0"
11661166
#define SQLITE_VERSION_NUMBER 3033000
1167-
#define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051"
1167+
#define SQLITE_SOURCE_ID "2020-08-07 19:52:01 fdc5fb902d7f2d10f73e64fe30c67153b59b26c5d707fc9c354e90967dbcc214"
11681168

11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
@@ -60679,7 +60679,34 @@ static int walIndexRecover(Wal *pWal){
6067960679
pWal->apWiData[iPg] = aShare;
6068060680
nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
6068160681
nHdr32 = nHdr / sizeof(u32);
60682+
#ifndef SQLITE_SAFER_WALINDEX_RECOVERY
60683+
/* Memcpy() should work fine here, on all reasonable implementations.
60684+
** Technically, memcpy() might change the destination to some
60685+
** intermediate value before setting to the final value, and that might
60686+
** cause a concurrent reader to malfunction. Memcpy() is allowed to
60687+
** do that, according to the spec, but no memcpy() implementation that
60688+
** we know of actually does that, which is why we say that memcpy()
60689+
** is safe for this. Memcpy() is certainly a lot faster.
60690+
*/
6068260691
memcpy(&aShare[nHdr32], &aPrivate[nHdr32], WALINDEX_PGSZ-nHdr);
60692+
#else
60693+
/* In the event that some platform is found for which memcpy()
60694+
** changes the destination to some intermediate value before
60695+
** setting the final value, this alternative copy routine is
60696+
** provided.
60697+
*/
60698+
{
60699+
int i;
60700+
for(i=nHdr32; i<WALINDEX_PGSZ/sizeof(u32); i++){
60701+
if( aShare[i]!=aPrivate[i] ){
60702+
/* Atomic memory operations are not required here because if
60703+
** the value needs to be changed, that means it is not being
60704+
** accessed concurrently. */
60705+
aShare[i] = aPrivate[i];
60706+
}
60707+
}
60708+
}
60709+
#endif
6068360710
if( iFrame<=iLast ) break;
6068460711
}
6068560712

@@ -61379,10 +61406,17 @@ static int walCheckpoint(
6137961406
sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0);
6138061407
rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
6138161408
if( rc==SQLITE_OK && nSize<nReq ){
61382-
sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
61409+
if( (nSize+(i64)pWal->hdr.mxFrame*szPage)<nReq ){
61410+
/* If the size of the final database is larger than the current
61411+
** database plus the amount of data in the wal file, then there
61412+
** must be corruption somewhere. */
61413+
rc = SQLITE_CORRUPT_BKPT;
61414+
}else{
61415+
sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT,&nReq);
61416+
}
6138361417
}
61384-
}
6138561418

61419+
}
6138661420

6138761421
/* Iterate through the contents of the WAL, copying data to the db file */
6138861422
while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
@@ -70389,7 +70423,7 @@ static int allocateBtreePage(
7038970423
*/
7039070424
#ifndef SQLITE_OMIT_AUTOVACUUM
7039170425
if( eMode==BTALLOC_EXACT ){
70392-
if( ALWAYS(nearby<=mxPage) ){
70426+
if( nearby<=mxPage ){
7039370427
u8 eType;
7039470428
assert( nearby>0 );
7039570429
assert( pBt->autoVacuum );
@@ -70685,7 +70719,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
7068570719
assert( CORRUPT_DB || iPage>1 );
7068670720
assert( !pMemPage || pMemPage->pgno==iPage );
7068770721

70688-
if( iPage<2 || NEVER(iPage>pBt->nPage) ){
70722+
if( iPage<2 || iPage>pBt->nPage ){
7068970723
return SQLITE_CORRUPT_BKPT;
7069070724
}
7069170725
if( pMemPage ){
@@ -87558,7 +87592,7 @@ case OP_Compare: {
8755887592
#ifdef SQLITE_DEBUG
8755987593
if( aPermute ){
8756087594
int k, mx = 0;
87561-
for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
87595+
for(k=0; k<n; k++) if( aPermute[k]>(u32)mx ) mx = aPermute[k];
8756287596
assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
8756387597
assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
8756487598
}else{
@@ -87908,7 +87942,7 @@ case OP_Column: {
8790887942
pDest = &aMem[pOp->p3];
8790987943
memAboutToChange(p, pDest);
8791087944
assert( pC!=0 );
87911-
assert( p2<pC->nField );
87945+
assert( p2<(u32)pC->nField );
8791287946
aOffset = pC->aOffset;
8791387947
assert( pC->eCurType!=CURTYPE_VTAB );
8791487948
assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
@@ -89097,7 +89131,7 @@ case OP_OpenWrite:
8909789131
}
8909889132
if( pOp->p5 & OPFLAG_P2ISREG ){
8909989133
assert( p2>0 );
89100-
assert( p2<=(p->nMem+1 - p->nCursor) );
89134+
assert( p2<=(u32)(p->nMem+1 - p->nCursor) );
8910189135
assert( pOp->opcode==OP_OpenWrite );
8910289136
pIn2 = &aMem[p2];
8910389137
assert( memIsValid(pIn2) );
@@ -91530,7 +91564,7 @@ case OP_IntegrityCk: {
9153091564
nRoot = pOp->p2;
9153191565
aRoot = pOp->p4.ai;
9153291566
assert( nRoot>0 );
91533-
assert( aRoot[0]==nRoot );
91567+
assert( aRoot[0]==(Pgno)nRoot );
9153491568
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
9153591569
pnErr = &aMem[pOp->p3];
9153691570
assert( (pnErr->flags & MEM_Int)!=0 );
@@ -113189,7 +113223,7 @@ SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, Pgno iFrom, Pgno
113189113223
static void destroyRootPage(Parse *pParse, int iTable, int iDb){
113190113224
Vdbe *v = sqlite3GetVdbe(pParse);
113191113225
int r1 = sqlite3GetTempReg(pParse);
113192-
if( NEVER(iTable<2) ) return;
113226+
if( iTable<2 ) sqlite3ErrorMsg(pParse, "corrupt schema");
113193113227
sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
113194113228
sqlite3MayAbort(pParse);
113195113229
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -188081,6 +188115,7 @@ typedef unsigned int u32;
188081188115
/* #include <string.h> */
188082188116
/* #include <stdio.h> */
188083188117
/* #include <assert.h> */
188118+
/* #include <stdlib.h> */
188084188119

188085188120
/* The following macro is used to suppress compiler warnings.
188086188121
*/
@@ -188418,6 +188453,23 @@ struct RtreeMatchArg {
188418188453
# define testcase(X)
188419188454
#endif
188420188455

188456+
/*
188457+
** Make sure that the compiler intrinsics we desire are enabled when
188458+
** compiling with an appropriate version of MSVC unless prevented by
188459+
** the SQLITE_DISABLE_INTRINSIC define.
188460+
*/
188461+
#if !defined(SQLITE_DISABLE_INTRINSIC)
188462+
# if defined(_MSC_VER) && _MSC_VER>=1400
188463+
# if !defined(_WIN32_WCE)
188464+
/* # include <intrin.h> */
188465+
# pragma intrinsic(_byteswap_ulong)
188466+
# pragma intrinsic(_byteswap_uint64)
188467+
# else
188468+
/* # include <cmnintrin.h> */
188469+
# endif
188470+
# endif
188471+
#endif
188472+
188421188473
/*
188422188474
** Macros to determine whether the machine is big or little endian,
188423188475
** and whether or not that determination is run-time or compile-time.
@@ -225642,7 +225694,7 @@ static void fts5SourceIdFunc(
225642225694
){
225643225695
assert( nArg==0 );
225644225696
UNUSED_PARAM2(nArg, apUnused);
225645-
sqlite3_result_text(pCtx, "fts5: 2020-07-29 12:23:20 1d69eee8b085d514f442840346f001b4785f8ec64f5ba66943e9577b26e2e29c", -1, SQLITE_TRANSIENT);
225697+
sqlite3_result_text(pCtx, "fts5: 2020-08-07 19:52:01 fdc5fb902d7f2d10f73e64fe30c67153b59b26c5d707fc9c354e90967dbcc214", -1, SQLITE_TRANSIENT);
225646225698
}
225647225699

225648225700
/*
@@ -230425,9 +230477,9 @@ SQLITE_API int sqlite3_stmt_init(
230425230477
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230426230478

230427230479
/************** End of stmt.c ************************************************/
230428-
#if __LINE__!=230428
230480+
#if __LINE__!=230480
230429230481
#undef SQLITE_SOURCE_ID
230430-
#define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ealt2"
230482+
#define SQLITE_SOURCE_ID "2020-08-07 19:52:01 fdc5fb902d7f2d10f73e64fe30c67153b59b26c5d707fc9c354e90967dbcalt2"
230431230483
#endif
230432230484
/* Return the source-id for this library */
230433230485
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }

src/sqlite3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ extern "C" {
125125
*/
126126
#define SQLITE_VERSION "3.33.0"
127127
#define SQLITE_VERSION_NUMBER 3033000
128-
#define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051"
128+
#define SQLITE_SOURCE_ID "2020-08-07 19:52:01 fdc5fb902d7f2d10f73e64fe30c67153b59b26c5d707fc9c354e90967dbcc214"
129129

130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers

src/sqlite3mc.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
7171
** Include SQLite3MultiCipher components
7272
*/
7373
#include "sqlite3mc.h"
74+
#include "sqlite3mc_version.h"
75+
76+
SQLITE_API const char*
77+
sqlite3mc_version()
78+
{
79+
static const char* version = SQLITE3MC_VERSION_STRING;
80+
return version;
81+
}
82+
83+
SQLITE_PRIVATE void
84+
sqlite3mcVersion(sqlite3_context* context, int argc, sqlite3_value** argv)
85+
{
86+
assert(argc == 0);
87+
sqlite3_result_text(context, sqlite3mc_version(), -1, 0);
88+
}
7489

7590
/*
7691
** Crypto algorithms
@@ -92,7 +107,6 @@ void chacha20_rng(void* out, size_t n);
92107
#endif
93108

94109
#ifdef SQLITE_USER_AUTHENTICATION
95-
#include "sqlite3userauth.h"
96110
#include "userauth.c"
97111
#endif
98112

@@ -277,6 +291,11 @@ mcRegisterCodecExtensions(sqlite3* db, char** pzErrMsg, const sqlite3_api_routin
277291
rc = sqlite3_create_function(db, "sqlite3mc_codec_data", 2, SQLITE_UTF8 | SQLITE_DETERMINISTIC,
278292
NULL, sqlite3mcCodecDataSql, 0, 0);
279293
}
294+
if (rc == SQLITE_OK)
295+
{
296+
rc = sqlite3_create_function(db, "sqlite3mc_version", 0, SQLITE_UTF8 | SQLITE_DETERMINISTIC,
297+
NULL, sqlite3mcVersion, 0, 0);
298+
}
280299
return rc;
281300
}
282301

src/sqlite3mc.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ sqlite3_win32_write_debug
284284
sqlite3mc_codec_data
285285
sqlite3mc_config
286286
sqlite3mc_config_cipher
287+
sqlite3mc_version
287288
sqlite3mc_vfs_create
288289
sqlite3mc_vfs_destroy
289290
sqlite3mc_vfs_shutdown

src/sqlite3mc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
#include "sqlite3.h"
1414

15+
#ifdef SQLITE_USER_AUHENTICATION
16+
#include "sqlite3userauth.h"
17+
#endif
18+
1519
/*
1620
** Symbols for ciphers
1721
*/
@@ -160,6 +164,7 @@ SQLITE_API void sqlite3_activate_see(const char* zPassPhrase);
160164
SQLITE_API int sqlite3mc_config(sqlite3* db, const char* paramName, int newValue);
161165
SQLITE_API int sqlite3mc_config_cipher(sqlite3* db, const char* cipherName, const char* paramName, int newValue);
162166
SQLITE_API unsigned char* sqlite3mc_codec_data(sqlite3* db, const char* zDbName, const char* paramName);
167+
SQLITE_API const char* sqlite3mc_version();
163168

164169
#ifdef SQLITE3MC_WXSQLITE3_COMPATIBLE
165170
SQLITE_API int wxsqlite3_config(sqlite3* db, const char* paramName, int newValue);

0 commit comments

Comments
 (0)