[Ruby-session-devel-cvs] CVS: ruby-session/src/session dbi.rb,NONE,1.1
Status: Alpha
Brought to you by:
thetitan
From: Sean C. <the...@us...> - 2002-06-13 12:28:30
|
Update of /cvsroot/ruby-session/ruby-session/src/session In directory usw-pr-cvs1:/tmp/cvs-serv28716/session Added Files: dbi.rb Log Message: *) Checking in work *) Still an outstanding DBI bug with unescaping data on restore from the database *) Oustanding bug with converting to a Time object from data stored in a 'timestamp without time zone' data type --- NEW FILE: dbi.rb --- $:.unshift('/usr/home/sean/open_source/ruby-dbi/src/lib/dbi') $:.unshift('/usr/home/sean/open_source/ruby-dbi/src/lib/dbd_pg') require 'dbi' #require 'Pg' class Session @@commit.push('dbi_commit') @@init.push('dbi_init') @@load.push('dbi_load') @@tmp = nil attr_accessor(:db_host, :db_name, :db_table_name, :db_type, :db_user) attr_reader(:dbh) attr_writer(:db_pass) private def dbi_commit() ins_sql() if @db_ins_sql.nil? get_dbh() if @dbh.nil? @@tmp = Marshal.dump(@data) @dbh.do(@db_ins_sql, @session_id, Marshal.dump(@data)) end # def dbi_commit() def dbi_init() @dbh = nil @db_dsn = nil @db_host = nil @db_name = nil @db_pass = nil @db_get_sql = nil @db_ins_sql = nil @db_table_name = 'session' @db_type = 'Pg' @db_user = nil end # def dbi_init() def dbi_load() get_sql() if @db_get_sql.nil? get_dbh() if @dbh.nil? row = @dbh.select_one(@db_get_sql, @session_id) if !row.nil? p @@tmp p row[1] raise row[1].to_s @data = Marshal.load(row[1].gsub(Regexp.new('\\\\\\\\'), '\\')) @start_date = row[2] @last_updated = row[3] @secure = row[4] @rekey_time = row[5] @expiration_time = row[6] $session = self end end # def dbi_commit() def dsn() if @db_dsn.nil? dsn = "DBI:#{@db_type}:#{@db_name}" dsn << ":#{@db_name}" if @db_host @db_dsn = dsn end return(@db_dsn) end # def dsn() def get_dbh() if @dbh.nil? dsn() if @db_dsn.nil? @dbh = DBI.connect(@db_dsn, @db_user, @db_pass) end # if @dbh.nil? return(@dbh) end # def get_dbh() def get_sql() if @db_get_sql.nil? #sql = "SELECT session_id, session_data, utc_start_time, utc_last_updated, secure, rekey_time, expiration_time FROM #{@db_table_name} WHERE session_id = ?" sql = "SELECT session_id, session_data, utc_start_time FROM #{@db_table_name} WHERE session_id = ?" @db_get_sql = sql end return(@db_get_sql) end # def get_sql() def ins_sql() if @db_ins_sql.nil? sql = "INSERT INTO session (session_id, session_data) VALUES (?,?)" @db_ins_sql = sql end end # def ins_sql() end # module Session |