jruby/activerecord-jdbc-adapter — pull request #124 by gfmurphy (2011-10-20 21:27:27+00:00)
Title: Sqlite3 query count

I'm going to need a review on this one.

The native sqlite3 driver relies on the C API to retrieve the auto-incremented *last_insert_row_id* of the last insert . The jdbc adapter executes another query that calls the the SQL fuction last_insert_rowid() to get the value. This causes the activerecord-jdbc-adapter to fail 14 tests in the AR test suite in rails master due the difference in the amount of SQL generated by ActiveRecord for both drivers.

This patch adds a method, *last_insert_row_id* to the Sqlite3RubyJdbcConnection object that obtains the value through the jdbc api method java.sql.Statement#getGeneratedKeys().

The driver does not indicate that this method is supported through its DataBaseMetaData; however; this appears to work since this method call is implemented as a SQL query, which calls the SQL fucntion last_insert_rowid() function, which is the same behavior as the current version of the adapter.

With this patch the extra queries now execute below ActiveRecord, allowing the tests to pass.

1. Is this even useful?
2. I'm unsure of the safety of this patch. I.E. is the connection member in the sqlite3 adapter always a Sqlite3RubyJdbcConnection? The method is currently not supported by a super class.
3. Is the the right place for the method?
4. I'm not clear on how to test this to ensure that changes in the driver do not break the adapter. Are the current tests that check auto-incremented ids enough?

Thanks for your feedback,
G