Skip to content

Commit 2744813

Browse files
committed
MYCPP-308: FIX CREATE VIEW USING SELECT WITH BIND GIVES ERROR.
Allow TableSel::bind() to update value.
1 parent d144266 commit 2744813

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

cdk/mysqlx/delayed_op.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ class SndViewCrud
749749
return m_has_opts ? this : NULL;
750750
}
751751

752+
const protocol::mysqlx::api::Args_map*
753+
get_args()
754+
{
755+
return m_find->m_param_conv.get();
756+
}
757+
752758

753759
Proto_op* start()
754760
{
@@ -758,11 +764,12 @@ class SndViewCrud
758764
case REPLACE:
759765
return &m_protocol.snd_CreateView(DM, *this, *m_find,
760766
get_cols(), REPLACE == m_type,
761-
get_opts());
767+
get_opts(), get_args());
762768

763769
case UPDATE:
764770
return &m_protocol.snd_ModifyView(DM, *this, *m_find,
765-
get_cols(), get_opts());
771+
get_cols(), get_opts(),
772+
m_find->m_param_conv.get());
766773
default:
767774
assert(false);
768775
return NULL; // quiet compile warnings

devapi/impl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,14 @@ class Op_base
623623

624624
// Parameters
625625

626-
void add_param(const mysqlx::string &name, Value val)
626+
void add_param(const mysqlx::string &name, Value &&val)
627627
{
628-
m_map.emplace(name, std::move(val));
628+
auto el = m_map.emplace(name, std::move(val));
629+
//substitute if exists
630+
if (!el.second)
631+
{
632+
el.first->second = std::move(val);
633+
}
629634
}
630635

631636
void clear_params()

devapi/tests/session-t.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,40 @@ TEST_F(Sess, view)
589589

590590
}
591591

592+
std::cout << "Create view with select bind" << std::endl;
593+
594+
{
595+
TableSelect sel = tbl.select();
596+
sel.where("age = :age").bind("age", 40);
597+
598+
sch.dropView(view_name).execute();
599+
600+
sch.createView(view_name).definedAs(sel).execute();
601+
602+
Table view = sch.getTable(view_name);
603+
604+
RowResult res = view.select().execute();
605+
606+
EXPECT_EQ(1, res.count());
607+
608+
Row row = res.fetchOne();
609+
610+
EXPECT_EQ(40, row.get(1).get<int>());
611+
612+
sel.bind("age", 30);
613+
614+
sch.alterView(view_name).definedAs(sel).execute();
615+
616+
res = view.select().execute();
617+
618+
EXPECT_EQ(1, res.count());
619+
620+
row = res.fetchOne();
621+
622+
EXPECT_EQ(30, row.get(1).get<int>());
623+
624+
}
625+
592626
std::cout << "Drop view" << std::endl;
593627

594628
sch.dropView(view_name).execute();

include/devapi/statement.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace internal {
136136

137137
struct Statement_impl : public Executable_impl
138138
{
139-
virtual void add_param(const string&, Value) = 0;
139+
virtual void add_param(const string&, Value&&) = 0;
140140
};
141141

142142
} // internal
@@ -190,7 +190,7 @@ class Statement
190190
Statement& bind(const string &parameter, Value val)
191191
{
192192
try {
193-
get_impl()->add_param(parameter, val);
193+
get_impl()->add_param(parameter, std::move(val));
194194
return *this;
195195
}
196196
CATCH_AND_WRAP

0 commit comments

Comments
 (0)