@@ -321,9 +321,35 @@ class MySQL_ParamBind
321
321
}
322
322
}
323
323
324
+
325
+
326
+ bool check_query_attr_support ()
327
+ {
328
+ if (has_query_attributes)
329
+ return true ;
330
+
331
+ assert (0 == attrs.size ());
332
+ return false ;
333
+ }
334
+
335
+
336
+ /*
337
+ Only resize `bind` vector accordingly but do not copy
338
+ attribute value from `attrs` -- this is done later in `getBindObject()`.
339
+ */
340
+
341
+ void resize_bind ()
342
+ {
343
+ if (param_count + attrs.size () > bind.size ())
344
+ {
345
+ bind.resize (param_count + attrs.size ());
346
+ }
347
+ }
348
+
349
+
324
350
/*
325
351
Set or overwrite existing value of an attribute with given name.
326
-
352
+
327
353
If `is_external` is false then existing external value will not
328
354
be changed.
329
355
*/
@@ -334,31 +360,177 @@ class MySQL_ParamBind
334
360
bool is_external
335
361
)
336
362
{
337
- /*
338
- Note: If we are talking to server that does not support query attributes then they are silently ignored.
339
- */
340
-
341
- if (!has_query_attributes)
342
- {
343
- assert (0 == attrs.size ());
363
+ if (!check_query_attr_support ())
344
364
return 0 ;
345
- }
346
365
347
366
int pos = attrs.setQueryAttrString (name, value, is_external);
367
+ resize_bind ();
368
+ return pos;
369
+ }
348
370
349
- /*
350
- Note: Here we only resize `bind` vector accordingly but do not copy
351
- attribute value from `attrs` -- this is done later in `getBindObject()`.
352
- */
353
371
354
- if (param_count + attrs.size () > bind.size ())
355
- bind.resize (param_count + attrs.size ());
372
+ /*
373
+ Set or overwrite BigInt value of an attribute with given name.
374
+ */
375
+
376
+ int setQueryAttrBigInt (
377
+ const sql::SQLString &name,
378
+ const sql::SQLString &value
379
+ )
380
+ {
381
+ if (!check_query_attr_support ())
382
+ return 0 ;
383
+
384
+ int pos = attrs.setQueryAttrBigInt (name, value);
385
+ resize_bind ();
386
+ return pos;
387
+ }
388
+
389
+
390
+ /*
391
+ Set or overwrite boolean value of an attribute with given name.
392
+ */
393
+
394
+ int setQueryAttrBoolean (
395
+ const sql::SQLString &name,
396
+ bool value
397
+ )
398
+ {
399
+ if (!check_query_attr_support ())
400
+ return 0 ;
401
+
402
+ int pos = attrs.setQueryAttrBoolean (name, value);
403
+ resize_bind ();
404
+ return pos;
405
+ }
406
+
407
+
408
+ /*
409
+ Set or overwrite DateTime value of an attribute with given name.
410
+ */
411
+
412
+ int setQueryAttrDateTime (
413
+ const sql::SQLString &name,
414
+ const sql::SQLString &value
415
+ )
416
+ {
417
+ if (!check_query_attr_support ())
418
+ return 0 ;
419
+
420
+ int pos = attrs.setQueryAttrDateTime (name, value);
421
+ resize_bind ();
422
+ return pos;
423
+ }
424
+
425
+
426
+ /*
427
+ Set or overwrite double value of an attribute with given name.
428
+ */
429
+
430
+ int setQueryAttrDouble (
431
+ const sql::SQLString &name,
432
+ double value
433
+ )
434
+ {
435
+ if (!check_query_attr_support ())
436
+ return 0 ;
437
+
438
+ int pos = attrs.setQueryAttrDouble (name, value);
439
+ resize_bind ();
440
+ return pos;
441
+ }
442
+
443
+
444
+ /*
445
+ Set or overwrite int32_t value of an attribute with given name.
446
+ */
447
+
448
+ int setQueryAttrInt (
449
+ const sql::SQLString &name,
450
+ int32_t value
451
+ )
452
+ {
453
+ if (!check_query_attr_support ())
454
+ return 0 ;
356
455
456
+ int pos = attrs.setQueryAttrInt (name, value);
457
+ resize_bind ();
357
458
return pos;
358
459
}
359
460
360
461
361
- bool isAllSet ()
462
+ /*
463
+ Set or overwrite uint32_t value of an attribute with given name.
464
+ */
465
+
466
+ int setQueryAttrUInt (
467
+ const sql::SQLString &name,
468
+ uint32_t value
469
+ )
470
+ {
471
+ if (!check_query_attr_support ())
472
+ return 0 ;
473
+
474
+ int pos = attrs.setQueryAttrUInt (name, value);
475
+ resize_bind ();
476
+ return pos;
477
+ }
478
+
479
+
480
+ /*
481
+ Set or overwrite int64_t value of an attribute with given name.
482
+ */
483
+
484
+ int setQueryAttrInt64 (
485
+ const sql::SQLString &name,
486
+ int64_t value
487
+ )
488
+ {
489
+ if (!check_query_attr_support ())
490
+ return 0 ;
491
+
492
+ int pos = attrs.setQueryAttrInt64 (name, value);
493
+ resize_bind ();
494
+ return pos;
495
+ }
496
+
497
+
498
+ /*
499
+ Set or overwrite uint64_t value of an attribute with given name.
500
+ */
501
+
502
+ int setQueryAttrUInt64 (
503
+ const sql::SQLString &name,
504
+ uint64_t value
505
+ )
506
+ {
507
+ if (!check_query_attr_support ())
508
+ return 0 ;
509
+
510
+ int pos = attrs.setQueryAttrUInt64 (name, value);
511
+ resize_bind ();
512
+ return pos;
513
+ }
514
+
515
+
516
+ /*
517
+ Set null value of an attribute with given name.
518
+ */
519
+
520
+ int setQueryAttrNull (
521
+ const sql::SQLString &name
522
+ )
523
+ {
524
+ if (!check_query_attr_support ())
525
+ return 0 ;
526
+
527
+ int pos = attrs.setQueryAttrNull (name);
528
+ resize_bind ();
529
+ return pos;
530
+ }
531
+
532
+
533
+ bool isAllSet ()
362
534
{
363
535
for (unsigned int i = 0 ; i < value_set.size (); ++i) {
364
536
if (!value_set[i]) {
@@ -453,7 +625,7 @@ class MySQL_ParamBind
453
625
by `getBindObject()`. This starts with empty names for parameters
454
626
(which are anonymous) followed by attribute names.
455
627
*/
456
-
628
+
457
629
std::vector<const char *> getNames ()
458
630
{
459
631
std::vector<const char *> names{bind.size (), nullptr };
@@ -1514,15 +1686,14 @@ MySQL_Prepared_Statement::setResultSetType(sql::ResultSet::enum_type /* type */)
1514
1686
}
1515
1687
/* }}} */
1516
1688
1517
-
1518
1689
/* {{{ MySQL_Prepared_Statement::setQueryAttrBigInt() -U- */
1519
1690
int
1520
1691
MySQL_Prepared_Statement::setQueryAttrBigInt (const sql::SQLString &name, const sql::SQLString& value)
1521
1692
{
1522
1693
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrBigInt" );
1523
1694
CPP_INFO_FMT (" this=%p" , this );
1524
1695
CPP_INFO_FMT (" name=%s value=%s" , name.c_str (), value.c_str ());
1525
- return 0 ;
1696
+ return param_bind-> setQueryAttrBigInt (name, value) ;
1526
1697
}
1527
1698
/* }}} */
1528
1699
@@ -1534,7 +1705,7 @@ MySQL_Prepared_Statement::setQueryAttrBoolean(const sql::SQLString &name, bool v
1534
1705
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrBoolean" );
1535
1706
CPP_INFO_FMT (" this=%p" , this );
1536
1707
CPP_INFO_FMT (" name=%s value=%s" , name.c_str (), value ? " true" : " false" );
1537
- return 0 ;
1708
+ return param_bind-> setQueryAttrBoolean (name, value) ;
1538
1709
}
1539
1710
/* }}} */
1540
1711
@@ -1546,7 +1717,7 @@ MySQL_Prepared_Statement::setQueryAttrDateTime(const sql::SQLString &name, const
1546
1717
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrDateTime" );
1547
1718
CPP_INFO_FMT (" this=%p" , this );
1548
1719
CPP_INFO_FMT (" name=%s value=%s" , name.c_str (), value.c_str ());
1549
- return 0 ;
1720
+ return param_bind-> setQueryAttrDateTime (name, value) ;
1550
1721
}
1551
1722
/* }}} */
1552
1723
@@ -1558,7 +1729,7 @@ MySQL_Prepared_Statement::setQueryAttrDouble(const sql::SQLString &name, double
1558
1729
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrDouble" );
1559
1730
CPP_INFO_FMT (" this=%p" , this );
1560
1731
CPP_INFO_FMT (" name=%s value=%f" , name.c_str (), value);
1561
- return 0 ;
1732
+ return param_bind-> setQueryAttrDouble (name, value) ;
1562
1733
}
1563
1734
/* }}} */
1564
1735
@@ -1570,7 +1741,7 @@ MySQL_Prepared_Statement::setQueryAttrInt(const sql::SQLString &name, int32_t va
1570
1741
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrInt" );
1571
1742
CPP_INFO_FMT (" this=%p" , this );
1572
1743
CPP_INFO_FMT (" name=%s value=%f" , name.c_str (), value);
1573
- return 0 ;
1744
+ return param_bind-> setQueryAttrInt (name, value) ;
1574
1745
}
1575
1746
/* }}} */
1576
1747
@@ -1582,7 +1753,7 @@ MySQL_Prepared_Statement::setQueryAttrUInt(const sql::SQLString &name, uint32_t
1582
1753
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrUInt" );
1583
1754
CPP_INFO_FMT (" this=%p" , this );
1584
1755
CPP_INFO_FMT (" name=%s value=%f" , name.c_str (), value);
1585
- return 0 ;
1756
+ return param_bind-> setQueryAttrUInt (name, value) ;
1586
1757
}
1587
1758
/* }}} */
1588
1759
@@ -1594,7 +1765,7 @@ MySQL_Prepared_Statement::setQueryAttrInt64(const sql::SQLString &name, int64_t
1594
1765
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrInt64" );
1595
1766
CPP_INFO_FMT (" this=%p" , this );
1596
1767
CPP_INFO_FMT (" name=%s value=%f" , name.c_str (), value);
1597
- return 0 ;
1768
+ return param_bind-> setQueryAttrInt64 (name, value) ;
1598
1769
}
1599
1770
/* }}} */
1600
1771
@@ -1606,7 +1777,7 @@ MySQL_Prepared_Statement::setQueryAttrUInt64(const sql::SQLString &name, uint64_
1606
1777
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrUInt64" );
1607
1778
CPP_INFO_FMT (" this=%p" , this );
1608
1779
CPP_INFO_FMT (" name=%s value=%f" , name.c_str (), value);
1609
- return 0 ;
1780
+ return param_bind-> setQueryAttrUInt64 (name, value) ;
1610
1781
}
1611
1782
/* }}} */
1612
1783
@@ -1618,7 +1789,7 @@ MySQL_Prepared_Statement::setQueryAttrNull(const sql::SQLString &name)
1618
1789
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrNull" );
1619
1790
CPP_INFO_FMT (" this=%p" , this );
1620
1791
CPP_INFO_FMT (" name=%s" , name.c_str ());
1621
- return 0 ;
1792
+ return param_bind-> setQueryAttrNull (name) ;
1622
1793
}
1623
1794
/* }}} */
1624
1795
@@ -1648,7 +1819,9 @@ MySQL_Prepared_Statement::setQueryAttrString(const sql::SQLString &name, const s
1648
1819
CPP_ENTER (" MySQL_Prepared_Statement::setQueryAttrString" );
1649
1820
CPP_INFO_FMT (" this=%p" , this );
1650
1821
CPP_INFO_FMT (" name=%s value=%f" , name.c_str (), value.c_str ());
1651
- return 0 ;
1822
+ // If this function was called it means that the user is setting
1823
+ // a string attribute. Therefore the external flag is true.
1824
+ return param_bind->setQueryAttrString (name, value, true );
1652
1825
}
1653
1826
/* }}} */
1654
1827
0 commit comments