From: Tom Gilbert Date: 2002-07-23T22:06:40+09:00 Subject: Re: bdb and $= * ts (decoux@moulon.inra.fr) wrote: > >>>>> "T" == Tom Gilbert writes: > > T> Hrm. I have a feeling the only way I could use this would be to tolower! > T> every key, right? But wouldn't that mean that the case information was > T> lost in the db itself? > > yes, > > T> e.g, I want to store a key "Fred Jones", but be able to lookup "fred > T> jones", and still have it display as "Fred Jones", if you see what I > T> mean.. > > Try this : > > pigeon% cat b.rb > #!/usr/bin/ruby > require 'bdb' > module BDB > class A < Btree > def bdb_bt_compare(a, b) > a.downcase <=> b.downcase > end > end > end > > db = BDB::A.open "basic", nil, "w" > db["Fred Jones"] = "abc" > p db["fred jones"] > p db.keys > pigeon% > > pigeon% b.rb > "abc" > ["Fred Jones"] > pigeon% Okay, that looks nice. However I'm currently using BDB::Hash because I don't really need sorted access to the keys. I can switch to BDB::Btree, if there aren't any major penalties for doing so.. I know I'll lose all my existing data saved in db's opened using the Hash api though :( I assume there's no way to set the compare function for BDB::Hash? Tom. -- .^. .-------------------------------------------------------. /V\ | Tom Gilbert, London, England | http://linuxbrit.co.uk | /( )\ | Open Source/UNIX consultant | tom@linuxbrit.co.uk | ^^-^^ `-------------------------------------------------------'