>
>From: Klaim <mj...@gm...>
>To: cpp...@li...
>Sent: Tue, January 4, 2011 12:18:59 PM
>Subject: Re: [Cppcms-users] Cppdb: How to fetch a column of unknown type at
>compile time?
>
>Hi,
>reading this example
>
>
> try {
>> int x = r.get<int>(v);
>> }
>> catch(cppdb::bad_value_cast const &e) {
>> // ok it can't be integer
>> }
>
>I'm thinking : could it be possible to provide a way to make it return a
>specific value instead of throwing when the conversion can't be done?
>I'm not sure that would be useful in this case but it have been when using
>boost::property_tree for example.
>Something like
>
>
> int x = r.get<int>( v , -1 ); // return -1 if something gone wrong
>
>Alllowing the two syntaxes help avoiding unnecessary try/catch when you just
>want an obviously wrong result instead of a potential exception you'll have to
>remember to catch to stop crashing.
>
Generally you can do following:
int x = -1;
r.fetch(v,x);
HOWEVER this works only when the value is NULL value, in case of impossible
type conversion bad_value_cast would be thrown.
If you don't want the bad_value_cast being thrown when you don't know the type,
just fetch the value as string and manipulate over it.
Artyom
|