Bug 489612 - Update mozStoragePrivateHelpers.* to follow style guidelines
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Fri, 08 May 2009 20:29:56 -0400
changeset 28140 4d9fc3354fbc77470bc4db3ac65c8bf3a2a6f0aa
parent 28139 c1cb148be7bb2a1df30d902457737cf38d02aca7
child 28141 5293c44639243bf3f111efb1ee4bc31a65a2f559
push idunknown
push userunknown
push dateunknown
bugs489612
milestone1.9.2a1pre
Bug 489612 - Update mozStoragePrivateHelpers.* to follow style guidelines Consistent spacing, consistent naming, and namespaces - OH MY! r=asuth
storage/src/mozStorageAsyncStatementExecution.cpp
storage/src/mozStorageConnection.cpp
storage/src/mozStoragePrivateHelpers.cpp
storage/src/mozStoragePrivateHelpers.h
storage/src/mozStorageService.cpp
storage/src/mozStorageStatement.cpp
--- a/storage/src/mozStorageAsyncStatementExecution.cpp
+++ b/storage/src/mozStorageAsyncStatementExecution.cpp
@@ -312,17 +312,17 @@ AsyncExecuteStatements::executeAndProces
 
     // Notify, and stop processing statements.
     (void)notifyError(mozIStorageError::ERROR, "");
     return false;
   }
 
 #ifdef DEBUG
   // Check to make sure that this statement was smart about what it did.
-  CheckAndLogStatementPerformance(aStatement);
+  checkAndLogStatementPerformance(aStatement);
 #endif
 
   // If we are done, we need to set our state accordingly while we still hold
   // our mutex.  We would have already returned if we were canceled or had
   // an error at this point.
   if (aLastStatement)
     mState = COMPLETED;
 
--- a/storage/src/mozStorageConnection.cpp
+++ b/storage/src/mozStorageConnection.cpp
@@ -346,17 +346,17 @@ Connection::initialize(nsIFile *aDatabas
     srv = ::sqlite3_open(NS_ConvertUTF16toUTF8(path).get(), &mDBConn);
   }
   else {
     // in memory database requested, sqlite uses a magic file name
     srv = ::sqlite3_open(":memory:", &mDBConn);
   }
   if (srv != SQLITE_OK) {
     mDBConn = nsnull;
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
   }
 
 #ifdef PR_LOGGING
   if (!gStorageLog)
     gStorageLog = ::PR_NewLogModule("mozStorage");
 
   ::sqlite3_trace(mDBConn, tracefunc, this);
 
@@ -365,17 +365,17 @@ Connection::initialize(nsIFile *aDatabas
     (void)aDatabaseFile->GetNativeLeafName(leafName);
   PR_LOG(gStorageLog, PR_LOG_NOTICE, ("Opening connection to '%s' (%p)",
                                       leafName.get(), this));
 #endif
 
   // Register our built-in SQL functions.
   if (registerFunctions(mDBConn) != SQLITE_OK) {
     mDBConn = nsnull;
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
   }
 
   // Execute a dummy statement to force the db open, and to verify if it is
   // valid or not.
   sqlite3_stmt *stmt;
   srv = ::sqlite3_prepare_v2(mDBConn, "SELECT * FROM sqlite_master", -1, &stmt,
                              NULL);
   if (srv == SQLITE_OK) {
@@ -385,17 +385,17 @@ Connection::initialize(nsIFile *aDatabas
         srv = SQLITE_OK;
     ::sqlite3_finalize(stmt);
   }
 
   if (srv != SQLITE_OK) {
     ::sqlite3_close(mDBConn);
     mDBConn = nsnull;
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
   }
 
   // Set the synchronous PRAGMA, according to the pref
   nsCOMPtr<nsIPrefBranch> 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);
 
@@ -436,32 +436,32 @@ Connection::databaseElementExists(enum D
   }
   query.Append("' AND name ='");
   query.Append(aElementName);
   query.Append("'");
 
   sqlite3_stmt *stmt;
   int srv = ::sqlite3_prepare_v2(mDBConn, query.get(), -1, &stmt, NULL);
   if (srv != SQLITE_OK)
-      return ConvertResultCode(srv);
+    return convertResultCode(srv);
 
   srv = ::sqlite3_step(stmt);
   // we just care about the return value from step
   (void)::sqlite3_finalize(stmt);
 
   if (srv == SQLITE_ROW) {
     *_exists = PR_TRUE;
     return NS_OK;
   }
   if (srv == SQLITE_DONE) {
     *_exists = PR_FALSE;
     return NS_OK;
   }
 
-  return ConvertResultCode(srv);
+  return convertResultCode(srv);
 }
 
 bool
 Connection::findFunctionByInstance(nsISupports *aInstance)
 {
   PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(mFunctionsMutex);
   FFEArguments args = { aInstance, false };
   mFunctions.EnumerateRead(findFunctionEnumerator, &args);
@@ -536,17 +536,17 @@ Connection::Close()
       ::sqlite3_progress_handler(mDBConn, 0, NULL, NULL);
   }
 
   int srv = ::sqlite3_close(mDBConn);
   if (srv != SQLITE_OK)
     NS_ERROR("sqlite3_close failed. There are probably outstanding statements that are listed above!");
 
   mDBConn = NULL;
