#!/bin/bash

# Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# IBM makes no representations or warranties about the suitability of
# this program, either express or implied, including but not limited to
# the implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. 
  

# 
# 
# # Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# # IBM makes no representations or warranties about the suitability of
# # this program, either express or implied, including but not limited to
# # the implied warranties of merchantability, fitness for a particular
# # purpose, or non-infringement. 
# 
#


. $DB_DIR/util/set_db.sh

DB_USER=`${ECHO} ${DB_USER_NAME} | ${TR} "[:lower:]" "[:upper:]"`
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_utility.analyze_schema('${DB_USER}', 'DELETE');
execute dbms_utility.analyze_schema('${DB_USER}', 'ESTIMATE', NULL, 20, 'FOR TABLE FOR ALL COLUMNS FOR ALL INDEXES');
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}

