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

Extended by:
Database::ResetIdentifierMangling
Includes:
MSSQL::DatabaseMethods
Defined in:
lib/sequel/adapters/odbc/mssql.rb

Constant Summary collapse

LAST_INSERT_ID_SQL =
'SELECT SCOPE_IDENTITY()'.freeze

Constants included from MSSQL::DatabaseMethods

MSSQL::DatabaseMethods::AUTO_INCREMENT, MSSQL::DatabaseMethods::DECIMAL_TYPE_RE, MSSQL::DatabaseMethods::FOREIGN_KEY_ACTION_MAP, MSSQL::DatabaseMethods::MSSQL_DEFAULT_RE, MSSQL::DatabaseMethods::SERVER_VERSION_RE, MSSQL::DatabaseMethods::SERVER_VERSION_SQL, MSSQL::DatabaseMethods::SQL_BEGIN, MSSQL::DatabaseMethods::SQL_COMMIT, MSSQL::DatabaseMethods::SQL_ROLLBACK, MSSQL::DatabaseMethods::SQL_ROLLBACK_TO_SAVEPOINT, MSSQL::DatabaseMethods::SQL_SAVEPOINT

Instance Attribute Summary

Attributes included from MSSQL::DatabaseMethods

#mssql_unicode_strings

Instance Method Summary collapse

Methods included from Database::ResetIdentifierMangling

extended

Methods included from MSSQL::DatabaseMethods

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

Instance Method Details

#execute_insert(sql, opts = OPTS) ⇒ Object

Return the last inserted identity value.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sequel/adapters/odbc/mssql.rb', line 24

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