Module: Sequel::ODBC::MSSQL::DatabaseMethods

Includes:
MSSQL::DatabaseMethods
Defined in:
lib/sequel/adapters/odbc/mssql.rb

Constant Summary

Constants included from MSSQL::DatabaseMethods

MSSQL::DatabaseMethods::FOREIGN_KEY_ACTION_MAP

Instance Attribute Summary

Attributes included from MSSQL::DatabaseMethods

#like_without_collate, #mssql_unicode_strings

Instance Method Summary collapse

Methods included from MSSQL::DatabaseMethods

#call_mssql_sproc, #database_type, #foreign_key_list, #freeze, #global_index_namespace?, #indexes, #server_version, #supports_partial_indexes?, #supports_savepoints?, #supports_transaction_isolation_levels?, #supports_transactional_ddl?, #tables, #views, #with_advisory_lock

Instance Method Details

#execute_insert(sql, opts = OPTS) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sequel/adapters/odbc/mssql.rb', line 19

def execute_insert(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      log_connection_yield(sql, conn){conn.do(sql)}
      begin
        last_insert_id_sql = 'SELECT SCOPE_IDENTITY()'
        s = log_connection_yield(last_insert_id_sql, conn){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