mardi 21 juillet 2015

SQLite - Check table format on CREATE and drop if needed

Say I need a table that has to have two columns (A TEXT, B TEXT). Every time before I run a program, I want to check if the table exists, and create it if it doesn't. Now say that the table with that name exists already, but has only one column (A TEXT), or maybe (A INT, B INT)

So in general, different columns. How do I check that on CREATE query? And if there's a conflict back it up somewhere and drop, then create a new correct table. If there's no conflict - don't do anything.

I am working in Python, using sqlite3 by the way. Database is stored locally for now and program is distributed to multiple people, that's why I need to check the database.

Aucun commentaire:

Enregistrer un commentaire