ยปCore Development>Code coverage>Doc/includes/sqlite3/execsql_fetchonerow.py

Python code coverage for Doc/includes/sqlite3/execsql_fetchonerow.py

#countcontent
1n/aimport sqlite3
2n/a
3n/acon = sqlite3.connect("mydb")
4n/a
5n/acur = con.cursor()
6n/aSELECT = "select name_last, age from people order by age, name_last"
7n/a
8n/a# 1. Iterate over the rows available from the cursor, unpacking the
9n/a# resulting sequences to yield their elements (name_last, age):
10n/acur.execute(SELECT)
11n/afor (name_last, age) in cur:
12n/a print('%s is %d years old.' % (name_last, age))
13n/a
14n/a# 2. Equivalently:
15n/acur.execute(SELECT)
16n/afor row in cur:
17n/a print('%s is %d years old.' % (row[0], row[1]))