Sha256: 48dfbdb04f760f202d3a04c31c1afc6b8214a97d9381b6ab30a6f15a6d3f9794

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

# frozen-string-literal: true

Sequel.require 'adapters/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

    # 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()'.freeze
        
        # Return the last inserted identity value.
        def execute_insert(sql, opts=OPTS)
          synchronize(opts[:server]) do |conn|
            begin
              log_connection_yield(sql, conn){conn.do(sql)}
              begin
                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

        # Use ODBC format, not Microsoft format, as the ODBC layer does
        # some translation.  MSSQL version is over-ridden to allow 3 millisecond decimal places        
        TIMESTAMP_FORMAT="{ts '%Y-%m-%d %H:%M:%S%N'}".freeze

        private

        def default_timestamp_format
          TIMESTAMP_FORMAT
        end

        # Use ODBC format, not Microsoft format, as the ODBC layer does
        # some translation.
        def literal_date(v)
          v.strftime(ODBC_DATE_FORMAT)
        end
      end
    end
  end
end

Version data entries

8 entries across 7 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/sequel-4.44.0/lib/sequel/adapters/odbc/mssql.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/sequel-4.44.0/lib/sequel/adapters/odbc/mssql.rb
sequel-4.45.0 lib/sequel/adapters/odbc/mssql.rb
tdiary-5.0.4 vendor/bundle/gems/sequel-4.44.0/lib/sequel/adapters/odbc/mssql.rb
sequel-4.44.0 lib/sequel/adapters/odbc/mssql.rb
sequel-4.43.0 lib/sequel/adapters/odbc/mssql.rb
sequel-4.42.1 lib/sequel/adapters/odbc/mssql.rb
sequel-4.42.0 lib/sequel/adapters/odbc/mssql.rb