Created
September 14, 2018 15:25
Star
You must be signed in to star a gist
SQLite application_id signed/unsigned integer range test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sqlite3 --version | |
3.11.0 2016-02-15 17:29:24 3d862f207e3adc00f78066799ac5a8c282430a5f | |
application_id: 0 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: 3 | |
SQLite says: 3 | |
file(1) says: SQLite 3.x database, application id 3 | |
raw bytes are: 0x00, 0x00, 0x00, 0x03 | |
application_id: 2147483647 | |
SQLite says: 2147483647 | |
file(1) says: SQLite 3.x database, application id 2147483647 | |
raw bytes are: 0x7f, 0xff, 0xff, 0xff | |
application_id: 2147483648 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: 2147483649 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: 4294967295 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: 4294967296 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: 4294967297 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: -2147483648 | |
SQLite says: -2147483648 | |
file(1) says: SQLite 3.x database, application id 2147483648 | |
raw bytes are: 0x80, 0x00, 0x00, 0x00 | |
application_id: -2147483647 | |
SQLite says: -2147483647 | |
file(1) says: SQLite 3.x database, application id 2147483649 | |
raw bytes are: 0x80, 0x00, 0x00, 0x01 | |
application_id: -3 | |
SQLite says: -3 | |
file(1) says: SQLite 3.x database, application id 4294967293 | |
raw bytes are: 0xff, 0xff, 0xff, 0xfd | |
application_id: -2147483649 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: -4294967295 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 | |
application_id: -4294967296 | |
SQLite says: 0 | |
file(1) says: SQLite 3.x database | |
raw bytes are: 0x00, 0x00, 0x00, 0x00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
printf '$ %s\n' 'sqlite3 --version' | |
sqlite3 --version | |
tmpdir="$(mktemp -d)" | |
tmpfile="${tmpdir}/test.db" | |
run() { | |
printf '\n' | |
rm -f "${tmpfile}" | |
printf 'application_id: %s\n' "$1" | |
printf 'SQLite says: ' | |
printf ' | |
PRAGMA application_id = 777; | |
PRAGMA application_id = %s; | |
PRAGMA application_id; | |
' "$1" | sqlite3 "${tmpfile}" | |
printf 'file(1) says: ' | |
file -b "${tmpfile}" | |
printf 'raw bytes are: ' | |
xxd -i -s 68 -l 4 <"${tmpfile}" | |
} | |
# Values between 0 and 2^31 - 1, inclusive, work fine. | |
run 0 | |
run 3 | |
run 2147483647 | |
# Values larger than 2^31 - 1 are treated as zero. | |
run 2147483648 | |
run 2147483649 | |
run 4294967295 | |
run 4294967296 | |
run 4294967297 | |
# Values between -2^31 and -1, inclusive, are treated inconsistently | |
# between SQLite and file(1). | |
run -2147483648 | |
run -2147483647 | |
run -3 | |
# Values smaller than -2^31 are treated as zero. | |
run -2147483649 | |
run -4294967295 | |
run -4294967296 | |
rm "${tmpfile}" | |
rmdir "${tmpdir}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment