Roland Bock wrote:
_NULL handling:_ Enabled by the restructured code and spurred by the library quince by Michael Shepanski, sqlpp11 can now calculate which result fields can or cannot be NULL.
Speaking of which, handling NULL for result values has been discussed a lot. The library now has compile-time configurable behavior, you can choose between an std::optional-like interface and mapping NULL to the trivial value of the result type, e.g. 0 for numbers or "" for strings, see also https://github.com/rbock/sqlpp11/wiki/NULL
The way how NULL values are handled is similar to how missing options are handled in ProgramOptions where if some parameter isn't passed it may be set to some default value which may be set by the user. Could it be possible to allow users to define their "trivial" values in sqlpp? If result fields correspond to columns, then you could certainly define a per column default value or even a function to be called which would
On 2014-08-19 16:43, Adam Wulkiewicz wrote: then yield the value, or throw, or assert... In other cases, say select(t.a + t.b), you could define a per-type default value/method in the connector. That should be rather easy to add.
I'm aware that there is a difference between the two - in sqlpp the structure is defined in compile-time but ProgramOptions is much more user friendly at the stage of defining possible options:
[...]
I'm wondering, could it be possible to implement similar, compile-time interface in sqlpp, e.g. something similar to MPL? I'm asking because what the sqlpp library requires is very complicated: https://github.com/rbock/sqlpp11/blob/master/tests/Sample.h I'm aware that its purpose is to create a type reflecting required columns and to use them from the level of C++ but couldn't it be done simpler?
The crucial part is the _member_t template. I need that one. The other
stuff can be constructed whatever way you like. But if the name of the
column is `beta`, then I need a way to get this:
template<typename T>
struct _member_t
{
T beta;
T& operator()() { return beta; }
const T& operator()() const { return beta; }
};
This is the magic ingredient that makes tables, result rows and
parameter sets of prepared statements to have members with a proper name.
The way it works is best to be observed in the table_t template, see
https://github.com/rbock/sqlpp11/blob/master/include/sqlpp11/table.h
template