diff options
| author | Israel Lins <[email protected]> | 2013-02-26 14:23:43 -0300 |
|---|---|---|
| committer | The Qt Project <[email protected]> | 2013-02-28 10:04:46 +0100 |
| commit | f4d7b4d10f7d3badbb0ac5ad5c0754a044f8bdd2 (patch) | |
| tree | ba119e18f6e46dfcc0e58fb4bf0108a56b765241 /src/sql/drivers/psql/qsql_psql.cpp | |
| parent | 267567b8da6967ae450c40a4d156fffcaf85d79b (diff) | |
PSQL: lastInsertId without OID on table
Make lastInsertID work for tables without OIDs.
The use of OID in tables is now deprecated in PostgeSQL and
lastval() is now provided.
http://www.postgresql.org/docs/8.1/interactive/runtime-config-compatible.html#GUC-DEFAULT-WITH-OIDS
Change-Id: I01dfdd7a2aab8826487657f691fea3c9268c16b2
Reviewed-by: Israel Lins Albuquerque <[email protected]>
Reviewed-by: Mark Brand <[email protected]>
Diffstat (limited to 'src/sql/drivers/psql/qsql_psql.cpp')
| -rw-r--r-- | src/sql/drivers/psql/qsql_psql.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 6a37e4b50d6..7d844fa1bdd 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -474,7 +474,12 @@ int QPSQLResult::numRowsAffected() QVariant QPSQLResult::lastInsertId() const { - if (isActive()) { + if (d->privDriver->pro >= QPSQLDriver::Version81) { + QSqlQuery qry(driver()->createResult()); + // Most recent sequence value obtained from nextval + if (qry.exec(QLatin1String("SELECT lastval();")) && qry.next()) + return qry.value(0); + } else if (isActive()) { Oid id = PQoidValue(d->result); if (id != InvalidOid) return QVariant(id); |
