@@ -367,108 +367,121 @@ QString QgsPostgresProvider::storageType() const
367
367
return " PostgreSQL database with PostGIS extension" ;
368
368
}
369
369
370
- void QgsPostgresProvider::declareCursor (const QString &cursorName,
370
+ bool QgsPostgresProvider::declareCursor (const QString &cursorName,
371
371
const QgsAttributeList &fetchAttributes,
372
372
bool fetchGeometry,
373
- QString whereClause,
374
- QStringList &attributeNames)
373
+ QString whereClause)
375
374
{
376
- QString declare = QString (" declare %1 binary cursor with hold for select %2" )
377
- .arg (cursorName).arg (quotedIdentifier (primaryKey));
378
-
379
- if (fetchGeometry)
375
+ try
380
376
{
381
- declare += QString (" ,asbinary(%1,'%2') as qgs_feature_geometry" )
382
- .arg ( quotedIdentifier (geometryColumn) )
383
- .arg ( endianString () );
384
- }
377
+ QString declare = QString (" declare %1 binary cursor with hold for select %2" )
378
+ .arg (cursorName).arg (quotedIdentifier (primaryKey));
385
379
386
- QgsFieldMap attributeMap = fields ();
387
- for (QgsAttributeList::const_iterator it = fetchAttributes.constBegin (); it != fetchAttributes.constEnd (); ++it)
388
- {
389
- QgsFieldMap::const_iterator fieldIt = attributeMap.find (*it);
390
- if (fieldIt != attributeMap.end ())
380
+ if (fetchGeometry)
381
+ {
382
+ declare += QString (" ,asbinary(%1,'%2') as qgs_feature_geometry" )
383
+ .arg ( quotedIdentifier (geometryColumn) )
384
+ .arg ( endianString () );
385
+ }
386
+
387
+ for (QgsAttributeList::const_iterator it = fetchAttributes.constBegin (); it != fetchAttributes.constEnd (); ++it)
391
388
{
392
- const QString &fieldname = fieldIt.value ().name ();
389
+ const QgsField &fld = field (*it);
390
+
391
+ const QString &fieldname = fld.name ();
392
+ if ( fieldname == primaryKey )
393
+ continue ;
393
394
394
- if ( fieldname != primaryKey )
395
+ const QString &type = fld.typeName ();
396
+ if ( type == " money" || type.startsWith (" _" ) )
395
397
{
396
- if ( fieldIt.value ().typeName () == " money" || fieldIt.value ().typeName ().startsWith (" _" ) )
397
- {
398
- // money and arrays don't support cast to text, but return text
399
- // TODO: check other types
400
- declare += " ," + quotedIdentifier ( fieldname );
401
- }
402
- else if ( fieldIt.value ().typeName () == " bool" )
403
- {
404
- // bool doesn't support cast to text either and even doesn't return text.
405
- // (even text() doesn't work with binary cursors)
406
- declare += QString (" ,CASE WHEN %1 THEN 't' WHEN NOT %1 THEN 'f' ELSE NULL END AS %1" )
407
- .arg ( quotedIdentifier (fieldname) );
408
- }
409
- else
410
- {
411
- declare += " ," + quotedIdentifier ( fieldname ) + " ::text" ;
412
- }
398
+ // money and arrays don't support cast to text, but return text
399
+ // TODO: check other types
400
+ declare += " ," + quotedIdentifier ( fieldname );
401
+ }
402
+ else if ( type == " bool" )
403
+ {
404
+ // bool doesn't support cast to text either and even doesn't return text.
405
+ // (even text() doesn't work with binary cursors)
406
+ declare += QString (" ,CASE WHEN %1 THEN 't' WHEN NOT %1 THEN 'f' ELSE NULL END AS %1" )
407
+ .arg ( quotedIdentifier (fieldname) );
408
+ }
409
+ else
410
+ {
411
+ declare += " ," + quotedIdentifier ( fieldname ) + " ::text" ;
413
412
}
414
-
415
- attributeNames << fieldname;
416
413
}
417
- }
418
414
419
- declare += " from " + mSchemaTableName ;
420
-
421
- if ( !whereClause.isEmpty () )
422
- declare += QString (" where %1" ).arg (whereClause);
415
+ declare += " from " + mSchemaTableName ;
416
+
417
+ if ( !whereClause.isEmpty () )
418
+ declare += QString (" where %1" ).arg (whereClause);
423
419
424
- QgsDebugMsg (" Binary cursor: " + declare);
420
+ QgsDebugMsg (" Binary cursor: " + declare);
425
421
426
- PQexecNR (connection, declare.toUtf8 ());
422
+ return PQexecNR (connection, declare.toUtf8 ());
423
+ }
424
+ catch (PGFieldNotFound)
425
+ {
426
+ return false ;
427
+ }
427
428
}
428
429
429
- void QgsPostgresProvider::getFeature (PGresult *queryResult, int row, bool fetchGeometry,
430
+ bool QgsPostgresProvider::getFeature (PGresult *queryResult, int row, bool fetchGeometry,
430
431
QgsFeature &feature,
431
- const QStringList &attributeNames,
432
432
const QgsAttributeList &fetchAttributes)
433
433
{
434
- int oid = *(int *)PQgetvalue (queryResult, row, PQfnumber (queryResult,quotedIdentifier (primaryKey).toUtf8 ()));
435
- if (swapEndian)
436
- oid = ntohl (oid); // convert oid to opposite endian
434
+ try
435
+ {
436
+ int oid = *(int *)PQgetvalue (queryResult, row, 0 );
437
+ if (swapEndian)
438
+ oid = ntohl (oid); // convert oid to opposite endian
437
439
438
- feature.setFeatureId (oid);
440
+ feature.setFeatureId (oid);
439
441
440
- // fetch attributes
441
- QgsAttributeList::const_iterator it = fetchAttributes.constBegin ();
442
- for (QStringList::const_iterator namesIt = attributeNames.begin (); namesIt != attributeNames.end (); ++namesIt, ++it)
443
- {
444
- QString val;
442
+ int col; // first attribute column
445
443
446
- if ( (*namesIt) == primaryKey )
444
+ if (fetchGeometry )
447
445
{
448
- val = QString::number (oid);
449
- }
450
- else
451
- {
452
- int fn = PQfnumber (queryResult,quotedIdentifier (*namesIt).toUtf8 ());
453
-
454
- if ( !PQgetisnull (queryResult, row, fn) )
446
+ int returnedLength = PQgetlength (queryResult, row, 1 );
447
+ if (returnedLength > 0 )
455
448
{
456
- val = QString::fromUtf8 (PQgetvalue (queryResult, row, fn));
449
+ unsigned char *featureGeom = new unsigned char [returnedLength + 1 ];
450
+ memset (featureGeom, ' \0 ' , returnedLength + 1 );
451
+ memcpy (featureGeom, PQgetvalue (queryResult, row, PQfnumber (queryResult,QString (" qgs_feature_geometry" ).toUtf8 ())), returnedLength);
452
+ feature.setGeometryAndOwnership (featureGeom, returnedLength + 1 );
457
453
}
458
454
else
459
455
{
460
- val = QString::null;
456
+ feature.setGeometryAndOwnership (0 , 0 );
457
+ QgsDebugMsg (" Couldn't get the feature geometry in binary form" );
461
458
}
462
- }
463
459
464
- if ( val.isNull () )
465
- {
466
- feature.addAttribute (*it, val);
460
+ col = 2 ;
467
461
}
468
462
else
469
463
{
470
- switch (attributeFields[*it].type ())
464
+ col = 1 ;
465
+ }
466
+
467
+ // iterate attributes
468
+ for (QgsAttributeList::const_iterator it=fetchAttributes.constBegin (); it!=fetchAttributes.constEnd (); it++)
469
+ {
470
+ const QgsField &fld = field (*it);
471
+
472
+ if ( fld.name () == primaryKey )
471
473
{
474
+ // primary key was already processed
475
+ feature.addAttribute (*it, QString::number (oid) );
476
+ continue ;
477
+ }
478
+
479
+ if ( !PQgetisnull (queryResult, row, col) )
480
+ {
481
+ QString val = QString::fromUtf8 (PQgetvalue (queryResult, row, col));
482
+
483
+ switch (fld.type ())
484
+ {
472
485
case QVariant::LongLong:
473
486
feature.addAttribute (*it, val.toLongLong ());
474
487
break ;
@@ -483,26 +496,22 @@ void QgsPostgresProvider::getFeature(PGresult *queryResult, int row, bool fetchG
483
496
break ;
484
497
default :
485
498
assert (0 && " unsupported field type" );
499
+ }
486
500
}
501
+ else
502
+ {
503
+ feature.addAttribute (*it, QVariant (QString::null));
504
+ }
505
+
506
+ col++;
487
507
}
488
- }
489
508
490
- if (fetchGeometry)
509
+ return true ;
510
+ }
511
+ catch (PGFieldNotFound)
491
512
{
492
- int returnedLength = PQgetlength (queryResult, row, PQfnumber (queryResult," qgs_feature_geometry" ));
493
- if (returnedLength > 0 )
494
- {
495
- unsigned char *featureGeom = new unsigned char [returnedLength + 1 ];
496
- memset (featureGeom, ' \0 ' , returnedLength + 1 );
497
- memcpy (featureGeom, PQgetvalue (queryResult, row, PQfnumber (queryResult,QString (" qgs_feature_geometry" ).toUtf8 ())), returnedLength);
498
- feature.setGeometryAndOwnership (featureGeom, returnedLength + 1 );
499
- }
500
- else
501
- {
502
- feature.setGeometryAndOwnership (0 , 0 );
503
- QgsDebugMsg (" Couldn't get the feature geometry in binary form" );
504
- }
505
- }
513
+ return false ;
514
+ }
506
515
}
507
516
508
517
void QgsPostgresProvider::select (QgsAttributeList fetchAttributes, QgsRect rect, bool fetchGeometry, bool useIntersect)
@@ -552,8 +561,9 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes, QgsRect rect,
552
561
553
562
mFetchGeom = fetchGeometry;
554
563
mAttributesToFetch = fetchAttributes;
555
- declareCursor ( cursorName, fetchAttributes, fetchGeometry, whereClause, mFetchAttributeNames );
556
-
564
+ if ( !declareCursor ( cursorName, fetchAttributes, fetchGeometry, whereClause ) )
565
+ return ;
566
+
557
567
mFetching = true ;
558
568
mFirstFetch = true ;
559
569
}
@@ -594,7 +604,7 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
594
604
for (int row = 0 ; row < rows; row++)
595
605
{
596
606
mFeatureQueue .push (QgsFeature ());
597
- getFeature (queryResult, row, mFetchGeom , mFeatureQueue .back (), mFetchAttributeNames , mAttributesToFetch );
607
+ getFeature (queryResult, row, mFetchGeom , mFeatureQueue .back (), mAttributesToFetch );
598
608
} // for each row in queue
599
609
600
610
PQclear (queryResult);
@@ -625,9 +635,9 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
625
635
626
636
bool QgsPostgresProvider::getFeatureAtId (int featureId, QgsFeature& feature, bool fetchGeometry, QgsAttributeList fetchAttributes)
627
637
{
628
- QStringList attributeNames;
629
638
QString cursorName = QString (" qgisfid%1" ).arg (providerId);
630
- declareCursor ( cursorName, fetchAttributes, fetchGeometry, QString (" %2=%3" ).arg (quotedIdentifier (primaryKey)).arg (featureId), attributeNames );
639
+ if ( !declareCursor ( cursorName, fetchAttributes, fetchGeometry, QString (" %2=%3" ).arg (quotedIdentifier (primaryKey)).arg (featureId) ) )
640
+ return false ;
631
641
632
642
PGresult *queryResult = PQexec (connection, QString (" fetch forward 1 from %1" ).arg (cursorName).toUtf8 ());
633
643
if (queryResult==0 )
@@ -646,12 +656,13 @@ bool QgsPostgresProvider::getFeatureAtId(int featureId, QgsFeature& feature, boo
646
656
QgsDebugMsg ( QString (" found %1 features instead of just one." ).arg (rows) );
647
657
}
648
658
649
- getFeature (queryResult, 0 , fetchGeometry, feature, attributeNames , fetchAttributes);
659
+ bool gotit = getFeature (queryResult, 0 , fetchGeometry, feature, fetchAttributes);
650
660
651
661
PQclear (queryResult);
652
662
653
663
PQexecNR (connection, QString (" CLOSE %1" ).arg (cursorName).toUtf8 ());
654
- return true ;
664
+
665
+ return gotit;
655
666
}
656
667
657
668
@@ -690,6 +701,18 @@ long QgsPostgresProvider::featureCount() const
690
701
return numberFeatures;
691
702
}
692
703
704
+ const QgsField &QgsPostgresProvider::field (int index) const
705
+ {
706
+ QgsFieldMap::const_iterator it = attributeFields.find (index);
707
+
708
+ if ( it==attributeFields.constEnd () ) {
709
+ QgsDebugMsg (" Field " + QString::number (index) + " not found." );
710
+ throw PGFieldNotFound ();
711
+ }
712
+
713
+ return it.value ();
714
+ }
715
+
693
716
/* *
694
717
* Return the number of fields
695
718
*/
@@ -1577,83 +1600,103 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
1577
1600
// Returns the minimum value of an attribute
1578
1601
QVariant QgsPostgresProvider::minValue (int index)
1579
1602
{
1580
- // get the field name
1581
- QgsField fld = attributeFields[index];
1582
- QString sql;
1583
- if (sqlWhereClause.isEmpty ())
1603
+ try
1584
1604
{
1585
- sql = QString (" select min(%1) from %2" )
1586
- .arg (quotedIdentifier (fld.name ()))
1587
- .arg (mSchemaTableName );
1605
+ // get the field name
1606
+ const QgsField &fld = field (index);
1607
+ QString sql;
1608
+ if (sqlWhereClause.isEmpty ())
1609
+ {
1610
+ sql = QString (" select min(%1) from %2" )
1611
+ .arg (quotedIdentifier (fld.name ()))
1612
+ .arg (mSchemaTableName );
1613
+ }
1614
+ else
1615
+ {
1616
+ sql = QString (" select min(%1) from %2 where %3" )
1617
+ .arg (quotedIdentifier (fld.name ()))
1618
+ .arg (mSchemaTableName )
1619
+ .arg (sqlWhereClause);
1620
+ }
1621
+ PGresult *rmin = PQexec (connection, sql.toUtf8 ());
1622
+ QString minValue = QString::fromUtf8 (PQgetvalue (rmin,0 ,0 ));
1623
+ PQclear (rmin);
1624
+ return minValue.toDouble ();
1588
1625
}
1589
- else
1626
+ catch (PGFieldNotFound)
1590
1627
{
1591
- sql = QString (" select min(%1) from %2 where %3" )
1592
- .arg (quotedIdentifier (fld.name ()))
1593
- .arg (mSchemaTableName )
1594
- .arg (sqlWhereClause);
1628
+ return QVariant (QString::null);
1595
1629
}
1596
- PGresult *rmin = PQexec (connection, sql.toUtf8 ());
1597
- QString minValue = QString::fromUtf8 (PQgetvalue (rmin,0 ,0 ));
1598
- PQclear (rmin);
1599
- return minValue.toDouble ();
1600
1630
}
1601
1631
1602
1632
// Returns the list of unique values of an attribute
1603
1633
void QgsPostgresProvider::getUniqueValues (int index, QStringList &uniqueValues)
1604
1634
{
1605
- // get the field name
1606
- QgsField fld = attributeFields[index];
1607
- QString sql;
1608
- if (sqlWhereClause.isEmpty ())
1609
- {
1610
- sql = QString (" select distinct %1 from %2 order by %1" )
1611
- .arg (quotedIdentifier (fld.name ()))
1612
- .arg (mSchemaTableName );
1613
- }
1614
- else
1615
- {
1616
- sql = QString (" select distinct %1 from %2 where %3 order by %1" )
1617
- .arg (quotedIdentifier (fld.name ()))
1618
- .arg (mSchemaTableName )
1619
- .arg (sqlWhereClause);
1620
- }
1621
-
1622
1635
uniqueValues.clear ();
1623
1636
1624
- PGresult *res= PQexec (connection, sql.toUtf8 ());
1625
- if (PQresultStatus (res) == PGRES_TUPLES_OK)
1637
+ try
1626
1638
{
1627
- for (int i=0 ; i<PQntuples (res); i++)
1628
- uniqueValues.append ( QString::fromUtf8 (PQgetvalue (res,i,0 )) );
1639
+ // get the field name
1640
+ const QgsField &fld = field (index);
1641
+ QString sql;
1642
+ if (sqlWhereClause.isEmpty ())
1643
+ {
1644
+ sql = QString (" select distinct %1 from %2 order by %1" )
1645
+ .arg (quotedIdentifier (fld.name ()))
1646
+ .arg (mSchemaTableName );
1647
+ }
1648
+ else
1649
+ {
1650
+ sql = QString (" select distinct %1 from %2 where %3 order by %1" )
1651
+ .arg (quotedIdentifier (fld.name ()))
1652
+ .arg (mSchemaTableName )
1653
+ .arg (sqlWhereClause);
1654
+ }
1655
+
1656
+ PGresult *res= PQexec (connection, sql.toUtf8 ());
1657
+ if (PQresultStatus (res) == PGRES_TUPLES_OK)
1658
+ {
1659
+ for (int i=0 ; i<PQntuples (res); i++)
1660
+ uniqueValues.append ( QString::fromUtf8 (PQgetvalue (res,i,0 )) );
1661
+ }
1662
+ PQclear (res);
1663
+ }
1664
+ catch (PGFieldNotFound)
1665
+ {
1629
1666
}
1630
- PQclear (res);
1631
1667
}
1632
1668
1633
1669
// Returns the maximum value of an attribute
1634
1670
1635
1671
QVariant QgsPostgresProvider::maxValue (int index)
1636
1672
{
1637
- // get the field name
1638
- QgsField fld = attributeFields[index];
1639
- QString sql;
1640
- if (sqlWhereClause.isEmpty ())
1673
+ try
1641
1674
{
1642
- sql = QString (" select max(%1) from %2" )
1643
- .arg (quotedIdentifier (fld.name ()))
1644
- .arg (mSchemaTableName );
1675
+ // get the field name
1676
+ const QgsField &fld = field (index);
1677
+ QString sql;
1678
+ if (sqlWhereClause.isEmpty ())
1679
+ {
1680
+ sql = QString (" select max(%1) from %2" )
1681
+ .arg (quotedIdentifier (fld.name ()))
1682
+ .arg (mSchemaTableName );
1683
+ }
1684
+ else
1685
+ {
1686
+ sql = QString (" select max(%1) from %2 where %3" )
1687
+ .arg (quotedIdentifier (fld.name ()))
1688
+ .arg (mSchemaTableName )
1689
+ .arg (sqlWhereClause);
1690
+ }
1691
+ PGresult *rmax = PQexec (connection, sql.toUtf8 ());
1692
+ QString maxValue = QString::fromUtf8 (PQgetvalue (rmax,0 ,0 ));
1693
+ PQclear (rmax);
1694
+ return maxValue.toDouble ();
1645
1695
}
1646
- else
1696
+ catch (PGFieldNotFound)
1647
1697
{
1648
- sql = QString (" select max(%1) from %2 where %3" )
1649
- .arg (quotedIdentifier (fld.name ()))
1650
- .arg (mSchemaTableName )
1651
- .arg (sqlWhereClause);
1652
- }
1653
- PGresult *rmax = PQexec (connection, sql.toUtf8 ());
1654
- QString maxValue = QString::fromUtf8 (PQgetvalue (rmax,0 ,0 ));
1655
- PQclear (rmax);
1656
- return maxValue.toDouble ();
1698
+ return QVariant (QString::null);
1699
+ }
1657
1700
}
1658
1701
1659
1702
@@ -1679,33 +1722,39 @@ bool QgsPostgresProvider::isValid(){
1679
1722
1680
1723
QVariant QgsPostgresProvider::getDefaultValue (int fieldId)
1681
1724
{
1682
- // Get the default column value from the Postgres information
1683
- // schema. If there is no default we return an empty string.
1684
-
1685
- // Maintaining a cache of the results of this query would be quite
1686
- // simple and if this query is called lots, could save some time.
1725
+ try
1726
+ {
1727
+ // Get the default column value from the Postgres information
1728
+ // schema. If there is no default we return an empty string.
1687
1729
1688
- QString fieldName = attributeFields[fieldId].name ();
1730
+ // Maintaining a cache of the results of this query would be quite
1731
+ // simple and if this query is called lots, could save some time.
1732
+ QString fieldName = field (fieldId).name ();
1689
1733
1690
- QString sql (" SELECT column_default FROM"
1734
+ QString sql (" SELECT column_default FROM"
1691
1735
" information_schema.columns WHERE"
1692
1736
" column_default IS NOT NULL"
1693
1737
" AND table_schema = " + quotedValue (mSchemaName ) +
1694
1738
" AND table_name = " + quotedValue (mTableName ) +
1695
1739
" AND column_name = " + quotedValue (fieldName) );
1696
1740
1697
- QVariant defaultValue (QString::null);
1741
+ QVariant defaultValue (QString::null);
1698
1742
1699
- PGresult* result = PQexec (connection, sql.toUtf8 ());
1743
+ PGresult* result = PQexec (connection, sql.toUtf8 ());
1700
1744
1701
- if (PQntuples (result)==1 && !PQgetisnull (result, 0 , 0 ) )
1702
- defaultValue = QString::fromUtf8 (PQgetvalue (result, 0 , 0 ));
1745
+ if (PQntuples (result)==1 && !PQgetisnull (result, 0 , 0 ) )
1746
+ defaultValue = QString::fromUtf8 (PQgetvalue (result, 0 , 0 ));
1703
1747
1704
- // QgsDebugMsg( QString("defaultValue for %1 is NULL: %2").arg(fieldId).arg( defaultValue.isNull() ) );
1748
+ // QgsDebugMsg( QString("defaultValue for %1 is NULL: %2").arg(fieldId).arg( defaultValue.isNull() ) );
1705
1749
1706
- PQclear (result);
1750
+ PQclear (result);
1707
1751
1708
- return defaultValue;
1752
+ return defaultValue;
1753
+ }
1754
+ catch (PGFieldNotFound)
1755
+ {
1756
+ return QVariant (QString::null);
1757
+ }
1709
1758
}
1710
1759
1711
1760
/* *
@@ -2035,20 +2084,27 @@ bool QgsPostgresProvider::changeAttributeValues(const QgsChangedAttributesMap &
2035
2084
// cycle through the changed attributes of the feature
2036
2085
for (QgsAttributeMap::const_iterator siter = attrs.begin (); siter != attrs.end (); ++siter)
2037
2086
{
2038
- QString fieldName = attributeFields[siter.key ()].name ();
2039
-
2040
- QString sql = QString (" UPDATE %1 SET %2=%3 WHERE %4=%5" )
2041
- .arg ( mSchemaTableName )
2042
- .arg ( quotedIdentifier (fieldName) )
2043
- .arg ( quotedValue ( siter->toString () ) )
2044
- .arg ( quotedIdentifier (primaryKey) )
2045
- .arg ( fid );
2046
- QgsDebugMsg (sql);
2047
-
2048
- PGresult* result=PQexec (connection, sql.toUtf8 ());
2049
- if ( result==0 || PQresultStatus (result)==PGRES_FATAL_ERROR )
2050
- throw PGException (result);
2051
- PQclear (result);
2087
+ try {
2088
+ QString fieldName = field (siter.key ()).name ();
2089
+
2090
+ QString sql = QString (" UPDATE %1 SET %2=%3 WHERE %4=%5" )
2091
+ .arg ( mSchemaTableName )
2092
+ .arg ( quotedIdentifier (fieldName) )
2093
+ .arg ( quotedValue ( siter->toString () ) )
2094
+ .arg ( quotedIdentifier (primaryKey) )
2095
+ .arg ( fid );
2096
+ QgsDebugMsg (sql);
2097
+
2098
+ PGresult* result=PQexec (connection, sql.toUtf8 ());
2099
+ if ( result==0 || PQresultStatus (result)==PGRES_FATAL_ERROR )
2100
+ throw PGException (result);
2101
+
2102
+ PQclear (result);
2103
+ }
2104
+ catch (PGFieldNotFound)
2105
+ {
2106
+ // Field was missing - shouldn't happen
2107
+ }
2052
2108
}
2053
2109
}
2054
2110
@@ -2149,7 +2205,7 @@ bool QgsPostgresProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
2149
2205
QgsAttributeList QgsPostgresProvider::allAttributesList ()
2150
2206
{
2151
2207
QgsAttributeList attributes;
2152
- for (QgsFieldMap::iterator it = attributeFields.begin (); it != attributeFields.end (); ++it)
2208
+ for (QgsFieldMap::const_iterator it = attributeFields.constBegin (); it != attributeFields.constEnd (); ++it)
2153
2209
{
2154
2210
attributes.push_back (it.key ());
2155
2211
}
@@ -2607,21 +2663,25 @@ QString QgsPostgresProvider::quotedValue( QString value ) const
2607
2663
return value.prepend (" '" ).append (" '" );
2608
2664
}
2609
2665
2610
- void QgsPostgresProvider::PQexecNR (PGconn *conn, const char *query)
2666
+ bool QgsPostgresProvider::PQexecNR (PGconn *conn, const char *query)
2611
2667
{
2612
2668
PGresult *res = PQexec (conn, query);
2613
2669
if (res)
2614
2670
{
2671
+ int errorStatus = PQresultStatus (res);
2615
2672
QgsDebugMsgLevel ( QString (" Query: %1 returned %2 [%3]" )
2616
2673
.arg (query)
2617
- .arg (PQresStatus ( PQresultStatus (res)) )
2674
+ .arg (errorStatus )
2618
2675
.arg (PQresultErrorMessage (res)), 3 );
2619
2676
PQclear (res);
2677
+
2678
+ return errorStatus==PGRES_COMMAND_OK;
2620
2679
}
2621
2680
else
2622
2681
{
2623
2682
QgsDebugMsgLevel ( QString (" Query: %1 returned no result buffer" ).arg (query), 3 );
2624
2683
}
2684
+ return false ;
2625
2685
}
2626
2686
2627
2687
void QgsPostgresProvider::showMessageBox (const QString& title, const QString& text)
0 commit comments