::@SET DBVER=38
::@SET DBPRV=37
::@SET DBPRVPATH=z:\Archief\FACILITOR\2019\02\DB37\FCLT37.sql
::=============================

::DBPRV zelf bepalen
::::FOR /F "tokens=1-6 delims=\" %%I IN ("%DBPRVPATH%") DO (
::::    ::ECHO I %%I, J %%J, K %%K, L %%L, M %%M, N %%N
::::    SET DBPRVFULL=%%M
::::    SET DBPRV=%DBPRVFULL:~2%
::::)

@SET BUILD=z:\Project\FACILITOR\BUILD

@SET SOURCE=z:\Project\FACILITOR\Database\%1

@IF EXIST %DBPRVPATH% GOTO START
ECHO %DBPRVPATH% niet gevonden | cscript emailerror.js %DBVER% %mailall% >> %0.log 2>>&1
ECHO %DBPRVPATH% niet gevonden
PAUSE
GOTO EINDE

:START
@echo off
REM Usage: %0 [mailall]
SET mailall=%2

SET OUTPUT=%BUILD%\DB%DBVER%\TEST_OUTPUT
MKDIR %OUTPUT%>nul
MKDIR %OUTPUT%\OLD>nul
DEL %OUTPUT%\OLD\*.LST
MOVE %OUTPUT%\*.lst %OUTPUT%\OLD

PUSHD %SOURCE%
CALL mx NOWAIT
POPD
:START0
IF EXIST %BUILD%\DB%DBVER%\FCLT%DBVER%.sql GOTO STARTCREA
ECHO %BUILD%\DB%DBVER%\FCLT%DBVER%.sql niet gevonden
PAUSE
GOTO EINDE
:STARTCREA

ECHO ==========================================================================================================>diffwork_%DBVER%.lst
ECHO Comparescript %0>>diffwork_%DBVER%.lst
ECHO Creates databases users TEST_DB%DBVER% and TEST_DB%DBPRV%TO%DBVER% and compares them>>diffwork_%DBVER%.lst
ECHO (password is the same as username in uppercase)>>diffwork_%DBVER%.lst
ECHO ==========================================================================================================>>diffwork_%DBVER%.lst
ECHO.>>diffwork_%DBVER%.lst

ECHO Starting Create DB%DBVER% test
ECHO Starting Create DB%DBVER% test>>diffwork_%DBVER%.lst
CALL _CREA_WORK %DBVER% z:\Project\FACILITOR\BUILD>>diffwork_%DBVER%.lst

ECHO Starting Update %DBPRV%to%DBVER% test
ECHO Starting Update %DBPRV%to%DBVER% test>>diffwork_%DBVER%.lst
CALL _CREA_WORK_UPDATE %DBPRV% %DBPRVPATH% %DBVER% z:\Project\FACILITOR\BUILD>>diffwork_%DBVER%.lst

ECHO %time:~,8% Starting Compare
ECHO Starting Compare>>diffwork_%DBVER%.lst
cscript compare.js %DBPRV% %DBVER% >>diffwork_%DBVER%.lst 2>>&1
ECHO %time:~,8% Done Compare

findstr /i "ORA-" "diffwork_%DBVER%.lst"
if %errorlevel%==1 GOTO EINDE

findstr /C:"ORA-" /C:"PLS-" "diffwork_%DBVER%.lst" | cscript emailerror.js %DBVER% %mailall% >> %0.log 2>>&1
@TITLE ORA-Errors found, e-mail sent
::PAUSE

:EINDE

move *.lst %OUTPUT%