@@ -2961,6 +2961,13 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
2961
2961
throw PGException ( result );
2962
2962
}
2963
2963
2964
+ if ( options->contains ( " lowercaseFieldNames" ) && options->value ( " lowercaseFieldNames" ).toBool () )
2965
+ {
2966
+ // convert primary key name to lowercase
2967
+ // this must happen after determining the field type of the primary key
2968
+ primaryKey = primaryKey.toLower ();
2969
+ }
2970
+
2964
2971
sql = QString ( " CREATE TABLE %1(%2 %3 PRIMARY KEY)" )
2965
2972
.arg ( schemaTableName )
2966
2973
.arg ( quotedIdentifier ( primaryKey ) )
@@ -3040,14 +3047,11 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
3040
3047
for ( int fldIdx = 0 ; fldIdx < fields.count (); ++fldIdx )
3041
3048
{
3042
3049
QgsField fld = fields[fldIdx];
3043
- if ( fld.name () == primaryKey )
3044
- {
3045
- oldToNewAttrIdxMap->insert ( fldIdx, 0 );
3046
- continue ;
3047
- }
3048
3050
3049
3051
if ( fld.name () == geometryColumn )
3050
3052
{
3053
+ // the "lowercaseFieldNames" option does not affect the name of the geometry column, so we perform
3054
+ // this test before converting the field name to lowercase
3051
3055
QgsDebugMsg ( " Found a field with the same name of the geometry column. Skip it!" );
3052
3056
continue ;
3053
3057
}
@@ -3058,6 +3062,12 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
3058
3062
fld.setName ( fld.name ().toLower () );
3059
3063
}
3060
3064
3065
+ if ( fld.name () == primaryKey )
3066
+ {
3067
+ oldToNewAttrIdxMap->insert ( fldIdx, 0 );
3068
+ continue ;
3069
+ }
3070
+
3061
3071
if ( !convertField ( fld, options ) )
3062
3072
{
3063
3073
if ( errorMessage )
0 commit comments