On 2015-04-01 08:29 PM, Gert Van Assche wrote: > Hi all, > > When running SQLite3 from command line, is there a way to interrupt the CMD > file when a condition is true? > > I'm importing a lot of plain text files that should all count the same > number of lines, so I want to compare the record count of all imported data > with the first file that was imported. > > I can detect this easily with a query like this: > > .import 'x.txt' T1 > .import 'y.txt' T2 > .mode list > .output importerror.txt > SELECT CASE (select count(*) from T1) WHEN (select count(*) from T2) > then 'OK' else 'Not all files contain the same number of lines' END; > > This is in an "script.sql" file and I run it by executing a batch file > (runscript.cmd). > > type script.sql | sqlite3.exe test.db > > > My question is: when the import fails (detected in the script.sql file), I > would like to stop executing the batch file (runscript.cmd). > > Is there a way to do so?
Hi Gert, I have not tested this but there is an SQLite expression called RAISE(conflict-clause, message) which will stop transaction execution - not too sure if it stops a file import in its tracks, but the test will be easy. https://www.sqlite.org/syntax/raise-function.html It is usually used inside triggers for this purpose, but I assume it will work wherever.