Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Externals">
<UniqueIdentifier>{cc75fc86-c08d-428a-8ae3-f9979e4588ab}</UniqueIdentifier>
</Filter>
<Filter Include="Code\teamcity">
<UniqueIdentifier>{5438a56d-1009-412a-86e3-ceb1112af275}</UniqueIdentifier>
</Filter>
<Filter Include="External">
<UniqueIdentifier>{cc75fc86-c08d-428a-8ae3-f9979e4588ab}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\configuration_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\utility.cpp">
<Filter>Externals</Filter>
</ClCompile>
<ClCompile Include="..\..\src\connection_info_test.cpp">
<Filter>Code</Filter>
</ClCompile>
Expand All @@ -37,38 +34,41 @@
<ClCompile Include="..\..\src\row_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\row.cpp">
<Filter>Externals</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\result_page.cpp">
<Filter>Externals</Filter>
</ClCompile>
<ClCompile Include="..\..\src\cursor_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\cursor.cpp">
<Filter>Externals</Filter>
</ClCompile>
<ClCompile Include="..\..\src\utility_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\config\configuration.cpp">
<Filter>Externals</Filter>
<ClCompile Include="..\..\src\column_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\config\connection_info.cpp">
<Filter>Externals</Filter>
<ClCompile Include="..\..\..\odbc\src\app\application_data_buffer.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\app\application_data_buffer.cpp">
<Filter>Externals</Filter>
<ClCompile Include="..\..\..\odbc\src\column.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\decimal.cpp">
<Filter>Externals</Filter>
<ClCompile Include="..\..\..\odbc\src\config\configuration.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc-driver\src\column.cpp">
<Filter>Externals</Filter>
<ClCompile Include="..\..\..\odbc\src\config\connection_info.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\src\column_test.cpp">
<Filter>Code</Filter>
<ClCompile Include="..\..\..\odbc\src\cursor.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc\src\decimal.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc\src\result_page.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc\src\row.cpp">
<Filter>External</Filter>
</ClCompile>
<ClCompile Include="..\..\..\odbc\src\utility.cpp">
<Filter>External</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down
55 changes: 47 additions & 8 deletions modules/platforms/cpp/odbc-test/src/cursor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ void CheckCursorNeedUpdate(Cursor& cursor)
{
BOOST_REQUIRE(cursor.NeedDataUpdate());

BOOST_REQUIRE(cursor.HasNext());
BOOST_REQUIRE(cursor.HasData());

BOOST_REQUIRE(!cursor.Increment());

BOOST_REQUIRE(!cursor.GetRow());
}

void CheckCursorReady(Cursor& cursor)
{
BOOST_REQUIRE(!cursor.NeedDataUpdate());

BOOST_REQUIRE(cursor.HasNext());
BOOST_REQUIRE(cursor.HasData());

BOOST_REQUIRE(cursor.GetRow());
}
Expand All @@ -94,11 +96,11 @@ void CheckCursorEnd(Cursor& cursor)
{
BOOST_REQUIRE(!cursor.NeedDataUpdate());

BOOST_REQUIRE(!cursor.HasNext());
BOOST_REQUIRE(!cursor.HasData());

BOOST_REQUIRE(!cursor.Increment());

BOOST_REQUIRE(cursor.GetRow());
BOOST_REQUIRE(!cursor.GetRow());
}

BOOST_AUTO_TEST_SUITE(CursorTestSuite)
Expand Down Expand Up @@ -126,7 +128,7 @@ BOOST_AUTO_TEST_CASE(TestCursorLast)

CheckCursorReady(cursor);

for (int32_t i = 0; i < pageSize - 1; ++i)
for (int32_t i = 0; i < pageSize; ++i)
BOOST_REQUIRE(cursor.Increment());

CheckCursorEnd(cursor);
Expand All @@ -144,10 +146,12 @@ BOOST_AUTO_TEST_CASE(TestCursorUpdate)

BOOST_REQUIRE(cursor.GetQueryId() == testQueryId);

CheckCursorReady(cursor);
for (int32_t i = 0; i < pageSize; ++i)
{
CheckCursorReady(cursor);

for (int32_t i = 0; i < pageSize - 1; ++i)
BOOST_REQUIRE(cursor.Increment());
}

CheckCursorNeedUpdate(cursor);

Expand All @@ -157,10 +161,45 @@ BOOST_AUTO_TEST_CASE(TestCursorUpdate)

CheckCursorReady(cursor);

for (int32_t i = 0; i < pageSize - 1; ++i)
for (int32_t i = 0; i < pageSize; ++i)
{
CheckCursorReady(cursor);

BOOST_REQUIRE(cursor.Increment());
}

CheckCursorEnd(cursor);
}

