Skip to content

Commit 98876da

Browse files
committedJan 17, 2012
commit error update:
- push commit errors in PostgreSQL, OGR and SpatiaLite provider - add provider errors to commit error - postgres provider: improve handling of geography columns
1 parent 0c9e60f commit 98876da

File tree

7 files changed

+100
-64
lines changed

7 files changed

+100
-64
lines changed
 

‎src/core/qgsvectorlayer.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,10 +3800,15 @@ bool QgsVectorLayer::commitChanges()
38003800

38013801
mAddedFeatures.clear();
38023802
}
3803+
else
3804+
{
3805+
mCommitErrors << tr( "ERROR: %n feature(s) not added.", "not added features count", mAddedFeatures.size() );
3806+
success = false;
3807+
}
38033808
}
38043809
else
38053810
{
3806-
mCommitErrors << tr( "ERROR: %n feature(s) not added.", "not added features count", mAddedFeatures.size() );
3811+
mCommitErrors << tr( "ERROR: %n feature(s) not added - provider doesn't support adding features.", "not added features count", mAddedFeatures.size() );
38073812
success = false;
38083813
}
38093814
}
@@ -3854,6 +3859,17 @@ bool QgsVectorLayer::commitChanges()
38543859
}
38553860
}
38563861

3862+
if ( !success )
3863+
{
3864+
if ( mDataProvider->hasErrors() )
3865+
{
3866+
mCommitErrors << tr( "\n Provider errors:" ) << mDataProvider->errors();
3867+
mDataProvider->clearErrors();
3868+
}
3869+
3870+
QgsMessageLog::logMessage( tr( "Commit errors:\n %1" ).arg( mCommitErrors.join( "\n " ) ) );
3871+
}
3872+
38573873
deleteCachedGeometries();
38583874

38593875
if ( success )
@@ -3867,8 +3883,6 @@ bool QgsVectorLayer::commitChanges()
38673883
updateFieldMap();
38683884
mDataProvider->updateExtents();
38693885

3870-
QgsMessageLog::logMessage( tr( "Commit errors:\n%1" ).arg( mCommitErrors.join( "\n" ) ) );
3871-
38723886
return success;
38733887
}
38743888

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ bool QgsOgrProvider::setSubsetString( QString theSQL, bool updateFeatureCount )
358358

359359
if ( !ogrLayer )
360360
{
361-
pushError( QString( "OGR[%1] error %2: %3" ).arg( CPLGetLastErrorType() ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ) );
361+
pushError( tr( "OGR[%1] error %2: %3" ).arg( CPLGetLastErrorType() ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ) );
362362
ogrLayer = prevLayer;
363363
mSubsetString = prevSubsetString;
364364
return false;
@@ -962,9 +962,9 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
962962
unsigned char* wkb = f.geometry()->asWkb();
963963
OGRGeometryH geom = NULL;
964964

965-
if ( OGR_G_CreateFromWkb( wkb, NULL, &geom, f.geometry()->wkbSize() )
966-
!= OGRERR_NONE )
965+
if ( OGR_G_CreateFromWkb( wkb, NULL, &geom, f.geometry()->wkbSize() ) != OGRERR_NONE )
967966
{
967+
pushError( tr( "OGR error creating wkb for feature %1: %2" ).arg( f.id() ).arg( CPLGetLastErrorMsg() ) );
968968
return false;
969969
}
970970

@@ -1021,7 +1021,7 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
10211021

10221022
if ( OGR_L_CreateFeature( ogrLayer, feature ) != OGRERR_NONE )
10231023
{
1024-
QgsMessageLog::logMessage( tr( "Writing of the feature %1 failed" ).arg( f.id() ), tr( "OGR" ) );
1024+
pushError( tr( "OGR error creating feature %1: %2" ).arg( f.id() ).arg( CPLGetLastErrorMsg() ) );
10251025
returnValue = false;
10261026
}
10271027
else
@@ -1078,7 +1078,7 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
10781078
type = OFTString;
10791079
break;
10801080
default:
1081-
QgsMessageLog::logMessage( tr( "type %1 for field %2 not found" ).arg( iter->typeName() ).arg( iter->name() ), tr( "OGR" ) );
1081+
pushError( tr( "type %1 for field %2 not found" ).arg( iter->typeName() ).arg( iter->name() ) );
10821082
returnvalue = false;
10831083
continue;
10841084
}
@@ -1089,7 +1089,7 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
10891089

