int main(void) { try { Environment::Initialize(); Connection con("db", "usr", "pwd"); Statement st(con); st.SetFetchMode(Statement::FetchScrollable); st.Execute("select rownum, 'Row ' || rownum from (select 1 from dual connect by level <= 65)"); Resultset rs = st.GetResultset(); rs.Last(); std::cout << "Total rows : " << rs.GetCount() << std::endl; rs.First(); print_row(rs); while (rs.Next()) { print_row(rs); } while (rs.Prev()) { print_row(rs); } rs.Seek(Resultset::SeekAbsolute, 30); print_row(rs); while (rs.GetCurrentRow() < 60 && rs.Next()) { print_row(rs); } rs.Seek(Resultset::SeekRelative, -15); print_row(rs); } catch (std::exception &ex) { std::cout << ex.what() << std::endl; } Environment::Cleanup(); return EXIT_SUCCESS; }
void test_scrollable_cursor(void) { if (Environment::GetRuntimeVersion() > Oracle9iR1) { ocout << otext("\n>>>>> TEST SCROLLABLE CURSORS \n\n"); Statement st(con); st.SetFetchMode(Statement::FetchScrollable); st.Execute(otext("select table_name from user_tables where ") otext("table_name like 'TEST_%' order by table_name")); Resultset rs = st.GetResultset(); rs.Last(); ocout << otext("Total rows : ") << rs.GetCount() << oendl; ocout << otext("... Go to row 1\n"); rs.First(); ocout << otext("table ") << rs.Get<ostring>(1) << oendl; ocout << otext("... Enumerate from row 2 to row ") << rs.GetCount() << otext(" ") << oendl; while (rs++) { ocout << otext("table ") << rs.Get<ostring>(1) << oendl; } ocout << otext("... Enumerate from row ") << rs.GetCount() - 1 << otext(" back to row 1") << oendl; while (rs.Prev()) { ocout << otext("table ") << rs.Get<ostring>(1) << oendl; } ocout << otext("... Go to the 3th row") << oendl; rs.Seek(Resultset::SeekAbsolute, 3); ocout << otext("table ") << rs.Get<ostring>(1) << oendl; ocout << otext("... Fetch the next 2 rows") << oendl; while (rs.GetCurrentRow() < 5 && rs++) { ocout << otext("table ") << rs.Get<ostring>(1) << oendl; } } }