summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorIsrael Lins <israelins85@yahoo.com.br>2013-02-26 14:23:43 -0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-28 10:04:46 +0100
commitf4d7b4d10f7d3badbb0ac5ad5c0754a044f8bdd2 (patch)
treeba119e18f6e46dfcc0e58fb4bf0108a56b765241 /src/sql
parent267567b8da6967ae450c40a4d156fffcaf85d79b (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 <israelins85@yahoo.com.br> Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp7
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 6a37e4b50d..7d844fa1bd 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);