Skip to content

Instantly share code, notes, and snippets.

@shepting
Created January 27, 2011 21:13
Show Gist options
  • Save shepting/799284 to your computer and use it in GitHub Desktop.
Save shepting/799284 to your computer and use it in GitHub Desktop.
Prints out all table and column names for an SQLite db
import sqlite3
import sys
try:
FILENAME = sys.argv[1]
except IndexError:
print "You must pass in a valid sqlite db."
sys.exit(1)
print FILENAME
conn = sqlite3.connect(FILENAME)
c1 = conn.cursor()
c2 = conn.cursor()
for table in c1.execute("SELECT name FROM sqlite_master WHERE type='table' order by name;"):
print "\n%s" % table[0]
c2.execute('SELECT * FROM %s' % table[0])
for column in [x[0] for x in c2.description]:
print " %s" % column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment