Skip to content

Commit 98a7a8a

Browse files
committed
Bug#27727505: Fix multiple results Columns information
1 parent d1072d5 commit 98a7a8a

File tree

4 files changed

+129
-4
lines changed

4 files changed

+129
-4
lines changed

devapi/result.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,7 @@ template<>
574574
internal::Row_result_detail<Columns>::Row_result_detail(common::Result_init &init)
575575
: internal::Result_detail(init)
576576
{
577-
auto &impl = get_impl();
578-
if (impl.next_result())
579-
m_cols.init(impl);
577+
next_result();
580578
}
581579

582580

@@ -600,6 +598,7 @@ void internal::Columns_detail<Column>::init(
600598
const internal::Result_detail::Impl &impl
601599
)
602600
{
601+
clear();
603602
for (col_count_t pos = 0; pos < impl.get_col_count(); ++pos)
604603
{
605604
emplace_back(impl.get_column(pos));

devapi/tests/bugs-t.cc

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,121 @@ TEST_F(Bugs, bug_26962725_double_bind)
140140

141141
EXPECT_EQ(0, myColl.find().execute().count());
142142
}
143+
144+
TEST_F(Bugs, bug_27727505_multiple_results)
145+
{
146+
mysqlx::Session &sess = get_sess();
147+
sess.dropSchema("bug_27727505_multiple_results");
148+
sess.createSchema("bug_27727505_multiple_results");
149+
150+
/* ddl */
151+
std::string strValue = "";
152+
sess.sql("use bug_27727505_multiple_results").execute();
153+
sess.sql("drop table if exists bug_27727505_multiple_results").execute();
154+
sess.sql("create table newtable(f0 int, f1 varchar(1024))").execute();
155+
for(int i=0;i<100;i++)
156+
{
157+
strValue.resize(1024, 'a');
158+
sess.sql("insert into newtable values(?,?)")
159+
.bind(i)
160+
.bind(strValue.c_str())
161+
.execute();
162+
}
163+
sess.sql("drop procedure if exists test").execute();
164+
sess.sql("CREATE PROCEDURE test() BEGIN select f0, f1 from newtable where"
165+
" f0 <= 33; select f0, f1 from newtable where f0 <= 10; END")
166+
.execute();
167+
SqlResult res = sess.sql("call test").execute();
168+
169+
Row row;
170+
int setNo = 0;
171+
do
172+
{
173+
std::vector<Row> rowAll = res.fetchAll();
174+
unsigned int j=0;
175+
for(j = 0;j < rowAll.size();j++)
176+
{
177+
string data = (string)rowAll[j][1];
178+
int num = rowAll[j][0];
179+
if((unsigned int)num!=j || strValue.compare(data))
180+
{
181+
std::stringstream ss;
182+
ss << "Fetch fail in set : "<<setNo<<" row : "<<num ;
183+
throw ss.str();
184+
}
185+
else
186+
{
187+
cout << "Fetch pass in set : "<<setNo<<" row : "<<num << endl;
188+
}
189+
}
190+
if((setNo == 0 && j != 34) || (setNo == 1 && j != 11))
191+
{
192+
throw "Not all results fetched";
193+
}
194+
std::vector<Type> expcType;
195+
expcType.push_back (Type::INT);
196+
expcType.push_back (Type::STRING);
197+
std::vector<string> expcName;
198+
expcName.push_back ("f0");
199+
expcName.push_back ("f1");
200+
201+
const Columns &cc = res.getColumns();
202+
for(unsigned int i=0;i < res.getColumnCount();i++)
203+
{
204+
if(expcName[i].compare(cc[i].getColumnName()))
205+
{
206+
throw "Column Name mismatch";
207+
}
208+
if(expcType[i] != cc[i].getType())
209+
{
210+
throw "Column Type mismatch";
211+
}
212+
if(0 != cc[i].getFractionalDigits())
213+
{
214+
throw "getFractionalDigits is not zero";
215+
}
216+
cout << cc[i].getColumnName() << endl;
217+
cout << cc[i].getType() << endl;
218+
cout << cc[i].isNumberSigned() << endl;
219+
cout << cc[i].getFractionalDigits() << endl;
220+
}
221+
222+
setNo++;
223+
}
224+
while(res.nextResult());
225+
sess.sql("drop procedure if exists test").execute();
226+
sess.sql("CREATE PROCEDURE test() BEGIN select f0, f1 from newtable "
227+
"where f0 > 1000; select f0, f1 from newtable where f0 <= 10;"
228+
" END").execute();
229+
res = sess.sql("call test").execute();
230+
setNo = 0;
231+
do
232+
{
233+
unsigned int j=0;
234+
std::vector<Row> rowAll = res.fetchAll();
235+
for(j = 0;j < rowAll.size();j++)
236+
{
237+
string data = (string)rowAll[j][1];
238+
int num = rowAll[j][0];
239+
if((unsigned int)num!=j || strValue.compare(data))
240+
{
241+
std::stringstream ss;
242+
ss << "Fetch fail in set : "<<setNo<<" row : "<<num ;
243+
throw ss.str();
244+
}
245+
else
246+
{
247+
cout << "Fetch pass in set : "<<setNo<<" row : "<<num << endl;
248+
}
249+
}
250+
if((setNo == 0 && j != 0) || (setNo == 1 && j != 11))
251+
{
252+
throw "Not all results fetched";
253+
}
254+
255+
setNo++;
256+
}
257+
while(res.nextResult());
258+
}
259+
260+

include/mysqlx/devapi/detail/result.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ class Row_result_detail
382382
const Column& get_column(col_count_t) const;
383383
const Columns& get_columns() const;
384384

385+
bool next_result()
386+
{
387+
bool rc = Result_detail::next_result();
388+
if (rc)
389+
m_cols.init(get_impl());
390+
return rc;
391+
}
392+
385393
friend iterator;
386394
friend RowResult;
387395
friend Columns;

include/mysqlx/devapi/result.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ class SqlResult
705705
bool nextResult()
706706
{
707707
try {
708-
return Result_detail::next_result();
708+
return Row_result_detail::next_result();
709709
}
710710
CATCH_AND_WRAP
711711
}

0 commit comments

Comments
 (0)