QgsDataSourceURI QgsPostgresConn::connUri( QString theConnName ) { QgsDebugMsg( "theConnName = " + theConnName ); QSettings settings; QString key = "/PostgreSQL/connections/" + theConnName; QString service = settings.value( key + "/service" ).toString(); QString host = settings.value( key + "/host" ).toString(); QString port = settings.value( key + "/port" ).toString(); if ( port.length() == 0 ) { port = "5432"; } QString database = settings.value( key + "/database" ).toString(); bool useEstimatedMetadata = settings.value( key + "/estimatedMetadata", false ).toBool(); int sslmode = settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt(); QString username; QString password; if ( settings.value( key + "/saveUsername" ).toString() == "true" ) { username = settings.value( key + "/username" ).toString(); } if ( settings.value( key + "/savePassword" ).toString() == "true" ) { password = settings.value( key + "/password" ).toString(); } // Old save setting if ( settings.contains( key + "/save" ) ) { username = settings.value( key + "/username" ).toString(); if ( settings.value( key + "/save" ).toString() == "true" ) { password = settings.value( key + "/password" ).toString(); } } QgsDataSourceURI uri; if ( !service.isEmpty() ) { uri.setConnection( service, database, username, password, ( QgsDataSourceURI::SSLmode ) sslmode ); } else { uri.setConnection( host, port, database, username, password, ( QgsDataSourceURI::SSLmode ) sslmode ); } uri.setUseEstimatedMetadata( useEstimatedMetadata ); return uri; }
void QgsOracleNewConnection::on_btnConnect_clicked() { QgsDataSourceURI uri; uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() ); if ( !txtOptions->text().isEmpty() ) uri.setParam( "dboptions", txtOptions->text() ); QgsOracleConn *conn = QgsOracleConnPool::instance()->acquireConnection( uri.connectionInfo() ); if ( conn ) { // Database successfully opened; we can now issue SQL commands. QMessageBox::information( this, tr( "Test connection" ), tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) ); // free connection resources QgsOracleConnPool::instance()->releaseConnection( conn ); } else { QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - consult message log for details.\n\n" ) ); } }
void QgsPgNewConnection::testConnection() { QgsDataSourceURI uri; if ( !txtService->text().isEmpty() ) { uri.setConnection( txtService->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text(), ( QgsDataSourceURI::SSLmode ) cbxSSLmode->itemData( cbxSSLmode->currentIndex() ).toInt(), mAuthConfigSelect->configId() ); } else { uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text(), ( QgsDataSourceURI::SSLmode ) cbxSSLmode->itemData( cbxSSLmode->currentIndex() ).toInt(), mAuthConfigSelect->configId() ); } QString conninfo = uri.connectionInfo(); QgsPostgresConn *conn = QgsPostgresConn::connectDb( conninfo, true ); if ( conn ) { // Database successfully opened; we can now issue SQL commands. QMessageBox::information( this, tr( "Test connection" ), tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) ); // free pg connection resources conn->unref(); } else { QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - consult message log for details.\n\n" ) ); } }
QgsDataSourceURI QgsOracleConn::connUri( QString theConnName ) { QgsDebugMsg( "theConnName = " + theConnName ); QSettings settings; QString key = "/Oracle/connections/" + theConnName; QString database = settings.value( key + "/database" ).toString(); QString host = settings.value( key + "/host" ).toString(); QString port = settings.value( key + "/port" ).toString(); if ( port.length() == 0 ) { port = "1521"; } bool useEstimatedMetadata = settings.value( key + "/estimatedMetadata", false ).toBool(); QString username; QString password; if ( settings.value( key + "/saveUsername" ).toString() == "true" ) { username = settings.value( key + "/username" ).toString(); } if ( settings.value( key + "/savePassword" ).toString() == "true" ) { password = settings.value( key + "/password" ).toString(); } QgsDataSourceURI uri; uri.setConnection( host, port, database, username, password ); uri.setUseEstimatedMetadata( useEstimatedMetadata ); if ( !settings.value( key + "/dboptions" ).toString().isEmpty() ) { uri.setParam( "dboptions", settings.value( key + "/dboptions" ).toString() ); } if ( !settings.value( key + "/dbworkspace" ).toString().isEmpty() ) { uri.setParam( "dbworkspace", settings.value( key + "/dbworkspace" ).toString() ); } return uri; }
void QgsOracleNewConnection::on_btnConnect_clicked() { QgsDataSourceURI uri; uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() ); QgsOracleConn *conn = QgsOracleConn::connectDb( uri ); if ( conn ) { // Database successfully opened; we can now issue SQL commands. QMessageBox::information( this, tr( "Test connection" ), tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) ); // free connection resources conn->disconnect(); } else { QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\n" ) ); } }