Giter Site home page Giter Site logo

Comments (4)

mloskot avatar mloskot commented on May 12, 2024

@kfmfe04 It should work well. There is dedicated test19() for the rowset<> and std::distance() in common-tests.h which boils down to this:

rowset<row> rs = (sql.prepare << "select * from soci_test");
assert(5 == std::distance(rs.begin(), rs.end()));

Is it possible you are re-using the iterator? The doc on rowset says:

The rowset_iterator type is compatible with requirements
defined for input iterator category

Perhaps, you could post a concise and self-contained code sample, that could help to reproduce it.

from soci.

kfmfe04 avatar kfmfe04 commented on May 12, 2024

Thank you for the quick reply. I just found in the mailing list that the iterator type you have implemented is an input iterator. I can understand the use of an input iterator for caching purposes/optimization/general code (eg pulling in a gazillion rows), but for regular use, it seems less convenient than a forward iterator.

Let's take the case of your example above: once I call std::distance() on rs.begin() and rs.end(), I can no longer iterator through rs, correct? My testing seems to indicate this is true - and this is consistent with input iterators.

Do I start-over and generate another rowset? Or perhaps I need to allocate my own memory to store the data so that I can iterate through it like a forward iterator or know how many rows have been selected?

EDIT: ok - I am going to wrap soci::rowset in a class where calls to begin() will be marked. If begin() is called a second time, I will throw a std::runtime_exception(), asking the developer to create a new instance. It's ugly, but it'll do. It's okay to close out this issue. TY.

from soci.

kfmfe04 avatar kfmfe04 commented on May 12, 2024

As a work-around for limitations of an input iterator, I made a copy of the results:

typedef soci::rowset<ROW_TUPLE> rowset_type;
rowset_type rs = (session.prepare << m_qry);
std::copy( rs.begin(), rs.end(), std::back_inserter(m_v));

where ROW_TUPLE is an appropriate boost::tuple<>, and m_v is a std::vector<ROW_TUPLE>.

It would be nice if, in the future, there is an option in SOCI to select a container replacement for soci::rowset<> (in my case, that would be std::vector<>) to avoid the extra copy, but this workaround will work fine for now.

from soci.

mloskot avatar mloskot commented on May 12, 2024

I assume it can be closed as by design.

I'd suggest to open new ticket with proposal of improvements, if anything comes to mind.

from soci.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.