-
Notifications
You must be signed in to change notification settings - Fork 357
Description
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:
auto s2 = select(t.id, t.text, t.nulltext).from(t).where(t.nulltext.is_null());
auto result = db(s2);
ASSERT_FALSE(result.empty());
ASSERT_TRUE(result.front().nulltext.is_null());
std::string text;
ASSERT_THROW(text = result.front().nulltext.value(), sqlpp::exception);
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 in connector_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 of enforce_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!