2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid

QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setSourceCrs( mLayer->crs() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )

QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setSourceCrs( mLayer->crs() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void QgsDistanceArea::setSourceCrs( long srsid )
mCoordTransform->setSourceCrs( srcCRS );
}

void QgsDistanceArea::setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS )
{
mCoordTransform->setSourceCrs( srcCRS );
}

void QgsDistanceArea::setSourceAuthId( QString authId )
{
QgsCoordinateReferenceSystem srcCRS;
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsdistancearea.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class CORE_EXPORT QgsDistanceArea
//! sets source spatial reference system (by QGIS CRS)
void setSourceCrs( long srsid );

//! sets source spatial reference system (by QGIS CRS)
void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );

//! sets source spatial reference system by authid
void setSourceAuthId( QString authid );

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, QString value
{
QVariant v( value );

if ( !v.convert( type ) )
v = QVariant( QString::null );
if ( !v.convert( type ) || value.isNull() )
v = QVariant( type );

return v;
}
Expand Down
116 changes: 59 additions & 57 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,7 +3270,7 @@ QString QgsSpatiaLiteProvider::description() const
return SPATIALITE_DESCRIPTION;
} // QgsSpatiaLiteProvider::description()

const QgsFields & QgsSpatiaLiteProvider::fields() const
const QgsFields& QgsSpatiaLiteProvider::fields() const
{
return attributeFields;
}
Expand All @@ -3290,7 +3290,7 @@ QVariant QgsSpatiaLiteProvider::minimumValue( int index )
try
{
// get the field name
const QgsField & fld = field( index );
const QgsField& fld = field( index );

sql = QString( "SELECT Min(%1) FROM %2" ).arg( quotedIdentifier( fld.name() ) ).arg( mQuery );

Expand All @@ -3301,41 +3301,44 @@ QVariant QgsSpatiaLiteProvider::minimumValue( int index )

ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
goto error;
if ( rows < 1 )
;
else
{
for ( i = 1; i <= rows; i++ )
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
minValue = results[( i * columns ) + 0];
sqlite3_free( errMsg );
}
}
sqlite3_free_table( results );

if ( minValue.isEmpty() )
{
// NULL or not found
return QVariant( QString::null );
minValue = QString();
}
else
{
return convertValue( fld.type(), minValue );
if ( rows < 1 )
;
else
{
for ( i = 1; i <= rows; i++ )
{
minValue = results[( i * columns ) + 0];
}
}
sqlite3_free_table( results );

if ( minValue.isEmpty() )
{
// NULL or not found
minValue = QString();
}
}

return convertValue( fld.type(), minValue );
}
catch ( SLFieldNotFound )
{
return QVariant( QString::null );
return QVariant( QVariant::Int );
}

error:
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
sqlite3_free( errMsg );
}
return QVariant( QString::null );
// dummy return, so compiler is quiet
return QVariant();
}

// Returns the maximum value of an attribute
Expand Down Expand Up @@ -3364,41 +3367,45 @@ QVariant QgsSpatiaLiteProvider::maximumValue( int index )

ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
goto error;
if ( rows < 1 )
;
else
{
for ( i = 1; i <= rows; i++ )
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
maxValue = results[( i * columns ) + 0];
sqlite3_free( errMsg );
}
}
sqlite3_free_table( results );

if ( maxValue.isEmpty() )
{
// NULL or not found
return QVariant( QString::null );
maxValue = QString();
}
else
{
return convertValue( fld.type(), maxValue );

if ( rows < 1 )
;
else
{
for ( i = 1; i <= rows; i++ )
{
maxValue = results[( i * columns ) + 0];
}
}
sqlite3_free_table( results );

if ( maxValue.isEmpty() )
{
// NULL or not found
maxValue = QString();
}
}

return convertValue( fld.type(), maxValue );
}
catch ( SLFieldNotFound )
{
return QVariant( QString::null );
return QVariant( QVariant::Int );
}

error:
QgsMessageLog::logMessage( tr( "SQLite error: %2\nSQL: %1" ).arg( sql ).arg( errMsg ? errMsg : tr( "unknown cause" ) ), tr( "SpatiaLite" ) );
// unexpected error
if ( errMsg != NULL )
{
sqlite3_free( errMsg );
}
return QVariant( QString::null );
// dummy return, so compiler is quiet
return QVariant();
}

// Returns the list of unique values of an attribute
Expand Down Expand Up @@ -3565,7 +3572,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )

for ( int i = 0; i < attributevec.count(); ++i )
{
if ( !attributevec[i].isValid() )
if ( !attributevec[i].isNull() )
continue;

if ( i >= attributeFields.count() )
Expand Down Expand Up @@ -3594,7 +3601,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); features++ )
{
// looping on each feature to insert
const QgsAttributes & attributevec = features->attributes();
const QgsAttributes& attributevec = features->attributes();

// resetting Prepared Statement and bindings
sqlite3_reset( stmt );
Expand Down Expand Up @@ -3627,23 +3634,18 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
for ( int i = 0; i < attributevec.count(); ++i )
{
QVariant v = attributevec[i];
if ( !v.isValid() )
if ( !v.isNull() )
continue;

// binding values for each attribute
if ( i >= attributeFields.count() )
continue;
break;

QString fieldname = attributeFields[i].name();
if ( fieldname.isEmpty() || fieldname == mGeometryColumn )
continue;

QVariant::Type type = attributeFields[i].type();
if ( v.toString().isEmpty() )
{
// assuming to be a NULL value
type = QVariant::Invalid;
}

if ( type == QVariant::Int )
{
Expand Down