Skip to content

Commit f7e689d

Browse files
author
jef
committedNov 27, 2007
followup to r7672: updated spitplugin
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7673 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3e0b7e4 commit f7e689d

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed
 

‎src/plugins/spit/qgsconnectiondialog.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C"
2929

3030
#include "qgsconnectiondialog.h"
3131
#include "qgsmessageviewer.h"
32+
#include "qgsdatasourceuri.h"
3233

3334
QgsConnectionDialog::QgsConnectionDialog(QWidget *parent, const QString& connName, Qt::WFlags fl)
3435
: QDialog(parent, fl)
@@ -62,17 +63,17 @@ QgsConnectionDialog::~QgsConnectionDialog()
6263

6364
void QgsConnectionDialog::testConnection()
6465
{
65-
QString connInfo = "host=" + txtHost->text() + " dbname=" + txtDatabase->text() +
66-
" port=" + txtPort->text() + " user=" + txtUsername->text() + " password=" + txtPassword->text();
67-
PGconn *pd = PQconnectdb((const char *) connInfo);
66+
QgsDataSourceURI uri;
67+
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
68+
PGconn *pd = PQconnectdb((const char *) uri.connInfo() );
69+
70+
if (PQstatus(pd) == CONNECTION_OK) {
71+
// Database successfully opened; we can now issue SQL commands.
72+
QMessageBox::information(this, tr("Test connection"), tr("Connection to ") + txtDatabase->text() + tr(" was successfull"));
73+
} else {
74+
QMessageBox::information(this, tr("Test connection"), tr("Connection failed - Check settings and try again "));
75+
}
6876

69-
if (PQstatus(pd) == CONNECTION_OK) {
70-
// Database successfully opened; we can now issue SQL commands.
71-
QMessageBox::information(this, tr("Test connection"), tr("Connection to ") + txtDatabase->text() + tr(" was successfull"));
72-
} else {
73-
QMessageBox::information(this, tr("Test connection"), tr("Connection failed - Check settings and try again "));
74-
}
75-
7677
PQfinish(pd);
7778
}
7879

‎src/plugins/spit/qgsspit.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "qgspgutil.h"
3737
#include "qgsspit.h"
3838
#include "qgsconnectiondialog.h"
39+
#include "qgsdatasourceuri.h"
3940
#include "qgseditreservedwordsdialog.h"
4041
#include "qgsmessageviewer.h"
4142
#include "spiticon.xpm"
@@ -431,12 +432,14 @@ PGconn* QgsSpit::checkConnection()
431432
}
432433
else
433434
{
434-
QString connInfo = "host=" + settings.readEntry( gl_key + connName + "/host" ) +
435-
" dbname=" + settings.readEntry( gl_key + connName + "/database" ) +
436-
" port=" + settings.readEntry( gl_key + connName + "/port" ) +
437-
" user=" + settings.readEntry( gl_key + connName + "/username" ) +
438-
" password=" + settings.readEntry( gl_key + connName + "/password" );
439-
pd = PQconnectdb( ( const char * ) connInfo );
435+
QgsDataSourceURI uri;
436+
uri.setConnection( settings.readEntry( gl_key + connName + "/host" ),
437+
settings.readEntry( gl_key + connName + "/port" ),
438+
settings.readEntry( gl_key + connName + "/database" ),
439+
settings.readEntry( gl_key + connName + "/username" ),
440+
settings.readEntry( gl_key + connName + "/password" ) );
441+
442+
pd = PQconnectdb( ( const char * ) uri.connInfo() );
440443

441444
if ( PQstatus( pd ) != CONNECTION_OK )
442445
{

0 commit comments

Comments
 (0)