dump-keys-sqlite3.sh: improve error checking

Check for errors when running the actual select and in the filter
command. Don't exit successfully if those fail.

Also some minor cleanups.