annotate Doc/lib/sqlite3/execsql_fetchonerow.py @ 40354:320dfdee8968 legacy-trunk

Patch #1472877: Fix Tix subwidget name resolution. Will backport to 2.5.
author Martin v. Löwis <martin@v.loewis.de>
date Sat, 18 Nov 2006 18:42:11 +0000
parents 204ec383b445
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
1 import sqlite3
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
3 con = sqlite3.connect("mydb")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
4
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
5 cur = con.cursor()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
6 SELECT = "select name_last, age from people order by age, name_last"
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
7
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
8 # 1. Iterate over the rows available from the cursor, unpacking the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
9 # resulting sequences to yield their elements (name_last, age):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
10 cur.execute(SELECT)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
11 for (name_last, age) in cur:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
12 print '%s is %d years old.' % (name_last, age)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
13
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
14 # 2. Equivalently:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
15 cur.execute(SELECT)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
16 for row in cur:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38069
diff changeset
17 print '%s is %d years old.' % (row[0], row[1])