home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / asctos.zip / ASCTOSQL.CMD
OS/2 REXX Batch file  |  1993-05-17  |  6KB  |  169 lines

  1. /*******************************************************************/
  2. /* ASCTOSQL.CMD - Converts IBM LAN NetView Start (Start) ASCII     */
  3. /* database files to data rows in a Database Manager database.     */
  4. /*                                                                 */
  5. /* This applet contains the code listed in the "Network Plotting   */
  6. /* Formation:  The LAN NetView Start Objects" article in the       */
  7. /* Spring 1993 issue of the OS/2 Developer magazine.               */
  8. /*                                                                 */
  9. /* An updated version of this applet, called ASCTOSQ2.CMD, is      */
  10. /* available with the IBM LAN NetView Start 1.1 product.  By       */
  11. /* examining either applet, you can see how the ASCII and SQL      */
  12. /* databases for the Start product work.                           */
  13. /*                                                                 */
  14. /* (c) Copyright IBM Corp., 1993                                   */
  15. /*                                                                 */
  16. /* DISCLAIMER OF WARRANTIES:                                       */
  17. /* The code provided in this applet program was created by the     */
  18. /* IBM Corporation.  This code is provided "AS IS", without        */
  19. /* warranty or support of any kind.  IBM shall not be liable for   */
  20. /* any damages arising out of the use of this applet code, even if */
  21. /* the users have been advised of the possibility of such damages. */
  22. /* IBM reserves the right to make improvements or changes to this  */
  23. /* applet code at any time without any notice to you.  This applet */
  24. /* can be further copied and redistributed without restriction.    */
  25. /*                                                                 */
  26. /*******************************************************************/
  27.  
  28. /* Get the source directory name and target database name. */
  29. parse upper arg dpath dbname rest
  30.  
  31. if ((dpath = '?') | (dpath = '')) then
  32.      do
  33.       say 'ASCTOSQL.CMD - Converts IBM LAN NetView Start ASCII database'
  34.       say 'files to data rows in a Database Manager database.'
  35.       say 'An example call:'
  36.       say ' '
  37.       say 'ASCTOSQL directory-with-ASCII-files sql-dbname'
  38.       say 'ASCTOSQL E:\NET1\ NETWORK'
  39.       say ' '
  40.       say 'The SQL database must have been created by LAN NetView Start'
  41.       say 'before this program is invoked.'
  42.       exit
  43.      end
  44.  
  45. if \(substr(dpath,length(dpath),length(dpath)) = '\') then
  46.      dpath = dpath || '\'
  47.  
  48. /* Load REXX utilities and initialize variables */
  49. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  50. call SysLoadFuncs
  51. numtables = 15
  52. tblname.1 = 'NETWORKS'
  53. tblname.2 = 'TOPOLOGIES'
  54. tblname.3 = 'FOLDERS'
  55. tblname.4 = 'NODES'
  56. tblname.5 = 'CONNECTIONS'
  57. tblname.6 = 'ADAPTERPARMS'
  58. tblname.7 = 'EMDFTPARMS'
  59. tblname.8 = 'EMNONDFTPARMS'
  60. tblname.9 = 'INCLUDES'
  61. tblname.10 = 'HOSTPARMS'
  62. tblname.11 = 'APPLICATIONS'
  63. tblname.12 = 'RTRANSFORMERS'
  64. tblname.13 = 'LCUTRANSFORMERS'
  65. tblname.14 = 'NVTRANSFORMERS'
  66. tblname.15 = 'LCUMAP'
  67. setname.1 = 'NODE_NAME_SET'
  68. setname.2 = 'LOCAL_NODE_NAME_SET'
  69. setname.3 = 'NODE_LAN_ADDRESS_SET'
  70. setname.4 = 'DBWORKSTATION_NAME_SET'
  71. setname.5 = 'LSCOMPUTER_NAME_SET'
  72. setname.6 = 'NODE_DOMAIN_NAME_SET'
  73.  
  74. /* Delete any DEL and MSG files that already exist. */
  75. do i = 1 to numtables
  76.     len = 8
  77.     if length(tblname.i) < 8 then
  78.         len = length(tblname.i)
  79.     delfilename.i = substr(tblname.i,1,len)
  80.     'erase ' delfilename.i || '.DEL'
  81.     'erase ' delfilename.i || '.MSG'
  82. end
  83.  
  84. /* Find the topology files. */
  85. fullpath = dpath || '*.TOP'
  86. call SysFileTree fullpath, 'file', 'F'
  87. do i = 1 to file.0
  88.     filename.i = substr(file.i,38)
  89. end
  90. numfiles = file.0
  91.  
  92. /* There's only one network file to find. */
  93. fullpath = dpath || '*.NET'
  94. call SysFileTree fullpath, 'file', 'F'
  95. numfiles = numfiles+1
  96. filename.numfiles = substr(file.1,38)
  97.  
  98. /* Go through each of the files and store them
  99. in the appropriate DEL file */
  100. do i = 1 to numfiles
  101.     say 'Processing File: ' || filename.i
  102.     outfilename = 'NONE'
  103.     do until lines(filename.i) = 0
  104.         inline = linein(filename.i)
  105.         skip = false
  106.         do j = 1 to numtables
  107.             if (tblname.j = substr(inline, 2, length(inline))) then
  108.                 do
  109.                     outfilename = delfilename.j || '.DEL'
  110.                     say '     On table: ' || tblname.j
  111.                     skip = true
  112.                 end
  113.         end
  114.  
  115.         /* if a set name was encountered, skip it and its data rows */
  116.         do j = 1 to 5
  117.             if (setname.j = substr(inline, 2, length(inline))) then
  118.                 do
  119.                     outfilename = 'NONE'
  120.                     skip = true
  121.             end
  122.         end
  123.  
  124.         if (skip = false & outfilename <> 'NONE') then
  125.             do
  126.                 /* if in the topology section and the
  127.                 topology id isn't 2 or 3, skip the row */
  128.                 if ((outfilename = 'TOPOLOGI.DEL') |
  129.                     (outfilename = 'FOLDERS.DEL')) then
  130.                     do
  131.                         topid = substr(inline, 1, (pos(',',inline) -1))
  132.                         tempstr = translate(filename.i, ' ', '\')
  133.                         tempstr = translate(tempstr, ' ', '.')
  134.                         fileid = word(tempstr, (words(tempstr)-1))
  135.                         if (\(topid = fileid) | (fileid = 2) | (fileid = 3)) then
  136.                             rc = lineout(outfilename, inline)
  137.                     end
  138.                 else
  139.                     rc = lineout(outfilename, inline)
  140.             end
  141.  
  142.      end
  143. end /* do */
  144.  
  145. /* Close all the DEL files. */
  146. do i = 1 to numtables
  147.       rc = lineout(delfilename.i || '.DEL')
  148. end
  149.  
  150. call dbm "STARTDBM"
  151. call dbm "START USING DATABASE " || dbname
  152. /* Import the DEL files into the database */
  153. do i = 1 to numtables
  154.     say 'Importing into table: ' || tblname.i
  155.     call dbm "DELETE FROM " || tblname.i
  156.     call dbm "IMPORT TO " || dbname || " FROM " || delfilename.i || ,
  157.     ".DEL OF DEL REPLACE INTO " || tblname.i || " MESSAGES " || ,
  158.     delfilename.i || ".MSG"
  159. end
  160. call dbm "STOP USING DATABASE"
  161. /* call dbm "STOPDBM" */
  162.  
  163. say ' '
  164. say 'ASCII to SQL DBM conversion complete.'
  165. say 'Examine the *.MSG message files for import warning messages,'
  166. say '  if any.  A data row might be rejected because it contained'
  167. say '  double quotes in a string value.'
  168.  
  169.