Final project for CS 164 at UC Berkeley, Fall 2014.
import sqlite3
from PDTable import PDTable
# Connect to the database
connection = sqlite3.connect('tests/db.sqlite3')
cursor = connection.cursor()
# Create a PDTable for the "counties" table
c = PDTable('counties', cursor=cursor)
# Get all the counties with a 2010 population greater than 2 million,
# get their statecodes, names, and 2010 populations,
# and show them in descending order by 2010 population
counties = reversed(
c.where(c.population_2010 > 2000000)
.select(c.statecode, c.name, c.population_2010)
.order(c.population_2010))
# Print the compiled SQL statement
print(counties.compile())
# Print the actual results of running the query
print(counties)