Skip to content

Commit fbdf34c

Browse files
committed
warn user when trying to add sqlite connection to browser and a connection with sae name already exists (#9404)
1 parent 5d02020 commit fbdf34c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/providers/spatialite/qgsspatialitesourceselect.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
279279
QFileInfo myFI( myFile );
280280
QString myPath = myFI.path();
281281
QString myName = myFI.fileName();
282+
QString baseKey = "/SpatiaLite/connections/";
282283

283284
// TODO: keep the test
284285
//handle = openSpatiaLiteDb( myFI.canonicalFilePath() );
@@ -287,13 +288,19 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
287288
// OK, this one is a valid SpatiaLite DB
288289
//closeSpatiaLiteDb( handle );
289290

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+
290299
// Persist last used SpatiaLite dir
291300
settings.setValue( "/UI/lastSpatiaLiteDir", myPath );
292301
// inserting this SQLite DB path
293-
QString baseKey = "/SpatiaLite/connections/";
294302
settings.setValue( baseKey + "selected", myName );
295-
baseKey += myName;
296-
settings.setValue( baseKey + "/sqlitepath", myFI.canonicalFilePath() );
303+
settings.setValue( baseKey + myName + "/sqlitepath", myFI.canonicalFilePath() );
297304
return true;
298305
}
299306

0 commit comments

Comments
 (0)