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

Side by Side Diff: chrome/browser/webdata/web_database_win.cc

Issue 201099: Convert the sqlite cookie database and web database to use the new sqlite... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months 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
« no previous file with comments | « chrome/browser/webdata/web_database_unittest.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/webdata/web_database.h" 5 #include "chrome/browser/webdata/web_database.h"
6 6
7 #include "app/sql/statement.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h"
8 #include "base/time.h" 10 #include "base/time.h"
9 #include "chrome/browser/password_manager/ie7_password.h" 11 #include "chrome/browser/password_manager/ie7_password.h"
10 #include "chrome/common/sqlite_utils.h"
11 12
12 bool WebDatabase::AddIE7Login(const IE7PasswordInfo& info) { 13 bool WebDatabase::AddIE7Login(const IE7PasswordInfo& info) {
13 SQLStatement s; 14 sql::Statement s(db_.GetUniqueStatement(
14 if (s.prepare(db_, 15 "INSERT OR REPLACE INTO ie7_logins "
15 "INSERT OR REPLACE INTO ie7_logins " 16 "(url_hash, password_value, date_created) "
16 "(url_hash, password_value, date_created) " 17 "VALUES (?,?,?)"));
17 "VALUES (?, ?, ?)") != SQLITE_OK) { 18 if (!s) {
18 NOTREACHED() << "Statement prepare failed"; 19 NOTREACHED() << db_.GetErrorMessage();
19 return false; 20 return false;
20 } 21 }
21 22
22 s.bind_wstring(0, info.url_hash); 23 s.BindString(0, WideToUTF8(info.url_hash));
23 s.bind_blob(1, &info.encrypted_data.front(), 24 s.BindBlob(1, &info.encrypted_data.front(),
24 static_cast<int>(info.encrypted_data.size())); 25 static_cast<int>(info.encrypted_data.size()));
25 s.bind_int64(2, info.date_created.ToTimeT()); 26 s.BindInt64(2, info.date_created.ToTimeT());
26 if (s.step() != SQLITE_DONE) { 27 if (!s.Run()) {
27 NOTREACHED(); 28 NOTREACHED();
28 return false; 29 return false;
29 } 30 }
30 return true; 31 return true;
31 } 32 }
32 33
33 bool WebDatabase::RemoveIE7Login(const IE7PasswordInfo& info) { 34 bool WebDatabase::RemoveIE7Login(const IE7PasswordInfo& info) {
34 SQLStatement s;
35 // Remove a login by UNIQUE-constrained fields. 35 // Remove a login by UNIQUE-constrained fields.
36 if (s.prepare(db_, 36 sql::Statement s(db_.GetUniqueStatement(
37 "DELETE FROM ie7_logins WHERE " 37 "DELETE FROM ie7_logins WHERE url_hash = ?"));
38 "url_hash = ?") != SQLITE_OK) { 38 if (!s) {
39 NOTREACHED() << "Statement prepare failed"; 39 NOTREACHED() << db_.GetErrorMessage();
40 return false; 40 return false;
41 } 41 }
42 s.bind_wstring(0, info.url_hash); 42 s.BindString(0, WideToUTF8(info.url_hash));
43 43
44 if (s.step() != SQLITE_DONE) { 44 if (!s.Run()) {
45 NOTREACHED(); 45 NOTREACHED();
46 return false; 46 return false;
47 } 47 }
48 return true; 48 return true;
49 } 49 }
50 50
51 bool WebDatabase::GetIE7Login(const IE7PasswordInfo& info, 51 bool WebDatabase::GetIE7Login(const IE7PasswordInfo& info,
52 IE7PasswordInfo* result) { 52 IE7PasswordInfo* result) {
53 DCHECK(result); 53 DCHECK(result);
54 SQLStatement s; 54 sql::Statement s(db_.GetUniqueStatement(
55 if (s.prepare(db_, 55 "SELECT password_value, date_created FROM ie7_logins "
56 "SELECT password_value, date_created FROM ie7_logins " 56 "WHERE url_hash == ? "));
57 "WHERE url_hash == ? ") != SQLITE_OK) { 57 if (!s) {
58 NOTREACHED() << "Statement prepare failed"; 58 NOTREACHED() << db_.GetErrorMessage();
59 return false; 59 return false;
60 } 60 }
61 61
62 s.bind_wstring(0, info.url_hash); 62 s.BindString(0, WideToUTF8(info.url_hash));
63 63 if (s.Step()) {
64 int64 query_result = s.step(); 64 s.ColumnBlobAsVector(0, &result->encrypted_data);
65 if (query_result == SQLITE_ROW) { 65 result->date_created = base::Time::FromTimeT(s.ColumnInt64(1));
66 s.column_blob_as_vector(0, &result->encrypted_data);
67 result->date_created = base::Time::FromTimeT(s.column_int64(1));
68 result->url_hash = info.url_hash; 66 result->url_hash = info.url_hash;
69 s.step();
70 } 67 }
71 return query_result == SQLITE_DONE; 68 return s.Succeeded();
72 } 69 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database_unittest.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698