-  return ConvertResultCode(srv);
+  return convertResultCode(srv);
 }
 
 NS_IMETHODIMP
 Connection::GetConnectionReady(PRBool *_ready)
 {
   *_ready = (mDBConn != nsnull);
   return NS_OK;
 }
@@ -643,17 +643,17 @@ Connection::CreateStatement(const nsACSt
 
 NS_IMETHODIMP
 Connection::ExecuteSimpleSQL(const nsACString &aSQLStatement)
 {
   if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
 
   int srv = ::sqlite3_exec(mDBConn, PromiseFlatCString(aSQLStatement).get(),
                            NULL, NULL, NULL);
-  return ConvertResultCode(srv);
+  return convertResultCode(srv);
 }
 
 nsresult
 Connection::ExecuteAsync(mozIStorageStatement **aStatements,
                          PRUint32 aNumStatements,
                          mozIStorageStatementCallback *aCallback,
                          mozIStoragePendingStatement **_handle)
 {
@@ -700,17 +700,17 @@ Connection::ExecuteAsync(mozIStorageStat
     rv = AsyncExecuteStatements::execute(stmts, this, aCallback, _handle);
 
   // We had a failure, so we need to clean up...
   if (rc != SQLITE_OK || NS_FAILED(rv)) {
     for (PRUint32 i = 0; i < stmts.Length(); i++)
       (void)::sqlite3_finalize(stmts[i]);
 
     if (rc != SQLITE_OK)
-      rv = ConvertResultCode(rc);
+      rv = convertResultCode(rc);
   }
 
   // Always reset all the statements
   for (PRUint32 i = 0; i < aNumStatements; i++)
     (void)aStatements[i]->Reset();
 
   return rv;
 }
@@ -800,17 +800,17 @@ Connection::CreateTable(const char *aTab
 
   char *buf = ::PR_smprintf("CREATE TABLE %s (%s)", aTableName, aTableSchema);
   if (!buf)
     return NS_ERROR_OUT_OF_MEMORY;
 
   int srv = ::sqlite3_exec(mDBConn, buf, NULL, NULL, NULL);
   ::PR_smprintf_free(buf);
 
-  return ConvertResultCode(srv);
+  return convertResultCode(srv);
 }
 
 NS_IMETHODIMP
 Connection::CreateFunction(const nsACString &aFunctionName,
                            PRInt32 aNumArguments,
                            mozIStorageFunction *aFunction)
 {
   if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
@@ -824,17 +824,17 @@ Connection::CreateFunction(const nsACStr
                                       nsPromiseFlatCString(aFunctionName).get(),
                                       aNumArguments,
                                       SQLITE_ANY,
                                       aFunction,
                                       basicFunctionHelper,
                                       NULL,
                                       NULL);
   if (srv != SQLITE_OK)
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 
   NS_ENSURE_TRUE(mFunctions.Put(aFunctionName, aFunction),
                  NS_ERROR_OUT_OF_MEMORY);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -857,17 +857,17 @@ Connection::CreateAggregateFunction(cons
                                       nsPromiseFlatCString(aFunctionName).get(),
                                       aNumArguments,
                                       SQLITE_ANY,
                                       aFunction,
                                       NULL,
                                       aggregateFunctionStepHelper,
                                       aggregateFunctionFinalHelper);
   if (srv != SQLITE_OK)
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 
   NS_ENSURE_TRUE(mFunctions.Put(aFunctionName, aFunction),
                  NS_ERROR_OUT_OF_MEMORY);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -882,17 +882,17 @@ Connection::RemoveFunction(const nsACStr
                                       nsPromiseFlatCString(aFunctionName).get(),
                                       0,
                                       SQLITE_ANY,
                                       NULL,
                                       NULL,
                                       NULL,
                                       NULL);
   if (srv != SQLITE_OK)
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 
   mFunctions.Remove(aFunctionName);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Connection::SetProgressHandler(PRInt32 aGranularity,
--- a/storage/src/mozStoragePrivateHelpers.cpp
+++ b/storage/src/mozStoragePrivateHelpers.cpp
@@ -41,18 +41,21 @@
 #include "sqlite3.h"
 
 #include "nsPrintfCString.h"
 #include "nsString.h"
 #include "nsError.h"
 
 #include "mozStoragePrivateHelpers.h"
 
+namespace mozilla {
+namespace storage {
+
 nsresult
-ConvertResultCode(int aSQLiteResultCode)
+convertResultCode(int aSQLiteResultCode)
 {
   switch (aSQLiteResultCode) {
     case SQLITE_OK:
     case SQLITE_ROW:
     case SQLITE_DONE:
       return NS_OK;
     case SQLITE_CORRUPT:
     case SQLITE_NOTADB:
@@ -80,35 +83,38 @@ ConvertResultCode(int aSQLiteResultCode)
       return NS_ERROR_ABORT;
   }
 
   // generic error
   return NS_ERROR_FAILURE;
 }
 
 void
-CheckAndLogStatementPerformance(sqlite3_stmt *aStatement)
+checkAndLogStatementPerformance(sqlite3_stmt *aStatement)
 {
   // Check to see if the query performed sorting operations or not.  If it
   // did, it may need to be optimized!
-  int count = sqlite3_stmt_status(aStatement, SQLITE_STMTSTATUS_SORT, 1);
+  int count = ::sqlite3_stmt_status(aStatement, SQLITE_STMTSTATUS_SORT, 1);
   if (count <= 0)
     return;
 
-  const char *sql = sqlite3_sql(aStatement);
+  const char *sql = ::sqlite3_sql(aStatement);
 
   // Check to see if this is marked to not warn
-  if (strstr(sql, "/* do not warn (bug "))
+  if (::strstr(sql, "/* do not warn (bug "))
     return;
 
   nsCAutoString message;
   message.AppendInt(count);
   if (count == 1)
     message.Append(" sort operation has ");
   else
     message.Append(" sort operations have ");
   message.Append("occurred for the SQL statement '");
   nsPrintfCString address("0x%p", aStatement);
   message.Append(address);
   message.Append("'.  See https://developer.mozilla.org/En/Storage/Warnings "
                  "details.");
   NS_WARNING(message.get());
 }
+
+} // namespace storage
+} // namespace mozilla
--- a/storage/src/mozStoragePrivateHelpers.h
+++ b/storage/src/mozStoragePrivateHelpers.h
@@ -1,10 +1,10 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: sw=4 ts=4 sts=4
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -33,39 +33,44 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef _MOZSTORAGEPRIVATEHELPERS_H_
-#define _MOZSTORAGEPRIVATEHELPERS_H_
+#ifndef _mozStoragePrivateHelpers_h_
+#define _mozStoragePrivateHelpers_h_
 
 #include "mozStorage.h"
 
 /**
  * This file contains convenience methods for mozStorage.
  */
 
+namespace mozilla {
+namespace storage {
+
 /**
  * Converts a SQLite return code to an nsresult return code.
  *
  * @param aSQLiteResultCode
  *        The SQLite return code to convert.
  * @returns the corresponding nsresult code for aSQLiteResultCode.
  */
-nsresult ConvertResultCode(int aSQLiteResultCode);
+nsresult convertResultCode(int aSQLiteResultCode);
 
 /**
  * Checks the performance of a SQLite statement and logs a warning with
  * NS_WARNING.  Currently this only checks the number of sort operations done
  * on a statement, and if more than zero have been done, the statement can be
  * made faster with the careful use of an index.
  *
  * @param aStatement
  *        The sqlite3_stmt object to check.
  */
-void CheckAndLogStatementPerformance(sqlite3_stmt *aStatement);
+void checkAndLogStatementPerformance(sqlite3_stmt *aStatement);
 
-#endif // _MOZSTORAGEPRIVATEHELPERS_H_
+} // namespace storage
+} // namespace mozilla
 
+#endif // _mozStoragePrivateHelpers_h_
--- a/storage/src/mozStorageService.cpp
+++ b/storage/src/mozStorageService.cpp
@@ -142,33 +142,33 @@ Service::initialize()
   mLock = ::PR_NewLock();
   NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
 
   // Disable memory allocation statistic collection, improving performance.
   // This must be done prior to a call to sqlite3_initialize to have any
   // effect.
   int rc = ::sqlite3_config(SQLITE_CONFIG_MEMSTATUS, 0);
   if (rc != SQLITE_OK)
-    return ConvertResultCode(rc);
+    return convertResultCode(rc);
 
   // Explicitly initialize sqlite3.  Although this is implicitly called by
   // various sqlite3 functions (and the sqlite3_open calls in our case),
   // the documentation suggests calling this directly.  So we do.
   rc = ::sqlite3_initialize();
   if (rc != SQLITE_OK)
-    return ConvertResultCode(rc);
+    return convertResultCode(rc);
 
   // This makes multiple connections to the same database share the same pager
   // cache.  We do not need to lock here with mLock because this function is
   // only ever called from Service::GetSingleton, which will only
   // call this function once, and will not return until this function returns.
   // (It does not matter where this is called relative to sqlite3_initialize.)
   rc = ::sqlite3_enable_shared_cache(1);
   if (rc != SQLITE_OK)
-    return ConvertResultCode(rc);
+    return convertResultCode(rc);
 
   nsCOMPtr<nsIObserverService> os =
     do_GetService("@mozilla.org/observer-service;1");
   NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
 
   nsresult rv = os->AddObserver(this, "xpcom-shutdown", PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -250,23 +250,23 @@ Service::OpenUnsharedDatabase(nsIFile *a
   // lifetimes, unaffected by changes to the shared caches setting, so we can
   // disable shared caches temporarily while we initialize the new connection
   // without affecting the caches currently in use by other connections.
   nsresult rv;
   {
     nsAutoLock lock(mLock);
     int rc = ::sqlite3_enable_shared_cache(0);
     if (rc != SQLITE_OK)
-      return ConvertResultCode(rc);
+      return convertResultCode(rc);
 
     rv = msc->initialize(aDatabaseFile);
 
     rc = ::sqlite3_enable_shared_cache(1);
     if (rc != SQLITE_OK)
-      return ConvertResultCode(rc);
+      return convertResultCode(rc);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ADDREF(*_connection = msc);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -320,17 +320,17 @@ mozStorageStatement::Finalize()
             do_QueryInterface(mStatementRowHolder);
         nsCOMPtr<mozIStorageStatementRow> iRow =
             do_QueryWrappedNative(wrapper);
         StatementRow *row = static_cast<StatementRow *>(iRow.get());
         row->mStatement = nsnull;
         mStatementRowHolder = nsnull;
     }
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* readonly attribute unsigned long parameterCount; */
 NS_IMETHODIMP
 mozStorageStatement::GetParameterCount(PRUint32 *aParameterCount)
 {
     NS_ENSURE_ARG_POINTER(aParameterCount);
 
@@ -442,17 +442,17 @@ mozStorageStatement::Reset()
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
 #ifdef DEBUG
     PR_LOG(gStorageLog, PR_LOG_DEBUG, ("Resetting statement: '%s'",
                                        sqlite3_sql(mDBStatement)));
 
-    CheckAndLogStatementPerformance(mDBStatement);
+    checkAndLogStatementPerformance(mDBStatement);
 #endif
 
     sqlite3_reset(mDBStatement);
     sqlite3_clear_bindings(mDBStatement);
 
     mExecuting = PR_FALSE;
 
     return NS_OK;
@@ -464,92 +464,92 @@ mozStorageStatement::BindUTF8StringParam
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_text (mDBStatement, aParamIndex + 1,
                                  nsPromiseFlatCString(aValue).get(),
                                  aValue.Length(), SQLITE_TRANSIENT);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void bindStringParameter (in unsigned long aParamIndex, in AString aValue); */
 NS_IMETHODIMP
 mozStorageStatement::BindStringParameter(PRUint32 aParamIndex, const nsAString & aValue)
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_text16 (mDBStatement, aParamIndex + 1,
                                    nsPromiseFlatString(aValue).get(),
                                    aValue.Length() * 2, SQLITE_TRANSIENT);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void bindDoubleParameter (in unsigned long aParamIndex, in double aValue); */
 NS_IMETHODIMP
 mozStorageStatement::BindDoubleParameter(PRUint32 aParamIndex, double aValue)
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_double (mDBStatement, aParamIndex + 1, aValue);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void bindInt32Parameter (in unsigned long aParamIndex, in long aValue); */
 NS_IMETHODIMP
 mozStorageStatement::BindInt32Parameter(PRUint32 aParamIndex, PRInt32 aValue)
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_int (mDBStatement, aParamIndex + 1, aValue);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void bindInt64Parameter (in unsigned long aParamIndex, in long long aValue); */
 NS_IMETHODIMP
 mozStorageStatement::BindInt64Parameter(PRUint32 aParamIndex, PRInt64 aValue)
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_int64 (mDBStatement, aParamIndex + 1, aValue);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void bindNullParameter (in unsigned long aParamIndex); */
 NS_IMETHODIMP
 mozStorageStatement::BindNullParameter(PRUint32 aParamIndex)
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_null (mDBStatement, aParamIndex + 1);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void bindBlobParameter (in unsigned long aParamIndex, [array, const, size_is (aValueSize)] in octet aValue, in unsigned long aValueSize); */
 NS_IMETHODIMP
 mozStorageStatement::BindBlobParameter(PRUint32 aParamIndex, const PRUint8 *aValue, PRUint32 aValueSize)
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
 
     int srv = sqlite3_bind_blob (mDBStatement, aParamIndex + 1, aValue,
                                  aValueSize, SQLITE_TRANSIENT);
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* void execute (); */
 NS_IMETHODIMP
 mozStorageStatement::Execute()
 {
     if (!mDBStatement)
         return NS_ERROR_NOT_INITIALIZED;
@@ -594,17 +594,17 @@ mozStorageStatement::ExecuteStep(PRBool 
         mExecuting = PR_FALSE;
     } else if (mExecuting == PR_TRUE) {
 #ifdef PR_LOGGING
         PR_LOG(gStorageLog, PR_LOG_ERROR, ("SQLite error after mExecuting was true!"));
 #endif
         mExecuting = PR_FALSE;
     }
 
-    return ConvertResultCode(srv);
+    return convertResultCode(srv);
 }
 
 /* nsICancelable executeAsync([optional] in storageIStatementCallback aCallback); */
 nsresult
 mozStorageStatement::ExecuteAsync(mozIStorageStatementCallback *aCallback,
                                   mozIStoragePendingStatement **_stmt)
 {
     mozIStorageStatement * stmts[1] = {this};