Sha256: ae2a8d8ed131270f36f888587abf5f600e4c52292187adaaf2192d6e28f25056

Contents?: true

Size: 1.86 KB

Versions: 25

Compression:

Stored size: 1.86 KB

Contents

require 'informix'

module Sequel
  module Informix
    class Database < Sequel::Database
      set_adapter_scheme :informix
      
      # AUTO_INCREMENT = 'IDENTITY(1,1)'.freeze
      # 
      # def auto_increment_sql
      #   AUTO_INCREMENT
      # end
      
      def connect
        ::Informix.connect(@opts[:database], @opts[:user], @opts[:password])
      end
      
      def disconnect
        @pool.disconnect {|c| c.close}
      end
    
      def dataset(opts = nil)
        Sequel::Informix::Dataset.new(self, opts)
      end
      
      # Returns number of rows affected
      def execute(sql)
        @logger.info(sql) if @logger
        @pool.hold {|c| c.do(sql)}
      end
      alias_method :do, :execute
      
      def query(sql, &block)
        @logger.info(sql) if @logger
        @pool.hold {|c| block[c.cursor(sql)]}
      end
    end
    
    class Dataset < Sequel::Dataset
      def literal(v)
        case v
        when Time
          literal(v.iso8601)
        else
          super
        end
      end

      def select_sql(opts = nil)
        limit = opts.delete(:limit)
        offset = opts.delete(:offset)
        sql = super
        if limit
          limit = "FIRST #{limit}"
          offset = offset ? "SKIP #{offset}" : ""
          sql.sub!(/^select /i,"SELECT #{offset} #{limit} ")
        end
        sql
      end
      
      def fetch_rows(sql, &block)
        @db.synchronize do
          @db.query(sql) do |cursor|
            begin
              cursor.open.each_hash {|r| block[r]}
            ensure
              cursor.drop
            end
          end
        end
        self
      end
      
      def insert(*values)
        @db.do insert_sql(*values)
      end
    
      def update(*args, &block)
        @db.do update_sql(*args, &block)
      end
    
      def delete(opts = nil)
        @db.do delete_sql(opts)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
sequel-0.5.0.2 lib/sequel/adapters/informix.rb
sequel-0.5.0.1 lib/sequel/adapters/informix.rb
sequel-0.4.5 lib/sequel/adapters/informix.rb
sequel-0.4.4.2 lib/sequel/adapters/informix.rb
sequel-0.5 lib/sequel/adapters/informix.rb
sequel_core-1.0.0.1 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.10 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.3 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.2 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.1 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.8.1 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.8.2 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.7 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.6 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.5 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.4 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.4.1 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.9.1 lib/sequel_core/adapters/informix.rb
sequel_core-1.0.8 lib/sequel_core/adapters/informix.rb
sequel_core-1.2.1 lib/sequel_core/adapters/informix.rb