5 ZPMSPOOL=${ZPMSPOOL:-/var/lib/admin/notes}
6 DB=$ZPMSPOOL/.sequence.db
7 SQL="sqlite3 -bail $DB"
12 create table sequence ( sequence text not null primary key, val integer not null default 0);
13 insert into sequence (sequence) values ('default');
17 # -c create named sequence
18 # -d delete named sequence
23 # -p prepare db, but do nothing
26 $SQL "insert into sequence (sequence) values ('${2:-default}')"
30 $SQL "delete from sequence where sequence = '${2:-default}'"
34 val=$($SQL "select val from sequence where sequence = '${2:-default}'")
39 $SQL 'select * from sequence'
43 $SQL "begin;update sequence set val = $2 where sequence = '${3:-default}'; commit;"
56 num=$(sqlite3 $DB "begin; update sequence set val = val + 1 where sequence = '$seq'; commit;select val from sequence where sequence = '$seq';")