Sha256: 97132a67b729ffaf2a350d141cbbb33e028cdbb18d3da647cd84921d8e3913ea

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

Sequel.require 'adapters/shared/mssql'

module Sequel
  module ODBC
    # Database and Dataset instance methods for MSSQL specific
    # support via ODBC.
    module MSSQL
      module DatabaseMethods
        include Sequel::MSSQL::DatabaseMethods
        LAST_INSERT_ID_SQL='SELECT SCOPE_IDENTITY()'
        
        # Return an instance of Sequel::ODBC::MSSQL::Dataset with the given opts.
        def dataset(opts=nil)
          Sequel::ODBC::MSSQL::Dataset.new(self, opts)
        end
        
        # Return the last inserted identity value.
        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
      end
      
      class Dataset < ODBC::Dataset
        include Sequel::MSSQL::DatasetMethods
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sequel-3.10.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.9.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.8.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.7.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.6.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.5.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.4.0 lib/sequel/adapters/odbc/mssql.rb
sequel-3.3.0 lib/sequel/adapters/odbc/mssql.rb