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