Skip to content

Commit

Permalink
Don't optimize a readonly database
Browse files Browse the repository at this point in the history
  • Loading branch information
jmroot committed Oct 2, 2024
1 parent c3c817e commit c219570
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/cregistry/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,28 +604,30 @@ int reg_checkpoint(reg_registry* reg, reg_error* errPtr) {
int reg_optimize(reg_registry* reg, reg_error* errPtr)
{
#if SQLITE_VERSION_NUMBER >= 3018000
int result = 0;
sqlite3_stmt* stmt = NULL;
if (sqlite3_prepare_v2(reg->db, "PRAGMA optimize", -1, &stmt, NULL) == SQLITE_OK) {
int r;
do {
sqlite3_step(stmt);
r = sqlite3_reset(stmt);
if (r == SQLITE_OK) {
result = 1;
}
} while (r == SQLITE_BUSY);
}
if (!result) {
reg_sqlite_error(reg->db, errPtr, NULL);
}
if (stmt) {
sqlite3_finalize(stmt);
if (sqlite3_libversion_number() >= 3018000
&& sqlite3_db_readonly(reg->db, "registry") == 0) {
int result = 0;
sqlite3_stmt* stmt = NULL;
if (sqlite3_prepare_v2(reg->db, "PRAGMA optimize", -1, &stmt, NULL) == SQLITE_OK) {
int r;
do {
sqlite3_step(stmt);
r = sqlite3_reset(stmt);
if (r == SQLITE_OK) {
result = 1;
}
} while (r == SQLITE_BUSY);
}
if (!result) {
reg_sqlite_error(reg->db, errPtr, NULL);
}
if (stmt) {
sqlite3_finalize(stmt);
}
return result;
}
return result;
#else
return 1;
#endif
return 1;
}

/**
Expand Down

0 comments on commit c219570

Please sign in to comment.