Sha256: bdf4937962c6bcab92e3ec863722c65e12be00bd4b3dcb036767762e408c11db

Contents?: true

Size: 1.59 KB

Versions: 115

Compression:

Stored size: 1.59 KB

Contents

# frozen-string-literal: true

require_relative '../shared/mssql'

module Sequel
  module ODBC
    Sequel.synchronize do
      DATABASE_SETUP[:mssql] = proc do |db|
        db.extend Sequel::ODBC::MSSQL::DatabaseMethods
        db.dataset_class = Sequel::ODBC::MSSQL::Dataset
        db.send(:set_mssql_unicode_strings)
      end
    end

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

        def execute_insert(sql, opts=OPTS)
          synchronize(opts[:server]) do |conn|
            begin
              log_connection_yield(sql, conn){conn.do(sql)}
              begin
                last_insert_id_sql = 'SELECT SCOPE_IDENTITY()'
                s = log_connection_yield(last_insert_id_sql, conn){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
      end
      class Dataset < ODBC::Dataset
        include Sequel::MSSQL::DatasetMethods

        private

        # Use ODBC format, not Microsoft format, as the ODBC layer does
        # some translation, but allow for millisecond precision.
        def default_timestamp_format
          "{ts '%Y-%m-%d %H:%M:%S%N'}"
        end

        # Use ODBC format, not Microsoft format, as the ODBC layer does
        # some translation.
        def literal_date(v)
          v.strftime("{d '%Y-%m-%d'}")
        end
      end
    end
  end
end

Version data entries

115 entries across 98 versions & 2 rubygems

Version Path
sequel-5.75.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.74.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.73.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.72.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.71.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.70.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.69.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.68.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.67.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.66.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.65.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.64.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.63.0 lib/sequel/adapters/odbc/mssql.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/sequel-5.62.0/lib/sequel/adapters/odbc/mssql.rb
sequel-5.62.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.61.0 lib/sequel/adapters/odbc/mssql.rb
sequel-5.60.1 lib/sequel/adapters/odbc/mssql.rb
sequel-5.60.0 lib/sequel/adapters/odbc/mssql.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/sequel-5.59.0/lib/sequel/adapters/odbc/mssql.rb
sequel-5.59.0 lib/sequel/adapters/odbc/mssql.rb