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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 193 } |
194 | 194 |
195 sql::Connection null_db; | 195 sql::Connection null_db; |
196 if (!null_db.OpenInMemory()) { | 196 if (!null_db.OpenInMemory()) { |
197 DLOG(FATAL) << "Unable to open in-memory database."; | 197 DLOG(FATAL) << "Unable to open in-memory database."; |
198 return false; | 198 return false; |
199 } | 199 } |
200 | 200 |
201 // Get the page size from the current connection, then propagate it | 201 // Get the page size from the current connection, then propagate it |
202 // to the null database. | 202 // to the null database. |
203 Statement s(GetUniqueStatement("PRAGMA page_size")); | 203 { |
204 if (!s.Step()) | 204 Statement s(GetUniqueStatement("PRAGMA page_size")); |
205 return false; | 205 if (!s.Step()) |
206 const std::string sql = StringPrintf("PRAGMA page_size=%d", s.ColumnInt(0)); | 206 return false; |
207 if (!null_db.Execute(sql.c_str())) | 207 const std::string sql = StringPrintf("PRAGMA page_size=%d", |
208 return false; | 208 s.ColumnInt(0)); |
| 209 if (!null_db.Execute(sql.c_str())) |
| 210 return false; |
| 211 } |
| 212 |
| 213 // Get the value of auto_vacuum from the current connection, then propagate it |
| 214 // to the null database. |
| 215 { |
| 216 Statement s(GetUniqueStatement("PRAGMA auto_vacuum")); |
| 217 if (!s.Step()) |
| 218 return false; |
| 219 const std::string sql = StringPrintf("PRAGMA auto_vacuum=%d", |
| 220 s.ColumnInt(0)); |
| 221 if (!null_db.Execute(sql.c_str())) |
| 222 return false; |
| 223 } |
209 | 224 |
210 // The page size doesn't take effect until a database has pages, and | 225 // The page size doesn't take effect until a database has pages, and |
211 // at this point the null database has none. Changing the schema | 226 // at this point the null database has none. Changing the schema |
212 // version will create the first page. This will not affect the | 227 // version will create the first page. This will not affect the |
213 // schema version in the resulting database, as SQLite's backup | 228 // schema version in the resulting database, as SQLite's backup |
214 // implementation propagates the schema version from the original | 229 // implementation propagates the schema version from the original |
215 // connection to the new version of the database, incremented by one | 230 // connection to the new version of the database, incremented by one |
216 // so that other readers see the schema change and act accordingly. | 231 // so that other readers see the schema change and act accordingly. |
217 if (!null_db.Execute("PRAGMA schema_version = 1")) | 232 if (!null_db.Execute("PRAGMA schema_version = 1")) |
218 return false; | 233 return false; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 605 |
591 int Connection::OnSqliteError(int err, sql::Statement *stmt) { | 606 int Connection::OnSqliteError(int err, sql::Statement *stmt) { |
592 if (error_delegate_.get()) | 607 if (error_delegate_.get()) |
593 return error_delegate_->OnError(err, this, stmt); | 608 return error_delegate_->OnError(err, this, stmt); |
594 // The default handling is to assert on debug and to ignore on release. | 609 // The default handling is to assert on debug and to ignore on release. |
595 DLOG(FATAL) << GetErrorMessage(); | 610 DLOG(FATAL) << GetErrorMessage(); |
596 return err; | 611 return err; |
597 } | 612 } |
598 | 613 |
599 } // namespace sql | 614 } // namespace sql |
OLD | NEW |