mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
PGSQL: Now using lastval() for GetInsertedId
git-svn-id: svn://ultimatepp.org/upp/trunk@7808 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d9d5bf64c6
commit
38b43035e7
1 changed files with 1 additions and 18 deletions
|
|
@ -579,24 +579,7 @@ int PostgreSQLConnection::GetRowsProcessed() const
|
|||
|
||||
Value PostgreSQLConnection::GetInsertedId() const
|
||||
{
|
||||
String pk = session.pkache.Get(last_insert_table, Null);
|
||||
if(IsNull(pk)) {
|
||||
String sqlc_expr;
|
||||
sqlc_expr <<
|
||||
"SELECT " <<
|
||||
"pg_attribute.attname " <<
|
||||
"FROM pg_index, pg_class, pg_attribute " <<
|
||||
"WHERE " <<
|
||||
"pg_class.oid = '" << last_insert_table << "'::regclass AND "
|
||||
"indrelid = pg_class.oid AND "
|
||||
"pg_attribute.attrelid = pg_class.oid AND "
|
||||
"pg_attribute.attnum = any(pg_index.indkey) "
|
||||
"AND indisprimary";
|
||||
Sql sqlc( sqlc_expr );
|
||||
pk = sqlc.Execute() && sqlc.Fetch() ? sqlc[0] : "ID";
|
||||
session.pkache.Add(last_insert_table, pk);
|
||||
}
|
||||
Sql sql("select currval('" + last_insert_table + "_" + pk +"_seq')", session);
|
||||
Sql sql("select lastval()", session); // Requires at least PGSQL 8.1 (released 2005)
|
||||
if(sql.Execute() && sql.Fetch())
|
||||
return sql[0];
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue