Use file browser (Tkinter filedialog ) to browse local directory system and select the database file.
On selection of the database file, it will show all the tables inside it.
If a wrong file which is not a database file is selected then error message will be displayed.
There will be one button to create one new SQLite 3 database after browsing the local directory – file system.
We will keep all our connection and file handling code inside the file connection.py. Our main file connector-sqlit-part-1.py will import the function my_connect from connection.py.
Copy the source code below.
In next part we will display the list of available tables inside database with number of records, empty table and delete table commands.
We will also add query window to run any SQL.
my_conn = create_engine(file1)
my_conn.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
except SQLAlchemyError as e:
error = str(e.__dict__['orig'])
The main file connector-sqlit-part-1.py will import the connection.py file. On click of the Browse & Connect button, the function my_connect_p() will execute and it will first establish the connection by calling my_connect().
If the connection is established and there is no error then we will check the number of tables available inside the database.
We will enable or disable the query button b2 ( discussed in Next part ) based on connection status.