DOP-C Programming Guide

Finding Values

Sometimes we want to find the rows in which the fields take on particular values.

Searching for the First Occurence

Suppose we have a table named table which has an int field a. We want to find out the ID of the first row by ID in which the value in a is 10. We should use:

size_t firstRow = a.findFirst(10); 

If instead we want to find the index, we should use:

size_t firstIndex = a.findFirstIndex(10);

Sometimes we want a more complex criteria by which we should select rows. For this, we can pass a boolean function.

bool criteria(int& a)
{
    if(a > 10) return true; 
    return false;
}

void foo()
{
    size_t firstRow = Data::a->findFirst(criteria);
}

If ever any of these searches fail, the methods return -1.

Searching for all Occurences

For each of the methods in the last section, there is a corresponding method to find all occurences. These return a vector of results. For example:

std::vector<size_t> allRows = a.findAll(10);