PROPERTY APPLICATION TITLE 'Nightly Routines'
IF (CHKFILE('C:\Temp')) <> 1 THEN
  MKDIR c:\temp
ENDIF
DISCONNECT
SET QUOTES=NULL
SET QUOTES='
SET DELIMIT=NULL
SET DELIMIT=','
SET LINEEND=NULL
SET LINEEND='þ'
SET SEMI=NULL
SET SEMI=';'
SET PLUS=NULL
SET PLUS='+'
SET SINGLE=NULL
SET SINGLE='_'
SET MANY=NULL
SET MANY='%'
SET IDQUOTES=NULL
SET IDQUOTES='`'
SET CURRENCY '$' PREF 4 B
SET DATE FORMAT MM/DD/YYYY
SET DATE SEQUENCE mmddyyyy
SET DATE YEAR 0
SET DATE CENTURY 20
SET TIME FORMAT HH:MM:SS AP
SET TIME SEQUENCE hhmmss
-- Connect Database
SET WALKMENU ON
SET ZERO ON
SET SCRATCH c:\temp
SET MESSAGES OFF
SET ERROR MESSAGES OFF
SET ERROR MESSAGE 2495 OFF
SET MULTI ON
SET STATICDB OFF
SET FASTLOCK ON
SET PAGELOCK ON
SET TIMEOUT 60
CONNECT dbname IDENTIFIED BY NONE
--SET ERROR MESSAGE 2495 ON
-- Check the availability of database
IF SQLCODE = -7 THEN
  EXIT
ENDIF
-- Set Default Character Settings
SET NULL ' '
SET QUOTES='
SET DELIMIT=','
SET LINEEND='þ'
SET SEMI=';'
SET PLUS='+'
SET SINGLE='_'
SET MANY='%'
SET IDQUOTES='`'
SET CURRENCY '$' PREF 4 B
SET DATE FORMAT MM/DD/YYYY
SET DATE SEQUENCE mmddyyyy
SET DATE YEAR 0
SET DATE CENTURY 20
SET TIME FORMAT HH:MM:SS AP
SET TIME SEQUENCE hhmmss

--other stuff runs here that i removed....


--pack database if not sunday
IF (TDWK(.#DATE)) <> 'Sunday' THEN
  PAUSE 4 USING 'packing database'
  --stop webserver to disconnect database connection
  LAUNCH c:\nightly\stopiis.bat||w
  PAUSE FOR 5 USING 'Waiting for iis to shut down'
  DISCONNECT
  CONNECT dbname
  --check to see if nobody is in database and pack if so
  SET VAR vconnection = (CVAL('CONNECTIONS'))
  IF vconnection = '1' THEN
    DISCONNECT
    SET MULTI OFF
    SET STATICDB OFF
    SET ROWLOCKS ON
    SET PAGELOCK ON
    SET MESSAGES OFF
    CONNECT dbname
    PACK ALL
  ENDIF
  DISCONNECT
  --restart webserver
  LAUNCH c:\nightly\startiis.bat||w
ENDIF

--reload database if sunday
IF (TDWK(.#DATE)) = 'Sunday' THEN
  PAUSE 4 USING 'reloading database'
  --stop webserver to disconnect database connection
  LAUNCH c:\nightly\stopiis.bat||w
  PAUSE FOR 5 USING 'Waiting for iis to shut down'
  DISCONNECT
  CONNECT dbname
  --check to see if nobody is in database and pack if so
  SET VAR vconnection = (CVAL('CONNECTIONS'))
  IF vconnection = '1' THEN
    DISCONNECT
    SET MULTI OFF
    SET STATICDB OFF
    SET ROWLOCKS ON
    SET PAGELOCK ON
    SET MESSAGES OFF
    connect dbname
    reload test
    disconnect
    RENAME dbname.rx? dbnamebk.rx?
    RENAME test.rx? dbname.rx?
    CONNECT dbname
    PACK ALL
  ENDIF
  DISCONNECT
  --restart webserver
  LAUNCH c:\nightly\startiis.bat||w
ENDIF
DISCONNECT
EXIT




