midrange.com code scratchpad
Name:
REXX SQL test skeleton variant
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/04/2009 08:24:19 am
IP:
Logged
Description:
I test SQL in REXX by putting the SQL into the middles of a skeleton REXX proc and calling the proc with a CL. The CL calls the QREXX API to execute the proc with the *EXECSQL command environment, and then it calls the QREXQ API to pull any result back from the proc. The SQL REXX variant that I was testing is here.
Code:
  1. /* SKELETON -- Change commands as needed... */
  2.  
  3. signal on error name command_error
  4. signal on failure name command_error
  5. signal on syntax name syntax_error
  6.  
  7. /* SQL runs here... */
  8.  
  9.    PRVDATE = '0001-01-01'
  10.  
  11.    sql_Stmt = ,
  12.            'values CHAR(DATE(CURRENT_DATE - 15 DAYS)) into ?'
  13.  
  14.    'execsql PREPARE S1 FROM :sql_Stmt'
  15.    'execsql EXECUTE S1 USING :PRVDATE'
  16.  
  17.    say  RC '<'PRVDATE'>'
  18.  
  19.    'execsql ',
  20.         'SET OPTION DATFMT = *ISO   '
  21.  
  22.    sql_Stmt = ,
  23.            'select CHAR(DATE(CURRENT_DATE - 15 DAYS))      ',
  24.            '    from sysibm/sysdummy1                      '
  25.  
  26.    'execsql ',
  27.         'PREPARE S2 FROM :sql_Stmt '
  28.    'execsql ',
  29.         'DECLARE C1 CURSOR FOR S2'
  30.    'execsql ',
  31.         'OPEN C1 '
  32.  
  33.    'execsql ',
  34.           'FETCH C1 INTO :PRVDATE'
  35.  
  36.    say  RC '<'PRVDATE'>'
  37.  
  38.    parse var PRVDATE year '-' month '-' day
  39.    say (year)(month)(day)
  40.  
  41.    'execsql ',
  42.          'CLOSE C1'
  43.  
  44.    queue (year)(month)(day)
  45.  
  46. exit
  47.  
  48. /* ---------------------------------------------------------------- */
  49. command_error:
  50.  
  51.        trace off
  52.  
  53.        parse source system start srcmbr srcfile srclib
  54.        say 'Unexpected error at line 'sigl' of REXX program ',
  55.            srcmbr' in 'srclib'/'srcfile'. The exception ID is 'rc'.'
  56.  
  57. exit(right(rc,4))
  58. /* ---------------------------------------------------------------- */
  59. syntax_error:
  60.  
  61.        trace off
  62.  
  63.        parse source system start srcmbr srcfile srclib
  64.        say 'Syntax error at line 'sigl' of REXX program ',
  65.            srcmbr' in 'srclib'/'srcfile'. The error code is 'rc'.',
  66.            ' The description is :'
  67.        say errortext(rc)
  68.  
  69. exit(rc)
  70.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css