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