2010-06-23 12:46:08 -07: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):
|
|
|
|
* Shawn Wilsher <me@shawnwilsher.com>
|
2010-12-15 13:21:02 -08:00
|
|
|
* Ben Turner <bent.mozilla@gmail.com>
|
2010-06-23 12:46:08 -07:00
|
|
|
*
|
|
|
|
* 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 11:51:06 -07:00
|
|
|
#include "IDBIndex.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#include "nsIIDBKeyRange.h"
|
2010-12-21 08:02:04 -08:00
|
|
|
#include "nsIJSContextStack.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2010-11-10 15:26:03 -08:00
|
|
|
#include "nsEventDispatcher.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "mozilla/storage.h"
|
2011-12-24 00:27:04 -08:00
|
|
|
#include "xpcpublic.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBCursor.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "IDBEvents.h"
|
2011-11-03 08:57:30 -07:00
|
|
|
#include "IDBKeyRange.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-28 09:46:21 -07:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
|
|
|
|
USING_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
class GetKeyHelper : public AsyncConnectionHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-12-15 13:21:02 -08:00
|
|
|
GetKeyHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
2011-11-03 08:59:17 -07:00
|
|
|
IDBKeyRange* aKeyRange)
|
|
|
|
: AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex),
|
|
|
|
mKeyRange(aKeyRange)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-06 22:21:36 -08:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
mIndex = nsnull;
|
2011-11-03 08:59:17 -07:00
|
|
|
mKeyRange = nsnull;
|
2010-10-19 10:58:52 -07:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
protected:
|
|
|
|
// In-params.
|
2010-10-19 10:58:52 -07:00
|
|
|
nsRefPtr<IDBIndex> mIndex;
|
2011-11-03 08:59:17 -07:00
|
|
|
nsRefPtr<IDBKeyRange> mKeyRange;
|
|
|
|
|
|
|
|
// Out-params.
|
2010-06-23 12:46:08 -07:00
|
|
|
Key mKey;
|
|
|
|
};
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
class GetHelper : public GetKeyHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-12-15 13:21:02 -08:00
|
|
|
GetHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
2011-11-03 08:59:17 -07:00
|
|
|
IDBKeyRange* aKeyRange)
|
|
|
|
: GetKeyHelper(aTransaction, aRequest, aIndex, aKeyRange)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2011-01-26 17:53:02 -08:00
|
|
|
~GetHelper()
|
2010-12-21 08:02:04 -08:00
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(mCloneReadInfo.mCloneBuffer);
|
2010-12-21 08:02:04 -08:00
|
|
|
}
|
|
|
|
|
2011-01-26 17:53:02 -08:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(mCloneReadInfo.mCloneBuffer);
|
2011-11-03 08:59:17 -07:00
|
|
|
GetKeyHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
protected:
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo mCloneReadInfo;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
class GetAllKeysHelper : public GetKeyHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-12-15 13:21:02 -08:00
|
|
|
GetAllKeysHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
2011-11-03 08:59:17 -07:00
|
|
|
IDBKeyRange* aKeyRange,
|
2010-12-15 13:21:02 -08:00
|
|
|
const PRUint32 aLimit)
|
2011-11-03 08:59:17 -07:00
|
|
|
: GetKeyHelper(aTransaction, aRequest, aIndex, aKeyRange), mLimit(aLimit)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-06 22:21:36 -08:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const PRUint32 mLimit;
|
|
|
|
nsTArray<Key> mKeys;
|
|
|
|
};
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
class GetAllHelper : public GetKeyHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-12-15 13:21:02 -08:00
|
|
|
GetAllHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
2011-11-03 08:59:17 -07:00
|
|
|
IDBKeyRange* aKeyRange,
|
2010-12-15 13:21:02 -08:00
|
|
|
const PRUint32 aLimit)
|
2011-11-03 08:59:17 -07:00
|
|
|
: GetKeyHelper(aTransaction, aRequest, aIndex, aKeyRange), mLimit(aLimit)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2011-01-26 17:53:02 -08:00
|
|
|
~GetAllHelper()
|
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
|
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(
|
|
|
|
mCloneReadInfos[index].mCloneBuffer);
|
2011-01-26 17:53:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-06 22:21:36 -08:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-21 08:02:04 -08:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
|
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(
|
|
|
|
mCloneReadInfos[index].mCloneBuffer);
|
2011-11-03 08:59:17 -07:00
|
|
|
}
|
2010-12-21 08:02:04 -08:00
|
|
|
GetKeyHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
protected:
|
|
|
|
const PRUint32 mLimit;
|
2011-12-15 23:34:24 -08:00
|
|
|
nsTArray<StructuredCloneReadInfo> mCloneReadInfos;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
class OpenKeyCursorHelper : public AsyncConnectionHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-12-15 13:21:02 -08:00
|
|
|
OpenKeyCursorHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBKeyRange* aKeyRange,
|
2010-12-15 13:21:02 -08:00
|
|
|
PRUint16 aDirection)
|
2010-10-19 10:58:52 -07:00
|
|
|
: AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex),
|
2011-11-03 08:57:30 -07:00
|
|
|
mKeyRange(aKeyRange), mDirection(aDirection)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-06 22:21:36 -08:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 21:54:25 -07:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
mIndex = nsnull;
|
2011-11-03 08:57:30 -07:00
|
|
|
mKeyRange = nsnull;
|
2010-09-09 21:54:25 -07:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
private:
|
|
|
|
// In-params.
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBIndex> mIndex;
|
2011-11-03 08:57:30 -07:00
|
|
|
nsRefPtr<IDBKeyRange> mKeyRange;
|
2010-06-23 12:46:08 -07:00
|
|
|
const PRUint16 mDirection;
|
|
|
|
|
|
|
|
// Out-params.
|
2010-12-09 18:15:00 -08:00
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
|
|
|
nsCString mContinueQuery;
|
|
|
|
nsCString mContinueToQuery;
|
|
|
|
Key mRangeKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
class OpenCursorHelper : public AsyncConnectionHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-12-15 13:21:02 -08:00
|
|
|
OpenCursorHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBKeyRange* aKeyRange,
|
2010-12-15 13:21:02 -08:00
|
|
|
PRUint16 aDirection)
|
2010-10-19 10:58:52 -07:00
|
|
|
: AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex),
|
2011-11-03 08:57:30 -07:00
|
|
|
mKeyRange(aKeyRange), mDirection(aDirection)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2011-01-26 17:53:02 -08:00
|
|
|
~OpenCursorHelper()
|
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
IDBObjectStore::ClearStructuredCloneBuffer(mCloneReadInfo.mCloneBuffer);
|
2011-01-26 17:53:02 -08:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-06 22:21:36 -08:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 21:54:25 -07:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
mIndex = nsnull;
|
2011-11-03 08:57:30 -07:00
|
|
|
mKeyRange = nsnull;
|
2010-09-09 21:54:25 -07:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
private:
|
|
|
|
// In-params.
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBIndex> mIndex;
|
2011-11-03 08:57:30 -07:00
|
|
|
nsRefPtr<IDBKeyRange> mKeyRange;
|
2010-06-23 12:46:08 -07:00
|
|
|
const PRUint16 mDirection;
|
|
|
|
|
|
|
|
// Out-params.
|
2010-12-09 18:15:00 -08:00
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo mCloneReadInfo;
|
2010-12-09 18:15:00 -08:00
|
|
|
nsCString mContinueQuery;
|
|
|
|
nsCString mContinueToQuery;
|
|
|
|
Key mRangeKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2011-11-03 08:57:42 -07:00
|
|
|
class CountHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CountHelper(IDBTransaction* aTransaction,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
|
|
|
IDBKeyRange* aKeyRange)
|
|
|
|
: AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex),
|
|
|
|
mKeyRange(aKeyRange), mCount(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
|
|
|
|
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
mIndex = nsnull;
|
|
|
|
mKeyRange = nsnull;
|
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<IDBIndex> mIndex;
|
|
|
|
nsRefPtr<IDBKeyRange> mKeyRange;
|
|
|
|
PRUint64 mCount;
|
|
|
|
};
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
inline
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GenerateRequest(IDBIndex* aIndex)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-11-10 15:26:03 -08:00
|
|
|
IDBTransaction* transaction = aIndex->ObjectStore()->Transaction();
|
|
|
|
IDBDatabase* database = transaction->Database();
|
|
|
|
return IDBRequest::Create(aIndex, database->ScriptContext(),
|
|
|
|
database->Owner(), transaction);
|
2010-09-09 15:15:38 -07:00
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBIndex>
|
|
|
|
IDBIndex::Create(IDBObjectStore* aObjectStore,
|
|
|
|
const IndexInfo* aIndexInfo)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
|
|
|
NS_ASSERTION(aIndexInfo, "Null pointer!");
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
IDBDatabase* database = aObjectStore->Transaction()->Database();
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBIndex> index = new IDBIndex();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
index->mScriptContext = database->ScriptContext();
|
|
|
|
index->mOwner = database->Owner();
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
index->mObjectStore = aObjectStore;
|
|
|
|
index->mId = aIndexInfo->id;
|
|
|
|
index->mName = aIndexInfo->name;
|
|
|
|
index->mKeyPath = aIndexInfo->keyPath;
|
2011-12-20 02:59:07 -08:00
|
|
|
index->mKeyPathArray = aIndexInfo->keyPathArray;
|
2010-06-23 12:46:08 -07:00
|
|
|
index->mUnique = aIndexInfo->unique;
|
2011-12-04 09:39:01 -08:00
|
|
|
index->mMultiEntry = aIndexInfo->multiEntry;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return index.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBIndex::IDBIndex()
|
2010-06-23 12:46:08 -07:00
|
|
|
: mId(LL_MININT),
|
2011-12-16 16:40:47 -08:00
|
|
|
mUnique(false)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBIndex::~IDBIndex()
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBIndex)
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBIndex)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mObjectStore)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptContext)
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBIndex)
|
2010-09-09 15:15:38 -07:00
|
|
|
// Don't unlink mObjectStore!
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mScriptContext)
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBIndex)
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIDBIndex)
|
2010-06-28 11:51:06 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBIndex)
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBIndex)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBIndex)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
DOMCI_DATA(IDBIndex, IDBIndex)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBIndex::GetName(nsAString& aName)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
aName.Assign(mName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBIndex::GetStoreName(nsAString& aStoreName)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return mObjectStore->GetName(aStoreName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-20 02:59:07 -08:00
|
|
|
IDBIndex::GetKeyPath(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-20 02:59:07 -08:00
|
|
|
if (UsesKeyPathArray()) {
|
|
|
|
JSObject* array = JS_NewArrayObject(aCx, mKeyPathArray.Length(), nsnull);
|
|
|
|
if (!array) {
|
|
|
|
NS_WARNING("Failed to make array!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mKeyPathArray.Length(); ++i) {
|
|
|
|
jsval val;
|
|
|
|
nsString tmp(mKeyPathArray[i]);
|
2011-12-24 00:27:04 -08:00
|
|
|
if (!xpc::StringToJsval(aCx, tmp, &val)) {
|
2011-12-20 02:59:07 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_SetElement(aCx, array, i, &val)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aVal = OBJECT_TO_JSVAL(array);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsString tmp(mKeyPath);
|
2011-12-24 00:27:04 -08:00
|
|
|
if (!xpc::StringToJsval(aCx, tmp, aVal)) {
|
2011-12-20 02:59:07 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
IDBIndex::GetUnique(bool* aUnique)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
*aUnique = mUnique;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-04 09:39:01 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBIndex::GetMultiEntry(bool* aMultiEntry)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
*aMultiEntry = mMultiEntry;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-09 18:14:09 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBIndex::GetObjectStore(nsIIDBObjectStore** aObjectStore)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIDBObjectStore> objectStore(mObjectStore);
|
|
|
|
objectStore.forget(aObjectStore);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBIndex::Get(const jsval& aKey,
|
|
|
|
JSContext* aCx,
|
2010-06-28 11:51:06 -07:00
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!transaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
2010-11-10 15:25:44 -08:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
nsresult rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!keyRange) {
|
|
|
|
// Must specify a key or keyRange for get().
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
2010-12-15 13:21:07 -08:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
nsRefPtr<GetHelper> helper =
|
2011-11-03 08:59:17 -07:00
|
|
|
new GetHelper(transaction, request, this, keyRange);
|
2010-06-23 12:46:08 -07:00
|
|
|
rv = helper->DispatchToTransactionPool();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBIndex::GetKey(const jsval& aKey,
|
|
|
|
JSContext* aCx,
|
2010-12-15 13:21:02 -08:00
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!transaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
2010-11-10 15:25:44 -08:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
nsresult rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!keyRange) {
|
|
|
|
// Must specify a key or keyRange for get().
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
2010-12-15 13:21:07 -08:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
nsRefPtr<GetKeyHelper> helper =
|
2011-11-03 08:59:17 -07:00
|
|
|
new GetKeyHelper(transaction, request, this, keyRange);
|
2010-11-10 15:25:44 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
rv = helper->DispatchToTransactionPool();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBIndex::GetAll(const jsval& aKey,
|
2010-06-28 11:51:06 -07:00
|
|
|
PRUint32 aLimit,
|
2011-11-03 08:57:30 -07:00
|
|
|
JSContext* aCx,
|
2010-06-28 11:51:06 -07:00
|
|
|
PRUint8 aOptionalArgCount,
|
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!transaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
2010-11-10 15:25:44 -08:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
if (aOptionalArgCount) {
|
|
|
|
rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptionalArgCount < 2) {
|
|
|
|
aLimit = PR_UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsRefPtr<GetAllHelper> helper =
|
2011-11-03 08:59:17 -07:00
|
|
|
new GetAllHelper(transaction, request, this, keyRange, aLimit);
|
2010-11-10 15:25:44 -08:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
rv = helper->DispatchToTransactionPool();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBIndex::GetAllKeys(const jsval& aKey,
|
2010-12-15 13:21:02 -08:00
|
|
|
PRUint32 aLimit,
|
2011-11-03 08:57:30 -07:00
|
|
|
JSContext* aCx,
|
2010-12-15 13:21:02 -08:00
|
|
|
PRUint8 aOptionalArgCount,
|
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!transaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
2010-11-10 15:25:44 -08:00
|
|
|
}
|
|
|
|
|
2010-12-15 13:21:07 -08:00
|
|
|
nsresult rv;
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
if (aOptionalArgCount) {
|
|
|
|
rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptionalArgCount < 2) {
|
|
|
|
aLimit = PR_UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
nsRefPtr<GetAllKeysHelper> helper =
|
2011-11-03 08:59:17 -07:00
|
|
|
new GetAllKeysHelper(transaction, request, this, keyRange, aLimit);
|
2010-11-10 15:25:44 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
rv = helper->DispatchToTransactionPool();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBIndex::OpenCursor(const jsval& aKey,
|
2010-06-28 11:51:06 -07:00
|
|
|
PRUint16 aDirection,
|
2011-11-03 08:57:30 -07:00
|
|
|
JSContext* aCx,
|
2010-06-28 11:51:06 -07:00
|
|
|
PRUint8 aOptionalArgCount,
|
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!transaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
if (aOptionalArgCount) {
|
|
|
|
rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-02 18:57:48 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (aOptionalArgCount >= 2) {
|
|
|
|
if (aDirection != nsIIDBCursor::NEXT &&
|
|
|
|
aDirection != nsIIDBCursor::NEXT_NO_DUPLICATE &&
|
|
|
|
aDirection != nsIIDBCursor::PREV &&
|
|
|
|
aDirection != nsIIDBCursor::PREV_NO_DUPLICATE) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR;
|
|
|
|
}
|
2011-11-02 18:57:48 -07:00
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
else {
|
|
|
|
aDirection = nsIIDBCursor::NEXT;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsRefPtr<OpenCursorHelper> helper =
|
2011-11-03 08:57:30 -07:00
|
|
|
new OpenCursorHelper(transaction, request, this, keyRange, aDirection);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
rv = helper->DispatchToTransactionPool();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBIndex::OpenKeyCursor(const jsval& aKey,
|
2010-12-15 13:21:02 -08:00
|
|
|
PRUint16 aDirection,
|
2011-11-03 08:57:30 -07:00
|
|
|
JSContext* aCx,
|
2010-12-15 13:21:02 -08:00
|
|
|
PRUint8 aOptionalArgCount,
|
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!transaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
if (aOptionalArgCount) {
|
|
|
|
rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (aOptionalArgCount >= 2) {
|
|
|
|
if (aDirection != nsIIDBCursor::NEXT &&
|
|
|
|
aDirection != nsIIDBCursor::NEXT_NO_DUPLICATE &&
|
|
|
|
aDirection != nsIIDBCursor::PREV &&
|
|
|
|
aDirection != nsIIDBCursor::PREV_NO_DUPLICATE) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR;
|
|
|
|
}
|
2011-11-02 18:57:48 -07:00
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
else {
|
|
|
|
aDirection = nsIIDBCursor::NEXT;
|
2011-11-02 18:57:48 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-02 18:03:47 -07:00
|
|
|
|
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2011-11-02 18:57:48 -07:00
|
|
|
nsRefPtr<OpenKeyCursorHelper> helper =
|
2011-11-03 08:57:30 -07:00
|
|
|
new OpenKeyCursorHelper(transaction, request, this, keyRange, aDirection);
|
2011-11-02 18:57:48 -07:00
|
|
|
|
2011-11-02 18:03:47 -07:00
|
|
|
rv = helper->DispatchToTransactionPool();
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
2011-11-02 18:03:15 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBIndex::Count(const jsval& aKey,
|
|
|
|
JSContext* aCx,
|
|
|
|
PRUint8 aOptionalArgCount,
|
|
|
|
nsIIDBRequest** _retval)
|
|
|
|
{
|
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
2011-11-03 08:57:42 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
if (aOptionalArgCount) {
|
|
|
|
rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
nsRefPtr<CountHelper> helper =
|
|
|
|
new CountHelper(transaction, request, this, keyRange);
|
|
|
|
rv = helper->DispatchToTransactionPool();
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-11-03 08:59:17 -07:00
|
|
|
GetKeyHelper::DoDatabaseWork(mozIStorageConnection* /* aConnection */)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:59:17 -07:00
|
|
|
NS_ASSERTION(mKeyRange, "Must have a key range here!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsCString indexTable;
|
2011-12-16 16:40:47 -08:00
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
indexTable.AssignLiteral("unique_index_data");
|
2011-11-03 08:59:17 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
indexTable.AssignLiteral("index_data");
|
2011-11-03 08:59:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCString keyRangeClause;
|
|
|
|
mKeyRange->GetBindingClause(NS_LITERAL_CSTRING("value"), keyRangeClause);
|
|
|
|
|
|
|
|
NS_ASSERTION(!keyRangeClause.IsEmpty(), "Huh?!");
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString query = NS_LITERAL_CSTRING("SELECT object_data_key FROM ") +
|
|
|
|
indexTable +
|
|
|
|
NS_LITERAL_CSTRING(" WHERE index_id = :index_id") +
|
|
|
|
keyRangeClause +
|
2011-11-03 08:59:17 -07:00
|
|
|
NS_LITERAL_CSTRING(" LIMIT 1");
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
|
|
|
|
mIndex->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
rv = mKeyRange->BindToStatement(stmt);
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-06-23 12:46:08 -07:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
if (hasResult) {
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mKey.SetFromStatement(stmt, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-01-06 22:21:36 -08:00
|
|
|
GetKeyHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
return mKey.ToJSVal(aCx, aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-11-03 08:59:17 -07:00
|
|
|
GetHelper::DoDatabaseWork(mozIStorageConnection* /* aConnection */)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:59:17 -07:00
|
|
|
NS_ASSERTION(mKeyRange, "Must have a key range here!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString indexTable;
|
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
indexTable.AssignLiteral("unique_index_data");
|
2011-11-03 08:59:17 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
indexTable.AssignLiteral("index_data");
|
2011-11-03 08:59:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCString keyRangeClause;
|
|
|
|
mKeyRange->GetBindingClause(NS_LITERAL_CSTRING("value"), keyRangeClause);
|
|
|
|
|
|
|
|
NS_ASSERTION(!keyRangeClause.IsEmpty(), "Huh?!");
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString query = NS_LITERAL_CSTRING("SELECT data, file_ids FROM object_data "
|
|
|
|
"INNER JOIN ") + indexTable +
|
|
|
|
NS_LITERAL_CSTRING(" AS index_table ON object_data.id = ") +
|
|
|
|
NS_LITERAL_CSTRING("index_table.object_data_id WHERE "
|
|
|
|
"index_id = :index_id") +
|
|
|
|
keyRangeClause +
|
2011-11-03 08:59:17 -07:00
|
|
|
NS_LITERAL_CSTRING(" LIMIT 1");
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
|
|
|
|
mIndex->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
rv = mKeyRange->BindToStatement(stmt);
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-06-23 12:46:08 -07:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
if (hasResult) {
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(stmt, 0, 1,
|
|
|
|
mDatabase->Manager(), mCloneReadInfo);
|
2010-12-21 08:02:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-01-06 22:21:36 -08:00
|
|
|
GetHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
bool result = IDBObjectStore::DeserializeValue(aCx, mCloneReadInfo, aVal);
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
mCloneReadInfo.mCloneBuffer.clear();
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2011-06-08 19:21:53 -07:00
|
|
|
NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
|
2011-01-26 17:53:02 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-11-03 08:59:17 -07:00
|
|
|
GetAllKeysHelper::DoDatabaseWork(mozIStorageConnection* /* aConnection */)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
nsCString tableName;
|
2011-12-16 16:40:47 -08:00
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
tableName.AssignLiteral("unique_index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
tableName.AssignLiteral("index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsCString keyRangeClause;
|
|
|
|
if (mKeyRange) {
|
|
|
|
mKeyRange->GetBindingClause(NS_LITERAL_CSTRING("value"), keyRangeClause);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCString limitClause;
|
|
|
|
if (mLimit != PR_UINT32_MAX) {
|
|
|
|
limitClause = NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
limitClause.AppendInt(mLimit);
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString query = NS_LITERAL_CSTRING("SELECT object_data_key FROM ") +
|
|
|
|
tableName +
|
|
|
|
NS_LITERAL_CSTRING(" WHERE index_id = :index_id") +
|
|
|
|
keyRangeClause + limitClause;
|
2011-11-03 08:59:17 -07:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
|
|
|
|
mIndex->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
if (mKeyRange) {
|
|
|
|
rv = mKeyRange->BindToStatement(stmt);
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
mKeys.SetCapacity(50);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-06-23 12:46:08 -07:00
|
|
|
while(NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
|
|
|
|
if (mKeys.Capacity() == mKeys.Length()) {
|
2011-11-03 08:57:30 -07:00
|
|
|
mKeys.SetCapacity(mKeys.Capacity() * 2);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Key* key = mKeys.AppendElement();
|
|
|
|
NS_ASSERTION(key, "This shouldn't fail!");
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = key->SetFromStatement(stmt, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-01-06 22:21:36 -08:00
|
|
|
GetAllKeysHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-01-06 22:21:36 -08:00
|
|
|
NS_ASSERTION(mKeys.Length() <= mLimit, "Too many results!");
|
|
|
|
|
|
|
|
nsTArray<Key> keys;
|
|
|
|
if (!mKeys.SwapElements(keys)) {
|
|
|
|
NS_ERROR("Failed to swap elements!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
JSObject* array = JS_NewArrayObject(aCx, 0, NULL);
|
|
|
|
if (!array) {
|
|
|
|
NS_WARNING("Failed to make array!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
if (!keys.IsEmpty()) {
|
|
|
|
if (!JS_SetArrayLength(aCx, array, jsuint(keys.Length()))) {
|
|
|
|
NS_WARNING("Failed to set array length!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2011-08-04 19:39:13 -07:00
|
|
|
for (uint32 index = 0, count = keys.Length(); index < count; index++) {
|
2011-01-06 22:21:36 -08:00
|
|
|
const Key& key = keys[index];
|
|
|
|
NS_ASSERTION(!key.IsUnset(), "Bad key!");
|
|
|
|
|
|
|
|
jsval value;
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = key.ToJSVal(aCx, &value);
|
2011-01-06 22:21:36 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to get jsval for key!");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_SetElement(aCx, array, index, &value)) {
|
|
|
|
NS_WARNING("Failed to set array element!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aVal = OBJECT_TO_JSVAL(array);
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-11-03 08:59:17 -07:00
|
|
|
GetAllHelper::DoDatabaseWork(mozIStorageConnection* /* aConnection */)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString indexTable;
|
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
indexTable.AssignLiteral("unique_index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
indexTable.AssignLiteral("index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsCString keyRangeClause;
|
|
|
|
if (mKeyRange) {
|
|
|
|
mKeyRange->GetBindingClause(NS_LITERAL_CSTRING("value"), keyRangeClause);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCString limitClause;
|
|
|
|
if (mLimit != PR_UINT32_MAX) {
|
|
|
|
limitClause = NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
limitClause.AppendInt(mLimit);
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString query = NS_LITERAL_CSTRING("SELECT data, file_ids FROM object_data "
|
|
|
|
"INNER JOIN ") + indexTable +
|
|
|
|
NS_LITERAL_CSTRING(" AS index_table ON object_data.id = "
|
|
|
|
"index_table.object_data_id "
|
|
|
|
"WHERE index_id = :index_id") +
|
|
|
|
keyRangeClause + limitClause;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
|
|
|
|
mIndex->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
if (mKeyRange) {
|
|
|
|
rv = mKeyRange->BindToStatement(stmt);
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
mCloneReadInfos.SetCapacity(50);
|
2011-11-03 08:59:17 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-06-23 12:46:08 -07:00
|
|
|
while(NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
|
2011-12-15 23:34:24 -08:00
|
|
|
if (mCloneReadInfos.Capacity() == mCloneReadInfos.Length()) {
|
|
|
|
mCloneReadInfos.SetCapacity(mCloneReadInfos.Capacity() * 2);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo* readInfo = mCloneReadInfos.AppendElement();
|
|
|
|
NS_ASSERTION(readInfo, "This shouldn't fail!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(stmt, 0, 1,
|
|
|
|
mDatabase->Manager(), *readInfo);
|
2010-12-21 08:02:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-01-06 22:21:36 -08:00
|
|
|
GetAllHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ASSERTION(mCloneReadInfos.Length() <= mLimit, "Too many results!");
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
nsresult rv = ConvertCloneReadInfosToArray(aCx, mCloneReadInfos, aVal);
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
|
|
|
|
mCloneReadInfos[index].mCloneBuffer.clear();
|
2011-01-26 17:53:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2010-12-15 13:21:02 -08:00
|
|
|
OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aConnection, "Passed a null connection!");
|
|
|
|
|
|
|
|
nsCString table;
|
2011-12-16 16:40:47 -08:00
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
table.AssignLiteral("unique_index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
table.AssignLiteral("index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_NAMED_LITERAL_CSTRING(value, "value");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsCString keyRangeClause;
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange) {
|
2011-11-03 08:59:17 -07:00
|
|
|
mKeyRange->GetBindingClause(value, keyRangeClause);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCAutoString directionClause(" ORDER BY value ");
|
2010-06-23 12:46:08 -07:00
|
|
|
switch (mDirection) {
|
|
|
|
case nsIIDBCursor::NEXT:
|
|
|
|
case nsIIDBCursor::NEXT_NO_DUPLICATE:
|
2011-12-16 16:40:47 -08:00
|
|
|
directionClause += NS_LITERAL_CSTRING("ASC, object_data_key ASC");
|
2010-06-23 12:46:08 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::PREV:
|
2011-12-16 16:40:47 -08:00
|
|
|
directionClause += NS_LITERAL_CSTRING("DESC, object_data_key DESC");
|
2011-11-07 23:34:59 -08:00
|
|
|
break;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
case nsIIDBCursor::PREV_NO_DUPLICATE:
|
2011-12-16 16:40:47 -08:00
|
|
|
directionClause += NS_LITERAL_CSTRING("DESC, object_data_key ASC");
|
2010-06-23 12:46:08 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction!");
|
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString firstQuery = NS_LITERAL_CSTRING("SELECT value, object_data_key "
|
|
|
|
"FROM ") + table +
|
|
|
|
NS_LITERAL_CSTRING(" WHERE index_id = :index_id") +
|
2010-12-09 18:15:00 -08:00
|
|
|
keyRangeClause + directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT 1");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
|
|
|
mTransaction->GetCachedStatement(firstQuery);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
|
|
|
|
mIndex->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange) {
|
2011-11-03 08:59:17 -07:00
|
|
|
rv = mKeyRange->BindToStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-12-09 18:15:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
if (!hasResult) {
|
2011-11-03 08:57:30 -07:00
|
|
|
mKey.Unset();
|
2010-12-09 18:15:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mKey.SetFromStatement(stmt, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-02 18:57:48 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mObjectKey.SetFromStatement(stmt, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// Now we need to make the query to get the next match.
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCAutoString queryStart = NS_LITERAL_CSTRING("SELECT value, object_data_key"
|
|
|
|
" FROM ") + table +
|
|
|
|
NS_LITERAL_CSTRING(" WHERE index_id = :id");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKey, "range_key");
|
|
|
|
|
|
|
|
switch (mDirection) {
|
|
|
|
case nsIIDBCursor::NEXT:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Upper().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Upper();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND value >= :current_key AND "
|
|
|
|
"( value > :current_key OR "
|
|
|
|
" object_data_key > :object_key )") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND value >= :current_key ") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::NEXT_NO_DUPLICATE:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Upper().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Upper();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart + NS_LITERAL_CSTRING(" AND value > :current_key") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart + NS_LITERAL_CSTRING(" AND value >= :current_key") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::PREV:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Lower().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Lower();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-11-21 20:18:25 -08:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND value <= :current_key AND "
|
|
|
|
"( value < :current_key OR "
|
|
|
|
" object_data_key < :object_key )") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND value <= :current_key ") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::PREV_NO_DUPLICATE:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Lower().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Lower();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND value < :current_key") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND value <= :current_key") +
|
|
|
|
directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT ");
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction type!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-01-06 22:21:36 -08:00
|
|
|
OpenKeyCursorHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2010-12-09 18:15:00 -08:00
|
|
|
if (mKey.IsUnset()) {
|
2011-01-06 22:21:36 -08:00
|
|
|
*aVal = JSVAL_VOID;
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBCursor::Create(mRequest, mTransaction, mIndex, mDirection, mRangeKey,
|
|
|
|
mContinueQuery, mContinueToQuery, mKey, mObjectKey);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(cursor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
return WrapNative(aCx, cursor, aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2010-12-15 13:21:02 -08:00
|
|
|
OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aConnection, "Passed a null connection!");
|
|
|
|
|
|
|
|
nsCString indexTable;
|
2011-12-16 16:40:47 -08:00
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
indexTable.AssignLiteral("unique_index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
indexTable.AssignLiteral("index_data");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
NS_NAMED_LITERAL_CSTRING(value, "index_table.value");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:59:17 -07:00
|
|
|
nsCString keyRangeClause;
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange) {
|
2011-11-03 08:59:17 -07:00
|
|
|
mKeyRange->GetBindingClause(value, keyRangeClause);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCAutoString directionClause(" ORDER BY index_table.value ");
|
2010-06-23 12:46:08 -07:00
|
|
|
switch (mDirection) {
|
|
|
|
case nsIIDBCursor::NEXT:
|
|
|
|
case nsIIDBCursor::NEXT_NO_DUPLICATE:
|
2011-12-16 16:40:47 -08:00
|
|
|
directionClause +=
|
|
|
|
NS_LITERAL_CSTRING("ASC, index_table.object_data_key ASC");
|
2010-06-23 12:46:08 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::PREV:
|
2011-12-16 16:40:47 -08:00
|
|
|
directionClause +=
|
|
|
|
NS_LITERAL_CSTRING("DESC, index_table.object_data_key DESC");
|
2011-11-07 23:34:59 -08:00
|
|
|
break;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
case nsIIDBCursor::PREV_NO_DUPLICATE:
|
2011-12-16 16:40:47 -08:00
|
|
|
directionClause +=
|
|
|
|
NS_LITERAL_CSTRING("DESC, index_table.object_data_key ASC");
|
2010-06-23 12:46:08 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction!");
|
|
|
|
}
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString firstQuery =
|
|
|
|
NS_LITERAL_CSTRING("SELECT index_table.value, "
|
|
|
|
"index_table.object_data_key, object_data.data, "
|
|
|
|
"object_data.file_ids FROM ") +
|
|
|
|
indexTable +
|
|
|
|
NS_LITERAL_CSTRING(" AS index_table INNER JOIN object_data ON "
|
|
|
|
"index_table.object_data_id = object_data.id "
|
|
|
|
"WHERE index_table.index_id = :id") +
|
|
|
|
keyRangeClause + directionClause +
|
|
|
|
NS_LITERAL_CSTRING(" LIMIT 1");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
|
|
|
mTransaction->GetCachedStatement(firstQuery);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"), mIndex->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange) {
|
2011-11-03 08:59:17 -07:00
|
|
|
rv = mKeyRange->BindToStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-12-09 18:15:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
if (!hasResult) {
|
2011-11-03 08:57:30 -07:00
|
|
|
mKey.Unset();
|
2010-12-09 18:15:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mKey.SetFromStatement(stmt, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-02 18:57:48 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mObjectKey.SetFromStatement(stmt, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(stmt, 2, 3,
|
|
|
|
mDatabase->Manager(), mCloneReadInfo);
|
2010-12-21 08:02:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// Now we need to make the query to get the next match.
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCAutoString queryStart =
|
|
|
|
NS_LITERAL_CSTRING("SELECT index_table.value, "
|
|
|
|
"index_table.object_data_key, object_data.data, "
|
|
|
|
"object_data.file_ids FROM ") +
|
|
|
|
indexTable +
|
|
|
|
NS_LITERAL_CSTRING(" AS index_table INNER JOIN object_data ON "
|
|
|
|
"index_table.object_data_id = object_data.id "
|
|
|
|
"WHERE index_table.index_id = :id");
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKey, "range_key");
|
2011-12-16 16:40:47 -08:00
|
|
|
|
2011-11-21 20:18:25 -08:00
|
|
|
NS_NAMED_LITERAL_CSTRING(limit, " LIMIT ");
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
switch (mDirection) {
|
|
|
|
case nsIIDBCursor::NEXT:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Upper().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Upper();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value >= :current_key AND "
|
|
|
|
"( index_table.value > :current_key OR "
|
|
|
|
" index_table.object_data_key > :object_key ) ") +
|
|
|
|
directionClause + limit;
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value >= :current_key") +
|
|
|
|
directionClause + limit;
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::NEXT_NO_DUPLICATE:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Upper().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Upper();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value > :current_key") +
|
|
|
|
directionClause + limit;
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value >= :current_key") +
|
|
|
|
directionClause + limit;
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::PREV:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Lower().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Lower();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value <= :current_key AND "
|
|
|
|
"( index_table.value < :current_key OR "
|
|
|
|
" index_table.object_data_key < :object_key ) ") +
|
|
|
|
directionClause + limit;
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value <= :current_key") +
|
|
|
|
directionClause + limit;
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIIDBCursor::PREV_NO_DUPLICATE:
|
2011-11-03 08:57:30 -07:00
|
|
|
if (mKeyRange && !mKeyRange->Lower().IsUnset()) {
|
|
|
|
AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(),
|
|
|
|
queryStart);
|
|
|
|
mRangeKey = mKeyRange->Lower();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2011-12-16 16:40:47 -08:00
|
|
|
mContinueQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value < :current_key") +
|
|
|
|
directionClause + limit;
|
|
|
|
mContinueToQuery =
|
|
|
|
queryStart +
|
|
|
|
NS_LITERAL_CSTRING(" AND index_table.value <= :current_key") +
|
|
|
|
directionClause + limit;
|
2010-12-09 18:15:00 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction type!");
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2011-01-06 22:21:36 -08:00
|
|
|
OpenCursorHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2010-12-09 18:15:00 -08:00
|
|
|
if (mKey.IsUnset()) {
|
2011-01-06 22:21:36 -08:00
|
|
|
*aVal = JSVAL_VOID;
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBCursor::Create(mRequest, mTransaction, mIndex, mDirection, mRangeKey,
|
|
|
|
mContinueQuery, mContinueToQuery, mKey, mObjectKey,
|
2011-12-15 23:34:24 -08:00
|
|
|
mCloneReadInfo);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(cursor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ASSERTION(!mCloneReadInfo.mCloneBuffer.data(), "Should have swapped!");
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
return WrapNative(aCx, cursor, aVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2011-11-03 08:57:42 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
CountHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
|
|
|
nsCString table;
|
2011-12-16 16:40:47 -08:00
|
|
|
if (mIndex->IsUnique()) {
|
|
|
|
table.AssignLiteral("unique_index_data");
|
2011-11-03 08:57:42 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-12-16 16:40:47 -08:00
|
|
|
table.AssignLiteral("index_data");
|
2011-11-03 08:57:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(lowerKeyName, "lower_key");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(upperKeyName, "upper_key");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(value, "value");
|
|
|
|
|
|
|
|
nsCAutoString keyRangeClause;
|
|
|
|
if (mKeyRange) {
|
|
|
|
if (!mKeyRange->Lower().IsUnset()) {
|
|
|
|
AppendConditionClause(value, lowerKeyName, false,
|
|
|
|
!mKeyRange->IsLowerOpen(), keyRangeClause);
|
|
|
|
}
|
|
|
|
if (!mKeyRange->Upper().IsUnset()) {
|
|
|
|
AppendConditionClause(value, upperKeyName, true,
|
|
|
|
!mKeyRange->IsUpperOpen(), keyRangeClause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString query = NS_LITERAL_CSTRING("SELECT count(*) FROM ") + table +
|
2011-12-16 16:40:47 -08:00
|
|
|
NS_LITERAL_CSTRING(" WHERE index_id = :id") +
|
2011-11-03 08:57:42 -07:00
|
|
|
keyRangeClause;
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"), mIndex->Id());
|
2011-11-03 08:57:42 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
if (mKeyRange) {
|
|
|
|
if (!mKeyRange->Lower().IsUnset()) {
|
|
|
|
rv = mKeyRange->Lower().BindToStatement(stmt, lowerKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
if (!mKeyRange->Upper().IsUnset()) {
|
|
|
|
rv = mKeyRange->Upper().BindToStatement(stmt, upperKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mCount = stmt->AsInt64(0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CountHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
|
|
|
{
|
|
|
|
return JS_NewNumberValue(aCx, static_cast<jsdouble>(mCount), aVal);
|
|
|
|
}
|