Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for ticket #439 (yet more problems with fully quoted
schema.tables)
Also a better behaviour when the user clicks on 'sample' or 'all' in
the postgres query builder without a table selected.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6238 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Dec 11, 2006
1 parent 1bc8bee commit f17d2de
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/gui/qgspgquerybuilder.cpp
Expand Up @@ -18,6 +18,7 @@
#include <QMessageBox>
#include "qgspgquerybuilder.h"
#include <qgslogger.h>
#include <QRegExp>
// default constructor
QgsPgQueryBuilder::QgsPgQueryBuilder(QWidget *parent, Qt::WFlags fl)
: QDialog(parent, fl)
Expand Down Expand Up @@ -82,12 +83,14 @@ QgsPgQueryBuilder::QgsPgQueryBuilder(QString tableName, PGconn *con,
.arg(PQdb(mPgConnection))
.arg(PQhost(mPgConnection))
.arg(PQuser(mPgConnection));

// populate minimum uri fields needed for the populate fields function
QStringList parts = QStringList::split(".", tableName); // table name contains table and schema
mUri->schema = parts[0];
QRegExp reg("\"(.+)\"\\.\"(.+)\"");
reg.indexIn(tableName);
QStringList parts = reg.capturedTexts(); // table name contains table and schema
mUri->schema = parts[1];
// strip whitespace to make sure the table name is clean
mUri->table = parts[1].stripWhiteSpace();
mUri->table = parts[2];

// and strip any quotation as this code does it's own quoting.
trimQuotation();

Expand Down Expand Up @@ -175,6 +178,9 @@ void QgsPgQueryBuilder::trimQuotation()

void QgsPgQueryBuilder::on_btnSampleValues_clicked()
{
if (lstFields->currentText().isEmpty())
return;

QString sql = "SELECT DISTINCT \"" + lstFields->currentText() + "\" " +
"FROM (SELECT \"" + lstFields->currentText() + "\" " +
"FROM \"" + mUri->schema + "\".\"" + mUri->table + "\" " +
Expand Down Expand Up @@ -214,6 +220,9 @@ void QgsPgQueryBuilder::on_btnSampleValues_clicked()

void QgsPgQueryBuilder::on_btnGetAllValues_clicked()
{
if (lstFields->currentText().isEmpty())
return;

QString sql = "select distinct \"" + lstFields->currentText()
+ "\" from \"" + mUri->schema + "\".\"" + mUri->table + "\" order by \"" + lstFields->currentText() + "\"";
// clear the values list
Expand Down

0 comments on commit f17d2de

Please sign in to comment.