TIPS: SQLite: Python: How to get the details of a table

There are two ways you can achieve it.
cursor.execute(“PRAGMA table_info(tablename)”)
print cursor.fetchall()

sql = sqlite3.connect(self.cFile)
c = sql.cursor()
query = “select * from preferences”
col = [tuple[0] for tuple in c.description]
print col

cur.description returns a tuple of information about each table. The entire tuple is : (name, type_code, display_size, internal_size, precision, scale, null_ok)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s