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
Instance Method Summary collapse
-
#execute_insert(sql, opts = OPTS) ⇒ Object
Return the last inserted identity value.
Methods included from Database::ResetIdentifierMangling
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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sequel/adapters/odbc/mssql.rb', line 22 def execute_insert(sql, opts=OPTS) synchronize(opts[:server]) do |conn| begin log_yield(sql){conn.do(sql)} begin s = log_yield(LAST_INSERT_ID_SQL){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 |