fixes for database

This commit is contained in:
Justin Balthrop 2009-11-19 13:46:38 -08:00
parent ea38686c2c
commit 110221e983

View file

@ -26,7 +26,7 @@ class Bdb::Database
primary_db = environment.env.db primary_db = environment.env.db
primary_db.pagesize = config[:page_size] if config[:page_size] primary_db.pagesize = config[:page_size] if config[:page_size]
primary_db.open(transaction, name, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0) primary_db.open(transaction, name, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
@db[:primary] = primary_db @db[:primary_key] = primary_db
indexes.each do |field, opts| indexes.each do |field, opts|
index_callback = lambda do |db, key, data| index_callback = lambda do |db, key, data|
@ -49,7 +49,7 @@ class Bdb::Database
end end
end end
end end
@db[index || :primary] @db[index || :primary_key]
end end
def close def close
@ -75,12 +75,7 @@ class Bdb::Database
flags = 0 if environment.disable_transactions? flags = 0 if environment.disable_transactions?
keys.each do |key| keys.each do |key|
if opts[:partial] and not key.kind_of?(Range) and not key == :all key = get_key(key, opts)
first = [*key]
last = first + [true]
key = first..last
end
if key == :all if key == :all
with_cursor(db) do |cursor| with_cursor(db) do |cursor|
if opts[:reverse] if opts[:reverse]
@ -189,6 +184,15 @@ class Bdb::Database
private private
def get_key(key, opts)
if opts[:partial] and not key.kind_of?(Range) and not key == :all
first = [*key]
last = first + [true]
key = first..last
end
key
end
def unmarshal(value, opts = {}) def unmarshal(value, opts = {})
value = Marshal.load(value) value = Marshal.load(value)
value.bdb_locator_key = opts[:tuple] ? Tuple.load(opts[:tuple]) : [*opts[:key]] value.bdb_locator_key = opts[:tuple] ? Tuple.load(opts[:tuple]) : [*opts[:key]]
@ -227,13 +231,13 @@ private
attr_reader :count, :group, :limit, :offset, :results attr_reader :count, :group, :limit, :offset, :results
def <<(item) def <<(item)
key = item[1]
@count += 1 @count += 1
return if count <= offset return if count <= offset
raise LimitReached if limit and count > limit + offset raise LimitReached if limit and count > limit + offset
if group if group
key = item.bdb_locator_key
group_key = group.is_a?(Fixnum) ? key[0,group] : key group_key = group.is_a?(Fixnum) ? key[0,group] : key
(results[group_key] ||= []) << item (results[group_key] ||= []) << item
elsif @block elsif @block