Opened 11 years ago

Closed 11 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()
Cc:

Description

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.CreateFeature(feat)

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

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

Attachments (1)

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

Download all attachments as: .zip

Change History (2)

by Even Rouault, 11 years ago

comment:1 by warmerdam, 11 years ago

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.