On 11/28/2011 09:10 AM, Carlos Franke wrote:
>> does it segfault in operator[] or when accessing the value?
> Sorry for not being precise. It segfaults when accessing the value (with 
> getString() in my case).
>
>> You must not fetch a value
>> from a tntdb::Value, which is actually null. If you do, the reaction is
>> the same as accessing a std::vector outside its bounds. And that is
>> undefined. Most probably a segfault.
> Should it not rather throw a tntdb::NullValue exception?
>
>> For every value you fetch from a database, which may be null you should
>> always first ask, if it is null.
> I will keep that in mind, although it is somewhat counterintuitive for string 
> values, where I would expect that an empty field results in an empty string 
> (""). It may however be best to keep things consistent with the other 
> get-methods.
>
> For now, I am working around the issue like this:
> string my_string = ( my_row.isNull(1)  ?  ""  :  my_row[1].getString() );
>
> Carlos
>
You can easily work around it using:

string my_string;
myrow[1] >> my_string;

The >> operator does nothing, if the value is null. It just returns 
false. If you are not interested in the return value, just ignore it as 
in my example.

And I don't feel it too intuitive to return an empty string for a null 
value. Either the field contains an empty string or it is null. If you 
request the string, and the getString method can't fulfill its task, it 
should not return something else like an empty string. I really suggest 
to use the >> operator to fetch values since it is the most flexible and 
robust variant.

Tommi

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to