@@ -53,8 +53,6 @@ static const QString TEXT_PROVIDER_DESCRIPTION =
53
53
+ GDALVersionInfo( " RELEASE_NAME" )
54
54
+ " )";
55
55
56
-
57
-
58
56
QgsOgrProvider::QgsOgrProvider ( QString const & uri )
59
57
: QgsVectorDataProvider( uri ),
60
58
ogrDataSource( 0 ),
@@ -768,7 +766,11 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
768
766
}
769
767
}
770
768
771
- OGR_L_SetFeature ( ogrLayer, of );
769
+ OGRErr res;
770
+ if (( res = OGR_L_SetFeature ( ogrLayer, of ) ) != OGRERR_NONE )
771
+ {
772
+ QgsLogger::warning ( " QgsOgrProvider::changeAttributeValues, setting the feature failed: " + QString::number ( res ) );
773
+ }
772
774
}
773
775
774
776
OGR_L_SyncToDisk ( ogrLayer );
@@ -778,6 +780,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
778
780
779
781
bool QgsOgrProvider::changeGeometryValues ( QgsGeometryMap & geometry_map )
780
782
{
783
+ OGRErr res;
781
784
OGRFeatureH theOGRFeature = 0 ;
782
785
OGRGeometryH theNewGeometry = 0 ;
783
786
@@ -809,15 +812,23 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
809
812
}
810
813
811
814
// set the new geometry
812
- if ( OGR_F_SetGeometryDirectly ( theOGRFeature, theNewGeometry ) != OGRERR_NONE )
815
+ if (( res = OGR_F_SetGeometryDirectly ( theOGRFeature, theNewGeometry ) ) != OGRERR_NONE )
816
+ {
817
+ QgsLogger::warning ( " QgsOgrProvider::changeGeometryValues, error while replacing geometry: " + QString::number ( res ) );
818
+ OGR_G_DestroyGeometry ( theNewGeometry );
819
+ theNewGeometry = 0 ;
820
+ continue ;
821
+ }
822
+
823
+
824
+ if (( res = OGR_L_SetFeature ( ogrLayer, theOGRFeature ) ) != OGRERR_NONE )
813
825
{
814
- QgsLogger::warning ( " QgsOgrProvider::changeGeometryValues, error while replacing geometry " );
826
+ QgsLogger::warning ( " QgsOgrProvider::changeGeometryValues, error while setting feature: " + QString::number ( res ) );
815
827
OGR_G_DestroyGeometry ( theNewGeometry );
816
828
theNewGeometry = 0 ;
817
829
continue ;
818
830
}
819
831
820
- OGR_L_SetFeature ( ogrLayer, theOGRFeature );
821
832
OGR_F_Destroy ( theOGRFeature );
822
833
}
823
834
OGR_L_SyncToDisk ( ogrLayer );
@@ -914,7 +925,7 @@ int QgsOgrProvider::capabilities() const
914
925
// TODO And test appropriately.
915
926
916
927
ability |= ChangeAttributeValues;
917
- ability |= QgsVectorDataProvider:: ChangeGeometries;
928
+ ability |= ChangeGeometries;
918
929
}
919
930
920
931
if ( OGR_L_TestCapability ( ogrLayer, " FastSpatialFilter" ) )
@@ -1505,48 +1516,42 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()
1505
1516
void QgsOgrProvider::uniqueValues ( int index, QList<QVariant> &uniqueValues )
1506
1517
{
1507
1518
QgsField fld = mAttributeFields [index ];
1508
- QFileInfo fi ( dataSourceUri () );
1509
- if ( !fi.exists () )
1510
- return ;
1519
+ QString theLayerName = OGR_FD_GetName ( OGR_L_GetLayerDefn ( ogrLayer ) );
1511
1520
1512
1521
QString sql = QString ( " SELECT DISTINCT %1 FROM %2 ORDER BY %1" )
1513
1522
.arg ( quotedIdentifier ( fld.name () ) )
1514
- .arg ( quotedIdentifier ( fi. completeBaseName () ) );
1523
+ .arg ( quotedIdentifier ( theLayerName ) );
1515
1524
1516
1525
uniqueValues.clear ();
1517
1526
1518
1527
QgsDebugMsg ( QString ( " SQL: %1" ).arg ( sql ) );
1519
- OGRLayerH lyr = OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , " SQL" );
1520
- if ( 0 == lyr )
1521
- return ;
1528
+ OGRLayerH l = OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , " SQL" );
1529
+ if ( l == 0 )
1530
+ return QgsVectorDataProvider::uniqueValues ( index , uniqueValues ) ;
1522
1531
1523
1532
OGRFeatureH f;
1524
- while ( 0 != ( f = OGR_L_GetNextFeature ( lyr ) ) )
1533
+ while ( 0 != ( f = OGR_L_GetNextFeature ( l ) ) )
1525
1534
{
1526
1535
uniqueValues << convertValue ( fld.type (), mEncoding ->toUnicode ( OGR_F_GetFieldAsString ( f, 0 ) ) );
1527
1536
OGR_F_Destroy ( f );
1528
1537
}
1529
1538
1530
- OGR_DS_ReleaseResultSet ( ogrDataSource, lyr );
1539
+ OGR_DS_ReleaseResultSet ( ogrDataSource, l );
1531
1540
}
1532
1541
1533
-
1534
-
1535
1542
QVariant QgsOgrProvider::minimumValue ( int index )
1536
1543
{
1537
1544
QgsField fld = mAttributeFields [index ];
1538
- QFileInfo fi ( dataSourceUri () );
1539
- if ( !fi.exists () )
1540
- return QVariant ();
1545
+ QString theLayerName = OGR_FD_GetName ( OGR_L_GetLayerDefn ( ogrLayer ) );
1541
1546
1542
1547
QString sql = QString ( " SELECT MIN(%1) FROM %2" )
1543
1548
.arg ( quotedIdentifier ( fld.name () ) )
1544
- .arg ( quotedIdentifier ( fi. completeBaseName () ) );
1549
+ .arg ( quotedIdentifier ( theLayerName ) );
1545
1550
1546
1551
OGRLayerH l = OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , " SQL" );
1547
1552
1548
1553
if ( l == 0 )
1549
- return QVariant ( );
1554
+ return QgsVectorDataProvider::minimumValue ( index );
1550
1555
1551
1556
OGRFeatureH f = OGR_L_GetNextFeature ( l );
1552
1557
if ( f == 0 )
@@ -1566,17 +1571,15 @@ QVariant QgsOgrProvider::minimumValue( int index )
1566
1571
QVariant QgsOgrProvider::maximumValue ( int index )
1567
1572
{
1568
1573
QgsField fld = mAttributeFields [index ];
1569
- QFileInfo fi ( dataSourceUri () );
1570
- if ( !fi.exists () )
1571
- return QVariant ();
1574
+ QString theLayerName = OGR_FD_GetName ( OGR_L_GetLayerDefn ( ogrLayer ) );
1572
1575
1573
1576
QString sql = QString ( " SELECT MAX(%1) FROM %2" )
1574
1577
.arg ( quotedIdentifier ( fld.name () ) )
1575
- .arg ( quotedIdentifier ( fi. completeBaseName () ) );
1578
+ .arg ( quotedIdentifier ( theLayerName ) );
1576
1579
1577
1580
OGRLayerH l = OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , " SQL" );
1578
1581
if ( l == 0 )
1579
- return QVariant ( );
1582
+ return QgsVectorDataProvider::maximumValue ( index );
1580
1583
1581
1584
OGRFeatureH f = OGR_L_GetNextFeature ( l );
1582
1585
if ( f == 0 )
0 commit comments