dimanche 3 janvier 2016

SQLITE: stop execution if select returns specific value

Is there any way to write an SQL input file for sqlite that would somehow "throw" an error, eg. exited the transaction with rollback, if a condition isn't met?

I have a script that is supposed to do something, but only if there is a certain row in one table. If it's not there, the execution of the script might have fatal results and corrupt the db.

The script is only started on demand right now, but I would prefer to add a fail-safe which would prevent its execution in case there is some issue.

Basically what I need is something like

/* IF */ SELECT value FROM meta WHERE key = 'version' /* != hardcoded_version_string THROW SOME EXCEPTION */

Is there any way to accomplish that? In Postgre / Oracle this could be done using PLSQL but I am not sure if sqlite support any such a thing?

Aucun commentaire:

Enregistrer un commentaire