10901090
if ( OGR_L_CreateField( ogrLayer, fielddefn, true ) != OGRERR_NONE )
10911091
{
1092-
QgsMessageLog::logMessage( tr( "writing of field %1 failed" ).arg( iter->name() ), tr( "OGR" ) );
1092+
pushError( tr( "OGR error creating field %1: %2" ).arg( iter->name() ).arg( CPLGetLastErrorMsg() ) );
10931093
returnvalue = false;
10941094
}
10951095
OGR_Fld_Destroy( fielddefn );
@@ -1109,15 +1109,15 @@ bool QgsOgrProvider::deleteAttributes( const QgsAttributeIds &attributes )
11091109
{
11101110
if ( OGR_L_DeleteField( ogrLayer, attr ) != OGRERR_NONE )
11111111
{
1112-
QgsMessageLog::logMessage( tr( "Failed to delete attribute %1" ).arg( attr ), tr( "OGR" ) );
1112+
pushError( tr( "OGR error deleting field %1: %2" ).arg( attr ).arg( CPLGetLastErrorMsg() ) );
11131113
res = false;
11141114
}
11151115
}
11161116
loadFields();
11171117
return res;
11181118
#else
11191119
Q_UNUSED( attributes );
1120-
QgsDebugMsg( "Deleting fields is supported only from GDAL >= 1.9.0" );
1120+
pushError( tr( "Deleting fields is not supported prior to GDAL 1.9.0" ) );
11211121
return false;
11221122
#endif
11231123
}
@@ -1138,15 +1138,15 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
11381138

11391139
if ( FID_TO_NUMBER( fid ) > std::numeric_limits<long>::max() )
11401140
{
1141-
QgsMessageLog::logMessage( tr( "Feature id %1 too large for OGR" ).arg( fid ), tr( "OGR" ) );
1141+
pushError( tr( "OGR error on feature %1: id too large" ).arg( fid ) );
11421142
continue;
11431143
}
11441144

11451145
OGRFeatureH of = OGR_L_GetFeature( ogrLayer, static_cast<long>( FID_TO_NUMBER( fid ) ) );
11461146

11471147
if ( !of )
11481148
{
1149-
QgsMessageLog::logMessage( tr( "Feature %1 for attribute update not found." ).arg( fid ), tr( "OGR" ) );
1149+
pushError( tr( "Feature %1 for attribute update not found." ).arg( fid ) );
11501150
continue;
11511151
}
11521152

@@ -1159,7 +1159,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
11591159
OGRFieldDefnH fd = OGR_F_GetFieldDefnRef( of, f );
11601160
if ( !fd )
11611161
{
1162-
QgsMessageLog::logMessage( tr( "Field %1 of feature %2 doesn't exist." ).arg( f ).arg( fid ), tr( "OGR" ) );
1162+
pushError( tr( "Field %1 of feature %2 doesn't exist." ).arg( f ).arg( fid ) );
11631163
continue;
11641164
}
11651165

@@ -1184,16 +1184,15 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
11841184
OGR_F_SetFieldString( of, f, mEncoding->fromUnicode( it2->toString() ).constData() );
11851185
break;
11861186
default:
1187-
QgsMessageLog::logMessage( tr( "Type %1 of attribute %2 of feature %3 unknown." ).arg( type ).arg( fid ).arg( f ), tr( "OGR" ) );
1187+
pushError( tr( "Type %1 of attribute %2 of feature %3 unknown." ).arg( type ).arg( fid ).arg( f ) );
11881188
break;
11891189
}
11901190
}
11911191
}
11921192

