Bug 614439 - Downgrading from a Places branch version leaves user with double triggers.

r=dietrich a=blocking
This commit is contained in:
Marco Bonardo 2010-11-24 16:36:05 +01:00
Родитель c794ac5f0b
Коммит c91a023899
3 изменённых файлов: 19 добавлений и 40 удалений

Просмотреть файл

@ -946,12 +946,6 @@ nsNavHistory::InitDB()
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATE);
NS_ENSURE_SUCCESS(rv, rv);
// Visits triggers.
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER);
NS_ENSURE_SUCCESS(rv, rv);
// This makes a big difference in startup time for large profiles because of
// finding bookmark redirects using the referring page.
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_FROMVISIT);
@ -993,6 +987,9 @@ nsNavHistory::InitAdditionalDBItems()
nsresult rv = InitFunctions();
NS_ENSURE_SUCCESS(rv, rv);
rv = InitTriggers();
NS_ENSURE_SUCCESS(rv, rv);
// These statements are used by frecency calculation. Since frecency runs in
// the storage async thread, it needs to access them through a const history
// object, for thread-safety. Due to const correctness it's not possible for
@ -1110,6 +1107,17 @@ nsNavHistory::InitFunctions()
return NS_OK;
}
nsresult
nsNavHistory::InitTriggers()
{
nsresult rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
mozIStorageStatement*
nsNavHistory::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
{
@ -1793,9 +1801,8 @@ nsNavHistory::MigrateV10Up(mozIStorageConnection *aDBConn)
nsresult
nsNavHistory::MigrateV11Up(mozIStorageConnection *aDBConn)
{
// Temp tables are going away, so we need the visit_count triggers to return.
// Regardless triggers existance, every time we pass through this migration
// Temp tables are going away.
// For triggers correctness, every time we pass through this migration
// step, we must ensure correctness of visit_count values.
nsresult rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"UPDATE moz_places SET visit_count = "
@ -1810,34 +1817,6 @@ nsNavHistory::MigrateV11Up(mozIStorageConnection *aDBConn)
);
NS_ENSURE_SUCCESS(rv, rv);
// Now create triggers if needed.
nsCOMPtr<mozIStorageStatement> triggerDetection;
rv = aDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT name "
"FROM sqlite_master "
"WHERE type = 'trigger' "
"AND name = :trigger_name"),
getter_AddRefs(triggerDetection));
NS_ENSURE_SUCCESS(rv, rv);
// Both visits triggers were removed in the past at the same time, so we can
// check just one of them.
PRBool triggerExists;
rv = triggerDetection->BindUTF8StringByName(
NS_LITERAL_CSTRING("trigger_name"),
NS_LITERAL_CSTRING("moz_historyvisits_afterinsert_v2_trigger")
);
NS_ENSURE_SUCCESS(rv, rv);
rv = triggerDetection->ExecuteStep(&triggerExists);
NS_ENSURE_SUCCESS(rv, rv);
if (!triggerExists) {
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}

Просмотреть файл

@ -717,7 +717,7 @@ protected:
*/
nsresult InitAdditionalDBItems();
nsresult InitFunctions();
nsresult InitStatements();
nsresult InitTriggers();
nsresult ForceMigrateBookmarksDB(mozIStorageConnection *aDBConn);
nsresult MigrateV3Up(mozIStorageConnection *aDBConn);
nsresult MigrateV6Up(mozIStorageConnection *aDBConn);

Просмотреть файл

@ -77,7 +77,7 @@
* table changes.
*/
#define CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER NS_LITERAL_CSTRING( \
"CREATE TRIGGER moz_historyvisits_afterinsert_v2_trigger " \
"CREATE TEMP TRIGGER moz_historyvisits_afterinsert_v2_trigger " \
"AFTER INSERT ON moz_historyvisits FOR EACH ROW " \
"BEGIN " \
"UPDATE moz_places SET " \
@ -88,7 +88,7 @@
)
#define CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER NS_LITERAL_CSTRING( \
"CREATE TRIGGER moz_historyvisits_afterdelete_v2_trigger " \
"CREATE TEMP TRIGGER moz_historyvisits_afterdelete_v2_trigger " \
"AFTER DELETE ON moz_historyvisits FOR EACH ROW " \
"BEGIN " \
"UPDATE moz_places SET " \