When somebody ask in the mailing list on how to extract a fieldname of a particular table of SQLite, the most common answer is that theres a specification of Python DBAPI2 on cursor object which has an attribute description.
In the Python Database API Specification v2.0 particularly on the cursor object, it states that:
.description
This read-only attribute is a sequence of 7-item
sequences. Each of these sequences contains information
describing one result column: (name, type_code,
display_size, internal_size, precision, scale,
null_ok). The first two items (name and type_code) are
mandatory, the other five are optional and must be set to
None if meaningfull values are not provided.
Below is my implemention on extracting fieldnames:
[python]
from pysqlite2 import dbapi2 as sqlite
#connecting to book.db
conn = sqlite.Connection(“book.db”)
#creating a cursor for book table
cursor = conn.execute(“select * from book”)
for i in cursor.description: print i[0]
# The table fieldnames will be be then displayed. [/python]
The only limitiation of the attribute description in pysqlite is that only fieldnames is displayed. You may notice in the PEP 249 document that it is mandatory to include name and typecode. There is a documentation which explains why this incompatibility to DBAPI specification happens but we hope that it would be rectified on the later revisions.