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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 sql::Statement s(db->GetUniqueStatement(kPageSql)); | 70 sql::Statement s(db->GetUniqueStatement(kPageSql)); |
71 s.BindString(0, name); | 71 s.BindString(0, name); |
72 EXPECT_TRUE(s.Step()); | 72 EXPECT_TRUE(s.Step()); |
73 return s.ColumnInt(0); | 73 return s.ColumnInt(0); |
74 } | 74 } |
75 | 75 |
76 // Helper to read a SQLite page into a buffer. |page_no| is 1-based | 76 // Helper to read a SQLite page into a buffer. |page_no| is 1-based |
77 // per SQLite usage. | 77 // per SQLite usage. |
78 bool ReadPage(const base::FilePath& path, size_t page_no, | 78 bool ReadPage(const base::FilePath& path, size_t page_no, |
79 char* buf, size_t page_size) { | 79 char* buf, size_t page_size) { |
80 file_util::ScopedFILE file(file_util::OpenFile(path, "rb")); | 80 file_util::ScopedFILE file(base::OpenFile(path, "rb")); |
81 if (!file.get()) | 81 if (!file.get()) |
82 return false; | 82 return false; |
83 if (0 != fseek(file.get(), (page_no - 1) * page_size, SEEK_SET)) | 83 if (0 != fseek(file.get(), (page_no - 1) * page_size, SEEK_SET)) |
84 return false; | 84 return false; |
85 if (1u != fread(buf, page_size, 1, file.get())) | 85 if (1u != fread(buf, page_size, 1, file.get())) |
86 return false; | 86 return false; |
87 return true; | 87 return true; |
88 } | 88 } |
89 | 89 |
90 // Helper to write a SQLite page into a buffer. |page_no| is 1-based | 90 // Helper to write a SQLite page into a buffer. |page_no| is 1-based |
91 // per SQLite usage. | 91 // per SQLite usage. |
92 bool WritePage(const base::FilePath& path, size_t page_no, | 92 bool WritePage(const base::FilePath& path, size_t page_no, |
93 const char* buf, size_t page_size) { | 93 const char* buf, size_t page_size) { |
94 file_util::ScopedFILE file(file_util::OpenFile(path, "rb+")); | 94 file_util::ScopedFILE file(base::OpenFile(path, "rb+")); |
95 if (!file.get()) | 95 if (!file.get()) |
96 return false; | 96 return false; |
97 if (0 != fseek(file.get(), (page_no - 1) * page_size, SEEK_SET)) | 97 if (0 != fseek(file.get(), (page_no - 1) * page_size, SEEK_SET)) |
98 return false; | 98 return false; |
99 if (1u != fwrite(buf, page_size, 1, file.get())) | 99 if (1u != fwrite(buf, page_size, 1, file.get())) |
100 return false; | 100 return false; |
101 return true; | 101 return true; |
102 } | 102 } |
103 #endif // !defined(USE_SYSTEM_SQLITE) | 103 #endif // !defined(USE_SYSTEM_SQLITE) |
104 | 104 |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 748 |
749 // Since the database was not corrupt, the entire schema and all | 749 // Since the database was not corrupt, the entire schema and all |
750 // data should be recovered. | 750 // data should be recovered. |
751 ASSERT_TRUE(Reopen()); | 751 ASSERT_TRUE(Reopen()); |
752 ASSERT_EQ(orig_schema, GetSchema(&db())); | 752 ASSERT_EQ(orig_schema, GetSchema(&db())); |
753 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n")); | 753 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n")); |
754 } | 754 } |
755 #endif // !defined(USE_SYSTEM_SQLITE) | 755 #endif // !defined(USE_SYSTEM_SQLITE) |
756 | 756 |
757 } // namespace | 757 } // namespace |
OLD | NEW |