@@ -227,110 +227,52 @@ class Statement
227
227
*/
228
228
void bind (const int aIndex);
229
229
230
- /* *
231
- * @brief Bind an int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
232
- */
233
- void bind (const char * apName, const int aValue)
234
- {
235
- bind (getIndex (apName), aValue);
236
- }
237
- /* *
238
- * @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
239
- */
240
- void bind (const char * apName, const unsigned aValue)
230
+ template <typename T>
231
+ inline void bind (const char * apName, const T &aValue)
241
232
{
242
233
bind (getIndex (apName), aValue);
243
234
}
244
235
245
- #if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
246
- /* *
247
- * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
248
- */
249
- void bind (const char * apName, const long aValue)
236
+ template <typename T> inline void bindNoCopy (const char * apName, const T& aValue)
250
237
{
251
- bind (apName, static_cast <int >(aValue));
252
- }
253
- #else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
254
- /* *
255
- * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
256
- */
257
- void bind (const char * apName, const long aValue)
258
- {
259
- bind (apName, static_cast <long long >(aValue));
260
- }
261
- #endif
262
- /* *
263
- * @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
264
- */
265
- void bind (const char * apName, const long long aValue)
266
- {
267
- bind (getIndex (apName), aValue);
268
- }
269
- /* *
270
- * @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
271
- */
272
- void bind (const char * apName, const double aValue)
273
- {
274
- bind (getIndex (apName), aValue);
275
- }
276
- /* *
277
- * @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
278
- *
279
- * @note Uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
280
- */
281
- void bind (const char * apName, const std::string& aValue)
282
- {
283
- bind (getIndex (apName), aValue);
238
+ bindNoCopy (getIndex (apName), aValue);
284
239
}
285
- /* *
286
- * @brief Bind a text value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
287
- *
288
- * @note Uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
289
- */
290
- void bind (const char * apName, const char * apValue)
240
+
241
+ #if __cplusplus >= 201103L
242
+ #define ENABLE_IF_CONST_CHAR_OR_VOID \
243
+ template <\
244
+ typename T\
245
+ , class = typename std::enable_if<\
246
+ std::is_same<T, const char >::value\
247
+ || std::is_same<T, const void >::value\
248
+ >::type\
249
+ >
250
+
251
+
252
+ ENABLE_IF_CONST_CHAR_OR_VOID
253
+ void bind (const char * apName, T* apValue)
291
254
{
292
255
bind (getIndex (apName), apValue);
293
256
}
294
- /* *
295
- * @brief Bind a binary blob value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
296
- *
297
- * @note Uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
298
- */
299
- void bind (const char * apName, const void * apValue, const int aSize)
300
- {
301
- bind (getIndex (apName), apValue, aSize);
302
- }
303
- /* *
304
- * @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
305
- *
306
- * The string can contain null characters as it is binded using its size.
307
- *
308
- * @warning Uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
309
- */
310
- void bindNoCopy (const char * apName, const std::string& aValue)
257
+ ENABLE_IF_CONST_CHAR_OR_VOID
258
+ void bindNoCopy (const char * apName, T* apValue)
311
259
{
312
- bindNoCopy (getIndex (apName), aValue );
260
+ bindNoCopy (getIndex (apName), apValue );
313
261
}
314
- /* *
315
- * @brief Bind a text value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
316
- *
317
- * Main usage is with null-terminated literal text (aka in code static strings)
318
- *
319
- * @warning Uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
320
- */
321
- void bindNoCopy (const char * apName, const char * apValue)
262
+
263
+ ENABLE_IF_CONST_CHAR_OR_VOID
264
+ void bind (const char * apName, T* apValue, const int aSize)
322
265
{
323
- bindNoCopy (getIndex (apName), apValue);
266
+ bind (getIndex (apName), apValue, aSize );
324
267
}
325
- /* *
326
- * @brief Bind a binary blob value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
327
- *
328
- * @warning Uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
329
- */
330
- void bindNoCopy (const char * apName, const void * apValue, const int aSize)
268
+ ENABLE_IF_CONST_CHAR_OR_VOID
269
+ void bindNoCopy (const char * apName, T* apValue, const int aSize)
331
270
{
332
271
bindNoCopy (getIndex (apName), apValue, aSize);
333
272
}
273
+ #endif
274
+
275
+
334
276
/* *
335
277
* @brief Bind a NULL value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
336
278
*
@@ -341,120 +283,37 @@ class Statement
341
283
bind (getIndex (apName));
342
284
}
343
285
344
-
345
- /* *
346
- * @brief Bind an int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
347
- */
348
- inline void bind (const std::string& aName, const int aValue)
286
+ template <typename T>
287
+ void bind (const std::string& aName, T &v)
349
288
{
350
- bind (aName.c_str (), aValue);
351
- }
352
- /* *
353
- * @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
354
- */
355
- inline void bind (const std::string& aName, const unsigned aValue)
356
- {
357
- bind (aName.c_str (), aValue);
289
+ bind (aName.c_str (), v);
358
290
}
359
291
360
- #if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
361
- /* *
362
- * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
363
- */
364
- void bind (const std::string& aName, const long aValue)
365
- {
366
- bind (aName.c_str (), static_cast <int >(aValue));
367
- }
368
- #else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
369
- /* *
370
- * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
371
- */
372
- void bind (const std::string& aName, const long aValue)
373
- {
374
- bind (aName.c_str (), static_cast <long long >(aValue));
375
- }
376
- #endif
377
- /* *
378
- * @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
379
- */
380
- inline void bind (const std::string& aName, const long long aValue)
381
- {
382
- bind (aName.c_str (), aValue);
383
- }
384
- /* *
385
- * @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
386
- */
387
- inline void bind (const std::string& aName, const double aValue)
388
- {
389
- bind (aName.c_str (), aValue);
390
- }
391
- /* *
392
- * @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
393
- *
394
- * @note Uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
395
- */
396
- inline void bind (const std::string& aName, const std::string& aValue)
397
- {
398
- bind (aName.c_str (), aValue);
399
- }
400
- /* *
401
- * @brief Bind a text value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
402
- *
403
- * @note Uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
404
- */
405
- inline void bind (const std::string& aName, const char * apValue)
406
- {
407
- bind (aName.c_str (), apValue);
408
- }
409
- /* *
410
- * @brief Bind a binary blob value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
411
- *
412
- * @note Uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
413
- */
414
- inline void bind (const std::string& aName, const void * apValue, const int aSize)
292
+ #if __cplusplus >= 201103L
293
+ ENABLE_IF_CONST_CHAR_OR_VOID
294
+ inline void bind (const std::string& aName, T* v)
415
295
{
416
- bind (aName.c_str (), apValue, aSize );
296
+ bind (aName.c_str (), v );
417
297
}
418
- /* *
419
- * @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
420
- *
421
- * The string can contain null characters as it is binded using its size.
422
- *
423
- * @warning Uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
424
- */
425
- inline void bindNoCopy (const std::string& aName, const std::string& aValue)
426
- {
427
- bindNoCopy (aName.c_str (), aValue);
428
- }
429
- /* *
430
- * @brief Bind a text value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
431
- *
432
- * Main usage is with null-terminated literal text (aka in code static strings)
433
- *
434
- * @warning Uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
435
- */
436
- inline void bindNoCopy (const std::string& aName, const char * apValue)
298
+
299
+ ENABLE_IF_CONST_CHAR_OR_VOID
300
+ inline void bind (const std::string& aName, T* v, const int aSize)
437
301
{
438
- bindNoCopy (aName.c_str (), apValue );
302
+ bind (aName.c_str (), v, aSize );
439
303
}
440
- /* *
441
- * @brief Bind a binary blob value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
442
- *
443
- * @warning Uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
444
- */
445
- inline void bindNoCopy (const std::string& aName, const void * apValue, const int aSize)
304
+
305
+ ENABLE_IF_CONST_CHAR_OR_VOID
306
+ inline void bindNoCopy (const std::string& aName, T* v)
446
307
{
447
- bindNoCopy (aName.c_str (), apValue, aSize );
308
+ bindNoCopy (aName.c_str (), v );
448
309
}
449
- /* *
450
- * @brief Bind a NULL value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
451
- *
452
- * @see clearBindings() to set all bound parameters to NULL.
453
- */
454
- inline void bind (const std::string& aName) // bind NULL value
310
+
311
+ ENABLE_IF_CONST_CHAR_OR_VOID
312
+ inline void bindNoCopy (const std::string& aName, T* v, const int aSize)
455
313
{
456
- bind (aName.c_str ());
314
+ bindNoCopy (aName.c_str (), v, aSize );
457
315
}
316
+ #endif
458
317
459
318
// //////////////////////////////////////////////////////////////////////////
460
319
0 commit comments