Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created September 14, 2018 15:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wchargin/ac2a339f002a9604018bbc3b3be59ffb to your computer and use it in GitHub Desktop.
SQLite application_id signed/unsigned integer range test case
$ 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
#!/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