Skip to content

Instantly share code, notes, and snippets.

@chapinb
Created January 8, 2015 17:13
Show Gist options
  • Save chapinb/68a09b9bf4c5c7ccf197 to your computer and use it in GitHub Desktop.
Save chapinb/68a09b9bf4c5c7ccf197 to your computer and use it in GitHub Desktop.
def get_sqlite_veiw_info(db_path):
"""
Read all SQLite table names
:param db_path: String path to database
:return: List of table names
"""
# TODO: Add ability to filter responsive table names
con = sqlite3.connect(db_path)
cur = con.cursor()
cur.execute('Select name, sql from sqlite_master where type = \'view\';')
# convert tuples to lists
tmp = cur.fetchall()
tmp2 = []
tmp3 = dict()
for i in tmp:
for x in i:
tmp3['name'] = x[0]
tmp3['sql'] = x[1]
tmp2.append(tmp3)
return tmp2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment