@@ -10953,6 +10953,15 @@ SQLITE_API void *libsql_close_hook(sqlite3 *db, void (*xClose)(void *pCtx, sqlit
1095310953*/
1095410954SQLITE_API int libsql_wal_disable_checkpoint(sqlite3 *db);
1095510955
10956+ /*
10957+ ** CAPI3REF: Get the checkpoint sequence counter of the WAL file
10958+ ** METHOD: sqlite3
10959+ **
10960+ ** ^The [libsql_wal_checkpoint_seq_count(D,P)] interface returns the checkpoint sequence counter
10961+ ** of the WAL file for [database connection] D into *P.
10962+ */
10963+ SQLITE_API int libsql_wal_checkpoint_seq_count(sqlite3 *db, unsigned int *pnCkpt);
10964+
1095610965/*
1095710966** CAPI3REF: Get the number of frames in the WAL file
1095810967** METHOD: sqlite3
@@ -14036,6 +14045,9 @@ typedef struct libsql_wal_methods {
1403614045 ** response to a ROLLBACK TO command. */
1403714046 int (*xSavepointUndo)(wal_impl* pWal, unsigned int *aWalData);
1403814047
14048+ /* Return the current checkpoint generation in the WAL file. */
14049+ int (*xCheckpointSeqCount)(wal_impl* pWal, unsigned int *pnCkpt);
14050+
1403914051 /* Return the number of frames in the WAL */
1404014052 int (*xFrameCount)(wal_impl* pWal, int, unsigned int *);
1404114053
@@ -57354,6 +57366,9 @@ typedef struct libsql_wal_methods {
5735457366 ** response to a ROLLBACK TO command. */
5735557367 int (*xSavepointUndo)(wal_impl* pWal, unsigned int *aWalData);
5735657368
57369+ /* Return the current checkpoint generation in the WAL file. */
57370+ int (*xCheckpointSeqCount)(wal_impl* pWal, unsigned int *pnCkpt);
57371+
5735757372 /* Return the number of frames in the WAL */
5735857373 int (*xFrameCount)(wal_impl* pWal, int, unsigned int *);
5735957374
@@ -65282,6 +65297,18 @@ SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3 *db){
6528265297 return rc;
6528365298}
6528465299
65300+ /**
65301+ ** Return the current checkpoint generation in the WAL file.
65302+ **/
65303+ SQLITE_PRIVATE int sqlite3PagerWalCheckpointSeqCount(Pager *pPager, unsigned int *pnCkpt){
65304+ if( pagerUseWal(pPager) ){
65305+ return pPager->wal->methods.xCheckpointSeqCount(pPager->wal->pData, pnCkpt);
65306+ } else {
65307+ *pnCkpt = 0;
65308+ return SQLITE_OK;
65309+ }
65310+ }
65311+
6528565312/**
6528665313** Return the number of frames in the WAL file.
6528765314**
@@ -69533,6 +69560,11 @@ static int walFrames(
6953369560 return rc;
6953469561}
6953569562
69563+ SQLITE_PRIVATE int sqlite3WalCheckpointSeqCount(Wal *pWal, unsigned int *pnCkpt){
69564+ *pnCkpt = pWal->nCkpt;
69565+ return SQLITE_OK;
69566+ }
69567+
6953669568SQLITE_PRIVATE int sqlite3WalFrameCount(Wal *pWal, int locked, unsigned int *pnFrames){
6953769569 int rc = SQLITE_OK;
6953869570 if( locked==0 ) {
@@ -70052,6 +70084,7 @@ static int sqlite3WalOpen(
7005270084 out->methods.xUndo = (int (*)(wal_impl *, int (*)(void *, unsigned int), void *))sqlite3WalUndo;
7005370085 out->methods.xSavepoint = (void (*)(wal_impl *, unsigned int *))sqlite3WalSavepoint;
7005470086 out->methods.xSavepointUndo = (int (*)(wal_impl *, unsigned int *))sqlite3WalSavepointUndo;
70087+ out->methods.xCheckpointSeqCount = (int (*)(wal_impl *, unsigned int *))sqlite3WalCheckpointSeqCount;
7005570088 out->methods.xFrameCount = (int (*)(wal_impl *, int, unsigned int *))sqlite3WalFrameCount;
7005670089 out->methods.xFrames = (int (*)(wal_impl *, int, libsql_pghdr *, unsigned int, int, int, int *))sqlite3WalFrames;
7005770090 out->methods.xCheckpoint = (int (*)(wal_impl *, sqlite3 *, int, int (*)(void *), void *, int, int, unsigned char *, int *, int *, int (*)(void*, int, const unsigned char*, int, int, int), void*))sqlite3WalCheckpoint;
@@ -183206,6 +183239,30 @@ int libsql_wal_disable_checkpoint(sqlite3 *db) {
183206183239 return SQLITE_OK;
183207183240}
183208183241
183242+ /*
183243+ ** Return the checkpoint sequence counter of the given database.
183244+ */
183245+ int libsql_wal_checkpoint_seq_count(sqlite3 *db, unsigned int *pnCkpt) {
183246+ int rc = SQLITE_OK;
183247+ Pager *pPager;
183248+
183249+ #ifdef SQLITE_OMIT_WAL
183250+ *pnFrame = 0;
183251+ return SQLITE_OK;
183252+ #else
183253+ #ifdef SQLITE_ENABLE_API_ARMOR
183254+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
183255+ #endif
183256+
183257+ sqlite3_mutex_enter(db->mutex);
183258+ pPager = sqlite3BtreePager(db->aDb[0].pBt);
183259+ rc = sqlite3PagerWalCheckpointSeqCount(pPager, pnCkpt);
183260+ sqlite3Error(db, rc);
183261+ sqlite3_mutex_leave(db->mutex);
183262+ return rc;
183263+ #endif
183264+ }
183265+
183209183266/*
183210183267** Return the number of frames in the WAL of the given database.
183211183268*/
0 commit comments