Opened 10 years ago

Closed 10 years ago

#4073 closed defect (fixed)

[Shapelib - PATCH] DBFAddNativeFieldType should flush the active record before updating the file

Reported by: Even Rouault Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords: shape CreateField()


The following snippet leads to junk being written in the first record because it is not flushed to disk before adding the second field. The attached patch fixes this by issuing a DBFFlushRecord() at the beginning of DBFAddNativeFieldType.

ds = ogr.GetDriverByName('ESRI Shapefile').CreateDataSource('createfield.dbf')
lyr = ds.CreateLayer('createfield')

lyr.CreateField(ogr.FieldDefn('foo', ogr.OFTString))

feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetField(0, 'foo')

lyr.CreateField(ogr.FieldDefn('bar', ogr.OFTString))

feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetField(1, 'bar')
ds = None

Attachments (1)

dbfopen_fix_DBFAddNativeFieldType.patch (643 bytes) - added by Even Rouault 10 years ago.

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by Even Rouault

comment:1 Changed 10 years ago by warmerdam

Resolution: fixed
Status: newclosed

Patch applied upstream, and pulled back into trunk (r22328).

Note: See TracTickets for help on using tickets.