開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Python (Paul Barry(著)、 O'Reilly Media )のChapter 9(Manage Your data: Handling input)、SQLITE MAGNETS(p.319)を解いてみる。
SQLITE MAGNETS(p.319)
コード(BBEdit)
createDBtables.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import sqlite3
connection = sqlite3.connect('coachdata.sqlite')
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE athletes(
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
name TEXT NOT NULL,
dob DATE NOT NULL)
""")
cursor.execute("""
CREATE TABLE timing_data(
athlete_id INTEGER NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (athlete_id) REFERENCES athletes)
""")
connection.commit()
connection.close()
入出力結果(Terminal, IPython)
$ ls coachdata.sqlite ls: coachdata.sqlite: No such file or directory $ ./createDBtables.py $ ls coachdata.sqlite coachdata.sqlite $
0 コメント:
コメントを投稿