#!/usr/local/bin/bash

prefix=/usr/local
exec_prefix=${prefix}
bindir=${exec_prefix}/bin

if [ "$1" == "" ]; then
				echo Usage $0 var -f file -v value --get --like
	exit 1
fi;

doit=1
get=0
like=0
var=$1
shift

while [ "$1" ]; do
	case "$1" in
		-f)	shift
			file=$1;;
		-v)	shift
			val=$1;;
		-g) get=1;;
		--get) get=1;;
		-l) like=1;;
		--like) like=1;;
		*)	echo unknown parameter $1 ;;
	esac;
	shift;
done;

if [ "$var" == "" ]; then
	echo var is empty
fi;

where="1"

if [ "$file" != "" ]; then
				where="$where and file='$file'"
fi;

if [ "$var" != "" ]; then
	if [ $like == 1 ]; then
		where="$where and var LIKE '$var'"
	else
		where="$where and var='$var'"
	fi
fi;

squery="SELECT * FROM SetupList WHERE $where";
uquery="UPDATE SetupList SET val='$val' WHERE $where";

echo $VERLIHUB_CFG

if [ $get == 1 ]; then
	$bindir/vh_getdb --query "$squery"
else
	if [ $doit == 1 ]; then
		$bindir/vh_getdb --query "$uquery"
	else
		$bindir/vh_getdb --printquery "$uquery"
	fi
fi

