merge backout
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 16 Jan 2010 06:47:34 -0800
changeset 37256 c4e11789ff88fe5a3fd940bd1634721b915c8cb3
parent 37254 73ded1179009f588efa01d6dafabb85cb2264fc9 (current diff)
parent 37255 e67409d2d2612468dbcd0d89f9d643f280cbe16a (diff)
child 37258 24813cf3a03a3ea0e7ef98a9935ebc267314985a
push idunknown
push userunknown
push dateunknown
milestone1.9.3a1pre
merge backout
toolkit/components/places/src/nsNavBookmarks.cpp
--- a/toolkit/components/places/src/Helpers.h
+++ b/toolkit/components/places/src/Helpers.h
@@ -61,38 +61,12 @@ public:
 /**
  * Macro to use in place of NS_DECL_MOZISTORAGESTATEMENTCALLBACK to declare the
  * methods this class does not implement.
  */
 #define NS_DECL_ASYNCSTATEMENTCALLBACK \
   NS_IMETHOD HandleResult(mozIStorageResultSet *); \
   NS_IMETHOD HandleCompletion(PRUint16);
 
-/**
- * Macros to use for lazy statements initialization in Places services that use
- * GetStatement() method.
- */
-#define RETURN_IF_STMT(_stmt, _sql)                                            \
-  PR_BEGIN_MACRO                                                               \
-  if (address_of(_stmt) == address_of(aStmt)) {                                \
-    if (!_stmt) {                                                              \
-      nsresult rv = mDBConn->CreateStatement(_sql, getter_AddRefs(_stmt));     \
-      NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && _stmt, nsnull);                       \
-    }                                                                          \
-    return _stmt.get();                                                        \
-  }                                                                            \
-  PR_END_MACRO
-
-// Async statements don't need to be scoped, they are reset when done.
-// So use this version for statements used async, scoped version for statements
-// used sync.
-#define DECLARE_AND_ASSIGN_LAZY_STMT(_localStmt, _globalStmt)                  \
-  mozIStorageStatement* _localStmt = GetStatement(_globalStmt);                \
-  NS_ENSURE_STATE(_localStmt)
-
-#define DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(_localStmt, _globalStmt)           \
-  DECLARE_AND_ASSIGN_LAZY_STMT(_localStmt, _globalStmt);                       \
-  mozStorageStatementScoper scoper(_localStmt)
-
 } // namespace places
 } // namespace mozilla
 
 #endif // mozilla_places_Helpers_h_
--- a/toolkit/components/places/src/nsAnnotationService.cpp
+++ b/toolkit/components/places/src/nsAnnotationService.cpp
@@ -45,17 +45,16 @@
 #include "nsNetUtil.h"
 #include "nsIVariant.h"
 #include "nsString.h"
 #include "nsVariant.h"
 
 #include "nsPlacesTables.h"
 #include "nsPlacesIndexes.h"
 #include "nsPlacesMacros.h"
-#include "Helpers.h"
 
 #include "mozilla/storage.h"
 
 #define ENSURE_ANNO_TYPE(_type, _statement)                                    \
   PR_BEGIN_MACRO                                                               \
   PRInt32 type = _statement->AsInt32(kAnnoIndex_Type);                         \
   NS_ENSURE_TRUE(type == nsIAnnotationService::_type, NS_ERROR_INVALID_ARG);   \
   PR_END_MACRO
@@ -116,16 +115,27 @@ nsAnnotationService::Init()
 
   return NS_OK;
 }
 
 
 mozIStorageStatement*
 nsAnnotationService::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
 {
+#define RETURN_IF_STMT(_stmt, _sql)                                        \
+  PR_BEGIN_MACRO                                                           \
+  if (address_of(_stmt) == address_of(aStmt)) {                            \
+    if (!_stmt) {                                                          \
+      nsresult rv = mDBConn->CreateStatement(_sql, getter_AddRefs(_stmt)); \
+      NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && _stmt, nsnull);                   \
+    }                                                                      \
+    return _stmt.get();                                                    \
+  }                                                                        \
+  PR_END_MACRO
+
   if (mShuttingDown)
     return nsnull;
 
   RETURN_IF_STMT(mDBGetAnnotationsForItem, NS_LITERAL_CSTRING(
     "SELECT n.name "
     "FROM moz_anno_attributes n "
     "JOIN moz_items_annos a ON a.anno_attribute_id = n.id "
     "WHERE a.item_id = ?1"));
@@ -220,16 +230,17 @@ nsAnnotationService::GetStatement(const 
            "(SELECT id FROM moz_anno_attributes WHERE name = ?1) AS nameid, "
            "a.id, a.dateAdded "
     "FROM moz_bookmarks b "
     "LEFT JOIN moz_items_annos a ON a.item_id = b.id "
                                "AND a.anno_attribute_id = nameid "
     "WHERE b.id = ?2"));
 
    return nsnull;
+#undef RETURN_IF_STMT
 }
 
 
 // nsAnnotationService::InitTables
 //
 //    All commands that initialize the schema of the DB go in here. This is
 //    called from history init before the dummy DB connection is started that
 //    will prevent us from modifying the schema.
