OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "sql/test/test_helpers.h" | 5 #include "sql/test/test_helpers.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (1u != fread(header, sizeof(header), 1, file.get())) | 85 if (1u != fread(header, sizeof(header), 1, file.get())) |
86 return false; | 86 return false; |
87 | 87 |
88 int64 db_size = 0; | 88 int64 db_size = 0; |
89 if (!base::GetFileSize(db_path, &db_size)) | 89 if (!base::GetFileSize(db_path, &db_size)) |
90 return false; | 90 return false; |
91 | 91 |
92 const unsigned page_size = ReadBigEndian(header + kPageSizeOffset, 2); | 92 const unsigned page_size = ReadBigEndian(header + kPageSizeOffset, 2); |
93 | 93 |
94 // One larger than the expected size. | 94 // One larger than the expected size. |
95 const unsigned page_count = (db_size + page_size) / page_size; | 95 const unsigned page_count = |
| 96 static_cast<unsigned>((db_size + page_size) / page_size); |
96 WriteBigEndian(page_count, header + kPageCountOffset, 4); | 97 WriteBigEndian(page_count, header + kPageCountOffset, 4); |
97 | 98 |
98 // Update change count so outstanding readers know the info changed. | 99 // Update change count so outstanding readers know the info changed. |
99 // Both spots must match for the page count to be considered valid. | 100 // Both spots must match for the page count to be considered valid. |
100 unsigned change_count = ReadBigEndian(header + kFileChangeCountOffset, 4); | 101 unsigned change_count = ReadBigEndian(header + kFileChangeCountOffset, 4); |
101 WriteBigEndian(change_count + 1, header + kFileChangeCountOffset, 4); | 102 WriteBigEndian(change_count + 1, header + kFileChangeCountOffset, 4); |
102 WriteBigEndian(change_count + 1, header + kVersionValidForOffset, 4); | 103 WriteBigEndian(change_count + 1, header + kVersionValidForOffset, 4); |
103 | 104 |
104 if (0 != fseek(file.get(), 0, SEEK_SET)) | 105 if (0 != fseek(file.get(), 0, SEEK_SET)) |
105 return false; | 106 return false; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 bool CountTableRows(sql::Connection* db, const char* table, size_t* count) { | 206 bool CountTableRows(sql::Connection* db, const char* table, size_t* count) { |
206 // TODO(shess): Table should probably be quoted with [] or "". See | 207 // TODO(shess): Table should probably be quoted with [] or "". See |
207 // http://www.sqlite.org/lang_keywords.html . Meanwhile, odd names | 208 // http://www.sqlite.org/lang_keywords.html . Meanwhile, odd names |
208 // will throw an error. | 209 // will throw an error. |
209 std::string sql = "SELECT COUNT(*) FROM "; | 210 std::string sql = "SELECT COUNT(*) FROM "; |
210 sql += table; | 211 sql += table; |
211 sql::Statement s(db->GetUniqueStatement(sql.c_str())); | 212 sql::Statement s(db->GetUniqueStatement(sql.c_str())); |
212 if (!s.Step()) | 213 if (!s.Step()) |
213 return false; | 214 return false; |
214 | 215 |
215 *count = s.ColumnInt64(0); | 216 *count = static_cast<size_t>(s.ColumnInt64(0)); |
216 return true; | 217 return true; |
217 } | 218 } |
218 | 219 |
219 bool CreateDatabaseFromSQL(const base::FilePath& db_path, | 220 bool CreateDatabaseFromSQL(const base::FilePath& db_path, |
220 const base::FilePath& sql_path) { | 221 const base::FilePath& sql_path) { |
221 if (base::PathExists(db_path) || !base::PathExists(sql_path)) | 222 if (base::PathExists(db_path) || !base::PathExists(sql_path)) |
222 return false; | 223 return false; |
223 | 224 |
224 std::string sql; | 225 std::string sql; |
225 if (!base::ReadFileToString(sql_path, &sql)) | 226 if (!base::ReadFileToString(sql_path, &sql)) |
(...skipping 16 matching lines...) Expand all Loading... |
242 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); | 243 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); |
243 | 244 |
244 // SQLite should always return a row of data. | 245 // SQLite should always return a row of data. |
245 EXPECT_TRUE(statement.Step()); | 246 EXPECT_TRUE(statement.Step()); |
246 | 247 |
247 return statement.ColumnString(0); | 248 return statement.ColumnString(0); |
248 } | 249 } |
249 | 250 |
250 } // namespace test | 251 } // namespace test |
251 } // namespace sql | 252 } // namespace sql |
OLD | NEW |