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>
This commit is contained in:
parent
267567b8da
commit
f4d7b4d10f
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user