ocilib::Resultset Class Reference

Database resultset. More...

`#include <ocilib.hpp>`

Inherits ocilib::HandleHolder< OCI_Resultset *>.

## Public Types

enum | SeekModeValues { SeekAbsolute = OCI_SFD_ABSOLUTE, SeekRelative = OCI_SFD_RELATIVE }
| Seek Modes enumerated values. More...
typedef Enum< SeekModeValues > | SeekMode
| Seek Modes. More...

## Public Member Functions

template<class T >
T | Get (unsigned int index) const
| Return the current value of the column at the given index in the resultset. More...
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. More...
template<class T >
T | Get (const ostring &name) const
| Return the current value of the column from its name in the resultset. More...
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. More...
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. More...
template<typename T >
unsigned int | ForEach (T callback)
| Fetch all rows in the resultset and call the given callback for row. More...
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. More...
bool | Next ()
| Fetch the next row of the resultset. More...
bool | Prev ()
| Fetch the previous row of the resultset. More...
bool | First ()
| Fetch the first row of the resultset. More...
bool | Last ()
| Fetch the last row of the resultset. More...
bool | Seek (SeekMode mode, int offset)
| Custom Fetch of the resultset. More...
unsigned int | GetCount () const
| Retrieve the number of rows fetched so far.
unsigned int | GetCurrentRow () const
| Retrieve the current row index. More...
unsigned int | GetColumnIndex (const ostring &name) const
| Return the index of the column in the result from its name. More...
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. More...
Column | GetColumn (const ostring &name) const
| Return the column from its name in the resultset. More...
bool | IsColumnNull (unsigned int index) const
| Check if the current row value is null for the column at the given index. More...
bool | IsColumnNull (const ostring &name) const
| Check if the current row value is null for the column of the given name. More...
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 6412 of file ocilib.hpp.

## Member Typedef Documentation

## SeekMode

typedef Enum<SeekModeValues> ocilib::Resultset::SeekMode

Seek Modes.

Possible values are Resultset::SeekModeValues

Definition at line 6437 of file ocilib.hpp.

## Member Enumeration Documentation

## SeekModeValues

enum ocilib::Resultset::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 6422 of file ocilib.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 6363 of file ocilib_impl.hpp.

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

Referenced by Get().

## 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 6029 of file ocilib_impl.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 6369 of file ocilib_impl.hpp.

References ocilib::Check(), ocilib::MakeString(), OCI_ColumnGetName(), 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 6035 of file ocilib_impl.hpp.

References ForEach(), and Get().

## Get() [5/5]

template<class T , class U >

bool ocilib::Resultset::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.

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 | ( | T | 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

Referenced by ocilib::Statement::Execute(), and Get().

## ForEach() [2/2]

template<class T , class U >

unsigned int ocilib::Resultset::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.

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 6061 of file ocilib_impl.hpp.

References ocilib::Check(), ocilib::MakeRaw(), ocilib::MakeString(), OCI_GetBigInt(), OCI_GetBigInt2(), OCI_GetColumnIndex(), OCI_GetDataLength(), OCI_GetDate(), OCI_GetDate2(), OCI_GetDouble(), OCI_GetDouble2(), OCI_GetFile(), OCI_GetFile2(), OCI_GetFloat(), OCI_GetFloat2(), OCI_GetInt(), OCI_GetInt2(), OCI_GetInterval(), OCI_GetInterval2(), OCI_GetLob(), OCI_GetLob2(), OCI_GetLong(), OCI_GetLong2(), OCI_GetNumber(), OCI_GetNumber2(), OCI_GetObject(), OCI_GetObject2(), OCI_GetRaw(), OCI_GetRaw2(), OCI_GetRef(), OCI_GetRef2(), OCI_GetShort(), OCI_GetShort2(), OCI_GetStatement(), OCI_GetStatement2(), OCI_GetString(), OCI_GetString2(), OCI_GetTimestamp(), OCI_GetTimestamp2(), OCI_GetUnsignedBigInt(), OCI_GetUnsignedBigInt2(), OCI_GetUnsignedInt(), OCI_GetUnsignedInt2(), OCI_GetUnsignedShort(), and OCI_GetUnsignedShort2().

## 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 5938 of file ocilib_impl.hpp.

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

## 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 5943 of file ocilib_impl.hpp.

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

## 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 5948 of file ocilib_impl.hpp.

References ocilib::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 5953 of file ocilib_impl.hpp.

References ocilib::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 5958 of file ocilib_impl.hpp.

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

## 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 5968 of file ocilib_impl.hpp.

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

## 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 5973 of file ocilib_impl.hpp.

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

## 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 5983 of file ocilib_impl.hpp.

References ocilib::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 5988 of file ocilib_impl.hpp.

References ocilib::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 5993 of file ocilib_impl.hpp.

References ocilib::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 5998 of file ocilib_impl.hpp.

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