home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / sybaserx.zip / SYBRX.CMD < prev   
OS/2 REXX Batch file  |  1996-01-27  |  5KB  |  158 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* SYBRX.CMD                                                       */
  4. /*                                                                 */
  5. /* This program calls the various REXX external functions          */
  6. /* provided in the SYBREXX.C function package.                     */
  7. /*                                                                 */
  8. /* Each function is called once to illustrate how it is used.      */
  9. /* Some of the functions have multiple options and multiple        */
  10. /* types of output, but not all options are used here.             */
  11. /*                                                                 */
  12. /*******************************************************************/
  13. '@echo off'
  14.  
  15. /* Modify these variables to suite your environment */
  16.  
  17. UserID = 'sa'
  18. Password = 'alicee'
  19. Database = 'Master'
  20. Server = 'DUNX_NB'
  21.  
  22. /* RxSybLoadFuncs:  This function will load all the rest,            */
  23. /* so we do not have to make many calls to RxFuncAdd.              */
  24.  
  25. Say 'This program will call many of the REXX functions provided'
  26. Say '  in SYBREXX.DLL.  The first one is RxSybLoadFuncs, which makes'
  27. Say '  all the others available.'
  28. Say ' '
  29.  
  30. call RxFuncAdd 'RxSybLoadFuncs', 'SYBREXX', 'RxSybLoadFuncs'
  31. call RxSybLoadFuncs
  32.  
  33. /* Set return codes */
  34. SUCCEED = 1
  35. FAIL = 0
  36. NO_MORE_ROWS = -2
  37. MORE_ROWS = -1
  38. TRUE = 1
  39. FALSE = 0
  40.  
  41. Say RxDbversion()
  42. Say
  43.  
  44. /*** Demonstrate RxDbsethandlers ***/
  45. Call RxDbsethandlers('no messages')  /* Note that this is not implemented */
  46.                                      /* Passing a filename (or any string)*/
  47.                                      /* prevents messages from appearing  */
  48.                                      /* on the screen.  An empty string   */
  49.                                      /* will send messages to the screen  */
  50.  
  51.  
  52. /*** Demonstrate RxDbsetlogintime ***/
  53. Call RxDbsetlogintime('5')
  54.  
  55. /*** Demonstrate RxDbsettime ***/
  56. Call RxDbsettime('0')
  57.  
  58. pLoginRec = RxDblogin()                /* Get a Login Structure */
  59.  
  60. Call RxDbsetluser pLoginRec, UserID   /* Set the User ID in the Login Struct */
  61.  
  62. Call RxDbsetlpwd pLoginRec, Password  /* Set the Password in the Login Struct */
  63.  
  64. Call RxDbsetlhost pLoginRec, 'SYBREXX' /* Set the Host in the Login Struct */
  65.  
  66. Call RxDbsetlapp pLoginRec, 'SYBRX.CMD'/* Set the Applic in the Login Struct */
  67.  
  68. Call RxDbsetlencrypt pLoginRec, TRUE   /* Set password encryption on */
  69.  
  70. dbproc = RxDbopen(pLoginRec, Server)   /* Open a DBPROCESS */
  71.  
  72. if (dbproc == 0) then do               /* Be sure to check we have a valid */
  73.     Say 'dbopen failed!'               /* DBPROCESS before continuing!     */
  74.     exit
  75. end
  76.  
  77. RetCode = RxDbuse(dbproc, Database)       /* Set the Database */
  78.  
  79.  
  80. /* Set up a SQL command string */
  81.  
  82. RetCode = RxDbcmd(dbproc, "select name, crdate from sysdatabases")
  83.  
  84.  
  85. if (RxDbsqlexec(dbproc) <> SUCCEED) then do    /* Execute it */
  86.     Say 'dbsqlexec failed!'
  87.     Call RxDbclose(dbproc)
  88.     exit
  89. end
  90.  
  91. if (RxDbresults(dbproc) <> SUCCEED) then do    /* Check results */
  92.     Say 'dbresults failed!'
  93.     Call RxDbclose(dbproc)
  94.     exit
  95. end
  96.  
  97.  
  98. if (RxDbrows(dbproc) <> SUCCEED) then do       /* Check if rows are returned */
  99.     Say 'dbresults failed!'
  100.     Call RxDbclose(dbproc)
  101.     exit
  102. end
  103.  
  104.  
  105. /*** Write out the Titles ***/
  106. Say Substr('Name',1,31) substr('Creation Date',1,31)
  107. Say Substr('',1,31,'-') substr('',1,31, '-')
  108.  
  109. do while (RxDbnextrow(dbproc) == MORE_ROWS)
  110.  
  111.     /*** Get the Data ***/
  112.     /* NOTE: At this stage RxDbdata only allocates 256 bytes for the returned */
  113.     /* data - I still need to make it smarter so that it will allocate        */
  114.     /* additional storage if required                                         */
  115.     /* This will probably only impact TEXT and BINARY columns                 */
  116.  
  117.     Name = RxDbdata(dbproc, '1')            /* Set Name = results column 1 */
  118.     CrDate = RxDbdata(dbproc, '2')          /* Set CrDate = results column 2 */
  119.  
  120.     Say Substr(Name,1,31) substr(CrDate,1,31)
  121.  
  122. end
  123.  
  124. Call RxDbclose(dbproc)        /* Close the DBPROCESS */
  125.  
  126.  
  127. Call RxSybDropFuncs
  128. say; say 'SYBRX demonstration program is complete.'
  129. say;
  130. say 'Written by: Duncan A. Groenewald'
  131. say '            12 Nursery Lane'
  132. say '            CONSTANTIA'
  133. say '            CAPE TOWN'
  134. say '            South Africa'
  135. say
  136. say
  137. say 'Internet: duncang@iaccess.za'
  138. say
  139. exit
  140.  
  141.  
  142.  
  143. SysPause:
  144. parse arg prompt
  145.   if prompt='' then
  146.     prompt='Press Enter key when ready . . .'
  147.   call SysSay prompt
  148.   Pull .
  149.   say
  150. return
  151.  
  152.  
  153.  
  154. SysSay:
  155. parse arg string
  156.   call charout 'STDOUT', string
  157. return
  158.