Re: Reading column names.

"Colin Barnette" <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Thanks for the speedy response Milo! However I was wondering if you
could expand on your sql statement. For instance, can I select the
columns from just one table? Perhaps if you could just break it down a
bit for explanation that would really be appreciated.

-Colin Barnette

On 1/31/07, Milo Pschigoda <[email protected]> wrote:
> I don't remember where I got this script, but it does the job for me.
> It is more for a human viewer, but I'm sure a little text manipulation
> would get the column names into variables
>
> --MilesP
>
> #! /usr/bin/python
>
> from pysqlite2 import dbapi2 as sqlite
> con=sqlite.connect("db.databasename")
> cur=con.cursor()
>
> sc="select sql from (select * from sqlite_master ) where type!='meta'
> order by tbl_name, type DESC, name"
> cur.execute(sc)
> d=cur.fetchone()
> while(d):
>  print(d)
>   d=cur.fetchone()
>
>
> On 1/30/07, Colin Barnette <[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!
> >
> > Thanks,
> >
> > Colin Barnette
> > _______________________________________________
> > pysqlite mailing list
> > pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
> > http://lists.initd.org/mailman/listinfo/pysqlite
> >
> _______________________________________________
> 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.