@@ -279,6 +279,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
279
279
QFileInfo myFI ( myFile );
280
280
QString myPath = myFI.path ();
281
281
QString myName = myFI.fileName ();
282
+ QString baseKey = " /SpatiaLite/connections/" ;
282
283
283
284
// TODO: keep the test
284
285
// handle = openSpatiaLiteDb( myFI.canonicalFilePath() );
@@ -287,13 +288,19 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
287
288
// OK, this one is a valid SpatiaLite DB
288
289
// closeSpatiaLiteDb( handle );
289
290
291
+ // if there is already a connection with this name, warn user (#9404) and do nothing
292
+ // ideally, user should be able to change item name so that several sqlite files with same name can co-exist
293
+ if ( ! settings.value ( baseKey + myName + " /sqlitepath" , " " ).toString ().isEmpty () )
294
+ {
295
+ QMessageBox::critical ( parent, tr ( " Error" ), tr ( " Cannot add connection '%1' : a connection with the same name already exists." ).arg ( myName ) );
296
+ return false ;
297
+ }
298
+
290
299
// Persist last used SpatiaLite dir
291
300
settings.setValue ( " /UI/lastSpatiaLiteDir" , myPath );
292
301
// inserting this SQLite DB path
293
- QString baseKey = " /SpatiaLite/connections/" ;
294
302
settings.setValue ( baseKey + " selected" , myName );
295
- baseKey += myName;
296
- settings.setValue ( baseKey + " /sqlitepath" , myFI.canonicalFilePath () );
303
+ settings.setValue ( baseKey + myName + " /sqlitepath" , myFI.canonicalFilePath () );
297
304
return true ;
298
305
}
299
306
0 commit comments