SQL - Python - データとテーブル - あらゆるものにふさわしい場所 - テーブルの作成
Head First SQL ―頭とからだで覚えるSQLの基本、 Lynn Beighley(著)、 佐藤 直生(監訳)、 松永 多苗子(翻訳)、 オライリージャパンの 1章(データとテーブル - あらゆるものにふさわしい場所)、p.21(自分で考えてみよう)の解答を求めてみる。
schema1.sql
drop table my_contacts;
create table my_contacts
(
last_name text,
first_name text,
email text,
birthday date,
profession text,
location text,
status text,
interests text,
seekinng teext
);
コード
sample1.py
#! /usr/bin/env python3
import sqlite3
con = sqlite3.connect('sample.db')
cur = con.cursor()
with open('schema1.sql') as f:
cur.executescript(f.read())
print(cur)
cur.close()
con.close()
入出力結果(Terminal, Zsh)
% ./sample1.py
<sqlite3.Cursor object at 0x100fb7cc0>
%