[sql] Remove mmap before Raze().

On Windows, file truncation silently fails when the file is memory
mapped.  Modify Raze() to disable memory mapping before truncating.

BUG=none
[email protected]

Review-Url: https://codereview.chromium.org/2830263002
Cr-Commit-Position: refs/heads/master@{#466555}
diff --git a/sql/connection.cc b/sql/connection.cc
index 0511e11..c80758f 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -1112,6 +1112,15 @@
   // page_size" can be used to query such a database.
   ScopedWritableSchema writable_schema(db_);
 
+#if defined(OS_WIN)
+  // On Windows, truncate silently fails when applied to memory-mapped files.
+  // Disable memory-mapping so that the truncate succeeds.  Note that other
+  // connections may have memory-mapped the file, so this may not entirely
+  // prevent the problem.
+  // [Source: <https://sqlite.org/mmap.html> plus experiments.]
+  ignore_result(Execute("PRAGMA mmap_size = 0"));
+#endif
+
   const char* kMain = "main";
   int rc = BackupDatabase(null_db.db_, db_, kMain);
   UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.RazeDatabase",rc);