home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / postpr.zip / postproc.cmd next >
OS/2 REXX Batch file  |  1994-07-12  |  48KB  |  1,240 lines

  1. /* VisPro REXX DB2 generated code post processor */
  2. /* POSTPROC.CMD */
  3. /* DPB  1 jul 94 created and distributed */
  4. /* jrb  5 jul 94 made into subroutines   POSTPRJB.CMD */
  5. /* jrb  6 jul 94 additional file header documentation */
  6. /*               ddlfile in specific project folder   */
  7. /* dpb  7/8/94   added COMMIT to ADD, CHANGE, DELETE events */
  8. /*      v 1.1    added author parameter */
  9. /*               fixed minor bug in SQUOTEIT & SQUOTEWC code */
  10. /* dpb/ 7/12/94  added HINT code genereation. Also fixed a bug */
  11. /* jrb  v 1.2    in the SQUOTEIT, SQUOTEWC code that while not */
  12. /*               fatal might have caused future problems. */
  13.  
  14. arg author pathname  /* eg. pathname=c:\visprorx\projects\test\main */
  15. if ARG() < 1 then do
  16.    say
  17.    say 
  18.    say "You must have at least the pathname as an argument."
  19.    say "Generally this results from drag/dropping the form on this object."
  20.    pause
  21.    exit
  22. end
  23. if Pathname = '' then do   
  24.    Pathname = Author
  25.    Author = 'Post Processor'
  26. end 
  27. version='PostProc Version 1.2'
  28. today=date()' 'time()
  29. call RxFuncAdd 'SysFileTree'  , 'RexxUtil', 'SysFileTree'
  30. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  31.  
  32. SubProcPath = substr(pathname   ,1,lastpos("\",pathname))'SubProcs'
  33. ProjectPath = substr(pathname   ,1,lastpos("\",pathname)-1)
  34. DDLfile=ProjectPath'\DDL.TXT'  /* JRB keeps .dbd * ddl.txt in each project */
  35. ProjectPath = substr(ProjectPath,1,lastpos("\",ProjectPath))
  36.  
  37. UndoPath    = pathname'\UNDO'
  38. ThreadPath  = pathname'\Threads'   /* ???? not used */
  39.  
  40. call BackUp
  41. call SingleQuote
  42. call SingleQuoteWildCard
  43. call FindEvents
  44. call GetColNames
  45.  
  46. /* Move the start using database code to the FORM OPEN event and      */
  47. /* delete it from the others.                                         */
  48.  
  49. call GetDBCodeFromAdd
  50. call SingleQuoteAdd
  51. call SingleQuoteChange
  52. call DelStartUsingFromChange
  53. call SingleQuoteDelete
  54. call DelStartUsingFromDelete
  55. call CommentToClear
  56. call CommentToContainerClick
  57. call CollapseFix
  58. call SingleQuoteWildCardSearch
  59. call DelStartUsingFromSearch
  60. call StartUsingInFormOpen
  61. call InsertColNamesForAdd
  62. call ColNamesForSelect
  63. call BuildWhereInSearch
  64. call ReadLimitInSearch
  65. call NullColumnsBeforeFetch
  66. call CommitAddPB
  67. call CommitChangePB
  68. call CommitDeletePB
  69. call ConfirmDeletePB
  70. call MakeHintFile
  71.  
  72. EXIT
  73.  
  74. /************************************************************************/
  75. /*      END MAIN                                                        */
  76. /************************************************************************/
  77.  
  78.  
  79.  
  80. /************************************************************************/
  81. /*      BEGIN SUBROUTINES                                               */
  82. /************************************************************************/
  83.  
  84. BackUp:
  85. /*========================================================================*/
  86. /* make a backup copy of the original files in case we want to start over */
  87. /*========================================================================*/
  88. file.0=0
  89. call SysFileTree UndoPath'\*.*', 'file', 'FO'
  90. if file.0 = 0 then do  /* if this is the first time then make a backup */
  91.    "MD "UndoPath
  92.    "xcopy "Pathname" "UndoPath
  93.    end
  94. else
  95.    "xcopy "UndoPath" "Pathname   /* reset the actual files from the backup */
  96. return
  97.  
  98. SingleQuote:
  99. /*=======================================================*/
  100. /* create the library subproc for handling single quotes */
  101. /*=======================================================*/
  102. filename=SubProcPath"\SQUOTEIT"
  103. rc=stream(filename,'c','close') 
  104. rc=SysFileDelete(filename)
  105.  
  106. CALL LINEOUT filename, "/* Single quote doubler subproc */"
  107. CALL LINEOUT filename, '/* 'filename' */'
  108. CALL LINEOUT filename, '/* 'author' 'today' 'version' */'
  109. CALL LINEOUT filename, ''
  110. CALL LINEOUT filename, 'arg value, FieldType  /* Use PARSE ARG instead of ARG for mixed case. */'
  111. CALL LINEOUT filename, 'q=pos("'||"'"||'",value)'
  112. CALL LINEOUT filename, 'do while q > 0'
  113. CALL LINEOUT filename, '   value=insert("'||"'"||'",value,q)'
  114. CALL LINEOUT filename, '   q=pos("'||"'"||'",value,q+2)'
  115. CALL LINEOUT filename, 'end'
  116. CALL LINEOUT filename, "if STRIP(value,'B',' ') = '' then return 'NULL'"
  117. CALL LINEOUT filename, 'if FieldType = '||"'"||'C'||"'"||' then value = '||'"'||"'"||'"'||'value'||'"'||"'"||'"'
  118. CALL LINEOUT filename, 'if FieldType = '||"'"||'T'||"'"||' then value = '||'"'||"'"||'"'||'value'||'"'||"'"||'"'
  119. CALL LINEOUT filename, 'return value'
  120. rc=stream(filename,'c','close') 
  121. return
  122.  
  123. SingleQuoteWildCard:
  124. /*=====================================================================*/
  125. /* create the library subproc for handling single quotes w/ wild cards */
  126. /*=====================================================================*/
  127. filename=SubProcPath"\SQUOTEWC"
  128. rc=stream(filename,'c','close') 
  129. rc=SysFileDelete(filename)
  130.  
  131. CALL LINEOUT filename, "/* Single quote w/ wild cards doubler subproc */"
  132. CALL LINEOUT filename, '/* 'filename' */'
  133. CALL LINEOUT filename, '/* 'author' 'today' 'version' */'
  134. CALL LINEOUT filename, ''
  135. CALL LINEOUT filename, 'arg value, FieldType  /* Use PARSE ARG instead of ARG for mixed case. */'
  136. CALL LINEOUT filename, 'q=pos("'||"'"||'",value)'
  137. CALL LINEOUT filename, 'do while q > 0'
  138. CALL LINEOUT filename, '   value=insert("'||"'"||'",value,q)'
  139. CALL LINEOUT filename, '   q=pos("'||"'"||'",value,q+2)'
  140. CALL LINEOUT filename, 'end'
  141. CALL LINEOUT filename, "if STRIP(value,'B',' ') = '' then return ''"  /* in this case we don't wan't NULL */
  142. CALL LINEOUT filename, 'if FieldType = '||"'"||'C'||"'"||' then value = '||'"'||"'%"||'"'||'value'||'"'||"%'"||'"'
  143. CALL LINEOUT filename, 'if FieldType = '||"'"||'T'||"'"||' then value = '||'"'||"'"||'"'||'value'||'"'||"'"||'"'
  144. CALL LINEOUT filename, 'return value'
  145. rc=stream(filename,'c','close') 
  146. return
  147.  
  148. FindEvents:
  149. /*=======================================*/
  150. /* get the .0 and .1 files in the path   */
  151. /*=======================================*/
  152.  
  153. call SysFileTree pathname'\*.0', 'file', 'FO'
  154. /* add in the FORM.1 file entry */
  155. count = file.0
  156. count = count + 1
  157. file.count = pathname'\Form.1'
  158. file.0 = count
  159. /*=============================================*/
  160. /* figure out which file goes with which event */
  161. /*=============================================*/
  162. do i=1 to count
  163.    filename=file.i
  164.    IF LENGTH(filename) > 0 THEN DO
  165.          j=0
  166.          DO WHILE LINES(filename)
  167.             value=LINEIN(filename)
  168.             j=j+1
  169.             /* insert here to use value */
  170.             select
  171.                when pos('register the rexx functions',value) > 0
  172.                   then do
  173.                          FormOpen = filename
  174.                          iterate i
  175.                        end
  176.                when pos('Arg window self index',value) > 0
  177.                   then do
  178.                          ContainerClicked = filename
  179.                          iterate i
  180.                        end
  181.                when pos("prep_string = 'INSERT INTO",value) > 0
  182.                   then do
  183.                          AddPB = filename
  184.                          iterate i
  185.                        end
  186.                when pos("prep_string = 'UPDATE",value) > 0
  187.                   then do
  188.                          ChangePB = filename
  189.                          iterate i
  190.                        end
  191.                when pos("prep_string = 'DELETE FROM",value) > 0
  192.                   then do
  193.                          DeletePB = filename
  194.                          iterate i
  195.                        end
  196.                when pos("prep_string = 'SELECT *",value) > 0
  197.                   then do 
  198.                          SearchPB = filename
  199.                          iterate i
  200.                        end
  201.                when ((pos("CALL VpSetItemValue",value) > 0) & j=6)
  202.                   then do 
  203.                          ClearPB = filename
  204.                          iterate i
  205.                        end
  206.                otherwise
  207.                   nop
  208.             end /* select */
  209.          END  /* do while */
  210.          rc=stream(filename,'c','close')
  211.    END  /* IF LENGTH */
  212.    rc=stream(filename,'c','close')
  213. end  /* end do i */
  214.  
  215.     say "Form open event    "FormOpen
  216.     say "Add     Pushbutton "AddPB
  217.     say "Change  Pushbutton "ChangePB
  218.     say "Delete  Pushbutton "DeletePB
  219.     say "ClearPB Pushbutton "ClearPB
  220.     say "Search  Pushbutton "SearchPB
  221.     say "Container Clicked  "ContainerClicked
  222. return
  223.  
  224. GetColNames:
  225. /*===============================================*/
  226. /* Now read the Add file to get the column names */
  227. /*===============================================*/
  228. filename=AddPB
  229. rc=stream(filename,'c','close') 
  230. IF LENGTH(filename) > 0 THEN DO
  231.       j=0
  232.       column.0 = 0
  233.       ColumnType.0 = 0
  234.       /* get to the start of the field section */
  235.       DO WHILE LINES(filename)
  236.          value=LINEIN(filename)
  237.          if pos("get the field values",value) > 0 then leave
  238.       END
  239.       /* get the colunm names */
  240.       DO WHILE LINES(filename)
  241.          value=LINEIN(filename)
  242.          if pos('prepare the SQL string',value) > 0 then do
  243.             column.0 = j
  244.             leave
  245.          end
  246.          if word(value,2) = '=' then do
  247.             j=j+1
  248.             column.j = word(value,1)
  249.             if pos('"',value) > 0 then ColumnType.j = 'C'
  250.             else ColumnType.j = 'N'
  251.          end
  252.          column.0 = j
  253.       END
  254.       DO WHILE LINES(filename)   /* now get the name of the table */
  255.          value=LINEIN(filename)
  256.          if pos("INSERT INTO",value) > 0 then do
  257.             Table=word(value,5)
  258.             Table=STRIP(Table,'B',",")
  259.             Table=STRIP(Table,'B',"'")
  260.          end /* if */
  261.       END  /* DO */
  262.       rc=stream(filename,'c','close') 
  263.       /* Now see if there is DDL.TXT file that can be used to               */
  264.       /* further refine the column types since Dates, Times, and TimeStamps */
  265.       /* require some special handling. We'll call these type 'T'           */
  266.       
  267.       filename=STREAM(ProjectPath"DDL.TXT",'c','query exists') 
  268. /*      filename=STREAM(DDLfile             ,'c','query exists')   /* jrb */*/
  269.       if LENGTH(filename) > 0 then do
  270.          DO WHILE LINES(filename)   /* find the create table statement */
  271.             value=LINEIN(filename)
  272.             if pos(Table,value) > 0 then leave
  273.          END
  274.          j=0
  275.          colddl.0=0
  276.          DO WHILE LINES(filename)   /* find the create table statement */
  277.             value=LINEIN(filename)
  278.             if pos("PRIMARY",value) > 0 then leave
  279.             j=j+1
  280.             colddl.j=STRIP(WORD(value,1),'B','(')
  281.             colddlType.j=WORD(value,2)
  282.             LeftParen=pos('(',colddlType.j,)
  283.             if LeftParen > 0 then colddlType.j=substr(colddlType.j,1,LeftParen-1)
  284.             colddlType.j=STRIP(colddlType.j,'B',',')
  285.          END
  286.          colddl.0=j
  287. /* Now we have to check each of the actual columns used to find out if */
  288. /* any of them are actually date, time or timestamp because these get  */
  289. /* treated later as character data types but LIKE can't be used with   */
  290. /* such predicates                                                     */
  291.          do i=1 to column.0
  292.             do j=1 to colddl.0
  293.                if column.i=colddl.j then do   /* we have a match */
  294.                   if colddlType.j= 'SMALLINT' then ColumnType.i = 'N'
  295.                   if colddlType.j= 'VARCHAR' then ColumnType.i = 'C'
  296.                   if colddlType.j= 'LONG' then ColumnType.i = 'C'
  297.                   if colddlType.j= 'CHAR' then ColumnType.i = 'C'
  298.                   if colddlType.j= 'DATE' then ColumnType.i = 'T'
  299.                   if colddlType.j= 'TIME' then ColumnType.i = 'T'
  300.                   if colddlType.j= 'TIMESTAMP' then ColumnType.i = 'T'
  301.                   if colddlType.j= 'INTEGER' then ColumnType.i = 'N'
  302.                   if colddlType.j= 'DECIMAL' then ColumnType.i = 'N'
  303.                   if colddlType.j= 'FLOAT' then ColumnType.i = 'N'
  304.                end /* if do */ 
  305.             end /* do i */
  306.          end /* do j */
  307.       rc=stream(filename,'c','close')
  308.       END /* if length */
  309.  
  310.           
  311. END /* IF LENGTH */
  312. do i = 1 to column.0
  313.    say "column "i" is "column.i" of type "ColumnType.i
  314. end
  315. return
  316.  
  317. GetDBCodeFromAdd:
  318. /********************************************/
  319. /* get the database code from the Add event */
  320. /********************************************/
  321. filename=AddPB
  322. tempfile='TEMPFILE'
  323. rc=stream(filename,'c','close') 
  324. rc=SysFileDelete(tempfile)
  325. CALL LINEOUT tempfile, "/* Add Pushbutton Event */"
  326. CALL LINEOUT tempfile, '/* 'filename' */'
  327. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  328. CALL LINEOUT tempfile, ''
  329. IF LENGTH(filename) > 0 THEN DO
  330.       j=0
  331.       /* get START USING DATABASE CODE and delete it from the event */
  332.       DO WHILE LINES(filename)
  333.          value=LINEIN(filename)
  334.          select
  335.             when pos("start the dbase and",value) > 0
  336.                then do
  337.                  CALL LINEOUT tempfile,"/* run the SQL */"
  338.                end
  339.             when pos("call sqldbs 'START USING DATABASE",value) > 0 
  340.                then do
  341.                  StartDBCode=value
  342.                  CALL LINEOUT tempfile,"DO"
  343.                  value=LINEIN(filename)   /* discard the original if */
  344.                end
  345.             when pos("stop using the database",value) > 0
  346.                then do  /* discard the next few lines */
  347.                  value=LINEIN(filename)   /* discard the call sqldbs */
  348.                  value=LINEIN(filename)   /* discard the IF check */
  349.                  value=LINEIN(filename)   /* discard the message box */
  350.                  value=LINEIN(filename)   /* discard the end */
  351.                  value=LINEIN(filename)   /* discard the else */
  352.                  value=LINEIN(filename)   /* discard the message box */
  353.                  CALL LINEOUT tempfile, "END"   /* put back the end */
  354.                end
  355.          OTHERWISE  /* otherwise just output the lines */
  356.             CALL LINEOUT tempfile,value
  357.          END  /* SELECT */
  358.       END  /* Do */
  359. END /* IF LENGTH */
  360. rc=stream(filename,'c','close') 
  361. rc=stream(tempfile,'c','close') 
  362. "copy "tempfile" "filename
  363. return
  364.  
  365. SingleQuoteAdd:
  366. /*****************************************************/
  367. /* Put the SQUOTEIT call in the Add event            */
  368. /*****************************************************/
  369. filename=AddPB
  370. tempfile='TEMPFILE'
  371. rc=stream(filename,'c','close') 
  372. rc=SysFileDelete(tempfile)
  373. IF LENGTH(filename) > 0 THEN DO
  374.       DO WHILE LINES(filename)   /* copy up to the get field values */
  375.          value=LINEIN(filename)
  376.          CALL LINEOUT tempfile, value
  377.          if pos("get the field values",value) > 0 then leave
  378.       END  /* Do */
  379.  
  380.       value=LINEIN(filename)      /* read the following blank line */
  381.       CALL LINEOUT tempfile, value
  382.       do i=1 to column.0
  383.          value=LINEIN(filename)
  384.          ColType = ColumnType.i
  385.          do k=1 to column.0
  386.              if word(value,1) = column.k then Coltype = ColumnType.k
  387.          end
  388.          Vstart=pos("VpGetItemValue",value)  /* process the current VpGetItemValue */
  389.          value = insert('squoteit(',value,Vstart-1)
  390.          Vend=pos(")",value)
  391.          value = insert(','||"'"||ColType||"'"||')',value,Vend)
  392.          quote=pos('"',value)          /* eliminate the "'" from both ends - not needed */
  393.          do while quote > 0
  394.             value = delstr(value,quote,3)
  395.             quote=pos('"',value)
  396.          end
  397.          CALL LINEOUT tempfile, value
  398.       end /* do i */
  399.       do while lines(filename)   /* copy the rest of the file */
  400.          value=LINEIN(filename)
  401.          call LINEOUT tempfile, value
  402.       end /* do */
  403.          
  404. END /* IF LENGTH */
  405. rc=stream(filename,'c','close') 
  406. rc=stream(tempfile,'c','close') 
  407. "copy "tempfile" "filename
  408. return
  409.  
  410. SingleQuoteChange:
  411. /********************************************/
  412. /* Put the SQUOTEIT call in the Change event         */
  413. /********************************************/
  414. filename=ChangePB
  415. tempfile='TEMPFILE'
  416. rc=stream(filename,'c','close')
  417. rc=SysFileDelete(tempfile)
  418. IF LENGTH(filename) > 0 THEN DO
  419.       DO WHILE LINES(filename)   /* copy up to the get field values */
  420.          value=LINEIN(filename)
  421.          CALL LINEOUT tempfile, value
  422.          if pos("get the field values",value) > 0 then leave
  423.       END  /* Do */
  424.  
  425.       value=LINEIN(filename)      /* read the following blank line */
  426.       CALL LINEOUT tempfile, value
  427.       do i=1 to column.0
  428.          value=LINEIN(filename)
  429.          ColType = ColumnType.i
  430.          do k=1 to column.0
  431.              if word(value,1) = column.k then Coltype = ColumnType.k
  432.          end
  433.          Vstart=pos("VpGetItemValue",value)  /* process the current VpGetItemValue */
  434.          value = insert('squoteit(',value,Vstart-1)
  435.          Vend=pos(")",value)
  436.          value = insert(','||"'"||ColType||"'"||')',value,Vend)
  437.          quote=pos('"',value)          /* eliminate the "'" from both ends - not needed */
  438.          do while quote > 0
  439.             value = delstr(value,quote,3)
  440.             quote=pos('"',value)
  441.          end
  442.          CALL LINEOUT tempfile, value
  443.       end /* do i */
  444.       do while lines(filename)   /* copy the rest of the file */
  445.          value=LINEIN(filename)
  446.          call LINEOUT tempfile, value
  447.       end /* do */
  448.  
  449. END /* IF LENGTH */
  450. rc=stream(filename,'c','close')
  451. rc=stream(tempfile,'c','close')
  452. "copy "tempfile" "filename
  453. return
  454.  
  455. DelStartUsingFromChange:
  456. /**********************************************************/
  457. /* delete Start Using database code from the Change event */
  458. /**********************************************************/
  459. filename=ChangePB
  460. tempfile='TEMPFILE'
  461. rc=stream(filename,'c','close')
  462. rc=SysFileDelete(tempfile)
  463. CALL LINEOUT tempfile, "/* Change Pushbutton Event */"
  464. CALL LINEOUT tempfile, '/* 'filename' */'
  465. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  466. CALL LINEOUT tempfile, ''
  467. IF LENGTH(filename) > 0 THEN DO
  468.       j=0
  469.       /* get START USING DATABASE CODE and delete it from the event */
  470.       DO WHILE LINES(filename)
  471.          value=LINEIN(filename)
  472.          select
  473.             when pos("start the dbase and",value) > 0
  474.                then do
  475.                  CALL LINEOUT tempfile,"/* run the SQL */"
  476.                end
  477.             when pos("call sqldbs 'START USING DATABASE",value) > 0
  478.                then do
  479.                  StartDBCode=value
  480.                  CALL LINEOUT tempfile,"DO"
  481.                  value=LINEIN(filename)   /* discard the original if */
  482.                end
  483.             when pos("stop using the database",value) > 0
  484.                then do  /* discard the next few lines */
  485.                  value=LINEIN(filename)   /* discard the call sqldbs */
  486.                  value=LINEIN(filename)   /* discard the IF check */
  487.                  value=LINEIN(filename)   /* discard the message box */
  488.                  value=LINEIN(filename)   /* discard the end */
  489.                  value=LINEIN(filename)   /* discard the else */
  490.                  value=LINEIN(filename)   /* discard the message box */
  491.                  CALL LINEOUT tempfile, "END"   /* put back the end */
  492.                end
  493.          OTHERWISE  /* otherwise just output the lines */
  494.             CALL LINEOUT tempfile,value
  495.          END  /* SELECT */
  496.       END  /* Do */
  497. END /* IF LENGTH */
  498. rc=stream(filename,'c','close')
  499. rc=stream(tempfile,'c','close')
  500. "copy "tempfile" "filename
  501. return
  502.  
  503. SingleQuoteDelete:
  504. /********************************************/
  505. /* Put the SQUOTEIT call in the Delete event          */
  506. /********************************************/
  507. filename=DeletePB
  508. tempfile='TEMPFILE'
  509. rc=stream(filename,'c','close')
  510. rc=SysFileDelete(tempfile)
  511. IF LENGTH(filename) > 0 THEN DO
  512.       DO WHILE LINES(filename)   /* copy up to the get field values */
  513.          value=LINEIN(filename)
  514.          CALL LINEOUT tempfile, value
  515.          if pos("get the field values",value) > 0 then leave
  516.       END  /* Do */
  517.  
  518.       value=LINEIN(filename)      /* read the following blank line */
  519.       CALL LINEOUT tempfile, value
  520.       do i=1 to column.0
  521.          value=LINEIN(filename)
  522.          ColType = ColumnType.i
  523.          do k=1 to column.0
  524.              if word(value,1) = column.k then Coltype = ColumnType.k
  525.          end
  526.          Vstart=pos("VpGetItemValue",value)  /* process the current VpGetItemValue */
  527.          if Vstart > 0 then do   /* only change VpGetItemValue lines */
  528.             value = insert('squoteit(',value,Vstart-1)
  529.             Vend=pos(")",value)
  530.             value = insert(','||"'"||ColType||"'"||')',value,Vend)
  531.             quote=pos('"',value)          /* eliminate the "'" from both ends - not needed */
  532.             do while quote > 0
  533.                value = delstr(value,quote,3)
  534.                quote=pos('"',value)
  535.             end
  536.          end
  537.          CALL LINEOUT tempfile, value
  538.       end /* do i */
  539.       do while lines(filename)   /* copy the rest of the file */
  540.          value=LINEIN(filename)
  541.          call LINEOUT tempfile, value
  542.       end /* do */
  543.  
  544. END /* IF LENGTH */
  545. rc=stream(filename,'c','close')
  546. rc=stream(tempfile,'c','close')
  547. "copy "tempfile" "filename
  548. return
  549.  
  550. DelStartUsingFromDelete:
  551. /**********************************************************/
  552. /* delete Start Using database code from the Delete event */
  553. /**********************************************************/
  554. filename=DeletePB
  555. tempfile='TEMPFILE'
  556. rc=stream(filename,'c','close')
  557. rc=SysFileDelete(tempfile)
  558. CALL LINEOUT tempfile, "/* Delete Pushbutton Event */"
  559. CALL LINEOUT tempfile, '/* 'filename' */'
  560. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  561. CALL LINEOUT tempfile, ''
  562. IF LENGTH(filename) > 0 THEN DO
  563.       j=0
  564.       /* get START USING DATABASE CODE and delete it from the event */
  565.       DO WHILE LINES(filename)
  566.          value=LINEIN(filename)
  567.          select
  568.             when pos("start the dbase and",value) > 0
  569.                then do
  570.                  CALL LINEOUT tempfile,"/* run the SQL */"
  571.                end
  572.             when pos("call sqldbs 'START USING DATABASE",value) > 0
  573.                then do
  574.                  StartDBCode=value
  575.                  CALL LINEOUT tempfile,"DO"
  576.                  value=LINEIN(filename)   /* discard the original if */
  577.                end
  578.             when pos("stop using the database",value) > 0
  579.                then do  /* discard the next few lines */
  580.                  value=LINEIN(filename)   /* discard the call sqldbs */
  581.                  value=LINEIN(filename)   /* discard the IF check */
  582.                  value=LINEIN(filename)   /* discard the message box */
  583.                  value=LINEIN(filename)   /* discard the end */
  584.                  value=LINEIN(filename)   /* discard the else */
  585.                  value=LINEIN(filename)   /* discard the message box */
  586.                  CALL LINEOUT tempfile, "END"   /* put back the end */
  587.                end
  588.          OTHERWISE  /* otherwise just output the lines */
  589.             CALL LINEOUT tempfile,value
  590.          END  /* SELECT */
  591.       END  /* Do */
  592. END /* IF LENGTH */
  593. rc=stream(filename,'c','close')
  594. rc=stream(tempfile,'c','close')
  595. "copy "tempfile" "filename
  596. return
  597.  
  598. CommentToClear:
  599. /**********************************/
  600. /* Add comment to the Clear event */
  601. /**********************************/
  602. filename=ClearPB
  603. tempfile='TEMPFILE'
  604. rc=stream(filename,'c','close')
  605. rc=SysFileDelete(tempfile)
  606. CALL LINEOUT tempfile, "/* Clear Pushbutton Event */"
  607. CALL LINEOUT tempfile, '/* 'filename' */'
  608. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  609. CALL LINEOUT tempfile, ''
  610. IF LENGTH(filename) > 0 THEN DO
  611.       DO WHILE LINES(filename)
  612.          value=LINEIN(filename)
  613.          CALL LINEOUT tempfile,value
  614.       END  /* Do */
  615. END /* IF LENGTH */
  616. rc=stream(filename,'c','close')
  617. rc=stream(tempfile,'c','close')
  618. "copy "tempfile" "filename
  619. return
  620.  
  621. CommentToContainerClick:
  622. /*************************************************/
  623. /* Add comment to the Container Clicked on event */
  624. /*************************************************/
  625. filename=ContainerClicked
  626. tempfile='TEMPFILE'
  627. rc=stream(filename,'c','close')
  628. rc=SysFileDelete(tempfile)
  629. CALL LINEOUT tempfile, "/* Container Clicked on Event */"
  630. CALL LINEOUT tempfile, '/* 'filename' */'
  631. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  632. CALL LINEOUT tempfile, ''
  633. IF LENGTH(filename) > 0 THEN DO
  634.       DO WHILE LINES(filename)
  635.          value=LINEIN(filename)
  636.          CALL LINEOUT tempfile,value
  637.       END  /* Do */
  638. END /* IF LENGTH */
  639. rc=stream(filename,'c','close')
  640. rc=stream(tempfile,'c','close')
  641. "copy "tempfile" "filename
  642. return
  643.  
  644. CollapseFix:
  645. /******************************************************/
  646. /* Add collapse fix to the Container Clicked on event */
  647. /******************************************************/
  648. filename=ContainerClicked
  649. tempfile='TEMPFILE'
  650. rc=stream(filename,'c','close')
  651. rc=SysFileDelete(tempfile)
  652. IF LENGTH(filename) > 0 THEN DO
  653.       DO WHILE LINES(filename)  /* read past the Arg line */
  654.          value=LINEIN(filename)
  655.          CALL LINEOUT tempfile,value
  656.          if pos("Arg window",value) then leave
  657.       END  /* Do */
  658.       CALL LINEOUT tempfile, " "
  659.       CALL LINEOUT tempfile, "/* The following line fixes a VisPro REXX bug that causes     */ "
  660.       CALL LINEOUT tempfile, "/* the application to close when doing a SEARCH without       */ "
  661.       CALL LINEOUT tempfile, "/* first clearing the fields. It causes some extra iterations */ "
  662.       CALL LINEOUT tempfile, "/* of this event but at least your app doesn't collapse.      */ "
  663.       CALL LINEOUT tempfile, "/* Remove this line when VisPro gets fixed.                   */ "
  664.       CALL LINEOUT tempfile, " "
  665.       CALL LINEOUT tempfile, "/* For an interesting variation on this theme, copy all of the*/ "
  666.       CALL LINEOUT tempfile, "/* code from this event into the double-click event for this  */ "
  667.       CALL LINEOUT tempfile, "/* object. Then delete this (single click) event. It allows   */ "
  668.       CALL LINEOUT tempfile, "/* the SEARCH criteria to remain in the fields until you click*/ "
  669.       CALL LINEOUT tempfile, "/* twice on a container record. This allows easy refinement of*/ "
  670.       CALL LINEOUT tempfile, "/* searches as needed.                                        */ "
  671.       CALL LINEOUT tempfile, " "
  672.       CALL LINEOUT tempfile, "index=VpGetIndex(window,'SEARCHCNR','SELECTED',0)  /* collapse fix */ "
  673.  
  674.       DO WHILE LINES(filename)   /* copy the rest of the file */
  675.          value=LINEIN(filename)
  676.          CALL LINEOUT tempfile,value
  677.       END  /* Do */
  678. END /* IF LENGTH */
  679. rc=stream(filename,'c','close')
  680. rc=stream(tempfile,'c','close')
  681. "copy "tempfile" "filename
  682. return
  683.  
  684. SingleQuoteWildCardSearch:
  685. /*****************************************************/
  686. /* Put the SQUOTEWC call in the Search event         */
  687. /*****************************************************/
  688. filename=SearchPB
  689. tempfile='TEMPFILE'
  690. rc=stream(filename,'c','close')
  691. rc=SysFileDelete(tempfile)
  692. IF LENGTH(filename) > 0 THEN DO
  693.       DO WHILE LINES(filename)   /* copy up to the get field values */
  694.          value=LINEIN(filename)
  695.          CALL LINEOUT tempfile, value
  696.          if pos("get the field values",value) > 0 then leave
  697.       END  /* Do */
  698.  
  699.       value=LINEIN(filename)      /* read the following blank line */
  700.       CALL LINEOUT tempfile, value
  701.       do i=1 to column.0
  702.          value=LINEIN(filename)
  703.          ColType = ColumnType.i
  704.          do k=1 to column.0
  705.              if word(value,1) = column.k then Coltype = ColumnType.k
  706.          end
  707.          Vstart=pos("VpGetItemValue",value)  /* process the current VpGetItemValue */
  708.          value = insert('squotewc(',value,Vstart-1)
  709.          Vend=pos(")",value)
  710.          value = insert(','||"'"||ColType||"'"||')',value,Vend)
  711.          quote=pos('"',value)          /* eliminate the "'" from both ends - not needed */
  712.          do while quote > 0
  713.             value = delstr(value,quote,3)
  714.             quote=pos('"',value)
  715.          end
  716.          CALL LINEOUT tempfile, value
  717.       end /* do i */
  718.       do while lines(filename)   /* copy the rest of the file */
  719.          value=LINEIN(filename)
  720.          call LINEOUT tempfile, value
  721.       end /* do */
  722.  
  723. END /* IF LENGTH */
  724. rc=stream(filename,'c','close')
  725. rc=stream(tempfile,'c','close')
  726. "copy "tempfile" "filename
  727. return
  728.  
  729. DelStartUsingFromSearch:
  730. /**********************************************************/
  731. /* delete Start Using database code from the Search event */
  732. /**********************************************************/
  733. filename=SearchPB
  734. tempfile='TEMPFILE'
  735. rc=stream(filename,'c','close')
  736. rc=SysFileDelete(tempfile)
  737. CALL LINEOUT tempfile, "/* Search Pushbutton Event */"
  738. CALL LINEOUT tempfile, '/* 'filename' */'
  739. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  740. CALL LINEOUT tempfile, ''
  741. IF LENGTH(filename) > 0 THEN DO
  742.       j=0
  743.       /* get START USING DATABASE CODE and delete it from the event */
  744.       DO WHILE LINES(filename)
  745.          value=LINEIN(filename)
  746.          select
  747.             when pos("start the dbase and",value) > 0
  748.                then do
  749.                  CALL LINEOUT tempfile,"/* run the SQL */"
  750.                end
  751.             when pos("call sqldbs 'START USING DATABASE",value) > 0
  752.                then do
  753.                  CALL LINEOUT tempfile,"DO"
  754.                  value=LINEIN(filename)   /* discard the original if */
  755.                end
  756.             when pos("stop using the database",value) > 0
  757.                then do  /* discard the next few lines */
  758.                  value=LINEIN(filename)   /* discard the call sqldbs */
  759.                  value=LINEIN(filename)   /* discard the IF check */
  760.                  value=LINEIN(filename)   /* discard the message box */
  761.                  value=LINEIN(filename)   /* discard the end */
  762.                  value=LINEIN(filename)   /* discard the end */
  763.                  value=LINEIN(filename)   /* discard the else */
  764.                  value=LINEIN(filename)   /* discard the message box */
  765.                  CALL LINEOUT tempfile, "   end"   /* put back the end */
  766.                  CALL LINEOUT tempfile, "END"   /* put back the end */
  767.                end
  768.          OTHERWISE  /* otherwise just output the lines */
  769.             CALL LINEOUT tempfile,value
  770.          END  /* SELECT */
  771.       END  /* Do */
  772. END /* IF LENGTH */
  773. rc=stream(filename,'c','close')
  774. rc=stream(tempfile,'c','close')
  775. "copy "tempfile" "filename
  776. return
  777.  
  778. StartUsingInFormOpen:
  779. /*********************************************************/
  780. /* put the Start Using database code into the FORM OPEN  */
  781. /*********************************************************/
  782. filename=FormOpen
  783. tempfile='TEMPFILE'
  784. rc=stream(filename,'c','close')
  785. rc=SysFileDelete(tempfile)
  786. CALL LINEOUT tempfile, "/* Form Open Event */"
  787. CALL LINEOUT tempfile, '/* 'filename' */'
  788. CALL LINEOUT tempfile, '/* 'author' 'today' 'version' */'
  789. CALL LINEOUT tempfile, ''
  790. IF LENGTH(filename) > 0 THEN DO
  791.       DO WHILE LINES(filename)
  792.          value=LINEIN(filename)
  793.          CALL LINEOUT tempfile, value
  794.       END  /* Do */
  795.       CALL LINEOUT tempfile, "  "
  796.       CALL LINEOUT tempfile, "/* Start using the database */"
  797.       CALL LINEOUT tempfile, "  "
  798.       CALL LINEOUT tempfile, StartDBCode
  799.       CALL LINEOUT tempfile, "IF SQLCA.SQLCODE <> 0 then"
  800.       CALL LINEOUT tempfile, "CALL VpMessageBox window, 'Error Starting Database : 'SQLCA.SQLCODE, SQLCA.SQLMSG"
  801. END /* IF LENGTH */
  802. rc=stream(filename,'c','close')
  803. rc=stream(tempfile,'c','close')
  804. "copy "tempfile" "filename
  805. return
  806.  
  807. InsertColNamesForAdd:
  808. /*************************************************************/
  809. /* put column names in the INSERT statement in the ADD event */
  810. /*************************************************************/
  811. filename=AddPB
  812. tempfile='TEMPFILE'
  813. rc=stream(filename,'c','close')
  814. rc=SysFileDelete(tempfile)
  815. IF LENGTH(filename) > 0 THEN DO
  816.       /* get down to the prep string statement */
  817.       DO WHILE LINES(filename)
  818.          value=LINEIN(filename)
  819.          if pos("prep_string",value) > 0 then leave
  820.          CALL LINEOUT tempfile, value
  821.       END  /* Do */
  822.       CALL LINEOUT tempfile, value   /* prep_string */
  823.       do i = 1 to column.0
  824.          select
  825.             when i=1 then do
  826.                d1="'"
  827.                d2="("
  828.                d3=",'"
  829.                d4=","
  830.              end  /* Do */
  831.             when i=column.0 then do
  832.                d1="'"
  833.                d2=""
  834.                d3=")"
  835.                d4="',"
  836.             end  /* Do */
  837.          otherwise
  838.                d1="'"
  839.                d2=""
  840.                d3=",'"
  841.                d4=","
  842.          end  /* select */
  843.          CALL LINEOUT tempfile, "                    "||d1||d2||column.i||d3||d4
  844.       end /* do */
  845.       DO WHILE LINES(filename)    /* append the rest of the file */
  846.          value=LINEIN(filename)
  847.          CALL LINEOUT tempfile, value
  848.       END  /* Do */
  849. END /* IF LENGTH */
  850. rc=stream(filename,'c','close')
  851. rc=stream(tempfile,'c','close')
  852. "copy "tempfile" "filename
  853. return
  854.  
  855. ColNamesForSelect:
  856. /****************************************************************/
  857. /* put column names in the SELECT statement in the SEARCH event */
  858. /* and make sure all FETCH columns have indicator variables.    */
  859. /****************************************************************/
  860. filename=SearchPB
  861. tempfile='TEMPFILE'
  862. rc=stream(filename,'c','close')
  863. rc=SysFileDelete(tempfile)
  864. IF LENGTH(filename) > 0 THEN DO
  865.       /* get down to the prep string statement */
  866.       DO WHILE LINES(filename)
  867.          value=LINEIN(filename)
  868.          if pos("prep_string",value) > 0 then leave
  869.          CALL LINEOUT tempfile, value
  870.       END  /* Do */
  871.       CALL LINEOUT tempfile, "prep_string = 'SELECT ',"
  872.       do i = 1 to column.0
  873.          select
  874.             when i=1 then do
  875.                d1="'"
  876.                d2=""
  877.                d3=",'"
  878.                d4=","
  879.              end  /* Do */
  880.             when i=column.0 then do
  881.                d1="'"
  882.                d2=""
  883.                d3=""
  884.                d4="',"
  885.             end  /* Do */
  886.          otherwise
  887.                d1="'"
  888.                d2=""
  889.                d3=",'"
  890.                d4=","
  891.          end  /* select */
  892.          CALL LINEOUT tempfile, "                    "||d1||d2||column.i||d3||d4
  893.       end /* do */
  894.       /* get down to the FETCH prep string statement */
  895.       DO WHILE LINES(filename)
  896.          value=LINEIN(filename)
  897.          if pos("prep_string = 'FETCH",value) > 0 then leave
  898.          CALL LINEOUT tempfile, value
  899.       END  /* Do */
  900.       CALL LINEOUT tempfile, value  /* ouput the FETCH */
  901.       do i = 1 to column.0
  902.          select
  903.             when i=1 then do
  904.                d1="'"
  905.                d2=""
  906.                d3=",'"
  907.                d4=","
  908.              end  /* Do */
  909.             when i=column.0 then do
  910.                d1="'"
  911.                d2=""
  912.                d3=""
  913.                d4="'"
  914.             end  /* Do */
  915.          otherwise
  916.                d1="'"
  917.                d2=""
  918.                d3=",'"
  919.                d4=","
  920.          end  /* select */
  921.          value=LINEIN(filename) /* skip over the corresponding column */
  922.          CALL LINEOUT tempfile, "                    "||d1||d2||":"||column.i||":N_"||column.i||d3||d4
  923.       end /* do */
  924.       DO WHILE LINES(filename)    /* append the rest of the file */
  925.          value=LINEIN(filename)
  926.          CALL LINEOUT tempfile, value
  927.       END  /* Do */
  928. END /* IF LENGTH */
  929. rc=stream(filename,'c','close')
  930. rc=stream(tempfile,'c','close')
  931. "copy "tempfile" "filename
  932. return
  933.  
  934. BuildWhereInSearch:
  935. /*******************************************************/
  936. /* add dynamic where clause in the SELECT statement    */
  937. /* in the SEARCH event                                 */
  938. /*******************************************************/
  939. filename=SearchPB
  940. tempfile='TEMPFILE'
  941. rc=stream(filename,'c','close')
  942. rc=SysFileDelete(tempfile)
  943. IF LENGTH(filename) > 0 THEN DO
  944.       /* get down to the prepare SQL string comment */
  945.       DO WHILE LINES(filename)
  946.          value=LINEIN(filename)
  947.          CALL LINEOUT tempfile, value
  948.          if pos("prepare the SQL string",value) > 0 then leave
  949.       END  /* Do */
  950.       CALL LINEOUT tempfile, "j=0"
  951.       do i = 1 to column.0
  952.          select
  953.             when ColumnType.i = 'C' then 
  954.                comparator = 'LIKE'
  955.             otherwise
  956.                comparator = '='
  957.             end  /* select */
  958.          CALL LINEOUT tempfile, "if "||column.i||" <> '' then do" 
  959.          CALL LINEOUT tempfile, "   j=j+1" 
  960.          CALL LINEOUT tempfile, "   WhereClause.j ="||'"'||column.i comparator ||'" 'column.i
  961.          CALL LINEOUT tempfile, "end"
  962.       end /* do */
  963. /* now generate the code to generate the where clause */
  964. CALL LINEOUT tempfile, "WhereString = '' "
  965. CALL LINEOUT tempfile, "if j > 0 then"
  966. CALL LINEOUT tempfile, "   do i=1 to j"
  967. CALL LINEOUT tempfile, "      select"
  968. CALL LINEOUT tempfile, "         when i=1"
  969. CALL LINEOUT tempfile, "           then LogicOper='WHERE '"
  970. CALL LINEOUT tempfile, "         Otherwise"
  971. CALL LINEOUT tempfile, "              LogicOper='AND '"
  972. CALL LINEOUT tempfile, "      end  /* select */"
  973. CALL LINEOUT tempfile, "      WhereString = WhereString LogicOper WhereClause.i"
  974. CALL LINEOUT tempfile, "end /* IF j */"
  975.       DO WHILE LINES(filename)    /* append up to the 'FROM */
  976.          value=LINEIN(filename)
  977.          if pos("'FROM",value) > 0 then leave
  978.          CALL LINEOUT tempfile, value
  979.       END  /* Do */
  980.       CALL LINEOUT tempfile, value "WhereString"   /* append the where string */
  981.       DO WHILE LINES(filename)    /* append the rest of the file */
  982.          value=LINEIN(filename)
  983.          CALL LINEOUT tempfile, value
  984.       END  /* Do */
  985. END /* IF LENGTH */
  986. rc=stream(filename,'c','close')
  987. rc=stream(tempfile,'c','close')
  988. "copy "tempfile" "filename
  989. return
  990.  
  991. ReadLimitInSearch:
  992. /*******************************************************/
  993. /* Add read limit code to the SEARCH event as well as  */
  994. /* a No Data Found message.                            */
  995. /*******************************************************/
  996. filename=SearchPB
  997. tempfile='TEMPFILE'
  998. rc=stream(filename,'c','close')
  999. rc=SysFileDelete(tempfile)
  1000. IF LENGTH(filename) > 0 THEN DO
  1001.       /* get down to the ARG window line */
  1002.       DO WHILE LINES(filename)
  1003.          value=LINEIN(filename)
  1004.          CALL LINEOUT tempfile, value
  1005.          if pos("Arg window",value) > 0 then leave
  1006.       END  /* Do */
  1007.       CALL LINEOUT tempfile, "ReadLimit = 1000"
  1008.       /* get down to the Retrieve data FETCH loop */
  1009.       DO WHILE LINES(filename)
  1010.          value=LINEIN(filename)
  1011.          CALL LINEOUT tempfile, value
  1012.          if pos("Retrieve data from the cursor",value) > 0 then leave
  1013.       END  /* Do */
  1014.       /* get down to the sqlexec */
  1015.       DO WHILE LINES(filename)
  1016.          value=LINEIN(filename)
  1017.          CALL LINEOUT tempfile, value
  1018.          if pos("call sqlexec",value) > 0 then leave
  1019.       END  /* Do */
  1020.       CALL LINEOUT tempfile,"   if numitems >= ReadLimit then do"
  1021.       CALL LINEOUT tempfile,"      leave"
  1022.       CALL LINEOUT tempfile,"   end /* if do */"
  1023.       /* get down to close cursor statement */
  1024.       DO WHILE LINES(filename)
  1025.          value=LINEIN(filename)
  1026.          CALL LINEOUT tempfile, value
  1027.          if pos("CLOSE c1",value) > 0 then leave
  1028.       END  /* Do */
  1029.       CALL LINEOUT tempfile,"   if numitems = 0 then do"
  1030.       CALL LINEOUT tempfile,"      CALL VpMessageBox window, 'Search Complete','No Rows Matched. '"
  1031.       CALL LINEOUT tempfile,"   end /* if do */"
  1032.       CALL LINEOUT tempfile,"   if numitems >= ReadLimit then do"
  1033.       CALL LINEOUT tempfile,"      CALL VpMessageBox window, 'Search Complete','Read Limit exceeded. First 'ReadLimit' rows retrieved.'"
  1034.       CALL LINEOUT tempfile,"   end /* if do */"
  1035.  
  1036.       DO WHILE LINES(filename)    /* append the rest of the file */
  1037.          value=LINEIN(filename)
  1038.          CALL LINEOUT tempfile, value
  1039.       END  /* Do */
  1040. END /* IF LENGTH */
  1041. rc=stream(filename,'c','close')
  1042. rc=stream(tempfile,'c','close')
  1043. "copy "tempfile" "filename
  1044. return
  1045.  
  1046. NullColumnsBeforeFetch:
  1047. /***********************************************************/
  1048. /* Add code to set the FETCH column variables to '' just   */
  1049. /* prior to the fetch so that the container isn't aliased. */
  1050. /***********************************************************/
  1051. filename=SearchPB
  1052. tempfile='TEMPFILE'
  1053. rc=stream(filename,'c','close')
  1054. rc=SysFileDelete(tempfile)
  1055. IF LENGTH(filename) > 0 THEN DO
  1056.       /* get down to the retrieve data from the cursor line */
  1057.       DO WHILE LINES(filename)
  1058.          value=LINEIN(filename)
  1059.          CALL LINEOUT tempfile, value
  1060.          if pos("Retrieve data from the cursor",value) > 0 then leave
  1061.       END  /* Do */
  1062.       /* get down to the following DO WHILE loop */
  1063.       DO WHILE LINES(filename)
  1064.          value=LINEIN(filename)
  1065.          CALL LINEOUT tempfile, value
  1066.          if pos("do while",value) > 0 then leave
  1067.       END  /* Do */
  1068.       do i=1 to column.0   /* add code to set variables = '' */
  1069.          CALL LINEOUT tempfile, "      "||column.i||" = "||"''"
  1070.       end
  1071.       DO WHILE LINES(filename)    /* append the rest of the file */
  1072.          value=LINEIN(filename)
  1073.          CALL LINEOUT tempfile, value
  1074.       END  /* Do */
  1075. END /* IF LENGTH */
  1076. rc=stream(filename,'c','close')
  1077. rc=stream(tempfile,'c','close')
  1078. "copy "tempfile" "filename
  1079. return
  1080.  
  1081. CommitAddPB:
  1082. /*****************************************************/
  1083. /* Put a COMMIT at the end of the ADD event          */
  1084. /*****************************************************/
  1085. filename=AddPB
  1086. tempfile='TEMPFILE'
  1087. rc=stream(filename,'c','close') 
  1088. rc=SysFileDelete(tempfile)
  1089. IF LENGTH(filename) > 0 THEN DO
  1090.       DO WHILE LINES(filename)   /* copy up to the turn off the hour glass */
  1091.          value=LINEIN(filename)
  1092.          if pos("turn off the hour glass",value) > 0 then leave
  1093.          CALL LINEOUT tempfile, value
  1094.       END  /* Do */
  1095.       CALL LINEOUT tempfile, ' '
  1096.       CALL LINEOUT tempfile, "CALL SQLEXEC 'COMMIT'"
  1097.       CALL LINEOUT tempfile, 'if sqlca.sqlcode <> 0 then do '
  1098.       CALL LINEOUT tempfile, "   CALL VpMessageBox window, 'Error Running SQL : 'SQLCA.SQLCODE, SQLCA.SQLMSG "
  1099.       CALL LINEOUT tempfile, 'end  /* if do */ '
  1100.       CALL LINEOUT tempfile, ' '
  1101.  
  1102.       CALL LINEOUT tempfile, value  /* don't forget the hour glass comment */
  1103.  
  1104.       do while lines(filename)   /* copy the rest of the file */
  1105.          value=LINEIN(filename)
  1106.          call LINEOUT tempfile, value
  1107.       end /* do */
  1108. END /* IF LENGTH */
  1109. rc=stream(filename,'c','close') 
  1110. rc=stream(tempfile,'c','close') 
  1111. "copy "tempfile" "filename
  1112. return
  1113.  
  1114. CommitChangePB:
  1115. /*****************************************************/
  1116. /* Put a COMMIT at the end of the CHANGE event       */
  1117. /*****************************************************/
  1118. filename=ChangePB
  1119. tempfile='TEMPFILE'
  1120. rc=stream(filename,'c','close') 
  1121. rc=SysFileDelete(tempfile)
  1122. IF LENGTH(filename) > 0 THEN DO
  1123.       DO WHILE LINES(filename)   /* copy up to the turn off the hour glass */
  1124.          value=LINEIN(filename)
  1125.          if pos("turn off the hour glass",value) > 0 then leave
  1126.          CALL LINEOUT tempfile, value
  1127.       END  /* Do */
  1128.       CALL LINEOUT tempfile, ' '
  1129.       CALL LINEOUT tempfile, "CALL SQLEXEC 'COMMIT'"
  1130.       CALL LINEOUT tempfile, 'if sqlca.sqlcode <> 0 then do '
  1131.       CALL LINEOUT tempfile, "   CALL VpMessageBox window, 'Error Running SQL : 'SQLCA.SQLCODE, SQLCA.SQLMSG "
  1132.       CALL LINEOUT tempfile, 'end  /* if do */ '
  1133.       CALL LINEOUT tempfile, ' '
  1134.  
  1135.       CALL LINEOUT tempfile, value  /* don't forget the hour glass comment */
  1136.  
  1137.       do while lines(filename)   /* copy the rest of the file */
  1138.          value=LINEIN(filename)
  1139.          call LINEOUT tempfile, value
  1140.       end /* do */
  1141. END /* IF LENGTH */
  1142. rc=stream(filename,'c','close') 
  1143. rc=stream(tempfile,'c','close') 
  1144. "copy "tempfile" "filename
  1145. return
  1146.  
  1147. CommitDeletePB:
  1148. /*****************************************************/
  1149. /* Put a COMMIT at the end of the DELETE event       */
  1150. /*****************************************************/
  1151. filename=DeletePB
  1152. tempfile='TEMPFILE'
  1153. rc=stream(filename,'c','close') 
  1154. rc=SysFileDelete(tempfile)
  1155. IF LENGTH(filename) > 0 THEN DO
  1156.       DO WHILE LINES(filename)   /* copy up to the turn off the hour glass */
  1157.          value=LINEIN(filename)
  1158.          if pos("turn off the hour glass",value) > 0 then leave
  1159.          CALL LINEOUT tempfile, value
  1160.       END  /* Do */
  1161.       CALL LINEOUT tempfile, ' '
  1162.       CALL LINEOUT tempfile, "CALL SQLEXEC 'COMMIT'"
  1163.       CALL LINEOUT tempfile, 'if sqlca.sqlcode <> 0 then do '
  1164.       CALL LINEOUT tempfile, "   CALL VpMessageBox window, 'Error Running SQL : 'SQLCA.SQLCODE, SQLCA.SQLMSG "
  1165.       CALL LINEOUT tempfile, 'end  /* if do */ '
  1166.       CALL LINEOUT tempfile, ' '
  1167.  
  1168.       CALL LINEOUT tempfile, value  /* don't forget the hour glass comment */
  1169.  
  1170.       do while lines(filename)   /* copy the rest of the file */
  1171.          value=LINEIN(filename)
  1172.          call LINEOUT tempfile, value
  1173.       end /* do */
  1174. END /* IF LENGTH */
  1175. rc=stream(filename,'c','close') 
  1176. rc=stream(tempfile,'c','close') 
  1177. "copy "tempfile" "filename
  1178. return
  1179.  
  1180. ConfirmDeletePB:
  1181. /*********************************************************/
  1182. /* insert DELETE confirmation code into the DELETE event */
  1183. /*********************************************************/
  1184. filename=DeletePB
  1185. tempfile='TEMPFILE'
  1186. rc=stream(filename,'c','close') 
  1187. rc=SysFileDelete(tempfile)
  1188. IF LENGTH(filename) > 0 THEN DO
  1189.       DO WHILE LINES(filename)   /* copy up to the turn on the hour glass */
  1190.          value=LINEIN(filename)
  1191.          if pos("turn on the hour glass",value) > 0 then leave
  1192.          CALL LINEOUT tempfile, value
  1193.       END  /* Do */
  1194.       CALL LINEOUT tempfile, ' '
  1195.       CALL LINEOUT tempfile, "response=VpMessageBox(window,'DELETE Confirmation','Are you sure you wish to DELETE the row?','YESNO')"
  1196.       CALL LINEOUT tempfile, "if response = 'YES' then do /* Do it */"
  1197.       CALL LINEOUT tempfile, ' '
  1198.  
  1199.       CALL LINEOUT tempfile, value  /* don't forget the hour glass comment */
  1200.  
  1201.       do while lines(filename)   /* copy the rest of the file */
  1202.          value=LINEIN(filename)
  1203.          call LINEOUT tempfile, value
  1204.       end /* do */
  1205.       CALL LINEOUT tempfile, "END  /* if YES do */"
  1206. END /* IF LENGTH */
  1207. rc=stream(filename,'c','close') 
  1208. rc=stream(tempfile,'c','close') 
  1209. "copy "tempfile" "filename
  1210. return
  1211.  
  1212. MakeHintFile:
  1213. /*=================================================*/
  1214. /* Make FORM.HIN file TIP entries for push buttons */
  1215. /*=================================================*/
  1216. filename=pathname'\FORM.HIN'
  1217. rc=stream(filename,'c','close')
  1218. rc=SysFileDelete(filename)
  1219. nul='00'X
  1220.  
  1221. HinAdd   ='Add a row to the database.'
  1222. HinChange='Change a row in the database.'
  1223. HinDelete='Delete a row from the database.'
  1224. HinClear ='Clear screen fields.'
  1225. HinSearch='Search for records matching fields or partial strings above;',
  1226.           ' or load a limited set to container.'
  1227. Hint=         HinAdd||nul||substr(   AddPB,lastpos('\',   AddPB)+1,4)||nul
  1228. Hint=Hint||HinChange||nul||substr(ChangePB,lastpos('\',ChangePB)+1,4)||nul
  1229. Hint=Hint||HinDelete||nul||substr(DeletePB,lastpos('\',DeletePB)+1,4)||nul
  1230. Hint=Hint|| HinClear||nul||substr( ClearPB,lastpos('\', ClearPB)+1,4)||nul
  1231. Hint=Hint||HinSearch||nul||substr(SearchPB,lastpos('\',SearchPB)+1,4)||nul
  1232.  
  1233. CALL CHAROUT filename, Hint
  1234. rc=stream(filename,'c','close')
  1235. return
  1236.  
  1237. /************************************************************************/
  1238. /*      END OF SUBROUTINES                                              */
  1239. /************************************************************************/
  1240.