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
19 changes: 19 additions & 0 deletions src/main/java/org/sqlite/SQLiteConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ public enum Pragma {
"application_id",
"Set the 32-bit signed big-endian \"Application ID\" integer located at offset 68 into the database header. Applications that use SQLite as their application file-format should set the Application ID integer to a unique integer so that utilities such as file(1) can determine the specific file type rather than just reporting \"SQLite3 Database\"",
null),
WAL_AUTOCHECKPOINT(
"wal_autocheckpoint",
"The wal_autocheckpoint pragma sets the write-ahead log auto-checkpoint interval. If the argument N is specified, then the auto-checkpoint is adjusted to fire whenever the WAL has N or more pages. Passing zero or a negative value turns off automatic checkpointing entirely. The default auto-checkpoint interval is 1000 or SQLITE_DEFAULT_WAL_AUTOCHECKPOINT.",
null),

// Limits
LIMIT_LENGTH(
Expand Down Expand Up @@ -1096,6 +1100,21 @@ public void setApplicationId(int id) {
set(Pragma.APPLICATION_ID, id);
}

/**
* Sets the write-ahead log auto-checkpoint interval. The auto-checkpoint fires whenever the WAL
* reaches #pages. Setting the auto-checkpoint size to zero or a negative value turns
* auto-checkpointing off. The default interval is 1000 pages (or {@code
* SQLITE_DEFAULT_WAL_AUTOCHECKPOINT}).
*
* @param pages the number of WAL pages that triggers an automatic checkpoint; zero or negative
* disables auto-checkpointing
* @see <a href=
* "https://www.sqlite.org/pragma.html#pragma_wal_autocheckpoint">www.sqlite.org/pragma.html#pragma_wal_autocheckpoint</a>
*/
public void setWalAutocheckpoint(int pages) {
set(Pragma.WAL_AUTOCHECKPOINT, pages);
}

public enum TransactionMode implements PragmaValue {
DEFERRED,
IMMEDIATE,
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/sqlite/SQLiteConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ public void setBusyTimeout() {
assertThat(config.getBusyTimeout()).isEqualTo(100);
}

@Test
public void setWalAutocheckpoint() {
SQLiteConfig config = new SQLiteConfig();
config.setWalAutocheckpoint(500);
assertThat(
config.toProperties()
.getProperty(
SQLiteConfig.Pragma.WAL_AUTOCHECKPOINT.getPragmaName()))
.isEqualTo("500");
}

@Test
public void setWalAutocheckpointDisabled() {
SQLiteConfig config = new SQLiteConfig();
config.setWalAutocheckpoint(0);
assertThat(
config.toProperties()
.getProperty(
SQLiteConfig.Pragma.WAL_AUTOCHECKPOINT.getPragmaName()))
.isEqualTo("0");
}

@Test
public void pragmaSet() {
Set<String> expectedPragmaSet = new HashSet<>();
Expand Down
Loading