Module: Sequel::ODBC::MSSQL::DatabaseMethods
- 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::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 = {}) ⇒ Object
Return the last inserted identity value.
Methods included from MSSQL::DatabaseMethods
#database_type, #indexes, #server_version, #supports_savepoints?, #supports_transaction_isolation_levels?, #tables, #views
Instance Method Details
#execute_insert(sql, opts = {}) ⇒ Object
Return the last inserted identity value.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sequel/adapters/odbc/mssql.rb', line 13 def execute_insert(sql, 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) Integer(row.first) end ensure s.drop if s end rescue ::ODBC::Error => e raise_error(e) end end end |