Skip to content

Commit 5ff189a

Browse files
committed
Added a getIndex method and used it.
1 parent 11fab0f commit 5ff189a

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

include/SQLiteCpp/Statement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class Statement
116116
// instead of being copied.
117117
// => if you know what you are doing, use bindNoCopy() instead of bind()
118118

119+
int getIndex(const char * const apName);
120+
119121
/**
120122
* @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
121123
*/

src/Statement.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void Statement::clearBindings()
8383
check(ret);
8484
}
8585

86+
int Statement::getIndex(const char * const apName)
87+
{
88+
return sqlite3_bind_parameter_index(mStmtPtr, apName);
89+
}
90+
8691
// Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
8792
void Statement::bind(const int aIndex, const int aValue)
8893
{
@@ -166,39 +171,39 @@ void Statement::bind(const int aIndex)
166171
// Bind an int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
167172
void Statement::bind(const char* apName, const int aValue)
168173
{
169-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
174+
const int index = getIndex(apName);
170175
const int ret = sqlite3_bind_int(mStmtPtr, index, aValue);
171176
check(ret);
172177
}
173178

174179
// Bind a 32bits unsigned int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
175180
void Statement::bind(const char* apName, const unsigned aValue)
176181
{
177-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
182+
const int index = getIndex(apName);
178183
const int ret = sqlite3_bind_int64(mStmtPtr, index, aValue);
179184
check(ret);
180185
}
181186

182187
// Bind a 64bits int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
183188
void Statement::bind(const char* apName, const long long aValue)
184189
{
185-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
190+
const int index = getIndex(apName);
186191
const int ret = sqlite3_bind_int64(mStmtPtr, index, aValue);
187192
check(ret);
188193
}
189194

190195
// Bind a double (64bits float) value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
191196
void Statement::bind(const char* apName, const double aValue)
192197
{
193-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
198+
const int index = getIndex(apName);
194199
const int ret = sqlite3_bind_double(mStmtPtr, index, aValue);
195200
check(ret);
196201
}
197202

198203
// Bind a string value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
199204
void Statement::bind(const char* apName, const std::string& aValue)
200205
{
201-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
206+
const int index = getIndex(apName);
202207
const int ret = sqlite3_bind_text(mStmtPtr, index, aValue.c_str(),
203208
static_cast<int>(aValue.size()), SQLITE_TRANSIENT);
204209
check(ret);
@@ -207,23 +212,23 @@ void Statement::bind(const char* apName, const std::string& aValue)
207212
// Bind a text value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
208213
void Statement::bind(const char* apName, const char* apValue)
209214
{
210-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
215+
const int index = getIndex(apName);
211216
const int ret = sqlite3_bind_text(mStmtPtr, index, apValue, -1, SQLITE_TRANSIENT);
212217
check(ret);
213218
}
214219

215220
// Bind a binary blob value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
216221
void Statement::bind(const char* apName, const void* apValue, const int aSize)
217222
{
218-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
223+
const int index = getIndex(apName);
219224
const int ret = sqlite3_bind_blob(mStmtPtr, index, apValue, aSize, SQLITE_TRANSIENT);
220225
check(ret);
221226
}
222227

223228
// Bind a string value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
224229
void Statement::bindNoCopy(const char* apName, const std::string& aValue)
225230
{
226-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
231+
const int index = getIndex(apName);
227232
const int ret = sqlite3_bind_text(mStmtPtr, index, aValue.c_str(),
228233
static_cast<int>(aValue.size()), SQLITE_STATIC);
229234
check(ret);
@@ -232,23 +237,23 @@ void Statement::bindNoCopy(const char* apName, const std::string& aValue)
232237
// Bind a text value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
233238
void Statement::bindNoCopy(const char* apName, const char* apValue)
234239
{
235-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
240+
const int index = getIndex(apName);
236241
const int ret = sqlite3_bind_text(mStmtPtr, index, apValue, -1, SQLITE_STATIC);
237242
check(ret);
238243
}
239244

240245
// Bind a binary blob value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
241246
void Statement::bindNoCopy(const char* apName, const void* apValue, const int aSize)
242247
{
243-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
248+
const int index = getIndex(apName);
244249
const int ret = sqlite3_bind_blob(mStmtPtr, index, apValue, aSize, SQLITE_STATIC);
245250
check(ret);
246251
}
247252

248253
// Bind a NULL value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
249254
void Statement::bind(const char* apName)
250255
{
251-
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
256+
const int index = getIndex(apName);
252257
const int ret = sqlite3_bind_null(mStmtPtr, index);
253258
check(ret);
254259
}

0 commit comments

Comments
 (0)