How to print contents of any database file



  1 import sqlite3 as lite
  2 import sys
  3
  4 def print_db_content(database_to_read):
  5         conn = lite.connect(database_to_read);
  6         cur = conn.cursor()
  7         # http://stackoverflow.com/questions/305378/list-of-tables-db-schema-dump-etc-using-the-python-sqlite3-api
  8         # Below query is equivalent to typing .tables in sqlite command line
  9         query = "SELECT name from sqlite_master where type = 'table'"
 10         tables_list = list(cur.execute(query))
 11         print tables_list
 12         for item in tables_list:
 13                 query = "SELECT * from '" + str(item[0]) + "'"
 14                 print query
 15                 cur = conn.cursor()
 16                 data = list(cur.execute(query))
 17                 for item1 in data:
 18                         print item1

 if __name__ == "__main__":
         if (len(sys.argv)<0):
                 print 'Usage: python print_content_of_database.py [database_absolute_path]'               
         else:
                 database=sys.argv[1]
                 print_db_content(database)

Comments

Popular posts from this blog

SOX - Sound eXchange - How to use SOX for audio processing tasks in research.

How to get video or audio duration of a file using ffmpeg?

Sox of Silence - Original post - http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/