#!/bin/sh if [ "$DOSQLDBG" != "true" ]; then DOSQLDBG="false" DOWEB="false" fi if [ -z "$sqldbgfile" ]; then sqldbgfile="" fi if [ -z "$DOWEB" ]; then DOWEB="false" fi # Testing sqldbgfile="/tmp/sql.log" DOSQLDBG="true" $DOSQLDBG && echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >>"$sqldbgfile" $DOSQLDBG && echo "stdsqlheader: "`date` 2>&1 >>"$sqldbgfile" #--------------------------------------------------------------------- sqlid="0" . /u/catcom/catcom_vars #--------------------------------------------------------------------- dbgecho() { $DOSQLDBG && echo "$1" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" } #--------------------------------------------------------------------- sqlmy_status() { if [ "$DOWEB" = "true" ]; then my_status "$1" else echo "$1" fi } sqlmy_error() { errstr="ERROR: $1" if [ "$DOWEB" = "true" ]; then echo "$errstr" echo "
" else echo "$errstr" fi } sqlmy_exit() { if [ "$DOWEB" = "true" ]; then sqlmy_status "Done." echo "" echo "" else echo "Done." fi exit $1 } #--------------------------------------------------------------------- # taken from t21websql script # output from echo "select ...." | txsql -d catcom -h -s #recordno|distid|distiddesc|lastdist|lastdistdate|altemail|altemailyn|wbd_method|wbd_type|userid|passwd|sdate|edate| #100805|1004|Web Billing Distribution List|||||EMAIL|STANDARD|pnoble|t26VHLSkRkLeM|01/01/2004|| #102787|1000|Web Billing Distribution List|||||EMAIL|STANDARD|gbutler|t2fxgIHu87FzU|01/01/2004|| #Status:|SQLCODE~0~OK~SQLERRD~10~0~2~4~0~2~select * from wbdconf |2| dot21sql() { if [ "$DOWEB" = "true" ]; then SQLEXEC="sqlrm" LOCKFILE="/tmp/t21websql.lok" while true do #neng=`ps -e | grep "$SQLEXEC" | grep -v "grep" | wc -l` #echo "$neng sql engine(s) active
" #if [ $neng -le 1 ]; then # break; #fi if [ ! -f "$LOCKFILE" ]; then break; fi #echo " $LOCKFILE exists - sleep 5
" sleep 5 done touch $LOCKFILE txsql -d catcom -h -s rm -f $LOCKFILE else txsql -d catcom -h -s fi } #--------------------------------------------------------------------- procsql() { $DOSQLDBG && echo "procsql()" >>"$sqldbgfile" dodebug="" $DOSQLDBG && dodebug="dodebug" if [ "$1" = "dodebug" ]; then dodebug=$1 shift fi procfunc=$1 sqlinput=$2 if [ -z "$sqlinput" -o -z "$procfunc" ]; then return 1 fi sqlid=`expr $sqlid + 1` sqloutf="/tmp/sqlout$$_$sqlid" sqlerrf="/tmp/sqlerr$$_$sqlid" sqlprocf="/tmp/sqlproc$$_$sqlid" # debug if [ "$dodebug" = "dodebug" ]; then $DOWEB && echo "
" >>"$sqldbgfile" echo "procsql() sqloutf=[$sqloutf] sqlerrf=[$sqlerrf] sqlprocf=[$sqlprocf]" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" echo "sqlid=[$sqlid]" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" echo "sqlinput=[$sqlinput]" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" echo "procfunc=[$procfunc]" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" fi # Process SQL sqltype=`echo "$sqlinput" | cut -c1-20 | awk '{ print toupper($1) }'` if [ "$dodebug" = "dodebug" ]; then echo "sqltype=[$sqltype]" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" fi sqlstmnt=$sqlinput #if [ "$sqltype" = "SELECT" ]; then #else #fi rm -f $sqloutf rm -f $sqlerrf rm -f $sqlprocf echo "$sqlstmnt" | dot21sql 1>$sqloutf 2>$sqlerrf nrows=`tail -1 $sqloutf |awk -F'|' '{if(match($1,"Status:")) print $3}'` # debug if [ "$dodebug" = "dodebug" ]; then echo "sqlstmnt = $sqlstmnt" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" echo "-------- nrows = $nrows --------" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" if [ "$DOWEB" = "true" ]; then cat $sqloutf | sed -e's/$/
/' >>"$sqldbgfile" else cat $sqloutf >>"$sqldbgfile" fi echo "----------------------------------------" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" fi if [ -z "$nrows" ]; then ( $DOWEB && echo "
" echo "[$sqlstmnt]" $DOWEB && echo "
" echo "Error: " $DOWEB && echo "" cat $sqlerrf $DOWEB && echo "" $DOWEB && echo "
" if [ "$DOWEB" = "true" ]; then cat $sqloutf | sed -e's/$/
/' else cat $sqloutf fi $DOWEB && echo "
" rm -f $sqloutf rm -f $sqlerrf rm -f $sqlprocf ) | tee -a "$sqldbgfile" return 1 fi awk -F'|' -v"sqlprocf=$sqlprocf" \ -v"procfunc=$procfunc" \ -v"DOWEB=$DOWEB" \ -v"dodebug=$dodebug" \ -v"sqldbgfile=$sqldbgfile" \ -f /u/catcom/scripts/stdsqlheader.awk < "$sqloutf" echo "rm -f $sqloutf" >>$sqlprocf echo "rm -f $sqlerrf" >>$sqlprocf echo "rm -f $sqlprocf" >>$sqlprocf if [ "$dodebug" = "dodebug" ]; then echo "-------- $sqlprocf --------" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" if [ "$DOWEB" = "true" ]; then cat $sqlprocf | sed -e's/$/
/' >>"$sqldbgfile" else cat $sqlprocf >>"$sqldbgfile" fi echo "---------------------------------" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" fi . $sqlprocf rm -f $sqloutf rm -f $sqlerrf rm -f $sqlprocf $DOSQLDBG && sqlmy_status "" >>"$sqldbgfile" return 0 } #--------------------------------------------------------------------- # Examples... eg_get_grname1() { grid=$1 sqlmy_status "Finding grname1 for $grid" procsql ":" "select grname1 from groupname where grid = \"$grid\"" $DOSQLDBG && echo "nrows=$nrows" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" $DOSQLDBG && echo "grname1 = [$grname1]" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" $DOWEB && echo "
" >>"$sqldbgfile" sqlmy_status "" if [ -z "$grname1" ]; then sqlmy_error "get_grname1 - grname1 not found for grid $grid" sqlmy_exit 1 fi } egsqlupdate() { procsql ":" "update site set sitenm2=sitenm2 where siteid > 0" echo "egsqlupdate() nrows=$nrows" $DOWEB && echo "
" >>"$sqldbgfile" } #eg multi row return handler egsqlhandler() { echo "egsqlhandler() siteid=[$siteid] sitenm1=[$sitenm1]" $DOWEB && echo "
" >>"$sqldbgfile" } egsqlmulti() { procsql "egsqlhandler" "select siteid, sitenm1 from site where siteid > 0" echo "egsqlmulti() nrows=$nrows" $DOWEB && echo "
" >>"$sqldbgfile" } #---------------------------------------------------------------------