Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
audacity::sqlite::RunContext Class Referencefinal

A class representing a context of a run operation. More...

#include <Statement.h>

Collaboration diagram for audacity::sqlite::RunContext:
[legend]

Public Member Functions

 RunContext (const RunContext &)=delete
 
 RunContext (RunContext &&) noexcept
 
RunContextoperator= (const RunContext &)=delete
 
RunContextoperator= (RunContext &&) noexcept
 
RunContextBind (int index, const void *data, int64_t size, bool makeCopy=true)
 
RunContextBind (int index, const std::string &value, bool makeCopy=true)
 
RunContextBind (int index, std::string_view value, bool makeCopy=true)
 
RunContextBind (int index, const char *value, bool makeCopy=true)
 
RunContextBind (int index, bool value)
 
RunContextBind (int index, int value)
 
RunContextBind (int index, long value)
 
RunContextBind (int index, long long value)
 
RunContextBind (int index, std::size_t value)
 
RunContextBind (int index, float value)
 
RunContextBind (int index, double value)
 
RunContextBind (int index, std::nullptr_t)
 
RunContextBindZeroBlob (int index, int64_t size)
 
template<typename T >
RunContextBind (const std::string &name, const T &value)
 
template<typename T >
RunContextBind (const std::string &name, const T &value, bool make_copy)
 
template<typename... Args>
RunContextBindAll (Args &&... args)
 
int GetParameterIndex (const std::string &name) const noexcept
 
RunResult Run ()
 

Private Member Functions

 RunContext (StatementHandlePtr statement) noexcept
 
template<typename Binder >
RunContextDoBind (Binder binder)
 

Private Attributes

StatementHandlePtr mStatement {}
 
std::vector< ErrormErrors {}
 
bool mNeedsReset { false }
 

Friends

class Statement
 

Detailed Description

A class representing a context of a run operation.

Indices are 1-based

Definition at line 132 of file Statement.h.

Constructor & Destructor Documentation

◆ RunContext() [1/3]

audacity::sqlite::RunContext::RunContext ( StatementHandlePtr  statement)
explicitprivatenoexcept

Definition at line 62 of file Statement.cpp.

63 : mStatement { std::move(stmt) }
64{
65}
StatementHandlePtr mStatement
Definition: Statement.h:187

◆ RunContext() [2/3]

audacity::sqlite::RunContext::RunContext ( const RunContext )
delete

◆ RunContext() [3/3]

audacity::sqlite::RunContext::RunContext ( RunContext &&  rhs)
noexcept

Definition at line 67 of file Statement.cpp.

68{
69 *this = std::move(rhs);
70}

Member Function Documentation

◆ Bind() [1/14]

template<typename T >
RunContext & audacity::sqlite::RunContext::Bind ( const std::string &  name,
const T &  value 
)
inline

Definition at line 162 of file Statement.h.

163 {
164 return Bind(GetParameterIndex(name), value);
165 }
wxString name
Definition: TagsEditor.cpp:166
int GetParameterIndex(const std::string &name) const noexcept
Definition: Statement.cpp:190
RunContext & Bind(int index, const void *data, int64_t size, bool makeCopy=true)
Definition: Statement.cpp:91

References name.

◆ Bind() [2/14]

template<typename T >
RunContext & audacity::sqlite::RunContext::Bind ( const std::string &  name,
const T &  value,
bool  make_copy 
)
inline

Definition at line 168 of file Statement.h.

169 {
170 return Bind(GetParameterIndex(name), value, make_copy);
171 }

References name.

◆ Bind() [3/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
bool  value 
)

Definition at line 137 of file Statement.cpp.

138{
139 return Bind(index, static_cast<long long>(value));
140}

References Bind().

Here is the call graph for this function:

◆ Bind() [4/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
const char *  value,
bool  makeCopy = true 
)

Definition at line 131 of file Statement.cpp.

133{
134 return Bind(index, std::string_view { value }, makeCopy);
135}

References Bind().

Here is the call graph for this function:

◆ Bind() [5/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
const std::string &  value,
bool  makeCopy = true 
)

Definition at line 107 of file Statement.cpp.

109{
110 return Bind(index, std::string_view { value }, makeCopy);
111}

References Bind().

Here is the call graph for this function:

◆ Bind() [6/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
const void *  data,
int64_t  size,
bool  makeCopy = true 
)

Definition at line 91 of file Statement.cpp.

93{
94 if (data == nullptr)
95 return BindZeroBlob(index, size);
96
97 return DoBind(
98 [&]
99 {
100 return sqlite3_bind_blob64(
101 *mStatement, index, data, size,
102 makeCopy ? SQLITE_TRANSIENT : SQLITE_STATIC);
103 });
104}
RunContext & DoBind(Binder binder)
Definition: Statement.cpp:81
RunContext & BindZeroBlob(int index, int64_t size)
Definition: Statement.cpp:184

References BindZeroBlob(), DoBind(), mStatement, and size.

Referenced by Bind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bind() [7/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
double  value 
)

Definition at line 172 of file Statement.cpp.

173{
174 return DoBind([&] { return sqlite3_bind_double(*mStatement, index, value); });
175}

References DoBind(), and mStatement.

Here is the call graph for this function:

◆ Bind() [8/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
float  value 
)

