OLD | NEW |
1 // Copyright (c) 2009 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 "webkit/database/databases_table.h" | 5 #include "webkit/database/databases_table.h" |
6 | 6 |
7 #include "app/sql/connection.h" | 7 #include "app/sql/connection.h" |
8 #include "app/sql/statement.h" | 8 #include "app/sql/statement.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 SQL_FROM_HERE, "DELETE FROM Databases WHERE origin = ? AND name = ?")); | 105 SQL_FROM_HERE, "DELETE FROM Databases WHERE origin = ? AND name = ?")); |
106 if (delete_statement.is_valid() && | 106 if (delete_statement.is_valid() && |
107 delete_statement.BindString(0, UTF16ToUTF8(origin_identifier)) && | 107 delete_statement.BindString(0, UTF16ToUTF8(origin_identifier)) && |
108 delete_statement.BindString(1, UTF16ToUTF8(database_name))) { | 108 delete_statement.BindString(1, UTF16ToUTF8(database_name))) { |
109 return (delete_statement.Run() && db_->GetLastChangeCount()); | 109 return (delete_statement.Run() && db_->GetLastChangeCount()); |
110 } | 110 } |
111 | 111 |
112 return false; | 112 return false; |
113 } | 113 } |
114 | 114 |
| 115 bool DatabasesTable::GetAllOrigins(std::vector<string16>* origins) { |
| 116 sql::Statement statement(db_->GetCachedStatement( |
| 117 SQL_FROM_HERE, "SELECT DISTINCT origin FROM Databases ORDER BY origin")); |
| 118 if (statement.is_valid()) { |
| 119 while (statement.Step()) |
| 120 origins->push_back(UTF8ToUTF16(statement.ColumnString(0))); |
| 121 return statement.Succeeded(); |
| 122 } |
| 123 |
| 124 return false; |
| 125 } |
| 126 |
115 bool DatabasesTable::GetAllDatabaseDetailsForOrigin( | 127 bool DatabasesTable::GetAllDatabaseDetailsForOrigin( |
116 const string16& origin_identifier, | 128 const string16& origin_identifier, |
117 std::vector<DatabaseDetails>* details_vector) { | 129 std::vector<DatabaseDetails>* details_vector) { |
118 sql::Statement statement(db_->GetCachedStatement( | 130 sql::Statement statement(db_->GetCachedStatement( |
119 SQL_FROM_HERE, "SELECT name, description, estimated_size " | 131 SQL_FROM_HERE, "SELECT name, description, estimated_size " |
120 "FROM Databases WHERE origin = ? ORDER BY origin, name")); | 132 "FROM Databases WHERE origin = ? ORDER BY name")); |
121 if (statement.is_valid() && | 133 if (statement.is_valid() && |
122 statement.BindString(0, UTF16ToUTF8(origin_identifier))) { | 134 statement.BindString(0, UTF16ToUTF8(origin_identifier))) { |
123 while (statement.Step()) { | 135 while (statement.Step()) { |
124 DatabaseDetails details; | 136 DatabaseDetails details; |
125 details.origin_identifier = origin_identifier; | 137 details.origin_identifier = origin_identifier; |
126 details.database_name = UTF8ToUTF16(statement.ColumnString(0)); | 138 details.database_name = UTF8ToUTF16(statement.ColumnString(0)); |
127 details.description = UTF8ToUTF16(statement.ColumnString(1)); | 139 details.description = UTF8ToUTF16(statement.ColumnString(1)); |
128 details.estimated_size = statement.ColumnInt64(2); | 140 details.estimated_size = statement.ColumnInt64(2); |
129 details_vector->push_back(details); | 141 details_vector->push_back(details); |
130 } | 142 } |
131 return statement.Succeeded(); | 143 return statement.Succeeded(); |
132 } | 144 } |
133 | 145 |
134 return false; | 146 return false; |
135 } | 147 } |
136 | 148 |
| 149 bool DatabasesTable::DeleteOrigin(const string16& origin_identifier) { |
| 150 sql::Statement delete_statement(db_->GetCachedStatement( |
| 151 SQL_FROM_HERE, "DELETE FROM Databases WHERE origin = ?")); |
| 152 if (delete_statement.is_valid() && |
| 153 delete_statement.BindString(0, UTF16ToUTF8(origin_identifier))) { |
| 154 return (delete_statement.Run() && db_->GetLastChangeCount()); |
| 155 } |
| 156 |
| 157 return false; |
| 158 } |
| 159 |
137 } // namespace webkit_database | 160 } // namespace webkit_database |
OLD | NEW |