| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/url_database.h" | 5 #include "chrome/browser/history/url_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // TODO(brettw): do something fancy here with encoding, etc. | 38 // TODO(brettw): do something fancy here with encoding, etc. |
| 39 return gurl.spec(); | 39 return gurl.spec(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Convenience to fill a history::URLRow. Must be in sync with the fields in | 42 // Convenience to fill a history::URLRow. Must be in sync with the fields in |
| 43 // kURLRowFields. | 43 // kURLRowFields. |
| 44 void URLDatabase::FillURLRow(SQLStatement& s, history::URLRow* i) { | 44 void URLDatabase::FillURLRow(SQLStatement& s, history::URLRow* i) { |
| 45 DCHECK(i); | 45 DCHECK(i); |
| 46 i->id_ = s.column_int64(0); | 46 i->id_ = s.column_int64(0); |
| 47 i->url_ = GURL(s.column_string(1)); | 47 i->url_ = GURL(s.column_string(1)); |
| 48 i->title_ = s.column_string16(2); | 48 i->title_ = s.column_wstring(2); |
| 49 i->visit_count_ = s.column_int(3); | 49 i->visit_count_ = s.column_int(3); |
| 50 i->typed_count_ = s.column_int(4); | 50 i->typed_count_ = s.column_int(4); |
| 51 i->last_visit_ = Time::FromInternalValue(s.column_int64(5)); | 51 i->last_visit_ = Time::FromInternalValue(s.column_int64(5)); |
| 52 i->hidden_ = s.column_int(6) != 0; | 52 i->hidden_ = s.column_int(6) != 0; |
| 53 i->favicon_id_ = s.column_int64(7); | 53 i->favicon_id_ = s.column_int64(7); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool URLDatabase::GetURLRow(URLID url_id, URLRow* info) { | 56 bool URLDatabase::GetURLRow(URLID url_id, URLRow* info) { |
| 57 // TODO(brettw) We need check for empty URLs to handle the case where | 57 // TODO(brettw) We need check for empty URLs to handle the case where |
| 58 // there are old URLs in the database that are empty that got in before | 58 // there are old URLs in the database that are empty that got in before |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 results->clear(); | 232 results->clear(); |
| 233 SQLITE_UNIQUE_STATEMENT(statement, GetStatementCache(), | 233 SQLITE_UNIQUE_STATEMENT(statement, GetStatementCache(), |
| 234 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls " | 234 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls " |
| 235 "WHERE url >= ? AND url < ? AND hidden = 0 " | 235 "WHERE url >= ? AND url < ? AND hidden = 0 " |
| 236 "ORDER BY typed_count DESC, visit_count DESC, last_visit_time DESC " | 236 "ORDER BY typed_count DESC, visit_count DESC, last_visit_time DESC " |
| 237 "LIMIT ?"); | 237 "LIMIT ?"); |
| 238 if (!statement.is_valid()) | 238 if (!statement.is_valid()) |
| 239 return; | 239 return; |
| 240 | 240 |
| 241 // We will find all strings between "prefix" and this string, which is prefix | 241 // We will find all strings between "prefix" and this string, which is prefix |
| 242 // followed by the maximum character size. | 242 // followed by the maximum character size. Use 8-bit strings for everything |
| 243 std::wstring end_query(prefix); | 243 // so we can be sure sqlite is comparing everything in 8-bit mode. Otherwise, |
| 244 end_query.push_back(std::numeric_limits<wchar_t>::max()); | 244 // it will have to convert strings either to UTF-8 or UTF-16 for comparison. |
| 245 std::string prefix_utf8(WideToUTF8(prefix)); |
| 246 std::string end_query(prefix_utf8); |
| 247 end_query.push_back(std::numeric_limits<unsigned char>::max()); |
| 245 | 248 |
| 246 statement->bind_wstring(0, prefix); | 249 statement->bind_string(0, prefix_utf8); |
| 247 statement->bind_wstring(1, end_query); | 250 statement->bind_string(1, end_query); |
| 248 statement->bind_int(2, static_cast<int>(max_results)); | 251 statement->bind_int(2, static_cast<int>(max_results)); |
| 249 | 252 |
| 250 while (statement->step() == SQLITE_ROW) { | 253 while (statement->step() == SQLITE_ROW) { |
| 251 history::URLRow info; | 254 history::URLRow info; |
| 252 FillURLRow(*statement, &info); | 255 FillURLRow(*statement, &info); |
| 253 if (info.url().is_valid()) | 256 if (info.url().is_valid()) |
| 254 results->push_back(info); | 257 results->push_back(info); |
| 255 } | 258 } |
| 256 } | 259 } |
| 257 | 260 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 std::wstring next_prefix = lower_prefix; | 393 std::wstring next_prefix = lower_prefix; |
| 391 next_prefix[next_prefix.size() - 1] = | 394 next_prefix[next_prefix.size() - 1] = |
| 392 next_prefix[next_prefix.size() - 1] + 1; | 395 next_prefix[next_prefix.size() - 1] + 1; |
| 393 statement->bind_int64(0, keyword_id); | 396 statement->bind_int64(0, keyword_id); |
| 394 statement->bind_wstring(1, lower_prefix); | 397 statement->bind_wstring(1, lower_prefix); |
| 395 statement->bind_wstring(2, next_prefix); | 398 statement->bind_wstring(2, next_prefix); |
| 396 statement->bind_int(3, max_count); | 399 statement->bind_int(3, max_count); |
| 397 | 400 |
| 398 KeywordSearchTermVisit visit; | 401 KeywordSearchTermVisit visit; |
| 399 while (statement->step() == SQLITE_ROW) { | 402 while (statement->step() == SQLITE_ROW) { |
| 400 visit.term = statement->column_string16(0); | 403 visit.term = statement->column_wstring(0); |
| 401 visit.time = Time::FromInternalValue(statement->column_int64(1)); | 404 visit.time = Time::FromInternalValue(statement->column_int64(1)); |
| 402 matches->push_back(visit); | 405 matches->push_back(visit); |
| 403 } | 406 } |
| 404 } | 407 } |
| 405 | 408 |
| 406 bool URLDatabase::MigrateFromVersion11ToVersion12() { | 409 bool URLDatabase::MigrateFromVersion11ToVersion12() { |
| 407 URLRow about_row; | 410 URLRow about_row; |
| 408 if (GetRowForURL(GURL("about:blank"), &about_row)) { | 411 if (GetRowForURL(GURL("about:blank"), &about_row)) { |
| 409 about_row.set_favicon_id(0); | 412 about_row.set_favicon_id(0); |
| 410 return UpdateURLRow(about_row.id(), about_row); | 413 return UpdateURLRow(about_row.id(), about_row); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 } | 474 } |
| 472 | 475 |
| 473 void URLDatabase::CreateSupplimentaryURLIndices() { | 476 void URLDatabase::CreateSupplimentaryURLIndices() { |
| 474 // Add a favicon index. This is useful when we delete urls. | 477 // Add a favicon index. This is useful when we delete urls. |
| 475 sqlite3_exec(GetDB(), "CREATE INDEX urls_favicon_id_INDEX ON urls (favicon_id)
", | 478 sqlite3_exec(GetDB(), "CREATE INDEX urls_favicon_id_INDEX ON urls (favicon_id)
", |
| 476 NULL, NULL, NULL); | 479 NULL, NULL, NULL); |
| 477 } | 480 } |
| 478 | 481 |
| 479 } // namespace history | 482 } // namespace history |
| 480 | 483 |
| OLD | NEW |