Bug 435994 - Implement ResultSet and Row for mozIStorageStatement::executeAsync
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Fri, 11 Jul 2008 15:47:28 -0400
changeset 15802 b8df7471a2e2f6de5c96523f223b36db46ef7500
parent 15801 3b714908eed1afb958e1e9fffe1d6b8796889d61
child 15803 1a1e94b4dca83b4c1c968908cef6eee6ebf40cc2
push idunknown
push userunknown
push dateunknown
bugs435994, 429986
milestone1.9.1a1pre
Bug 435994 - Implement ResultSet and Row for mozIStorageStatement::executeAsync These creates the result set and row objects to be used with the async storage API added in bug 429986. r=vlad sr=shaver
storage/public/Makefile.in
storage/public/mozIStorageResultSet.idl
storage/public/mozIStorageRow.idl
storage/src/Makefile.in
storage/src/mozStorageResultSet.cpp
storage/src/mozStorageResultSet.h
storage/src/mozStorageRow.cpp
storage/src/mozStorageRow.h
--- a/storage/public/Makefile.in
+++ b/storage/public/Makefile.in
@@ -53,15 +53,17 @@ XPIDLSRCS = \
 	mozIStorageConnection.idl \
 	mozIStorageAggregateFunction.idl \
 	mozIStorageFunction.idl \
 	mozIStorageProgressHandler.idl \
 	mozIStorageStatement.idl \
 	mozIStorageStatementWrapper.idl \
 	mozIStorageDataSet.idl \
 	mozIStorageValueArray.idl \
