Last active
July 18, 2018 03:35
-
-
Save BlogBlocks/453817a53d4f6737f53e55fab9b25a14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| """ | |
| Gets tablename and column names from unknown database | |
| just enter database name. | |
| USAGE: | |
| import dbINFO | |
| database= "databases/history.db" | |
| #database= "databases/sat2.db" | |
| #database= "databases/ImageD.db" | |
| dbINFO.dbinfo(database) | |
| """ | |
| import sqlite3 | |
| def dbinfo(database): | |
| conn = sqlite3.connect(database) | |
| conn.text_factory = str | |
| c = conn.cursor() | |
| res = c.execute("SELECT name FROM sqlite_master WHERE type='table';") | |
| row = c.fetchone() | |
| row = str(row) | |
| row = row.replace("(","");row = row.replace(",)","") | |
| row = row.replace("'","") | |
| print row | |
| cur = c.execute("select * from \"%s\"" % row) | |
| columns = [description[0] for description in cur.description] | |
| return columns | |
| # if run directly | |
| #database = "databases/history.db" | |
| #dbinfo(database) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment