Skip to content
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

Soci 1057 #1084

Closed
wants to merge 4 commits into from
Closed

Soci 1057 #1084

wants to merge 4 commits into from

Conversation

cstiborg
Copy link
Contributor

This PR allows the creation of an empty rowset as per #1057.

Copy link
Member

@vadz vadz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't think this is correct. I'd also rather avoid changing the existing rowset_iterator ctor, we already have a ctor for creating an invalid iterator, so we should just use it instead.

Also, could you please rebase your branch on SOCI master to avoid having unrelated changes in this PR?

TIA!

@@ -136,7 +141,7 @@ class rowset_impl
iterator begin() const
{
// No ownership transfer occurs here
return iterator(*st_, *define_);
return iterator(st_.get(), define_.get());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how does this not result in a crash... rowset_iterator ctor calls ++ which uses the pointer, which is null here for an invalid rowset.

Am I missing something here or would it actually crash if you added a test exercising the new code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been testing this and it does work. However, I also wonder why the ++(*this) doesn't make it explode... I can do a gdb session on it and see where it takes me.

Talking about the design itself, I agree that changing the rowset_iterator ctor is not ideal, however, I was taken away by the beauty of the minimal change to begin(). I did another version in which I didn't change the rowset_iterator instead I had:

iterator begin() const
{
// No ownership transfer occurs here
return (st_.get() == nullptr)
? iterator()
: iterator(*st_, *define_);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, beauty is in the eye of the beholder and personally I find a ctor taking optional and maybe null pointers pretty ugly. And

iterator begin() const
{
    // Empty rowset doesn't have any valid begin iterator.
    return st_ ? iterator(*st_, *define_) : iterator();
}

seems perfectly fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's coming up - I just need to test it - while I'm at it, should I add a clear for #198 and close a 10 year old issue? ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, adding clear() would be welcome as well. Just please add a unit test for it too. TIA!

This doesn't make sense, so explicitly delete the ctor from session to
prevent such code from compiling.

Closes SOCI#1081.

See SOCI#1082.
@cstiborg cstiborg closed this Oct 11, 2023
@cstiborg cstiborg deleted the soci-1057 branch October 11, 2023 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants