Skip to content
Permalink
Browse files

error logging:

- fix key message in postgres provider
- add logging of errors to spatialite provider
- log commit errors in vector layer
  • Loading branch information
jef-n committed Jan 15, 2012
1 parent 64a0f7f commit 6f2ade7983e1748c474a26fea2c8c4332056c3e7
@@ -50,6 +50,7 @@
#include "qgsgeometry.h"
#include "qgslabel.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsmaptopixel.h"
#include "qgspoint.h"
#include "qgsproviderregistry.h"
@@ -3865,7 +3866,8 @@ bool QgsVectorLayer::commitChanges()

updateFieldMap();
mDataProvider->updateExtents();
QgsDebugMsg( "result:\n " + mCommitErrors.join( "\n " ) );

QgsMessageLog::logMessage( tr( "Commit errors:\n%1" ).arg( mCommitErrors.join( "\n" ) ) );

return success;
}
@@ -1398,9 +1398,12 @@ bool QgsPostgresProvider::determinePrimaryKey()
{
mPrimaryKeyType = pktTid;
}
else
{
QgsMessageLog::logMessage( tr( "The table has no column suitable for use as a key. Quantum GIS requires a primary key, a PostgreSQL oid column or a ctid for tables." ), tr( "PostGIS" ) );
}
}

QgsMessageLog::logMessage( tr( "The table has no column suitable for use as a key. Quantum GIS requires a primary key, a PostgreSQL oid column or a ctid for tables." ), tr( "PostGIS" ) );
}
else if ( type == "v" ) // the relation is a view
{
@@ -22,11 +22,11 @@ email : a.furieri@lqt.it
#include <qgsmessageoutput.h>
#include <qgsrectangle.h>
#include <qgscoordinatereferencesystem.h>
#include "qgsvectorlayerimport.h"

#include "qgsvectorlayerimport.h"
#include "qgsspatialiteprovider.h"

#include "qgslogger.h"
#include "qgsmessagelog.h"

#include <QFileInfo>
#include <QDir>
@@ -572,9 +572,7 @@ void QgsSpatiaLiteProvider::loadFields()
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
{
// some error occurred
QgsDebugMsg( QString( "SQLite error: %1\n\nSQL: %2" )
.arg( sql )
.arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
return;
}

@@ -642,10 +640,10 @@ void QgsSpatiaLiteProvider::loadFields()
return;

error:
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1" ).arg( QString::fromUtf8( errMsg ) ) );
sqlite3_free( errMsg );
}
}
@@ -840,7 +838,7 @@ bool QgsSpatiaLiteProvider::getFeature( sqlite3_stmt *stmt, bool fetchGeometry,
else
{
// some unexpected error occurred
QgsDebugMsg( QString( "sqlite3_step() error: %1" ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error getting feature: %1" ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ), tr( "SpatiaLite" ) );
return false;
}

@@ -3290,7 +3288,7 @@ bool QgsSpatiaLiteProvider::prepareStatement(
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
{
// some error occurred
QgsDebugMsg( QString( "SQLite error: %1\n\nSQL: %2" ).arg( sql ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
return false;
}

@@ -3421,10 +3419,10 @@ QVariant QgsSpatiaLiteProvider::minimumValue( int index )
}

error:
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1" ).arg( QString::fromUtf8( errMsg ) ) );
sqlite3_free( errMsg );
}
return QVariant( QString::null );
@@ -3476,10 +3474,10 @@ QVariant QgsSpatiaLiteProvider::maximumValue( int index )
}

error:
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1" ).arg( QString::fromUtf8( errMsg ) ) );
sqlite3_free( errMsg );
}
return QVariant( QString::null );
@@ -3518,7 +3516,7 @@ void QgsSpatiaLiteProvider::uniqueValues( int index, QList < QVariant > &uniqueV
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
{
// some error occurred
QgsDebugMsg( QString( "SQLite error: %1\n\nSQL: %2" ).arg( sql ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
return;
}

@@ -3554,7 +3552,7 @@ void QgsSpatiaLiteProvider::uniqueValues( int index, QList < QVariant > &uniqueV
}
else
{
QgsDebugMsg( QString( "SQL error:\n%1\n%2" ).arg( sql ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
sqlite3_finalize( stmt );
return;
}
@@ -3627,7 +3625,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
{
// some error occurred
QgsDebugMsg( QString( "SQLite error: %1\n\nSQL: %2" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
return false;
}

@@ -3727,7 +3725,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
return true;

abort:
QgsDebugMsg( QString( "SQL error:\n%1\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
if ( errMsg )
{
sqlite3_free( errMsg );
@@ -3763,7 +3761,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds &id )
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
{
// some error occurred
QgsDebugMsg( QString( "SQLite error: %1\n\nSQL: %2" ).arg( sql ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
return false;
}

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

abort:
QgsDebugMsg( QString( "SQL error:\n%1\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
if ( errMsg )
{
sqlite3_free( errMsg );
@@ -3861,7 +3859,7 @@ bool QgsSpatiaLiteProvider::addAttributes( const QList<QgsField> &attributes )
return true;

abort:
QgsDebugMsg( QString( "SQL error:\n%1\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
if ( errMsg )
{
sqlite3_free( errMsg );
@@ -3956,7 +3954,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
return true;

abort:
QgsDebugMsg( QString( "SQL error:\n%1\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
if ( errMsg )
{
sqlite3_free( errMsg );
@@ -3996,7 +3994,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
{
// some error occurred
QgsDebugMsg( QString( "SQLite error: %1\n\nSQL: %2" ).arg( sql ).arg( QString::fromUtf8( sqlite3_errmsg( sqliteHandle ) ) ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( sqlite3_errmsg( sqliteHandle ) ), tr( "SpatiaLite" ) );
return false;
}

@@ -4048,7 +4046,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
return true;

abort:
QgsDebugMsg( QString( "SQL error:\n%1\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
if ( errMsg )
{
sqlite3_free( errMsg );
@@ -4063,7 +4061,6 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
return false;
}


int QgsSpatiaLiteProvider::capabilities() const
{
return enabledCapabilities;
@@ -4240,7 +4237,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
}
if ( errMsg )
{
QgsDebugMsg( QString( "sqlite error %1 [%2]" ).arg( sql ).arg( errMsg ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
errMsg = 0;
}
@@ -4279,7 +4276,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
}
if ( errMsg )
{
QgsDebugMsg( QString( "sqlite error %1 [%2]" ).arg( sql ).arg( errMsg ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
errMsg = 0;
}
@@ -4323,7 +4320,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
}
if ( errMsg )
{
QgsDebugMsg( QString( "sqlite error %1 [%2]" ).arg( sql ).arg( errMsg ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
errMsg = 0;
}
@@ -4343,7 +4340,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
}
if ( errMsg )
{
QgsDebugMsg( QString( "sqlite error %1 [%2]" ).arg( sql ).arg( errMsg ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
errMsg = 0;
}
@@ -4363,7 +4360,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
}
if ( errMsg )
{
QgsDebugMsg( QString( "sqlite error %1 [%2]" ).arg( sql ).arg( errMsg ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
errMsg = 0;
}
@@ -4489,10 +4486,10 @@ bool QgsSpatiaLiteProvider::getTableGeometryDetails()
return getSridDetails();

error:
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1\n\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
sqlite3_free( errMsg );
}
return false;
@@ -4575,7 +4572,7 @@ bool QgsSpatiaLiteProvider::getViewGeometryDetails()
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1\n\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
}
return false;
@@ -4645,7 +4642,7 @@ bool QgsSpatiaLiteProvider::getVShapeGeometryDetails()
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1\n\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
}
return false;
@@ -4761,7 +4758,7 @@ bool QgsSpatiaLiteProvider::getQueryGeometryDetails()
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1\n\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
}
return false;
@@ -4798,7 +4795,7 @@ bool QgsSpatiaLiteProvider::getSridDetails()
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1\n\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
}
return false;
@@ -4849,7 +4846,7 @@ bool QgsSpatiaLiteProvider::getTableSummary()
// unexpected error
if ( errMsg != NULL )
{
QgsDebugMsg( QString( "SQL error: %1\n\n%2" ).arg( sql ).arg( errMsg ? QString::fromUtf8( errMsg ) : "unknown cause" ) );
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ), tr( "SpatiaLite" ) );
sqlite3_free( errMsg );
}
return false;
@@ -4993,7 +4990,7 @@ QGISEXTERN bool createDb( const QString& dbPath, QString& errCause )
ret = sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, &errMsg );
if ( ret != SQLITE_OK )
{
errCause = QObject::tr( "Unable to activate FOREIGN_KEY constraints" );
errCause = QObject::tr( "Unable to activate FOREIGN_KEY constraints [%1]" ).arg( errMsg );
sqlite3_free( errMsg );
sqlite3_close( sqlite_handle );
return false;

0 comments on commit 6f2ade7

Please sign in to comment.
You can’t perform that action at this time.