#
#
# patch "ChangeLog"
# from [20ddcad4fcef72deb257d9cf1769af16d9475233]
# to [87be10b22d9008f59e9133ec8dbe38e7f8edeb66]
#
# patch "schema_migration.cc"
# from [6c44cfb87b044ddc7669113c1ea26be395abad37]
# to [d29a88209eb9605e602510c255ad7cf9f4095386]
#
============================================================
--- ChangeLog 20ddcad4fcef72deb257d9cf1769af16d9475233
+++ ChangeLog 87be10b22d9008f59e9133ec8dbe38e7f8edeb66
@@ -1,3 +1,8 @@
+2005-12-04 Nathaniel Smith
+
+ * schema_migration.cc: Modernize error checking a bit. (Use E()
+ and I() instead of throwing runtime_errors.)
+
2005-12-03 Nathaniel Smith
* sanity.cc (dump_buffer): If we dumped debug info, write out a
============================================================
--- schema_migration.cc 6c44cfb87b044ddc7669113c1ea26be395abad37
+++ schema_migration.cc d29a88209eb9605e602510c255ad7cf9f4095386
@@ -181,7 +181,7 @@
if (res != SQLITE_OK)
{
logged_sqlite3_exec(sql, "ROLLBACK", NULL, NULL, NULL);
- throw runtime_error("failure extracting schema from sqlite_master");
+ E(false, F("failure extracting schema from sqlite_master"));
}
massage_sql_tokens(tmp, tmp2);
calculate_id(tmp2, id);
@@ -209,14 +209,12 @@
{
string init;
- if (sql == NULL)
- throw runtime_error("NULL sqlite object given to migrate");
+ I(sql != NULL);
calculate_schema_id(sql, init);
- if (sqlite3_create_function(sql, "sha1", -1, SQLITE_UTF8, NULL,
- &sqlite_sha1_fn, NULL, NULL))
- throw runtime_error("error registering sha1 function with sqlite");
+ I(!sqlite3_create_function(sql, "sha1", -1, SQLITE_UTF8, NULL,
+ &sqlite_sha1_fn, NULL, NULL));
bool migrating = false;
for (vector< pair >::const_iterator i = migration_events.begin();
@@ -225,8 +223,8 @@
if (i->first == init)
{
- if (logged_sqlite3_exec(sql, "BEGIN EXCLUSIVE", NULL, NULL, NULL) != SQLITE_OK)
- throw runtime_error("error at transaction BEGIN statement");
+ E(logged_sqlite3_exec(sql, "BEGIN EXCLUSIVE", NULL, NULL, NULL) == SQLITE_OK,
+ F("error at transaction BEGIN statement"));
migrating = true;
}
@@ -240,24 +238,22 @@
{
if (migrating)
logged_sqlite3_exec(sql, "ROLLBACK", NULL, NULL, NULL);
- throw runtime_error("mismatched pre-state to migration step");
+ I(false);
}
if (i->second == NULL)
{
logged_sqlite3_exec(sql, "ROLLBACK", NULL, NULL, NULL);
- throw runtime_error("NULL migration specifier");
+ I(false);
}
// do this migration step
else if (! i->second(sql, &errmsg, __app))
{
- string e("migration step failed");
- if (errmsg != NULL)
- e.append(string(": ") + errmsg);
logged_sqlite3_exec(sql, "ROLLBACK", NULL, NULL, NULL);
- throw runtime_error(e);
- }
+ E(false, F("migration step failed: %s")
+ % (errmsg ? errmsg : "unknown error"));
+ }
}
}
@@ -269,21 +265,19 @@
if (curr != target_id)
{
logged_sqlite3_exec(sql, "ROLLBACK", NULL, NULL, NULL);
- throw runtime_error("mismatched result of migration, "
- "got " + curr + ", wanted " + target_id);
+ E(false, F("mismatched result of migration, got %s, wanted %s")
+ % curr % target_id);
}
P(F("committing changes to database"));
- if (logged_sqlite3_exec(sql, "COMMIT", NULL, NULL, NULL) != SQLITE_OK)
- {
- throw runtime_error("failure on COMMIT");
- }
+ E(logged_sqlite3_exec(sql, "COMMIT", NULL, NULL, NULL) == SQLITE_OK,
+ F("failure on COMMIT"));
P(F("optimizing database"));
- if (logged_sqlite3_exec(sql, "VACUUM", NULL, NULL, NULL) != SQLITE_OK)
- throw runtime_error("error vacuuming after migration");
+ E(logged_sqlite3_exec(sql, "VACUUM", NULL, NULL, NULL) == SQLITE_OK,
+ F("error vacuuming after migration"));
- if (logged_sqlite3_exec(sql, "ANALYZE", NULL, NULL, NULL) != SQLITE_OK)
- throw runtime_error("error running analyze after migration");
+ E(logged_sqlite3_exec(sql, "ANALYZE", NULL, NULL, NULL) == SQLITE_OK,
+ F("error running analyze after migration"));
}
else
{