@@ -3270,7 +3270,7 @@ QString QgsSpatiaLiteProvider::description() const
3270
3270
return SPATIALITE_DESCRIPTION;
3271
3271
} // QgsSpatiaLiteProvider::description()
3272
3272
3273
- const QgsFields & QgsSpatiaLiteProvider::fields () const
3273
+ const QgsFields& QgsSpatiaLiteProvider::fields () const
3274
3274
{
3275
3275
return attributeFields;
3276
3276
}
@@ -3290,7 +3290,7 @@ QVariant QgsSpatiaLiteProvider::minimumValue( int index )
3290
3290
try
3291
3291
{
3292
3292
// get the field name
3293
- const QgsField & fld = field ( index );
3293
+ const QgsField& fld = field ( index );
3294
3294
3295
3295
sql = QString ( " SELECT Min(%1) FROM %2" ).arg ( quotedIdentifier ( fld.name () ) ).arg ( mQuery );
3296
3296
@@ -3301,41 +3301,44 @@ QVariant QgsSpatiaLiteProvider::minimumValue( int index )
3301
3301
3302
3302
ret = sqlite3_get_table ( sqliteHandle, sql.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
3303
3303
if ( ret != SQLITE_OK )
3304
- goto error;
3305
- if ( rows < 1 )
3306
- ;
3307
- else
3308
3304
{
3309
- for ( i = 1 ; i <= rows; i++ )
3305
+ QgsMessageLog::logMessage ( tr ( " SQLite error: %2\n SQL: %1" ).arg ( sql ).arg ( errMsg ? errMsg : tr ( " unknown cause" ) ), tr ( " SpatiaLite" ) );
3306
+ // unexpected error
3307
+ if ( errMsg != NULL )
3310
3308
{
3311
- minValue = results[( i * columns ) + 0 ] ;
3309
+ sqlite3_free ( errMsg ) ;
3312
3310
}
3313
- }
3314
- sqlite3_free_table ( results );
3315
-
3316
- if ( minValue.isEmpty () )
3317
- {
3318
- // NULL or not found
3319
- return QVariant ( QString::null );
3311
+ minValue = QString ();
3320
3312
}
3321
3313
else
3322
3314
{
3323
- return convertValue ( fld.type (), minValue );
3315
+ if ( rows < 1 )
3316
+ ;
3317
+ else
3318
+ {
3319
+ for ( i = 1 ; i <= rows; i++ )
3320
+ {
3321
+ minValue = results[( i * columns ) + 0 ];
3322
+ }
3323
+ }
3324
+ sqlite3_free_table ( results );
3325
+
3326
+ if ( minValue.isEmpty () )
3327
+ {
3328
+ // NULL or not found
3329
+ minValue = QString ();
3330
+ }
3324
3331
}
3332
+
3333
+ return convertValue ( fld.type (), minValue );
3325
3334
}
3326
3335
catch ( SLFieldNotFound )
3327
3336
{
3328
- return QVariant ( QString::null );
3337
+ return QVariant ( QVariant::Int );
3329
3338
}
3330
3339
3331
- error:
3332
- QgsMessageLog::logMessage ( tr ( " SQLite error: %2\n SQL: %1" ).arg ( sql ).arg ( errMsg ? errMsg : tr ( " unknown cause" ) ), tr ( " SpatiaLite" ) );
3333
- // unexpected error
3334
- if ( errMsg != NULL )
3335
- {
3336
- sqlite3_free ( errMsg );
3337
- }
3338
- return QVariant ( QString::null );
3340
+ // dummy return, so compiler is quiet
3341
+ return QVariant ();
3339
3342
}
3340
3343
3341
3344
// Returns the maximum value of an attribute
@@ -3364,41 +3367,45 @@ QVariant QgsSpatiaLiteProvider::maximumValue( int index )
3364
3367
3365
3368
ret = sqlite3_get_table ( sqliteHandle, sql.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
3366
3369
if ( ret != SQLITE_OK )
3367
- goto error;
3368
- if ( rows < 1 )
3369
- ;
3370
- else
3371
3370
{
3372
- for ( i = 1 ; i <= rows; i++ )
3371
+ QgsMessageLog::logMessage ( tr ( " SQLite error: %2\n SQL: %1" ).arg ( sql ).arg ( errMsg ? errMsg : tr ( " unknown cause" ) ), tr ( " SpatiaLite" ) );
3372
+ // unexpected error
3373
+ if ( errMsg != NULL )
3373
3374
{
3374
- maxValue = results[( i * columns ) + 0 ] ;
3375
+ sqlite3_free ( errMsg ) ;
3375
3376
}
3376
- }
3377
- sqlite3_free_table ( results );
3378
-
3379
- if ( maxValue.isEmpty () )
3380
- {
3381
- // NULL or not found
3382
- return QVariant ( QString::null );
3377
+ maxValue = QString ();
3383
3378
}
3384
3379
else
3385
3380
{
3386
- return convertValue ( fld.type (), maxValue );
3381
+
3382
+ if ( rows < 1 )
3383
+ ;
3384
+ else
3385
+ {
3386
+ for ( i = 1 ; i <= rows; i++ )
3387
+ {
3388
+ maxValue = results[( i * columns ) + 0 ];
3389
+ }
3390
+ }
3391
+ sqlite3_free_table ( results );
3392
+
3393
+ if ( maxValue.isEmpty () )
3394
+ {
3395
+ // NULL or not found
3396
+ maxValue = QString ();
3397
+ }
3387
3398
}
3399
+
3400
+ return convertValue ( fld.type (), maxValue );
3388
3401
}
3389
3402
catch ( SLFieldNotFound )
3390
3403
{
3391
- return QVariant ( QString::null );
3404
+ return QVariant ( QVariant::Int );
3392
3405
}
3393
3406
3394
- error:
3395
- QgsMessageLog::logMessage ( tr ( " SQLite error: %2\n SQL: %1" ).arg ( sql ).arg ( errMsg ? errMsg : tr ( " unknown cause" ) ), tr ( " SpatiaLite" ) );
3396
- // unexpected error
3397
- if ( errMsg != NULL )
3398
- {
3399
- sqlite3_free ( errMsg );
3400
- }
3401
- return QVariant ( QString::null );
3407
+ // dummy return, so compiler is quiet
3408
+ return QVariant ();
3402
3409
}
3403
3410
3404
3411
// Returns the list of unique values of an attribute
@@ -3565,7 +3572,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
3565
3572
3566
3573
for ( int i = 0 ; i < attributevec.count (); ++i )
3567
3574
{
3568
- if ( !attributevec[i].isValid () )
3575
+ if ( !attributevec[i].isNull () )
3569
3576
continue ;
3570
3577
3571
3578
if ( i >= attributeFields.count () )
@@ -3594,7 +3601,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
3594
3601
for ( QgsFeatureList::iterator features = flist.begin (); features != flist.end (); features++ )
3595
3602
{
3596
3603
// looping on each feature to insert
3597
- const QgsAttributes & attributevec = features->attributes ();
3604
+ const QgsAttributes& attributevec = features->attributes ();
3598
3605
3599
3606
// resetting Prepared Statement and bindings
3600
3607
sqlite3_reset ( stmt );
@@ -3627,23 +3634,18 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
3627
3634
for ( int i = 0 ; i < attributevec.count (); ++i )
3628
3635
{
3629
3636
QVariant v = attributevec[i];
3630
- if ( !v.isValid () )
3637
+ if ( !v.isNull () )
3631
3638
continue ;
3632
3639
3633
3640
// binding values for each attribute
3634
3641
if ( i >= attributeFields.count () )
3635
- continue ;
3642
+ break ;
3636
3643
3637
3644
QString fieldname = attributeFields[i].name ();
3638
3645
if ( fieldname.isEmpty () || fieldname == mGeometryColumn )
3639
3646
continue ;
3640
3647
3641
3648
QVariant::Type type = attributeFields[i].type ();
3642
- if ( v.toString ().isEmpty () )
3643
- {
3644
- // assuming to be a NULL value
3645
- type = QVariant::Invalid;
3646
- }
3647
3649
3648
3650
if ( type == QVariant::Int )
3649
3651
{
0 commit comments