3 #==============================================================================
5 # File ID: d6a111fc-6a8c-11e5-b795-fefdb24f8e10
7 # Edit an SQLite database in your favourite text editor.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
20 while test -n "$1"; do
22 -h|
--help) opt_help
=1; shift ;;
23 -n|
--dry-run) opt_dry_run
=1; shift ;;
24 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
25 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
26 --version) echo $progname $VERSION; exit 0 ;;
29 if printf '%s\n' "$1" |
grep -q ^
-; then
30 echo "$progname: $1: Unknown option" >&2
38 opt_verbose
=$
(($opt_verbose - $opt_quiet))
40 if test "$opt_help" = "1"; then
41 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
44 Edit an SQLite 3.x database file in your favourite text editor. The
45 original version is backuped with the current UTC time stamp and process
48 Usage: $progname [options] sqlite_database_file
55 Simulate what would happen.
57 Be more quiet. Can be repeated to increase silence.
59 Increase level of verbosity. Can be repeated.
61 Print version information.
71 echo $progname: No SQLite database specified
>&2
75 echo $progname: $db: File is a symlink
>&2
79 echo $progname: $db: File not found or is not a regular
file >&2
83 echo $progname: $db: File is not readable by you
>&2
87 echo $progname: $db: File is not writable by you
>&2
90 test -n "$EDITOR" ||
{
91 echo $progname: \
$EDITOR environment variable is not defined
>&2
94 sqlite3
"$db" "PRAGMA integrity_check;" ||
{
95 echo $progname: $db: SQLite database contains errors
>&2
99 bck
="$db.$(date -u +"%Y
%m
%dT
%H
%M
%SZ
")-$$.bck"
101 if test "$opt_dry_run" = "1"; then
102 echo $progname: $db: File would be edited
>&2
105 test -e "$sql" ||
# Don't overwrite an existing file
106 sqlite3
"$db" .dump
>"$sql"
109 cp -p "$db" "$bck" ||
{
110 echo $progname: $db: Error when creating backup
$bck
115 until test "$sqlite_ok" = "1"; do
118 sqlite3
"$db" <"$sql" && sqlite_ok
=1 ||
{
120 echo -n "$progname: Press Enter to edit again, " >&2
121 echo -n or q to abort...
>&2
124 test "$choice" = "q" && exit
129 sqlite3
"$db" <"$sql"
132 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :