September 2010
Intermediate to advanced
440 pages
9h 23m
English
As with most programming languages, the more one knows about the data and data structure, the better one can program to handle it. This is at least doubly true for database programming with aggregate functions and clauses such as those which we cover in this chapter.
Putting the SELECT statement into Python is not particularly complex, but handling the results intelligently requires a knowledge of their format. Again, setting up a basic database session in Python would look like this:
#!/usr/bin/env python
import MySQLdb
mydb = MySQLdb.connect('localhost', 'skipper', 'secret', 'sakila')
cursor = mydb.cursor()For the statement to be run against sakila, we can use the following:
statement = """SELECT * FROM film WHERE title LIKE ...
Read now
Unlock full access