Skip to content

Commit

Permalink
fix #3036
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14276 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 23, 2010
1 parent 2639de6 commit 924d03c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -309,12 +309,30 @@ QgsVectorFileWriter::QgsVectorFileWriter(
int ogrIdx = OGR_FD_GetFieldIndex( defn, mCodec->fromUnicode( attrField.name() ) );
if ( ogrIdx < 0 )
{
QgsDebugMsg( "error creating field " + attrField.name() );
mErrorMessage = QObject::tr( "created field %1 not found (OGR error: %2)" )
.arg( attrField.name() )
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
mError = ErrAttributeCreationFailed;
return;
// if we didn't find our new column, assume it's name was truncated and
// it was the last one added (like for shape files)
int fieldCount = OGR_FD_GetFieldCount( defn );

OGRFieldDefnH fdefn = OGR_FD_GetFieldDefn( defn, fieldCount - 1 );
if ( fdefn )
{
const char *fieldName = OGR_Fld_GetNameRef( fdefn );

if ( attrField.name().left( strlen( fieldName ) ) == fieldName )
{
ogrIdx = fieldCount - 1;
}
}

if ( ogrIdx < 0 )
{
QgsDebugMsg( "error creating field " + attrField.name() );
mErrorMessage = QObject::tr( "created field %1 not found (OGR error: %2)" )
.arg( attrField.name() )
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
mError = ErrAttributeCreationFailed;
return;
}
}

mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx );
Expand Down

0 comments on commit 924d03c

Please sign in to comment.