Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created December 2, 2010 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noqisofon/724923 to your computer and use it in GitHub Desktop.
Save noqisofon/724923 to your computer and use it in GitHub Desktop.
Ruby の sqlite3 でテーブルを作成する。
#!c:/bin/ruby/bin/ruby
# -*- encoding: shift_jis -*-
require 'rubygems'
require 'sqlite3'
# SQLite3 モジュールの取り込み。
include SQLite3
# データベースファイル作成。
database = Database.new( "message-notifier.sqlite" )
# テーブル作成のための SQL クエリ。
sql_query = <<-SQL
create table messages (
message_id int primary key, -- メッセージ番号。
title varchar(128) not null, -- メッセージのタイトル。
message varchar(1024) not null, -- メッセージ本文。
creation_date datetime not null -- メッセージ作成日。
)
SQL
puts sql_query
# クエリを実行。
database.execute( sql_query )
# データベースを閉じる。
database.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment