28 lines
724 B
Bash
28 lines
724 B
Bash
#!/usr/bin/env bash
|
|
openDatabase() {
|
|
[[ -f "$database" ]] || populate_db=1
|
|
rm -f "$tempdir"/sqlite.{in,out}
|
|
mkfifo "$tempdir"/sqlite.{in,out}
|
|
sqlite3 -bail -newline $'\0' \
|
|
"$database" \
|
|
< "$tempdir/sqlite.in" \
|
|
> "$tempdir/sqlite.out" &
|
|
exec 3> "$tempdir"/sqlite.in
|
|
exec 4< "$tempdir"/sqlite.out
|
|
rm "$tempdir"/sqlite.{in,out}
|
|
if (( debug > 2 ))
|
|
then
|
|
exec 5>&3
|
|
exec 3> >(tee -a "$tempdir/debug.log" >&5)
|
|
fi
|
|
(( populate_db )) && cat $schema >&3
|
|
echo '.separator ::AtOM:SQL:Sep::' >&3
|
|
echo 'PRAGMA foreign_keys = ON;' >&3
|
|
echo 'PRAGMA recursive_triggers = ON;' >&3
|
|
echo 'PRAGMA temp_store = 2;' >&3
|
|
echo 'PRAGMA locking_mode = EXCLUSIVE;' >&3
|
|
read -u4 -d $'\0'
|
|
unset REPLY
|
|
checkDatabaseVersion
|
|
}
|