From: Michael Vrable Date: Mon, 2 Jun 2008 20:48:36 +0000 (-0700) Subject: Store unspecified scheme names in database as empty string, not null. X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=commitdiff_plain;h=910255ec7fb85ef6c7b9515e9761892ca408c389 Store unspecified scheme names in database as empty string, not null. Avoid the use of nulls to represent an unspecified backup scheme in the local database. This should fix the bug where database cleaning would not touch backups without a scheme name. --- diff --git a/contrib/upgrade0.7-localdb.sql b/contrib/upgrade0.7-localdb.sql index a7bf056..9fbed0e 100644 --- a/contrib/upgrade0.7-localdb.sql +++ b/contrib/upgrade0.7-localdb.sql @@ -4,6 +4,10 @@ -- This script should be loaded after connecting to the database to be -- upgraded. +-- An unspecified bacukp scheme name is now stored in the database as an empty +-- string rather than as NULL. +update snapshots set scheme = '' where scheme is null; + -- The subblock_signatures table was added to store a signature for old blocks -- for performing subfile incremental backups. create table subblock_signatures ( diff --git a/localdb.cc b/localdb.cc index 2f5af6e..cc8a83c 100644 --- a/localdb.cc +++ b/localdb.cc @@ -85,6 +85,9 @@ void LocalDb::Open(const char *path, const char *snapshot_name, sqlite3_extended_result_codes(db, 1); + if (snapshot_scheme == NULL) + snapshot_scheme = ""; + /* Insert this snapshot into the database, and determine the integer key * which will be used to identify it. */ sqlite3_stmt *stmt = Prepare("insert into " @@ -92,11 +95,8 @@ void LocalDb::Open(const char *path, const char *snapshot_name, "values (?, ?, julianday('now'), ?)"); sqlite3_bind_text(stmt, 1, snapshot_name, strlen(snapshot_name), SQLITE_TRANSIENT); - if (snapshot_scheme == NULL) - sqlite3_bind_null(stmt, 2); - else - sqlite3_bind_text(stmt, 2, snapshot_scheme, strlen(snapshot_scheme), - SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 2, snapshot_scheme, strlen(snapshot_scheme), + SQLITE_TRANSIENT); sqlite3_bind_double(stmt, 3, intent); rc = sqlite3_step(stmt); diff --git a/metadata.cc b/metadata.cc index f29c486..d946386 100644 --- a/metadata.cc +++ b/metadata.cc @@ -116,7 +116,7 @@ MetadataWriter::MetadataWriter(TarSegmentStore *store, { statcache_path = path; statcache_path += "/statcache2"; - if (snapshot_scheme != NULL) + if (snapshot_scheme != NULL && strlen(snapshot_scheme) > 0) statcache_path = statcache_path + "-" + snapshot_scheme; statcache_tmp_path = statcache_path + "." + snapshot_name; diff --git a/scandir.cc b/scandir.cc index d50867a..d462432 100644 --- a/scandir.cc +++ b/scandir.cc @@ -758,17 +758,14 @@ int main(int argc, char *argv[]) * snapshot. */ string database_path = localdb_dir + "/localdb.sqlite"; db = new LocalDb; - db->Open(database_path.c_str(), desc_buf, - backup_scheme.size() ? backup_scheme.c_str() : NULL, + db->Open(database_path.c_str(), desc_buf, backup_scheme.c_str(), snapshot_intent); tss = new TarSegmentStore(remote, db); /* Initialize the stat cache, for skipping over unchanged files. */ metawriter = new MetadataWriter(tss, localdb_dir.c_str(), desc_buf, - backup_scheme.size() - ? backup_scheme.c_str() - : NULL); + backup_scheme.c_str()); scanfile(".", false); diff --git a/schema.sql b/schema.sql index 2851f0f..9d2137e 100644 --- a/schema.sql +++ b/schema.sql @@ -7,7 +7,7 @@ create table snapshots ( snapshotid integer primary key, name text not null, - scheme text, + scheme text not null, timestamp real, intent real );