|
Boost : |
From: james.jones_at_[hidden]
Date: 2006-10-06 12:05:13
From: Nicola Musatti <Nicola.Musatti_at_[hidden]>
> I believe this is an instance of the need of representing concepts both in the
> SQL and in the C++ world. I see indicators as conceptually a part of the SQL
> world, in that they are a way to access additional, detailed information about
> the result of a query, beyond the retrieved value itself.
>
> Once the value is converted to a C++ type it assumes a value in the domain of
> that type... or not. In this case boost::optional or its moral equivalent is a
> reasonable representation.
>
> Side note: a while ago I wrote a Nullable<T> type that provided implicit
> conversion to T and threw an exception if it held a null value. Personally I'd
> prefer that kind of interface, but I think it's better to stick as much as
> possible to what's available in the standard library or in Boost.
I've been following this thread closely, as I have a need for a database library in C++ as well (don't we all?). I wrote my own, which serves my purposes OK, but would certainly be interested in a Boosted version.
On this particular point, while obviously indicator variables are the SQL way to provide information about data fields, having a separate variable is very much not in the spirit of C++. But it would be easy to define:
template<class DataType, class IndicatorType>
class value
{
private:
IndicatorType indicator;
DataType data;
public:
bool is_null() const { return indicator.is_null(); }
bool is_truncated() const { return indicator.is_truncated(); }
/* ... other queries ... */
};
-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk