views:

158

answers:

1

I have a CRecordSet (Visual C++ 6.0) and I'm using ODBC to connect to postgresql 8.0.8.

__

The problem: I insert a row into a table with a serial id (autoincrement), and I would like to retrieve the id after my insert.

I can't use the RETURNING keyword, not supported on this version of PGsql, but I can use currval('sequence').

However, in my code, I need to execute the default query and then override it to execute the query with currval().

From what I understand, I can only override the query by calling CRecordSet::Open() again, which would create a new session, rendering currval() useless.

__

So: How can I override the SQL, then execute this new query via a Requery() and not via Open()?

A: 

As far as I understand, currval() is not connection specific. You should get the correct value back on the new connection. You could also try and append the 'select currval()' at the end of your INSERT statement.

INSERT INTO mytable VALUES (1); SELECT currval('mysequence');