Skip to content
Permalink
Browse files
Make PostgreSQL lowercaseFieldNames option behave correctly with prim…
…ary key field names
  • Loading branch information
nyalldawson committed May 20, 2014
1 parent 7772042 commit 3470b1d5c074ee5377ad43f939252f5b6c3ac152
Showing with 15 additions and 5 deletions.
  1. +15 −5 src/providers/postgres/qgspostgresprovider.cpp
@@ -2961,6 +2961,13 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
throw PGException( result );
}

if ( options->contains( "lowercaseFieldNames" ) && options->value( "lowercaseFieldNames" ).toBool() )
{
//convert primary key name to lowercase
//this must happen after determining the field type of the primary key
primaryKey = primaryKey.toLower();
}

sql = QString( "CREATE TABLE %1(%2 %3 PRIMARY KEY)" )
.arg( schemaTableName )
.arg( quotedIdentifier( primaryKey ) )
@@ -3040,14 +3047,11 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{
QgsField fld = fields[fldIdx];
if ( fld.name() == primaryKey )
{
oldToNewAttrIdxMap->insert( fldIdx, 0 );
continue;
}

if ( fld.name() == geometryColumn )
{
//the "lowercaseFieldNames" option does not affect the name of the geometry column, so we perform
//this test before converting the field name to lowercase
QgsDebugMsg( "Found a field with the same name of the geometry column. Skip it!" );
continue;
}
@@ -3058,6 +3062,12 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
fld.setName( fld.name().toLower() );
}

if ( fld.name() == primaryKey )
{
oldToNewAttrIdxMap->insert( fldIdx, 0 );
continue;
}

if ( !convertField( fld, options ) )
{
if ( errorMessage )

0 comments on commit 3470b1d

Please sign in to comment.