home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / DSL.ZIP / DSL.CMD
OS/2 REXX Batch file  |  1993-01-07  |  4KB  |  159 lines

  1. /* DSL.CMD - version 1.0 - 2/17/90 */
  2. /* Author: Anton Versteeg          */
  3. Trace 'o'
  4. rcx = Rxfuncquery('SQLDBS')
  5. If rcx <> 0 then
  6.    rcy = Rxfuncadd('SQLDBS','SQLAR','SQLDBS')
  7. rcx = Rxfuncquery('SQLEXEC')
  8. If rcx <> 0 then
  9.    rcy = Rxfuncadd('SQLEXEC','SQLAR','SQLEXEC')
  10. Say "DSL.CMD - version 1.0 - 2/17/90"
  11.  
  12. DT.384 = 'DATE'
  13. DT.388 = 'TIME'
  14. DT.392 = 'TIMESTAMP'
  15. DT.448 = 'VARCHAR'
  16. DT.452 = 'CHAR'
  17. DT.456 = 'LONG VCHAR'
  18. DT.464 = 'VARGRAPH'
  19. DT.468 = 'GRAPHIC'
  20. DT.472 = 'LONG VGRAPH'
  21. DT.480 = 'FLOAT'
  22. DT.484 = 'DECIMAL'
  23. DT.496 = 'INTEGER'
  24. DT.500 = 'SMALLINT'
  25.  
  26.  
  27. dbs.1 = 8;
  28. dbs.2 = 8;
  29. dbs.3 = 2;
  30. dbs.4 = 6;
  31. dbs.5 = 8;
  32. dbs.6 = 8;
  33. dbs.7 = 8;
  34. dbs.8 = 3;
  35. dbs.9 = 1;
  36.  
  37.  
  38. sample_rc = 0
  39. call SQLDBS 'START DATABASE MANAGER'
  40. if result<>0 then signal ERROR
  41. if (SQLCA.SQLCODE <> -1026 & SQLCA.SQLCODE <> 0)
  42.   then signal ERROR
  43. call SQLDBS 'OPEN DATABASE DIRECTORY ON 0 USING :scan_db'
  44. if scan_db.2 = 0 then do
  45.   "Sorry, you don't have any databases."
  46.   Signal FINISH
  47. End
  48.  
  49. Else Do
  50.   Say ""
  51.   Say " --ALIAS- | -DBNAME- | DR |INTNAME | NODENAME | DBTYPE   | COMMENT  | CP  | ET|"
  52.   Say " ---------|----------|----|--------|----------|----------|----------|-----|---|"
  53.   Do i=1 to scan_db.2
  54.     CALL SQLDBS 'GET DATABASE DIRECTORY ENTRY :scan_db.1 USING :entry'
  55.     outa = ''
  56.     Do j=1 to 9
  57.       outa=outa Left(entry.j,dbs.j) '|'
  58.     End
  59.     Say outa
  60.   End
  61. End
  62.  
  63. Do forever
  64.   Say ""
  65.   Say "Please enter a database name or Press Enter to exit."
  66.   Pull db1
  67.   if db1="" then leave
  68.   Say "Starting:" db1
  69.   call SQLDBS 'START USING DATABASE' db1
  70.   if SQLCA.SQLCODE <> 0 then do
  71.     if SQLCA.SQLCODE=-1013 Then Say "Database does not exist"
  72.     else say "Error:" SQLMSG
  73.   end
  74.   else do forever
  75.     Say "Enter select statement or press Enter to return to database selection."
  76.     Say "Enter a ? to get a list of your tables."
  77.     parse pull sel_jobs
  78.     say sel_jobs
  79.     If sel_jobs = '' Then Leave
  80.     If sel_jobs = '?' Then Do
  81.       Say "You have the following tables:"
  82.       sel_jobs = "SELECT CREATOR,NAME,TYPE,CTIME,COLCOUNT,CARD FROM SYSIBM.SYSTABLES"
  83.     End
  84.     Call SQLEXEC 'DECLARE c1 CURSOR FOR s1'
  85.     if result <> 0 | SQLCA.SQLCODE <> 0 Then signal ERROR
  86.     sqlda = ""
  87.     Call SQLEXEC 'PREPARE s1 FROM :sel_jobs'
  88.     if result <> 0 | SQLCA.SQLCODE <> 0 Then Do
  89.       say SQLMSG
  90.       Iterate
  91.     End
  92.     Call SQLEXEC 'DESCRIBE s1 INTO :sqlda '
  93.     if result <> 0 | SQLCA.SQLCODE <> 0 Then signal ERROR
  94.     line. = ''
  95.     do i=1 to sqlda.sqld
  96.       t=sqlda.i.sqltype
  97.       Nulls=0
  98.       if t//2>0 then do
  99.         t=t-1
  100.         Nulls=1
  101.       End
  102.       line.1 = line.1 Left(DT.t,10)
  103.       if t = 484 | t = 485
  104.       Then l =  sqlda.i.sqllen.precision','sqlda.i.sqllen.scale
  105.       Else l =  sqlda.i.sqllen
  106.       line.2  =  line.2 left(l,10)
  107.       If Nulls=1 Then line.3 = line.3 'Nulls OK  '
  108.                  Else line.3 = line.3 'Required  '
  109.       line.4=line.4 left(sqlda.i.sqlname,10)
  110.     end
  111.     line.5 = copies('-',sqlda.sqld*11)
  112.     do i=1 to 5
  113.       say line.i
  114.     end
  115.     call SQLEXEC 'OPEN c1'
  116.     if result <> 0 | SQLCA.SQLCODE <> 0 Then signal ERROR
  117.  
  118.     do while result=0  & SQLCA.SQLCODE = 0
  119.       call SQLEXEC 'FETCH c1 USING DESCRIPTOR :sqlda'
  120.       if result=0 & SQLCA.SQLCODE=0 then do
  121.         line=''
  122.         do i=1 to sqlda.sqld
  123.           if sqlda.i.sqlind = -1 then line = line '-         '
  124.                                  else line = line left(sqlda.i.sqldata,10)
  125.         end
  126.         say line
  127.       end
  128.       else if SQLCA.SQLCODE <> 100 then signal ERROR
  129.     end
  130.     call SQLEXEC 'CLOSE c1'
  131.     if result <> 0 | SQLCA.SQLCODE <> 0 Then signal ERROR
  132.   end
  133.   Say "Stopping:" db1
  134.   call SQLDBS 'STOP  USING DATABASE'
  135.   Say "Stopped. RC =" SQLCA.SQLCODE
  136.   If SQLCA.SQLCODE <> 0 Then Say SQLMSG
  137. end
  138.  
  139. result=0
  140. signal FINISH
  141.  
  142. ERROR: sample_rc = SQLCA.SQLCODE
  143.        say "return code:" sample_rc
  144.        say SQLMSG
  145.        exit sample_rc
  146.  
  147. FINISH: say 'DSL finished with rc = 'sample_rc
  148.         say 'and result ='result
  149.         call sqlDBS 'STOP USING DATABASE'
  150.         exit sample_rc
  151.  
  152. rcy = Rxfuncdrop('SQLDBS')
  153.    If rcy <> 0 Then
  154.      Say "RXfuncdrop rc =" rcy
  155. rcy = Rxfuncdrop('SQLEXEC')
  156.    If rcy <> 0 Then
  157.      Say "RXfuncdrop rc =" rcy
  158.  
  159.