summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/psql/qsql_psql.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-05-19 15:31:46 +0200
committerAndy Shaw <andy.shaw@qt.io>2017-07-12 09:01:50 +0000
commit0843c6ca7fe604d8c44b9a81b8fcb072ab424172 (patch)
treee6784759b9dd8729d5bd179a38552170e084a723 /src/plugins/sqldrivers/psql/qsql_psql.cpp
parent9423be1f190bd7cdeb04add39f4ec621a33a3041 (diff)
QSqlField: Add a means to see what the tablename is for a given field
When you are using a query that pulls from a number of different tables then it can be ambiguous as to which table a particular field belongs to. So this will make it possible to determine the table that a given field belongs to if it is set. Task-number: QTBUG-7170 Change-Id: I49b7890c0523d81272a153df3860df800ff853d5 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/plugins/sqldrivers/psql/qsql_psql.cpp')
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index b60fa1058f..a3aa0f6593 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -552,6 +552,11 @@ QSqlRecord QPSQLResult::record() const
f.setName(QString::fromUtf8(PQfname(d->result, i)));
else
f.setName(QString::fromLocal8Bit(PQfname(d->result, i)));
+ QSqlQuery qry(driver()->createResult());
+ if (qry.exec(QStringLiteral("SELECT relname FROM pg_class WHERE pg_class.oid = %1")
+ .arg(PQftable(d->result, i))) && qry.next()) {
+ f.setTableName(qry.value(0).toString());
+ }
int ptype = PQftype(d->result, i);
f.setType(qDecodePSQLType(ptype));
int len = PQfsize(d->result, i);
@@ -1132,7 +1137,7 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const
i.exec(stmt.arg(tbl));
while (i.isActive() && i.next()) {
- QSqlField f(i.value(0).toString(), qDecodePSQLType(i.value(1).toInt()));
+ QSqlField f(i.value(0).toString(), qDecodePSQLType(i.value(1).toInt()), tablename);
idx.append(f);
idx.setName(i.value(2).toString());
}
@@ -1237,7 +1242,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const
QString defVal = query.value(5).toString();
if (!defVal.isEmpty() && defVal.at(0) == QLatin1Char('\''))
defVal = defVal.mid(1, defVal.length() - 2);
- QSqlField f(query.value(0).toString(), qDecodePSQLType(query.value(1).toInt()));
+ QSqlField f(query.value(0).toString(), qDecodePSQLType(query.value(1).toInt()), tablename);
f.setRequired(query.value(2).toBool());
f.setLength(len);
f.setPrecision(precision);
@@ -1264,7 +1269,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const
len = precision - 4;
precision = -1;
}
- QSqlField f(query.value(0).toString(), qDecodePSQLType(query.value(1).toInt()));
+ QSqlField f(query.value(0).toString(), qDecodePSQLType(query.value(1).toInt()), tablename);
f.setRequired(query.value(2).toBool());
f.setLength(len);
f.setPrecision(precision);