Ruby/Database/dbm
Материал из Wiki.crossplatform.ru
Версия от 17:55, 13 сентября 2010; ViGOur (Обсуждение | вклад)
Содержание |
each loop on Berkeley DB Databases
require "bdb" db = BDB::Btree.create("e.db", nil, BDB::CREATE) db["earth"] = "M" db["water"] = "A" db["air"] = "s" db["fire"] = "P" db.each { |k,v| puts k } puts db["water"] db.close
Save and retrieve data from Berkeley DB Databases
require "bdb" db = BDB::Hash.create("r2.db", nil, BDB::CREATE) db["W"] = "i" db.close db = BDB::Hash.open("r2.db", nil, "r") db["W"] db.close
Save and retrieve data from DBM
require "dbm" d = DBM.new("data") d["123"] = "123" puts d["123"] d.close puts d["123"] # RuntimeError: closed DBM file e = DBM.open("data") e["123"] w=e.to_hash e.close e["123"] # RuntimeError: closed DBM file w["123"]
Using Berkeley DB Databases
require "dbm" DBM.open("r") do |db| db["t"] ="W" db[23] = "F" end DBM.open("r") do |db| puts db["t"] puts db["23"] end p Dir["r.*"]