| 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 13
13: def execute_insert(sql, opts={})
14: synchronize(opts[:server]) do |conn|
15: begin
16: log_yield(sql){conn.do(sql)}
17: begin
18: s = log_yield(LAST_INSERT_ID_SQL){conn.run(LAST_INSERT_ID_SQL)}
19: if (rows = s.fetch_all) and (row = rows.first)
20: Integer(row.first)
21: end
22: ensure
23: s.drop if s
24: end
25: rescue ::ODBC::Error => e
26: raise_error(e)
27: end
28: end
29: end