WORM 0.2
A C++ DAL/ORM code generation framework
Public Member Functions | Protected Member Functions | Protected Attributes

WSql::WSqlResult Class Reference

The WSqlResult class provides a representation of the result set from a query. More...

#include <wsqlresult.h>

Inheritance diagram for WSql::WSqlResult:

List of all members.

Public Member Functions

 WSqlResult (const WSqlDriver *driver)
 WSqlResult (const WSql::WSqlResult &other)
virtual ~WSqlResult ()
virtual WSqlResultoperator= (const WSqlResult &other)
void addRecord (WSqlRecord &r)
void setIsCached (bool b)
void setIsValid (bool b)
bool isValid () const
bool isCached () const
virtual int size () const
virtual int count () const
virtual bool empty () const
virtual bool hasOutValues () const
virtual void clear ()
virtual WSqlRecord current ()
virtual WSqlRecord fetch (int i=-1)
virtual WSqlRecord fetchFirst ()
virtual WSqlRecord fetchLast ()
virtual WSqlRecord fetchNext ()
virtual WSqlRecord fetchPrevious ()

Protected Member Functions

virtual bool seek (int i, bool relative=false)
virtual bool next ()
virtual bool previous ()
virtual bool first ()
virtual bool last ()

Protected Attributes

std::vector< WSqlRecord >
::const_iterator 
const_cur_record_it
std::vector< WSqlRecord >::iterator record_it
const WSqlDriver_driver
std::vector< WSqlRecord_records
bool _isCached

Detailed Description

The WSqlResult class provides a representation of the result set from a query.

WSqlResult represents the results of a query to the database as a vector of WSqlRecords. By default isCached() returns true and the vector is populated by the WSqlDriver. If the query was not a select or returned no results then size() will be 0 and hasOutValues() will return false.

If you are implementing your own SQL driver (by subclassing WSqlDriver), you must also subclass WSqlResult and implement the all the pure virtual functions and other virtual functions that you need. This is mostly to support databases that allow partial retrieval of a result set - in which case the implementation will offer the ability to setIsCached() and manage the fetching of records internally.

Example usage:

std::string sql = "select * from " + tablename + " limit 2";
if(!db.execute(sql)) exit();

WSqlResult *result = db.getResult();
WSqlRecord record = result->fetchFirst();
while(!record.empty())
{
    WSqlField fld;
    for(int i = 0;i < record.size();i++)
    {
        fld = record.field(i);
        std::cout << "Field " << fld.name() << ", Origin Column "<< fld.columnName() 
        << "Value: " << fld.data<std::string>() << std::endl;
    }
    record = result->fetchNext();
}
See also:
WSqlRecord WSqlField WSqlDatabase

Definition at line 30 of file wsqlresult.h.


Constructor & Destructor Documentation

WSql::WSqlResult::WSqlResult ( const WSqlDriver driver)

Creates an empty result object.

Definition at line 67 of file wsqlresult.cpp.

WSql::WSqlResult::WSqlResult ( const WSql::WSqlResult other)

Definition at line 75 of file wsqlresult.cpp.

WSql::WSqlResult::~WSqlResult ( ) [virtual]

Destroys the object and frees any allocated resources.

Definition at line 97 of file wsqlresult.cpp.


Member Function Documentation

void WSql::WSqlResult::addRecord ( WSqlRecord r) [inline]
Todo:
virtual bool operator==(const WSqlResult& other) const;

Reimplemented in WSql::WMysqlResult.

Definition at line 41 of file wsqlresult.h.

