計算機科学のブログ

ほしい物リスト

Python - SQL - SQLite - List Comprehensions: Database Integrations - parameterized function

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 13.(List Comprehensions: Database Integrations)、EXERCISE(595/682)の解答を求めてみる。

コード

webapp/data_utils.py

import DBcm
from queries import *

db_details = 'CoachDB.sqlite3'


def get_swimmers_events(name, age, date):
    with DBcm.UseDatabase(db_details) as db:
        db.execute(
            SQL_SWIMMERS_EVENTS_BY_SESSION,
            (
                name,
                age,
                date,
            ),
        )
        results = db.fetchall()
    return results