set PLESK_ROOT_D=%~1
set DBUSER=%~2
set DBPASSWD=%~3
set DBNAME=%~4
set horde=%~5

set RETURN=0

cmd /c "type "%horde%scripts\upgrades\dump_horde_db.sql" | FIND "INSERT INTO horde_datatree_seq VALUES(""
if x%ERRORLEVEL%x NEQ x0x goto check_horde_histories_seq

rem Create horde_datatree_seq sequence table
"%PLESK_ROOT_D%MySQL\bin\mysql.exe" -u%DBUSER% -p%DBPASSWD% %DBNAME% -e "CREATE TABLE horde_datatree_seq (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY(id));"
if x%ERRORLEVEL%x NEQ x0x set RETURN=%ERRORLEVEL%

:check_horde_histories_seq
cmd /c "type "%horde%scripts\upgrades\dump_horde_db.sql" | FIND "INSERT INTO horde_histories_seq VALUES(""
if x%ERRORLEVEL%x NEQ x0x goto exit

rem Create horde_histories_seq sequence table
"%PLESK_ROOT_D%MySQL\bin\mysql.exe" -u%DBUSER% -p%DBPASSWD% %DBNAME% -e "CREATE TABLE horde_histories_seq (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY(id));"
if x%ERRORLEVEL%x NEQ x0x set RETURN=%ERRORLEVEL%

:exit
exit %RETURN%
