#!/usr/koeki/bin/ruby
# coding: utf-8
Encoding.default_external = 'utf-8'	# UTF-8のCSVファイルを読むため
require 'cgi'
require 'sqlite3'
c = CGI.new(:accept_charset => "UTF-8")

#データベース読み取り処理は全く同じ
db = SQLite3::Database.new("gomi.db")
result = db.execute("SELECT * FROM gomi;")
result.each do |row|
  keep = row.join(",")
end

trash = c["gomi"]

if trash > ""			
  ptn = Regexp.new(trash)
  keep = keep.select {|row| ptn =~ row["name"]}
end

puts row["name"]
