Skip to content

Commit

Permalink
Fix for ticket #431 (postgres tables not visible in query builder).
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6203 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Dec 7, 2006
1 parent 47018f5 commit dfbdb69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/gui/qgspgquerybuilder.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() + "\" " +
Expand Down
5 changes: 4 additions & 1 deletion src/gui/qgspgquerybuilder.h
Expand Up @@ -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
Expand Down

0 comments on commit dfbdb69

Please sign in to comment.