@@ -1275,17 +1286,20 @@ nsAnnotationService::GetPagesWithAnnotat
   return NS_OK;
 }
 
 
 nsresult
 nsAnnotationService::GetPagesWithAnnotationCOMArray(const nsACString& aName,
                                                     nsCOMArray<nsIURI>* _results)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetPagesWithAnnotation);
+  mozIStorageStatement* stmt = GetStatement(mDBGetPagesWithAnnotation);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = stmt->BindUTF8StringParameter(0, aName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasMore = PR_FALSE;
   while (NS_SUCCEEDED(rv = stmt->ExecuteStep(&hasMore)) &&
          hasMore) {
     nsCAutoString uristring;
     rv = stmt->GetUTF8String(0, uristring);
@@ -1338,17 +1352,19 @@ nsAnnotationService::GetItemsWithAnnotat
   return NS_OK;
 }
 
 
 nsresult
 nsAnnotationService::GetItemsWithAnnotationTArray(const nsACString& aName,
                                                   nsTArray<PRInt64>* _results)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemsWithAnnotation);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemsWithAnnotation);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindUTF8StringParameter(0, aName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasMore = PR_FALSE;
   while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) &&
          hasMore) {
     if (!_results->AppendElement(stmt->AsInt64(0)))
       return NS_ERROR_OUT_OF_MEMORY;
@@ -1953,17 +1969,19 @@ nsAnnotationService::StartSetAnnotation(
                                         PRInt32 aFlags,
                                         PRUint16 aExpiration,
                                         PRUint16 aType,
                                         mozIStorageStatement** _statement)
 {
   bool isItemAnnotation = (aItemId > 0);
 
   // Ensure the annotation name exists.
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(addNameStmt, mDBAddAnnotationName);
+  mozIStorageStatement* addNameStmt = GetStatement(mDBAddAnnotationName);
+  NS_ENSURE_STATE(addNameStmt);
+  mozStorageStatementScoper addNameScoper(addNameStmt);
   nsresult rv = addNameStmt->BindUTF8StringParameter(0, aName);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = addNameStmt->Execute();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We have to check 2 things:
   // - if the annotation already exists we should update it.
   // - we should not allow setting annotations on invalid URIs or itemIds.
--- a/toolkit/components/places/src/nsFaviconService.cpp
+++ b/toolkit/components/places/src/nsFaviconService.cpp
@@ -368,16 +368,27 @@ nsFaviconService::Init()
 
   return NS_OK;
 }
 
 
 mozIStorageStatement*
 nsFaviconService::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
 {
+#define RETURN_IF_STMT(_stmt, _sql)                                        \
+  PR_BEGIN_MACRO                                                           \
+  if (address_of(_stmt) == address_of(aStmt)) {                            \
+    if (!_stmt) {                                                          \
+      nsresult rv = mDBConn->CreateStatement(_sql, getter_AddRefs(_stmt)); \
+      NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && _stmt, nsnull);                   \
+    }                                                                      \
+    return _stmt.get();                                                    \
+  }                                                                        \
+  PR_END_MACRO
+
   if (mShuttingDown)
     return nsnull;
 
   RETURN_IF_STMT(mDBGetIconInfo, NS_LITERAL_CSTRING(
     "SELECT id, length(data), expiration FROM moz_favicons WHERE url = ?1"));
 
   RETURN_IF_STMT(mDBGetURL, NS_LITERAL_CSTRING(
     "SELECT f.id, f.url, length(f.data), f.expiration "
@@ -418,16 +429,17 @@ nsFaviconService::GetStatement(const nsC
   RETURN_IF_STMT(mDBRemoveAllFavicons, NS_LITERAL_CSTRING(
     "DELETE FROM moz_favicons WHERE id NOT IN ("
       "SELECT favicon_id FROM moz_places_temp WHERE favicon_id NOT NULL "
       "UNION ALL "
       "SELECT favicon_id FROM moz_places WHERE favicon_id NOT NULL "
     ")"));
 
   return nsnull;
+#undef RETURN_IF_STMT
 }
 
 
 // nsFaviconService::InitTables
 //
 //    Called by the history service to create the favicon table. The history
 //    service uses this table in its queries, so it must exist even if
 //    nobody has called the favicon service.
@@ -537,17 +549,19 @@ nsFaviconService::SetFaviconUrlForPageIn
   nsNavHistory* historyService = nsNavHistory::GetHistoryService();
   NS_ENSURE_TRUE(historyService, NS_ERROR_OUT_OF_MEMORY);
 
   if (historyService->InPrivateBrowsingMode())
     return NS_OK;
 
   mozStorageTransaction transaction(mDBConn, PR_FALSE);
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetIconInfo);
+    mozIStorageStatement* stmt = GetStatement(mDBGetIconInfo);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = BindStatementURI(stmt, 0, aFaviconURI);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool hasResult = PR_FALSE;
     if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
       // We already have an entry for this icon, just get the stats
       rv = stmt->GetInt64(0, &iconId);
       NS_ENSURE_SUCCESS(rv, rv);
@@ -560,42 +574,49 @@ nsFaviconService::SetFaviconUrlForPageIn
         *aHasData = PR_TRUE;
     }
   }
 
   if (iconId == -1) {
     // We did not find any entry, so create a new one
 
     // not-binded params are automatically nullified by mozStorage
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBInsertIcon);
+    mozIStorageStatement* stmt = GetStatement(mDBInsertIcon);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = BindStatementURI(stmt, 0, aFaviconURI);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = stmt->Execute();
     NS_ENSURE_SUCCESS(rv, rv);
 
     {
-      DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetIconInfo);
+      mozIStorageStatement* getInfoStmt = GetStatement(mDBGetIconInfo);
+      NS_ENSURE_STATE(getInfoStmt);
+      mozStorageStatementScoper scoper(getInfoStmt);
+
       rv = BindStatementURI(getInfoStmt, 0, aFaviconURI);
       NS_ENSURE_SUCCESS(rv, rv);
 
       PRBool hasResult;
       rv = getInfoStmt->ExecuteStep(&hasResult);
       NS_ENSURE_SUCCESS(rv, rv);
       NS_ASSERTION(hasResult, "hasResult is false but the call succeeded?");
       iconId = getInfoStmt->AsInt64(0);
     }
   }
 
   // now link our icon entry with the page
   PRInt64 pageId;
   rv = historyService->GetUrlIdFor(aPageURI, &pageId, PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBSetPageFavicon);
