Sha256: 4df0903d6452587c5bae6e70135a5fdbacf226549ea1ba10df8e4eaa98a7a665

Contents?: true

Size: 1.93 KB

Versions: 86

Compression:

Stored size: 1.93 KB

Contents

# frozen-string-literal: true

require_relative '../shared/sqlanywhere'
require_relative 'transactions'

module Sequel
  module JDBC
    drv = [
      lambda{Java::sybase.jdbc4.sqlanywhere.IDriver},
      lambda{Java::ianywhere.ml.jdbcodbc.jdbc4.IDriver},
      lambda{Java::sybase.jdbc.sqlanywhere.IDriver},
      lambda{Java::ianywhere.ml.jdbcodbc.jdbc.IDriver},
      lambda{Java::com.sybase.jdbc4.jdbc.Sybdriver},
      lambda{Java::com.sybase.jdbc3.jdbc.Sybdriver}
    ].each do |class_proc|
      begin
        break class_proc.call
      rescue NameError
      end
    end
    raise(Sequel::AdapterNotFound, "no suitable SQLAnywhere JDBC driver found") unless drv

    Sequel.synchronize do
      DATABASE_SETUP[:sqlanywhere] = proc do |db|
        db.extend(Sequel::JDBC::SqlAnywhere::DatabaseMethods)
        db.convert_smallint_to_bool = true
        db.dataset_class = Sequel::JDBC::SqlAnywhere::Dataset
        drv
      end
    end

    module SqlAnywhere
      module DatabaseMethods
        include Sequel::SqlAnywhere::DatabaseMethods
        include Sequel::JDBC::Transactions

        private

        # Use @@IDENTITY to get the last inserted id
        def last_insert_id(conn, opts=OPTS)
          statement(conn) do |stmt|
            sql = 'SELECT @@IDENTITY'
            rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)}
            rs.next
            rs.getLong(1)
          end
        end
      end

      class Dataset < JDBC::Dataset
        include Sequel::SqlAnywhere::DatasetMethods

        private

        SMALLINT_TYPE = Java::JavaSQL::Types::SMALLINT
        BOOLEAN_METHOD = Object.new
        def BOOLEAN_METHOD.call(r, i)
          v = r.getShort(i)
          v != 0 unless r.wasNull
        end

        def type_convertor(map, meta, type, i)
          if convert_smallint_to_bool && type == SMALLINT_TYPE
            BOOLEAN_METHOD
          else
            super
          end
        end
      end
    end
  end
end

Version data entries

86 entries across 72 versions & 2 rubygems

Version Path
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/jdbc/sqlanywhere.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/adapters/jdbc/sqlanywhere.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/jdbc/sqlanywhere.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/jdbc/sqlanywhere.rb
sequel-5.44.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.43.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.42.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
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/jdbc/sqlanywhere.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.41.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.40.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.39.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.38.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.37.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.36.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/sequel-5.32.0/lib/sequel/adapters/jdbc/sqlanywhere.rb