SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

How to create an empty rowset? #1057

Closed vatnic closed 8 months ago

vatnic commented 1 year ago

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 1 year ago

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!

asmwarrior commented 11 months ago

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? `

asmwarrior commented 11 months ago

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 rowsetto std::vector.

cstiborg commented 9 months ago

I've created a PR which patches rowset with a default constructor. Feel free to comment.

asmwarrior commented 8 months ago

Is it possible to make a new tag(release) in the git? I just looked at the git commit history, the last git tag is 4.0.3, which is in beginning of the year 2022. Thanks.