Re: Reading column names.

"Milo Pschigoda" <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Interesting, I think I like the cursor.description better then the
script I was using. Provided you know the table names, which is part
of what I use the script-bit for.

A little more information about the script I was using:
The sql statement is an embedded statement, the inner statement
(select * from sqlite_master) selects all the data from the
sqlite_master table, which is metadata about the database tables. The
outer statement selects from that only the table creation columns.
This is exactly the string that was used to create the tables.

--MilesP

On 1/31/07, Andy Chambers <achambers.home-gM/[email protected]> wrote:
> > Hi, I'm trying to find out how to read the column names of a given table.
> >
> > I spent about an hour googling but to no avail. Any help is appreciated!
>
> The python database api specifies this
>
> http://www.python.org/dev/peps/pep-0249/
>
> The cursor has an attribute `description' that has details about the
> types and names of columns for each query executed.  For any table
> therefore, you can do
>
>     cursor.execute("select * from table")
>     print cursor.description
>
> .. to get the information you require.
>
> Regards,
> Andy
> _______________________________________________
> pysqlite mailing list
> pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
> http://lists.initd.org/mailman/listinfo/pysqlite
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.