+  mozIStorageStatement* stmt = GetStatement(mDBSetPageFavicon);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   rv = stmt->BindInt64Parameter(0, pageId);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt64Parameter(1, iconId);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->Execute();
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = transaction.Commit();
@@ -768,17 +789,19 @@ nsFaviconService::SetFaviconData(nsIURI*
       return NS_ERROR_FAILURE;
     }
   }
 
   mozIStorageStatement* statement;
   {
     // this block forces the scoper to reset our statement: necessary for the
     // next statement
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetIconInfo);
+    mozIStorageStatement* stmt = GetStatement(mDBGetIconInfo);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = BindStatementURI(stmt, 0, aFaviconURI);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool hasResult;
     rv = stmt->ExecuteStep(&hasResult);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (hasResult) {
@@ -878,17 +901,19 @@ nsFaviconService::SetFaviconDataFromData
 NS_IMETHODIMP
 nsFaviconService::GetFaviconData(nsIURI* aFaviconURI, nsACString& aMimeType,
                                  PRUint32* aDataLen, PRUint8** aData)
 {
   NS_ENSURE_ARG(aFaviconURI);
   NS_ENSURE_ARG_POINTER(aDataLen);
   NS_ENSURE_ARG_POINTER(aData);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetData);
+  mozIStorageStatement* stmt = GetStatement(mDBGetData);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = BindStatementURI(stmt, 0, aFaviconURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult = PR_FALSE;
   if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
     rv = stmt->GetUTF8String(1, aMimeType);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -934,17 +959,19 @@ nsFaviconService::GetFaviconDataAsDataUR
 
 
 NS_IMETHODIMP
 nsFaviconService::GetFaviconForPage(nsIURI* aPageURI, nsIURI** _retval)
 {
   NS_ENSURE_ARG(aPageURI);
   NS_ENSURE_ARG_POINTER(_retval);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetURL);
+  mozIStorageStatement* stmt = GetStatement(mDBGetURL);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = BindStatementURI(stmt, 0, aPageURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
     nsCAutoString url;
     rv = stmt->GetUTF8String(1, url);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -956,17 +983,19 @@ nsFaviconService::GetFaviconForPage(nsIU
 
 
 NS_IMETHODIMP
 nsFaviconService::GetFaviconImageForPage(nsIURI* aPageURI, nsIURI** _retval)
 {
   NS_ENSURE_ARG(aPageURI);
   NS_ENSURE_ARG_POINTER(_retval);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetURL);
+  mozIStorageStatement* stmt = GetStatement(mDBGetURL);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = BindStatementURI(stmt, 0, aPageURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   nsCOMPtr<nsIURI> faviconURI;
   if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
     PRInt32 dataLen;
     rv = stmt->GetInt32(2, &dataLen);
@@ -1187,17 +1216,18 @@ nsFaviconService::FinalizeStatements() {
 }
 
 
 nsresult
 nsFaviconService::GetFaviconDataAsync(nsIURI* aFaviconURI,
                                       mozIStorageStatementCallback *aCallback)
 {
   NS_ASSERTION(aCallback, "Doesn't make sense to call this without a callback");
-  DECLARE_AND_ASSIGN_LAZY_STMT(stmt, mDBGetData);
+  mozIStorageStatement* stmt = GetStatement(mDBGetData);
+  NS_ENSURE_STATE(stmt);
   nsresult rv = BindStatementURI(stmt, 0, aFaviconURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<mozIStoragePendingStatement> pendingStatement;
   return stmt->ExecuteAsync(aCallback, getter_AddRefs(pendingStatement));
 }
 
 
--- a/toolkit/components/places/src/nsNavBookmarks.cpp
+++ b/toolkit/components/places/src/nsNavBookmarks.cpp
@@ -52,17 +52,16 @@
 #include "nsPrintfCString.h"
 #include "nsIUUIDGenerator.h"
 #include "prprf.h"
 #include "nsILivemarkService.h"
 #include "nsPlacesTriggers.h"
 #include "nsPlacesTables.h"
 #include "nsPlacesIndexes.h"
 #include "nsPlacesMacros.h"
-#include "Helpers.h"
 
 const PRInt32 nsNavBookmarks::kFindBookmarksIndex_ID = 0;
 const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Type = 1;
 const PRInt32 nsNavBookmarks::kFindBookmarksIndex_PlaceID = 2;
 const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Parent = 3;
 const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Position = 4;
 const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Title = 5;
 
@@ -218,16 +217,27 @@ nsNavBookmarks::InitTables(mozIStorageCo
 
   return NS_OK;
 }
 
 
 mozIStorageStatement*
 nsNavBookmarks::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
 {
+#define RETURN_IF_STMT(_stmt, _sql)                                        \
+  PR_BEGIN_MACRO                                                           \
+  if (address_of(_stmt) == address_of(aStmt)) {                            \
+    if (!_stmt) {                                                          \
+      nsresult rv = mDBConn->CreateStatement(_sql, getter_AddRefs(_stmt)); \
+      NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && _stmt, nsnull);                   \
+    }                                                                      \
+    return _stmt.get();                                                    \
+  }                                                                        \
+  PR_END_MACRO
+
   if (mShuttingDown)
     return nsnull;
 
   // Double ordering covers possible lastModified ties, that could happen when
   // importing, syncing or due to extensions.
   RETURN_IF_STMT(mDBFindURIBookmarks, NS_LITERAL_CSTRING(
     "SELECT b.id "
     "FROM moz_bookmarks b "
@@ -429,16 +439,17 @@ nsNavBookmarks::GetStatement(const nsCOM
 
   RETURN_IF_STMT(mDBSetItemTitle, NS_LITERAL_CSTRING(
     "UPDATE moz_bookmarks SET title = ?1, lastModified = ?2 WHERE id = ?3 "));
 
   RETURN_IF_STMT(mDBChangeBookmarkURI, NS_LITERAL_CSTRING(
     "UPDATE moz_bookmarks SET fk = ?1, lastModified = ?2 WHERE id = ?3 "));
 
   return nsnull;
+#undef RETURN_IF_STMT
 }
 
 
 nsresult
 nsNavBookmarks::FinalizeStatements() {
   mShuttingDown = true;
 
   mozIStorageStatement* stmts[] = {
@@ -845,17 +856,19 @@ nsNavBookmarks::RecursiveAddBookmarkHash
 {
   nsresult rv;
   nsTArray<PRInt64> found;
 
   // scope for the DB statement. The statement must be reset by the time we
   // recursively call ourselves again, because our recursive call will use the
   // same statement.
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetRedirectDestinations);
+    mozIStorageStatement* stmt = GetStatement(mDBGetRedirectDestinations);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = stmt->BindInt64Parameter(0, aCurrentSource);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->BindInt64Parameter(1, aMinTime);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool hasMore;
     while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
       // add this newly found redirect destination to the hashtable
@@ -928,17 +941,20 @@ nsNavBookmarks::UpdateBookmarkHashOnRemo
 PRBool
 nsNavBookmarks::IsRealBookmark(PRInt64 aPlaceId)
 {
   // Fast path is to check the hash table first.  If it is in the hash table,
   // then verify that it is a real bookmark.
   PRInt64 bookmarkId;
   PRBool isBookmark = GetBookmarksHash()->Get(aPlaceId, &bookmarkId);
   if (isBookmark) {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsRealBookmark);
+    mozIStorageStatement* stmt = GetStatement(mDBIsRealBookmark);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
+
     nsresult rv = stmt->BindInt64Parameter(0, aPlaceId);
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
     rv = stmt->BindInt32Parameter(1, TYPE_BOOKMARK);
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
     rv = stmt->BindUTF8StringParameter(2, NS_LITERAL_CSTRING(LMANNO_FEEDURI));
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
 
     // If we get any rows, then there exists at least one bookmark corresponding
@@ -957,17 +973,19 @@ nsNavBookmarks::IsRealBookmark(PRInt64 a
 //
 //    This checks to see if the specified place_id is actually bookmarked.
 //    This does not check for redirects in the hashtable.
 
 nsresult
 nsNavBookmarks::IsBookmarkedInDatabase(PRInt64 aPlaceId,
                                        PRBool* aIsBookmarked)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsBookmarkedInDatabase);
+  mozIStorageStatement* stmt = GetStatement(mDBIsBookmarkedInDatabase);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aPlaceId);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt32Parameter(1, TYPE_BOOKMARK);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->ExecuteStep(aIsBookmarked);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
@@ -977,17 +995,20 @@ nsresult
 nsNavBookmarks::AdjustIndices(PRInt64 aFolderId,
                               PRInt32 aStartIndex,
                               PRInt32 aEndIndex,
                               PRInt32 aDelta)
 {
   NS_ASSERTION(aStartIndex >= 0 && aEndIndex <= PR_INT32_MAX &&
                aStartIndex <= aEndIndex, "Bad indices");
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBAdjustPosition);
+  mozIStorageStatement* stmt = GetStatement(mDBAdjustPosition);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = stmt->BindInt32Parameter(0, aDelta);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt64Parameter(1, aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt32Parameter(2, aStartIndex);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt32Parameter(3, aEndIndex);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1048,17 +1069,20 @@ nsNavBookmarks::InsertBookmarkInDB(PRInt
                                    const nsACString& aTitle,
                                    PRTime aDateAdded,
                                    PRTime aLastModified,
                                    const nsAString& aServiceContractId,
                                    PRInt64* _newItemId)
 {
   NS_ASSERTION(_newItemId, "Null pointer passed to InsertBookmarkInDB!");
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBInsertBookmark);
+  mozIStorageStatement* stmt = GetStatement(mDBInsertBookmark);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv;
   if (aItemId && aItemId != -1)
     rv = stmt->BindInt64Parameter(kInsertBookmarkIndex_Id, aItemId);
   else
     rv = stmt->BindNullParameter(kInsertBookmarkIndex_Id);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aPlaceId && aPlaceId != -1)
@@ -1096,17 +1120,19 @@ nsNavBookmarks::InsertBookmarkInDB(PRInt
     rv = stmt->BindInt64Parameter(kInsertBookmarkIndex_LastModified, aDateAdded);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = stmt->Execute();
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!aItemId || aItemId == -1) {
     // Get the new inserted item id.
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(lastInsertIdStmt, mDBGetLastBookmarkID);
+    mozIStorageStatement* lastInsertIdStmt = GetStatement(mDBGetLastBookmarkID);
+    NS_ENSURE_STATE(lastInsertIdStmt);
+    mozStorageStatementScoper scoper(lastInsertIdStmt);
     PRBool hasResult;
     rv = lastInsertIdStmt->ExecuteStep(&hasResult);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(hasResult, NS_ERROR_UNEXPECTED);
     rv = lastInsertIdStmt->GetInt64(0, _newItemId);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   else {
@@ -1249,17 +1275,20 @@ nsNavBookmarks::RemoveItem(PRInt64 aItem
   nsresult rv;
   PRInt32 childIndex;
   PRInt64 placeId, folderId;
   PRUint16 itemType;
   nsCAutoString buffer;
   nsCAutoString spec;
 
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
+    mozIStorageStatement* getInfoStmt = GetStatement(mDBGetItemProperties);
+    NS_ENSURE_STATE(getInfoStmt);
+    mozStorageStatementScoper scoper(getInfoStmt);
+
     rv = getInfoStmt->BindInt64Parameter(0, aItemId);
     NS_ENSURE_SUCCESS(rv, rv);
     PRBool hasResult;
     rv = getInfoStmt->ExecuteStep(&hasResult);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!hasResult)
       return NS_ERROR_INVALID_ARG; // invalid bookmark id
 
@@ -1291,17 +1320,19 @@ nsNavBookmarks::RemoveItem(PRInt64 aItem
 
   // First, remove item annotations
   nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
   NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
   rv = annosvc->RemoveItemAnnotations(aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBRemoveItem);
+    mozIStorageStatement* stmt = GetStatement(mDBRemoveItem);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = stmt->BindInt64Parameter(0, aItemId);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->Execute();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (childIndex != -1) {
     rv = AdjustIndices(folderId, childIndex + 1, PR_INT32_MAX, -1);
@@ -1529,17 +1560,19 @@ nsNavBookmarks::InsertSeparator(PRInt64 
 
 
 nsresult
 nsNavBookmarks::GetLastChildId(PRInt64 aFolderId, PRInt64* aItemId)
 {
   NS_ASSERTION(aFolderId > 0, "Invalid folder id");
   *aItemId = -1;
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetLastChildId);
+  mozIStorageStatement* stmt = GetStatement(mDBGetLastChildId);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
   PRBool found;
   rv = stmt->ExecuteStep(&found);
   NS_ENSURE_SUCCESS(rv, rv);
   if (found) {
     rv = stmt->GetInt64(0, aItemId);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -1562,17 +1595,20 @@ nsNavBookmarks::GetIdForItemAt(PRInt64 a
   nsresult rv;
   if (aIndex == nsINavBookmarksService::DEFAULT_INDEX) {
     // Get last item within aFolder.
     rv = GetLastChildId(aFolder, aItemId);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   else {
     // Get the item in aFolder with position aIndex.
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildAt);
+    mozIStorageStatement* stmt = GetStatement(mDBGetChildAt);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
+
     rv = stmt->BindInt64Parameter(0, aFolder);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->BindInt32Parameter(1, aIndex);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool found;
     rv = stmt->ExecuteStep(&found);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -1585,17 +1621,19 @@ nsNavBookmarks::GetIdForItemAt(PRInt64 a
 }
 
 
 nsresult 
 nsNavBookmarks::GetParentAndIndexOfFolder(PRInt64 aFolderId,
                                           PRInt64* _aParent,
                                           PRInt32* _aIndex)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG);
 
@@ -1618,17 +1656,19 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFo
 
   mozStorageTransaction transaction(mDBConn, PR_FALSE);
 
   nsresult rv;
   PRInt64 parent;
   PRInt32 index, type;
   nsCAutoString folderType;
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
+    mozIStorageStatement* getInfoStmt = GetStatement(mDBGetItemProperties);
+    NS_ENSURE_STATE(getInfoStmt);
+    mozStorageStatementScoper scoper(getInfoStmt);
     rv = getInfoStmt->BindInt64Parameter(0, aFolderId);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool hasResult;
     rv = getInfoStmt->ExecuteStep(&hasResult);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!hasResult) {
       return NS_ERROR_INVALID_ARG; // folder is not in the hierarchy
@@ -1666,17 +1706,19 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFo
   }
 
   // Remove all of the folder's children
   rv = RemoveFolderChildren(aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   {
     // Remove the folder from its parent.
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBRemoveItem);
+    mozIStorageStatement* stmt = GetStatement(mDBRemoveItem);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = stmt->BindInt64Parameter(0, aFolderId);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->Execute();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   rv = AdjustIndices(parent, index + 1, PR_INT32_MAX, -1);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1724,17 +1766,19 @@ nsresult
 nsNavBookmarks::GetDescendantChildren(PRInt64 aFolderId,
                                       PRInt64 aGrandParentId,
                                       nsTArray<folderChildrenInfo>& aFolderChildrenArray) {
   // New children will be added from this index on.
   PRUint32 startIndex = aFolderChildrenArray.Length();
   nsresult rv;
   {
     // Collect children informations.
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildren);
+    mozIStorageStatement* stmt = GetStatement(mDBGetChildren);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = stmt->BindInt64Parameter(0, aFolderId);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool hasMore;
     while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
       folderChildrenInfo child;
       rv = stmt->GetInt64(nsNavHistory::kGetInfoIndex_ItemId, &child.itemId);
       NS_ENSURE_SUCCESS(rv, rv);
@@ -1785,17 +1829,19 @@ NS_IMETHODIMP
 nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolderId)
 {
   NS_ENSURE_ARG_MIN(aFolderId, 1);
 
   nsresult rv;
   PRUint16 itemType;
   PRInt64 grandParentId;
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
+    mozIStorageStatement* getInfoStmt = GetStatement(mDBGetItemProperties);
+    NS_ENSURE_STATE(getInfoStmt);
+    mozStorageStatementScoper scoper(getInfoStmt);
     rv = getInfoStmt->BindInt64Parameter(0, aFolderId);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Sanity check: ensure that item exists.
     PRBool folderExists;
     if (NS_FAILED(getInfoStmt->ExecuteStep(&folderExists)) || !folderExists)
       return NS_ERROR_INVALID_ARG;
 
@@ -1954,17 +2000,19 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId
 
   // get item properties
   nsresult rv;
   PRInt64 oldParent;
   PRInt32 oldIndex;
   PRUint16 itemType;
   nsCAutoString folderType;
   {
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
+    mozIStorageStatement* getInfoStmt = GetStatement(mDBGetItemProperties);
+    NS_ENSURE_STATE(getInfoStmt);
+    mozStorageStatementScoper scoper(getInfoStmt);
     rv = getInfoStmt->BindInt64Parameter(0, aItemId);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool hasResult;
     rv = getInfoStmt->ExecuteStep(&hasResult);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!hasResult) {
       return NS_ERROR_INVALID_ARG; // folder is not in the hierarchy
@@ -1992,17 +2040,19 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId
   if (itemType == TYPE_FOLDER) {
     PRInt64 ancestorId = aNewParent;
 
     while (ancestorId) {
       if (ancestorId == aItemId) {
         return NS_ERROR_INVALID_ARG;
       }
 
-      DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
+      mozIStorageStatement* getInfoStmt = GetStatement(mDBGetItemProperties);
+      NS_ENSURE_STATE(getInfoStmt);
+      mozStorageStatementScoper scoper(getInfoStmt);
       rv = getInfoStmt->BindInt64Parameter(0, ancestorId);
       NS_ENSURE_SUCCESS(rv, rv);
 
       PRBool hasResult;
       rv = getInfoStmt->ExecuteStep(&hasResult);
       NS_ENSURE_SUCCESS(rv, rv);
       if (hasResult) {
         rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &ancestorId);
@@ -2068,17 +2118,19 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId
     NS_ENSURE_SUCCESS(rv, rv);
     // Now, make room in the new parent for the insertion.
     rv = AdjustIndices(aNewParent, newIndex, PR_INT32_MAX, 1);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   {
     // Update parent and position.
-    DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBMoveItem);
+    mozIStorageStatement* stmt = GetStatement(mDBMoveItem);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
     rv = stmt->BindInt64Parameter(0, aNewParent);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->BindInt32Parameter(1, newIndex);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->BindInt64Parameter(2, aItemId);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->Execute();
     NS_ENSURE_SUCCESS(rv, rv);
@@ -2115,17 +2167,16 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId
 
 nsresult
 nsNavBookmarks::SetItemDateInternal(mozIStorageStatement* aStatement,
                                     PRInt64 aItemId,
                                     PRTime aValue)
 {
   NS_ENSURE_STATE(aStatement);
   mozStorageStatementScoper scoper(aStatement);
-
   nsresult rv = aStatement->BindInt64Parameter(0, aValue);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStatement->BindInt64Parameter(1, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = aStatement->Execute();
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -2160,17 +2211,19 @@ nsNavBookmarks::SetItemDateAdded(PRInt64
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetItemDateAdded(PRInt64 aItemId, PRTime* _dateAdded)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
   NS_ENSURE_ARG_POINTER(_dateAdded);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG); // Invalid itemId.
 
@@ -2205,17 +2258,19 @@ nsNavBookmarks::SetItemLastModified(PRIn
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetItemLastModified(PRInt64 aItemId, PRTime* aLastModified)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
   NS_ENSURE_ARG_POINTER(aLastModified);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!hasResult)
@@ -2295,17 +2350,19 @@ nsNavBookmarks::SetItemGUID(PRInt64 aIte
 }
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetItemIdForGUID(const nsAString& aGUID, PRInt64* aItemId)
 {
   NS_ENSURE_ARG_POINTER(aItemId);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemIdForGUID);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemIdForGUID);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindStringParameter(0, aGUID);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasMore = PR_FALSE;
   rv = stmt->ExecuteStep(&hasMore);
   if (NS_FAILED(rv) || ! hasMore) {
     *aItemId = -1;
     return NS_OK; // not found: return -1
@@ -2321,17 +2378,20 @@ nsNavBookmarks::GetItemIdForGUID(const n
 NS_IMETHODIMP
 nsNavBookmarks::SetItemTitle(PRInt64 aItemId, const nsACString& aTitle)
 {
   // GetItemType also ensures that aItemId points to a valid item.
   PRUint16 itemType;
   nsresult rv = GetItemType(aItemId, &itemType);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(statement, mDBSetItemTitle);
+  mozIStorageStatement* statement = GetStatement(mDBSetItemTitle);
+  NS_ENSURE_STATE(statement);
+  mozStorageStatementScoper scoper(statement);
+
   // Support setting a null title, we support this in insertBookmark.
   if (aTitle.IsVoid())
     rv = statement->BindNullParameter(0);
   else
     rv = statement->BindUTF8StringParameter(0, aTitle);
   NS_ENSURE_SUCCESS(rv, rv);
   PRTime lastModified = PR_Now();
   rv = statement->BindInt64Parameter(1, lastModified);
@@ -2353,17 +2413,20 @@ nsNavBookmarks::SetItemTitle(PRInt64 aIt
 }
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetItemTitle(PRInt64 aItemId, nsACString& aTitle)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!hasResult)
@@ -2376,17 +2439,19 @@ nsNavBookmarks::GetItemTitle(PRInt64 aIt
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetBookmarkURI(PRInt64 aItemId, nsIURI** aURI)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
   NS_ENSURE_ARG_POINTER(aURI);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!hasResult)
@@ -2410,17 +2475,20 @@ nsNavBookmarks::GetBookmarkURI(PRInt64 a
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetItemType(PRInt64 aItemId, PRUint16* _type)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
   NS_ENSURE_ARG_POINTER(_type);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!hasResult) {
@@ -2432,17 +2500,19 @@ nsNavBookmarks::GetItemType(PRInt64 aIte
 
   return NS_OK;
 }
 
 
 nsresult
 nsNavBookmarks::GetFolderType(PRInt64 aFolder, nsACString& aType)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aFolder);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!hasResult) {
@@ -2453,17 +2523,19 @@ nsNavBookmarks::GetFolderType(PRInt64 aF
 }
 
 
 nsresult
 nsNavBookmarks::ResultNodeForContainer(PRInt64 aID,
                                        nsNavHistoryQueryOptions* aOptions,
                                        nsNavHistoryResultNode** aNode)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aID);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG);
 
@@ -2507,17 +2579,20 @@ nsNavBookmarks::ResultNodeForContainer(P
 }
 
 
 nsresult
 nsNavBookmarks::QueryFolderChildren(PRInt64 aFolderId,
                                     nsNavHistoryQueryOptions* aOptions,
                                     nsCOMArray<nsNavHistoryResultNode>* aChildren)
 {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildren);
+  mozIStorageStatement* stmt = GetStatement(mDBGetChildren);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = stmt->BindInt64Parameter(0, aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsNavHistoryQueryOptions> options = do_QueryInterface(aOptions, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRInt32 index = -1;
   PRBool hasResult;
@@ -2594,17 +2669,20 @@ nsNavBookmarks::QueryFolderChildren(PRIn
   return NS_OK;
 }
 
 
 nsresult
 nsNavBookmarks::FolderCount(PRInt64 aFolderId, PRInt32* _folderCount)
 {
   *_folderCount = 0;
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFolderCount);
+  mozIStorageStatement* stmt = GetStatement(mDBFolderCount);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = stmt->BindInt64Parameter(0, aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(hasResult, NS_ERROR_UNEXPECTED);
 
@@ -2724,17 +2802,20 @@ nsNavBookmarks::ChangeBookmarkURI(PRInt6
   // before we change it.  GetBookmarkURI will fail if aBookmarkId is bad.
   nsCOMPtr<nsIURI> oldURI;
   PRInt64 oldPlaceId;
   rv = GetBookmarkURI(aBookmarkId, getter_AddRefs(oldURI));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = history->GetUrlIdFor(oldURI, &oldPlaceId, PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(statement, mDBChangeBookmarkURI);
+  mozIStorageStatement* statement = GetStatement(mDBChangeBookmarkURI);
+  NS_ENSURE_STATE(statement);
+  mozStorageStatementScoper scoper(statement);
+
   rv = statement->BindInt64Parameter(0, placeId);
   NS_ENSURE_SUCCESS(rv, rv);
   PRTime lastModified = PR_Now();
   rv = statement->BindInt64Parameter(1, lastModified);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = statement->BindInt64Parameter(2, aBookmarkId);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = statement->Execute();
@@ -2781,17 +2862,19 @@ nsNavBookmarks::ChangeBookmarkURI(PRInt6
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetFolderIdForItem(PRInt64 aItemId, PRInt64* aFolderId)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
   NS_ENSURE_ARG_POINTER(aFolderId);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!hasResult)
@@ -2807,17 +2890,20 @@ nsNavBookmarks::GetFolderIdForItem(PRInt
 
 
 nsresult
 nsNavBookmarks::GetBookmarkIdsForURITArray(nsIURI* aURI,
                                            nsTArray<PRInt64>& aResult)
 {
   NS_ENSURE_ARG(aURI);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFindURIBookmarks);
+  mozIStorageStatement* stmt = GetStatement(mDBFindURIBookmarks);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+
   nsresult rv = BindStatementURI(stmt, 0, aURI);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt32Parameter(1, TYPE_BOOKMARK);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool more;
   while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&more))) && more) {
     PRInt64 bookmarkId;
@@ -2865,17 +2951,19 @@ nsNavBookmarks::GetBookmarkIdsForURI(nsI
 NS_IMETHODIMP
 nsNavBookmarks::GetItemIndex(PRInt64 aItemId, PRInt32* _index)
 {
   NS_ENSURE_ARG_MIN(aItemId, 1);
   NS_ENSURE_ARG_POINTER(_index);
 
   *_index = -1;
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemIndex);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemIndex);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, rv);
   if (!hasResult)
     return NS_OK;
 
@@ -2920,17 +3008,19 @@ nsNavBookmarks::SetItemIndex(PRInt64 aIt
   }
 
   // Ensure we are not going out of range.
   PRInt32 folderCount;
   rv = FolderCount(parent, &folderCount);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(aNewIndex < folderCount, NS_ERROR_INVALID_ARG);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBSetItemIndex);
+  mozIStorageStatement* stmt = GetStatement(mDBSetItemIndex);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindInt32Parameter(1, aNewIndex);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = stmt->Execute();
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -3035,17 +3125,19 @@ nsNavBookmarks::SetKeywordForBookmark(PR
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetKeywordForURI(nsIURI* aURI, nsAString& aKeyword)
 {
   NS_ENSURE_ARG(aURI);
   aKeyword.Truncate(0);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetKeywordForURI);
+  mozIStorageStatement* stmt = GetStatement(mDBGetKeywordForURI);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = BindStatementURI(stmt, 0, aURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasMore = PR_FALSE;
   rv = stmt->ExecuteStep(&hasMore);
   if (NS_FAILED(rv) || !hasMore) {
     aKeyword.SetIsVoid(PR_TRUE);
     return NS_OK; // not found: return void keyword string
@@ -3059,17 +3151,19 @@ nsNavBookmarks::GetKeywordForURI(nsIURI*
 
 
 NS_IMETHODIMP
 nsNavBookmarks::GetKeywordForBookmark(PRInt64 aBookmarkId, nsAString& aKeyword)
 {
   NS_ENSURE_ARG_MIN(aBookmarkId, 1);
   aKeyword.Truncate(0);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetKeywordForBookmark);
+  mozIStorageStatement* stmt = GetStatement(mDBGetKeywordForBookmark);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aBookmarkId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasMore = PR_FALSE;
   rv = stmt->ExecuteStep(&hasMore);
   if (NS_FAILED(rv) || ! hasMore) {
     aKeyword.SetIsVoid(PR_TRUE);
     return NS_OK; // not found: return void keyword string
@@ -3088,17 +3182,19 @@ nsNavBookmarks::GetURIForKeyword(const n
   NS_ENSURE_ARG_POINTER(aURI);
   NS_ENSURE_TRUE(!aKeyword.IsEmpty(), NS_ERROR_INVALID_ARG);
   *aURI = nsnull;
 
   // Shortcuts are always lowercased internally.
   nsAutoString kwd(aKeyword);
   ToLowerCase(kwd);
 
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetURIForKeyword);
+  mozIStorageStatement* stmt = GetStatement(mDBGetURIForKeyword);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindStringParameter(0, kwd);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasMore = PR_FALSE;
   rv = stmt->ExecuteStep(&hasMore);
   if (NS_FAILED(rv) || ! hasMore)
     return NS_OK; // not found: leave URI null
 
@@ -3390,17 +3486,19 @@ nsNavBookmarks::OnItemAnnotationRemoved(
                                     lastModified, itemType));
 
   return NS_OK;
 }
 
 
 PRBool
 nsNavBookmarks::ItemExists(PRInt64 aItemId) {
-  DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
+  mozIStorageStatement* stmt = GetStatement(mDBGetItemProperties);
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
   nsresult rv = stmt->BindInt64Parameter(0, aItemId);
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
 
   PRBool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
 
   return hasResult;