第 10 回 CGI ことおぼえ レポート課題 氏名:舟山真 学籍番号:c1111286 語学クラス:英語2 コース:政策マネジメント チーム名:Oh!にぎり チームホームページアドレス:http://roy/~c111108/Ohnigiri/ 部門: プロジェクトコード名: チーム SNS アドレス: 1、筆記問題 ・pstore とは Ruby のオブジェクトを外部ファイルに格納するためのクラスのこと。 transaction のブロック内でなければデータベースにアクセスすることが出来な いので注意。 ・pstore の使い方 require 'pstore' #受け取ったデータをためる宣言 cgi = CGI.new(:accept_charset => "EUC-JP") pstore = PStore.new("pstore/bbs.db") #データベースを入力させる部分 db.transaction do #入力されたデータを読み込んで出 力する部分 ・実際のプログラム 今回の授業で作成したプログラムは次のようになる。 #!/usr/bin/env ruby #coding: euc-jp require 'cgi' require 'pstore' cgi = CGI.new(:accept_charset => "EUC-JP") db = PStore.new("pstore/bbs.db") usr = cgi["usr"] cmt = cgi["comment"] t = Time.now.to_i myprog = "pstore_bbs.rb" print("Content-type: text/html; charset=EUC-JP\n\n") print("\n") print("\n") print("けいじばん\n") print("\n") print("\n") print("

けいじばん

\n") print("\n") db.transaction do if db == nil db = Hash.new end db[t] = [usr,cmt] printf("
    ") for time in db.roots.sort printf("
  1. %s:%s
  2. \n",db[time][0],db[time][1]) end end print("
\n") printf("
", myprog) print("