daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 113 in 6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #*****************************************************************
  2. #
  3. # Name:
  4. #
  5. # Source:
  6. #
  7. # URL:
  8. #
  9. # Date:
  10. #*****************************************************************
  11. import sys
  12. import os
  13. import sqlite3
  14. from sqlite3 import Error
  15.  
  16. def main():
  17.     print sys.argv[1]
  18.     db_file = sys.argv[1]
  19.     return db_file
  20.  
  21. def create_connection(db_file):
  22.     """ create a database connection to a SQLite database """
  23.     choice = 0
  24.     tablenames = []
  25.     try:
  26.         conn = sqlite3.connect(db_file)
  27.         c = conn.cursor()
  28.         print(sqlite3.version)
  29.         row = c.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
  30.         print(type(row))
  31.         for line in row:
  32.             choice +=1
  33.             print(str(choice) + ")" + " " + line[0])
  34.             tablenames += [line[0]]
  35.         print(tablenames)
  36.         tablechoice = raw_input("Enter the number of the table that you want to edit  ")
  37.         tableindex = int(tablechoice)
  38.         chosentable = tablenames[tableindex-1]
  39.         print chosentable
  40.         tablestmt = "PRAGMA table_info(" + chosentable + ")"
  41.         tablecolumns = c.execute(tablestmt )
  42.         for index in tablecolumns:
  43.             print index
  44.  
  45. # get the tables in the database
  46. # `SELECT name FROM sqlite_master WHERE type = "table"`
  47. # First string in a sqlite database file. This identifys the file
  48. # as a sqlite database file "SQLite format 3"      
  49.     except Error as e:
  50.         print(e)
  51.     finally:
  52.         conn.close()
  53.  
  54. if __name__ == '__main__':
  55.     filename = main()
  56.     create_connection(filename)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top