#!/bin/sh
CDBS_TOP=${CDBS_TOP:-/data/cdbs1/tools/}
export CDBS_TOP

. ${CDBS_TOP}/util/defines.sh
export DSQUERY

echo "starting run_cdbs_sql"
echo "database " ${CDBS_DB?"CDBS_ERROR: CDBS_DB is undefined"}
echo "server " ${CDBS_SERVER?"CDBS_ERROR: CDBS_SERVER is undefined"}
date

dir=`pwd`
if test $# -lt 1
then
echo "usage: run_cdbs_sql input_file_name"
exit
fi
isql -Ucalwrite -ne < $1  > $1.out
if [ `grep '^Msg' $1.out | wc -l` -gt 0 -o `grep -i "CDBS ERROR" $1.out | wc -l` -gt 0 ]
then
   echo "possible errors in processing sql file $1"
   echo "see output file $1.out"
   exit 1
else
   echo "No errors in processing sql file $1. Created output file $1.out."
   exit 0
fi


