SqlResult Class Reference

Get access to the results returned from a query, if any. More...

#include <sqlresult.hpp>

List of all members.

Public Member Functions

 SqlResult ()
 Constructor.
 ~SqlResult ()
 Destructor.
int rows () const
 Find out how many rows are in the result set.
string fetch ()
 Get the next data field in the result set.
int fetchInteger ()
 Get the next data field in the result set, converted to an int.
long fetchLong ()
 Get the next data field in the result set, converted to a long.
float fetchFloat ()
 Get the next data field in the result set, converted to a float.
double fetchDouble ()
 Get the next data field in the result set, converted to a double.
const char * fetchCstring ()
 Get the next data field in the result set, converted to a C style pointer based string constant.
void skip (int columns=1)
 Skip the next data field in the result set.
void skipRow ()
 Skip the rest of the row.
bool empty () const
 Find out if there are any results in the set.
void add (SqlRow *newRow)
 add a row to the result set.


Detailed Description

Get access to the results returned from a query, if any.

 SqlDatabase *db = new MySqlContext( ... );
 SqlQuery query( *db );
 SqlResult result = query( "SELECT * FROM my_table;" );

 while( !result.empty() )
   {
     std::string myString = result.fetch();
     int myInt = result.fetchInteger();
     // do something with myText and myInt
   }

 delete db;

Definition at line 87 of file sqlresult.hpp.


Constructor & Destructor Documentation

SqlResult::SqlResult (  ) 

Constructor.

Definition at line 74 of file sqlresult.cpp.

SqlResult::~SqlResult (  ) 

Destructor.

Definition at line 78 of file sqlresult.cpp.


Member Function Documentation

int SqlResult::rows (  )  const

Find out how many rows are in the result set.

Returns:
The number of rows.

Definition at line 93 of file sqlresult.cpp.

string SqlResult::fetch (  ) 

Get the next data field in the result set.

This member function will, in addition to returning the data, also delete it from the result set.

Returns:
The next field.

Definition at line 98 of file sqlresult.cpp.

References SqlRow::empty(), and SqlRow::fetch().

Referenced by fetchCstring(), fetchDouble(), fetchFloat(), fetchInteger(), fetchLong(), and skip().

int SqlResult::fetchInteger (  ) 

Get the next data field in the result set, converted to an int.

Returns:
The result as an integer.
See also:
SqlResult::fetch()

Definition at line 117 of file sqlresult.cpp.

References fetch().

long SqlResult::fetchLong (  ) 

Get the next data field in the result set, converted to a long.

Returns:
The result as a long.
See also:
SqlResult::fetch()

Definition at line 122 of file sqlresult.cpp.

References fetch().

float SqlResult::fetchFloat (  ) 

Get the next data field in the result set, converted to a float.

Returns:
The result as a float.
See also:
SqlResult::fetch()

Definition at line 127 of file sqlresult.cpp.

References fetch().

double SqlResult::fetchDouble (  ) 

Get the next data field in the result set, converted to a double.

Returns:
The result as a double.
See also:
SqlResult::fetch()

Definition at line 132 of file sqlresult.cpp.

References fetch().

const char * SqlResult::fetchCstring (  ) 

Get the next data field in the result set, converted to a C style pointer based string constant.

Returns:
The result as an integer.
See also:
SqlResult::fetch()

Definition at line 137 of file sqlresult.cpp.

References fetch().

void SqlResult::skip ( int  columns = 1  ) 

Skip the next data field in the result set.

Parameters:
columns The number of fields/columns to skip. If not specified (or if negative) a default of 1 is used.

Definition at line 142 of file sqlresult.cpp.

References fetch().

void SqlResult::skipRow (  ) 

Skip the rest of the row.

The next fetch you do will return the first field in the next row.

Definition at line 151 of file sqlresult.cpp.

bool SqlResult::empty (  )  const

Find out if there are any results in the set.

This function is typically used as an expression in a loop.

 while( !result.empty() )
   {
     std::string myData = result.fetch();
     ... do something with myData
   }

Definition at line 161 of file sqlresult.cpp.

void SqlResult::add ( SqlRow newRow  ) 

add a row to the result set.

Note that this is used by the inherited SqlDatabase classes, so there should be no reason for you use this function directly.

Parameters:
newRow The SqlRow to be added.

Definition at line 88 of file sqlresult.cpp.


The documentation for this class was generated from the following files:
Generated on Sat Aug 18 16:21:45 2007 for SqlWrapperXX by  doxygen 1.5.0