virtual void WSql::WSqlResult::clear ( ) [inline, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 53 of file wsqlresult.h.

virtual int WSql::WSqlResult::count ( ) const [inline, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 49 of file wsqlresult.h.

WSqlRecord WSql::WSqlResult::current ( ) [virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 152 of file wsqlresult.cpp.

virtual bool WSql::WSqlResult::empty ( ) const [inline, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 50 of file wsqlresult.h.

WSqlRecord WSql::WSqlResult::fetch ( int  index = -1) [virtual]

Returns the record from an arbitrary (zero-based) row index.

If the index is not in valid range an empty record is returned.

See also:
isActive(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious()

Reimplemented in WSql::WMysqlResult.

Definition at line 159 of file wsqlresult.cpp.

WSqlRecord WSql::WSqlResult::fetchFirst ( ) [virtual]

Returns the record from the first record (row 0) in the result.

See also:
fetch(), fetchLast()

Reimplemented in WSql::WMysqlResult.

Definition at line 166 of file wsqlresult.cpp.

WSqlRecord WSql::WSqlResult::fetchLast ( ) [virtual]

Returns the record from the last record (last row) in the result.

See also:
fetch(), fetchFirst()

Reimplemented in WSql::WMysqlResult.

Definition at line 172 of file wsqlresult.cpp.

WSqlRecord WSql::WSqlResult::fetchNext ( ) [virtual]

Returns the record from the next available record (row) in the result.

See also:
fetch(), fetchPrevious()

Reimplemented in WSql::WMysqlResult.

Definition at line 178 of file wsqlresult.cpp.

WSqlRecord WSql::WSqlResult::fetchPrevious ( ) [virtual]

Returns the record from the previous record (row) in the result.

Reimplemented in WSql::WMysqlResult.

Definition at line 184 of file wsqlresult.cpp.

bool WSql::WSqlResult::first ( ) [protected, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 190 of file wsqlresult.cpp.

virtual bool WSql::WSqlResult::hasOutValues ( ) const [inline, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 51 of file wsqlresult.h.

bool WSql::WSqlResult::isCached ( ) const [inline]

Definition at line 46 of file wsqlresult.h.

bool WSql::WSqlResult::isValid ( ) const [inline]

Definition at line 45 of file wsqlresult.h.

bool WSql::WSqlResult::last ( ) [protected, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 195 of file wsqlresult.cpp.

bool WSql::WSqlResult::next ( ) [protected, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 203 of file wsqlresult.cpp.

WSqlResult & WSql::WSqlResult::operator= ( const WSqlResult other) [virtual]

Definition at line 84 of file wsqlresult.cpp.

bool WSql::WSqlResult::previous ( ) [protected, virtual]

Reimplemented in WSql::WMysqlResult.

Definition at line 207 of file wsqlresult.cpp.

bool WSql::WSqlResult::seek ( int  pos,
bool  relative = false 
) [protected, virtual]
Todo:
test this

Reimplemented in WSql::WMysqlResult.

Definition at line 213 of file wsqlresult.cpp.

void WSql::WSqlResult::setIsCached ( bool  b) [inline]

Reimplemented in WSql::WMysqlResult.

Definition at line 42 of file wsqlresult.h.

void WSql::WSqlResult::setIsValid ( bool  b) [inline]

Definition at line 43 of file wsqlresult.h.

int WSql::WSqlResult::size ( ) const [inline, virtual]

Returns the number of records in the result returned from a SELECT statement. Note that this will be 0 if no results were returned..

See also:
numRowsAffected()

Reimplemented in WSql::WMysqlResult.

Definition at line 48 of file wsqlresult.h.


Member Data Documentation

Definition at line 71 of file wsqlresult.h.

bool WSql::WSqlResult::_isCached [protected]

Definition at line 73 of file wsqlresult.h.

std::vector<WSqlRecord> WSql::WSqlResult::_records [protected]

Definition at line 72 of file wsqlresult.h.

std::vector<WSqlRecord>::const_iterator WSql::WSqlResult::const_cur_record_it [protected]

Definition at line 69 of file wsqlresult.h.

std::vector<WSqlRecord>::iterator WSql::WSqlResult::record_it [protected]

Definition at line 70 of file wsqlresult.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines