File tree 1 file changed +29
-2
lines changed
1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -354,8 +354,35 @@ QgsVectorFileWriter::QgsVectorFileWriter(
354
354
return ;
355
355
}
356
356
357
+ QString name ( attrField.name () );
358
+
359
+ if ( driverName == " SQLite" && name.compare ( " ogc_fid" , Qt::CaseInsensitive ) == 0 )
360
+ {
361
+ int i;
362
+ for ( i = 0 ; i < 10 ; i++ )
363
+ {
364
+ name = QString ( " ogc_fid%1" ).arg ( i );
365
+
366
+ int j;
367
+ for ( j = 0 ; j < fields.size () && name.compare ( fields[j].name (), Qt::CaseInsensitive ) != 0 ; j++ )
368
+ ;
369
+
370
+ if ( j == fields.size () )
371
+ break ;
372
+ }
373
+
374
+ if ( i == 10 )
375
+ {
376
+ mErrorMessage = QObject::tr ( " no available replacement for internal fieldname ogc_fid found" ).arg ( attrField.name () );
377
+ mError = ErrAttributeCreationFailed;
378
+ return ;
379
+ }
380
+
381
+ QgsMessageLog::logMessage ( QObject::tr ( " Reserved attribute name ogc_fid replaced with %1" ).arg ( name ), QObject::tr ( " OGR" ) );
382
+ }
383
+
357
384
// create field definition
358
- OGRFieldDefnH fld = OGR_Fld_Create ( mCodec ->fromUnicode ( attrField. name () ), ogrType );
385
+ OGRFieldDefnH fld = OGR_Fld_Create ( mCodec ->fromUnicode ( name ), ogrType );
359
386
if ( ogrWidth > 0 )
360
387
{
361
388
OGR_Fld_SetWidth ( fld, ogrWidth );
@@ -383,7 +410,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
383
410
}
384
411
OGR_Fld_Destroy ( fld );
385
412
386
- int ogrIdx = OGR_FD_GetFieldIndex ( defn, mCodec ->fromUnicode ( attrField. name () ) );
413
+ int ogrIdx = OGR_FD_GetFieldIndex ( defn, mCodec ->fromUnicode ( name ) );
387
414
if ( ogrIdx < 0 )
388
415
{
389
416
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM < 1700
You can’t perform that action at this time.
0 commit comments