diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-30 19:33:53 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-30 19:33:53 +0000 |
commit | 9660ddd38561758694488c7110a7edbeacb1b305 (patch) | |
tree | a08b6f154d33fa14365addf0681ee0f78b35220e /chrome/browser/history | |
parent | 769d3c1343f9a53a9ade10146c48f022adb099d8 (diff) | |
download | chromium_src-9660ddd38561758694488c7110a7edbeacb1b305.zip chromium_src-9660ddd38561758694488c7110a7edbeacb1b305.tar.gz chromium_src-9660ddd38561758694488c7110a7edbeacb1b305.tar.bz2 |
Correct sqlite wrapper behavior on systems where wchar_t is UTF-32,
for example Linux.
The problem was that old code assumed wstring is UTF-16, which resulted
in string corruption on Linux. I actually tested it on browser/history
unit tests, see http://codereview.chromium.org/18758.
Review URL: http://codereview.chromium.org/18805
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8977 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r-- | chrome/browser/history/download_database.cc | 4 | ||||
-rw-r--r-- | chrome/browser/history/starred_url_database.cc | 4 | ||||
-rw-r--r-- | chrome/browser/history/url_database.cc | 19 | ||||
-rw-r--r-- | chrome/browser/history/visitsegment_database.cc | 2 |
4 files changed, 16 insertions, 13 deletions
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc index f4b88eb..7f66dba 100644 --- a/chrome/browser/history/download_database.cc +++ b/chrome/browser/history/download_database.cc @@ -70,9 +70,9 @@ void DownloadDatabase::QueryDownloads(std::vector<DownloadCreateInfo>* results) DownloadCreateInfo info; info.db_handle = statement->column_int64(0); std::wstring path_str; - statement->column_string16(1, &path_str); + statement->column_wstring(1, &path_str); info.path = FilePath::FromWStringHack(path_str); - statement->column_string16(2, &info.url); + statement->column_wstring(2, &info.url); info.start_time = Time::FromTimeT(statement->column_int64(3)); info.received_bytes = statement->column_int64(4); info.total_bytes = statement->column_int64(5); diff --git a/chrome/browser/history/starred_url_database.cc b/chrome/browser/history/starred_url_database.cc index c4fabbc0..2a877c4 100644 --- a/chrome/browser/history/starred_url_database.cc +++ b/chrome/browser/history/starred_url_database.cc @@ -58,7 +58,7 @@ void FillInStarredEntry(SQLStatement* s, StarredEntry* entry) { switch (s->column_int(1)) { case 0: entry->type = history::StarredEntry::URL; - entry->url = GURL(WideToUTF8(s->column_string16(6))); + entry->url = GURL(WideToUTF8(s->column_wstring(6))); break; case 1: entry->type = history::StarredEntry::BOOKMARK_BAR; @@ -73,7 +73,7 @@ void FillInStarredEntry(SQLStatement* s, StarredEntry* entry) { NOTREACHED(); break; } - entry->title = s->column_string16(2); + entry->title = s->column_wstring(2); entry->date_added = Time::FromInternalValue(s->column_int64(3)); entry->visual_order = s->column_int(4); entry->parent_group_id = s->column_int64(5); diff --git a/chrome/browser/history/url_database.cc b/chrome/browser/history/url_database.cc index c824a6e..6db3b10 100644 --- a/chrome/browser/history/url_database.cc +++ b/chrome/browser/history/url_database.cc @@ -45,7 +45,7 @@ void URLDatabase::FillURLRow(SQLStatement& s, history::URLRow* i) { DCHECK(i); i->id_ = s.column_int64(0); i->url_ = GURL(s.column_string(1)); - i->title_ = s.column_string16(2); + i->title_ = s.column_wstring(2); i->visit_count_ = s.column_int(3); i->typed_count_ = s.column_int(4); i->last_visit_ = Time::FromInternalValue(s.column_int64(5)); @@ -239,12 +239,15 @@ void URLDatabase::AutocompleteForPrefix(const std::wstring& prefix, return; // We will find all strings between "prefix" and this string, which is prefix - // followed by the maximum character size. - std::wstring end_query(prefix); - end_query.push_back(std::numeric_limits<wchar_t>::max()); - - statement->bind_wstring(0, prefix); - statement->bind_wstring(1, end_query); + // followed by the maximum character size. Use 8-bit strings for everything + // so we can be sure sqlite is comparing everything in 8-bit mode. Otherwise, + // it will have to convert strings either to UTF-8 or UTF-16 for comparison. + std::string prefix_utf8(WideToUTF8(prefix)); + std::string end_query(prefix_utf8); + end_query.push_back(std::numeric_limits<unsigned char>::max()); + + statement->bind_string(0, prefix_utf8); + statement->bind_string(1, end_query); statement->bind_int(2, static_cast<int>(max_results)); while (statement->step() == SQLITE_ROW) { @@ -397,7 +400,7 @@ void URLDatabase::GetMostRecentKeywordSearchTerms( KeywordSearchTermVisit visit; while (statement->step() == SQLITE_ROW) { - visit.term = statement->column_string16(0); + visit.term = statement->column_wstring(0); visit.time = Time::FromInternalValue(statement->column_int64(1)); matches->push_back(visit); } diff --git a/chrome/browser/history/visitsegment_database.cc b/chrome/browser/history/visitsegment_database.cc index 0da96a1..1687e13 100644 --- a/chrome/browser/history/visitsegment_database.cc +++ b/chrome/browser/history/visitsegment_database.cc @@ -315,7 +315,7 @@ void VisitSegmentDatabase::QuerySegmentUsage( std::string url; std::wstring title; statement2->column_string(0, &url); - statement2->column_string16(1, &title); + statement2->column_wstring(1, &title); pud->SetURL(GURL(url)); pud->SetTitle(title); } |