Skip to content
Permalink
Browse files

Merge pull request #2443 from elpaso/bugfix-11794

SQLITE ask for a new name if already exists
  • Loading branch information
elpaso committed Nov 12, 2015
2 parents be8c7da + 325f099 commit 854ce17699601167429d5ba55db4e16d3d452df9
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/providers/spatialite/qgsspatialitesourceselect.cpp
@@ -281,6 +281,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
QFileInfo myFI( myFile );
QString myPath = myFI.path();
QString myName = myFI.fileName();
QString savedName = myFI.fileName();
QString baseKey = "/SpatiaLite/connections/";

// TODO: keep the test
@@ -290,19 +291,24 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
// OK, this one is a valid SpatiaLite DB
//closeSpatiaLiteDb( handle );

// if there is already a connection with this name, warn user (#9404) and do nothing
// ideally, user should be able to change item name so that several sqlite files with same name can co-exist
if ( ! settings.value( baseKey + myName + "/sqlitepath", "" ).toString().isEmpty() )
// if there is already a connection with this name, ask for a new name
while ( ! settings.value( baseKey + savedName + "/sqlitepath", "" ).toString().isEmpty() )
{
QMessageBox::critical( parent, tr( "Error" ), tr( "Cannot add connection '%1' : a connection with the same name already exists." ).arg( myName ) );
return false;
bool ok;
savedName = QInputDialog::getText( NULL , tr( "Cannot add connection '%1'" ).arg( myName ) ,
tr( "A connection with the same name already exists,\nplease provide a new name:" ), QLineEdit::Normal,
"", &ok );
if ( !ok || savedName.isEmpty() )
{
return false;
}
}

// Persist last used SpatiaLite dir
settings.setValue( "/UI/lastSpatiaLiteDir", myPath );
// inserting this SQLite DB path
settings.setValue( baseKey + "selected", myName );
settings.setValue( baseKey + myName + "/sqlitepath", myFI.canonicalFilePath() );
settings.setValue( baseKey + "selected", savedName );
settings.setValue( baseKey + savedName + "/sqlitepath", myFI.canonicalFilePath() );
return true;
}

0 comments on commit 854ce17

Please sign in to comment.
You can’t perform that action at this time.