call ..\shared\SetVariables.cmd
@echo off
rem this command will logon to a database based on the AIRGROUP_DEPLOY_TYPE
rem using the userid and password defined in uid and pwd
rem 
rem -----------------------------------------------------------------
rem     Define script variables. 
rem     Path where the SQL script lives
set inpath=%CD%
rem     Name of the script. Script must end with the word Quit to exit the SQLPlus processor
set SQLInput1=83_Backup_PURGE_TABLES.sql
set SQLInput2=84_Truncate_EIM_ACRL_NOTE_TABLES.sql
set SQLInput3=85_Delete_EIM_LOY_TXN.sql
rem     Logfile name will also be the folder name under mileageplan
set logname=1_Cleanup_checks
set uid=%SOLAR_SIEBEL_PURGE_UID%
set upw=%SOLAR_SIEBEL_PURGE_PWD%

set suid=%SOLAR_SIEBEL_UID%
set supw=%SOLAR_SIEBEL_PWD%
rem -----------------------------------------------------------------
rem 
rem Get current date and time and append to logfile name
rem
for /F "tokens=2-4 delims=/ " %%v in ('date /T') do (set cdate=%%x%%v%%w)
for /F "tokens=1-3 delims=:." %%v in ('echo %time%') do (set ctime=%%v%%w%%x)
rem
rem
set logpath=%AIRGROUP_LOG_ROOT%\MileagePlan\TransactionPurge\%logname%
rem
if not exist %logpath%\*.* md %logpath%
rem
set logfile=%logpath%\%logname%-%cdate%%ctime%.log
rem 
rem
echo **** Begin process **** >%logfile%
if exist %inpath%\%SQLInput1% goto NextSQL-1
echo *** Cannot find SQL input file1 >>%logfile%
goto ErrorExit
:NextSQL-1
if exist %inpath%\%SQLInput2% goto NextSQL-2
echo *** Cannot find SQL input file2 >>%logfile%
goto ErrorExit
:NextSQL-2
if exist %inpath%\%SQLInput3% goto SetConnect
echo *** Cannot find SQL input file3 >>%logfile%
goto ErrorExit

:SetConnect
CALL ..\shared\Solar_Connect.cmd %logfile%
if not "%errorlevel%"=="0" goto ErrorExit
rem
:Startsql
rem
sqlplus -L %Uid%/%upw%@%DBConnect% @%inpath%\%SQLInput1% >>%logfile%
if not "%errorlevel%"=="0" goto ErrorExit
echo **** Process Complete **** >>%logfile%

sqlplus -L %sUid%/%supw%@%DBConnect% @%inpath%\%SQLInput2% >>%logfile%
if not "%errorlevel%"=="0" goto ErrorExit
echo **** Process Complete **** >>%logfile%

sqlplus -L %Uid%/%upw%@%DBConnect% @%inpath%\%SQLInput3% >>%logfile%
if not "%errorlevel%"=="0" goto ErrorExit
echo **** Process Complete **** >>%logfile%

goto exit
rem
:ErrorExit
echo **** Processing error **** >>%logfile%
echo **** Processing error ****
:EXIT


