| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 DLOG(FATAL) << "Unable to open in-memory database."; | 233 DLOG(FATAL) << "Unable to open in-memory database."; |
| 234 return false; | 234 return false; |
| 235 } | 235 } |
| 236 | 236 |
| 237 if (page_size_) { | 237 if (page_size_) { |
| 238 // Enforce SQLite restrictions on |page_size_|. | 238 // Enforce SQLite restrictions on |page_size_|. |
| 239 DCHECK(!(page_size_ & (page_size_ - 1))) | 239 DCHECK(!(page_size_ & (page_size_ - 1))) |
| 240 << " page_size_ " << page_size_ << " is not a power of two."; | 240 << " page_size_ " << page_size_ << " is not a power of two."; |
| 241 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h | 241 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h |
| 242 DCHECK_LE(page_size_, kSqliteMaxPageSize); | 242 DCHECK_LE(page_size_, kSqliteMaxPageSize); |
| 243 const std::string sql = StringPrintf("PRAGMA page_size=%d", page_size_); | 243 const std::string sql = |
| 244 base::StringPrintf("PRAGMA page_size=%d", page_size_); |
| 244 if (!null_db.Execute(sql.c_str())) | 245 if (!null_db.Execute(sql.c_str())) |
| 245 return false; | 246 return false; |
| 246 } | 247 } |
| 247 | 248 |
| 248 #if defined(OS_ANDROID) | 249 #if defined(OS_ANDROID) |
| 249 // Android compiles with SQLITE_DEFAULT_AUTOVACUUM. Unfortunately, | 250 // Android compiles with SQLITE_DEFAULT_AUTOVACUUM. Unfortunately, |
| 250 // in-memory databases do not respect this define. | 251 // in-memory databases do not respect this define. |
| 251 // TODO(shess): Figure out a way to set this without using platform | 252 // TODO(shess): Figure out a way to set this without using platform |
| 252 // specific code. AFAICT from sqlite3.c, the only way to do it | 253 // specific code. AFAICT from sqlite3.c, the only way to do it |
| 253 // would be to create an actual filesystem database, which is | 254 // would be to create an actual filesystem database, which is |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 | 660 |
| 660 const base::TimeDelta kBusyTimeout = | 661 const base::TimeDelta kBusyTimeout = |
| 661 base::TimeDelta::FromSeconds(kBusyTimeoutSeconds); | 662 base::TimeDelta::FromSeconds(kBusyTimeoutSeconds); |
| 662 | 663 |
| 663 if (page_size_ != 0) { | 664 if (page_size_ != 0) { |
| 664 // Enforce SQLite restrictions on |page_size_|. | 665 // Enforce SQLite restrictions on |page_size_|. |
| 665 DCHECK(!(page_size_ & (page_size_ - 1))) | 666 DCHECK(!(page_size_ & (page_size_ - 1))) |
| 666 << " page_size_ " << page_size_ << " is not a power of two."; | 667 << " page_size_ " << page_size_ << " is not a power of two."; |
| 667 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h | 668 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h |
| 668 DCHECK_LE(page_size_, kSqliteMaxPageSize); | 669 DCHECK_LE(page_size_, kSqliteMaxPageSize); |
| 669 const std::string sql = StringPrintf("PRAGMA page_size=%d", page_size_); | 670 const std::string sql = |
| 671 base::StringPrintf("PRAGMA page_size=%d", page_size_); |
| 670 if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout)) | 672 if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout)) |
| 671 DLOG(FATAL) << "Could not set page size: " << GetErrorMessage(); | 673 DLOG(FATAL) << "Could not set page size: " << GetErrorMessage(); |
| 672 } | 674 } |
| 673 | 675 |
| 674 if (cache_size_ != 0) { | 676 if (cache_size_ != 0) { |
| 675 const std::string sql = StringPrintf("PRAGMA cache_size=%d", cache_size_); | 677 const std::string sql = |
| 678 base::StringPrintf("PRAGMA cache_size=%d", cache_size_); |
| 676 if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout)) | 679 if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout)) |
| 677 DLOG(FATAL) << "Could not set cache size: " << GetErrorMessage(); | 680 DLOG(FATAL) << "Could not set cache size: " << GetErrorMessage(); |
| 678 } | 681 } |
| 679 | 682 |
| 680 if (!ExecuteWithTimeout("PRAGMA secure_delete=ON", kBusyTimeout)) { | 683 if (!ExecuteWithTimeout("PRAGMA secure_delete=ON", kBusyTimeout)) { |
| 681 DLOG(FATAL) << "Could not enable secure_delete: " << GetErrorMessage(); | 684 DLOG(FATAL) << "Could not enable secure_delete: " << GetErrorMessage(); |
| 682 Close(); | 685 Close(); |
| 683 return false; | 686 return false; |
| 684 } | 687 } |
| 685 | 688 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 736 |
| 734 if (error_delegate_.get()) | 737 if (error_delegate_.get()) |
| 735 return error_delegate_->OnError(err, this, stmt); | 738 return error_delegate_->OnError(err, this, stmt); |
| 736 | 739 |
| 737 // The default handling is to assert on debug and to ignore on release. | 740 // The default handling is to assert on debug and to ignore on release. |
| 738 DLOG(FATAL) << GetErrorMessage(); | 741 DLOG(FATAL) << GetErrorMessage(); |
| 739 return err; | 742 return err; |
| 740 } | 743 } |
| 741 | 744 |
| 742 } // namespace sql | 745 } // namespace sql |
| OLD | NEW |