Fix for ticket #431 (postgres tables not visible in query builder).

git-svn-id: http://svn.osgeo.org/qgis/trunk@6203 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
g_j_m 2006-12-07 20:56:34 +00:00
parent 47018f58c0
commit dfbdb69acb
2 changed files with 24 additions and 1 deletions

View File

@ -53,6 +53,9 @@ QgsPgQueryBuilder::QgsPgQueryBuilder(QgsDataSourceURI *uri,
mOwnConnection = true; // we own this connection since we created it
// tell the DB that we want text encoded in UTF8
PQsetClientEncoding(mPgConnection, "UNICODE");
// and strip any quotation as this code does it's own quoting.
trimQuotation();
lblDataUri->setText(datasource);
populateFields();
}
@ -85,6 +88,8 @@ QgsPgQueryBuilder::QgsPgQueryBuilder(QString tableName, PGconn *con,
mUri->schema = parts[0];
// strip whitespace to make sure the table name is clean
mUri->table = parts[1].stripWhiteSpace();
// and strip any quotation as this code does it's own quoting.
trimQuotation();
lblDataUri->setText(datasource);
populateFields();
@ -153,6 +158,21 @@ void QgsPgQueryBuilder::populateFields()
PQclear(result);
}
void QgsPgQueryBuilder::trimQuotation()
{
// Trim " characters that may be surrounding the table and schema name
if (mUri->schema.at(0) == '"')
{
mUri->schema.remove(mUri->schema.length()-1, 1);
mUri->schema.remove(0, 1);
}
if (mUri->table.at(0) == '"')
{
mUri->table.remove(mUri->table.length()-1, 1);
mUri->table.remove(0, 1);
}
}
void QgsPgQueryBuilder::on_btnSampleValues_clicked()
{
QString sql = "SELECT DISTINCT \"" + lstFields->currentText() + "\" " +

View File

@ -119,7 +119,10 @@ class QgsPgQueryBuilder : public QDialog, private Ui::QgsPgQueryBuilderBase {
*/
void populateFields();
/*!
* Trims surround " characters from the schema and table name
*/
void trimQuotation();
/*! Get the number of records that would be returned by the current SQL
* @return Number of records or -1 if an error was encountered