@@ -256,7 +256,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
256
256
257
257
QString mySql = " select srs_id,description,projection_acronym,"
258
258
" ellipsoid_acronym,parameters,srid,auth_name||':'||auth_id,is_geo "
259
- " from tbl_srs where " + expression + " =" + quotedValue ( value );
259
+ " from tbl_srs where " + expression + " =" + quotedValue ( value ) + " order by deprecated " ;
260
260
myResult = sqlite3_prepare ( myDatabase, mySql.toUtf8 (),
261
261
mySql.toUtf8 ().length (),
262
262
&myPreparedStatement, &myTail );
@@ -444,7 +444,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
444
444
* - if the above does not match perform a whole text search on proj4 string (if not null)
445
445
*/
446
446
// QgsDebugMsg( "wholetext match on name failed, trying proj4string match" );
447
- myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( theProj4String.trimmed () ) );
447
+ myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( theProj4String.trimmed () ) + " order by deprecated " );
448
448
if ( myRecord.empty () )
449
449
{
450
450
// Ticket #722 - aaronr
@@ -479,7 +479,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
479
479
myStart2 = myLat2RegExp.indexIn ( theProj4String, myStart2 );
480
480
theProj4StringModified.replace ( myStart2 + LAT_PREFIX_LEN, myLength2 - LAT_PREFIX_LEN, lat1Str );
481
481
QgsDebugMsg ( " trying proj4string match with swapped lat_1,lat_2" );
482
- myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( theProj4StringModified.trimmed () ) );
482
+ myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( theProj4StringModified.trimmed () ) + " order by deprecated " );
483
483
}
484
484
}
485
485
@@ -496,9 +496,10 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
496
496
497
497
// split on spaces followed by a plus sign (+) to deal
498
498
// also with parameters containing spaces (e.g. +nadgrids)
499
+ // make sure result is trimmed (#5598)
499
500
foreach ( QString param, theProj4String.split ( QRegExp ( " \\ s+(?=\\ +)" ), QString::SkipEmptyParts ) )
500
501
{
501
- QString arg = QString ( " ' '||parameters||' ' LIKE %1" ).arg ( quotedValue ( QString ( " % %1 %" ).arg ( param ) ) );
502
+ QString arg = QString ( " ' '||parameters||' ' LIKE %1" ).arg ( quotedValue ( QString ( " % %1 %" ).arg ( param. trimmed () ) ) );
502
503
if ( param.startsWith ( " +datum=" ) )
503
504
{
504
505
datum = arg;
@@ -512,13 +513,13 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
512
513
513
514
if ( !datum.isEmpty () )
514
515
{
515
- myRecord = getRecord ( sql + delim + datum );
516
+ myRecord = getRecord ( sql + delim + datum + " order by deprecated " );
516
517
}
517
518
518
519
if ( myRecord.empty () )
519
520
{
520
521
// datum might have disappeared in definition - retry without it
521
- myRecord = getRecord ( sql );
522
+ myRecord = getRecord ( sql + " order by deprecated " );
522
523
}
523
524
}
524
525
@@ -558,7 +559,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
558
559
if ( mIsValidFlag )
559
560
{
560
561
// but the proj.4 parsed string might already be in our database
561
- myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( toProj4 () ) );
562
+ myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( toProj4 () ) + " order by deprecated " );
562
563
if ( myRecord.empty () )
563
564
{
564
565
// It's not, so try to add it
@@ -568,7 +569,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
568
569
if ( mIsValidFlag )
569
570
{
570
571
// but validate that it's there afterwards
571
- myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( toProj4 () ) );
572
+ myRecord = getRecord ( " select * from tbl_srs where parameters=" + quotedValue ( toProj4 () ) + " order by deprecated " );
572
573
}
573
574
}
574
575
@@ -928,7 +929,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
928
929
// Set up the query to retrieve the projection information
929
930
// needed to populate the list
930
931
QString mySql = QString ( " select srs_id,parameters from tbl_srs where "
931
- " projection_acronym=%1 and ellipsoid_acronym=%2" )
932
+ " projection_acronym=%1 and ellipsoid_acronym=%2 order by deprecated " )
932
933
.arg ( quotedValue ( mProjectionAcronym ) )
933
934
.arg ( quotedValue ( mEllipsoidAcronym ) );
934
935
// Get the full path name to the sqlite3 spatial reference database.
@@ -1212,7 +1213,7 @@ QString QgsCoordinateReferenceSystem::proj4FromSrsId( const int theSrsId )
1212
1213
1213
1214
QString myDatabaseFileName;
1214
1215
QString myProjString;
1215
- QString mySql = QString ( " select parameters from tbl_srs where srs_id = %1" ).arg ( theSrsId );
1216
+ QString mySql = QString ( " select parameters from tbl_srs where srs_id = %1 order by deprecated " ).arg ( theSrsId );
1216
1217
1217
1218
QgsDebugMsg ( " mySrsId = " + QString::number ( theSrsId ) );
1218
1219
QgsDebugMsg ( " USER_CRS_START_ID = " + QString::number ( USER_CRS_START_ID ) );
@@ -1451,7 +1452,7 @@ int QgsCoordinateReferenceSystem::syncDb()
1451
1452
1452
1453
const char *tail;
1453
1454
sqlite3_stmt *select ;
1454
- QString sql = " select auth_name,auth_id,parameters from tbl_srs WHERE auth_name IS NOT NULL AND auth_id IS NOT NULL" ;
1455
+ QString sql = " select auth_name,auth_id,parameters from tbl_srs WHERE auth_name IS NOT NULL AND auth_id IS NOT NULL order by deprecated " ;
1455
1456
if ( sqlite3_prepare ( database, sql.toAscii (), sql.size (), &select , &tail ) != SQLITE_OK )
1456
1457
{
1457
1458
qCritical ( " Could not prepare: %s [%s]\n " , sql.toAscii ().constData (), sqlite3_errmsg ( database ) );
0 commit comments