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

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

Constant Summary collapse

LAST_INSERT_ID_SQL =
'SELECT SCOPE_IDENTITY()'

Instance Method Summary collapse

Instance Method Details

#dataset(opts = nil) ⇒ Object

Return an instance of Sequel::ODBC::MSSQL::Dataset with the given opts.


13
14
15
# File 'lib/sequel/lib/sequel/adapters/odbc/mssql.rb', line 13

def dataset(opts=nil)
  Sequel::ODBC::MSSQL::Dataset.new(self, opts)
end

#execute_insert(sql, opts = {}) ⇒ Object

Return the last inserted identity value.


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

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