@@ -418,7 +418,6 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
418
418
for (int row = 0 ; row < rows; row++)
419
419
{
420
420
int oid = *(int *)PQgetvalue (queryResult, row, PQfnumber (queryResult," \" " +primaryKey+" \" " ));
421
- // QgsDebugMsg("Primary key type is " + QString::number(primaryKeyType));
422
421
423
422
if (swapEndian)
424
423
oid = ntohl (oid); // convert oid to opposite endian
@@ -432,11 +431,17 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
432
431
433
432
for (; name_it != mFetchAttributeNames .end (); ++name_it, ++index_it)
434
433
{
435
- QString name = *name_it; // just for the debugger
436
- // int number = PQfnumber(queryResult,*name_it); //just for the debugger
437
- char * attribute = PQgetvalue (queryResult, row, PQfnumber (queryResult,*name_it));
434
+ QString val;
435
+ if ( (*name_it) == primaryKey)
436
+ {
437
+ val = QString::number (oid);
438
+ }
439
+ else
440
+ {
441
+ char * attribute = PQgetvalue (queryResult, row, PQfnumber (queryResult,*name_it));
442
+ val = QString::fromUtf8 (attribute);
443
+ }
438
444
439
- QString val = QString::fromUtf8 (attribute);
440
445
switch (attributeFields[*index_it].type ())
441
446
{
442
447
case QVariant::Int:
@@ -534,7 +539,10 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes,
534
539
}
535
540
for (std::list<QString>::const_iterator it = mFetchAttributeNames .begin (); it != mFetchAttributeNames .end (); ++it)
536
541
{
537
- declare += " ," + *it + " ::text" ;
542
+ if ( (*it) != primaryKey) // no need to fetch primary key again
543
+ {
544
+ declare += " ," + *it + " ::text" ;
545
+ }
538
546
}
539
547
540
548
declare += " " ;
@@ -625,7 +633,10 @@ bool QgsPostgresProvider::getFeatureAtId(int featureId,
625
633
}
626
634
for (namesIt = attributeNames.begin (); namesIt != attributeNames.end (); ++namesIt)
627
635
{
628
- sql += " ," + *namesIt + " ::text" ;
636
+ if ( (*namesIt) != primaryKey) // no need to fetch primary key again
637
+ {
638
+ sql += " ," + *namesIt + " ::text" ;
639
+ }
629
640
}
630
641
631
642
sql += " " + QString (" from %1" ).arg (mSchemaTableName );
@@ -660,10 +671,17 @@ bool QgsPostgresProvider::getFeatureAtId(int featureId,
660
671
661
672
for (namesIt = attributeNames.begin (); namesIt != attributeNames.end (); ++namesIt, ++it)
662
673
{
663
- QString name = *namesIt; // just for the debugger
664
- char * attribute = PQgetvalue (res, 0 , PQfnumber (res,*namesIt));
674
+ QString val;
675
+ if ( (*namesIt) == primaryKey)
676
+ {
677
+ val = QString::number (oid);
678
+ }
679
+ else
680
+ {
681
+ char * attribute = PQgetvalue (res, 0 , PQfnumber (res,*namesIt));
682
+ val = QString::fromUtf8 (attribute);
683
+ }
665
684
666
- QString val = QString::fromUtf8 (attribute);
667
685
switch (attributeFields[*it].type ())
668
686
{
669
687
case QVariant::Int:
0 commit comments