2009-06-17 19:12:51 +00: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 11:12:37 +00: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 19:12:51 +00:00
|
|
|
|
2010-06-01 12:38:00 +00:00
|
|
|
#ifndef mozStorageBindingParams_h
|
|
|
|
#define mozStorageBindingParams_h
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsIVariant.h"
|
2010-08-27 19:42:58 +00:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
#include "mozStorageBindingParamsArray.h"
|
|
|
|
#include "mozStorageStatement.h"
|
2010-03-24 07:32:40 +00:00
|
|
|
#include "mozStorageAsyncStatement.h"
|
2015-03-12 16:55:56 +00:00
|
|
|
#include "Variant.h"
|
2009-06-17 19:12:51 +00:00
|
|
|
|
2010-03-24 07:32:40 +00:00
|
|
|
#include "mozIStorageBindingParams.h"
|
|
|
|
#include "IStorageBindingParamsInternal.h"
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
|
|
|
|
class BindingParams : public mozIStorageBindingParams,
|
2010-03-24 07:32:40 +00:00
|
|
|
public IStorageBindingParamsInternal {
|
2009-06-17 19:12:51 +00:00
|
|
|
public:
|
2013-07-19 02:24:15 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-06-17 19:12:51 +00:00
|
|
|
NS_DECL_MOZISTORAGEBINDINGPARAMS
|
2010-03-24 07:32:40 +00:00
|
|
|
NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locks the parameters and prevents further modification to it (such as
|
|
|
|
* binding more elements to it).
|
|
|
|
*/
|
|
|
|
void lock();
|
|
|
|
|
2009-07-28 17:21:03 +00:00
|
|
|
/**
|
|
|
|
* Unlocks the parameters and allows modification to it again.
|
2010-03-24 07:32:40 +00: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 17:21:03 +00:00
|
|
|
*/
|
2010-03-24 07:32:40 +00:00
|
|
|
void unlock(Statement *aOwningStatement);
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
/**
|
2010-03-24 07:32:40 +00:00
|
|
|
* @returns the pointer to the owning BindingParamsArray. Used by a
|
|
|
|
* BindingParamsArray to verify that we belong to it when added.
|
2009-06-17 19:12:51 +00:00
|
|
|
*/
|
2010-03-24 07:32:40 +00:00
|
|
|
const mozIStorageBindingParamsArray *getOwner() const;
|
2009-06-17 19:12:51 +00:00
|
|
|
|
2010-03-24 07:32:40 +00:00
|
|
|
BindingParams(mozIStorageBindingParamsArray *aOwningArray,
|
2009-06-17 19:12:51 +00:00
|
|
|
Statement *aOwningStatement);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-06-23 22:40:03 +00:00
|
|
|
protected:
|
2010-03-24 07:32:40 +00:00
|
|
|
virtual ~BindingParams() {}
|
|
|
|
|
2014-08-07 23:47:28 +00:00
|
|
|
explicit BindingParams(mozIStorageBindingParamsArray *aOwningArray);
|
2015-03-12 16:55:56 +00:00
|
|
|
// Note that this is managed as a sparse array, so particular caution should
|
|
|
|
// be used for out-of-bounds usage.
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<Variant_base> > mParameters;
|
2010-03-24 07:32:40 +00:00
|
|
|
bool mLocked;
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
private:
|
2010-03-24 07:32:40 +00: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 19:12:51 +00:00
|
|
|
Statement *mOwningStatement;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mParamCount;
|
2010-03-24 07:32:40 +00: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 20:31:49 +00:00
|
|
|
NS_IMETHOD BindByName(const nsACString &aName, nsIVariant *aValue) override;
|
2017-11-06 03:37:28 +00:00
|
|
|
NS_IMETHOD BindByIndex(uint32_t aIndex, nsIVariant *aValue) override;
|
2010-03-24 07:32:40 +00:00
|
|
|
|
2017-11-06 03:37:28 +00:00
|
|
|
virtual already_AddRefed<mozIStorageError> bind(
|
|
|
|
sqlite3_stmt *aStatement) override;
|
2010-03-24 07:32:40 +00:00
|
|
|
|
2014-08-07 23:47:28 +00:00
|
|
|
explicit AsyncBindingParams(mozIStorageBindingParamsArray *aOwningArray);
|
2010-03-24 07:32:40 +00:00
|
|
|
virtual ~AsyncBindingParams() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, nsIVariant> mNamedParameters;
|
2009-06-17 19:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-01 12:38:00 +00:00
|
|
|
#endif // mozStorageBindingParams_h
|