-
Notifications
You must be signed in to change notification settings - Fork 344
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
Handling of ::sqlpp::tag::enforce_null_result_treatment
does not seem to be implemented, NULL documentation is erroneous
#568
Comments
Thank you for the detailed report! And sorry for the mess in the documentation. As you already guessed, there is some history to it.
If you really want an exception to the thrown then accessing the value of a result field that is NULL, the per-column configuration could be re-introduced with relative ease, I think. I would suggest a parameter for the code generator that adds the trait, and then checking for the trait in the in However, in C++17 or later, I would definitely use WDYT? Thanks, PS: All that said, I started updating the documentation to cover the current behavior. |
Hi Roland, thanks for the quick reply and action on the documentation, really appreciate it! A couple of thoughts:
I hope what I wrote is relatable to how sqlpp is thought to work. If not, then please forgive my ignorance. As it feels from your message and from other threads that I read on this topic that you have pretty much made up your mind to go with optional - you just needed a final push? - I would appreciate if you could let me know when this will be available. If you need help with this, I am happy to assist, but then I need a crash course on the related parts of sqlpp architecture before I dare to make changes to it. |
Thanks for your thoughts, this is much appreciated. You are right. I am convinced that using Switching to sqlpp11 to C++17 and refactoring it step by step might therefore be an option. But I wonder how to deal with bug fixes for the C++11 code (there still are folks out there who use C++11)? |
If you want to get your hands dirty and play with code, try out https://github.com/rbock/sqlpp11/tree/optional From the commit message:
|
Continued a bit. All result types except blob should work now for sqlite3. text parameters are currently not working. I am thinking of backporting minimal versions of |
I would suggest to drop the 11 from sqlpp11and just call it sqlpp. Add |
+1 to that. Btw Sy Brand has implemented So maybe it makes sense to use directly his implementation which is a single .hpp file, 72 KB in size. I am not sure whether it is better to add his project as a dependency or just copy his source code into sqlpp. Or maybe just use his implementation and simplify it a bit (he has made a few extensions to std::optional, which we don't really have to copy). |
If I remember correctly rbock wants to keep compatibility with sqlpp11 in the current codebase and then just make a full rewrite of sqlpp once C++ supports reflection, which will probably be in C++26. We discussed it a while ago and IIRC decided to add I think it makes sense to use the same approach with |
Well, I'm obviously oblivious to the history. Thanks for the background. Aliasing these constructs is then a good way to solve the compatibility issue. Is that all that's missing is that somebody does it? Regarding backward compatibility though, I am not sure if it is worth the effort. If the ultimate goal is a complete rewrite with reflection then the result will be surely something very similar to the EF in .Net. I would assume that it will not necessarily be a straightforward thing to do so a new stable library is quite a few years away after reflection becomes available. Sqlpp11 and the new version will then also need to live side by side for for a couple of more years. Imagining this timeline are we going to still have C++11 compatibility in the library in 2035? Following from the above, I think dropping the burden of backward compatibility and just considering the current sqlpp11 as "version 1" and the new - yet to be written with reflection - "version 2" would make things lot less complicated going forward. It may also make that future rewrite somewhat easier. Anyway, I rest my case. On the end I am happy with any working solution. Sqlpp is a great library aliases or not. :-) |
In order to add support for IMHO implementing the compatibility layer (sqlpp::compat::optional for c++11/14) is not that much work per se as and the more complex part will be to backport the changes from sqlpp17. But I might be wrong since we don't really know until someone implements it. BTW we already have Regarding the hypothetical sqlpp26 (or whatever its name will be), I would expect that from a user-point of view it will have the same or very similar interface. I think that sqlpp11 has found the perfect balance between unchecked raw SQL queries and the rigid and limited ORM frameworkis and I don't think it can be improved significantly by making major changes in its interface. That is why I wouldn't expect any major changes from a user perspective. But then again I might be wrong here too. |
Hi, Thanks for the discussion! These are pretty much the thoughts I am going through myself. To sum it up:\
Re effort:\
Cheers, |
I am using sqlpp11 with sqlite3.
I wanted to enable the behavior of sqlpp11 throwing an sqlpp::exception when a null value is being assigned to a variable. E.g. I would expect the below test to pass:
but in fact it fails with
ASSERT_THROW
.From the documentation one could assume that the presence of the tag
enforce_null_result_treatment
with the connection and/or with the column influences this behavior. Now it appears that whether this tag is present or not at the column, it does not make the slightest difference, the null values are always converted to the trivial value of the column type.Examining the code the tag does not appear anywhere else than the place it is defined in
type-traits.h
. and inconnector_api/connection.h
. I could not quite figure out in general how the_traits
are used and have their effect. I would be grateful for a pointer on this to help me grasp the concept.The documentation of NULL handling seems to be obsolete and is ambiguous/erroneous. For example the usage of
tvin()
mentioned there is surely dead based on this issue. And when it comes to the usage ofenforce_null_result_treatment
I could not really decide whether the tag being present makes(should make) the code throw an exception or the lack of that tag. Based on the tag name alone I guess that having the tag should cause conversion to trivial value and not having it should cause throwing exceptions, but this is just a guess.I would gladly offer my assistance in form of a PR, but having spent only 2 days with sqlpp at this point I do not feel the confidence to add more than this humble notice.
Other than this, the library is great, thank you all who contributed and/or still do!
The text was updated successfully, but these errors were encountered: