SOCI/soci

How to create an empty rowset?

vatnic opened this issue · 5 comments

vatnic commented

Good afternoon!
I did not find documentation on how to create an empty rowset, which is necessary for output from the method, when an exception occurs.

rowset<row> DbConnector::selectData(wxWindow* win, wxString selectString)
{
    rowset<row> rowSet= (sql.prepare << "");
    try
    {
        rowSet= (sql.prepare << selectString);
        return rowSet;
    }
    catch (const std::exception& e)
    {
        wxMessageDialog messageDialog(win, e.what(), "Ошибка", wxOK);
        messageDialog.ShowModal();
    }
    return rowSet;
}

How to create an empty rowset without accessing the database?

vadz commented

I'm afraid a rowset has to be always valid currently. It wouldn't be difficult to add a default ctor to it and change begin() and end() to return the (same) invalid iterator for such an empty rowset. Any patches doing this would be welcome!

I got here by searching. I just want to know how to got the size of the rowset. Maybe this issue is related, I see there is no function call named size(), so I have to iterate all the elements of the rowset to get the size of this rowset?
`

Add rowset::clear() · Issue #198 · SOCI/soci

This is a related discussion, but it is in year 2013, and no response of this issue.

Also, in this issue ORM and rowset · Issue #1020 · SOCI/soci, some one gives a way to translate the rowset to std::vector.