| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 sql::Connection null_db; | 174 sql::Connection null_db; |
| 175 if (!null_db.OpenInMemory()) { | 175 if (!null_db.OpenInMemory()) { |
| 176 DLOG(FATAL) << "Unable to open in-memory database."; | 176 DLOG(FATAL) << "Unable to open in-memory database."; |
| 177 return false; | 177 return false; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Get the page size from the current connection, then propagate it | 180 // Get the page size from the current connection, then propagate it |
| 181 // to the null database. | 181 // to the null database. |
| 182 Statement s(GetUniqueStatement("PRAGMA page_size")); | 182 { |
| 183 if (!s.Step()) | 183 Statement s(GetUniqueStatement("PRAGMA page_size")); |
| 184 return false; | 184 if (!s.Step()) |
| 185 const std::string sql = StringPrintf("PRAGMA page_size=%d", s.ColumnInt(0)); | 185 return false; |
| 186 if (!null_db.Execute(sql.c_str())) | 186 const std::string sql = StringPrintf("PRAGMA page_size=%d", |
| 187 return false; | 187 s.ColumnInt(0)); |
| 188 if (!null_db.Execute(sql.c_str())) |
| 189 return false; |
| 190 } |
| 191 |
| 192 // Get the value of auto_vacuum from the current connection, then propagate it |
| 193 // to the null database. |
| 194 { |
| 195 Statement s(GetUniqueStatement("PRAGMA auto_vacuum")); |
| 196 if (!s.Step()) |
| 197 return false; |
| 198 const std::string sql = StringPrintf("PRAGMA auto_vacuum=%d", |
| 199 s.ColumnInt(0)); |
| 200 if (!null_db.Execute(sql.c_str())) |
| 201 return false; |
| 202 } |
| 188 | 203 |
| 189 // The page size doesn't take effect until a database has pages, and | 204 // The page size doesn't take effect until a database has pages, and |
| 190 // at this point the null database has none. Changing the schema | 205 // at this point the null database has none. Changing the schema |
| 191 // version will create the first page. This will not affect the | 206 // version will create the first page. This will not affect the |
| 192 // schema version in the resulting database, as SQLite's backup | 207 // schema version in the resulting database, as SQLite's backup |
| 193 // implementation propagates the schema version from the original | 208 // implementation propagates the schema version from the original |
| 194 // connection to the new version of the database, incremented by one | 209 // connection to the new version of the database, incremented by one |
| 195 // so that other readers see the schema change and act accordingly. | 210 // so that other readers see the schema change and act accordingly. |
| 196 if (!null_db.Execute("PRAGMA schema_version = 1")) | 211 if (!null_db.Execute("PRAGMA schema_version = 1")) |
| 197 return false; | 212 return false; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 578 |
| 564 int Connection::OnSqliteError(int err, sql::Statement *stmt) { | 579 int Connection::OnSqliteError(int err, sql::Statement *stmt) { |
| 565 if (error_delegate_.get()) | 580 if (error_delegate_.get()) |
| 566 return error_delegate_->OnError(err, this, stmt); | 581 return error_delegate_->OnError(err, this, stmt); |
| 567 // The default handling is to assert on debug and to ignore on release. | 582 // The default handling is to assert on debug and to ignore on release. |
| 568 DLOG(FATAL) << GetErrorMessage(); | 583 DLOG(FATAL) << GetErrorMessage(); |
| 569 return err; | 584 return err; |
| 570 } | 585 } |
| 571 | 586 |
| 572 } // namespace sql | 587 } // namespace sql |
| OLD | NEW |