Skip to content

Commit 1ce802c

Browse files
committed
CDK: Add new method end_of_reply() to Reply interface.
This method checks if there is more data in the reply, without moving to the next result if it exists. This is needed for correct error reporting, because has_results() starts reading next result (if it exists) and can throw error if server reports one.
1 parent 91cf753 commit 1ce802c

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

cdk/include/mysql/cdk/api/reply.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class Reply
4747

4848
typedef typename Traits::row_count_t row_count_t;
4949

50-
5150
/*
5251
Method has_results() Returns true if there are result sets included in the
5352
reply. To access these result sets one has to create a cursor. The exact
@@ -58,6 +57,7 @@ class Reply
5857
In other words, has_results() informs about result sets that can be still �consumed� and if it returns false it means that all of them have been processed.
5958
Returns true if there are result sets included in the reply.
6059
*/
60+
6161
virtual bool has_results() = 0;
6262

6363

@@ -66,8 +66,17 @@ class Reply
6666
(and thus avoiding allocation of cursor resources). If reply has several
6767
result sets then the next one becomes available.
6868
*/
69+
6970
virtual void skip_result() = 0;
7071

72+
/*
73+
This method returns true if all results in the reply have been consumed.
74+
If it returns false, then there are more results pending, but they do not
75+
need to contain rows (so that creating a new cursor might fail). To check
76+
if there are more rows to consume with a cursor, call has_results().
77+
*/
78+
79+
virtual bool end_of_reply() = 0;
7180

7281
/*
7382
Method has_out_params() informs if this reply contains values for output

cdk/include/mysql/cdk/reply.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ class Reply
6767

6868
// Reply interface
6969

70-
bool has_results()
70+
bool end_of_reply() override
71+
{
72+
assert(m_impl);
73+
return !m_impl->check_results();
74+
}
75+
76+
bool has_results() override
7177
{
7278
/*
7379
If we are in a state after consuming one result set and there is
@@ -79,43 +85,51 @@ class Reply
7985
return m_impl->next_result() || m_impl->check_results();
8086
}
8187

82-
void skip_result()
88+
void skip_result() override
8389
{
8490
m_impl->discard_result();
8591
m_impl->wait();
8692
// Note: this moves to next result set, if present.
8793
m_impl->next_result();
8894
}
8995

90-
row_count_t affected_rows() { return m_impl->affected_rows(); }
91-
row_count_t last_insert_id() { return m_impl->last_insert_id(); }
96+
void discard() override
97+
{ m_impl->discard(); }
98+
99+
row_count_t affected_rows() override
100+
{ return m_impl->affected_rows(); }
101+
102+
row_count_t last_insert_id()
103+
{ return m_impl->last_insert_id(); }
104+
92105
const std::vector<std::string>& generated_ids() const
93106
{ return m_impl->generated_ids(); }
94-
void discard() { m_impl->discard(); }
95107

96108
// Diagnostics interface
97109

98-
unsigned int entry_count(Severity::value level=Severity::ERROR)
110+
unsigned int entry_count(Severity::value level=Severity::ERROR) override
99111
{ return m_impl->entry_count(level); }
100112

101-
Diagnostic_iterator& get_entries(Severity::value level=Severity::ERROR)
113+
Diagnostic_iterator& get_entries(Severity::value level=Severity::ERROR) override
102114
{ return m_impl->get_entries(level); }
103115

104-
const Error& get_error()
116+
const Error& get_error() override
105117
{ return m_impl->get_error(); }
106118

107119
// Async_op interface
108120

109-
bool is_completed() const { return m_impl->is_completed(); }
121+
bool is_completed() const override
122+
{ return m_impl->is_completed(); }
110123

111124
private:
112125

113126
// Async_op
114127

115-
bool do_cont() { return m_impl->cont(); }
116-
void do_wait() { return m_impl->wait(); }
117-
void do_cancel() { return m_impl->cancel(); }
118-
const cdk::api::Event_info* get_event_info() const
128+
bool do_cont() override { return m_impl->cont(); }
129+
void do_wait() override { return m_impl->wait(); }
130+
void do_cancel() override { return m_impl->cancel(); }
131+
132+
const cdk::api::Event_info* get_event_info() const override
119133
{ return m_impl->get_event_info(); }
120134

121135

0 commit comments

Comments
 (0)