OCILIB (C and C++ Driver for Oracle)  4.7.5
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
ocilib::Resultset Class Reference

Database resultset. More...

#include <types.hpp>

Inherits ocilib::core::HandleHolder< OCI_Resultset * >.

Public Types

enum  SeekModeValues { SeekAbsolute = OCI_SFD_ABSOLUTE , SeekRelative = OCI_SFD_RELATIVE }
 Seek Modes enumerated values. More...
 
typedef core::Enum< SeekModeValuesSeekMode
 Seek Modes.
 

Public Member Functions

template<class T >
Get (unsigned int index) const
 Return the current value of the column at the given index in the resultset.
 
template<class T >
void Get (unsigned int index, T &value) const
 Assign to the current value of the column at the given index in the resultset.
 
template<class T >
Get (const ostring &name) const
 Return the current value of the column from its name in the resultset.
 
template<class T >
void Get (const ostring &name, T &value) const
 Assign to the current value of the column from its name in the resultset.
 
template<class T , class U >
bool Get (T &value, U adapter) const
 Return a given user type from the current fetched row. It allow translating row column values returned by a query to a user defined type using the given adapter type.
 
template<typename T >
unsigned int ForEach (T callback)
 Fetch all rows in the resultset and call the given callback for row.
 
template<typename T , typename U >
unsigned int ForEach (T callback, U adapter)
 Fetch all rows in the resultset and call the given callback for row It allow translating row column values returned by a query to a user defined type using the given adapter type.
 
bool Next ()
 Fetch the next row of the resultset.
 
bool Prev ()
 Fetch the previous row of the resultset.
 
bool First ()
 Fetch the first row of the resultset.
 
bool Last ()
 Fetch the last row of the resultset.
 
bool Seek (SeekMode mode, int offset)
 Custom Fetch of the resultset.
 
unsigned int GetCount () const
 Retrieve the number of rows fetched so far.
 
unsigned int GetCurrentRow () const
 Retrieve the current row index.
 
unsigned int GetColumnIndex (const ostring &name) const
 Return the index of the column in the result from its name.
 
unsigned int GetColumnCount () const
 Return the number of columns in the resultset.
 
Column GetColumn (unsigned int index) const
 Return the column from its index in the resultset.
 
Column GetColumn (const ostring &name) const
 Return the column from its name in the resultset.
 
bool IsColumnNull (unsigned int index) const
 Check if the current row value is null for the column at the given index.
 
bool IsColumnNull (const ostring &name) const
 Check if the current row value is null for the column of the given name.
 
Statement GetStatement () const
 Return the statement associated with the resultset.
 
bool operator++ (int)
 Convenient operator overloading that performs a call to Next()
 
bool operator-- (int)
 Convenient operator overloading that performs a call to Prev()
 
bool operator+= (int offset)
 Convenient operator overloading that performs a call to Seek() with Resultset::SeekRelative and the given offset.
 
bool operator-= (int offset)
 Convenient operator overloading that performs a call to Seek() with Resultset::SeekRelative and the given offset that is internally negated.
 

Detailed Description

Database resultset.

This class wraps the OCILIB object handle OCI_Resultset and its related methods

Definition at line 6504 of file types.hpp.

Member Typedef Documentation

◆ SeekMode

Seek Modes.

Possible values are Resultset::SeekModeValues

Definition at line 6529 of file types.hpp.

Member Enumeration Documentation

◆ SeekModeValues

Seek Modes enumerated values.

Enumerator
SeekAbsolute 

Seek is performed using a given absolute offset. The statement must be scrollable

SeekRelative 

Seek is performed using a given relative offset from the current position. The statement must be scrollable

Definition at line 6514 of file types.hpp.

Member Function Documentation

◆ Get() [1/5]

template<class T >
T ocilib::Resultset::Get ( unsigned int  index) const

Return the current value of the column at the given index in the resultset.

Template Parameters
T- C++ type of the value to retrieve
Parameters
index- Column position
Note
Column position starts at 1.

Definition at line 458 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetColl().

◆ Get() [2/5]

template<class T >
void ocilib::Resultset::Get ( unsigned int  index,
T &  value 
) const

Assign to the current value of the column at the given index in the resultset.

Template Parameters
T- C++ type of the value to retrieve
Parameters
index- Column position
value- value to fill
Note
Column position starts at 1.

Definition at line 124 of file Resultset.hpp.

◆ Get() [3/5]

template<class T >
T ocilib::Resultset::Get ( const ostring name) const

Return the current value of the column from its name in the resultset.

Template Parameters
T- C++ type of the value to retrieve
Parameters
name- Column name
Note
The column name is case insensitive.

Definition at line 464 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetColl2().

◆ Get() [4/5]

template<class T >
void ocilib::Resultset::Get ( const ostring name,
T &  value 
) const

Assign to the current value of the column from its name in the resultset.

Template Parameters
T- C++ type of the value to retrieve
Parameters
name- Column name
value- value to fill

Definition at line 130 of file Resultset.hpp.

◆ Get() [5/5]

template<class T , class U >
bool ocilib::Resultset::Get ( T &  value,
adapter 
) const

Return a given user type from the current fetched row. It allow translating row column values returned by a query to a user defined type using the given adapter type.

Parameters
value- User defined type value to be filled by the adapter function
adapter- User defined adapter function
Note
The user defined adapter function must conform to the following prototype: bool adapter (const Resultset &, T &) It shall return true if it has filled the value from the resultset otherwise false

◆ ForEach() [1/2]

template<typename T >
unsigned int ocilib::Resultset::ForEach ( callback)

Fetch all rows in the resultset and call the given callback for row.

Parameters
callback- User defined callback
Note
The user defined callback function must conform to the following prototype: bool callback(const Resultset &) It shall return true to continue fetching the resultset or false to stop the fetch
Returns
The number of rows fetched

◆ ForEach() [2/2]

template<class T , class U >
unsigned int ocilib::Resultset::ForEach ( callback,
adapter 
)

Fetch all rows in the resultset and call the given callback for row It allow translating row column values returned by a query to a user defined type using the given adapter type.

Parameters
callback- User defined callback
adapter- User defined adapter function
Note
The user defined adapter function must conform to the following prototype: [UserDefinedType] adapter (const Resultset &) The return value type must match the parameter of the callback method
The user defined callback function must conform to the following prototype: bool callback(const [UserDefinedType] &) It shall return true to continue fetching the resultset or false to stop the fetch
Returns
The number of rows fetched

Definition at line 156 of file Resultset.hpp.

References GetCurrentRow(), and Next().

◆ Next()

bool ocilib::Resultset::Next ( )
inline

Fetch the next row of the resultset.

Note
Next() works for normal and scrollable resultsets
Returns
true on success otherwise false if :
  • Empty resultset
  • Last row already fetched

Definition at line 33 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_FetchNext().

Referenced by ForEach(), and operator++().

◆ Prev()

bool ocilib::Resultset::Prev ( )
inline

Fetch the previous row of the resultset.

Note
Prev() works ONLY for scrollable resultsets
Returns
true on success otherwise false if :
  • Empty resultset
  • First row already fetched

Definition at line 38 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_FetchPrev().

Referenced by operator--().

◆ First()

bool ocilib::Resultset::First ( )
inline

Fetch the first row of the resultset.

Note
First() works ONLY for scrollable resultsets
Returns
true on success otherwise false if the resultset is empty

Definition at line 43 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_FetchFirst().

◆ Last()

bool ocilib::Resultset::Last ( )
inline

Fetch the last row of the resultset.

Note
Last() works ONLY for scrollable resultsets
Returns
true on success otherwise false if the resultset is empty

Definition at line 48 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_FetchLast().

◆ Seek()

bool ocilib::Resultset::Seek ( SeekMode  mode,
int  offset 
)
inline

Custom Fetch of the resultset.

Parameters
mode- Fetch direction
offset- Fetch offset
Warning
hSeek() works ONLY for scrollable resultsets
Note
If you intend to use Seek() on a scrollable statement and if any of the selected columns is a ref cursor or a nested table, you must set the fetching size to 1 using Statement::SetFetchSize() before calling Statement::GetResultset() Otherwise Seek() will fails with a OCI-10002 error
Returns
true on success otherwise false the resultset is empty or seek offset out of bounds

Definition at line 53 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_FetchSeek().

Referenced by operator+=(), and operator-=().

◆ GetCount()

unsigned int ocilib::Resultset::GetCount ( ) const
inline

Retrieve the number of rows fetched so far.

Definition at line 58 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetRowCount().

◆ GetCurrentRow()

unsigned int ocilib::Resultset::GetCurrentRow ( ) const
inline

Retrieve the current row index.

Note
  • GetCurrentRow() returns the current row number starting from 1
  • If the resultset has not been fetched or if the resultset is empty, it returns 0
  • If the resultset has been fully fetched, it returns the last fetched row number

Definition at line 63 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetCurrentRow().

Referenced by ForEach().

◆ GetColumnIndex()

unsigned int ocilib::Resultset::GetColumnIndex ( const ostring name) const
inline

Return the index of the column in the result from its name.

Parameters
name- Column name
Warning
The column name is case insensitive
Note
Column position starts at 1.

Definition at line 68 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetColumnIndex().

◆ GetColumnCount()

unsigned int ocilib::Resultset::GetColumnCount ( ) const
inline

Return the number of columns in the resultset.

Definition at line 73 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetColumnCount().

◆ GetColumn() [1/2]

Column ocilib::Resultset::GetColumn ( unsigned int  index) const
inline

Return the column from its index in the resultset.

Parameters
index- Column index
Note
Column position starts at 1.

Definition at line 78 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetColumn().

◆ GetColumn() [2/2]

Column ocilib::Resultset::GetColumn ( const ostring name) const
inline

Return the column from its name in the resultset.

Parameters
name- Column name
Note
The column name is case insensitive

Definition at line 83 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_GetColumn2().

◆ IsColumnNull() [1/2]

bool ocilib::Resultset::IsColumnNull ( unsigned int  index) const
inline

Check if the current row value is null for the column at the given index.

Parameters
index- Column index
Note
Column position starts at 1.

Definition at line 88 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_IsNull().

◆ IsColumnNull() [2/2]

bool ocilib::Resultset::IsColumnNull ( const ostring name) const
inline

Check if the current row value is null for the column of the given name.

Parameters
name- Column name

Definition at line 93 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_IsNull2().

◆ GetStatement()

Statement ocilib::Resultset::GetStatement ( ) const
inline

Return the statement associated with the resultset.

Definition at line 98 of file Resultset.hpp.

References ocilib::core::Check(), and OCI_ResultsetGetStatement().

◆ operator++()

bool ocilib::Resultset::operator++ ( int  )
inline

Convenient operator overloading that performs a call to Next()

Definition at line 103 of file Resultset.hpp.

References Next().

◆ operator--()

bool ocilib::Resultset::operator-- ( int  )
inline

Convenient operator overloading that performs a call to Prev()

Definition at line 108 of file Resultset.hpp.

References Prev().

◆ operator+=()

bool ocilib::Resultset::operator+= ( int  offset)
inline

Convenient operator overloading that performs a call to Seek() with Resultset::SeekRelative and the given offset.

Definition at line 113 of file Resultset.hpp.

References Seek(), and SeekRelative.

◆ operator-=()

bool ocilib::Resultset::operator-= ( int  offset)
inline

Convenient operator overloading that performs a call to Seek() with Resultset::SeekRelative and the given offset that is internally negated.

Definition at line 118 of file Resultset.hpp.

References Seek(), and SeekRelative.