Skip to content

Commit 0793598

Browse files
committed
IGNITE-16359 ODBC: Fix incorrect queries handling with empty results - Fixes apache#9778.
Signed-off-by: Ivan Daschinsky <[email protected]>
1 parent 7bbf2c3 commit 0793598

File tree

5 files changed

+42
-103
lines changed

5 files changed

+42
-103
lines changed

modules/platforms/cpp/odbc-test/src/streaming_test.cpp

Lines changed: 36 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ struct StreamingTestSuiteFixture : odbc::OdbcTestSuite
262262
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
263263
}
264264

265+
// Performs additional checks for set streaming parameter query.
266+
void ExecSetStreamingQuery(const std::string& query) {
267+
SQLRETURN ret = ExecQuery(query);
268+
269+
if (!SQL_SUCCEEDED(ret))
270+
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
271+
272+
SQLSMALLINT columnCount;
273+
ret = SQLNumResultCols(stmt, &columnCount);
274+
275+
if (!SQL_SUCCEEDED(ret))
276+
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
277+
278+
BOOST_ASSERT(columnCount == 0);
279+
}
280+
265281
/** Node started during the test. */
266282
Ignite grid;
267283

@@ -275,21 +291,15 @@ BOOST_AUTO_TEST_CASE(TestStreamingSimple)
275291
{
276292
Connect("DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=11110;SCHEMA=cache");
277293

278-
SQLRETURN res = ExecQuery("set streaming on batch_size 100 flush_frequency 100");
279-
280-
if (res != SQL_SUCCESS)
281-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
294+
ExecSetStreamingQuery("set streaming on batch_size 100 flush_frequency 100");
282295

283296
InsertTestStrings(0, 10);
284297

285298
BOOST_CHECK_EQUAL(cache.Size(), 0);
286299

287300
InsertTestStrings(10, 110);
288301

289-
res = ExecQuery("set streaming off");
290-
291-
if (res != SQL_SUCCESS)
292-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
302+
ExecSetStreamingQuery("set streaming off");
293303

294304
BOOST_CHECK_EQUAL(cache.Size(), 110);
295305

@@ -300,7 +310,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingAllOptions)
300310
{
301311
Connect("DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=11110;SCHEMA=cache");
302312

303-
SQLRETURN res = ExecQuery(
313+
ExecSetStreamingQuery(
304314
"set streaming 1 "
305315
"allow_overwrite on "
306316
"batch_size 512 "
@@ -309,19 +319,13 @@ BOOST_AUTO_TEST_CASE(TestStreamingAllOptions)
309319
"flush_frequency 100 "
310320
"ordered");
311321

312-
if (res != SQL_SUCCESS)
313-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
314-
315322
InsertTestStrings(0, 10);
316323

317324
BOOST_CHECK_EQUAL(cache.Size(), 0);
318325

319326
InsertTestStrings(0, 512);
320327

321-
res = ExecQuery("set streaming off");
322-
323-
if (res != SQL_SUCCESS)
324-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
328+
ExecSetStreamingQuery("set streaming off");
325329

326330
BOOST_CHECK_EQUAL(cache.Size(), 512);
327331
}
@@ -330,21 +334,15 @@ BOOST_AUTO_TEST_CASE(TestStreamingNotAllowedOverwrite)
330334
{
331335
Connect("DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=11110;SCHEMA=cache");
332336

333-
SQLRETURN res = ExecQuery("set streaming 1 allow_overwrite off batch_size 10");
334-
335-
if (res != SQL_SUCCESS)
336-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
337+
ExecSetStreamingQuery("set streaming 1 allow_overwrite off batch_size 10");
337338

338339
InsertTestStrings(0, 10);
339340

340341
BOOST_CHECK_EQUAL(cache.Size(), 0);
341342

342343
InsertTestStrings(0, 10);
343344

344-
res = ExecQuery("set streaming off");
345-
346-
if (res != SQL_SUCCESS)
347-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
345+
ExecSetStreamingQuery("set streaming off");
348346

349347
BOOST_CHECK_EQUAL(cache.Size(), 10);
350348
}
@@ -353,10 +351,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingReset)
353351
{
354352
Connect("DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=11110;SCHEMA=cache");
355353

356-
SQLRETURN res = ExecQuery("set streaming 1 batch_size 100 flush_frequency 1000");
357-
358-
if (res != SQL_SUCCESS)
359-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
354+
ExecSetStreamingQuery("set streaming 1 batch_size 100 flush_frequency 1000");
360355

361356
InsertTestStrings(0, 10);
362357

@@ -366,21 +361,15 @@ BOOST_AUTO_TEST_CASE(TestStreamingReset)
366361

367362
BOOST_CHECK_EQUAL(cache.Size(), 0);
368363

369-
res = ExecQuery("set streaming 1 batch_size 10 flush_frequency 100");
370-
371-
if (res != SQL_SUCCESS)
372-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
364+
ExecSetStreamingQuery("set streaming 1 batch_size 10 flush_frequency 100");
373365

374366
BOOST_CHECK_EQUAL(cache.Size(), 20);
375367

376368
InsertTestStrings(20, 50);
377369

378370
BOOST_CHECK_EQUAL(cache.Size(), 20);
379371

380-
res = ExecQuery("set streaming 0");
381-
382-
if (res != SQL_SUCCESS)
383-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
372+
ExecSetStreamingQuery("set streaming 0");
384373

385374
BOOST_CHECK_EQUAL(cache.Size(), 50);
386375
}
@@ -389,10 +378,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingClosingStatement)
389378
{
390379
Connect("DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=11110;SCHEMA=cache");
391380

392-
SQLRETURN res = ExecQuery("set streaming 1 batch_size 100 flush_frequency 1000");
393-
394-
if (res != SQL_SUCCESS)
395-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
381+
ExecSetStreamingQuery("set streaming 1 batch_size 100 flush_frequency 1000");
396382

397383
InsertTestStrings(0, 10);
398384

@@ -402,15 +388,12 @@ BOOST_AUTO_TEST_CASE(TestStreamingClosingStatement)
402388

403389
BOOST_CHECK_EQUAL(cache.Size(), 0);
404390

405-
res = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
391+
SQLRETURN res = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
406392

407393
if (res != SQL_SUCCESS)
408394
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
409395

410-
res = ExecQuery("set streaming 0");
411-
412-
if (res != SQL_SUCCESS)
413-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
396+
ExecSetStreamingQuery("set streaming 0");
414397

415398
BOOST_CHECK_EQUAL(cache.Size(), 10);
416399
}
@@ -426,10 +409,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingSeveralStatements)
426409
if (res != SQL_SUCCESS)
427410
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
428411

