Re: How can one detect which tables are in a database?

"Milo Pschigoda" <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
I forget where I picked up this script, but it's part of my standard
module for pysqlite programs now:

#! /usr/bin/python

from pysqlite2 import dbapi2 as sqlite

def metadata(dbf):
    """Connects to a database file given in paramater and prints out
table creation strings."""
    con=sqlite.connect(dbf)
    cur=con.cursor()

    sc="select sql from (select * from sqlite_master ) where
type!='meta' order by t
    bl_name, type DESC, name"
    cur.execute(sc)
    d=cur.fetchone()
    while(d):
        print(d)
        d=cur.fetchone()


On 9/17/06, Charles D Hixson <[email protected]> wrote:
> In Postgresql I could do:
> def   listTables(conn):
>    """   given a database connection, list the tables included in that
> database  """
>    sql   =  \
>       """select c.relname FROM pg_catalog.pg_class c
>          LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
>          WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog',
> 'pg_toast')
>          AND pg_catalog.pg_table_is_visible(c.oid);
>       """
>    cur   =  conn.cursor()
>    cur.execute(sql)
>    tables   =  cur.fetchall()
>    return   list( (tbl[0]  for   tbl   in tables) )
>
> but this is dependent upon various features of Postgresql.  Still, it
> shows the kind of function I'm after.  Any suggestions?  Any references?
>
> _______________________________________________
> 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.