#*****************************************************************
#
# Name:Command line prototype of wxpython date entry from.
#
# Source: Self
#
# URL:Self
#
# Date: 2019-01-25 16:02:32
#*****************************************************************
import sys
import os
import sqlite3
from sqlite3 import Error

def main():
    print sys.argv[1]
    db_file = sys.argv[1]
    return db_file

def create_connection(db_file):
    """ create a database connection to a SQLite database """
    choice = 0
    tablenames = []
    foreignkeyexist = "PRAGMA foreign_key_list"
    foreignkeyon = "PRAGMA foreign_key = 'ON'"
    try:
        conn = sqlite3.connect(db_file)
        c = conn.cursor()
        conn.text_factory = bytes
        c.execute(foreignkeyon)
        print(sqlite3.version)
        row = c.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
        print(type(row))
        for line in row:
            choice +=1
            print(str(choice) + ")" + " " + line[0])
            tablenames += [line[0]]
        print(tablenames)
        tablechoice = raw_input("Enter the number of the table that you want to edit  ")
        tableindex = int(tablechoice)
        chosentable = tablenames[tableindex-1]
        print chosentable
        tablestmt = "PRAGMA table_info(" + chosentable + ")"
        tablecolumns = c.execute(tablestmt )
        for index in tablecolumns:
            if  not index[5]:
                if "BLOB" not in index[2]:
                        print index

# get the tables in the database
# `SELECT name FROM sqlite_master WHERE type = "table"`
# First string in a sqlite database file. This identifys the file
# as a sqlite database file "SQLite format 3"       
    except Error as e:
        print(e)
    finally:
        conn.close()
 
if __name__ == '__main__':
    filename = main()
    create_connection(filename)