BOOST_AUTO_TEST_CASE(TestCursorUpdateOneRow)
{
Cursor cursor(testQueryId);

std::auto_ptr<ResultPage> resultPage = CreateTestPage(false, 1);

cursor.UpdateData(resultPage);

BOOST_REQUIRE(cursor.GetQueryId() == testQueryId);

CheckCursorReady(cursor);

BOOST_REQUIRE(cursor.Increment());

CheckCursorNeedUpdate(cursor);

BOOST_REQUIRE(!cursor.Increment());

resultPage = CreateTestPage(true, 1);

cursor.UpdateData(resultPage);

CheckCursorReady(cursor);

BOOST_REQUIRE(cursor.Increment());

CheckCursorEnd(cursor);

BOOST_REQUIRE(!cursor.Increment());
}

BOOST_AUTO_TEST_SUITE_END()
41 changes: 41 additions & 0 deletions modules/platforms/cpp/odbc-test/src/row_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ BOOST_AUTO_TEST_CASE(TestRowMoveToNext)
for (size_t i = 0; i < rowNum - 1; ++i)
{
BOOST_REQUIRE(row.GetSize() == 4);

BOOST_REQUIRE(row.MoveToNext());
}

BOOST_REQUIRE(row.GetSize() == 4);
}

BOOST_AUTO_TEST_CASE(TestRowRead)
Expand All @@ -162,6 +165,44 @@ BOOST_AUTO_TEST_CASE(TestRowRead)

BOOST_REQUIRE(row.MoveToNext());
}

CheckRowData(row, rowNum - 1);
}

BOOST_AUTO_TEST_CASE(TestSingleRow)
{
ignite::impl::interop::InteropUnpooledMemory mem(4096);

const size_t rowNum = 1;

FillMemWithData(mem, 1);

Row row(mem);

BOOST_REQUIRE(row.GetSize() == 4);

CheckRowData(row, 0);
}

BOOST_AUTO_TEST_CASE(TestTwoRows)
{
ignite::impl::interop::InteropUnpooledMemory mem(4096);

const size_t rowNum = 2;

FillMemWithData(mem, 2);

Row row(mem);

BOOST_REQUIRE(row.GetSize() == 4);

CheckRowData(row, 0);

BOOST_REQUIRE(row.MoveToNext());

BOOST_REQUIRE(row.GetSize() == 4);

CheckRowData(row, 1);
}

BOOST_AUTO_TEST_SUITE_END()
15 changes: 11 additions & 4 deletions modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,28 @@ namespace ignite

/**
* Move cursor to the next result row.
*
* @return False if data update required or no more data.
*/
bool Increment();

/**
* Check if the cursor needs data update.
*
* @return True if the cursor needs data update.
*/
bool NeedDataUpdate() const;

/**
* Check if the cursor has next row row.
* @return True if the cursor has next row row.
* Check if the cursor has data.
*
* @return True if the cursor has data.
*/
bool HasNext() const;
bool HasData() const;

/**
* Get query ID.
*
* @return Query ID.
*/
int64_t GetQueryId() const
Expand All @@ -77,13 +81,16 @@ namespace ignite

/**
* Update current cursor page data.
*
* @param newPage New result page.
*/
void UpdateData(std::auto_ptr<ResultPage>& newPage);

/**
* Get current row.
* @return Current row.
*
* @return Current row. Returns zero if cursor needs data update or
* has no more data.
*/
Row* GetRow();

Expand Down
16 changes: 10 additions & 6 deletions modules/platforms/cpp/odbc/src/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ namespace ignite
{
++currentPagePos;

Row *row = currentRow.get();

if (row)
row->MoveToNext();
if (currentPagePos == currentPage->GetSize())
currentRow.reset();
else
{
Row *row = currentRow.get();

if (row)
row->MoveToNext();
}
return true;
}
return false;
Expand All @@ -54,7 +58,7 @@ namespace ignite
currentPagePos == currentPage->GetSize());
}

bool Cursor::HasNext() const
bool Cursor::HasData() const
{
return !currentPage.get() || !currentPage->IsLast() ||
currentPagePos < currentPage->GetSize();
Expand All @@ -64,7 +68,7 @@ namespace ignite
{
currentPage = newPage;

currentPagePos = 1;
currentPagePos = 0;

currentRow.reset(new Row(currentPage->GetData()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace ignite
}
}

void DiagnosableAdapter::AddStatusRecord(SqlState sqlState, const std::string & message)
void DiagnosableAdapter::AddStatusRecord(SqlState sqlState, const std::string& message)
{
LOG_MSG("Adding new record: %s\n", message.c_str());
AddStatusRecord(sqlState, message, 0, 0);
}
}
Expand Down
Loading