pysqlite - Checking the existance of a table

Cousin Stanley CousinStanley at HotMail.Com
Sat Jun 18 09:17:25 EDT 2005


| I am starting to play with pysqlite,
| and would like to know if there is a function
| to determine if a table exists or not.

rh0dium ....

   One way to get at a list of table names
   in an SQLite data base is to query
   the  sqlite_master  table ....


import sys
import sqlite

this_db  = sys.argv[ 1 ]

list_sql = [ "select tbl_name" ,
              "from   sqlite_master" ]

str_sql  = '\n'.join( list_sql )

dbc      = sqlite.connect( db = "%s" % this_db )

curs     = dbc.cursor()

curs.execute( str_sql )

list_tables = curs.fetchall()

print '\n    Table Names in SQLite DB .... %s \n' % ( this_db )

for table_name in list_tables :

     print "        %s " % ( table_name )

print

dbc.close()


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list