Skip to content
Permalink
Browse files

fix #3036

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14276 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Sep 23, 2010
1 parent 2639de6 commit 924d03c4161b6a92ee93d9f03e92032988139409
Showing with 24 additions and 6 deletions.
  1. +24 −6 src/core/qgsvectorfilewriter.cpp
@@ -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 );

0 comments on commit 924d03c

Please sign in to comment.
You can’t perform that action at this time.