Comments (4)
@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.
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.
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.
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)
- SQLite incorrect DDL handling HOT 3
- Oracle incorrect DDL handling HOT 2
- SOCI doesn't support automatic type conversion HOT 14
- Spelling mistake "execude_hardcoded" HOT 1
- "foreign_keys" does not work (SQLite) HOT 18
- soci 4.0 build Oracle backend on Windows HOT 6
- CMake installation issues with soci as a dependency HOT 2
- Add a `db_json` in the enum HOT 1
- Support for Postgresql LISTEN command? HOT 3
- fsanitize=undefined in parent project causes to link due to missing rtti infos in soci.so HOT 3
- Getting multiple recordsets from a stored procedure
- SOCI doesn't compile when using the `UNICODE` flag on Windows HOT 4
- Next release
- vcpkg soci crashes on session::close() HOT 1
- Streamline cmake usage HOT 14
- How to read DATETIME(3) type in database? HOT 2
- Missing backend includes HOT 2
- failed to connect to mysql database after I upgrade the mariadbclient library inside the msys2 HOT 2
- MSVC: number of sections exceeded object file format limit
- Issue with Boost 1.84 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soci.