|
18 | 18 | #include <QMessageBox>
|
19 | 19 | #include "qgspgquerybuilder.h"
|
20 | 20 | #include <qgslogger.h>
|
| 21 | +#include <QRegExp> |
21 | 22 | // default constructor
|
22 | 23 | QgsPgQueryBuilder::QgsPgQueryBuilder(QWidget *parent, Qt::WFlags fl)
|
23 | 24 | : QDialog(parent, fl)
|
@@ -82,12 +83,14 @@ QgsPgQueryBuilder::QgsPgQueryBuilder(QString tableName, PGconn *con,
|
82 | 83 | .arg(PQdb(mPgConnection))
|
83 | 84 | .arg(PQhost(mPgConnection))
|
84 | 85 | .arg(PQuser(mPgConnection));
|
85 |
| - |
86 | 86 | // populate minimum uri fields needed for the populate fields function
|
87 |
| - QStringList parts = QStringList::split(".", tableName); // table name contains table and schema |
88 |
| - mUri->schema = parts[0]; |
| 87 | + QRegExp reg("\"(.+)\"\\.\"(.+)\""); |
| 88 | + reg.indexIn(tableName); |
| 89 | + QStringList parts = reg.capturedTexts(); // table name contains table and schema |
| 90 | + mUri->schema = parts[1]; |
89 | 91 | // strip whitespace to make sure the table name is clean
|
90 |
| - mUri->table = parts[1].stripWhiteSpace(); |
| 92 | + mUri->table = parts[2]; |
| 93 | + |
91 | 94 | // and strip any quotation as this code does it's own quoting.
|
92 | 95 | trimQuotation();
|
93 | 96 |
|
@@ -175,6 +178,9 @@ void QgsPgQueryBuilder::trimQuotation()
|
175 | 178 |
|
176 | 179 | void QgsPgQueryBuilder::on_btnSampleValues_clicked()
|
177 | 180 | {
|
| 181 | + if (lstFields->currentText().isEmpty()) |
| 182 | + return; |
| 183 | + |
178 | 184 | QString sql = "SELECT DISTINCT \"" + lstFields->currentText() + "\" " +
|
179 | 185 | "FROM (SELECT \"" + lstFields->currentText() + "\" " +
|
180 | 186 | "FROM \"" + mUri->schema + "\".\"" + mUri->table + "\" " +
|
@@ -214,6 +220,9 @@ void QgsPgQueryBuilder::on_btnSampleValues_clicked()
|
214 | 220 |
|
215 | 221 | void QgsPgQueryBuilder::on_btnGetAllValues_clicked()
|
216 | 222 | {
|
| 223 | + if (lstFields->currentText().isEmpty()) |
| 224 | + return; |
| 225 | + |
217 | 226 | QString sql = "select distinct \"" + lstFields->currentText()
|
218 | 227 | + "\" from \"" + mUri->schema + "\".\"" + mUri->table + "\" order by \"" + lstFields->currentText() + "\"";
|
219 | 228 | // clear the values list
|
|
0 commit comments