This is an automated email from the ASF dual-hosted git repository. isapego pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new 652f37b IGNITE-13793: Implement SQLRowCount for SELECT 652f37b is described below commit 652f37b1709d6ef430eb490b179ecfae2f3d95dd Author: Igor Sapego <isap...@apache.org> AuthorDate: Wed Dec 2 19:38:30 2020 +0300 IGNITE-13793: Implement SQLRowCount for SELECT This closes #8525 --- .../platforms/cpp/odbc-test/src/queries_test.cpp | 38 ++++++++++++++++++++-- modules/platforms/cpp/odbc/src/cursor.cpp | 7 ++-- .../platforms/cpp/odbc/src/query/data_query.cpp | 6 +++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/modules/platforms/cpp/odbc-test/src/queries_test.cpp b/modules/platforms/cpp/odbc-test/src/queries_test.cpp index 6cded84..60333ff 100644 --- a/modules/platforms/cpp/odbc-test/src/queries_test.cpp +++ b/modules/platforms/cpp/odbc-test/src/queries_test.cpp @@ -1629,7 +1629,7 @@ BOOST_AUTO_TEST_CASE(TestErrorMessage) BOOST_AUTO_TEST_CASE(TestAffectedRows) { - Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache"); + Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache;PAGE_SIZE=1024"); const int recordsNum = 100; @@ -1670,7 +1670,41 @@ BOOST_AUTO_TEST_CASE(TestAffectedRows) if (!SQL_SUCCEEDED(ret)) BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt)); - BOOST_CHECK_EQUAL(affected, 0); + BOOST_CHECK_EQUAL(affected, 1024); +} + +BOOST_AUTO_TEST_CASE(TestAffectedRowsOnSelect) +{ + Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache;PAGE_SIZE=123"); + + const int recordsNum = 1000; + + // Inserting values. + InsertTestStrings(recordsNum); + + // Just selecting everything to make sure everything is OK + SQLCHAR selectReq[] = "SELECT _key, strField FROM TestType ORDER BY _key"; + + SQLRETURN ret = SQLExecDirect(stmt, selectReq, sizeof(selectReq)); + + if (!SQL_SUCCEEDED(ret)) + BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt)); + + for (int i = 0; i < 200; ++i) + { + SQLLEN affected = -1; + ret = SQLRowCount(stmt, &affected); + + if (!SQL_SUCCEEDED(ret)) + BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt)); + + BOOST_CHECK_EQUAL(affected, 123); + + ret = SQLFetch(stmt); + + if (!SQL_SUCCEEDED(ret)) + BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt)); + } } BOOST_AUTO_TEST_CASE(TestMultipleSelects) diff --git a/modules/platforms/cpp/odbc/src/cursor.cpp b/modules/platforms/cpp/odbc/src/cursor.cpp index b41f5b1..cee18d8 100644 --- a/modules/platforms/cpp/odbc/src/cursor.cpp +++ b/modules/platforms/cpp/odbc/src/cursor.cpp @@ -21,8 +21,11 @@ namespace ignite { namespace odbc { - Cursor::Cursor(int64_t queryId) : queryId(queryId), currentPage(), - currentPagePos(0), currentRow() + Cursor::Cursor(int64_t queryId) : + queryId(queryId), + currentPage(), + currentPagePos(0), + currentRow() { // No-op. } diff --git a/modules/platforms/cpp/odbc/src/query/data_query.cpp b/modules/platforms/cpp/odbc/src/query/data_query.cpp index a93e5a3..54723a1 100644 --- a/modules/platforms/cpp/odbc/src/query/data_query.cpp +++ b/modules/platforms/cpp/odbc/src/query/data_query.cpp @@ -189,7 +189,11 @@ namespace ignite int64_t DataQuery::AffectedRows() const { int64_t affected = rowsAffectedIdx < rowsAffected.size() ? rowsAffected[rowsAffectedIdx] : 0; - return affected < 0 ? 0 : affected; + + if (affected >= 0) + return affected; + + return connection.GetConfiguration().GetPageSize(); } SqlResult::Type DataQuery::NextResultSet()