Below code works for different databases i.e. MYSQL and ORACLE
The problem is for MYSQL in Block:
if [ $? -ne 0 ]
;
$?
taking value accordingly but in case of ORACLE
$?
is always taking this value as zero (0).
That is the reason in Oracle it always going in else Block in any case..
and in case of MYSQL it is working fine.....
add_fk()
{
echo "`date` Entering $0 " | tee -a $LOGFILE
if [ $DB_SYSTEM = "ORACLE" ]
then
sqlplus -s sna/dbmanager <<! | tee -a $LOGFILE
ALTER TABLE TABLE_NAME ADD CONSTRAINT CONSTRAINT_NAME_FKEY
FOREIGN KEY (LAYERRATENAME)
REFERENCES REFERENCE_TABLE(REFERENCE_TABLENAME);
exit
!
if [ $? -ne 0 ]
then
echo "Foreign Key can not be established - incompatibile data" | tee -a $LOGFILE
echo " Please verify the data in TABLE_NAME and REFERENCE_TABLE table" | tee -a $LOGFILE
status=2
else
echo "Foreign Key is Added" | tee -a $LOGFILE
fi
elif [ $DB_SYSTEM = "MYSQL" ]
then
mysql --user=${OSMDB_USR} --password=${OSMDB_PWD} ${DB_NAME} <<!
set storage_engine=INNODB;
ALTER TABLE TABLE_NAME ADD CONSTRAINT CONSTRAINT_NAME_FKEY
FOREIGN KEY (LAYERRATENAME)
REFERENCES REFERENCE_TABLE(REFERENCE_TABLENAME);
exit
!
if [ $? -ne 0 ]
then
echo "Foreign Key can not be established - incompatibile data" | tee -a $LOGFILE
echo " Please verify the data in TABLE_NAME and REFERENCE_TABLE table" | tee -a $LOGFILE
status=2
else
echo "Foreign Key is Added" | tee -a $LOGFILE
fi
fi
}
Please help me:wall:
---------- Post updated at 04:41 PM ---------- Previous update was at 04:12 PM ----------
if [ $? -ne 0 ]
Or please let me know .. what does above meant..?