[gdal-dev] Nullable fields in OGR
Frank Warmerdam
warmerdam at pobox.com
Thu Feb 18 14:36:16 EST 2010
Jason Roberts wrote:
> Even and Frank, thanks for your replies. I am a little confused because you
> each appeared to describe different behaviors.
>
> Frank said:
>
>> There is currently no way to test if a datastore supports the concept
>> of NULL fields, but if it does not it should just write a default value
>> (0.0, empty string, etc).
>
> Even said:
>
>> For relational databases such as SQLite,
>> Postgres or MySQL, this is also supported, unless if you try to write a
> NULL
>> value and the schema of the table constraints the column to be non
> NULLable,
>> you'll get an error when inserting/updating the feature.
>
> Which one is correct, or is it decided on a per-driver basis, with no policy
> specified by the OGR team? If this is too much trivia for you bother with,
> let me know and I will try to determine it by looking at the code.
Jason,
I imagine Even is correct about the behavior of some of the
RDBMS drivers.
> It would be nice if a future version of OGRFieldDefn allowed the caller to
> interrogate whether a field can be set to NULL. If it cannot be done, my
> personal preference would be for Even's behavior to occur: that
> OGRLayer::CreateFeature or SetFeature fails if a NULL field is not allowed
> by the underlying format. If NULLs are silently translated to 0.0, empty
> string, etc, this could be very bad for certain applications. It would be
> nice to protect the user from this, so he doesn't have to remember which
> formats support NULL and which do not. I would be happy to create a ticket
> if you thought this was worthwhile.
I'm personally ambivalent about this, but I have seen this (an IsNULLABLE
test) in other systems similar to OGR - for instance PCI's GDB.
> Even, you mentioned that the shapefile driver supports NULL fields. My
> understanding is that shapefiles do not support NULL, at least not according
> to ESRI. The only exception are date fields, which sort of support NULL. For
> more on that, see
> http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Geoprocessing%
> 20considerations%20for%20shapefile%20output. Does OGR do something
> different?
I believe Shapelib writes *** for numeric nulls, zeros for date nulls,
? for logical nulls and an empty string for other nulls. That means, for
instance, that Shapelib and OGR cannot differentiate between empty string
fields and null string fields (they will be reported as NULL).
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the gdal-dev
mailing list