1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozStorageBindingParams_h
8 #define mozStorageBindingParams_h
10 #include "nsCOMArray.h"
11 #include "nsIVariant.h"
12 #include "nsInterfaceHashtable.h"
14 #include "mozStorageBindingParamsArray.h"
15 #include "mozStorageStatement.h"
16 #include "mozStorageAsyncStatement.h"
19 #include "mozIStorageBindingParams.h"
20 #include "IStorageBindingParamsInternal.h"
25 class BindingParams
: public mozIStorageBindingParams
,
26 public IStorageBindingParamsInternal
{
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_DECL_MOZISTORAGEBINDINGPARAMS
30 NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL
33 * Locks the parameters and prevents further modification to it (such as
34 * binding more elements to it).
39 * Unlocks the parameters and allows modification to it again.
41 * @param aOwningStatement
42 * The statement that owns us. We cleared this when we were locked,
43 * and our invariant requires us to have this, so you need to tell us
46 void unlock(Statement
* aOwningStatement
);
49 * @returns the pointer to the owning BindingParamsArray. Used by a
50 * BindingParamsArray to verify that we belong to it when added.
52 const mozIStorageBindingParamsArray
* getOwner() const;
54 BindingParams(mozIStorageBindingParamsArray
* aOwningArray
,
55 Statement
* aOwningStatement
);
58 virtual ~BindingParams() {}
60 explicit BindingParams(mozIStorageBindingParamsArray
* aOwningArray
);
61 // Note that this is managed as a sparse array, so particular caution should
62 // be used for out-of-bounds usage.
63 nsTArray
<RefPtr
<Variant_base
> > mParameters
;
68 * Track the BindingParamsArray that created us until we are added to it.
69 * (Once we are added we are locked and no one needs to look up our owner.)
70 * Ref-counted since there is no invariant that guarantees it stays alive
71 * otherwise. This keeps mOwningStatement alive for us too since the array
72 * also holds a reference.
74 nsCOMPtr
<mozIStorageBindingParamsArray
> mOwningArray
;
76 * Used in the synchronous binding case to map parameter names to indices.
77 * Not reference-counted because this is only non-null as long as mOwningArray
78 * is non-null and mOwningArray also holds a statement reference.
80 Statement
* mOwningStatement
;
85 * Adds late resolution of named parameters so they don't get resolved until we
86 * try and bind the parameters on the async thread. We also stop checking
87 * parameter indices for being too big since we just just don't know how many
90 * We support *either* binding by name or binding by index. Trying to do both
91 * results in only binding by name at sqlite3_stmt bind time.
93 class AsyncBindingParams
: public BindingParams
{
95 NS_IMETHOD
BindByName(const nsACString
& aName
, nsIVariant
* aValue
) override
;
96 NS_IMETHOD
BindByIndex(uint32_t aIndex
, nsIVariant
* aValue
) override
;
98 virtual already_AddRefed
<mozIStorageError
> bind(
99 sqlite3_stmt
* aStatement
) override
;
101 explicit AsyncBindingParams(mozIStorageBindingParamsArray
* aOwningArray
);
102 virtual ~AsyncBindingParams() {}
105 nsInterfaceHashtable
<nsCStringHashKey
, nsIVariant
> mNamedParameters
;
108 } // namespace storage
109 } // namespace mozilla
111 #endif // mozStorageBindingParams_h