diff options
Diffstat (limited to 'chrome')
-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 | ||||
-rw-r--r-- | chrome/common/sqlite_utils.cc | 36 | ||||
-rw-r--r-- | chrome/common/sqlite_utils.h | 27 |
9 files changed, 54 insertions, 70 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; } diff --git a/chrome/common/sqlite_utils.cc b/chrome/common/sqlite_utils.cc index e45614a..a1d62bc 100644 --- a/chrome/common/sqlite_utils.cc +++ b/chrome/common/sqlite_utils.cc @@ -6,6 +6,7 @@ #include "base/file_path.h" #include "base/logging.h" +#include "base/string16.h" int OpenSqliteDb(const FilePath& filepath, sqlite3** database) { #if defined(OS_WIN) @@ -203,16 +204,6 @@ int SQLStatement::prepare(sqlite3* db, const char* sql, int sql_len) { return rv; } -int SQLStatement::prepare16(sqlite3* db, const wchar_t* sql, int sql_len) { - DCHECK(!stmt_); - sql_len *= sizeof(wchar_t); - int rv = sqlite3_prepare16_v2(db, sql, sql_len, &stmt_, NULL); - if (rv != SQLITE_OK) { - DLOG(ERROR) << "SQLStatement.prepare16_v2 failed: " << sqlite3_errmsg(db); - } - return rv; -} - int SQLStatement::step() { DCHECK(stmt_); return sqlite3_step(stmt_); @@ -289,10 +280,10 @@ int SQLStatement::bind_text(int index, const char* value, int value_len, return sqlite3_bind_text(stmt_, index + 1, value, value_len, dtor); } -int SQLStatement::bind_text16(int index, const wchar_t* value, int value_len, +int SQLStatement::bind_text16(int index, const char16* value, int value_len, Function dtor) { DCHECK(stmt_); - value_len *= sizeof(wchar_t); + value_len *= sizeof(char16); return sqlite3_bind_text16(stmt_, index + 1, value, value_len, dtor); } @@ -311,11 +302,6 @@ int SQLStatement::column_type(int index) { return sqlite3_column_type(stmt_, index); } -const wchar_t* SQLStatement::column_name16(int index) { - DCHECK(stmt_); - return static_cast<const wchar_t*>( sqlite3_column_name16(stmt_, index) ); -} - const void* SQLStatement::column_blob(int index) { DCHECK(stmt_); return sqlite3_column_blob(stmt_, index); @@ -386,7 +372,7 @@ bool SQLStatement::column_string(int index, std::string* str) { DCHECK(stmt_); DCHECK(str); const char* s = column_text(index); -str->assign(s ? s : std::string("")); + str->assign(s ? s : std::string()); return s != NULL; } @@ -396,22 +382,22 @@ std::string SQLStatement::column_string(int index) { return str; } -const wchar_t* SQLStatement::column_text16(int index) { +const char16* SQLStatement::column_text16(int index) { DCHECK(stmt_); - return static_cast<const wchar_t*>( sqlite3_column_text16(stmt_, index) ); + return static_cast<const char16*>(sqlite3_column_text16(stmt_, index)); } -bool SQLStatement::column_string16(int index, std::wstring* str) { +bool SQLStatement::column_wstring(int index, std::wstring* str) { DCHECK(stmt_); DCHECK(str); - const wchar_t* s = column_text16(index); - str->assign(s ? s : std::wstring(L"")); + const char* s = column_text(index); + str->assign(s ? UTF8ToWide(s) : std::wstring()); return (s != NULL); } -std::wstring SQLStatement::column_string16(int index) { +std::wstring SQLStatement::column_wstring(int index) { std::wstring wstr; - column_string16(index, &wstr); + column_wstring(index, &wstr); return wstr; } diff --git a/chrome/common/sqlite_utils.h b/chrome/common/sqlite_utils.h index f704141..457d96a 100644 --- a/chrome/common/sqlite_utils.h +++ b/chrome/common/sqlite_utils.h @@ -9,6 +9,8 @@ #include <vector> #include "base/basictypes.h" +#include "base/string16.h" +#include "base/string_util.h" #include "third_party/sqlite/preprocessed/sqlite3.h" @@ -210,13 +212,6 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr { int prepare(sqlite3* db, const char* sql, int sql_len); - int prepare16(sqlite3* db, const wchar_t* sql) { - return prepare16(db, sql, -1); - } - - // sql_len is number of characters or may be negative - // a for null-terminated sql string - int prepare16(sqlite3* db, const wchar_t* sql, int sql_len); int step(); int reset(); sqlite_int64 last_insert_rowid(); @@ -249,8 +244,9 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr { int bind_wstring(int index, const std::wstring& value) { // don't use c_str so it doesn't have to fix up the null terminator // (sqlite just uses the length) - return bind_text16(index, value.data(), - static_cast<int>(value.length()), SQLITE_TRANSIENT); + std::string value_utf8(WideToUTF8(value)); + return bind_text(index, value_utf8.data(), + static_cast<int>(value_utf8.length()), SQLITE_TRANSIENT); } int bind_text(int index, const char* value) { @@ -268,19 +264,19 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr { int bind_text(int index, const char* value, int value_len, Function dtor); - int bind_text16(int index, const wchar_t* value) { + int bind_text16(int index, const char16* value) { return bind_text16(index, value, -1, SQLITE_TRANSIENT); } // value_len is number of characters or may be negative // a for null-terminated value string - int bind_text16(int index, const wchar_t* value, int value_len) { + int bind_text16(int index, const char16* value, int value_len) { return bind_text16(index, value, value_len, SQLITE_TRANSIENT); } // value_len is number of characters or may be negative // a for null-terminated value string - int bind_text16(int index, const wchar_t* value, int value_len, + int bind_text16(int index, const char16* value, int value_len, Function dtor); int bind_value(int index, const sqlite3_value* value); @@ -291,7 +287,6 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr { int column_count(); int column_type(int index); - const wchar_t* column_name16(int index); const void* column_blob(int index); bool column_blob_as_vector(int index, std::vector<unsigned char>* blob); bool column_blob_as_string(int index, std::string* blob); @@ -304,9 +299,9 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr { const char* column_text(int index); bool column_string(int index, std::string* str); std::string column_string(int index); - const wchar_t* column_text16(int index); - bool column_string16(int index, std::wstring* str); - std::wstring column_string16(int index); + const char16* column_text16(int index); + bool column_wstring(int index, std::wstring* str); + std::wstring column_wstring(int index); private: DISALLOW_COPY_AND_ASSIGN(SQLStatement); |