开发者

why does access 2010 with postgresql odbc driver call IDENT_CURRENT?

I am migrating an access 2003 application to access 2010. The application uses the postgres odbc driver to access its data.

On access 2010 it tries to use the IDENT_CURRENT function on the postgresql server (as seen with wireshark) to identify the id of a recently inserted row ... Unfortunately IDENT_CURRENT is not a function supported by postgresql as far as I know ...

I am us开发者_运维技巧ing the latest postgresql ODBC driver (9.0) with a postgresql 8.3 database.


Using currval is the right way to go (emphasis mine):

Return the value most recently obtained by nextval for this sequence in the current session. (An error is reported if nextval has never been called for this sequence in this session.) Because this is returning a session-local value, it gives a predictable answer whether or not other sessions have executed nextval since the current session did.

And wrapping it up in an IDENT_CURRENT function is a perfectly reasonable porting technique.

You could also use RETURNING id on your INSERT statements (again, emphasis mine):

The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted. This is primarily useful for obtaining values that were supplied by defaults, such as a serial sequence number.

That might be a bit quicker and cleaner but you'd still have some portability issues. OTOH, I think you're going to have portability issues no matter what you do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