SQL::ConnectionGenerateLastInsertedIdentityStatement Method
Syntax
Arguments
- TableInfoSQL::TableInfo
The table to retrieve the last inserted identity. If not specified, the identity will be retrieved for the table from the last INSERT statement.
Returns
- SQL_StatementCharacter
Returns a SQL SELECT statement that will retrieve the last inserted identity.
Description
Generate a SQL statement to retrieve the identity from the last insert statement (may be specific to the table passed in).
Discussion
The SQL::Connection::GenerateLastInsertedIdentityStatement() method retrieves the last identity value generated for an insert on the currently open connection.
Notes
This is current connection specific for most databases. For databases that use sequences to maintain identity (such as Oracle), the sequence may not be correct after the transaction has been completed.
For databases that use sequences to generate identities the SQL::TableInfo is a required parameter. It must include an identity column in its definition. That column must specify the sequence name to be used.
Example
dim cn as SQL::Connection ?cn.open("::Name::SQLServer2014Test") = .T. dim TableInfo as SQL::TableInfo ?cn.gettableinfo(TableInfo, "Proposals") = .T. ?cn.GenerateLastInsertedIdentityStatement(TableInfo) = "select isnull(scope_identity(), @@identity) OPTION (MAXDOP 1)"
See Also