Skip to content
Advertisement

Continue executing sql statements if error found python sqlite3

I have a file containing sql commands and I want to execute the commands given in the file and if any command throws any error then ignore the error and execute the next command. Here is a sample file:

For eg. if the classroom table doesn’t exists then the drop table command will produce an error and the program will terminate. I want that the program keep running and execute all commands in the file.

The problem I’m facing is that the create table command is in multiple lines so I don’t know how to execute that.

Advertisement

Answer

Take a look at the sqlite3 manual:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement