2009-06-17 12:12:51 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-17 12:12:51 -07:00
|
|
|
|
2010-06-01 05:38:00 -07:00
|
|
|
#ifndef mozStorageBindingParams_h
|
|
|
|
#define mozStorageBindingParams_h
|
2009-06-17 12:12:51 -07:00
|
|
|
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsIVariant.h"
|
2010-08-27 12:42:58 -07:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2009-06-17 12:12:51 -07:00
|
|
|
|
|
|
|
#include "mozStorageBindingParamsArray.h"
|
|
|
|
#include "mozStorageStatement.h"
|
2010-03-24 00:32:40 -07:00
|
|
|
#include "mozStorageAsyncStatement.h"
|
2015-03-12 09:55:56 -07:00
|
|
|
#include "Variant.h"
|
2009-06-17 12:12:51 -07:00
|
|
|
|
2010-03-24 00:32:40 -07:00
|
|
|
#include "mozIStorageBindingParams.h"
|
|
|
|
#include "IStorageBindingParamsInternal.h"
|
2009-06-17 12:12:51 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
|
|
|
|
class BindingParams : public mozIStorageBindingParams
|
2010-03-24 00:32:40 -07:00
|
|
|
, public IStorageBindingParamsInternal
|
2009-06-17 12:12:51 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-06-17 12:12:51 -07:00
|
|
|
NS_DECL_MOZISTORAGEBINDINGPARAMS
|
2010-03-24 00:32:40 -07:00
|
|
|
NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL
|
2009-06-17 12:12:51 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locks the parameters and prevents further modification to it (such as
|
|
|
|
* binding more elements to it).
|
|
|
|
*/
|
|
|
|
void lock();
|
|
|
|
|
2009-07-28 10:21:03 -07:00
|
|
|
/**
|
|
|
|
* Unlocks the parameters and allows modification to it again.
|
2010-03-24 00:32:40 -07:00
|
|
|
*
|
|
|
|
* @param aOwningStatement
|
|
|
|
* The statement that owns us. We cleared this when we were locked,
|
|
|
|
* and our invariant requires us to have this, so you need to tell us
|
|
|
|
* again.
|
2009-07-28 10:21:03 -07:00
|
|
|
*/
|
2010-03-24 00:32:40 -07:00
|
|
|
void unlock(Statement *aOwningStatement);
|
2009-06-17 12:12:51 -07:00
|
|
|
|
|
|
|
/**
|
2010-03-24 00:32:40 -07:00
|
|
|
* @returns the pointer to the owning BindingParamsArray. Used by a
|
|
|
|
* BindingParamsArray to verify that we belong to it when added.
|
2009-06-17 12:12:51 -07:00
|
|
|
*/
|
2010-03-24 00:32:40 -07:00
|
|
|
const mozIStorageBindingParamsArray *getOwner() const;
|
2009-06-17 12:12:51 -07:00
|
|
|
|
2010-03-24 00:32:40 -07:00
|
|
|
BindingParams(mozIStorageBindingParamsArray *aOwningArray,
|
2009-06-17 12:12:51 -07:00
|
|
|
Statement *aOwningStatement);
|
2014-06-23 15:40:03 -07:00
|
|
|
protected:
|
2010-03-24 00:32:40 -07:00
|
|
|
virtual ~BindingParams() {}
|
|
|
|
|
2014-08-07 16:47:28 -07:00
|
|
|
explicit BindingParams(mozIStorageBindingParamsArray *aOwningArray);
|
2015-03-12 09:55:56 -07:00
|
|
|
// Note that this is managed as a sparse array, so particular caution should
|
|
|
|
// be used for out-of-bounds usage.
|
2015-10-17 22:24:48 -07:00
|
|
|
nsTArray<RefPtr<Variant_base> > mParameters;
|
2010-03-24 00:32:40 -07:00
|
|
|
bool mLocked;
|
2009-06-17 12:12:51 -07:00
|
|
|
|
|
|
|
private:
|
2010-03-24 00:32:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Track the BindingParamsArray that created us until we are added to it.
|
|
|
|
* (Once we are added we are locked and no one needs to look up our owner.)
|
|
|
|
* Ref-counted since there is no invariant that guarantees it stays alive
|
|
|
|
* otherwise. This keeps mOwningStatement alive for us too since the array
|
|
|
|
* also holds a reference.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<mozIStorageBindingParamsArray> mOwningArray;
|
|
|
|
/**
|
|
|
|
* Used in the synchronous binding case to map parameter names to indices.
|
|
|
|
* Not reference-counted because this is only non-null as long as mOwningArray
|
|
|
|
* is non-null and mOwningArray also holds a statement reference.
|
|
|
|
*/
|
2009-06-17 12:12:51 -07:00
|
|
|
Statement *mOwningStatement;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mParamCount;
|
2010-03-24 00:32:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds late resolution of named parameters so they don't get resolved until we
|
|
|
|
* try and bind the parameters on the async thread. We also stop checking
|
|
|
|
* parameter indices for being too big since we just just don't know how many
|
|
|
|
* there are.
|
|
|
|
*
|
|
|
|
* We support *either* binding by name or binding by index. Trying to do both
|
|
|
|
* results in only binding by name at sqlite3_stmt bind time.
|
|
|
|
*/
|
|
|
|
class AsyncBindingParams : public BindingParams
|
|
|
|
{
|
|
|
|
public:
|
2012-07-06 13:31:49 -07:00
|
|
|
NS_IMETHOD BindByName(const nsACString & aName,
|
2010-03-24 00:32:40 -07:00
|
|
|
nsIVariant *aValue);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD BindByIndex(uint32_t aIndex, nsIVariant *aValue);
|
2010-03-24 00:32:40 -07:00
|
|
|
|
|
|
|
virtual already_AddRefed<mozIStorageError> bind(sqlite3_stmt * aStatement);
|
|
|
|
|
2014-08-07 16:47:28 -07:00
|
|
|
explicit AsyncBindingParams(mozIStorageBindingParamsArray *aOwningArray);
|
2010-03-24 00:32:40 -07:00
|
|
|
virtual ~AsyncBindingParams() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, nsIVariant> mNamedParameters;
|
2009-06-17 12:12:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-01 05:38:00 -07:00
|
|
|
#endif // mozStorageBindingParams_h
|