Skip to content

Commit bc6d2df

Browse files
author
Bogdan Degtyariov
committed
Merge branch 'wl15968' into trunk
Change-Id: I5deea86ed48720565eb5e1c003971fc57e5e8783
2 parents 06982c5 + 68a0f85 commit bc6d2df

File tree

3 files changed

+295
-28
lines changed

3 files changed

+295
-28
lines changed

jdbc/driver/mysql_prepared_statement.cpp

Lines changed: 201 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,35 @@ class MySQL_ParamBind
321321
}
322322
}
323323

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+
324350
/*
325351
Set or overwrite existing value of an attribute with given name.
326-
352+
327353
If `is_external` is false then existing external value will not
328354
be changed.
329355
*/
@@ -334,31 +360,177 @@ class MySQL_ParamBind
334360
bool is_external
335361
)
336362
{
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())
344364
return 0;
345-
}
346365

347366
int pos = attrs.setQueryAttrString(name, value, is_external);
367+
resize_bind();
368+
return pos;
369+
}
348370

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-
*/
353371

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;
356455

456+
int pos = attrs.setQueryAttrInt(name, value);
457+
resize_bind();
357458
return pos;
358459
}
359460

360461

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()
362534
{
363535
for (unsigned int i = 0; i < value_set.size(); ++i) {
364536
if (!value_set[i]) {
@@ -453,7 +625,7 @@ class MySQL_ParamBind
453625
by `getBindObject()`. This starts with empty names for parameters
454626
(which are anonymous) followed by attribute names.
455627
*/
456-
628+
457629
std::vector<const char*> getNames()
458630
{
459631
std::vector<const char*> names{bind.size(), nullptr};
@@ -1514,15 +1686,14 @@ MySQL_Prepared_Statement::setResultSetType(sql::ResultSet::enum_type /* type */)
15141686
}
15151687
/* }}} */
15161688

1517-
15181689
/* {{{ MySQL_Prepared_Statement::setQueryAttrBigInt() -U- */
15191690
int
15201691
MySQL_Prepared_Statement::setQueryAttrBigInt(const sql::SQLString &name, const sql::SQLString& value)
15211692
{
15221693
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrBigInt");
15231694
CPP_INFO_FMT("this=%p", this);
15241695
CPP_INFO_FMT("name=%s value=%s", name.c_str(), value.c_str());
1525-
return 0;
1696+
return param_bind->setQueryAttrBigInt(name, value);
15261697
}
15271698
/* }}} */
15281699

@@ -1534,7 +1705,7 @@ MySQL_Prepared_Statement::setQueryAttrBoolean(const sql::SQLString &name, bool v
15341705
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrBoolean");
15351706
CPP_INFO_FMT("this=%p", this);
15361707
CPP_INFO_FMT("name=%s value=%s", name.c_str(), value ? "true" : "false");
1537-
return 0;
1708+
return param_bind->setQueryAttrBoolean(name, value);
15381709
}
15391710
/* }}} */
15401711

@@ -1546,7 +1717,7 @@ MySQL_Prepared_Statement::setQueryAttrDateTime(const sql::SQLString &name, const
15461717
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrDateTime");
15471718
CPP_INFO_FMT("this=%p", this);
15481719
CPP_INFO_FMT("name=%s value=%s", name.c_str(), value.c_str());
1549-
return 0;
1720+
return param_bind->setQueryAttrDateTime(name, value);
15501721
}
15511722
/* }}} */
15521723

@@ -1558,7 +1729,7 @@ MySQL_Prepared_Statement::setQueryAttrDouble(const sql::SQLString &name, double
15581729
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrDouble");
15591730
CPP_INFO_FMT("this=%p", this);
15601731
CPP_INFO_FMT("name=%s value=%f", name.c_str(), value);
1561-
return 0;
1732+
return param_bind->setQueryAttrDouble(name, value);
15621733
}
15631734
/* }}} */
15641735

@@ -1570,7 +1741,7 @@ MySQL_Prepared_Statement::setQueryAttrInt(const sql::SQLString &name, int32_t va
15701741
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrInt");
15711742
CPP_INFO_FMT("this=%p", this);
15721743
CPP_INFO_FMT("name=%s value=%f", name.c_str(), value);
1573-
return 0;
1744+
return param_bind->setQueryAttrInt(name, value);
15741745
}
15751746
/* }}} */
15761747

@@ -1582,7 +1753,7 @@ MySQL_Prepared_Statement::setQueryAttrUInt(const sql::SQLString &name, uint32_t
15821753
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrUInt");
15831754
CPP_INFO_FMT("this=%p", this);
15841755
CPP_INFO_FMT("name=%s value=%f", name.c_str(), value);
1585-
return 0;
1756+
return param_bind->setQueryAttrUInt(name, value);
15861757
}
15871758
/* }}} */
15881759

@@ -1594,7 +1765,7 @@ MySQL_Prepared_Statement::setQueryAttrInt64(const sql::SQLString &name, int64_t
15941765
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrInt64");
15951766
CPP_INFO_FMT("this=%p", this);
15961767
CPP_INFO_FMT("name=%s value=%f", name.c_str(), value);
1597-
return 0;
1768+
return param_bind->setQueryAttrInt64(name, value);
15981769
}
15991770
/* }}} */
16001771

@@ -1606,7 +1777,7 @@ MySQL_Prepared_Statement::setQueryAttrUInt64(const sql::SQLString &name, uint64_
16061777
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrUInt64");
16071778
CPP_INFO_FMT("this=%p", this);
16081779
CPP_INFO_FMT("name=%s value=%f", name.c_str(), value);
1609-
return 0;
1780+
return param_bind->setQueryAttrUInt64(name, value);
16101781
}
16111782
/* }}} */
16121783

@@ -1618,7 +1789,7 @@ MySQL_Prepared_Statement::setQueryAttrNull(const sql::SQLString &name)
16181789
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrNull");
16191790
CPP_INFO_FMT("this=%p", this);
16201791
CPP_INFO_FMT("name=%s", name.c_str());
1621-
return 0;
1792+
return param_bind->setQueryAttrNull(name);
16221793
}
16231794
/* }}} */
16241795

@@ -1648,7 +1819,9 @@ MySQL_Prepared_Statement::setQueryAttrString(const sql::SQLString &name, const s
16481819
CPP_ENTER("MySQL_Prepared_Statement::setQueryAttrString");
16491820
CPP_INFO_FMT("this=%p", this);
16501821
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);
16521825
}
16531826
/* }}} */
16541827

0 commit comments

Comments
 (0)