Backup · WAL · Operational Checkpoints
The sample's DatabaseOption block also contains operational settings. They aren't manipulated by scripts, but they're the settings most likely to save you in production — worth a chapter of their own.
DB_Sqlite.xmp Operational Options
"DatabaseOption": {
"Connections": [ /* ... */ ],
"BackupFolder": "XDatabase/Backup",
"AutoBackupEnabled": false,
"AutoBackupIntervalHours": 24,
"BackupKeepLast": 30,
"JournalMode": "WAL"
}Meanings and recommended values, option by option.
1) JournalMode — WAL Recommended
SQLite's journal mode determines how transactional data is recorded.
| Value | Behavior | Recommendation |
|---|---|---|
DELETE (default) | Creates / deletes a journal file per transaction. Single-user OK | Small tools |
WAL | Write-Ahead Logging — other processes can read while you write | Production-recommended |
MEMORY | Journal in memory only — corruption risk on power loss | Temporary cache |
OFF | No journal — dangerous | Never |
The sample is set to "WAL". WAL benefits:
- The equipment sequence keeps INSERT-ing while DB Studio or external analysis tools SELECT simultaneously.
- Transaction commits get faster — much better responsiveness for many-short-transaction patterns (like the sample).
- Auto-recovery on abnormal termination.
To change it, just edit the JournalMode key in connections.json / .xmp. You'll see two auxiliary files appear in XDatabase/: LocalDB.db-wal and LocalDB.db-shm.
Backup caveat — copy the WAL/SHM files together too, or pre-checkpoint with
PRAGMA wal_checkpoint(TRUNCATE)to flush WAL changes into the main file before copying just.db.
2) BackupFolder + Manual Backup
A SQLite file is a single file, so it can be copied while the system is running — especially after a WAL checkpoint.
The sample sets "XDatabase/Backup" as the backup folder. Files actually appear in that folder when auto backup is on, or when the tool runs a manual backup.
| Option | Recommended | Meaning |
|---|---|---|
| BackupFolder | "XDatabase/Backup" | Backup file directory (relative to project root) |
| AutoBackupEnabled | Production: true | Periodic auto backup |
| AutoBackupIntervalHours | 24 | Backup interval (hours) |
| BackupKeepLast | 30 | Number of backups to keep — extras pruned automatically |
Auto backup files are typically named {db_name}_{YYYYMMDD_HHMMSS}.db — alphabetical sort = chronological sort.
Pattern for OS-level Backup
If you schedule backups at the OS level instead, the recommended flow:
1. PRAGMA wal_checkpoint(TRUNCATE); // run from SQL tab
2. LocalDB.db → copy to external disk/network
3. (optional) verify file integrity3) ConnectionTimeout / CommandTimeout / Reconnect
The four timing options inside Connections:
| Option | Recommended | Meaning |
|---|---|---|
| ConnectionTimeout | 15 sec | Time before giving up on Open() |
| CommandTimeout | 30 sec | Single-SQL execution timeout |
| PingIntervalSec | 10 sec | Periodic liveness check (meaningful for networked DBs) |
| ReconnectRetries | 3 | Auto-reconnect attempts on disconnection |
Mostly minor for a single-file SQLite, but they carry over verbatim when you move to MSSQL — they're pre-set in the sample for that reason.
4) Six Operational Checkpoints in the Code
The six defensive patterns shared by every DB function in the sample.
A. IsOpen guard
if( DB["local"].IsOpen == false )
{
ShowMessage(EB_Ok, "DB is not open. Press [Open] first.");
return false;
}B. Selected row guard
if( SelectIndex < 0 || SelectIndex >= DB["local"].RowCount )
{
ShowMessage(EB_Ok, "Select a row first.");
return false;
}C. LastError logging
if( DB["local"].RunSqlQueryParam(sql, p) == false )
{
LogError($"DB_xxx failed : {DB["local"].LastError}");
ShowMessage(EB_Ok, $"DB xxx failed : {DB["local"].LastError}");
return false;
}D. Rollback on transaction failure
if( DB["local"].RunSqlQueryParam(sql, p) == false )
{
DB["local"].Rollback();
// ...
}E. Sync status label on Open failure
if( DB["local"].Open() == false )
{
DbStatusText = "● CLOSED";
return false;
}
DbStatusText = "● OPEN";F. Refresh after mutation
return DB_Refresh();After every INSERT / UPDATE / DELETE, refresh the screen so DB state and screen state never drift.
5) Pre-production Checklist
| Item | Check |
|---|---|
JournalMode | "WAL" |
AutoBackupEnabled | true (production) |
BackupFolder | Separate disk recommended |
BackupKeepLast | Mind disk space (typically 14 – 60) |
LastError logging | Present in every failure branch |
IsOpen guard | First line of every DB function |
DB_Refresh at end of mutating function | Skipping leaves stale screen |
| External backup schedule | Weekly full backup at OS level recommended |
That's everything the DB_Sqlite sample shows about production-grade database integration. To take this into a real project, port the patterns from these 9 chapters and just swap in your domain table.