LCOV - code coverage report
Current view: top level - storage - mozStorageBindingParams.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 2 100.0 %
Date: 2017-07-14 16:53:18 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #ifndef mozStorageBindingParams_h
       8             : #define mozStorageBindingParams_h
       9             : 
      10             : #include "nsCOMArray.h"
      11             : #include "nsIVariant.h"
      12             : #include "nsInterfaceHashtable.h"
      13             : 
      14             : #include "mozStorageBindingParamsArray.h"
      15             : #include "mozStorageStatement.h"
      16             : #include "mozStorageAsyncStatement.h"
      17             : #include "Variant.h"
      18             : 
      19             : #include "mozIStorageBindingParams.h"
      20             : #include "IStorageBindingParamsInternal.h"
      21             : 
      22             : namespace mozilla {
      23             : namespace storage {
      24             : 
      25             : class BindingParams : public mozIStorageBindingParams
      26             :                     , public IStorageBindingParamsInternal
      27             : {
      28             : public:
      29             :   NS_DECL_THREADSAFE_ISUPPORTS
      30             :   NS_DECL_MOZISTORAGEBINDINGPARAMS
      31             :   NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL
      32             : 
      33             :   /**
      34             :    * Locks the parameters and prevents further modification to it (such as
      35             :    * binding more elements to it).
      36             :    */
      37             :   void lock();
      38             : 
      39             :   /**
      40             :    * Unlocks the parameters and allows modification to it again.
      41             :    *
      42             :    * @param aOwningStatement
      43             :    *        The statement that owns us.  We cleared this when we were locked,
      44             :    *        and our invariant requires us to have this, so you need to tell us
      45             :    *        again.
      46             :    */
      47             :   void unlock(Statement *aOwningStatement);
      48             : 
      49             :   /**
      50             :    * @returns the pointer to the owning BindingParamsArray.  Used by a
      51             :    *          BindingParamsArray to verify that we belong to it when added.
      52             :    */
      53             :   const mozIStorageBindingParamsArray *getOwner() const;
      54             : 
      55             :   BindingParams(mozIStorageBindingParamsArray *aOwningArray,
      56             :                 Statement *aOwningStatement);
      57             : protected:
      58          45 :   virtual ~BindingParams() {}
      59             : 
      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;
      64             :   bool mLocked;
      65             : 
      66             : private:
      67             : 
      68             :   /**
      69             :    * Track the BindingParamsArray that created us until we are added to it.
      70             :    * (Once we are added we are locked and no one needs to look up our owner.)
      71             :    * Ref-counted since there is no invariant that guarantees it stays alive
      72             :    * otherwise.  This keeps mOwningStatement alive for us too since the array
      73             :    * also holds a reference.
      74             :    */
      75             :   nsCOMPtr<mozIStorageBindingParamsArray> mOwningArray;
      76             :   /**
      77             :    * Used in the synchronous binding case to map parameter names to indices.
      78             :    * Not reference-counted because this is only non-null as long as mOwningArray
      79             :    * is non-null and mOwningArray also holds a statement reference.
      80             :    */
      81             :   Statement *mOwningStatement;
      82             :   uint32_t mParamCount;
      83             : };
      84             : 
      85             : /**
      86             :  * Adds late resolution of named parameters so they don't get resolved until we
      87             :  * try and bind the parameters on the async thread.  We also stop checking
      88             :  * parameter indices for being too big since we just just don't know how many
      89             :  * there are.
      90             :  *
      91             :  * We support *either* binding by name or binding by index.  Trying to do both
      92             :  * results in only binding by name at sqlite3_stmt bind time.
      93             :  */
      94             : class AsyncBindingParams : public BindingParams
      95             : {
      96             : public:
      97             :   NS_IMETHOD BindByName(const nsACString & aName,
      98             :                                       nsIVariant *aValue);
      99             :   NS_IMETHOD BindByIndex(uint32_t aIndex, nsIVariant *aValue);
     100             : 
     101             :   virtual already_AddRefed<mozIStorageError> bind(sqlite3_stmt * aStatement);
     102             : 
     103             :   explicit AsyncBindingParams(mozIStorageBindingParamsArray *aOwningArray);
     104          18 :   virtual ~AsyncBindingParams() {}
     105             : 
     106             : private:
     107             :   nsInterfaceHashtable<nsCStringHashKey, nsIVariant> mNamedParameters;
     108             : };
     109             : 
     110             : } // namespace storage
     111             : } // namespace mozilla
     112             : 
     113             : #endif // mozStorageBindingParams_h

Generated by: LCOV version 1.13