[QGIS Commit] r14276 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Sep 23 11:13:23 EDT 2010


Author: jef
Date: 2010-09-23 15:13:23 +0000 (Thu, 23 Sep 2010)
New Revision: 14276

Modified:
   trunk/qgis/src/core/qgsvectorfilewriter.cpp
Log:
fix #3036

Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp	2010-09-23 15:00:15 UTC (rev 14275)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp	2010-09-23 15:13:23 UTC (rev 14276)
@@ -309,12 +309,30 @@
     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 );



More information about the QGIS-commit mailing list