diff --git a/mozilla/storage/src/mozStorageConnection.cpp b/mozilla/storage/src/mozStorageConnection.cpp index 1a7266aabd0..e07fd50bf9c 100644 --- a/mozilla/storage/src/mozStorageConnection.cpp +++ b/mozilla/storage/src/mozStorageConnection.cpp @@ -48,6 +48,8 @@ #include "nsAutoPtr.h" #include "nsIFile.h" #include "nsIVariant.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "mozIStorageAggregateFunction.h" #include "mozIStorageFunction.h" @@ -66,6 +68,8 @@ PRLogModuleInfo* gStorageLog = nsnull; #endif +#define PREF_TS_SYNCHRONOUS "toolkit.storage.synchronous" + NS_IMPL_ISUPPORTS1(mozStorageConnection, mozIStorageConnection) mozStorageConnection::mozStorageConnection(mozIStorageService* aService) @@ -157,6 +161,28 @@ mozStorageConnection::Initialize(nsIFile *aDatabaseFile) return ConvertResultCode(srv); } + // Set the synchronous PRAGMA, according to the pref + nsCOMPtr pref(do_GetService(NS_PREFSERVICE_CONTRACTID)); + PRInt32 synchronous = 1; // Default to NORMAL if pref not set + if (pref) + (void)pref->GetIntPref(PREF_TS_SYNCHRONOUS, &synchronous); + + switch (synchronous) { + case 2: + (void)ExecuteSimpleSQL(NS_LITERAL_CSTRING( + "PRAGMA synchronous = FULL;")); + break; + case 0: + (void)ExecuteSimpleSQL(NS_LITERAL_CSTRING( + "PRAGMA synchronous = OFF;")); + break; + case 1: + default: + (void)ExecuteSimpleSQL(NS_LITERAL_CSTRING( + "PRAGMA synchronous = NORMAL;")); + break; + } + return NS_OK; } diff --git a/mozilla/storage/test/unit/test_storage_connection.js b/mozilla/storage/test/unit/test_storage_connection.js index c3a73f42688..a715b77b514 100644 --- a/mozilla/storage/test/unit/test_storage_connection.js +++ b/mozilla/storage/test/unit/test_storage_connection.js @@ -197,6 +197,20 @@ function test_createTable(){ } } +function test_defaultSynchronousAtNormal() +{ + var msc = getOpenedDatabase(); + var stmt = createStatement("PRAGMA synchronous;"); + try { + stmt.executeStep(); + do_check_eq(1, stmt.getInt32(0)); + } + finally { + stmt.reset(); + stmt.finalize(); + } +} + var tests = [ test_connectionReady_open, test_connectionReady_closed, @@ -216,6 +230,7 @@ var tests = [ test_set_schemaVersion_same, test_set_schemaVersion_negative, test_createTable, + test_defaultSynchronousAtNormal, ]; function run_test()