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 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Mozilla Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
24 * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
25 * Andrew Sutherland <asutherland@asutherland.org>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef mozStorageBindingParams_h
42 #define mozStorageBindingParams_h
44 #include "nsCOMArray.h"
45 #include "nsIVariant.h"
46 #include "nsInterfaceHashtable.h"
48 #include "mozStorageBindingParamsArray.h"
49 #include "mozStorageStatement.h"
50 #include "mozStorageAsyncStatement.h"
52 #include "mozIStorageBindingParams.h"
53 #include "IStorageBindingParamsInternal.h"
58 class BindingParams
: public mozIStorageBindingParams
59 , public IStorageBindingParamsInternal
63 NS_DECL_MOZISTORAGEBINDINGPARAMS
64 NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL
67 * Locks the parameters and prevents further modification to it (such as
68 * binding more elements to it).
73 * Unlocks the parameters and allows modification to it again.
75 * @param aOwningStatement
76 * The statement that owns us. We cleared this when we were locked,
77 * and our invariant requires us to have this, so you need to tell us
80 void unlock(Statement
*aOwningStatement
);
83 * @returns the pointer to the owning BindingParamsArray. Used by a
84 * BindingParamsArray to verify that we belong to it when added.
86 const mozIStorageBindingParamsArray
*getOwner() const;
88 BindingParams(mozIStorageBindingParamsArray
*aOwningArray
,
89 Statement
*aOwningStatement
);
90 virtual ~BindingParams() {}
93 BindingParams(mozIStorageBindingParamsArray
*aOwningArray
);
94 nsCOMArray
<nsIVariant
> mParameters
;
100 * Track the BindingParamsArray that created us until we are added to it.
101 * (Once we are added we are locked and no one needs to look up our owner.)
102 * Ref-counted since there is no invariant that guarantees it stays alive
103 * otherwise. This keeps mOwningStatement alive for us too since the array
104 * also holds a reference.
106 nsCOMPtr
<mozIStorageBindingParamsArray
> mOwningArray
;
108 * Used in the synchronous binding case to map parameter names to indices.
109 * Not reference-counted because this is only non-null as long as mOwningArray
110 * is non-null and mOwningArray also holds a statement reference.
112 Statement
*mOwningStatement
;
113 PRUint32 mParamCount
;
117 * Adds late resolution of named parameters so they don't get resolved until we
118 * try and bind the parameters on the async thread. We also stop checking
119 * parameter indices for being too big since we just just don't know how many
122 * We support *either* binding by name or binding by index. Trying to do both
123 * results in only binding by name at sqlite3_stmt bind time.
125 class AsyncBindingParams
: public BindingParams
128 NS_SCRIPTABLE NS_IMETHOD
BindByName(const nsACString
& aName
,
130 NS_SCRIPTABLE NS_IMETHOD
BindByIndex(PRUint32 aIndex
, nsIVariant
*aValue
);
132 virtual already_AddRefed
<mozIStorageError
> bind(sqlite3_stmt
* aStatement
);
134 AsyncBindingParams(mozIStorageBindingParamsArray
*aOwningArray
);
135 virtual ~AsyncBindingParams() {}
138 nsInterfaceHashtable
<nsCStringHashKey
, nsIVariant
> mNamedParameters
;
140 struct NamedParameterIterationClosureThunk
142 AsyncBindingParams
*self
;
143 sqlite3_stmt
*statement
;
144 nsCOMPtr
<mozIStorageError
> err
;
147 static PLDHashOperator
iterateOverNamedParameters(const nsACString
&aName
,
149 void *voidClosureThunk
);
152 } // namespace storage
153 } // namespace mozilla
155 #endif // mozStorageBindingParams_h