Skip to content

Commit

Permalink
qgspostgresprovider: Fix primary key retrieval with lowercase option
Browse files Browse the repository at this point in the history
The `lowercaseFieldNames` allows to transform the column names to
lowercase. If this option is enabled, then the requested primary
key (`primaryKey`) is in lowercase but the `fields` are
not. Therefore, the requested primary key will never be found.

This issues is fixed by converting the field names to lowercase when
looking for the primary key if the option is enabled.

Closes: qgis#55856
  • Loading branch information
ptitjano committed Feb 7, 2024
1 parent b6c7889 commit ba315b4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4609,13 +4609,15 @@ Qgis::VectorExportResult QgsPostgresProvider::createEmptyLayer( const QString &u
{
pkList = parseUriKey( primaryKey );
const auto constPkList = pkList;
const bool lowercaseFieldNames = options && options->value( QStringLiteral( "lowercaseFieldNames" ), false ).toBool();
for ( const QString &col : constPkList )
{
// search for the passed field
QString type;
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{
if ( fields[fldIdx].name() == col )
const QString fieldName = lowercaseFieldNames ? fields[fldIdx].name().toLower() : fields[fldIdx].name();
if ( fieldName == col )
{
// found, get the field type
QgsField fld = fields[fldIdx];
Expand Down

0 comments on commit ba315b4

Please sign in to comment.