| 1 |
import sqlite3 |
| 2 |
|
| 3 |
FIELD_MAX_WIDTH = 20 |
| 4 |
TABLE_NAME = 'people' |
| 5 |
SELECT = 'select * from %s order by age, name_last' % TABLE_NAME |
| 6 |
|
| 7 |
con = sqlite3.connect("mydb") |
| 8 |
|
| 9 |
cur = con.cursor() |
| 10 |
cur.execute(SELECT) |
| 11 |
|
| 12 |
|
| 13 |
for fieldDesc in cur.description: |
| 14 |
print fieldDesc[0].ljust(FIELD_MAX_WIDTH) , |
| 15 |
print |
| 16 |
print '-' * 78 |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
fieldIndices = range(len(cur.description)) |
| 21 |
for row in cur: |
| 22 |
for fieldIndex in fieldIndices: |
| 23 |
fieldValue = str(row[fieldIndex]) |
| 24 |
print fieldValue.ljust(FIELD_MAX_WIDTH) , |
| 25 |
|
| 26 |
print |