OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/connection.h" | 5 #include "sql/connection.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 // page, and if it does not match the total retrieved from a | 1105 // page, and if it does not match the total retrieved from a |
1106 // filesystem call, treats the database as corrupt. This situation | 1106 // filesystem call, treats the database as corrupt. This situation |
1107 // breaks almost all SQLite calls. "PRAGMA writable_schema" can be | 1107 // breaks almost all SQLite calls. "PRAGMA writable_schema" can be |
1108 // used to hint to SQLite to soldier on in that case, specifically | 1108 // used to hint to SQLite to soldier on in that case, specifically |
1109 // for purposes of recovery. [See SQLITE_CORRUPT_BKPT case in | 1109 // for purposes of recovery. [See SQLITE_CORRUPT_BKPT case in |
1110 // sqlite3.c lockBtree().] | 1110 // sqlite3.c lockBtree().] |
1111 // TODO(shess): With this, "PRAGMA auto_vacuum" and "PRAGMA | 1111 // TODO(shess): With this, "PRAGMA auto_vacuum" and "PRAGMA |
1112 // page_size" can be used to query such a database. | 1112 // page_size" can be used to query such a database. |
1113 ScopedWritableSchema writable_schema(db_); | 1113 ScopedWritableSchema writable_schema(db_); |
1114 | 1114 |
| 1115 #if defined(OS_WIN) |
| 1116 // On Windows, truncate silently fails when applied to memory-mapped files. |
| 1117 // Disable memory-mapping so that the truncate succeeds. Note that other |
| 1118 // connections may have memory-mapped the file, so this may not entirely |
| 1119 // prevent the problem. |
| 1120 // [Source: <https://sqlite.org/mmap.html> plus experiments.] |
| 1121 ignore_result(Execute("PRAGMA mmap_size = 0")); |
| 1122 #endif |
| 1123 |
1115 const char* kMain = "main"; | 1124 const char* kMain = "main"; |
1116 int rc = BackupDatabase(null_db.db_, db_, kMain); | 1125 int rc = BackupDatabase(null_db.db_, db_, kMain); |
1117 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.RazeDatabase",rc); | 1126 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.RazeDatabase",rc); |
1118 | 1127 |
1119 // The destination database was locked. | 1128 // The destination database was locked. |
1120 if (rc == SQLITE_BUSY) { | 1129 if (rc == SQLITE_BUSY) { |
1121 return false; | 1130 return false; |
1122 } | 1131 } |
1123 | 1132 |
1124 // SQLITE_NOTADB can happen if page 1 of db_ exists, but is not | 1133 // SQLITE_NOTADB can happen if page 1 of db_ exists, but is not |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 const std::string& dump_name) { | 2064 const std::string& dump_name) { |
2056 return memory_dump_provider_ && | 2065 return memory_dump_provider_ && |
2057 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); | 2066 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); |
2058 } | 2067 } |
2059 | 2068 |
2060 base::TimeTicks TimeSource::Now() { | 2069 base::TimeTicks TimeSource::Now() { |
2061 return base::TimeTicks::Now(); | 2070 return base::TimeTicks::Now(); |
2062 } | 2071 } |
2063 | 2072 |
2064 } // namespace sql | 2073 } // namespace sql |
OLD | NEW |