@echo off
@cls
@echo ** 		 						**
@echo ** 		Batch file to deploy DB changes 		**
@echo ** 		 						**
@echo .
@echo Please ensure that a backup of the database is available!!
@echo .
@color 74
@echo This batch file will stop the magicview 300 services and then deploy the changes.
@echo This may take a few minutes....Please wait...
@echo .......
@net stop magicview300 /y

if %errorlevel% GTR 0 (echo Service stop returned errors, error was  %errorlevel% ) else (echo service stopped succesfully)

@dbisql -c "eng=tempSrv; dsn=pcv_dicom_db;uid=dba;pwd=pa++word@MV300; ASTART=YES" -nogui -q  create index img_file_name_ids on image ("image filename")  

@echo.
@echo. The result of execution is :
goto ret%errorlevel%

:ret1
@echo General failure. At some point, a SQL or Interactive SQL statement did not execute successfully ! Please start the db engine manually and retry!
goto end

:ret5
@echo The user terminated interactive SQL. Please start the db engine manually and retry!
goto end

:ret9
@echo Unable to connect.. Please check the ODBC configuration!
goto end

:ret255
@echo Bad command. The command contained incomplete or invalid options. Contact the administrator!
goto end

:ret0
@echo The batch run was succesful! Please restart the magicview300 services

:end
@color

@dbisql -c "eng=tempSrv; dsn=pcvjbdb;uid=dba;pwd=pa++word@MV300; ASTART=YES" -nogui -q drop table "DBA"."CDQRetrieveDetails"
@dbisql -c "eng=tempSrv; dsn=pcvjbdb;uid=dba;pwd=pa++word@MV300; ASTART=YES" -nogui -q  CREATE TABLE "DBA"."CDQRetrieveDetails" ("Job UID" integer  NOT NULL,"Series Instance UID" varchar(64)  NOT NULL DEFAULT '',"File Availability" tinyint  NOT NULL DEFAULT 0,"Study Instance UID" varchar(64)  NOT NULL DEFAULT '',PRIMARY KEY ("Job UID", "Series Instance UID"));
@dbisql -c "eng=tempSrv; dsn=pcvcdarchive;uid=dba;pwd=pa++word@MV300; ASTART=YES" -nogui -q  UPDATE "DBA"."Patient" SET "PrimaryCharacterSet" = 3 WHERE (("Character Set" IS NULL) OR ("Character Set" = ''));

echo done executing batch file! 



