Bug 461344 - abort if the version of sqlite we are using is not new enough
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Fri, 31 Oct 2008 20:38:58 -0400
changeset 21163 78b60e831d3c69108a8daa8d1145059e9830fd3e
parent 21162 5587400a222e81838c6684d1a10f3ed9c21dad6c
child 21165 3bd9b32db89406145ca12bafe7dae968068123b9
push idunknown
push userunknown
push dateunknown
bugs461344
milestone1.9.1b2pre
Bug 461344 - abort if the version of sqlite we are using is not new enough This adds a runtime check to ensure that the version of SQLite that is running is the same as the one that we were compiled with. If the check fails, we will display a prompt to the user, and abort. r=bsmedberg
storage/src/mozStorageService.cpp
--- a/storage/src/mozStorageService.cpp
+++ b/storage/src/mozStorageService.cpp
@@ -41,32 +41,52 @@
 
 #include "mozStorageService.h"
 #include "mozStorageConnection.h"
 #include "nsCRT.h"
 #include "plstr.h"
 #include "prinit.h"
 #include "nsAutoLock.h"
 #include "nsAutoPtr.h"
+#include "nsEmbedCID.h"
 #include "mozStoragePrivateHelpers.h"
 
 #include "sqlite3.h"
 
+#include "nsIPromptService.h"
+
 NS_IMPL_THREADSAFE_ISUPPORTS1(mozStorageService, mozIStorageService)
 
 mozStorageService *mozStorageService::gStorageService = nsnull;
 
 mozStorageService *
 mozStorageService::GetSingleton()
 {
     if (gStorageService) {
         NS_ADDREF(gStorageService);
         return gStorageService;
     }
 
+    // Ensure that we are using the same version of SQLite that we compiled with
+    // or newer.  Our configure check ensures we are using a new enough version
+    // at compile time.
+    if (SQLITE_VERSION_NUMBER > sqlite3_libversion_number()) {
+        nsCOMPtr<nsIPromptService> ps =
+            do_GetService(NS_PROMPTSERVICE_CONTRACTID);
+        if (ps) {
+            nsAutoString title, message;
+            title.AppendASCII("SQLite Version Error");
+            message.AppendASCII("The application has been updated, but your "
+                                "version of SQLite is too old and the "
+                                "application cannot run.");
+            (void)ps->Alert(nsnull, title.get(), message.get());
+        }
+        PR_Abort();
+    }
+
     gStorageService = new mozStorageService();
     if (gStorageService) {
         NS_ADDREF(gStorageService);
         if (NS_FAILED(gStorageService->Init()))
             NS_RELEASE(gStorageService);
     }
 
     return gStorageService;