J
Jim Cain
I'm having trouble figuring out how to do transactions. I'm using db
4.5.40 from Oracle and bdb 0.6.0. Here's a code snippet:
require 'bdb'
BDB::Hash.open('models.db', nil, BDB::TRUNCATE) {}
BDB::Hash.open('makes.db', nil, BDB::TRUNCATE) {}
BDB::Env.open('db', BDB::CREATE | BDB::INIT_TRANSACTION) do |env|
models = makes = nil
env.begin(BDB::TXN_COMMIT) do |tx|
models = tx.open_db(BDB::HASH, 'models.db', nil, BDB::CREATE)
makes = tx.open_db(BDB::HASH, 'makes.db', nil, BDB::CREATE | BDB:
UPSORT)
models.associate(makes) { |sdb, key, value| value }
end
env.begin(BDB::TXN_COMMIT) do |tx|
tx.assoc(models, makes)
puts '===== Before'
puts '----- models'
models.each { |key, value| puts "#{key} = #{value}" }
puts '----- makes'
makes.each { |key, value| puts "#{key} = #{value}" }
end
env.begin(BDB::TXN_COMMIT) do |tx|
tx.assoc(models, makes)
models['Civic'] = 'Honda'
models['Accord'] = 'Honda' # this is line 26 where the error is occurring
models['S2000'] = 'Honda'
models['Camry'] = 'Toyota'
models['Solara'] = 'Toyota'
end
env.begin do |tx|
tx.assoc(models, makes)
puts '===== After'
puts '----- models'
models.each { |key, value| puts "#{key} = #{value}" }
puts '----- makes'
makes.each { |key, value| puts "#{key} = #{value}" }
end
makes.close
models.close
end
Now I have no idea if I'm using transactions properly, not to mention
any of the other various features, but I suspect I'm not since I get
this output:
===== Before
----- models
----- makes
/home/jim/eclipse/testRuby/test.rb:26:in `close': BUG : current_env
not set (BDB::Fatal)
from /home/jim/eclipse/testRuby/test.rb:26:in `open'
from /home/jim/eclipse/testRuby/test.rb:6
/home/jim/eclipse/testRuby/test.rb:26: [BUG] Segmentation fault
ruby 1.8.5 (2007-03-13) [i386-linux]
I would greatly appreciate any help that anyone can provide.
Cheers,
Jim
4.5.40 from Oracle and bdb 0.6.0. Here's a code snippet:
require 'bdb'
BDB::Hash.open('models.db', nil, BDB::TRUNCATE) {}
BDB::Hash.open('makes.db', nil, BDB::TRUNCATE) {}
BDB::Env.open('db', BDB::CREATE | BDB::INIT_TRANSACTION) do |env|
models = makes = nil
env.begin(BDB::TXN_COMMIT) do |tx|
models = tx.open_db(BDB::HASH, 'models.db', nil, BDB::CREATE)
makes = tx.open_db(BDB::HASH, 'makes.db', nil, BDB::CREATE | BDB:
models.associate(makes) { |sdb, key, value| value }
end
env.begin(BDB::TXN_COMMIT) do |tx|
tx.assoc(models, makes)
puts '===== Before'
puts '----- models'
models.each { |key, value| puts "#{key} = #{value}" }
puts '----- makes'
makes.each { |key, value| puts "#{key} = #{value}" }
end
env.begin(BDB::TXN_COMMIT) do |tx|
tx.assoc(models, makes)
models['Civic'] = 'Honda'
models['Accord'] = 'Honda' # this is line 26 where the error is occurring
models['S2000'] = 'Honda'
models['Camry'] = 'Toyota'
models['Solara'] = 'Toyota'
end
env.begin do |tx|
tx.assoc(models, makes)
puts '===== After'
puts '----- models'
models.each { |key, value| puts "#{key} = #{value}" }
puts '----- makes'
makes.each { |key, value| puts "#{key} = #{value}" }
end
makes.close
models.close
end
Now I have no idea if I'm using transactions properly, not to mention
any of the other various features, but I suspect I'm not since I get
this output:
===== Before
----- models
----- makes
/home/jim/eclipse/testRuby/test.rb:26:in `close': BUG : current_env
not set (BDB::Fatal)
from /home/jim/eclipse/testRuby/test.rb:26:in `open'
from /home/jim/eclipse/testRuby/test.rb:6
/home/jim/eclipse/testRuby/test.rb:26: [BUG] Segmentation fault
ruby 1.8.5 (2007-03-13) [i386-linux]
I would greatly appreciate any help that anyone can provide.
Cheers,
Jim