429-
res = ExecQuery("set streaming 1 batch_size 100 flush_frequency 1000");
430-
431-
if (res != SQL_SUCCESS)
432-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
412+
ExecSetStreamingQuery("set streaming 1 batch_size 100 flush_frequency 1000");
433413

434414
InsertTestStrings(0, 10);
435415

@@ -441,10 +421,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingSeveralStatements)
441421

442422
BOOST_CHECK_EQUAL(cache.Size(), 0);
443423

444-
res = ExecQuery("set streaming 0");
445-
446-
if (res != SQL_SUCCESS)
447-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
424+
ExecSetStreamingQuery("set streaming 0");
448425

449426
BOOST_CHECK_EQUAL(cache.Size(), 50);
450427

@@ -465,10 +442,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingSeveralStatementsClosing)
465442
if (res != SQL_SUCCESS)
466443
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
467444

468-
res = ExecQuery("set streaming 1 batch_size 100 flush_frequency 1000");
469-
470-
if (res != SQL_SUCCESS)
471-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
445+
ExecSetStreamingQuery("set streaming 1 batch_size 100 flush_frequency 1000");
472446

473447
InsertTestStrings(0, 10);
474448

@@ -497,10 +471,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingSeveralStatementsClosing)
497471
if (res != SQL_SUCCESS)
498472
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
499473

500-
res = ExecQuery("set streaming 0");
501-
502-
if (res != SQL_SUCCESS)
503-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
474+
ExecSetStreamingQuery("set streaming 0");
504475

505476
BOOST_CHECK_EQUAL(cache.Size(), 50);
506477
}
@@ -516,10 +487,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingDifferentStatements)
516487
if (res != SQL_SUCCESS)
517488
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
518489

519-
res = ExecQuery("set streaming 1 batch_size 100 flush_frequency 1000");
520-
521-
if (res != SQL_SUCCESS)
522-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
490+
ExecSetStreamingQuery("set streaming 1 batch_size 100 flush_frequency 1000");
523491

524492
InsertTestStrings2(0, 10);
525493

@@ -538,10 +506,7 @@ BOOST_AUTO_TEST_CASE(TestStreamingDifferentStatements)
538506

539507
BOOST_CHECK_EQUAL(cache.Size(), 0);
540508

541-
res = ExecQuery("set streaming 0");
542-
543-
if (res != SQL_SUCCESS)
544-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
509+
ExecSetStreamingQuery("set streaming 0");
545510

546511
BOOST_CHECK_EQUAL(cache.Size(), 50);
547512

@@ -558,20 +523,11 @@ BOOST_AUTO_TEST_CASE(TestStreamingManyObjects)
558523

559524
Connect("DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=11110;SCHEMA=cache");
560525

561-
SQLRETURN res = ExecQuery("set streaming on");
562-
563-
if (res != SQL_SUCCESS)
564-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
526+
ExecSetStreamingQuery("set streaming on");
565527

566528
InsertTestStrings(0, OBJECT_NUM);
567529

568-
if (res != SQL_SUCCESS)
569-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
570-
571-
res = ExecQuery("set streaming 0");
572-
573-
if (res != SQL_SUCCESS)
574-
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
530+
ExecSetStreamingQuery("set streaming 0");
575531

576532
BOOST_CHECK_EQUAL(cache.Size(), OBJECT_NUM);
577533

modules/platforms/cpp/odbc/include/ignite/odbc/query/internal_query.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ namespace ignite
113113
return SqlResult::AI_SUCCESS;
114114
}
115115

116-
/**
117-
* Get column metadata.
118-
*
119-
* @return Column metadata.
120-
*/
121-
virtual const meta::ColumnMetaVector* GetMeta()
122-
{
123-
return 0;
124-
}
125-
126116
/**
127117
* Check if data is available.
128118
*

modules/platforms/cpp/odbc/include/ignite/odbc/query/query.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ namespace ignite
120120
*
121121
* @return Column metadata.
122122
*/
123-
virtual const meta::ColumnMetaVector* GetMeta() = 0;
123+
virtual const meta::ColumnMetaVector* GetMeta()
124+
{
125+
static const meta::ColumnMetaVector empty;
126+
127+
return &empty;
128+
}
124129

125130
/**
126131
* Check if data is available.

modules/platforms/cpp/odbc/include/ignite/odbc/query/streaming_query.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ namespace ignite
6060
*/
6161
virtual SqlResult::Type Execute();
6262

63-
/**
64-
* Get column metadata.
65-
*
66-
* @return Column metadata.
67-
*/
68-
virtual const meta::ColumnMetaVector* GetMeta();
69-
7063
/**
7164
* Fetch next result row to application buffers.
7265
*

modules/platforms/cpp/odbc/src/query/streaming_query.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ namespace ignite
4949
return connection.GetStreamingContext().Execute(sql, params);
5050
}
5151

52-
const meta::ColumnMetaVector* StreamingQuery::GetMeta()
53-
{
54-
return 0;
55-
}
56-
5752
SqlResult::Type StreamingQuery::FetchNextRow(app::ColumnBindingMap&)
5853
{
5954
return SqlResult::AI_NO_DATA;

0 commit comments

Comments
 (0)