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 | |
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')
-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 | ||||
-rw-r--r-- | chrome/browser/importer/firefox3_importer.cc | 6 | ||||
-rw-r--r-- | chrome/browser/meta_table_helper.cc | 4 | ||||
-rwxr-xr-x | chrome/browser/webdata/web_database.cc | 22 |
7 files changed, 32 insertions, 29 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); } diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index ea470d5..cb2f13f 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -103,7 +103,7 @@ void Firefox3Importer::ImportHistory() { continue; history::URLRow row(url); - row.set_title(s.column_string16(1)); + row.set_title(s.column_wstring(1)); row.set_visit_count(s.column_int(2)); row.set_hidden(s.column_int(3) == 1); row.set_typed_count(s.column_int(4)); @@ -421,7 +421,7 @@ void Firefox3Importer::GetTopBookmarkFolder(sqlite3* db, int folder_id, BookmarkItem* item = new BookmarkItem; item->parent = -1; // The top level folder has no parent. item->id = folder_id; - item->title = s.column_string16(0); + item->title = s.column_wstring(0); item->type = 2; item->favicon = 0; list->push_back(item); @@ -453,7 +453,7 @@ void Firefox3Importer::GetWholeBookmarkFolder(sqlite3* db, BookmarkList* list, item->parent = static_cast<int>(position); item->id = s.column_int(0); item->url = GURL(s.column_string(1)); - item->title = s.column_string16(2); + item->title = s.column_wstring(2); item->type = s.column_int(3); item->keyword = s.column_string(4); item->date_added = Time::FromTimeT(s.column_int64(5)/1000000); diff --git a/chrome/browser/meta_table_helper.cc b/chrome/browser/meta_table_helper.cc index 11fd5f5..6667197 100644 --- a/chrome/browser/meta_table_helper.cc +++ b/chrome/browser/meta_table_helper.cc @@ -53,7 +53,7 @@ bool MetaTableHelper::SetValue(const std::string& key, SQLStatement s; if (!PrepareSetStatement(&s, key)) return false; - s.bind_text16(1, value.c_str()); + s.bind_wstring(1, value); return s.step() == SQLITE_DONE; } @@ -64,7 +64,7 @@ bool MetaTableHelper::GetValue(const std::string& key, if (!PrepareGetStatement(&s, key)) return false; - s.column_string16(0, value); + s.column_wstring(0, value); return true; } diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index 7d5b524..7ee4f79 100755 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -541,23 +541,23 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { std::wstring tmp; template_url->set_id(s.column_int64(0)); - s.column_string16(1, &tmp); + s.column_wstring(1, &tmp); DCHECK(!tmp.empty()); template_url->set_short_name(tmp); - s.column_string16(2, &tmp); + s.column_wstring(2, &tmp); template_url->set_keyword(tmp); - s.column_string16(3, &tmp); + s.column_wstring(3, &tmp); if (!tmp.empty()) template_url->SetFavIconURL(GURL(WideToUTF8(tmp))); - s.column_string16(4, &tmp); + s.column_wstring(4, &tmp); template_url->SetURL(tmp, 0, 0); template_url->set_safe_for_autoreplace(s.column_int(5) == 1); - s.column_string16(6, &tmp); + s.column_wstring(6, &tmp); if (!tmp.empty()) template_url->set_originating_url(GURL(WideToUTF8(tmp))); @@ -571,7 +571,7 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { template_url->set_show_in_default_list(s.column_int(10) == 1); - s.column_string16(11, &tmp); + s.column_wstring(11, &tmp); template_url->SetSuggestionsURL(tmp, 0, 0); template_url->set_prepopulate_id(s.column_int(12)); @@ -761,12 +761,12 @@ static void InitPasswordFormFromStatement(PasswordForm* form, form->origin = GURL(tmp); s->column_string(1, &tmp); form->action = GURL(tmp); - s->column_string16(2, &form->username_element); - s->column_string16(3, &form->username_value); - s->column_string16(4, &form->password_element); + s->column_wstring(2, &form->username_element); + s->column_wstring(3, &form->username_value); + s->column_wstring(4, &form->password_element); s->column_blob_as_string(5, &encrypted_password); Encryptor::DecryptWideString(encrypted_password, &form->password_value); - s->column_string16(6, &form->submit_element); + s->column_wstring(6, &form->submit_element); s->column_string(7, &tmp); form->signon_realm = tmp; form->ssl_valid = (s->column_int(8) > 0); @@ -1020,7 +1020,7 @@ bool WebDatabase::GetFormValuesForElementName(const std::wstring& name, values->clear(); int result; while ((result = s.step()) == SQLITE_ROW) - values->push_back(s.column_string16(0)); + values->push_back(s.column_wstring(0)); return result == SQLITE_DONE; } |