module Sequel::ODBC::MSSQL::DatabaseMethods

  1. lib/sequel/adapters/odbc/mssql.rb
Parent: MSSQL

Methods

Public Instance

  1. execute_insert

Constants

LAST_INSERT_ID_SQL = 'SELECT SCOPE_IDENTITY()'.freeze  

Public Instance methods

execute_insert (sql, opts=OPTS)

Return the last inserted identity value.

[show source]
# File lib/sequel/adapters/odbc/mssql.rb, line 14
def execute_insert(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      log_yield(sql){conn.do(sql)}
      begin
        s = log_yield(LAST_INSERT_ID_SQL){conn.run(LAST_INSERT_ID_SQL)}
        if (rows = s.fetch_all) and (row = rows.first) and (v = row.first)
          Integer(v)
        end
      ensure
        s.drop if s
      end
    rescue ::ODBC::Error => e
      raise_error(e)
    end
  end
end