May 2019
Intermediate to advanced
542 pages
13h 37m
English
Once our connection is actually connected, we can use it to start inspecting the database. For example, the tables() method lists all tables in the database. We can use this to check that all required tables are present as follows, for example:
required_tables = {'roasts', 'coffees', 'reviews'} tables = self.db.tables() missing_tables = required_tables - set(tables) if missing_tables: qtw.QMessageBox.critica( None, 'DB Integrity Error' 'Missing tables, please repair DB: ' f'{missing_tables}') sys.exit(1)
Here, we compare the tables that exist in the database to a set of the required tables. If we find any missing, we'll show an error and exit.
Read now
Unlock full access