On Tue, 3 Apr 2007, Jim Cain wrote:

> OK, I figured out that a lot of my previous code was wrong, not even
> considering the transactions, so I removed the transactional stuff and
> got down to this:
>
> require 'bdb'
>
> BDB::Hash.open('models.db', nil, BDB::CREATE | BDB::TRUNCATE) {}
> BDB::Hash.open('makes.db', nil, BDB::CREATE | BDB::TRUNCATE,
> :set_flags => BDB::DUP | BDB::DUPSORT) {}
>
> BDB::Hash.open('models.db', nil, BDB::CREATE) do |models|
> BDB::Hash.open('makes.db', nil, BDB::CREATE, :set_flags => BDB::DUP
> | BDB::DUPSORT) do |makes|
>   models.associate(makes) { |sdb, key, value| value }
>
>   puts '===== Before'
>   puts '----- models'
>   models.each { |key, value| puts "#{key} = #{value}" }
>   puts '----- makes'
>   makes.each_primary { |skey, pkey, pvalue| p [skey, pkey, pvalue] }
>
>   models['Civic'] = 'Honda'
>   models['Accord'] = 'Honda'
>   models['S2000'] = 'Honda'
>   models['Camry'] = 'Toyota'
>   models['Solara'] = 'Toyota'
>
>   puts '===== After'
>   puts '----- models'
>   models.each { |key, value| puts "#{key} = #{value}" }
>   puts '----- makes'
>   makes.each_primary { |skey, pkey, pvalue| p [skey, pkey, pvalue] }
> end
> end
>
> And here is the output, which looks right to me:
>
> ===== Before
> ----- models
> ----- makes
> ===== After
> ----- models
> Civic = Honda
> Accord = Honda
> Camry = Toyota
> Solara = Toyota
> S2000 = Honda
> ----- makes
> ["Honda", "Accord", "Honda"]
> ["Honda", "Civic", "Honda"]
> ["Honda", "S2000", "Honda"]
> ["Toyota", "Camry", "Toyota"]
> ["Toyota", "Solara", "Toyota"]
>
> Now I just have to figure out the transactional part. I'll follow up
> on the list once I do.

there are transaction examples in the bdb src - have you looked at that?

-a
-- 
be kind whenever possible... it is always possible.
- the dalai lama