2010-06-23 23:46:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* ***** 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 Indexed Database.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Turner <bent.mozilla@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBCursor.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
#include "nsIVariant.h"
|
|
|
|
|
2010-08-27 00:57:25 +04:00
|
|
|
#include "jscntxt.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "mozilla/storage.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
2011-10-03 23:11:31 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2010-11-11 02:26:03 +03:00
|
|
|
#include "nsEventDispatcher.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBEvents.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBIndex.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "TransactionThreadPool.h"
|
|
|
|
|
|
|
|
USING_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
inline
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GenerateRequest(IDBCursor* aCursor)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
IDBDatabase* database = aCursor->Transaction()->Database();
|
2010-11-11 02:26:03 +03:00
|
|
|
return IDBRequest::Create(aCursor, database->ScriptContext(),
|
|
|
|
database->Owner(), aCursor->Transaction());
|
2010-09-10 02:15:38 +04:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
class ContinueHelper : public AsyncConnectionHelper
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-12-10 05:15:00 +03:00
|
|
|
ContinueHelper(IDBCursor* aCursor)
|
|
|
|
: AsyncConnectionHelper(aCursor->mTransaction, aCursor->mRequest),
|
|
|
|
mCursor(aCursor)
|
|
|
|
{ }
|
|
|
|
|
2011-01-27 04:53:02 +03:00
|
|
|
~ContinueHelper()
|
|
|
|
{
|
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(mCloneBuffer);
|
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-07 09:21:36 +03:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
mCursor = nsnull;
|
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual nsresult
|
|
|
|
BindArgumentsToStatement(mozIStorageStatement* aStatement) = 0;
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
GatherResultsFromStatement(mozIStorageStatement* aStatement) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<IDBCursor> mCursor;
|
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
2010-12-21 19:02:04 +03:00
|
|
|
JSAutoStructuredCloneBuffer mCloneBuffer;
|
2010-12-10 05:15:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueObjectStoreHelper : public ContinueHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContinueObjectStoreHelper(IDBCursor* aCursor)
|
|
|
|
: ContinueHelper(aCursor)
|
|
|
|
{ }
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
private:
|
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueIndexHelper : public ContinueHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContinueIndexHelper(IDBCursor* aCursor)
|
|
|
|
: ContinueHelper(aCursor)
|
2010-06-23 23:46:08 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
2010-12-10 05:15:00 +03:00
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueIndexObjectHelper : public ContinueIndexHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContinueIndexObjectHelper(IDBCursor* aCursor)
|
|
|
|
: ContinueIndexHelper(aCursor)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBObjectStore* aObjectStore,
|
|
|
|
PRUint16 aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
2010-12-21 19:02:04 +03:00
|
|
|
JSAutoStructuredCloneBuffer& aCloneBuffer)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aObjectStore, aDirection,
|
|
|
|
aRangeKey, aContinueQuery, aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
cursor->mObjectStore = aObjectStore;
|
|
|
|
cursor->mType = OBJECTSTORE;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mKey = aKey;
|
2010-12-21 19:02:04 +03:00
|
|
|
cursor->mCloneBuffer.swap(aCloneBuffer);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBIndex* aIndex,
|
|
|
|
PRUint16 aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex, "Null pointer!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
|
|
|
NS_ASSERTION(!aObjectKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aIndex->ObjectStore(),
|
|
|
|
aDirection, aRangeKey, aContinueQuery,
|
|
|
|
aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
cursor->mIndex = aIndex;
|
2010-12-16 00:21:11 +03:00
|
|
|
cursor->mType = INDEXKEY;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mKey = aKey,
|
|
|
|
cursor->mObjectKey = aObjectKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBIndex* aIndex,
|
|
|
|
PRUint16 aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey,
|
2010-12-21 19:02:04 +03:00
|
|
|
JSAutoStructuredCloneBuffer& aCloneBuffer)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex, "Null pointer!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aIndex->ObjectStore(),
|
|
|
|
aDirection, aRangeKey, aContinueQuery,
|
|
|
|
aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
cursor->mObjectStore = aIndex->ObjectStore();
|
|
|
|
cursor->mIndex = aIndex;
|
|
|
|
cursor->mType = INDEXOBJECT;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mKey = aKey;
|
|
|
|
cursor->mObjectKey = aObjectKey;
|
2010-12-21 19:02:04 +03:00
|
|
|
cursor->mCloneBuffer.swap(aCloneBuffer);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::CreateCommon(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBObjectStore* aObjectStore,
|
|
|
|
PRUint16 aDirection,
|
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aRequest, "Null pointer!");
|
|
|
|
NS_ASSERTION(aTransaction, "Null pointer!");
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
|
|
|
NS_ASSERTION(!aContinueQuery.IsEmpty(), "Empty query!");
|
|
|
|
NS_ASSERTION(!aContinueToQuery.IsEmpty(), "Empty query!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
nsRefPtr<IDBCursor> cursor = new IDBCursor();
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
cursor->mRequest = aRequest;
|
|
|
|
cursor->mTransaction = aTransaction;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mObjectStore = aObjectStore;
|
|
|
|
cursor->mScriptContext = aTransaction->Database()->ScriptContext();
|
|
|
|
cursor->mOwner = aTransaction->Database()->Owner();
|
2010-06-23 23:46:08 +04:00
|
|
|
cursor->mDirection = aDirection;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mContinueQuery = aContinueQuery;
|
|
|
|
cursor->mContinueToQuery = aContinueToQuery;
|
|
|
|
cursor->mRangeKey = aRangeKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBCursor::IDBCursor()
|
2010-12-10 05:15:00 +03:00
|
|
|
: mType(OBJECTSTORE),
|
|
|
|
mDirection(nsIIDBCursor::NEXT),
|
2011-02-11 10:47:00 +03:00
|
|
|
mCachedPrimaryKey(JSVAL_VOID),
|
2010-06-23 23:46:08 +04:00
|
|
|
mCachedValue(JSVAL_VOID),
|
2011-02-11 10:47:00 +03:00
|
|
|
mHaveCachedPrimaryKey(false),
|
2010-06-23 23:46:08 +04:00
|
|
|
mHaveCachedValue(false),
|
2011-02-11 10:47:00 +03:00
|
|
|
mRooted(false),
|
2011-01-07 09:21:36 +03:00
|
|
|
mContinueCalled(false),
|
|
|
|
mHaveValue(true)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
}
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBCursor::~IDBCursor()
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
if (mRooted) {
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_DROP_JS_OBJECTS(this, IDBCursor);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
2010-12-21 19:02:04 +03:00
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(mCloneBuffer);
|
2010-09-10 02:15:38 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBCursor)
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBCursor)
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRequest,
|
2011-06-24 06:18:00 +04:00
|
|
|
nsIDOMEventTarget)
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTransaction,
|
2011-06-24 06:18:00 +04:00
|
|
|
nsIDOMEventTarget)
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mObjectStore)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mIndex)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptContext)
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
|
2011-02-11 10:47:00 +03:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedPrimaryKey ||
|
|
|
|
JSVAL_IS_VOID(tmp->mCachedPrimaryKey),
|
|
|
|
"Should have a cached primary key");
|
|
|
|
NS_ASSERTION(tmp->mHaveCachedValue || JSVAL_IS_VOID(tmp->mCachedValue),
|
|
|
|
"Should have a cached value");
|
2011-11-03 05:57:48 +04:00
|
|
|
if (JSVAL_IS_GCTHING(tmp->mCachedValue)) {
|
|
|
|
void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedValue);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedValue")
|
2010-09-14 02:32:56 +04:00
|
|
|
}
|
2011-02-11 10:47:00 +03:00
|
|
|
if (JSVAL_IS_GCTHING(tmp->mCachedPrimaryKey)) {
|
|
|
|
void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedPrimaryKey);
|
2011-02-02 18:30:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedPrimaryKey")
|
2011-02-11 10:47:00 +03:00
|
|
|
}
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
|
2010-09-10 02:15:38 +04:00
|
|
|
// Don't unlink mObjectStore, mIndex, or mTransaction!
|
2010-11-08 18:02:49 +03:00
|
|
|
if (tmp->mRooted) {
|
|
|
|
NS_DROP_JS_OBJECTS(tmp, IDBCursor);
|
|
|
|
tmp->mCachedPrimaryKey = JSVAL_VOID;
|
|
|
|
tmp->mCachedValue = JSVAL_VOID;
|
|
|
|
tmp->mHaveCachedPrimaryKey = false;
|
|
|
|
tmp->mHaveCachedValue = false;
|
|
|
|
tmp->mRooted = false;
|
|
|
|
tmp->mHaveValue = false;
|
|
|
|
}
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRequest)
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mScriptContext)
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBCursor)
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIDBCursor)
|
2011-02-11 10:47:00 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIDBCursorWithValue, mType != INDEXKEY)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBCursorWithValue,
|
|
|
|
mType != INDEXKEY)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBCursor,
|
|
|
|
mType == INDEXKEY)
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBCursor)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBCursor)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
DOMCI_DATA(IDBCursor, IDBCursor)
|
2011-02-11 10:47:00 +03:00
|
|
|
DOMCI_DATA(IDBCursorWithValue, IDBCursor)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBCursor::GetDirection(PRUint16* aDirection)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
*aDirection = mDirection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-10 05:14:09 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBCursor::GetSource(nsISupports** aSource)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
return mType == OBJECTSTORE ?
|
|
|
|
CallQueryInterface(mObjectStore, aSource) :
|
|
|
|
CallQueryInterface(mIndex, aSource);
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_IMETHODIMP
|
2011-11-03 05:57:48 +04:00
|
|
|
IDBCursor::GetKey(nsIVariant** aKey)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
if (!mCachedKey) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWritableVariant> variant =
|
|
|
|
do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() || !mHaveValue, "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
if (!mHaveValue) {
|
|
|
|
rv = variant->SetAsVoid();
|
|
|
|
}
|
|
|
|
else if (mKey.IsString()) {
|
|
|
|
rv = variant->SetAsAString(mKey.StringValue());
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
2011-11-03 05:57:48 +04:00
|
|
|
else if (mKey.IsInt()) {
|
|
|
|
rv = variant->SetAsInt64(mKey.IntValue());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Huh?!");
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
rv = variant->SetWritable(false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
nsIWritableVariant* result;
|
|
|
|
variant.forget(&result);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
mCachedKey = dont_AddRef(static_cast<nsIVariant*>(result));
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
nsCOMPtr<nsIVariant> result(mCachedKey);
|
|
|
|
result.forget(aKey);
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-02-11 10:47:00 +03:00
|
|
|
IDBCursor::GetPrimaryKey(JSContext* aCx,
|
|
|
|
jsval* aValue)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue) {
|
|
|
|
*aValue = JSVAL_VOID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
if (!mHaveCachedPrimaryKey) {
|
|
|
|
if (!mRooted) {
|
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
NS_ASSERTION(mType == OBJECTSTORE ? !mKey.IsUnset() :
|
|
|
|
!mObjectKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
nsresult rv =
|
|
|
|
IDBObjectStore::GetJSValFromKey(mType == OBJECTSTORE ? mKey : mObjectKey,
|
|
|
|
aCx, &mCachedPrimaryKey);
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
mHaveCachedPrimaryKey = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = mCachedPrimaryKey;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBCursor::GetValue(JSContext* aCx,
|
|
|
|
jsval* aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(mType != INDEXKEY, "GetValue shouldn't exist on index keys");
|
|
|
|
|
|
|
|
if (!mHaveValue) {
|
|
|
|
*aValue = JSVAL_VOID;
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveCachedValue) {
|
2011-02-11 10:47:00 +03:00
|
|
|
if (!mRooted) {
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
2011-02-11 10:47:00 +03:00
|
|
|
mRooted = true;
|
2010-09-14 02:32:56 +04:00
|
|
|
}
|
|
|
|
|
2011-06-09 06:21:53 +04:00
|
|
|
if (!IDBObjectStore::DeserializeValue(aCx, mCloneBuffer, &mCachedValue)) {
|
2010-12-21 19:02:04 +03:00
|
|
|
mCachedValue = JSVAL_VOID;
|
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
|
|
|
}
|
|
|
|
|
2011-07-12 21:42:24 +04:00
|
|
|
mCloneBuffer.clear();
|
2010-06-23 23:46:08 +04:00
|
|
|
mHaveCachedValue = true;
|
|
|
|
}
|
|
|
|
|
2010-06-29 02:22:41 +04:00
|
|
|
*aValue = mCachedValue;
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-07-15 10:19:36 +04:00
|
|
|
IDBCursor::Continue(const jsval &aKey,
|
2010-12-16 00:21:07 +03:00
|
|
|
JSContext* aCx)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2010-12-16 00:21:14 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue || mContinueCalled) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Key key;
|
2011-11-03 05:57:48 +04:00
|
|
|
nsresult rv = IDBObjectStore::GetKeyFromJSVal(aKey, aCx, key);
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
if (!key.IsUnset()) {
|
|
|
|
switch (mDirection) {
|
|
|
|
case nsIIDBCursor::NEXT:
|
|
|
|
case nsIIDBCursor::NEXT_NO_DUPLICATE:
|
|
|
|
if (key <= mKey) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
case nsIIDBCursor::PREV:
|
|
|
|
case nsIIDBCursor::PREV_NO_DUPLICATE:
|
|
|
|
if (key >= mKey) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction type!");
|
|
|
|
}
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
mContinueToKey = key;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
PRUint16 readyState;
|
|
|
|
if (NS_FAILED(mRequest->GetReadyState(&readyState))) {
|
|
|
|
NS_ERROR("This should never fail!");
|
|
|
|
}
|
|
|
|
NS_ASSERTION(readyState == nsIIDBRequest::DONE, "Should be DONE!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
nsRefPtr<ContinueHelper> helper;
|
|
|
|
switch (mType) {
|
|
|
|
case OBJECTSTORE:
|
|
|
|
helper = new ContinueObjectStoreHelper(this);
|
|
|
|
break;
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
case INDEXKEY:
|
2010-12-10 05:15:00 +03:00
|
|
|
helper = new ContinueIndexHelper(this);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXOBJECT:
|
|
|
|
helper = new ContinueIndexObjectHelper(this);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown cursor type!");
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
rv = helper->DispatchToTransactionPool();
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mContinueCalled = true;
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-11-11 02:25:44 +03:00
|
|
|
IDBCursor::Update(const jsval& aValue,
|
2010-06-29 02:22:41 +04:00
|
|
|
JSContext* aCx,
|
2010-06-28 22:51:06 +04:00
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2010-12-16 00:21:14 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
|
|
|
}
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue || mType == INDEXKEY) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
2010-12-16 00:21:11 +03:00
|
|
|
NS_ASSERTION(mType != INDEXOBJECT || !mObjectKey.IsUnset(), "Bad key!");
|
|
|
|
|
|
|
|
nsresult rv;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-29 02:22:41 +04:00
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
const Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
if (!mObjectStore->KeyPath().IsEmpty()) {
|
2010-12-16 00:21:11 +03:00
|
|
|
// This has to be an object.
|
|
|
|
if (JSVAL_IS_PRIMITIVE(aValue)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the object given has the correct keyPath value set on it.
|
2010-06-23 23:46:08 +04:00
|
|
|
const nsString& keyPath = mObjectStore->KeyPath();
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
jsval prop;
|
|
|
|
JSBool ok = JS_GetUCProperty(aCx, JSVAL_TO_OBJECT(aValue),
|
|
|
|
reinterpret_cast<const jschar*>(keyPath.get()),
|
|
|
|
keyPath.Length(), &prop);
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
Key key;
|
2011-11-03 05:57:48 +04:00
|
|
|
rv = IDBObjectStore::GetKeyFromJSVal(prop, aCx, key);
|
2010-12-16 00:21:11 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
if (key != objectKey) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
return mObjectStore->Put(aValue, JSVAL_VOID, aCx, 0, _retval);
|
2010-11-11 02:25:44 +03:00
|
|
|
}
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
jsval keyVal;
|
2011-11-03 05:57:48 +04:00
|
|
|
rv = IDBObjectStore::GetJSValFromKey(objectKey, aCx, &keyVal);
|
2010-12-16 00:21:11 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
return mObjectStore->Put(aValue, keyVal, aCx, 1, _retval);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-12-16 00:21:11 +03:00
|
|
|
IDBCursor::Delete(JSContext* aCx,
|
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2010-12-16 00:21:14 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
|
|
|
}
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue || mType == INDEXKEY) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
2010-12-16 00:21:11 +03:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
const Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
jsval key;
|
2011-11-03 05:57:48 +04:00
|
|
|
nsresult rv = IDBObjectStore::GetJSValFromKey(objectKey, aCx, &key);
|
2010-12-16 00:21:11 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
return mObjectStore->Delete(key, aCx, _retval);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
nsresult
|
|
|
|
ContinueHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
|
|
|
// We need to pick a query based on whether or not the cursor's mContinueToKey
|
|
|
|
// is set. If it is unset then othing was passed to continue so we'll grab the
|
|
|
|
// next item in the database that is greater than (less than, if we're running
|
|
|
|
// a PREV cursor) the current key. If it is set then a key was passed to
|
|
|
|
// continue so we'll grab the next item in the database that is greater than
|
|
|
|
// (less than, if we're running a PREV cursor) or equal to the key that was
|
|
|
|
// specified.
|
|
|
|
|
|
|
|
const nsCString& query = mCursor->mContinueToKey.IsUnset() ?
|
|
|
|
mCursor->mContinueQuery :
|
|
|
|
mCursor->mContinueToQuery;
|
|
|
|
NS_ASSERTION(!query.IsEmpty(), "Bad query!");
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = BindArgumentsToStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasResult;
|
2010-12-10 05:15:00 +03:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
if (hasResult) {
|
|
|
|
rv = GatherResultsFromStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
2011-11-03 05:57:48 +04:00
|
|
|
mKey = Key::UNSETKEY;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-01-27 04:53:02 +03:00
|
|
|
ContinueHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2011-01-07 09:21:36 +03:00
|
|
|
// Remove cached stuff from last time.
|
2011-11-03 05:57:48 +04:00
|
|
|
mCursor->mCachedKey = nsnull;
|
2011-11-03 05:03:15 +04:00
|
|
|
mCursor->mCachedValue = JSVAL_VOID;
|
2011-11-03 05:57:48 +04:00
|
|
|
mCursor->mCachedPrimaryKey = JSVAL_VOID;
|
2011-11-03 05:03:15 +04:00
|
|
|
mCursor->mHaveCachedValue = false;
|
2011-11-03 05:57:48 +04:00
|
|
|
mCursor->mHaveCachedPrimaryKey = false;
|
2011-01-07 09:21:36 +03:00
|
|
|
mCursor->mContinueCalled = false;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
if (mKey.IsUnset()) {
|
2011-01-07 09:21:36 +03:00
|
|
|
mCursor->mHaveValue = false;
|
2011-01-27 04:53:02 +03:00
|
|
|
*aVal = JSVAL_VOID;
|
2011-01-07 09:21:36 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-01-27 04:53:02 +03:00
|
|
|
NS_ASSERTION(mCursor->mType == IDBCursor::OBJECTSTORE ||
|
|
|
|
!mObjectKey.IsUnset(), "Bad key!");
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
// Set new values.
|
|
|
|
mCursor->mKey = mKey;
|
|
|
|
mCursor->mObjectKey = mObjectKey;
|
2011-11-03 05:57:48 +04:00
|
|
|
mCursor->mContinueToKey = Key::UNSETKEY;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-27 04:53:02 +03:00
|
|
|
mCursor->mCloneBuffer.swap(mCloneBuffer);
|
2011-07-12 21:42:24 +04:00
|
|
|
mCloneBuffer.clear();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-27 04:53:02 +03:00
|
|
|
nsresult rv = WrapNative(aCx, mCursor, aVal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
2010-09-10 08:54:25 +04:00
|
|
|
|
2011-01-27 04:53:02 +03:00
|
|
|
return NS_OK;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueObjectStoreHelper::BindArgumentsToStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Bind object store id.
|
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mCursor->mObjectStore->Id());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(currentKeyName, "current_key");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKeyName, "range_key");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// Bind current key.
|
|
|
|
const Key& currentKey = mCursor->mContinueToKey.IsUnset() ?
|
|
|
|
mCursor->mKey :
|
|
|
|
mCursor->mContinueToKey;
|
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
if (currentKey.IsString()) {
|
|
|
|
rv = aStatement->BindStringByName(currentKeyName, currentKey.StringValue());
|
|
|
|
}
|
|
|
|
else if (currentKey.IsInt()) {
|
|
|
|
rv = aStatement->BindInt64ByName(currentKeyName, currentKey.IntValue());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad key!");
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
// Bind range key if it is specified.
|
|
|
|
const Key& rangeKey = mCursor->mRangeKey;
|
|
|
|
|
|
|
|
if (!rangeKey.IsUnset()) {
|
2011-11-03 05:57:48 +04:00
|
|
|
if (rangeKey.IsString()) {
|
|
|
|
rv = aStatement->BindStringByName(rangeKeyName, rangeKey.StringValue());
|
|
|
|
}
|
|
|
|
else if (rangeKey.IsInt()) {
|
|
|
|
rv = aStatement->BindInt64ByName(rangeKeyName, rangeKey.IntValue());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad key!");
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueObjectStoreHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Figure out what kind of key we have next.
|
2011-11-03 05:57:48 +04:00
|
|
|
PRInt32 keyType;
|
|
|
|
nsresult rv = aStatement->GetTypeOfIndex(0, &keyType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
if (keyType == mozIStorageStatement::VALUE_TYPE_INTEGER) {
|
|
|
|
mKey = aStatement->AsInt64(0);
|
|
|
|
}
|
|
|
|
else if (keyType == mozIStorageStatement::VALUE_TYPE_TEXT) {
|
|
|
|
rv = aStatement->GetString(0, mKey.ToString());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad SQLite type!");
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-21 19:02:04 +03:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneDataFromStatement(aStatement, 1,
|
|
|
|
mCloneBuffer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueIndexHelper::BindArgumentsToStatement(mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Bind index id.
|
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mCursor->mIndex->Id());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(currentKeyName, "current_key");
|
|
|
|
|
|
|
|
// Bind current key.
|
|
|
|
const Key& currentKey = mCursor->mContinueToKey.IsUnset() ?
|
|
|
|
mCursor->mKey :
|
|
|
|
mCursor->mContinueToKey;
|
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
if (currentKey.IsString()) {
|
|
|
|
rv = aStatement->BindStringByName(currentKeyName, currentKey.StringValue());
|
|
|
|
}
|
|
|
|
else if (currentKey.IsInt()) {
|
|
|
|
rv = aStatement->BindInt64ByName(currentKeyName, currentKey.IntValue());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad key!");
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// Bind range key if it is specified.
|
|
|
|
if (!mCursor->mRangeKey.IsUnset()) {
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKeyName, "range_key");
|
2011-11-03 05:57:48 +04:00
|
|
|
if (mCursor->mRangeKey.IsString()) {
|
|
|
|
rv = aStatement->BindStringByName(rangeKeyName,
|
|
|
|
mCursor->mRangeKey.StringValue());
|
|
|
|
}
|
|
|
|
else if (mCursor->mRangeKey.IsInt()) {
|
|
|
|
rv = aStatement->BindInt64ByName(rangeKeyName,
|
|
|
|
mCursor->mRangeKey.IntValue());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad key!");
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// Bind object key if duplicates are allowed and we're not continuing to a
|
|
|
|
// specific key.
|
|
|
|
if ((mCursor->mDirection == nsIIDBCursor::NEXT ||
|
|
|
|
mCursor->mDirection == nsIIDBCursor::PREV) &&
|
|
|
|
mCursor->mContinueToKey.IsUnset()) {
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!mCursor->mObjectKey.IsUnset(), "Bad key!");
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(objectKeyName, "object_key");
|
2011-11-03 05:57:48 +04:00
|
|
|
if (mCursor->mObjectKey.IsString()) {
|
|
|
|
rv = aStatement->BindStringByName(objectKeyName,
|
|
|
|
mCursor->mObjectKey.StringValue());
|
|
|
|
}
|
|
|
|
else if (mCursor->mObjectKey.IsInt()) {
|
|
|
|
rv = aStatement->BindInt64ByName(objectKeyName,
|
|
|
|
mCursor->mObjectKey.IntValue());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad key!");
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueIndexHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
2011-11-03 05:57:48 +04:00
|
|
|
PRInt32 keyType;
|
|
|
|
nsresult rv = aStatement->GetTypeOfIndex(0, &keyType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
NS_ASSERTION(keyType == mozIStorageStatement::VALUE_TYPE_INTEGER ||
|
|
|
|
keyType == mozIStorageStatement::VALUE_TYPE_TEXT,
|
|
|
|
"Bad key type!");
|
|
|
|
|
|
|
|
if (keyType == mozIStorageStatement::VALUE_TYPE_INTEGER) {
|
|
|
|
mKey = aStatement->AsInt64(0);
|
|
|
|
}
|
|
|
|
else if (keyType == mozIStorageStatement::VALUE_TYPE_TEXT) {
|
|
|
|
rv = aStatement->GetString(0, mKey.ToString());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad SQLite type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aStatement->GetTypeOfIndex(1, &keyType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NS_ASSERTION(keyType == mozIStorageStatement::VALUE_TYPE_INTEGER ||
|
|
|
|
keyType == mozIStorageStatement::VALUE_TYPE_TEXT,
|
|
|
|
"Bad key type!");
|
|
|
|
|
|
|
|
if (keyType == mozIStorageStatement::VALUE_TYPE_INTEGER) {
|
|
|
|
mObjectKey = aStatement->AsInt64(1);
|
|
|
|
}
|
|
|
|
else if (keyType == mozIStorageStatement::VALUE_TYPE_TEXT) {
|
|
|
|
rv = aStatement->GetString(1, mObjectKey.ToString());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad SQLite type!");
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
nsresult
|
|
|
|
ContinueIndexObjectHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
2011-11-03 05:57:48 +04:00
|
|
|
PRInt32 keyType;
|
|
|
|
nsresult rv = aStatement->GetTypeOfIndex(0, &keyType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2011-11-03 05:57:48 +04:00
|
|
|
NS_ASSERTION(keyType == mozIStorageStatement::VALUE_TYPE_INTEGER ||
|
|
|
|
keyType == mozIStorageStatement::VALUE_TYPE_TEXT,
|
|
|
|
"Bad key type!");
|
|
|
|
|
|
|
|
if (keyType == mozIStorageStatement::VALUE_TYPE_INTEGER) {
|
|
|
|
mKey = aStatement->AsInt64(0);
|
|
|
|
}
|
|
|
|
else if (keyType == mozIStorageStatement::VALUE_TYPE_TEXT) {
|
|
|
|
rv = aStatement->GetString(0, mKey.ToString());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad SQLite type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aStatement->GetTypeOfIndex(1, &keyType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NS_ASSERTION(keyType == mozIStorageStatement::VALUE_TYPE_INTEGER ||
|
|
|
|
keyType == mozIStorageStatement::VALUE_TYPE_TEXT,
|
|
|
|
"Bad key type!");
|
|
|
|
|
|
|
|
if (keyType == mozIStorageStatement::VALUE_TYPE_INTEGER) {
|
|
|
|
mObjectKey = aStatement->AsInt64(1);
|
|
|
|
}
|
|
|
|
else if (keyType == mozIStorageStatement::VALUE_TYPE_TEXT) {
|
|
|
|
rv = aStatement->GetString(1, mObjectKey.ToString());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Bad SQLite type!");
|
|
|
|
}
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2010-12-21 19:02:04 +03:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneDataFromStatement(aStatement, 2,
|
|
|
|
mCloneBuffer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|