-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ORM: the query result rowset becomes invalid after a for loop #1064
Comments
When reading the document: soci/docs/statements.md at master · SOCI/soci It looks like the I mean the row object(instance) is only constructed when they are accessed in the for loop? After that, they just got destroyed? |
OK, I just debugged for a while, I have change the definition of
The result is: The constructor and the destructor only called once. And the So, I see only one instance of person object. This is used for the performance improvement? |
When using Person person;
soci::statement stmt = (sql.prepare << "SELECT * FROM testtable", soci::into(person));
stmt.execute();
while (stmt.fetch()) {
std::cout << person.id << std::endl;
} A |
Hi, @zann1x thanks for the explanation. I strongly suggest that your comments should be put in the document of soci. Because this will happens for all kinds of beginners like me. What do you think? Another issue I see is that in your comments in this ticket (ORM and rowset · Issue #1020 · SOCI/soci), you try to use the
But since there is only one instance of "Person" instance, I think the 'move" semantic is not necessary. I mean the normal constructor like below is enough.
What do yo think about this? Thanks. |
That would surely be a great addition to the docs. Feel free to create a merge request for it!
It is true that only a single instance of |
Hi, thanks for the explanation. Though I'm still not quite understand the move structure, I will try to learn it more. About the document improvement, I will do it in the future. (I'm not a native English speaker, so writing some document is a bit hard for me, but I will try it later) |
I have a very strange issue, when I got a
soci::rowset
of the query result. I can use afor
loop to print its values, but if I run thefor
loop again on the samerowset
, the iterator got invalid.Here is a simple test code:
The result is: the first for loop can print the results, suppose I have two result items, and their ids will be printed. But the second for loop just did nothing, none of the items were returned.
The person class is very simple:
This looks very strange, that the rowset got invalid after the first loop.
The original question in-fact comes from the another issue, that I would like to convert the
rowset
to astd::vector<persion>
, but it looks like theiterator
got invalid if I run a for loop, see my test code here:#1020 (comment)
Any one can explain this?
Thanks.
The text was updated successfully, but these errors were encountered: