Skip to content
Permalink
Browse files

Fix for ticket #400 (postgresql passwords with spaces didn't work). Now

also works with other punctuation characters too.
Also a tidy up of some odd \ characters


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6113 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Nov 18, 2006
1 parent e321270 commit 76f82b90f4e8e83ce9df84276438203b0c5a5bee
Showing with 48 additions and 19 deletions.
  1. +6 −3 src/gui/qgsdbsourceselect.cpp
  2. +6 −1 src/gui/qgsnewconnection.cpp
  3. +36 −15 src/providers/postgres/qgspostgresprovider.cpp
@@ -323,10 +323,13 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
QString password = QInputDialog::getText(tr("Password for ") + database + "@" + host,
tr("Please enter your password:"),
QLineEdit::Password, QString::null, &makeConnection, this);

// allow null password entry in case its valid for the database
// allow null password entry in case its valid for the database
}
connString += " password=" + password;

// Need to escape the password to allow for single quotes and backslashes
password.replace('\\', "\\\\");
password.replace('\'', "\\'");
connString += " password='" + password + "'";
#ifdef QGISDEBUG
std::cout << "Connection info: " << connString.toLocal8Bit().data() << std::endl;
#endif
@@ -99,12 +99,17 @@ void QgsNewConnection::testConnection()
// following line uses Qt SQL plugin - currently not used
// QSqlDatabase *testCon = QSqlDatabase::addDatabase("QPSQL7","testconnection");

// Need to escape the password to allow for single quotes and backslashes
QString password = txtPassword->text();
password.replace('\\', "\\\\");
password.replace('\'', "\\'");

QString connInfo =
"host=" + txtHost->text() +
" dbname=" + txtDatabase->text() +
" port=" + txtPort->text() +
" user=" + txtUsername->text() +
" password=" + txtPassword->text();
" password='" + password + "'";
PGconn *pd = PQconnectdb(connInfo.toLocal8Bit().data());
// std::cout << pd->ErrorMessage();
if (PQstatus(pd) == CONNECTION_OK)
@@ -147,11 +147,32 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
{
mUri.username = parm[1];
}
parm = QStringList::split("=", conParts[4]);
if(parm.size() == 2)
{
mUri.password = parm[1];
}

// The password can have '=' and ' ' characters in it, so we can't
// use the split on '=' and ' ' technique - use indexOf()
// instead.
QString key="password='";
int i = connInfo.indexOf(key);
if (i != -1)
{
QString password = connInfo.mid(i+key.length());
// Now walk through the string till we find a ' character, but
// need to allow for an escaped ' character (which will be the
// \' character pair).
int n = 0;
bool escaped = false;
while (n < password.length() && (password[n] != '\'' || escaped))
{
if (password[n] == '\\')
escaped = true;
else
escaped = false;
n++;
}
// The -1 is to remove the trailing ' character
mUri.password = password.left(n-1);
}
else
/* end uri structure */

QgsDebugMsg("Geometry column is: " + geometryColumn);
@@ -266,7 +287,7 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
QString attnum = PQgetvalue(tresult, 0, 0);
PQclear(tresult);

QgsDebugMsg("Field: " + attnum + " maps to " + QString::number(i) + " " + fieldName + ", " + \
QgsDebugMsg("Field: " + attnum + " maps to " + QString::number(i) + " " + fieldName + ", " +
fieldType + " (" + QString::number(fldtyp) + "), " + fieldSize + ", " + QString::number(fieldModifier));

attributeFieldsIdMap[attnum.toInt()] = i;
@@ -1344,13 +1365,13 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
temp.table_type = PQgetvalue(result, i, 6);
temp.column_type = PQgetvalue(result, i, 7);

QgsDebugMsg(temp.view_schema + "." \
+ temp.view_name + "." \
+ temp.view_column_name + " <- " \
+ temp.table_schema + "." \
+ temp.table_name + "." \
+ temp.column_name + " is a '" \
+ temp.table_type + "' of type " \
QgsDebugMsg(temp.view_schema + "."
+ temp.view_name + "."
+ temp.view_column_name + " <- "
+ temp.table_schema + "."
+ temp.table_name + "."
+ temp.column_name + " is a '"
+ temp.table_type + "' of type "
+ temp.column_type);

columnRelations[temp.view_schema + '.' +
@@ -2471,8 +2492,8 @@ void QgsPostgresProvider::customEvent( QCustomEvent * e )

QgsDebugMsg("QgsPostgresProvider: new extent has been saved");

QgsDebugMsg("QgsPostgresProvider: Set extent to: " + QString::number(layerExtent.xMin()) + ", " + \
QString::number(layerExtent.yMin()) + " " + QString::number(layerExtent.xMax()) + ", " + \
QgsDebugMsg("QgsPostgresProvider: Set extent to: " + QString::number(layerExtent.xMin()) + ", " +
QString::number(layerExtent.yMin()) + " " + QString::number(layerExtent.xMax()) + ", " +
QString::number(layerExtent.yMax()));

QgsDebugMsg("QgsPostgresProvider: emitting fullExtentCalculated()");

0 comments on commit 76f82b9

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