Sha256: e441d718e828cb77d7df0c6eee9f00c8ddb4073acc39858396a6d64ba0aba1b7
Contents?: true
Size: 1.61 KB
Versions: 8
Compression:
Stored size: 1.61 KB
Contents
if !Object.const_defined?('Sequel') require File.join(File.dirname(__FILE__), '../sequel') end require 'win32ole' module Sequel module ADO class Database < Sequel::Database set_adapter_scheme :ado AUTO_INCREMENT = 'IDENTITY(1,1)'.freeze def auto_increment_sql AUTO_INCREMENT end def connect dbname = @opts[:database] handle = WIN32OLE.new('ADODB.Connection') handle.Open(dbname) handle end def dataset(opts = nil) ADO::Dataset.new(self, opts) end def execute(sql) @logger.info(sql) if @logger @pool.hold {|conn| conn.Execute(sql)} end alias_method :do, :execute end class Dataset < Sequel::Dataset def literal(v) case v when Time: literal(v.iso8601) else super end end def fetch_rows(sql, &block) @db.synchronize do s = @db.execute sql fields = s.Fields.extend(Enumerable) @columns = fields.map {|x| x.Name.to_sym} s.moveFirst s.getRows.transpose.each {|r| yield hash_row(r)} end self end def hash_row(row) @columns.inject({}) do |m, c| m[c] = row.shift m end end def insert(*values) @db.do insert_sql(*values) end def update(values, opts = nil) @db.do update_sql(values, opts) self end def delete(opts = nil) @db.do delete_sql(opts) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems