Module | Sequel::ODBC::MSSQL::DatabaseMethods |
In: |
lib/sequel/adapters/odbc/mssql.rb
|
LAST_INSERT_ID_SQL | = | 'SELECT SCOPE_IDENTITY()'.freeze |
Return the last inserted identity value.
# File lib/sequel/adapters/odbc/mssql.rb, line 22 22: def execute_insert(sql, opts=OPTS) 23: synchronize(opts[:server]) do |conn| 24: begin 25: log_yield(sql){conn.do(sql)} 26: begin 27: s = log_yield(LAST_INSERT_ID_SQL){conn.run(LAST_INSERT_ID_SQL)} 28: if (rows = s.fetch_all) and (row = rows.first) and (v = row.first) 29: Integer(v) 30: end 31: ensure 32: s.drop if s 33: end 34: rescue ::ODBC::Error => e 35: raise_error(e) 36: end 37: end 38: end