Files
2025-05-20 11:57:43 -04:00

36 lines
714 B
Python

#!/usr/bin/env python
import sqlite3
s3conn = sqlite3.connect("../DATA/presidents.db")
# uncomment to make _all_ cursors dictionary cursors
# conn.row_factory = sqlite3.Row
NAME_QUERY = '''
select firstname, lastname
from presidents
where termnum < 5
'''
cur = s3conn.cursor()
# select first name, last name from all presidents
cur.execute(NAME_QUERY)
for row in cur.fetchall():
print(row)
print('-' * 50)
dcur = s3conn.cursor() # <1>
# make _this_ cursor a dictionary cursor
dcur.row_factory = sqlite3.Row # <2>
# select first name, last name from all presidents
dcur.execute(NAME_QUERY)
for row in dcur.fetchall():
print(row['firstname'], row['lastname']) # <3>
print('-' * 50)