1193-
OGRErr res;
1194-
if (( res = OGR_L_SetFeature( ogrLayer, of ) ) != OGRERR_NONE )
1193+
if ( OGR_L_SetFeature( ogrLayer, of ) != OGRERR_NONE )
11951194
{
1196-
QgsMessageLog::logMessage( tr( "Update of Feature %1 failed: %2" ).arg( fid ).arg( res ), tr( "OGR" ) );
1195+
pushError( tr( "OGR error setting feature %1: %2" ).arg( fid ).arg( CPLGetLastErrorMsg() ) );
11971196
}
11981197
}
11991198

@@ -1203,7 +1202,6 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
12031202

12041203
bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
12051204
{
1206-
OGRErr res;
12071205
OGRFeatureH theOGRFeature = 0;
12081206
OGRGeometryH theNewGeometry = 0;
12091207

@@ -1213,14 +1211,14 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
12131211
{
12141212
if ( FID_TO_NUMBER( it.key() ) > std::numeric_limits<long>::max() )
12151213
{
1216-
QgsMessageLog::logMessage( tr( "Feature id %1 too large for OGR" ).arg( it.key() ), tr( "OGR" ) );
1214+
pushError( tr( "OGR error on feature %1: id too large" ).arg( it.key() ) );
12171215
continue;
12181216
}
12191217

12201218
theOGRFeature = OGR_L_GetFeature( ogrLayer, static_cast<long>( FID_TO_NUMBER( it.key() ) ) );
12211219
if ( !theOGRFeature )
12221220
{
1223-
QgsMessageLog::logMessage( tr( "Feature %1 not found for geometry update." ).arg( it.key() ), tr( "OGR" ) );
1221+
pushError( tr( "OGR error changing geometry: feature %1 not found" ).arg( it.key() ) );
12241222
continue;
12251223
}
12261224

@@ -1230,31 +1228,31 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
12301228
&theNewGeometry,
12311229
it->wkbSize() ) != OGRERR_NONE )
12321230
{
1233-
QgsMessageLog::logMessage( tr( "Creation of new geometry for feature %1 failed." ).arg( it.key() ), tr( "OGR" ) );
1231+
pushError( tr( "OGR error creating geometry for feature %1: %2" ).arg( it.key() ).arg( CPLGetLastErrorMsg() ) );
12341232
OGR_G_DestroyGeometry( theNewGeometry );
12351233
theNewGeometry = 0;
12361234
continue;
12371235
}
12381236

12391237
if ( !theNewGeometry )
12401238
{
1241-
QgsMessageLog::logMessage( tr( "Newly created geometry for feature %1 is null." ).arg( it.key() ), tr( "OGR" ) );
1239+
pushError( tr( "OGR error in feature %1: geometry is null" ).arg( it.key() ) );
12421240
continue;
12431241
}
12441242

12451243
//set the new geometry
1246-
if (( res = OGR_F_SetGeometryDirectly( theOGRFeature, theNewGeometry ) ) != OGRERR_NONE )
1244+
if ( OGR_F_SetGeometryDirectly( theOGRFeature, theNewGeometry ) != OGRERR_NONE )
12471245
{
1248-
QgsMessageLog::logMessage( tr( "Geometry update for feature %1 failed: %2" ).arg( it.key() ).arg( res ), tr( "OGR" ) );
1246+
pushError( tr( "OGR error setting geometry of feature %1: %2" ).arg( it.key() ).arg( CPLGetLastErrorMsg() ) );
12491247
OGR_G_DestroyGeometry( theNewGeometry );
12501248
theNewGeometry = 0;
12511249
continue;
12521250
}
12531251

12541252

1255-
if (( res = OGR_L_SetFeature( ogrLayer, theOGRFeature ) ) != OGRERR_NONE )
1253+
if ( OGR_L_SetFeature( ogrLayer, theOGRFeature ) != OGRERR_NONE )
12561254
{
1257-
QgsMessageLog::logMessage( tr( "Update of feature %1 failed: %2" ).arg( it.key() ).arg( res ), tr( "OGR" ) );
1255+
pushError( tr( "OGR error setting feature %1: %2" ).arg( it.key() ).arg( CPLGetLastErrorMsg() ) );
12581256
OGR_G_DestroyGeometry( theNewGeometry );
12591257
theNewGeometry = 0;
12601258
continue;
@@ -1336,11 +1334,17 @@ bool QgsOgrProvider::deleteFeature( QgsFeatureId id )
13361334
{
13371335
if ( FID_TO_NUMBER( id ) > std::numeric_limits<long>::max() )
13381336
{
1339-
QgsMessageLog::logMessage( tr( "id %1 too large for OGR" ).arg( id ), tr( "OGR" ) );
1337+
pushError( tr( "OGR error on feature %1: id too large" ).arg( id ) );
13401338
return false;
13411339
}
13421340

1343-
return OGR_L_DeleteFeature( ogrLayer, FID_TO_NUMBER( id ) ) == OGRERR_NONE;
1341+
if ( OGR_L_DeleteFeature( ogrLayer, FID_TO_NUMBER( id ) ) != OGRERR_NONE )
1342+
{
1343+
pushError( tr( "OGR error deleting feature %1: %2" ).arg( id ).arg( CPLGetLastErrorMsg() ) );
1344+
return false;
1345+
}
1346+
1347+
return true;
13441348
}
13451349

13461350
int QgsOgrProvider::capabilities() const

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,13 @@ QString QgsPostgresConn::postgisVersion()
662662
return mPostgisVersionInfo;
663663
}
664664

665-
QString QgsPostgresConn::quotedIdentifier( QString ident )
665+
QString QgsPostgresConn::quotedIdentifier( QString ident, bool isGeography )
666666
{
667667
ident.replace( '"', "\"\"" );
668-
return ident.prepend( "\"" ).append( "\"" );
668+
ident = ident.prepend( "\"" ).append( "\"" );
669+
if ( isGeography )
670+
ident += "::geometry";
671+
return ident;
669672
}
670673

671674
QString QgsPostgresConn::quotedValue( QVariant value )
@@ -694,23 +697,32 @@ PGresult *QgsPostgresConn::PQexec( QString query, bool logError )
694697
QgsDebugMsgLevel( QString( "Executing SQL: %1" ).arg( query ), 3 );
695698
PGresult *res = ::PQexec( mConn, query.toUtf8() );
696699

697-
if ( logError )
700+
if ( res )
698701
{
699-
if ( res )
702+
int errorStatus = PQresultStatus( res );
703+
if ( errorStatus != PGRES_COMMAND_OK && errorStatus != PGRES_TUPLES_OK )
700704
{
701-
int errorStatus = PQresultStatus( res );
702-
if ( errorStatus != PGRES_COMMAND_OK && errorStatus != PGRES_TUPLES_OK )
705+
if ( logError )
703706
{
704707
QgsMessageLog::logMessage( tr( "Errornous query: %1 returned %2 [%3]" )
705708
.arg( query ).arg( errorStatus ).arg( PQresultErrorMessage( res ) ),
706709
tr( "PostGIS" ) );
707710
}
708-
}
709-
else
710-
{
711-
QgsMessageLog::logMessage( tr( "Query failed: %1\nError: %2" ).arg( query ), tr( "PostGIS" ) );
711+
else
712+
{
713+
QgsDebugMsg( QString( "Not logged errornous query: %1 returned %2 [%3]" )
714+
.arg( query ).arg( errorStatus ).arg( PQresultErrorMessage( res ) ) );
715+
}
712716
}
713717
}
718+
else if ( logError )
719+
{
720+
QgsMessageLog::logMessage( tr( "Query failed: %1\nError: no result buffer" ).arg( query ) );
721+
}
722+
else
723+
{
724+
QgsDebugMsg( tr( "Not logged query failed: %1\nError: no result buffer" ).arg( query ) );
725+
}
714726

