| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/history/download_database.h" | 5 #include "chrome/browser/history/download_database.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "app/sql/statement.h" | 10 #include "app/sql/statement.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 139 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 140 "UPDATE downloads SET state=? WHERE state=?")); | 140 "UPDATE downloads SET state=? WHERE state=?")); |
| 141 if (!statement) | 141 if (!statement) |
| 142 return false; | 142 return false; |
| 143 statement.BindInt(0, DownloadItem::CANCELLED); | 143 statement.BindInt(0, DownloadItem::CANCELLED); |
| 144 statement.BindInt(1, DownloadItem::IN_PROGRESS); | 144 statement.BindInt(1, DownloadItem::IN_PROGRESS); |
| 145 return statement.Run(); | 145 return statement.Run(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 int64 DownloadDatabase::CreateDownload(const DownloadCreateInfo& info) { | 148 int64 DownloadDatabase::CreateDownload(const DownloadCreateInfo& info) { |
| 149 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 149 // If the database contains the 'last_modified' field, then set it to blank. |
| 150 "INSERT INTO downloads " | 150 bool has_last_mod = GetDB().DoesColumnExist("downloads", "last_modified"); |
| 151 "(full_path, url, start_time, received_bytes, total_bytes, state) " | 151 sql::Statement statement; |
| 152 "VALUES (?, ?, ?, ?, ?, ?)")); | 152 if (has_last_mod) { |
| 153 statement.Assign(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 154 "INSERT INTO downloads " |
| 155 "(full_path, url, start_time, received_bytes, total_bytes, state, " |
| 156 "last_modified) " |
| 157 "VALUES (?, ?, ?, ?, ?, ?, ?)")); |
| 158 } else { |
| 159 statement.Assign(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 160 "INSERT INTO downloads " |
| 161 "(full_path, url, start_time, received_bytes, total_bytes, state) " |
| 162 "VALUES (?, ?, ?, ?, ?, ?)")); |
| 163 } |
| 153 if (!statement) | 164 if (!statement) |
| 154 return 0; | 165 return 0; |
| 155 | 166 |
| 156 BindFilePath(statement, info.path, 0); | 167 BindFilePath(statement, info.path, 0); |
| 157 statement.BindString(1, info.url.spec()); | 168 statement.BindString(1, info.url.spec()); |
| 158 statement.BindInt64(2, info.start_time.ToTimeT()); | 169 statement.BindInt64(2, info.start_time.ToTimeT()); |
| 159 statement.BindInt64(3, info.received_bytes); | 170 statement.BindInt64(3, info.received_bytes); |
| 160 statement.BindInt64(4, info.total_bytes); | 171 statement.BindInt64(4, info.total_bytes); |
| 161 statement.BindInt(5, info.state); | 172 statement.BindInt(5, info.state); |
| 173 if (has_last_mod) |
| 174 statement.BindString(6, ""); |
| 162 | 175 |
| 163 if (statement.Run()) | 176 if (statement.Run()) |
| 164 return GetDB().GetLastInsertRowId(); | 177 return GetDB().GetLastInsertRowId(); |
| 165 return 0; | 178 return 0; |
| 166 } | 179 } |
| 167 | 180 |
| 168 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { | 181 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { |
| 169 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 182 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 170 "DELETE FROM downloads WHERE id=?")); | 183 "DELETE FROM downloads WHERE id=?")); |
| 171 if (!statement) | 184 if (!statement) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 190 statement.BindInt64(0, start_time); | 203 statement.BindInt64(0, start_time); |
| 191 statement.BindInt64( | 204 statement.BindInt64( |
| 192 1, | 205 1, |
| 193 end_time ? end_time : std::numeric_limits<int64>::max()); | 206 end_time ? end_time : std::numeric_limits<int64>::max()); |
| 194 statement.BindInt(2, DownloadItem::COMPLETE); | 207 statement.BindInt(2, DownloadItem::COMPLETE); |
| 195 statement.BindInt(3, DownloadItem::CANCELLED); | 208 statement.BindInt(3, DownloadItem::CANCELLED); |
| 196 statement.Run(); | 209 statement.Run(); |
| 197 } | 210 } |
| 198 | 211 |
| 199 } // namespace history | 212 } // namespace history |
| OLD | NEW |