# IBM Confidential
# OCO Source Materials
# 5724-V51
#
# (c) Copyright IBM Corp. 2000, 2008 All Rights Reserved.
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.

#!      /bin/sh

#	Copyright 2007, IBM Corporation

#      dopurgesrcitems.sh - Purge the source items indicated by a source catalog in a CET_BADBLOB table

#

# Usage of the file
if [[ $# -ne 5 ]]
then
 echo "Usage "
 echo "dopurgesrcitems.sh --db=databasename --dbuser=dbusername --dbpassword=dbuserpassword --srcCtgId=srcctgid --outfile=filename"
 echo " "
 echo "Example dopurgesrcitems.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --srcCtgId=6 --outfile=foo.txt"
 
 exit 0
fi

# Declare the variables
DBName=`echo $1 |cut -d "=" -f2`;export DBName
DBUSER=`echo $2 |cut -d "=" -f2`;export DBUSER
DBUserPassword=`echo $3 |cut -d "=" -f2`;export DBUserPassword
SrcCtgId=`echo $4 |cut -d "=" -f2`;export SrcCtgId
Outfile=`echo $5 |cut -d "=" -f2`;export Outfile

PurgeFile="${SrcCtgId}-{`date |awk '{print "purgereport_item_ca_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`-.txt";export PurgeFile

sed s/"srcCtgId"/"${SrcCtgId}"/ $TOP/src/integrity/SQL/oracle/purge_src_items.sql > purge_scratch.sql

sqlplus -s ${DBUSER}/${DBUserPassword}@${DBName} <<EOF
--set heading off
--set line 100000
--set wrap off
--set newpage NONE
@$TOP/src/integrity/SQL/oracle/procs
spool temppurge.txt;
@purge_scratch
spool off;
EOF

mv temppurge.txt ${Outfile}
rm purge_scratch.sql

exit $?

