set PLESK_ROOT_D=%~1
set db=%~2
set horde=%~3

"%PLESK_ROOT_D%admin\bin\sqlite.exe" "%db%upgrade.db" < "%horde%scripts\upgrades\dump_horde_3.3.6_cln.sqlite" > "%horde%scripts\upgrades\dump_horde_db.sql"
if x%ERRORLEVEL%x NEQ x0x exit 1
cmd /c "type "%horde%scripts\upgrades\dump_horde_db.sql" | FIND "SQL error: no such table:""
if x%ERRORLEVEL%x EQU x0x goto dump_horde_336_upg

cmd /c "echo success>"%horde%scripts\upgrades\dump_horde_3.3.6_cln.success""
exit 0

:dump_horde_336_upg
"%PLESK_ROOT_D%admin\bin\sqlite.exe" "%db%upgrade.db" < "%horde%scripts\upgrades\dump_horde_3.3.6_upg.sqlite" > "%horde%scripts\upgrades\dump_horde_db.sql"
if x%ERRORLEVEL%x NEQ x0x exit 1
cmd /c "type "%horde%scripts\upgrades\dump_horde_db.sql" | FIND "SQL error: no such table:""
if x%ERRORLEVEL%x EQU x0x goto dump_horde_310

cmd /c "echo success>"%horde%scripts\upgrades\dump_horde_3.3.6_upg.success""
exit 0

:dump_horde_310
"%PLESK_ROOT_D%admin\bin\sqlite.exe" "%db%upgrade.db" < "%horde%scripts\upgrades\dump_horde_3.1.0.sqlite" > "%horde%scripts\upgrades\dump_horde_db.sql"
if x%ERRORLEVEL%x NEQ x0x exit 1
cmd /c "type "%horde%scripts\upgrades\dump_horde_db.sql" | FIND "SQL error: no such table:""
if x%ERRORLEVEL%x EQU x0x goto unexpected_error

cmd /c "echo success>"%horde%scripts\upgrades\dump_horde_3.1.0.success""
exit 0

:unexpected_error
cmd /c "ren "%horde%scripts\upgrades\dump_horde_db.sql" "dump_horde_db.sql.error""

exit 1
