зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1678030 - Move CreateAndExecuteSingleStepStatement to QuotaCommon and use in all quota clients. r=dom-workers-and-storage-reviewers,janv
Differential Revision: https://phabricator.services.mozilla.com/D97460
This commit is contained in:
Родитель
ef2934709b
Коммит
e6b749fc81
|
@ -411,21 +411,13 @@ class MOZ_RAII AutoDisableForeignKeyChecking {
|
|||
public:
|
||||
explicit AutoDisableForeignKeyChecking(mozIStorageConnection* aConn)
|
||||
: mConn(aConn), mForeignKeyCheckingDisabled(false) {
|
||||
nsCOMPtr<mozIStorageStatement> state;
|
||||
nsresult rv = mConn->CreateStatement("PRAGMA foreign_keys;"_ns,
|
||||
getter_AddRefs(state));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool hasMoreData = false;
|
||||
rv = state->ExecuteStep(&hasMoreData);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
CACHE_TRY_INSPECT(const auto& state,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
*mConn, "PRAGMA foreign_keys;"_ns),
|
||||
QM_VOID);
|
||||
|
||||
int32_t mode;
|
||||
rv = state->GetInt32(0, &mode);
|
||||
nsresult rv = state->GetInt32(0, &mode);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
@ -624,27 +616,21 @@ nsresult InitializeConnection(mozIStorageConnection& aConn) {
|
|||
// is very easy to put the database in a state where the auto_vacuum
|
||||
// pragma above fails silently.
|
||||
#ifdef DEBUG
|
||||
nsCOMPtr<mozIStorageStatement> state;
|
||||
rv = aConn.CreateStatement("PRAGMA auto_vacuum;"_ns, getter_AddRefs(state));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
{
|
||||
CACHE_TRY_INSPECT(const auto& state,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
aConn, "PRAGMA auto_vacuum;"_ns));
|
||||
|
||||
bool hasMoreData = false;
|
||||
rv = state->ExecuteStep(&hasMoreData);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
int32_t mode;
|
||||
rv = state->GetInt32(0, &mode);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
int32_t mode;
|
||||
rv = state->GetInt32(0, &mode);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// integer value 2 is incremental mode
|
||||
if (NS_WARN_IF(mode != 2)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
// integer value 2 is incremental mode
|
||||
if (NS_WARN_IF(mode != 2)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1709,25 +1695,19 @@ Result<int32_t, nsresult> InsertSecurityInfo(mozIStorageConnection& aConn,
|
|||
return Err(rv);
|
||||
}
|
||||
|
||||
rv = aConn.CreateStatement("SELECT last_insert_rowid()"_ns,
|
||||
getter_AddRefs(state));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
{
|
||||
CACHE_TRY_INSPECT(const auto& state,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
aConn, "SELECT last_insert_rowid()"_ns));
|
||||
|
||||
hasMoreData = false;
|
||||
rv = state->ExecuteStep(&hasMoreData);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
int32_t id;
|
||||
rv = state->GetInt32(0, &id);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
int32_t id;
|
||||
rv = state->GetInt32(0, &id);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
return id;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId,
|
||||
|
@ -2080,23 +2060,14 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
|
|||
return rv;
|
||||
}
|
||||
|
||||
rv = aConn.CreateStatement("SELECT last_insert_rowid()"_ns,
|
||||
getter_AddRefs(state));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
CACHE_TRY_INSPECT(
|
||||
const int32_t& entryId, ([&aConn]() -> Result<int32_t, nsresult> {
|
||||
CACHE_TRY_INSPECT(const auto& state,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
aConn, "SELECT last_insert_rowid()"_ns));
|
||||
|
||||
bool hasMoreData = false;
|
||||
rv = state->ExecuteStep(&hasMoreData);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
int32_t entryId;
|
||||
rv = state->GetInt32(0, &entryId);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
CACHE_TRY_RETURN(MOZ_TO_RESULT_INVOKE(state, GetInt32, 0));
|
||||
}()));
|
||||
|
||||
rv = aConn.CreateStatement(
|
||||
nsLiteralCString("INSERT INTO request_headers ("
|
||||
|
@ -2680,21 +2651,12 @@ Result<nsAutoCString, nsresult> HashCString(nsICryptoHash& aCrypto,
|
|||
|
||||
nsresult IncrementalVacuum(mozIStorageConnection& aConn) {
|
||||
// Determine how much free space is in the database.
|
||||
nsCOMPtr<mozIStorageStatement> state;
|
||||
nsresult rv =
|
||||
aConn.CreateStatement("PRAGMA freelist_count;"_ns, getter_AddRefs(state));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool hasMoreData = false;
|
||||
rv = state->ExecuteStep(&hasMoreData);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
CACHE_TRY_INSPECT(const auto& state,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
aConn, "PRAGMA freelist_count;"_ns));
|
||||
|
||||
int32_t freePages = 0;
|
||||
rv = state->GetInt32(0, &freePages);
|
||||
nsresult rv = state->GetInt32(0, &freePages);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -2727,25 +2689,19 @@ nsresult IncrementalVacuum(mozIStorageConnection& aConn) {
|
|||
|
||||
// Verify that our incremental vacuum actually did something
|
||||
#ifdef DEBUG
|
||||
rv =
|
||||
aConn.CreateStatement("PRAGMA freelist_count;"_ns, getter_AddRefs(state));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
{
|
||||
CACHE_TRY_INSPECT(const auto& state,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
aConn, "PRAGMA freelist_count;"_ns));
|
||||
|
||||
hasMoreData = false;
|
||||
rv = state->ExecuteStep(&hasMoreData);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
freePages = 0;
|
||||
rv = state->GetInt32(0, &freePages);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
freePages = 0;
|
||||
rv = state->GetInt32(0, &freePages);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
MOZ_ASSERT(freePages <= kMaxFreePages);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(freePages <= kMaxFreePages);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -685,20 +685,6 @@ nsresult SetDefaultPragmas(mozIStorageConnection& aConnection) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
Result<nsCOMPtr<mozIStorageStatement>, nsresult>
|
||||
CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
|
||||
const nsACString& aStatementString) {
|
||||
IDB_TRY_UNWRAP(auto stmt, MOZ_TO_RESULT_INVOKE_TYPED(
|
||||
nsCOMPtr<mozIStorageStatement>, aConnection,
|
||||
CreateStatement, aStatementString));
|
||||
|
||||
IDB_TRY_UNWRAP(const DebugOnly<bool> hasResult,
|
||||
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
|
||||
MOZ_ASSERT(hasResult);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
template <typename StepFunc>
|
||||
Result<Ok, nsresult> CollectWhileHasResult(mozIStorageStatement& aStmt,
|
||||
StepFunc&& aStepFunc) {
|
||||
|
|
|
@ -2127,12 +2127,10 @@ nsresult UpgradeSchemaFrom17_0To18_0Helper::DoUpgradeInternal(
|
|||
#ifdef DEBUG
|
||||
{
|
||||
// Make sure there's only one entry in the |database| table.
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
MOZ_ASSERT(NS_SUCCEEDED(aConnection.CreateStatement(
|
||||
"SELECT COUNT(*) FROM database;"_ns, getter_AddRefs(stmt))));
|
||||
|
||||
bool hasResult;
|
||||
MOZ_ASSERT(NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)));
|
||||
IDB_TRY_INSPECT(const auto& stmt,
|
||||
quota::CreateAndExecuteSingleStepStatement(
|
||||
aConnection, "SELECT COUNT(*) FROM database;"_ns),
|
||||
QM_ASSERT_UNREACHABLE);
|
||||
|
||||
int64_t count;
|
||||
MOZ_ASSERT(NS_SUCCEEDED(stmt->GetInt64(0, &count)));
|
||||
|
|
|
@ -856,23 +856,12 @@ nsresult SetShadowJournalMode(mozIStorageConnection* aConnection) {
|
|||
constexpr auto journalModeQueryStart = "PRAGMA journal_mode = "_ns;
|
||||
constexpr auto journalModeWAL = "wal"_ns;
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv = aConnection->CreateStatement(
|
||||
journalModeQueryStart + journalModeWAL, getter_AddRefs(stmt));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool hasResult;
|
||||
rv = stmt->ExecuteStep(&hasResult);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(hasResult);
|
||||
LS_TRY_INSPECT(const auto& stmt,
|
||||
CreateAndExecuteSingleStepStatement(
|
||||
*aConnection, journalModeQueryStart + journalModeWAL));
|
||||
|
||||
nsCString journalMode;
|
||||
rv = stmt->GetUTF8String(0, journalMode);
|
||||
nsresult rv = stmt->GetUTF8String(0, journalMode);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -882,19 +871,8 @@ nsresult SetShadowJournalMode(mozIStorageConnection* aConnection) {
|
|||
|
||||
// Set the threshold for auto-checkpointing the WAL. We don't want giant
|
||||
// logs slowing down us.
|
||||
rv = aConnection->CreateStatement("PRAGMA page_size;"_ns,
|
||||
getter_AddRefs(stmt));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool hasResult;
|
||||
rv = stmt->ExecuteStep(&hasResult);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(hasResult);
|
||||
LS_TRY_INSPECT(const auto& stmt, CreateAndExecuteSingleStepStatement(
|
||||
*aConnection, "PRAGMA page_size;"_ns));
|
||||
|
||||
int32_t pageSize;
|
||||
rv = stmt->GetInt32(0, &pageSize);
|
||||
|
|
|
@ -6029,20 +6029,9 @@ nsresult QuotaManager::CreateLocalStorageArchiveConnectionFromWebAppsStore(
|
|||
|
||||
if (connection) {
|
||||
// Find out the journal mode.
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
rv = connection->CreateStatement("PRAGMA journal_mode;"_ns,
|
||||
getter_AddRefs(stmt));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool hasResult;
|
||||
rv = stmt->ExecuteStep(&hasResult);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(hasResult);
|
||||
QM_TRY_INSPECT(const auto& stmt,
|
||||
CreateAndExecuteSingleStepStatement(
|
||||
*connection, "PRAGMA journal_mode;"_ns));
|
||||
|
||||
nsCString journalMode;
|
||||
rv = stmt->GetUTF8String(0, journalMode);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "QuotaCommon.h"
|
||||
|
||||
#include "mozIStorageConnection.h"
|
||||
#include "mozIStorageStatement.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
#include "nsIConsoleService.h"
|
||||
|
@ -155,6 +157,20 @@ Result<nsCOMPtr<nsIFile>, nsresult> CloneFileAndAppend(
|
|||
return resultFile;
|
||||
}
|
||||
|
||||
Result<nsCOMPtr<mozIStorageStatement>, nsresult>
|
||||
CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
|
||||
const nsACString& aStatementString) {
|
||||
QM_TRY_UNWRAP(auto stmt, MOZ_TO_RESULT_INVOKE_TYPED(
|
||||
nsCOMPtr<mozIStorageStatement>, aConnection,
|
||||
CreateStatement, aStatementString));
|
||||
|
||||
QM_TRY_UNWRAP(const DebugOnly<bool> hasResult,
|
||||
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
|
||||
MOZ_ASSERT(hasResult);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
#ifdef QM_ENABLE_SCOPED_LOG_EXTRA_INFO
|
||||
MOZ_THREAD_LOCAL(const nsACString*) ScopedLogExtraInfo::sQueryValue;
|
||||
|
||||
|
|
|
@ -738,6 +738,8 @@
|
|||
# define RETURN_STATUS_OR_RESULT(_status, _rv) return _rv
|
||||
#endif
|
||||
|
||||
class mozIStorageConnection;
|
||||
class mozIStorageStatement;
|
||||
class nsIFile;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -977,6 +979,13 @@ nsDependentCSubstring GetLeafName(const nsACString& aPath);
|
|||
Result<nsCOMPtr<nsIFile>, nsresult> CloneFileAndAppend(
|
||||
nsIFile& aDirectory, const nsAString& aPathElement);
|
||||
|
||||
// Creates a statement with the specified aStatementString, executes a single
|
||||
// step, and asserts that it has a result, and returns the statement. Any other
|
||||
// errors are propagated.
|
||||
Result<nsCOMPtr<mozIStorageStatement>, nsresult>
|
||||
CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
|
||||
const nsACString& aStatementString);
|
||||
|
||||
void LogError(const nsLiteralCString& aModule, const nsACString& aExpr,
|
||||
const nsACString& aSourceFile, int32_t aSourceLine);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче