#!/bin/bash
# Licensed Materials - Property of IBM
# 5724-I68
#
# © Copyright IBM Corp. 2000, 2007
#
# US Government Users Restricted Rights - Use, duplication, or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

. $DB_DIR/util/set_db.sh

#DB_USER=`${ECHO} ${DB_USER_NAME} | ${TR} "[:lower:]" "[:upper:]"`
DB_USER=`${ECHO} ${DB_USER_NAME} | ${TR} "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"`
START_TIME=`date`


if [ "$CCD_DB" = "oracle" ]; then

${ECHO} "******************************************************************************"
${ECHO} "Running analyze schema on the schema ${DB_USER}"
${ECHO} "System is going to run two commands."
${ECHO} "It could take some time to run the second command. Do not kill the session."
${ECHO} "******************************************************************************"

STATEMENT=`cat <<EOF
execute dbms_stats.gather_schema_stats(NULL,estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO', DEGREE => 2, cascade => TRUE);
EOF`

${ECHO} "---------------------"
${ECHO} "executing:"
${ECHO} "$STATEMENT"
${ECHO} "---------------------"

${CCD_SQLPLUS} ${CONNECTION} <<EOF
$STATEMENT
EOF


elif [ "$CCD_DB" = "db2" ]; then

${ECHO} "******************************************************************************"
${ECHO} "Running REORGCHK and collecting statistics on the schema ${DB_USER}"
${ECHO} "It could take some time to run the command. Do not kill the session."
${ECHO} "******************************************************************************"

STATEMENT="reorgchk update statistics on schema ${DB_USER}"
${ECHO} "---------------------"
${ECHO} "executing:"
${ECHO} "$STATEMENT"
${ECHO} "---------------------"
. ${DB_DIR}/util/run_db_cmd.sh --var=$STATEMENT --disconnect=yes

else  
      ${ECHO} "Error! Database Environment has not been set."  
      exit 
fi


END_TIME=`date` 
${ECHO} 
${ECHO} =====================================================
${ECHO}   Completed Updating Statistics for $DB_USER
${ECHO}   Start Time : $START_TIME 
${ECHO}   End Time   : $END_TIME
${ECHO} =====================================================
${ECHO}

