Skip to content

Commit be13399

Browse files
author
Bogdan Degtyariov
committed
Improved processing of pending warning and errors
1 parent 2917dba commit be13399

File tree

3 files changed

+94
-21
lines changed

3 files changed

+94
-21
lines changed

xapi/mysqlx_cc_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ typedef struct mysqlx_result_struct : public Mysqlx_diag
130130
std::vector<mysqlx_row_t*> m_row_set;
131131
std::vector<mysqlx_doc_t*> m_doc_set;
132132
cdk::scoped_ptr<mysqlx_error_t> m_current_warning;
133+
cdk::scoped_ptr<mysqlx_error_t> m_current_error;
133134

134135
// We need column names in UTF8
135136
std::vector<Column_info> m_col_info;
136137
uint32_t m_filter_mask;
137-
cdk::foundation::Diagnostic_iterator *m_warning_iter;
138+
uint32_t m_current_warning_index;
139+
uint32_t m_current_error_index;
138140

139141
std::vector<std::string> m_doc_id_list;
140142
uint64_t m_current_id_index;
@@ -187,6 +189,8 @@ typedef struct mysqlx_result_struct : public Mysqlx_diag
187189

188190
mysqlx_error_t *get_next_warning();
189191

192+
virtual mysqlx_error_t *get_error();
193+
190194
/*
191195
Read the next row from the result set and advance the cursor position
192196
*/

xapi/result.cc

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ bool mysqlx_result_t::init_result(bool wait)
111111
if (wait)
112112
m_reply.wait();
113113

114-
m_warning_iter = NULL;
114+
m_current_warning_index = 0;
115+
m_current_error_index = 0;
115116

116117
if (m_reply.has_results())
117118
{
@@ -537,19 +538,53 @@ const char * mysqlx_result_t::get_next_doc_id()
537538
return m_doc_id_list[m_current_id_index - 1].data();
538539
}
539540

541+
mysqlx_error_t * mysqlx_result_t::get_error()
542+
{
543+
mysqlx_error_t *err = Mysqlx_diag::get_error();
544+
545+
if (err)
546+
return err; // return the error if there is any
547+
548+
// Otherwise the error might be pending
549+
m_reply.wait();
550+
if (m_reply.entry_count() > m_current_error_index)
551+
{
552+
cdk::foundation::Diagnostic_iterator *m_iter;
553+
uint32_t num = 0;
554+
m_iter = &(m_reply.get_entries(cdk::foundation::api::Severity::ERROR));
555+
556+
while (m_iter->next())
557+
{
558+
if (++num > m_current_error_index)
559+
{
560+
m_current_error_index = num;
561+
m_current_error.reset(new mysqlx_error_t(m_iter->entry().get_error(), true));
562+
return m_current_error.get();
563+
}
564+
}
565+
}
566+
567+
return NULL;
568+
}
569+
540570

541571
mysqlx_error_t * mysqlx_result_t::get_next_warning()
542572
{
543-
if (get_warning_count())
573+
if (get_warning_count() > m_current_warning_index)
544574
{
545-
if (m_warning_iter == NULL)
546-
m_warning_iter = &(m_reply.get_entries(cdk::foundation::api::Severity::WARNING));
547-
if (m_warning_iter->next())
548-
m_current_warning.reset(new mysqlx_error_t(m_warning_iter->entry().get_error(), true));
549-
else
550-
m_current_warning.reset(NULL);
575+
cdk::foundation::Diagnostic_iterator *m_iter;
576+
uint32_t num = 0;
577+
m_iter = &(m_reply.get_entries(cdk::foundation::api::Severity::WARNING));
551578

552-
return m_current_warning.get();
579+
while (m_iter->next())
580+
{
581+
if (++num > m_current_warning_index)
582+
{
583+
m_current_warning_index = num;
584+
m_current_warning.reset(new mysqlx_error_t(m_iter->entry().get_error(), true));
585+
return m_current_warning.get();
586+
}
587+
}
553588
}
554589

555590
return NULL;

xapi/tests/xapi_crud-t.cc

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ TEST_F(xapi_bugs, collection_id_test)
21752175
{
21762176
SKIP_IF_NO_XPLUGIN
21772177

2178-
mysqlx_result_t *res;
2178+
mysqlx_result_t *res;
21792179
mysqlx_stmt_t *stmt;
21802180
mysqlx_schema_t *schema;
21812181
mysqlx_collection_t *collection;
@@ -2230,19 +2230,53 @@ TEST_F(xapi_bugs, collection_id_test)
22302230

22312231
switch (i)
22322232
{
2233-
case 0: // just _id in the JSON
2234-
EXPECT_TRUE(strstr(json_string, "a_key") == NULL);
2233+
case 0: // just _id in the JSON
2234+
EXPECT_TRUE(strstr(json_string, "a_key") == NULL);
22352235
break;
2236-
case 1: // { "a_key" : 100}
2237-
EXPECT_TRUE(strstr(json_string, "\"a_key\": 100") != NULL);
2238-
break;
2239-
case 2: // { "a_key" : 200, "_id" : "111222333"}
2240-
EXPECT_TRUE(strstr(json_string, "\"a_key\": 200") != NULL);
2241-
break;
2242-
default: // no more documents in the result
2243-
FAIL();
2236+
case 1: // { "a_key" : 100}
2237+
EXPECT_TRUE(strstr(json_string, "\"a_key\": 100") != NULL);
2238+
break;
2239+
case 2: // { "a_key" : 200, "_id" : "111222333"}
2240+
EXPECT_TRUE(strstr(json_string, "\"a_key\": 200") != NULL);
2241+
break;
2242+
default: // no more documents in the result
2243+
FAIL();
22442244
}
22452245

22462246
++i;
22472247
}
22482248
}
2249+
2250+
TEST_F(xapi_bugs, myc_352_stored_proc_err)
2251+
{
2252+
SKIP_IF_NO_XPLUGIN
2253+
2254+
mysqlx_result_t *res;
2255+
const char *schema_name = "cc_crud_test";
2256+
const char *errmsg = NULL;
2257+
2258+
AUTHENTICATE();
2259+
2260+
mysqlx_schema_drop(get_session(), schema_name);
2261+
EXPECT_EQ(RESULT_OK, mysqlx_schema_create(get_session(), schema_name));
2262+
2263+
res = mysqlx_sql(get_session(),
2264+
"CREATE PROCEDURE cc_crud_test.myc_352(d INT)" \
2265+
" BEGIN" \
2266+
" select 1, 2, 3;" \
2267+
" IF d = 0 THEN " \
2268+
" BEGIN " \
2269+
" select point(1, 0) / point(1, 2); " \
2270+
" END; " \
2271+
" END IF; " \
2272+
" select 'abc', 1.0; " \
2273+
" END", MYSQLX_NULL_TERMINATED);
2274+
2275+
res = mysqlx_sql(get_session(), "CALL cc_crud_test.myc_352(0)",
2276+
MYSQLX_NULL_TERMINATED);
2277+
2278+
EXPECT_EQ(RESULT_OK, mysqlx_store_result(res, NULL));
2279+
EXPECT_EQ(RESULT_ERROR, mysqlx_next_result(res));
2280+
EXPECT_TRUE((errmsg = mysqlx_error_message(res)) != NULL);
2281+
printf("\nExpected error: %s\n", errmsg);
2282+
}

0 commit comments

Comments
 (0)