715727
return res;
716728
}
@@ -742,7 +754,7 @@ bool QgsPostgresConn::closeCursor( QString cursorName )
742754

743755
bool QgsPostgresConn::PQexecNR( QString query, bool retry )
744756
{
745-
QgsPostgresResult res = ::PQexec( mConn, query.toUtf8() );
757+
QgsPostgresResult res = PQexec( query, false );
746758

747759
ExecStatusType errorStatus = res.PQresultStatus();
748760
if ( errorStatus == PGRES_COMMAND_OK )
@@ -849,6 +861,7 @@ QString QgsPostgresConn::PQerrorMessage()
849861

850862
int QgsPostgresConn::PQsendQuery( QString query )
851863
{
864+
Q_ASSERT( mConn );
852865
return ::PQsendQuery( mConn, query.toUtf8() );
853866
}
854867

@@ -1027,7 +1040,7 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
10271040
.arg( postgisTypeFilter( layerProperty.geometryColName, QGis::Line, layerProperty.isGeography ) )
10281041
.arg( postgisTypeFilter( layerProperty.geometryColName, QGis::Polygon, layerProperty.isGeography ) )
10291042
.arg( majorVersion() < 2 ? "srid" : "st_srid" )
1030-
.arg( quotedIdentifier( layerProperty.geometryColName ) )
1043+
.arg( quotedIdentifier( layerProperty.geometryColName, layerProperty.isGeography ) )
10311044
.arg( table );
10321045

10331046
QgsDebugMsg( "Retrieving geometry types: " + query );
@@ -1119,9 +1132,7 @@ QString QgsPostgresConn::postgisWkbTypeName( QGis::WkbType wkbType )
11191132

11201133
QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QGis::GeometryType geomType, bool isGeography )
11211134
{
1122-
geomCol = quotedIdentifier( geomCol );
1123-
if ( isGeography )
1124-
geomCol += "::geometry";
1135+
geomCol = quotedIdentifier( geomCol, isGeography );
11251136

11261137
switch ( geomType )
11271138
{

‎src/providers/postgres/qgspostgresconn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class QgsPostgresConn : public QObject
134134

135135
/** Double quote a PostgreSQL identifier for placement in a SQL string.
136136
*/
137-
static QString quotedIdentifier( QString ident );
137+
static QString quotedIdentifier( QString ident, bool isGeography = false );
138138

139139
/** Quote a value for placement in a SQL string.
140140
*/

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ bool QgsPostgresProvider::declareCursor(
254254

255255
if ( fetchGeometry )
256256
{
257-
query += QString( "%1(%2(%3::geometry),'%4')" )
257+
query += QString( "%1(%2(%3),'%4')" )
258258
.arg( mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
259259
.arg( mConnectionRO->majorVersion() < 2 ? "force_2d" : "st_force_2d" )
260-
.arg( quotedIdentifier( mGeometryColumn ) )
260+
.arg( quotedIdentifier( mGeometryColumn, mIsGeography ) )
261261
.arg( endianString() );
262262
delim = ",";
263263
}
@@ -557,7 +557,7 @@ void QgsPostgresProvider::select( QgsAttributeList fetchAttributes, QgsRectangle
557557
{
558558
whereClause += QString( " AND %1(%2,%3)" )
559559
.arg( mConnectionRO->majorVersion() < 2 ? "intersects" : "st_intersects" )
560-
.arg( quotedIdentifier( mGeometryColumn ) )
560+
.arg( quotedIdentifier( mGeometryColumn, mIsGeography ) )
561561
.arg( qBox );
562562
}
563563
}
@@ -566,7 +566,7 @@ void QgsPostgresProvider::select( QgsAttributeList fetchAttributes, QgsRectangle
566566
{
567567
whereClause += QString( " AND %1(%2)=%3" )
568568
.arg( mConnectionRO->majorVersion() < 2 ? "srid" : "st_srid" )
569-
.arg( quotedIdentifier( mGeometryColumn ) )
569+
.arg( quotedIdentifier( mGeometryColumn, mIsGeography ) )
570570
.arg( mRequestedSrid );
571571
}
572572

@@ -626,6 +626,12 @@ bool QgsPostgresProvider::nextFeature( QgsFeature& feature )
626626
if ( !queryResult.result() )
627627
break;
628628

629+
if ( queryResult.PQresultStatus() != PGRES_TUPLES_OK )
630+
{
631+
QgsMessageLog::logMessage( tr( "Fetching from cursor %1 failed\nDatabase error: %2" ).arg( cursorName ).arg( mConnectionRO->PQerrorMessage() ), tr( "PostGIS" ) );
632+
break;
633+
}
634+
629635
int rows = queryResult.PQntuples();
630636
if ( rows == 0 )
631637
continue;
@@ -853,7 +859,7 @@ bool QgsPostgresProvider::featureAtId( QgsFeatureId featureId, QgsFeature& featu
853859
if ( !declareCursor( cursorName, fetchAttributes, fetchGeometry, whereClause( featureId ) ) )
854860
return false;
855861

856-
QgsPostgresResult queryResult = mConnectionRO->PQexec( QString( "fetch forward 1 from %1" ).arg( cursorName ) );
862+
QgsPostgresResult queryResult = mConnectionRO->PQexec( QString( "FETCH FORWARD 1 FROM %1" ).arg( cursorName ) );
857863

858864
int rows = queryResult.PQntuples();
859865
if ( rows == 0 )
@@ -1961,7 +1967,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
19611967
}
19621968
catch ( PGException &e )
19631969
{
1964-
QgsMessageLog::logMessage( tr( "Error while adding features.\nError: %1" ).arg( e.errorMessage() ), tr( "PostGIS" ) );
1970+
pushError( tr( "PostGIS error while adding features: %1" ).arg( e.errorMessage() ) );
19651971
mConnectionRW->PQexecNR( "ROLLBACK" );
19661972
mConnectionRW->PQexecNR( "DEALLOCATE addfeatures" );
19671973
returnvalue = false;
@@ -2007,7 +2013,7 @@ bool QgsPostgresProvider::deleteFeatures( const QgsFeatureIds & id )
20072013
}
20082014
catch ( PGException &e )
20092015
{
2010-
QgsMessageLog::logMessage( tr( "Error while deleting features.\nError: %1" ).arg( e.errorMessage() ), tr( "PostGIS" ) );
2016+
pushError( tr( "PostGIS error while deleting features: %1" ).arg( e.errorMessage() ) );
20112017
mConnectionRW->PQexecNR( "ROLLBACK" );
20122018
returnvalue = false;
20132019
}
@@ -2070,7 +2076,7 @@ bool QgsPostgresProvider::addAttributes( const QList<QgsField> &attributes )
20702076
}
20712077
catch ( PGException &e )
20722078
{
2073-
QgsMessageLog::logMessage( tr( "Error while adding attributes. Error: %1" ).arg( e.errorMessage() ), tr( "PostGIS" ) );
2079+
pushError( tr( "PostGIS error while adding attributes: %1" ).arg( e.errorMessage() ) );
20742080
mConnectionRW->PQexecNR( "ROLLBACK" );
20752081
returnvalue = false;
20762082
}
@@ -2117,7 +2123,7 @@ bool QgsPostgresProvider::deleteAttributes( const QgsAttributeIds& ids )
21172123
}
21182124
catch ( PGException &e )
21192125
{
2120-
QgsMessageLog::logMessage( tr( "Error while deleting attributes.\nError: %1" ).arg( e.errorMessage() ), tr( "PostGIS" ) );
2126+
pushError( tr( "PostGIS error while deleting attributes: %1" ).arg( e.errorMessage() ) );
21212127
mConnectionRW->PQexecNR( "ROLLBACK" );
21222128
returnvalue = false;
21232129
}
@@ -2222,7 +2228,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
22222228
}
22232229
catch ( PGException &e )
22242230
{
2225-
QgsMessageLog::logMessage( tr( "Error while changing attributes.\nError: %1" ).arg( e.errorMessage() ), tr( "PostGIS" ) );
2231+
pushError( tr( "PostGIS error while changing attributes: %1" ).arg( e.errorMessage() ) );
22262232
mConnectionRW->PQexecNR( "ROLLBACK" );
22272233
returnvalue = false;
22282234
}
@@ -2305,7 +2311,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
23052311
}
23062312
catch ( PGException &e )
23072313
{
2308-
QgsMessageLog::logMessage( tr( "Error while changing geometry values.\nError: %1" ).arg( e.errorMessage() ), tr( "PostGIS" ) );
2314+
pushError( tr( "PostGIS error while changing geometry values: %1" ).arg( e.errorMessage() ) );
23092315
mConnectionRW->PQexecNR( "ROLLBACK" );
23102316
mConnectionRW->PQexecNR( "DEALLOCATE updatefeatures" );
23112317
returnvalue = false;
@@ -2624,6 +2630,7 @@ bool QgsPostgresProvider::getGeometryDetails()
26242630
layerProperty.schemaName = mSchemaName;
26252631
layerProperty.tableName = mTableName;
26262632
layerProperty.geometryColName = mGeometryColumn;
2633+
layerProperty.isGeography = mIsGeography;
26272634

26282635
QString delim = "";
26292636

@@ -2644,7 +2651,7 @@ bool QgsPostgresProvider::getGeometryDetails()
26442651
layerProperty.sql += QString( "%1%2(%3)=%4" )
26452652
.arg( delim )
26462653
.arg( mConnectionRO->majorVersion() < 2 ? "srid" : "st_srid" )
2647-
.arg( quotedIdentifier( mGeometryColumn ) )
2654+
.arg( quotedIdentifier( mGeometryColumn, mIsGeography ) )
26482655
.arg( mRequestedSrid );
26492656
delim = " AND ";
26502657
}

‎src/providers/postgres/qgspostgresprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
488488

489489
void disconnectDb();
490490

491-
static QString quotedIdentifier( QString ident ) { return QgsPostgresConn::quotedIdentifier( ident ); }
491+
static QString quotedIdentifier( QString ident, bool isGeography = false ) { return QgsPostgresConn::quotedIdentifier( ident, isGeography ); }
492492
static QString quotedValue( QVariant value ) { return QgsPostgresConn::quotedValue( value ); }
493493

494494
static int sProviderIds;

‎src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,7 +3725,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
37253725
return true;
37263726

37273727
abort:
3728-
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
3728+
pushError( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ) );
37293729
if ( errMsg )
37303730
{
37313731
sqlite3_free( errMsg );
@@ -3761,7 +3761,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds &id )
37613761
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
37623762
{
37633763
// some error occurred
3764-
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
3764+
pushError( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ) );
37653765
return false;
37663766
}
37673767

@@ -3803,7 +3803,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds &id )
38033803
return true;
38043804

38053805
abort:
3806-
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
3806+
pushError( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ) );
38073807
if ( errMsg )
38083808
{
38093809
sqlite3_free( errMsg );
@@ -3859,7 +3859,7 @@ bool QgsSpatiaLiteProvider::addAttributes( const QList<QgsField> &attributes )
38593859
return true;
38603860

38613861
abort:
3862-
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
3862+
pushError( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ) );
38633863
if ( errMsg )
38643864
{
38653865
sqlite3_free( errMsg );
@@ -3954,7 +3954,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
39543954
return true;
39553955

39563956
abort:
3957-
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
3957+
pushError( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ) );
39583958
if ( errMsg )
39593959
{
39603960
sqlite3_free( errMsg );
@@ -4046,7 +4046,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
40464046
return true;
40474047

40484048
abort:
4049-
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
4049+
pushError( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ) );
40504050
if ( errMsg )
40514051
{
40524052
sqlite3_free( errMsg );

0 commit comments

Comments
 (0)
Please sign in to comment.