Permalink
Browse files

add category_list

  • Loading branch information...
1 parent 8b777f3 commit 9d5987172d6a76c04c19f2440a73932018602d9a @falconindy committed Jul 2, 2010
Showing with 14 additions and 3 deletions.
  1. +14 −3 clockwerk
View
@@ -89,6 +89,8 @@ lock_release() {
# return 2 on sql error
job_start() {
lock_acquire || return 1
+ local ret=$?
+ [[ $ret -eq 1 ]]
local jobstart=$(date +%s) category=$1 comment=$2
@@ -147,11 +149,11 @@ seconds_to_hms() {
# return 1 on category exists
# return 2 on sql error
category_add() {
- sql="INSERT INTO category(c_name, c_desc) VALUES('$1', '$2');"
+ local sql="INSERT INTO category(c_name, c_desc) VALUES('$1', '$2');"
local result=$(exec_query "$sql" 2>&1)
[[ $result = "Error: column c_name is not unique" ]] && return 1
- [[ $result =~ ^Error* ]] && return 2
+ [[ $result =~ ^Error:* ]] && return 2
return 0
}
@@ -160,6 +162,14 @@ category_del() {
:
}
+category_list() {
+ local sql="SELECT c_name, c_desc FROM category"
+
+ while IFS=$'|' read c_name c_desc; do
+ printf "%-20s%-20s\n" "$c_name" "$c_desc"
+ done < <(exec_query "$sql")
+}
+
do_job() {
local action=$1; shift
@@ -182,14 +192,15 @@ do_category() {
case $action in
"add") category_add "$@" ;;
+ "list") category_list ;;
*) die "Not implemented" ;;
esac
}
do_report() {
local action=$1; shift
-
+ die "Not implemented"
}
#sanity checks

0 comments on commit 9d59871

Please sign in to comment.