Bug 607112 - make GUID a column in moz_places and moz_bookmarks

Part 3 - create a guid column on moz_places and add guids
r=mak
This commit is contained in:
Shawn Wilsher 2010-12-02 09:43:50 -08:00
parent 43de9ba84f
commit d161f47b13
4 changed files with 70 additions and 0 deletions

View File

@ -952,6 +952,9 @@ nsNavHistory::InitDB()
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_LASTVISITDATE);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_GUID);
NS_ENSURE_SUCCESS(rv, rv);
// CREATE TABLE moz_historyvisits.
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS);
NS_ENSURE_SUCCESS(rv, rv);
@ -1094,6 +1097,18 @@ nsNavHistory::CheckAndUpdateGUIDs()
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
// Finally, we need to generate guids for any places that do not already have
// one.
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_places "
"SET guid = GENERATE_GUID() "
"WHERE guid IS NULL "
), getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -1927,6 +1942,17 @@ nsNavHistory::MigrateV11Up(mozIStorageConnection *aDBConn)
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_GUID);
NS_ENSURE_SUCCESS(rv, rv);
// moz_placess grew a guid column. Add the column, but do not populate it
// with anything just yet. We will do that soon.
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"ALTER TABLE moz_places "
"ADD COLUMN guid TEXT"
));
NS_ENSURE_SUCCESS(rv, rv);
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_GUID);
NS_ENSURE_SUCCESS(rv, rv);
}
// We need to update our guids before we do any real database work.

View File

@ -79,6 +79,11 @@
"lastvisitdateindex", "moz_places", "last_visit_date", "" \
)
#define CREATE_IDX_MOZ_PLACES_GUID \
CREATE_PLACES_IDX( \
"guid_uniqueindex", "moz_places", "guid", "UNIQUE" \
)
/**
* moz_historyvisits
*/

View File

@ -53,6 +53,7 @@
", favicon_id INTEGER" \
", frecency INTEGER DEFAULT -1 NOT NULL" \
", last_visit_date INTEGER " \
", guid TEXT" \
")" \
)
#define MOZ_PLACES_COLUMNS \

View File

@ -51,6 +51,7 @@ function test_initial_state()
stmt.finalize();
do_check_false(db.indexExists("moz_bookmarks_guid_uniqueindex"));
do_check_false(db.indexExists("moz_places_guid_uniqueindex"));
// There should be five item annotations for a bookmark guid.
stmt = db.createStatement(
@ -167,6 +168,40 @@ function test_bookmark_guid_annotation_removed()
run_next_test();
}
function test_moz_places_guid_exists()
{
// This will throw if the column does not exist
let stmt = DBConn().createStatement(
"SELECT guid "
+ "FROM moz_places "
);
stmt.finalize();
run_next_test();
}
function test_place_guids_non_null()
{
// First, sanity check that we have a non-zero amount of places.
let stmt = DBConn().createStatement(
"SELECT COUNT(1) "
+ "FROM moz_places "
);
do_check_true(stmt.executeStep());
do_check_neq(stmt.getInt32(0), 0);
stmt.finalize();
// Now, make sure we have no NULL guid entry.
stmt = DBConn().createStatement(
"SELECT guid "
+ "FROM moz_places "
+ "WHERE guid IS NULL "
);
do_check_false(stmt.executeStep());
stmt.finalize();
run_next_test();
}
function test_final_state()
{
// We open a new database mostly so that we can check that the settings were
@ -183,6 +218,7 @@ function test_final_state()
}
do_check_true(db.indexExists("moz_bookmarks_guid_uniqueindex"));
do_check_true(db.indexExists("moz_places_guid_uniqueindex"));
do_check_eq(db.schemaVersion, 11);
@ -199,6 +235,8 @@ let tests = [
test_bookmark_guids_non_null,
test_bookmark_guid_annotation_imported,
test_bookmark_guid_annotation_removed,
test_moz_places_guid_exists,
test_place_guids_non_null,
test_final_state,
];
let index = 0;