#! /bin/bash


usage() {
    echo "addStructColumn.sh -c <champ> -t <type>"
}

while true
do
  case $1 in
    -c) champ="$2"
        shift 2
        ;;
    -t) type="$2"
            if [ -z "$type" ]
            then
                          shift 1
            else
                          shift 2
            fi
        ;;
    -h) usage
            exit 0
        ;;
     *)
        break
        ;;
  esac
done

if [ ! -z "$champ" ]
then
    if [ ! -z "$type" ]
    then
	listeT=`psql -U pimengest pimengest -c "select champ from structtable" -t`
	for i in ${listeT}
	do
	    echo $i" "$champ" "$type | awk '{print "alter table struct"$1" add column "$2" "$3";"}'
	done
    else 
	usage
    fi
fi

