@goto INITIALIZE
:BEGIN
if "%~0"=="LISTS_DOWNLOADING.cmd" set is_nested_call$$$$=1
call $SQLTRANS "(SettingsOnly)"
if !errorlevel! neq 0 goto ERROR

if !is_nested_call$$$$!==1 goto START
cls
echo LISTS DOWNLOADING (DATABASES AND PROCESSES):
echo ίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίίί
echo.
echo ώ SQL-server  : !$sql_server!
echo ώ SQL-database: !$sql_database!
echo.
echo ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ
echo ΝΝ STARTING THE SCRIPT(S) ON SQL-SERVER: ΝΝΝ (TRANSLATION CONFIRMATION) ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ
echo.
call $CONFIRMPAUSE.cmd
if !errorlevel! neq 0 goto ERROR

:START
call :DELETE_FILES "*.csv"
if !errorlevel! neq 0 goto FAILURE

echo.
echo ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ

rem set SqlToCsvExport.InsertColHeaders=0
rem set SqlToCsvExport.InsertRecNoColumn=0
rem set SqlToCsvExport.ColSepChar=^|
rem set SqlToCsvExport.EmbraceAllWithQuotes=0
rem set SqlToCsvExport.IncorrectCharSubst=
rem set SqlToCsvExport.RecNoCaption=R/N
rem set SqlToCsvExport.SuppressAlienLetters=0
rem set SqlToCsvExport.ExportInUTF8=0

echo.
echo *** DOWNLOADING DATABASE LIST: ***
call $SQLTOCSVEXP.cmd "!$sql_server!" "!$sql_database!" "Download_DB_list"
if !errorlevel! neq 0 goto FAILURE
echo.
echo *** DOWNLOADING PROCESS LIST: ***
call $SQLTOCSVEXP.cmd "!$sql_server!" "!$sql_database!" "Download_process_list"
if !errorlevel! neq 0 goto FAILURE

:SUCCESS
if !is_nested_call$$$$!==1 goto FINISH
echo.
echo ΝΝ LISTS DOWNLOADING ΔΔ SUCCESS ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ
echo ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ
goto FINISH

:FAILURE
if !is_nested_call$$$$!==1 goto ERROR
echo.
echo ΝΝ ## LISTS DOWNLOADING ΔΔ FAILURE ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ
echo ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ
goto ERROR

::==================================================================================================

:DELETE_FILES
call :RESET_ERROR
if not exist "%~1" goto :EOF
echo.
echo * Deleting files: "%~1" ...
del /q "%~1"
if not exist "%~1" goto :EOF
goto :RETURN_ERROR

::==================================================================================================
:INITIALIZE
@echo off
call :SET_ERROR
setlocal enableextensions disabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING
set DP0$$=%~dp0
set P1$$=%~1
set P2$$=%~2
set P3$$=%~3
set P4$$=%~4
set P5$$=%~5
set P6$$=%~6
set P7$$=%~7
set P8$$=%~8
set P9$$=%~9
call :SET_ERROR
setlocal enableextensions enabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_EXTENDED_CMD_PROCESSING
set is_nested_call$$$$=0
set initial_cd$$$$=!CD!
goto BEGIN
::==================================================================================================
:CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING
echo.
echo ## Can not switch on simple command processing (without delayed expansion).
goto TERMINATED
:CANT_SWITCH_ON_EXTENDED_CMD_PROCESSING
echo.
echo ## Can not switch on extended command processing.
goto TERMINATED
::--------------------------------------------------------------------------------------------------
rem :
rem echo.
rem echo ## 
rem goto TERMINATED
::--------------------------------------------------------------------------------------------------
:TERMINATED
echo ## CMD-execution is terminated (in "%~dpnx0").
echo 
pause
EXIT 255
::==================================================================================================
:RESET_ERROR
set errorlevel=0
set errorlevel=
goto :EOF
:SET_ERROR
verify # 2>nul
goto :EOF
::==================================================================================================
:RETURN_SUCCESS
set errorlevel=0
set errorlevel=
goto :EOF
:RETURN_ERROR
verify # 2>nul
goto :EOF
:END_LOCAL_RETURN_SUCCESS
endlocal
goto RETURN_SUCCESS
:END_LOCAL_RETURN_ERROR
endlocal
goto RETURN_ERROR
::==================================================================================================
:FINISH
if !is_nested_call$$$$!==0 (
echo.
pause )
endlocal
endlocal
goto RETURN_SUCCESS
:ERROR
if !is_nested_call$$$$!==0 (
echo 
pause )
endlocal
endlocal
goto RETURN_ERROR
::==================================================================================================
