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 24 24: def execute_insert(sql, opts=OPTS) 25: synchronize(opts[:server]) do |conn| 26: begin 27: log_connection_yield(sql, conn){conn.do(sql)} 28: begin 29: s = log_connection_yield(LAST_INSERT_ID_SQL, conn){conn.run(LAST_INSERT_ID_SQL)} 30: if (rows = s.fetch_all) and (row = rows.first) and (v = row.first) 31: Integer(v) 32: end 33: ensure 34: s.drop if s 35: end 36: rescue ::ODBC::Error => e 37: raise_error(e) 38: end 39: end 40: end