Wenn kein Element existiert, wird ein Exception geworfen. Dies ist etwas unschoen, also wird diese abgefangen und nil zurueckgegeben.

master
Denis Knauf 2010-02-06 00:41:43 +01:00
parent 926e53ae3e
commit 37a9161470
1 changed files with 7 additions and 1 deletions

View File

@ -17,9 +17,15 @@ module SBDB
def bdb_object() @db end
def sync() @db.sync end
def close( f = nil) @db.close f || 0 end
def []( k) @db.get nil, k.nil? ? nil : k.to_s, nil, 0 end
def cursor( &e) Cursor.new self, &e end
def [] k
@db.get nil, k.nil? ? nil : k.to_s, nil, 0
rescue Bdb::DbError
return if $!.code == Bdb::DB_KEYEMPTY
raise $!
end
def []= k, v
if v.nil?
@db.del nil, k.to_s, 0