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

Side by Side Diff: chrome/browser/history/visit_database.cc

Issue 9005036: [sql] WARN_UNUSED_RESULT on Execute(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/history/visit_database.h" 5 #include "chrome/browser/history/visit_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // save space, we do not record those user browsed visits which would be the 55 // save space, we do not record those user browsed visits which would be the
56 // majority in this table. Only other sources are recorded. 56 // majority in this table. Only other sources are recorded.
57 // Due to the tight relationship between visit_source and visits table, they 57 // Due to the tight relationship between visit_source and visits table, they
58 // should be created and dropped at the same time. 58 // should be created and dropped at the same time.
59 if (!GetDB().DoesTableExist("visit_source")) { 59 if (!GetDB().DoesTableExist("visit_source")) {
60 if (!GetDB().Execute("CREATE TABLE visit_source(" 60 if (!GetDB().Execute("CREATE TABLE visit_source("
61 "id INTEGER PRIMARY KEY,source INTEGER NOT NULL)")) 61 "id INTEGER PRIMARY KEY,source INTEGER NOT NULL)"))
62 return false; 62 return false;
63 } 63 }
64 64
65 // Index over url so we can quickly find visits for a page. This will just 65 // Index over url so we can quickly find visits for a page.
66 // fail if it already exists and we'll ignore it. 66 if (!GetDB().Execute(
67 GetDB().Execute("CREATE INDEX visits_url_index ON visits (url)"); 67 "CREATE INDEX IF NOT EXISTS visits_url_index ON visits (url)"))
68 return false;
68 69
69 // Create an index over from visits so that we can efficiently find 70 // Create an index over from visits so that we can efficiently find
70 // referrers and redirects. Ignore failures because it likely already exists. 71 // referrers and redirects.
71 GetDB().Execute("CREATE INDEX visits_from_index ON visits (from_visit)"); 72 if (!GetDB().Execute(
73 "CREATE INDEX IF NOT EXISTS visits_from_index ON "
74 "visits (from_visit)"))
75 return false;
72 76
73 // Create an index over time so that we can efficiently find the visits in a 77 // Create an index over time so that we can efficiently find the visits in a
74 // given time range (most history views are time-based). Ignore failures 78 // given time range (most history views are time-based).
75 // because it likely already exists. 79 if (!GetDB().Execute(
76 GetDB().Execute("CREATE INDEX visits_time_index ON visits (visit_time)"); 80 "CREATE INDEX IF NOT EXISTS visits_time_index ON "
81 "visits (visit_time)"))
82 return false;
77 83
78 return true; 84 return true;
79 } 85 }
80 86
81 bool VisitDatabase::DropVisitTable() { 87 bool VisitDatabase::DropVisitTable() {
82 GetDB().Execute("DROP TABLE visit_source");
83 // This will also drop the indices over the table. 88 // This will also drop the indices over the table.
84 return GetDB().Execute("DROP TABLE visits"); 89 return
90 GetDB().Execute("DROP TABLE IF EXISTS visit_source") &&
91 GetDB().Execute("DROP TABLE visits");
85 } 92 }
86 93
87 // Must be in sync with HISTORY_VISIT_ROW_FIELDS. 94 // Must be in sync with HISTORY_VISIT_ROW_FIELDS.
88 // static 95 // static
89 void VisitDatabase::FillVisitRow(sql::Statement& statement, VisitRow* visit) { 96 void VisitDatabase::FillVisitRow(sql::Statement& statement, VisitRow* visit) {
90 visit->visit_id = statement.ColumnInt64(0); 97 visit->visit_id = statement.ColumnInt64(0);
91 visit->url_id = statement.ColumnInt64(1); 98 visit->url_id = statement.ColumnInt64(1);
92 visit->visit_time = base::Time::FromInternalValue(statement.ColumnInt64(2)); 99 visit->visit_time = base::Time::FromInternalValue(statement.ColumnInt64(2));
93 visit->referring_visit = statement.ColumnInt64(3); 100 visit->referring_visit = statement.ColumnInt64(3);
94 visit->transition = content::PageTransitionFromInt(statement.ColumnInt(4)); 101 visit->transition = content::PageTransitionFromInt(statement.ColumnInt(4));
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // Get the source entries out of the query result. 545 // Get the source entries out of the query result.
539 while (statement.Step()) { 546 while (statement.Step()) {
540 std::pair<VisitID, VisitSource> source_entry(statement.ColumnInt64(0), 547 std::pair<VisitID, VisitSource> source_entry(statement.ColumnInt64(0),
541 static_cast<VisitSource>(statement.ColumnInt(1))); 548 static_cast<VisitSource>(statement.ColumnInt(1)));
542 sources->insert(source_entry); 549 sources->insert(source_entry);
543 } 550 }
544 } 551 }
545 } 552 }
546 553
547 } // namespace history 554 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698