On Wed, Sep 18, 2019 at 6:43 PM Clemens Ladisch <clem...@ladisch.de> wrote:

> Peng Yu wrote:
> > Is there a better way to just return an exit status of 0 for
> > a sqlite3 DB file and 1 otherwise?
>
> Extract the magic header string from a known DB file:
>
>   dd bs=16 count=1 < some.db > sqlite3-signature
>
> Then you can compare it against the beginning of the file:
>
>   cmp --bytes=16 sqlite3-signature /tmp/tmp.erZ5aS6PUX.sqa > /dev/null
>   [ $? = 0 ] && echo SQLite DB


I'm actually surprised sqlite3[.exe] itself doesn't have a more to do that.
I tried using it to open a non-DB file, and it opens in interactive mode,
with
no error or warning, wether I use -bail or not. I was expecting a hard
error.

You'd think sqlite3[.exe] is the best suited to figure out if a file is a
valie SQLite database or not,
and exit with a non-zero status if it's not (possibly using a given CLI arg
for that behavior). That
would be a useful addition, if it's not already possible in a way I can't
find. Parsing the 100 bytes
header would do and be super fast. --DD
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to