Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Unified Diff: components/history/core/browser/download_database.cc

Issue 1897153005: Make SQL in DownloadDatabase SQLite pre 3.8.3 compatible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: char() was added by 3.7.16 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/history/core/browser/history_backend_db_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/history/core/browser/download_database.cc
diff --git a/components/history/core/browser/download_database.cc b/components/history/core/browser/download_database.cc
index fb6b9efb68fffe5af1679601fc435c9d6ad22429..890b781c4ee73d0a10a9c82efc18cfedd58773db 100644
--- a/components/history/core/browser/download_database.cc
+++ b/components/history/core/browser/download_database.cc
@@ -4,6 +4,8 @@
#include "components/history/core/browser/download_database.h"
+#include <inttypes.h>
+
#include <limits>
#include <memory>
#include <string>
@@ -12,6 +14,7 @@
#include "base/debug/alias.h"
#include "base/files/file_path.h"
#include "base/metrics/histogram.h"
+#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -238,16 +241,26 @@ bool DownloadDatabase::MigrateHashHttpMethodAndGenerateGuids() {
// have an elevated risk of collision with GUIDs generated via
// base::GenerateGUID() and are considered valid by all known consumers. Hence
// no additional migration logic is being introduced to fix those GUIDs.
- const char kMigrateGuidsQuery[] =
- "UPDATE downloads SET guid = printf"
- "(\"%08X-%s-4%s-%01X%s-%s\","
- " id,"
- " hex(randomblob(2)),"
- " substr(hex(randomblob(2)),2),"
- " (8 | (random() & 3)),"
- " substr(hex(randomblob(2)),2),"
- " hex(randomblob(6)))";
- return GetDB().Execute(kMigrateGuidsQuery);
+ sql::Statement select(GetDB().GetUniqueStatement("SELECT id FROM downloads"));
+ sql::Statement update(
+ GetDB().GetUniqueStatement("UPDATE downloads SET guid = ? WHERE id = ?"));
+ while (select.Step()) {
+ uint32_t id = select.ColumnInt(0);
+ uint64_t r1 = base::RandUint64();
+ uint64_t r2 = base::RandUint64();
+ std::string guid = base::StringPrintf(
+ "%08" PRIX32 "-%04" PRIX64 "-4%03" PRIX64 "-%04" PRIX64 "-%012" PRIX64,
+ id, r1 >> 48,
+ (r1 >> 36) & 0xfff,
+ ((8 | ((r1 >> 34) & 3)) << 12) | ((r1 >> 22) & 0xfff),
+ r2 & 0xffffffffffff);
+ update.BindString(0, guid);
+ update.BindInt(1, id);
+ if (!update.Run())
+ return false;
+ update.Reset(true);
+ }
+ return true;
}
bool DownloadDatabase::MigrateDownloadTabUrl() {
« no previous file with comments | « no previous file | components/history/core/browser/history_backend_db_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698