Sha256: c949e87823940a54fd548b58f283ee8499be253ed6b756150cc015350508811b

Contents?: true

Size: 1.95 KB

Versions: 27

Compression:

Stored size: 1.95 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
      def self.SqlAnywhereBoolean(r, i)
        v = r.getShort(i)
        v != 0 unless r.wasNull
      end

      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 = SqlAnywhere.method(:SqlAnywhereBoolean)

        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

27 entries across 24 versions & 2 rubygems

Version Path
sequel-5.17.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.16.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.0.11 vendor/bundle/gems/sequel-5.15.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.0.11 vendor/bundle/gems/sequel-5.11.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.15.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.14.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.13.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.12.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.11.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.10.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.0.9 vendor/bundle/gems/sequel-5.9.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.9.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.8.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.7.1 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.7.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.0.8 vendor/bundle/gems/sequel-5.6.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/sequel-5.6.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/sequel-5.3.0/lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.6.0 lib/sequel/adapters/jdbc/sqlanywhere.rb
sequel-5.5.0 lib/sequel/adapters/jdbc/sqlanywhere.rb