Python - SQLite - Databases: Getting Organized - pragma, table_list
Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly Guide、 Paul Barry(著)、 O’Reilly Mediaの Chapter 12.(Databases: Getting Organized)、EXERCISE(540/682)の解答を求めてみる。
Jupyter(コード、入出力結果)
CreateDatabaseTables.ipynb
SQL = '''
create table if not exists swimers (
id integer not null primary key autoincrement,
name varchar(32) not null,
age integer not null
)
'''
with DBcm.UseDatabase(db_details) as db:
db.execute(SQL)
with DBcm.UseDatabase(db_details) as db:
results = db.execute('pragma table_list').fetchall()
results
[('main', 'sqlite_sequence', 'table', 2, 0, 0),
('main', 'swimers', 'table', 3, 0, 0),
('main', 'sqlite_schema', 'table', 5, 0, 0),
('temp', 'sqlite_temp_schema', 'table', 5, 0, 0)]