mrcsparker/activerecord-jdbcteradata-adapter — pull request #17 by RobGoretsky (2013-12-18 21:22:20+00:00)
Title: Allow Proper Functionality For Tables Without Auto-Increment PK

I have been using the AR JDBC Teradata adapter to load data into previously existing tables in my database. In some cases, these tables do not have a standard Auto-Incremented "ID" column. For example, we could have a "Posts" table that has a "post_id" primary key that is set manually by my script.

This adapter had been mostly working for me in these cases, but I found that I was hitting an Exception when loading data that contained a string that had more than three periods in it.

I dug into the code, and found what looks to be a bug - on line 140 of lib/arjdbc/teradata/adapter.rb, we are calling last_insert_id and passing it the complete SQL statement. This looks to be incorrect, as the last_insert_id method actually expects a table name. I found that using the _table_name_from_insert(sql) method resolved this and made my spec now properly pass.

After making this change I ran all of the existing specs and they all continue to pass.