-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2107.rb
More file actions
25 lines (21 loc) · 1007 Bytes
/
ex2107.rb
File metadata and controls
25 lines (21 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
require 'rubygems' # RubyGemsでインストールしたときには記述
require 'dbi' # DBIを使う
# dbhを作成し、データベース'fruits01.db'に接続する
# もし既に存在するときは、そのデータベースファイルを開く
dbh = DBI.connect( 'DBI:SQLite3:fruits01.db' )
# もしすでにこのデータベースにテーブル'products'があれば削除する
dbh.do("drop table if exists products")
puts "table 'products' has dropped."
# 新しく'products'テーブルを作成する
dbh.do("create table products (
id int not null,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price int not null,
date_available datetime not null,
primary key(id));")
puts "table 'products' has created."
# データベースとの接続を終了する
dbh.disconnect