@@ -51,6 +51,7 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
51
51
52
52
QMap<QString, QgsPostgresProvider::Conn *> QgsPostgresProvider::Conn::connectionsRO;
53
53
QMap<QString, QgsPostgresProvider::Conn *> QgsPostgresProvider::Conn::connectionsRW;
54
+ QMap<QString, QString> QgsPostgresProvider::Conn::passwordCache;
54
55
int QgsPostgresProvider::providerIds = 0 ;
55
56
56
57
QgsPostgresProvider::QgsPostgresProvider ( QString const & uri )
@@ -310,25 +311,36 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
310
311
{
311
312
QString password = QString::null;
312
313
313
- while ( PQstatus ( pd ) != CONNECTION_OK )
314
+ while ( PQstatus ( pd ) != CONNECTION_OK )
314
315
{
315
316
bool ok = true ;
316
- password = QInputDialog::getText ( 0 ,
317
- tr ( " Enter password" ),
318
- tr ( " Error: %1Enter password for %2" )
317
+
318
+ if ( passwordCache.contains ( conninfo ) )
319
+ {
320
+ password = passwordCache.take ( conninfo );
321
+ }
322
+ else
323
+ {
324
+ password = QInputDialog::getText ( 0 ,
325
+ tr ( " Enter password" ),
326
+ tr ( " Error: %1Enter password for %2" )
319
327
.arg ( QString::fromUtf8 ( PQerrorMessage ( pd ) ) )
320
328
.arg ( conninfo ),
321
- QLineEdit::Password,
322
- password,
323
- &ok );
324
-
325
- ::PQfinish ( pd );
329
+ QLineEdit::Password,
330
+ password,
331
+ &ok );
332
+ }
326
333
327
- if ( !ok )
334
+ if ( !ok )
328
335
break ;
329
336
337
+ ::PQfinish ( pd );
338
+
330
339
pd = PQconnectdb ( QString ( " %1 password='%2'" ).arg ( conninfo ).arg ( password ).toLocal8Bit () );
331
340
}
341
+
342
+ if ( PQstatus ( pd ) == CONNECTION_OK )
343
+ passwordCache[ conninfo ] = password;
332
344
}
333
345
334
346
if ( PQstatus ( pd ) != CONNECTION_OK )
0 commit comments