Sha256: 81d5f0b64b3ca75a19e5b66031cca2f5181db20a9b4504a7aa9b0ed06377bb54

Contents?: true

Size: 1.97 KB

Versions: 103

Compression:

Stored size: 1.97 KB

Contents

# frozen-string-literal: true

require_relative '../shared/mssql'

module Sequel
  module ADO
    module MSSQL
      module DatabaseMethods
        include Sequel::MSSQL::DatabaseMethods

        def execute_dui(sql, opts=OPTS)
          return super unless @opts[:provider]
          synchronize(opts[:server]) do |conn|
            begin
              sql = "SET NOCOUNT ON; #{sql}; SELECT @@ROWCOUNT"
              rst = log_connection_yield(sql, conn){conn.Execute(sql)}
              rst.GetRows[0][0]
            rescue ::WIN32OLERuntimeError => e
              raise_error(e)
            end
          end
        end

        private

        # The ADO adapter's default provider doesn't support transactions, since it 
        # creates a new native connection for each query.  So Sequel only attempts
        # to use transactions if an explicit :provider is given.
        def begin_transaction(conn, opts=OPTS)
          super if @opts[:provider]
        end

        def commit_transaction(conn, opts=OPTS)
          super if @opts[:provider]
        end

        def rollback_transaction(conn, opts=OPTS)
          super if @opts[:provider]
        end
      end
      
      class Dataset < ADO::Dataset
        include Sequel::MSSQL::DatasetMethods

        # Use a nasty hack of multiple SQL statements in the same call and
        # having the last one return the most recently inserted id.  This
        # is necessary as ADO's default :provider uses a separate native
        # connection for each query.
        def insert(*values)
          return super if (@opts[:sql] && !@opts[:prepared_sql]) || @opts[:returning]
          with_sql("SET NOCOUNT ON; #{insert_sql(*values)}; SELECT CAST(SCOPE_IDENTITY() AS INTEGER)").single_value
        end
        
        # If you use a better :provider option for the database, you can get an
        # accurate number of rows matched.
        def provides_accurate_rows_matched?
          !!db.opts[:provider]
        end
      end
    end
  end
end

Version data entries

103 entries across 89 versions & 2 rubygems

Version Path
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/sequel-5.53.0/lib/sequel/adapters/ado/mssql.rb
sequel-5.53.0 lib/sequel/adapters/ado/mssql.rb
sequel-5.52.0 lib/sequel/adapters/ado/mssql.rb
sequel-5.51.0 lib/sequel/adapters/ado/mssql.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/sequel-5.50.0/lib/sequel/adapters/ado/mssql.rb
sequel-5.50.0 lib/sequel/adapters/ado/mssql.rb
sequel-5.49.0 lib/sequel/adapters/ado/mssql.rb
sequel-5.48.0 lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/sequel-5.47.0/lib/sequel/adapters/ado/mssql.rb
sequel-5.47.0 lib/sequel/adapters/ado/mssql.rb
sequel-5.46.0 lib/sequel/adapters/ado/mssql.rb
sequel-5.45.0 lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.43.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/adapters/ado/mssql.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/adapters/ado/mssql.rb