+	mozIStorageResultSet.idl \
+	mozIStorageRow.idl \
 	$(NULL)
 
 EXPORTS = \
 	mozStorageHelper.h \
 	$(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/storage/public/mozIStorageResultSet.idl
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab 
+ * ***** 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/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 ***** */
+
+#include "nsISupports.idl"
+interface mozIStorageRow;
+
+[scriptable, uuid(18dd7953-076d-4598-8105-3e32ad26ab24)]
+interface mozIStorageResultSet : nsISupports {
+
+  /**
+   * Obtains the next row from the result set from the statement that was
+   * executed.
+   *
+   * @returns the next row from the result set.  This will be null when there
+   *          are no more results.
+   */
+  mozIStorageRow getNextRow();
+};
new file mode 100644
--- /dev/null
+++ b/storage/public/mozIStorageRow.idl
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab 
+ * ***** 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/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 ***** */
+
+#include "mozIStorageValueArray.idl"
+interface nsIVariant;
+
+[scriptable, uuid(62d1b6bd-cbfe-4f9b-aee1-0ead4af4e6dc)]
+interface mozIStorageRow : mozIStorageValueArray {
+
+  /**
+   * Obtains the result of a given column specified by aIndex.
+   *
+   * @param aIndex
+   *        Zero-based index of the result to get from the tuple.
+   * @returns the result of the specified column.
+   */
+  nsIVariant getResultByIndex(in unsigned long aIndex);
+
+  /**
+   * Obtains the result of a given column specified by aIndex.
+   *
+   * @param aName
+   *        Name of the result to get from the tuple.
+   * @returns the result of the specified column.
+   */
+  nsIVariant getResultByName(in AUTF8String aName);
+};
--- a/storage/src/Makefile.in
+++ b/storage/src/Makefile.in
@@ -62,16 +62,18 @@ REQUIRES = xpcom \
 
 CPPSRCS = \
 	mozStorageService.cpp \
 	mozStorageConnection.cpp \
 	mozStorageStatement.cpp \
 	mozStorageStatementWrapper.cpp \
 	mozStorageValueArray.cpp \
 	mozStorageUnicodeFunctions.cpp \
+	mozStorageRow.cpp \
+	mozStorageResultSet.cpp \
 	$(NULL)
 
 LOCAL_INCLUDES = \
 	$(SQLITE_CFLAGS)
 
 # This is the default value.  If we ever change it when compiling sqlite, we
 # will need to change it here as well.
 DEFINES += -DSQLITE_MAX_LIKE_PATTERN_LENGTH=50000
new file mode 100644
--- /dev/null
+++ b/storage/src/mozStorageResultSet.cpp
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab
+ * ***** 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/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 ***** */
+
+#include "mozStorageRow.h"
+#include "mozStorageResultSet.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//// mozStorageResultSet
+
+/**
+ * Note:  This object is only ever accessed on one thread at a time.  It it not
+ *        threadsafe, but it does need threadsafe AddRef and Release.
+ */
+NS_IMPL_THREADSAFE_ISUPPORTS1(mozStorageResultSet, mozIStorageResultSet)
+
+mozStorageResultSet::mozStorageResultSet() :
+    mCurrentIndex(0)
+{
+}
+
+mozStorageResultSet::~mozStorageResultSet()
+{
+  mData.Clear();
+}
+
+nsresult
+mozStorageResultSet::add(mozIStorageRow *aRow)
+{
+  return mData.AppendObject(aRow) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//// mozIStorageResultSet
+
+NS_IMETHODIMP
+mozStorageResultSet::GetNextRow(mozIStorageRow **_row)
+{
+  if (mCurrentIndex >= mData.Count()) {
+    // Just return null here
+    return NS_OK;
+  }
+
+  NS_ADDREF(*_row = mData.ObjectAt(mCurrentIndex++));
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/storage/src/mozStorageResultSet.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab
+ * ***** 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/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 __mozStorageResultSet_h__
+#define __mozStorageResultSet_h__
+
+#include "mozIStorageResultSet.h"
+#include "nsCOMArray.h"
+class mozIStorageRow;
+
+class mozStorageResultSet : public mozIStorageResultSet
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_MOZISTORAGERESULTSET
+
+  mozStorageResultSet();
+  ~mozStorageResultSet();
+
+  /**
+   * Adds a tuple to this result set.
+   */
+  nsresult add(mozIStorageRow *aTuple);
+
+private:
+  /**
+   * Stores the current index of the active result set.
+   */
+  PRInt32 mCurrentIndex;
+  /**
+   * Stores the tuples.
+   */
+  nsCOMArray<mozIStorageRow> mData;
+};
+
+#endif // __mozStorageResultSet_h__
new file mode 100644
--- /dev/null
+++ b/storage/src/mozStorageRow.cpp
@@ -0,0 +1,261 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab
+ * ***** 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/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 ***** */
+
+#include "nsString.h"
+
+#include "sqlite3.h"
+#include "mozStorageVariant.h"
+#include "mozStorageRow.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//// mozStorageRow
+
+/**
+ * Note:  This object is only ever accessed on one thread at a time.  It it not
+ *        threadsafe, but it does need threadsafe AddRef and Release.
+ */
+NS_IMPL_THREADSAFE_ISUPPORTS2(
+  mozStorageRow,
+  mozIStorageRow,
+  mozIStorageValueArray
+)
+
+nsresult
+mozStorageRow::initialize(sqlite3_stmt *aStatement)
+{
+  // Initialize the hash table
+  NS_ENSURE_TRUE(mNameHashtable.Init(), NS_ERROR_OUT_OF_MEMORY);
+
+  // Get the number of results
+  mNumCols = sqlite3_column_count(aStatement);
+
+  // Start copying over values
+  for (PRUint32 i = 0; i < mNumCols; i++) {
+    // Store the value
+    nsIVariant *variant = nsnull;
+    int type = sqlite3_column_type(aStatement, i);
+    switch (type) {
+      case SQLITE_INTEGER:
+        variant = new mozStorageInteger(sqlite3_column_int64(aStatement, i));
+        break;
+      case SQLITE_FLOAT:
+        variant = new mozStorageFloat(sqlite3_column_double(aStatement, i));
+        break;
+      case SQLITE_TEXT:
+      {
+        nsAutoString str(
+          static_cast<const PRUnichar *>(sqlite3_column_text16(aStatement, i))
+        );
+        variant = new mozStorageText(str);
+        break;
+      }
+      case SQLITE_NULL:
+        variant = new mozStorageNull();
+        break;
+      case SQLITE_BLOB:
+      {
+        int size = sqlite3_column_bytes(aStatement, i);
+        const void *data = sqlite3_column_blob(aStatement, i);
+        variant = new mozStorageBlob(std::pair<const void *, int>(data, size));
+        break;
+      }
+      default:
+        return NS_ERROR_UNEXPECTED;
+    }
+    NS_ENSURE_TRUE(variant, NS_ERROR_OUT_OF_MEMORY);
+
+    // Insert into our storage array
+    NS_ENSURE_TRUE(mData.InsertObjectAt(variant, i), NS_ERROR_OUT_OF_MEMORY);
+
+    // Associate the name (if any) with the index
+    const char *name = sqlite3_column_name(aStatement, i);
+    if (!name) break;
+    nsCAutoString colName(name);
+    mNameHashtable.Put(colName, i);
+  }
+
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//// mozIStorageRow
+
+NS_IMETHODIMP
+mozStorageRow::GetResultByIndex(PRUint32 aIndex, nsIVariant **_result)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  NS_ADDREF(*_result = mData.ObjectAt(aIndex));
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetResultByName(const nsACString &aName, nsIVariant **_result)
+{
+  PRUint32 index;
+  NS_ENSURE_TRUE(mNameHashtable.Get(aName, &index), NS_ERROR_NOT_AVAILABLE);
+  return GetResultByIndex(index, _result);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//// mozIStorageValueArray
+
+NS_IMETHODIMP
+mozStorageRow::GetNumEntries(PRUint32 *_entries)
+{
+  *_entries = mNumCols;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_type)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  PRUint16 type;
+  (void)mData.ObjectAt(aIndex)->GetDataType(&type);
+  switch (type) {
+    case nsIDataType::VTYPE_INT32:
+    case nsIDataType::VTYPE_INT64:
+      *_type = mozIStorageValueArray::VALUE_TYPE_INTEGER;
+      break;
+    case nsIDataType::VTYPE_DOUBLE:
+      *_type = mozIStorageValueArray::VALUE_TYPE_FLOAT;
+      break;
+    case nsIDataType::VTYPE_ASTRING:
+      *_type = mozIStorageValueArray::VALUE_TYPE_TEXT;
+      break;
+    case nsIDataType::VTYPE_ARRAY:
+      *_type = mozIStorageValueArray::VALUE_TYPE_BLOB;
+      break;
+    default:
+      *_type = mozIStorageValueArray::VALUE_TYPE_NULL;
+      break;
+  }
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetInt32(PRUint32 aIndex, PRInt32 *_value)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  return mData.ObjectAt(aIndex)->GetAsInt32(_value);
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetInt64(PRUint32 aIndex, PRInt64 *_value)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  return mData.ObjectAt(aIndex)->GetAsInt64(_value);
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetDouble(PRUint32 aIndex, double *_value)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  return mData.ObjectAt(aIndex)->GetAsDouble(_value);
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetUTF8String(PRUint32 aIndex, nsACString &_value)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  return mData.ObjectAt(aIndex)->GetAsAUTF8String(_value);
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetString(PRUint32 aIndex, nsAString &_value)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  return mData.ObjectAt(aIndex)->GetAsAString(_value);
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetBlob(PRUint32 aIndex, PRUint32 *_size, PRUint8 **_blob)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  PRUint16 type;
+  nsIID interface;
+  return mData.ObjectAt(aIndex)->GetAsArray(&type, &interface, _size,
+                                            reinterpret_cast<void **>(_blob));
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetIsNull(PRUint32 aIndex, PRBool *_isNull)
+{
+  if (aIndex >= mNumCols)
+    return NS_ERROR_ILLEGAL_VALUE;
+
+  PRUint16 type;
+  (void)mData.ObjectAt(aIndex)->GetDataType(&type);
+  *_isNull = type == nsIDataType::VTYPE_VOID;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetSharedUTF8String(PRUint32, PRUint32 *, char const **)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetSharedString(PRUint32, PRUint32 *, const PRUnichar **)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+mozStorageRow::GetSharedBlob(PRUint32, PRUint32 *, const PRUint8 **)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
new file mode 100644
--- /dev/null
+++ b/storage/src/mozStorageRow.h
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab
+ * ***** 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/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 __mozStorageRow_h__
+#define __mozStorageRow_h__
+
+#include "mozIStorageRow.h"
+#include "nsCOMArray.h"
+#include "nsDataHashtable.h"
+class nsIVariant;
+struct sqlite3_stmt;
+
+class mozStorageRow : public mozIStorageRow
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_MOZISTORAGEROW
+  NS_DECL_MOZISTORAGEVALUEARRAY
+
+  /**
+   * Initializes the object with the given statement.  Copies the values from
+   * the statement.
+   *
+   * @param aStatement
+   *        The sqlite statement to pull results from.
+   */
+  nsresult initialize(sqlite3_stmt *aStatement);
+
+private:
+  /**
+   * The number of columns in this tuple.
+   */
+  PRUint32 mNumCols;
+
+  /**
+   * Stores the data in the tuple.
+   */
+  nsCOMArray<nsIVariant> mData;
+
+  /**
+   * Maps a given name to a column index.
+   */
+  nsDataHashtable<nsCStringHashKey, PRUint32> mNameHashtable;
+};
+
+#endif // __mozStorageRow_h__