int main(void) { try { Environment::Initialize(); Connection con("db", "usr", "pwd"); Statement st(con); st.Execute("select * from all_users"); Resultset rs = st.GetResultset(); while (rs++) { std::cout << "UserName:"******"username") << " Created:" << rs.Get<ostring>("created") << std::endl; } std::cout << "=> Total fetched rows : " << rs.GetCount() << std::endl; } 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; } } }
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_ref_cursor(void) { ocout << otext("\n>>>>> TEST REF CURSOR \n\n"); Statement stBind(con); Statement st(con); st.Prepare(otext("begin open :c for select * from test_fetch; end;")); st.Bind(otext(":c"), stBind, BindInfo::Out); st.ExecutePrepared(); Resultset rs = stBind.GetResultset(); while (rs++) { PrintProductFromQuery(rs); } ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl; }
int main3(void) { ofstream of; of.open("out.tsv"); try { Environment::Initialize(); Connection con("localhost", "scott", "tiger"); Statement st(con); st.Execute("select * from APEX_040000.WWV_FLOW_STEP_ITEMS"); Resultset rs = st.GetResultset(); auto colCount = rs.GetColumnCount(); cout << colCount << '\n'; for (int i=1; i <=colCount; i++){ cout << rs.GetColumn(i).GetName() << "|" << rs.GetColumn(i).GetFullSQLType() << '\n'; } while (rs++) { for (int i = 1; i <= colCount; i++){ of << rs.Get<ostring>(i); if (i < colCount){ of << "\t"; } } of << "\n"; } std::cout << "=> Total fetched rows : " << rs.GetCount() << std::endl; } catch (std::exception &ex) { std::cout << ex.what() << std::endl; } Environment::Cleanup(); of.close(); return EXIT_SUCCESS; }
void test_fetch(void) { ocout << otext("\n>>>>> SIMPLE TEST FETCH WITH META DATA\n\n"); Statement st(con); st.Execute(otext("select * from test_fetch")); Resultset rs = st.GetResultset(); for (int i = 1, n = rs.GetColumnCount(); i <= n; i++) { ocout << otext("> Field : #") << i << otext(" - Name : ") << rs.GetColumn(i).GetName() << oendl; } ocout << oendl; while (rs++) { PrintProductFromQuery(rs); } ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl; }
void test_lob(void) { ocout << otext("\n>>>>> TEST LOB MANIPULATION\n\n"); Statement st(con); st.Execute(otext("select code, content from test_lob where code=1 for update")); Resultset rs = st.GetResultset(); while (rs++) { Clob clob = rs.Get<Clob>(2); clob.Write(otext("today, ")); clob.Append(otext("i'm going to the cinema ! ")); clob.Seek(SeekSet, 0); ocout << otext("> code : ") << rs.Get<int>(1) << otext(", content : ") << clob.Read(SizeString) << oendl; } con.Commit(); ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl; }
void test_fetch_translate(void) { ocout << otext("\n>>>>> SIMPLE TEST FETCH WITH ROW TRANSLATION TO USER TYPE \n\n"); Statement st(con); st.Execute(otext("select * from test_fetch")); Resultset rs = st.GetResultset(); ocout << oendl; while (rs++) { Product p; if (rs.Get(p, FillProductFromQuery)) { PrintProductFromObject(p); } } ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl; }
void test_returning(void) { ocout << otext("\n>>>>> TEST RETURNING CLAUSE \n\n"); Statement st(con); st.Prepare(otext("update test_lob set code = code + 1 returning code, content into :i, :l")); st.Register<int>(otext(":i")); st.Register<Clob>(otext(":l")); st.ExecutePrepared(); Resultset rs = st.GetResultset(); while (rs++) { Clob clob = rs.Get<Clob>(2); clob.Append(otext("(modified)")); clob.Seek(SeekSet, 0); ocout << otext("> code : ") << rs.Get<int>(1) << otext(" - ") << clob.Read(static_cast<unsigned int>(clob.GetLength())) << oendl; } con.Commit(); ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl; }