Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/codecext.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
** License: MIT
*/

/*
** Forward declaration for pager codec cache update function.
** This should be called after encryption is added, removed, or changed.
*/
void libsql_pager_update_codec_cache(struct Pager *pPager);

/*
** "Special" version of function sqlite3BtreeSetPageSize
** This version allows to reduce the number of reserved bytes per page,
Expand Down Expand Up @@ -585,6 +591,8 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
{
sqlite3mcSetIsEncrypted(codec, 0);
}
/* Update the pager's cached codec status after changing encryption */
libsql_pager_update_codec_cache(pPager);
}
else
{
Expand Down
16 changes: 14 additions & 2 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -58152,6 +58152,7 @@ struct Pager {
u8 readOnly; /* True for a read-only database */
u8 memDb; /* True to inhibit all file I/O */
u8 memVfs; /* VFS-implemented memory database */
u8 hasCodec; /* True if pager has encryption codec */

/**************************************************************************
** The following block contains those class members that change during
Expand Down Expand Up @@ -58243,6 +58244,15 @@ int libsql_pager_has_codec(struct Pager *_p) {
#endif
}

/*
** Update the cached codec status.
** This should be called after encryption is added, removed, or changed
** via sqlite3_rekey_v2() to ensure the cached hasCodec value is correct.
*/
void libsql_pager_update_codec_cache(struct Pager *pPager) {
pPager->hasCodec = libsql_pager_has_codec(pPager);
}

int libsql_pager_codec(libsql_pghdr *hdr, void **ret) {
if (!ret) {
return SQLITE_MISUSE_BKPT;
Expand Down Expand Up @@ -58380,7 +58390,7 @@ static const unsigned char aJournalMagic[] = {
SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
if( pPager->fd->pMethods==0 ) return 0;
if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
if( libsql_pager_has_codec(pPager) != 0 ) return 0;
if( pPager->hasCodec ) return 0;
#ifndef SQLITE_OMIT_WAL
if( pagerUseWal(pPager) ){
u32 iRead = 0;
Expand Down Expand Up @@ -58603,7 +58613,7 @@ static void setGetterMethod(Pager *pPager){
if( pPager->errCode ){
pPager->xGet = getPageError;
#if SQLITE_MAX_MMAP_SIZE>0
}else if( USEFETCH(pPager) && libsql_pager_has_codec(pPager) == 0 ){
}else if( USEFETCH(pPager) && !pPager->hasCodec ){
pPager->xGet = getPageMMap;
#endif /* SQLITE_MAX_MMAP_SIZE>0 */
}else{
Expand Down Expand Up @@ -62625,6 +62635,8 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
/* pPager->xBusyHandler = 0; */
/* pPager->pBusyHandlerArg = 0; */
pPager->xReiniter = xReinit;
/* Cache the codec check result to avoid expensive VFS stack traversal on every page read */
pPager->hasCodec = libsql_pager_has_codec(pPager);
setGetterMethod(pPager);
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
Expand Down
16 changes: 14 additions & 2 deletions libsql-ffi/bundled/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -58152,6 +58152,7 @@ struct Pager {
u8 readOnly; /* True for a read-only database */
u8 memDb; /* True to inhibit all file I/O */
u8 memVfs; /* VFS-implemented memory database */
u8 hasCodec; /* True if pager has encryption codec */

/**************************************************************************
** The following block contains those class members that change during
Expand Down Expand Up @@ -58243,6 +58244,15 @@ int libsql_pager_has_codec(struct Pager *_p) {
#endif
}

/*
** Update the cached codec status.
** This should be called after encryption is added, removed, or changed
** via sqlite3_rekey_v2() to ensure the cached hasCodec value is correct.
*/
void libsql_pager_update_codec_cache(struct Pager *pPager) {
pPager->hasCodec = libsql_pager_has_codec(pPager);
}

int libsql_pager_codec(libsql_pghdr *hdr, void **ret) {
if (!ret) {
return SQLITE_MISUSE_BKPT;
Expand Down Expand Up @@ -58380,7 +58390,7 @@ static const unsigned char aJournalMagic[] = {
SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
if( pPager->fd->pMethods==0 ) return 0;
if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
if( libsql_pager_has_codec(pPager) != 0 ) return 0;
if( pPager->hasCodec ) return 0;
#ifndef SQLITE_OMIT_WAL
if( pagerUseWal(pPager) ){
u32 iRead = 0;
Expand Down Expand Up @@ -58603,7 +58613,7 @@ static void setGetterMethod(Pager *pPager){
if( pPager->errCode ){
pPager->xGet = getPageError;
#if SQLITE_MAX_MMAP_SIZE>0
}else if( USEFETCH(pPager) && libsql_pager_has_codec(pPager) == 0 ){
}else if( USEFETCH(pPager) && !pPager->hasCodec ){
pPager->xGet = getPageMMap;
#endif /* SQLITE_MAX_MMAP_SIZE>0 */
}else{
Expand Down Expand Up @@ -62625,6 +62635,8 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
/* pPager->xBusyHandler = 0; */
/* pPager->pBusyHandlerArg = 0; */
pPager->xReiniter = xReinit;
/* Cache the codec check result to avoid expensive VFS stack traversal on every page read */
pPager->hasCodec = libsql_pager_has_codec(pPager);
setGetterMethod(pPager);
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
Expand Down
16 changes: 14 additions & 2 deletions libsql-sqlite3/src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ struct Pager {
u8 readOnly; /* True for a read-only database */
u8 memDb; /* True to inhibit all file I/O */
u8 memVfs; /* VFS-implemented memory database */
u8 hasCodec; /* True if pager has encryption codec */

/**************************************************************************
** The following block contains those class members that change during
Expand Down Expand Up @@ -721,6 +722,15 @@ int libsql_pager_has_codec(struct Pager *_p) {
#endif
}

/*
** Update the cached codec status.
** This should be called after encryption is added, removed, or changed
** via sqlite3_rekey_v2() to ensure the cached hasCodec value is correct.
*/
void libsql_pager_update_codec_cache(struct Pager *pPager) {
pPager->hasCodec = libsql_pager_has_codec(pPager);
}

int libsql_pager_codec(libsql_pghdr *hdr, void **ret) {
if (!ret) {
return SQLITE_MISUSE_BKPT;
Expand Down Expand Up @@ -858,7 +868,7 @@ static const unsigned char aJournalMagic[] = {
int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
if( pPager->fd->pMethods==0 ) return 0;
if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
if( libsql_pager_has_codec(pPager) != 0 ) return 0;
if( pPager->hasCodec ) return 0;
#ifndef SQLITE_OMIT_WAL
if( pagerUseWal(pPager) ){
u32 iRead = 0;
Expand Down Expand Up @@ -1081,7 +1091,7 @@ static void setGetterMethod(Pager *pPager){
if( pPager->errCode ){
pPager->xGet = getPageError;
#if SQLITE_MAX_MMAP_SIZE>0
}else if( USEFETCH(pPager) && libsql_pager_has_codec(pPager) == 0 ){
}else if( USEFETCH(pPager) && !pPager->hasCodec ){
pPager->xGet = getPageMMap;
#endif /* SQLITE_MAX_MMAP_SIZE>0 */
}else{
Expand Down Expand Up @@ -5103,6 +5113,8 @@ int sqlite3PagerOpen(
/* pPager->xBusyHandler = 0; */
/* pPager->pBusyHandlerArg = 0; */
pPager->xReiniter = xReinit;
/* Cache the codec check result to avoid expensive VFS stack traversal on every page read */
pPager->hasCodec = libsql_pager_has_codec(pPager);
setGetterMethod(pPager);
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
Expand Down
Loading