Definition at line 166 of file Statement.cpp.

167{
168 return Bind(index, static_cast<double>(value));
169}

References Bind().

Here is the call graph for this function:

◆ Bind() [9/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
int  value 
)

Definition at line 143 of file Statement.cpp.

144{
145 return Bind(index, static_cast<long long>(value));
146}

References Bind().

Here is the call graph for this function:

◆ Bind() [10/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
long long  value 
)

Definition at line 155 of file Statement.cpp.

156{
157 return DoBind([&] { return sqlite3_bind_int64(*mStatement, index, value); });
158}

References DoBind(), and mStatement.

Here is the call graph for this function:

◆ Bind() [11/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
long  value 
)

Definition at line 149 of file Statement.cpp.

150{
151 return Bind(index, static_cast<long long>(value));
152}

References Bind().

Here is the call graph for this function:

◆ Bind() [12/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
std::nullptr_t   
)

Definition at line 178 of file Statement.cpp.

179{
180 return DoBind([&] { return sqlite3_bind_null(*mStatement, index); });
181}

References DoBind(), and mStatement.

Here is the call graph for this function:

◆ Bind() [13/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
std::size_t  value 
)

Definition at line 160 of file Statement.cpp.

161{
162 return DoBind([&] { return sqlite3_bind_int64(*mStatement, index, value); });
163}

◆ Bind() [14/14]

RunContext & audacity::sqlite::RunContext::Bind ( int  index,
std::string_view  value,
bool  makeCopy = true 
)

Definition at line 113 of file Statement.cpp.

115{
116 return DoBind(
117 [&]
118 {
119 if (mNeedsReset)
120 {
121 mNeedsReset = false;
122 sqlite3_reset(*mStatement);
123 }
124
125 return sqlite3_bind_text(
126 *mStatement, index, value.data(), value.size(),
127 makeCopy ? SQLITE_TRANSIENT : SQLITE_STATIC);
128 });
129}

References DoBind(), mNeedsReset, and mStatement.

Here is the call graph for this function:

◆ BindAll()

template<typename... Args>
RunContext & audacity::sqlite::RunContext::BindAll ( Args &&...  args)
inline

Definition at line 173 of file Statement.h.

174 {
175 int index = 0;
176 (Bind(++index, std::forward<Args>(args)), ...);
177 return *this;
178 }

Referenced by audacity::sqlite::Statement::Prepare().

Here is the caller graph for this function:

◆ BindZeroBlob()

RunContext & audacity::sqlite::RunContext::BindZeroBlob ( int  index,
int64_t  size 
)

Definition at line 184 of file Statement.cpp.

185{
186 return DoBind([&]
187 { return sqlite3_bind_zeroblob64(*mStatement, index, size); });
188}

References DoBind(), mStatement, and size.

Referenced by Bind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoBind()

template<typename Binder >
RunContext & audacity::sqlite::RunContext::DoBind ( Binder  binder)
private

Definition at line 81 of file Statement.cpp.

82{
83 if (mStatement == nullptr)
84 mErrors.emplace_back(Error(SQLITE_MISUSE));
85 else if (int result = binder(); result != SQLITE_OK)
86 mErrors.emplace_back(Error(result));
87
88 return *this;
89}
std::vector< Error > mErrors
Definition: Statement.h:188

References mErrors, and mStatement.

Referenced by Bind(), and BindZeroBlob().

Here is the caller graph for this function:

◆ GetParameterIndex()

int audacity::sqlite::RunContext::GetParameterIndex ( const std::string &  name) const
noexcept

Definition at line 190 of file Statement.cpp.

191{
192 return mStatement != nullptr ?
193 sqlite3_bind_parameter_index(*mStatement, name.data()) :
194 -1;
195}

References name.

◆ operator=() [1/2]

RunContext & audacity::sqlite::RunContext::operator= ( const RunContext )
delete

◆ operator=() [2/2]

RunContext & audacity::sqlite::RunContext::operator= ( RunContext &&  rhs)
noexcept

Definition at line 72 of file Statement.cpp.

73{
74 std::swap(mStatement, rhs.mStatement);
75 std::swap(mErrors, rhs.mErrors);
76
77 return *this;
78}
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

References anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ Run()

RunResult audacity::sqlite::RunContext::Run ( )

Definition at line 197 of file Statement.cpp.

198{
199 mNeedsReset = true;
200 return RunResult { mStatement, std::move(mErrors) };
201}

References mErrors, mNeedsReset, and mStatement.

Friends And Related Function Documentation

◆ Statement

friend class Statement
friend

Definition at line 134 of file Statement.h.

Member Data Documentation

◆ mErrors

std::vector<Error> audacity::sqlite::RunContext::mErrors {}
private

Definition at line 188 of file Statement.h.

Referenced by DoBind(), and Run().

◆ mNeedsReset

bool audacity::sqlite::RunContext::mNeedsReset { false }
private

Definition at line 189 of file Statement.h.

Referenced by Bind(), and Run().

◆ mStatement

StatementHandlePtr audacity::sqlite::RunContext::mStatement {}
private

Definition at line 187 of file Statement.h.

Referenced by Bind(), BindZeroBlob(), DoBind(), and Run().


The documentation for this class was generated from the following files: