Skip to content

Commit 1e26f31

Browse files
committed
MYCPP-72: DevAPI methods to define and manage views.
1 parent 426f394 commit 1e26f31

File tree

10 files changed

+948
-23
lines changed

10 files changed

+948
-23
lines changed

devapi/collection_crud.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class Op_collection_add
110110
, m_pos(0)
111111
{}
112112

113+
Executable_impl* clone() const override
114+
{
115+
return new Op_collection_add(*this);
116+
}
117+
113118

114119
void add_json(const mysqlx::string &json) override
115120
{
@@ -365,8 +370,13 @@ class Op_collection_remove
365370
add_where(expr);
366371
}
367372

373+
Executable_impl* clone() const override
374+
{
375+
return new Op_collection_remove(*this);
376+
}
377+
368378

369-
cdk::Reply* send_command()
379+
cdk::Reply* send_command() override
370380
{
371381
return
372382
new cdk::Reply(get_cdk_session().coll_remove(
@@ -430,8 +440,12 @@ class Op_collection_find
430440
add_where(expr);
431441
}
432442

443+
Executable_impl* clone() const override
444+
{
445+
return new Op_collection_find(*this);
446+
}
433447

434-
cdk::Reply* send_command()
448+
cdk::Reply* send_command() override
435449
{
436450
return
437451
new cdk::Reply(get_cdk_session().coll_find(
@@ -530,6 +544,11 @@ class Op_collection_modify
530544
add_where(expr);
531545
}
532546

547+
Executable_impl* clone() const override
548+
{
549+
return new Op_collection_modify(*this);
550+
}
551+
533552
cdk::Reply* send_command() override
534553
{
535554
// Do nothing if no update specifications were added

devapi/impl.h

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ class Op_base
536536
: public Impl
537537
, public cdk::Limit
538538
, public cdk::Param_source
539-
, internal::nocopy
540539
{
541540
protected:
542541

@@ -566,6 +565,14 @@ class Op_base
566565
Op_base(Table &tbl)
567566
: m_sess(&tbl.getSession())
568567
{}
568+
Op_base(const Op_base& other)
569+
: m_sess (other.m_sess )
570+
, m_limit (other.m_limit )
571+
, m_has_limit (other.m_has_limit )
572+
, m_offset (other.m_offset )
573+
, m_has_offset (other.m_has_offset)
574+
, m_map (other.m_map )
575+
{}
569576

570577
virtual ~Op_base()
571578
{}
@@ -760,10 +767,15 @@ class Op_sort
760767

761768
protected:
762769

763-
template <typename T>
764-
Op_sort(T &x) : Op_base<Impl>(x)
770+
template <class X,
771+
typename std::enable_if<
772+
std::is_convertible<X*, DatabaseObject*>::value
773+
>::type* = nullptr
774+
>
775+
Op_sort(X &x) : Op_base<Impl>(x)
765776
{}
766777

778+
767779
public:
768780

769781
cdk::Order_by* get_order_by()
@@ -822,8 +834,12 @@ class Op_having
822834

823835
protected:
824836

825-
template <typename T>
826-
Op_having(T &x) : Op_sort<Impl,PM>(x)
837+
template <class X,
838+
typename std::enable_if<
839+
std::is_convertible<X*, DatabaseObject*>::value
840+
>::type* = nullptr
841+
>
842+
Op_having(X &x) : Op_sort<Impl,PM>(x)
827843
{}
828844

829845
public:
@@ -875,8 +891,12 @@ class Op_group_by
875891

876892
protected:
877893

878-
template <typename T>
879-
Op_group_by(T &x) : Op_having<Impl,PM>(x)
894+
template <class X,
895+
typename std::enable_if<
896+
std::is_convertible<X*, DatabaseObject*>::value
897+
>::type* = nullptr
898+
>
899+
Op_group_by(X &x) : Op_having<Impl,PM>(x)
880900
{}
881901

882902
public:
@@ -932,7 +952,12 @@ class Op_projection
932952

933953
protected:
934954

935-
template <class X>
955+
956+
template <class X,
957+
typename std::enable_if<
958+
std::is_convertible<X*, DatabaseObject*>::value
959+
>::type* = nullptr
960+
>
936961
Op_projection(X &init) : Op_group_by<Impl,PM>(init)
937962
{}
938963

@@ -1052,17 +1077,32 @@ class Op_select : public Base
10521077
{
10531078
protected:
10541079

1080+
mysqlx::string m_where_expr;
10551081
std::unique_ptr<parser::Expression_parser> m_expr;
10561082

1057-
template <class X>
1083+
template <class X,
1084+
typename std::enable_if<
1085+
std::is_convertible<X*, DatabaseObject*>::value
1086+
>::type* = nullptr
1087+
>
10581088
Op_select(X &init) : Base(init)
10591089
{}
10601090

1091+
Op_select(const Op_select &other)
1092+
: Base(other)
1093+
, m_where_expr(other.m_where_expr)
1094+
{
1095+
if (!m_where_expr.empty())
1096+
m_expr.reset(new parser::Expression_parser(PM, m_where_expr));
1097+
}
1098+
10611099
public:
10621100

10631101
void add_where(const mysqlx::string &expr)
10641102
{
1065-
m_expr.reset(new parser::Expression_parser(PM, expr));
1103+
m_where_expr = expr;
1104+
if (!m_where_expr.empty())
1105+
m_expr.reset(new parser::Expression_parser(PM, m_where_expr));
10661106
}
10671107

10681108
cdk::Expression* get_where() const

devapi/session.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,12 +1151,18 @@ struct Op_sql : public Op_base<internal::SqlStatement_impl>
11511151
}
11521152
m_params;
11531153

1154-
void add_param(Value val)
1154+
void add_param(Value val) override
11551155
{
11561156
m_params.m_values.emplace_back(std::move(val));
11571157
}
11581158

1159-
cdk::Reply* send_command()
1159+
Executable_impl* clone() const override
1160+
{
1161+
return new Op_sql(*this);
1162+
}
1163+
1164+
1165+
cdk::Reply* send_command() override
11601166
{
11611167
return new cdk::Reply(
11621168
get_cdk_session().sql(

0 commit comments

Comments
 (0)