Skip to content

Commit cdf7d44

Browse files
author
jef
committedSep 23, 2010
fix #3036
git-svn-id: http://svn.osgeo.org/qgis/trunk@14276 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d7d8789 commit cdf7d44

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,30 @@ QgsVectorFileWriter::QgsVectorFileWriter(
309309
int ogrIdx = OGR_FD_GetFieldIndex( defn, mCodec->fromUnicode( attrField.name() ) );
310310
if ( ogrIdx < 0 )
311311
{
312-
QgsDebugMsg( "error creating field " + attrField.name() );
313-
mErrorMessage = QObject::tr( "created field %1 not found (OGR error: %2)" )
314-
.arg( attrField.name() )
315-
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
316-
mError = ErrAttributeCreationFailed;
317-
return;
312+
// if we didn't find our new column, assume it's name was truncated and
313+
// it was the last one added (like for shape files)
314+
int fieldCount = OGR_FD_GetFieldCount( defn );
315+
316+
OGRFieldDefnH fdefn = OGR_FD_GetFieldDefn( defn, fieldCount - 1 );
317+
if ( fdefn )
318+
{
319+
const char *fieldName = OGR_Fld_GetNameRef( fdefn );
320+
321+
if ( attrField.name().left( strlen( fieldName ) ) == fieldName )
322+
{
323+
ogrIdx = fieldCount - 1;
324+
}
325+
}
326+
327+
if ( ogrIdx < 0 )
328+
{
329+
QgsDebugMsg( "error creating field " + attrField.name() );
330+
mErrorMessage = QObject::tr( "created field %1 not found (OGR error: %2)" )
331+
.arg( attrField.name() )
332+
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
333+
mError = ErrAttributeCreationFailed;
334+
return;
335+
}
318336
}
319337

320338
mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx );

0 commit comments

Comments
 (0)
Please sign in to comment.