Created
January 27, 2011 21:13
-
-
Save shepting/799284 to your computer and use it in GitHub Desktop.
Prints out all table and column names for an SQLite db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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