GetCount

Each cursor has a GetCount method which will returns the number of items contained in the Cursor collection. By definition the GetCount method for a Singleton Cursor will always return 1. The GetCount method for the special Cursors (BeforeFirst/AfterLast) will always return 0.

A read transaction is not required for this method, but it is possible to retrieve out of data information without one.

uint64_t GetCount (void) const throw (rdm_exception&);
Returns: The number of items contained in the Cursor collection

The following example demonstrates the use Cursor.GetCount method to retrieve the number of sensors records in the database.

#include "CMeasurementsModelCPP.h"

void CMeasurementsModelCPP::GetNumberOfSensors (
    uint64_t      &num_sensors) const throw (const rdm_exception&)
{
    Cursor_sensor s;

    /* Start a read transaction and lock all database tables */
    measurements_db.StartRead(RDM_LOCK_ALL);
    try
    {
        /* Get a sensor cursor */
        s = measurements_db.Get_sensor_Rows();

        /* Get the number of sensors in the database */
        num_sensors = (uint32_t) s.GetCount();

        /* end the transaction */
        measurements_db.End(); 
    }
    catch (rdm_exception e)
    {
        /* There was an error, we need to end the transaction */
        measurements_db.End(); 

        /* Rethrow the exception */
        throw e;
    }
}