home *** CD-ROM | disk | FTP | other *** search
/ IBM Presents OS/2 Software Hits 1995 / OS-2_SW_HITS_2ND_EDITION_1995.ISO / i17 / ur423843.dsk / CSD3.DFI / RUINST.CMD < prev    next >
OS/2 REXX Batch file  |  1993-04-19  |  5KB  |  144 lines

  1. /****************************************************************/
  2. /* RUINST.CMD - Builds the database tables for the RU utility   */
  3. /****************************************************************/
  4. trace on
  5. database = "lm11"
  6.  
  7. If Rxfuncquery('SQLEXEC') <> 0 then
  8.    rcy = Rxfuncadd('SQLEXEC', 'SQLAR', 'SQLEXEC')
  9.  
  10. If Rxfuncquery('SQLDBS') <> 0 then
  11.    rcy = Rxfuncadd('SQLDBS', 'SQLAR', 'SQLDBS')
  12.  
  13. say 'Starting Database Manager.......'
  14.  
  15. call SQLDBS 'START DATABASE MANAGER'
  16.  
  17. /* Test to see if DBM was started or already started */
  18. if sqlca.sqlcode <> 0 then do
  19.    if sqlca.sqlcode <> -1026 then do
  20.       say 'Could not start DATABASE MANAGER'
  21.       say 'SQLCODE = ' sqlca.sqlcode
  22.       return '1'
  23.    end
  24. end
  25.  
  26. call SQLDBS 'START USING DATABASE 'database
  27. if sqlca.sqlcode <> 0 then do
  28.    call DBERROR "START USING database"
  29.    return '1'
  30. end
  31. call CREATE_TABLES
  32. call SQLDBS 'STOP USING DATABASE'
  33. return
  34.  
  35. CREATE_TABLES:
  36. /****************************************************/
  37. /* This procedure creates the RU tables, tests      */
  38. /* if create was successful and calls an error      */
  39. /* procedure if an unexpected error occurrs         */
  40. /****************************************************/
  41.  
  42. /*****************************************************/
  43. /*     Create Ring_performance  table                */
  44. /*****************************************************/
  45.  
  46. RUTable = 'CREATE TABLE LANM.RING_PERFORMANCE ',
  47.           '(segment_number        char(3)  NOT NULL,',
  48.           ' time_logged           time     NOT NULL,',
  49.           ' date_logged           date     NOT NULL,',
  50.           ' interval_seconds      int      NOT NULL,',
  51.           ' seconds_timestamp     int      NOT NULL,',
  52.           ' utilization           dec(3,1) NOT NULL)'
  53.  
  54. say 'Creating RING_PERFORMANCE table....'
  55. call SQLEXEC 'EXECUTE IMMEDIATE :RUTable'
  56. if sqlca.sqlcode <> 0 & sqlca.sqlcode <> -601 then
  57.    call DBERROR "Creating RING_PERFORMANCE table"
  58.  
  59. say 'Creating RINGPERF index....'
  60.  
  61. RUIndex = 'CREATE UNIQUE INDEX LANM.RINGPERF ON LANM.RING_PERFORMANCE ',
  62.           ' (segment_number, seconds_timestamp)'
  63.  
  64. call SQLEXEC 'EXECUTE IMMEDIATE :RUIndex'
  65. if sqlca.sqlcode <> 0 & sqlca.sqlcode <> 605 then
  66.   if sqlca.sqlcode <>-1024 then
  67.    call DBERROR "Creating RINGPERF index"
  68.   else
  69.    call RU_EXIT
  70.  
  71. RUComment = 'COMMENT ON TABLE LANM.RING_PERFORMANCE IS ''Ring Performance'''
  72.  
  73. call SQLEXEC 'EXECUTE IMMEDIATE :RUComment'
  74.  
  75. /* Test to see if table was created    */
  76. if sqlca.sqlcode <> 0 & sqlca.sqlcode <> -601 then
  77.   if sqlca.sqlcode <>-1024 then
  78.    call DBERROR "Creating comment on table"
  79.   else
  80.    call RU_EXIT
  81.  
  82. call SQLEXEC 'COMMIT'
  83.  
  84. /******************************************************/
  85. /*     Create RUPOLL Definitions table                */
  86. /******************************************************/
  87.  
  88. RUTable = 'CREATE TABLE LANM.RUPOLL_DEFS ',
  89.           '(segment_no            char(3)  NOT NULL,',
  90.           ' interval              char(4)  NOT NULL)'
  91.  
  92. say 'Creating RUPOLL_DEFS table....'
  93. call SQLEXEC 'EXECUTE IMMEDIATE :RUTable'
  94. if sqlca.sqlcode <> 0 & sqlca.sqlcode <> -601 then
  95.   if sqlca.sqlcode <>-1024 then
  96.    call DBERROR "Creating RUPOLL_DEFS table"
  97.   else
  98.    call RU_EXIT
  99.  
  100. say 'Creating RUDEFS index....'
  101.  
  102. RUIndex = 'CREATE UNIQUE INDEX LANM.RUDEFS ON LANM.RUPOLL_DEFS ',
  103.           ' (segment_no)'
  104.  
  105. call SQLEXEC 'EXECUTE IMMEDIATE :RUIndex'
  106. if sqlca.sqlcode <> 0 & sqlca.sqlcode <> 605 then
  107.   if sqlca.sqlcode <>-1024 then
  108.    call DBERROR "Creating RUDEFS index"
  109.   else
  110.    call RU_EXIT
  111.  
  112. RUComment = 'COMMENT ON TABLE LANM.RUPOLL_DEFS IS ''Ring Performance Definitions'''
  113.  
  114. call SQLEXEC 'EXECUTE IMMEDIATE :RUComment'
  115.  
  116. /* Test to see if table was created    */
  117. if sqlca.sqlcode <> 0 & sqlca.sqlcode <> -601 then
  118.   if sqlca.sqlcode <>-1024 then
  119.    call DBERROR "Creating comment on table"
  120.   else
  121.    call RU_EXIT
  122.  
  123. call SQLEXEC 'COMMIT'
  124.  
  125. say 'Done.'
  126. call RU_EXIT
  127.  
  128. RU_EXIT:
  129. return;
  130.  
  131. DBERROR:
  132. /*****************************************************/
  133. /* This procedure is called if an unexpected error   */
  134. /* occurrs while creating a table.  It displays the  */
  135. /* SQLCODE and SQLERRM                               */
  136. /*****************************************************/
  137.    event = arg(1)
  138.    say 'Error occurred while' event
  139.    say 'SQLCODE = ' sqlca.sqlcode
  140.    say 'SQLERRM = ' sqlca.sqlerrmc
  141.    say 'Consult the Database Manager Programming Guide'
  142.    call SQLDBS 'STOP USING DATABASE'
  143.    return '1'
  144.