Returning Generated Database Keys in a Cross Database Way

The Javadoc documentation for SRConnection says that the prepareStatmentForGeneratedKeys and fetchGeneratedKey methods are used for “returning generated keys in a way that’s safe for all database drivers.”

I was wondering if the method “runPrepInsertGetKey” is also safe to use for all database drivers for the purpose of returning automatically generated keys. Is it safe to use for all database drivers too?

Also the documentation for the Jython function system.db.runPrepUpdate says this: “Not all databases support automatic retrieval of generated keys.” This made me wonder if the system.db.runPrepUpdate function uses the database translators that come with Ignition or not.

Will system.db.runPrepUpdate return generated keys when getKey=1 for the 6 databases that have database translators?

Fetching the auto generated key is up to the JDBC driver and the database. It has nothing to do with the translators. The runPrepUpdate function will try on all databases but may error out if it doesn’t support fetching the auto generated key. The functions do work for MySQL, SQL Server, and Oracle which is the majority.