/ Check-in [27a5c09c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:If the sqlite3_wal_checkpoint() API is passed a NULL pointer in place of a database name, attempt to checkpoint all attached databases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wal
Files: files | file ages | folders
SHA1: 27a5c09ce8a35039d844d08cfe5698e8b438abfe
User & Date: dan 2010-05-03 14:05:43
Context
2010-05-03
14:08
Merge the write-ahead-logging changes into the trunk. check-in: de9ae443 user: drh tags: trunk
14:05
If the sqlite3_wal_checkpoint() API is passed a NULL pointer in place of a database name, attempt to checkpoint all attached databases. Closed-Leaf check-in: 27a5c09c user: dan tags: wal
13:37
Make sure the mutex is held while calling sqlite3ApiExit() in sqlite3_wal_checkpoint(). Other cleanup of WAL logic. check-in: 11a85b82 user: drh tags: wal
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
....
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294




1295
1296
1297

1298
1299
1300
1301


1302

1303
1304
1305
1306
1307
1308



1309
1310
1311
1312
1313
1314
1315
** Checkpoint database zDb. If zDb is NULL, the main database is checkpointed.
*/
int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
#ifdef SQLITE_OMIT_WAL
  return SQLITE_OK;
#else
  int rc;                         /* Return code */
  int iDb = 0;                    /* sqlite3.aDb[] index of db to checkpoint */

  sqlite3_mutex_enter(db->mutex);
  if( zDb ){
    iDb = sqlite3FindDbName(db, zDb);
  }
  if( iDb<0 ){
    rc = SQLITE_ERROR;
................................................................................
}

#ifndef SQLITE_OMIT_WAL
/*
** Run a checkpoint on database iDb. This is a no-op if database iDb is
** not currently open in WAL mode.
**
** If a transaction is open at either the database handle (db) or b-tree
** level, this function returns SQLITE_LOCKED and a checkpoint is not
** attempted. If an error occurs while running the checkpoint, an SQLite
** error code is returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
**
** The mutex on database handle db should be held by the caller. The mutex
** associated with the specific b-tree being checkpointed is taken by
** this function while the checkpoint is running.




*/
int sqlite3Checkpoint(sqlite3 *db, int iDb){
  Btree *pBt;                     /* Btree handle to checkpoint */

  int rc;                         /* Return code */

  assert( sqlite3_mutex_held(db->mutex) );



  pBt = db->aDb[iDb].pBt;

  if( sqlite3BtreeIsInReadTrans(pBt) ){
    rc = SQLITE_LOCKED;
  }else{
    sqlite3BtreeEnter(pBt);
    rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
    sqlite3BtreeLeave(pBt);



  }

  return rc;
}
#endif /* SQLITE_OMIT_WAL */

/*







|







 







|
|
|
|




>
>
>
>


<
>
|



>
>
|
>
|
|
|
|
|
|
>
>
>







1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
....
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
** Checkpoint database zDb. If zDb is NULL, the main database is checkpointed.
*/
int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
#ifdef SQLITE_OMIT_WAL
  return SQLITE_OK;
#else
  int rc;                         /* Return code */
  int iDb = SQLITE_MAX_ATTACHED;  /* sqlite3.aDb[] index of db to checkpoint */

  sqlite3_mutex_enter(db->mutex);
  if( zDb ){
    iDb = sqlite3FindDbName(db, zDb);
  }
  if( iDb<0 ){
    rc = SQLITE_ERROR;
................................................................................
}

#ifndef SQLITE_OMIT_WAL
/*
** Run a checkpoint on database iDb. This is a no-op if database iDb is
** not currently open in WAL mode.
**
** If a transaction is open on the database being checkpointed, this 
** function returns SQLITE_LOCKED and a checkpoint is not attempted. If 
** an error occurs while running the checkpoint, an SQLite error code is 
** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
**
** The mutex on database handle db should be held by the caller. The mutex
** associated with the specific b-tree being checkpointed is taken by
** this function while the checkpoint is running.
**
** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
** checkpointed. If an error is encountered it is returned immediately -
** no attempt is made to checkpoint any remaining databases.
*/
int sqlite3Checkpoint(sqlite3 *db, int iDb){

  int rc = SQLITE_OK;             /* Return code */
  int i;                          /* Used to iterate through attached dbs */

  assert( sqlite3_mutex_held(db->mutex) );

  for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
    if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
      Btree *pBt = db->aDb[i].pBt;
      if( pBt ){
        if( sqlite3BtreeIsInReadTrans(pBt) ){
          rc = SQLITE_LOCKED;
        }else{
          sqlite3BtreeEnter(pBt);
          rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
          sqlite3BtreeLeave(pBt);
        }
      }
    }
  }

  return rc;
}
#endif /* SQLITE_OMIT_WAL */

/*