Skip to content

Commit

Permalink
Create the last_inserted_id method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Couzens committed Feb 29, 2012
1 parent e650b8f commit 09cec18
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/active_record/connection_adapters/sqlanywhere_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ def delete_sql(sql, name = nil) #:nodoc:
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
execute(sql, name)

last_inserted_id(nil)
end

def last_inserted_id(result)
identity = SA.instance.api.sqlany_execute_direct(@connection, 'SELECT @@identity')
raise ActiveRecord::StatementInvalid.new("#{SA.instance.api.sqlany_error(@connection)}:#{sql}") if identity.nil?
SA.instance.api.sqlany_fetch_next(identity)
Expand Down

0 comments on commit 09cec18

Please sign in to comment.