Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/storage/mozStorageStatement.h
Line
Count
Source (jump to first uncovered line)
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 mozStorageStatement_h
8
#define mozStorageStatement_h
9
10
#include "nsAutoPtr.h"
11
#include "nsString.h"
12
13
#include "nsTArray.h"
14
15
#include "mozStorageBindingParamsArray.h"
16
#include "mozStorageStatementData.h"
17
#include "mozIStorageStatement.h"
18
#include "mozIStorageValueArray.h"
19
#include "StorageBaseStatementInternal.h"
20
#include "mozilla/Attributes.h"
21
22
struct sqlite3_stmt;
23
24
namespace mozilla {
25
namespace storage {
26
class StatementJSHelper;
27
class Connection;
28
class StatementParamsHolder;
29
class StatementRowHolder;
30
31
class Statement final : public mozIStorageStatement
32
                      , public mozIStorageValueArray
33
                      , public StorageBaseStatementInternal
34
{
35
public:
36
  NS_DECL_THREADSAFE_ISUPPORTS
37
  NS_DECL_MOZISTORAGESTATEMENT
38
  NS_DECL_MOZISTORAGEBASESTATEMENT
39
  NS_DECL_MOZISTORAGEBINDINGPARAMS
40
  // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
41
  NS_DECL_STORAGEBASESTATEMENTINTERNAL
42
43
  Statement();
44
45
  /**
46
   * Initializes the object on aDBConnection by preparing the SQL statement
47
   * given by aSQLStatement.
48
   *
49
   * @param aDBConnection
50
   *        The Connection object this statement is associated with.
51
   * @param aNativeConnection
52
   *        The native Sqlite connection this statement is associated with.
53
   * @param aSQLStatement
54
   *        The SQL statement to prepare that this object will represent.
55
   */
56
  nsresult initialize(Connection *aDBConnection,
57
                      sqlite3* aNativeConnection,
58
                      const nsACString &aSQLStatement);
59
60
61
  /**
62
   * Obtains the native statement pointer.
63
   */
64
0
  inline sqlite3_stmt *nativeStatement() { return mDBStatement; }
65
66
  /**
67
   * Obtains and transfers ownership of the array of parameters that are bound
68
   * to this statment.  This can be null.
69
   */
70
  inline already_AddRefed<BindingParamsArray> bindingParamsArray()
71
0
  {
72
0
    return mParamsArray.forget();
73
0
  }
74
75
private:
76
    ~Statement();
77
78
    sqlite3_stmt *mDBStatement;
79
    uint32_t mParamCount;
80
    uint32_t mResultColumnCount;
81
    nsTArray<nsCString> mColumnNames;
82
    bool mExecuting;
83
84
    /**
85
     * @return a pointer to the BindingParams object to use with our Bind*
86
     *         method.
87
     */
88
    mozIStorageBindingParams *getParams();
89
90
    /**
91
     * Holds the array of parameters to bind to this statement when we execute
92
     * it asynchronously.
93
     */
94
    RefPtr<BindingParamsArray> mParamsArray;
95
96
    /**
97
     * The following two members are only used with the JS helper.  They cache
98
     * the row and params objects.
99
     */
100
    nsMainThreadPtrHandle<StatementParamsHolder> mStatementParamsHolder;
101
    nsMainThreadPtrHandle<StatementRowHolder> mStatementRowHolder;
102
103
  /**
104
   * Internal version of finalize that allows us to tell it if it is being
105
   * called from the destructor so it can know not to dispatch events that
106
   * require a reference to us.
107
   *
108
   * @param aDestructing
109
   *        Is the destructor calling?
110
   */
111
  nsresult internalFinalize(bool aDestructing);
112
113
  friend class StatementJSHelper;
114
};
115
116
inline nsISupports*
117
ToSupports(Statement* p)
118
0
{
119
0
  return NS_ISUPPORTS_CAST(mozIStorageStatement*, p);
120
0
}
121
122
} // namespace storage
123
} // namespace mozilla
124
125
#endif // mozStorageStatement_h