Skip to content

Commit

Permalink
IGNITE-13793: Implement SQLRowCount for SELECT
Browse files Browse the repository at this point in the history
This closes #8525
  • Loading branch information
isapego committed Dec 2, 2020
1 parent 338165a commit 77ffffc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
38 changes: 36 additions & 2 deletions modules/platforms/cpp/odbc-test/src/queries_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions modules/platforms/cpp/odbc/src/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
6 changes: 5 additions & 1 deletion modules/platforms/cpp/odbc/src/query/data_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 77ffffc

Please sign in to comment.