marshalsql.rb
rbmud-0.2/lib/marshalsql.rb · 679 B
From the archive RbMUD-0.2.tar.bz2
Download the archive « Back to the archive contents
#!/usr/local/bin/ruby
# $Revision: 1.6 $
# $Date: 2003/12/04 22:18:34 $
# $Author: mikeman2 $
#Creates a module 'MarshalSQL' that uses marshal to store objects in an
#sql database.
#!!broken -- may need to dump data into more friendly format for db
module MarshalSQL
def MarshalSQL.load(fname, table = "players")
fnames = []
DB.query("SELECT name, marshal FROM `#{table}`").each_hash do |a|
if a['name'] == fname
return Marshal.load("#{a['marshal']}")
else
return nil
end
end
return nil
end
def MarshalSQL.dump(object, fname, table = "players")
DB.query("REPLACE INTO `#{table}` VALUES ('#{fname}', '#{Marshal.dump(object)}')")
return
end
end