Using metadata
On February 23, 2006, an American B-2 bomber crashed shortly after take-off in Guam due to bad data being fed to the airplane's flight control computers. A lack of data checking resulted in the loss of a $2.1 billion plane. As with any user interaction in programming, it is foolish to trust data without validating its integrity first.
One of the main ways of validating user input is to verify the data definition for the database. More often than not, the database definition will be known at the time of application development. You can then verify user input against a known specification. However, if you do not have this luxury, you will need to query the database for its definition and ensure the user's data does not run afoul of it.
Querying the database for its structure
If we are completely ignorant of a database's structure, we need to first retrieve a table listing. To affect that, we use SHOW TABLES
.
statement = """SHOW TABLES""" command = cur.execute(statement)
Be sure to...