6 #-i insert, otherwise search
11 pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
13 while getopts f:t:a:T:i opt; do
15 f) pkgfile="$OPTARG" ;;
16 t) target="$OPTARG" ;;
17 a) action="$OPTARG" ;;
18 T) timestamp="$OPTARG" ;;
20 *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
25 if [ $op = 'insert' ]; then
27 cols='action,target,info';
28 if [ -n "$timestamp" ]; then
29 cols='ts,action,target,info'
32 printf "insert into zpmlog (%s)\n" $cols
34 if [ -n "$timestamp" ]; then
35 printf "'%s', " "$timestamp"
37 if [ -n "$action" ]; then
38 printf "'%s', " "$action"
42 if [ -n "$target" ]; then
43 printf "'%s', " "$target"
49 } | zpm shell $pkgfile
53 if [ $op = 'search' ]; then
55 printf 'select ts,action,target,info from zpmlog where\n';
56 if [ -n "$timestamp" ]; then
57 printf "ts >= '%s' and " "$timestamp"
60 if [ -n "$action" ]; then
61 printf "action = '%s' and " "$action"
63 if [ -n "$target" ]; then
64 printf "target = '%s' and " "$target"
67 } | zpm shell $pkgfile