331 lines
		
	
	
		
			9.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			331 lines
		
	
	
		
			9.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| compile insert SQLExp_Manager_Equates
 | |
| 
 | |
| *****************************************************************************
 | |
| *
 | |
| * Name       :  SQLExp_Manager_Equates
 | |
| * Description:  Equates and internal subroutines used by the SQL Warehousing
 | |
| *               Manager and the wizard which starts the warehousing process.
 | |
| *
 | |
| * History (Date, Initials, Notes)
 | |
| *   03/03/97  cp   Original programmer
 | |
| *   06/16/97  cp   Updated for 3.5, split out of SQLExp_Manager
 | |
| *
 | |
| *****************************************************************************
 | |
| 
 | |
| goto SkipCode
 | |
| 
 | |
| 
 | |
| equ WP_ALL$ to "WP"
 | |
| 
 | |
| * values selected in the start wizard the last time run are stored in SYSENV/CFG_SQLEXP
 | |
| equ OPT_WPLIST$     to 41           ;* list of WP names to run, @vm-delim'd
 | |
| equ OPT_LOCK$       to 42           ;* 1=prevent all, 2=prevent specific, 3=prevent none
 | |
| equ OPT_CREATE$     to 43           ;* bool, TRUE$ means create tables first
 | |
| equ OPT_CLEAR$      to 44           ;* 1=clear, 2=drop/create, 3=don't clear
 | |
| equ OPT_NOTUSED45$  to 45
 | |
| equ OPT_NOTUSED46$  to 46
 | |
| equ OPT_DUALCON$    to 47           ;* TRUE$ if second non-transacted con needed
 | |
| equ OPT_SCHEDTYPE$  to 48           ;* 1=last-used sched, 2=every n seconds, 3=once apiece
 | |
| equ OPT_DELAY$      to 49           ;* delay, in seconds, between re-runs
 | |
| 
 | |
| * schedule data (amv) from the manager is stored in SYSENV/CFG_SQLEXP
 | |
| equ SCHED_WPNAME$   to 51           ;* list of wp names, @vm-delim'd
 | |
| equ SCHED_TYPE$     to 52           ;* 1=not scheduled, 2=next available, 3=certain date/time
 | |
| equ SCHED_TIME$     to 53           ;* dt value for type=3
 | |
| equ SCHED_REPEAT$   to 54           ;* TRUE$ means repeat
 | |
| equ SCHED_INTERVAL$ to 55           ;* interval in seconds
 | |
| equ SCHED_SELECT$   to 56           ;* FULL, UPDATES, or custom
 | |
| equ SCHED_CREATE$   to 57           ;* TRUE$ means this wp needs tables created
 | |
| equ SCHED_CLEAR$    to 58           ;* 1=clear, 2=drop/create, 3=none
 | |
| equ SCHED_LASTRUN$  to 59           ;* last time run
 | |
| equ SCHED_DTFMT$    to 60           ;* date format (sv), defaults to "D2/"
 | |
| 
 | |
| * manager states
 | |
| equ MGR_ST_STOP$    to 0            ;* not running
 | |
| equ MGR_ST_WAIT$    to 1            ;* waiting to exec next
 | |
| equ MGR_ST_RUN$     to 2            ;* running wp
 | |
| equ MGR_ST_PAUSE$   to 3            ;* pausing (pause button)
 | |
| equ MGR_ST_ABORT$   to 4            ;* running wp with expectation of a possible debugger abort (i.e. a wp blows up)
 | |
| 
 | |
| * proc info
 | |
| equ PROC_NAME$      to 1
 | |
| equ PROC_LASTRUN$   to 2
 | |
| equ PROC_NEXTRUN$   to 3
 | |
| equ PROC_TYPE$      to 4            ;* see SCHED_TYPE$
 | |
| equ PROC_TIME$      to 5            ;* see SCHED_TIME$
 | |
| equ PROC_REPEAT$    to 6            ;* see SCHED_REPEAT$
 | |
| equ PROC_INTERVAL$  to 7            ;* see SCHED_INTERVAL$
 | |
| equ PROC_SELECT$    to 8            ;* see SCHED_SELECT$
 | |
| equ PROC_CREATE$    to 9            ;* see SCHED_CREATE$
 | |
| equ PROC_CLEAR$     to 10           ;* see SCHED_CLEAR$
 | |
| equ PROC_FIRST$     to 11           ;* TRUE$ if proc hasn't been run yet (used for create table logic)
 | |
| equ PROC_SCHED$     to 12           ;* time at which proc is scheduled to run
 | |
| 
 | |
| 
 | |
| *********************
 | |
| * bulk get properties
 | |
| *********************
 | |
| GetProps:
 | |
|   swap "@" with @window in Ctrls
 | |
|   convert "," to @rm in Ctrls
 | |
|   convert "," to @rm in Props
 | |
|   Vals = Get_Property(Ctrls, Props)
 | |
| return
 | |
| 
 | |
| 
 | |
| *********************
 | |
| * bulk set properties
 | |
| *********************
 | |
| SetProps:
 | |
|   swap "@" with @window in Ctrls
 | |
|   convert "," to @rm in Ctrls
 | |
|   convert "," to @rm in Props
 | |
|   Set_Property(Ctrls, Props, Vals)
 | |
| return
 | |
| 
 | |
| 
 | |
| ***********************
 | |
| * display error message
 | |
| ***********************
 | |
| * Error [in ] - text of error message
 | |
| * Ret   [out] - failure
 | |
| ErrMsg:
 | |
|   Error<MICON$>    = "H"
 | |
|   Error<MCAPTION$> = Get_Property(@window, "TEXT")
 | |
|   Msg(@window, Error)
 | |
|   Ret = FALSE$
 | |
| return
 | |
| 
 | |
| 
 | |
| **********************
 | |
| * display info message
 | |
| **********************
 | |
| * Error [in ] - text of info message
 | |
| InfoMsg:
 | |
|   Error<MICON$>    = "!"
 | |
|   Error<MCAPTION$> = Get_Property(@window, "TEXT")
 | |
|   Msg(@window, Error)
 | |
| return
 | |
| 
 | |
| 
 | |
| ******************
 | |
| * add error to log
 | |
| ******************
 | |
| * Error [in ] - text to log (can be @fm-delim'd for multi errors)
 | |
| LogError:
 | |
|   Limit = Get_Property(@window: ".ET_LOG", "LIMIT") <2>
 | |
|   if Limit < 1000 then
 | |
|    * remove blank errors
 | |
|     convert " ":@fm to @fm:" " in Error
 | |
|     Error = trim(Error)
 | |
|     convert " ":@fm to @fm:" " in Error
 | |
| 
 | |
|    * stamp each error with currrent time
 | |
|     Error = @fm: Error
 | |
|     Limit += count(Error, @fm)
 | |
|     if Limit >= 1000 then
 | |
|       Error := @fm: "<Log Truncated>"
 | |
|     end
 | |
|     dFmt = Get_Property(@window, "@OPTIONS") <SCHED_DTFMT$>
 | |
|     swap @fm with (@fm: fmt(date(), dFmt): " ": fmt(time(), "MTS"): @vm) in Error
 | |
|     Error [1,1] = ""
 | |
| 
 | |
|    * append to error log
 | |
|     Send_Message(@window: ".ET_LOG", "INSERT", -1, Error)
 | |
|     Set_Property(@window: ".CB_REVIEW", "ENABLED", TRUE$)
 | |
|   end
 | |
| return
 | |
| 
 | |
| 
 | |
| ***************************
 | |
| * lock warehouse procedures
 | |
| ***************************
 | |
| * Type   [in ] - 1=all, 2=specific, 3=none
 | |
| * List   [in ] - @fm-delim'd list of procs
 | |
| * Init   [in ] - TRUE$ if this is the first lock attempt
 | |
| * Ret    [out] - TRUE$ on success, FALSE$ on failure
 | |
| * Error  [out] - description on failure
 | |
| LockProcs:
 | |
|   Ret = TRUE$
 | |
|   if Type and len(List) else return
 | |
| 
 | |
|   open "SYSENV" to f else
 | |
|     Error = "Unable to open SYSENV."
 | |
|     Ret = FALSE$
 | |
|     return
 | |
|   end
 | |
| 
 | |
|  * type 1 puts an exclusive (obtrusive) lock on "all"
 | |
|   if Type = 1 then
 | |
|     if Init then
 | |
|       lock f, WP_ALL$, X else
 | |
|         Error = "Another workstation is already using the Warehouse Manager."
 | |
|         Ret = FALSE$
 | |
|       end
 | |
|     end
 | |
|     return
 | |
|   end
 | |
| 
 | |
|  * types 2&3 put a shared (non-obtrusive) lock on "all"
 | |
|   if Init then
 | |
|     lock f, WP_ALL$, S else
 | |
|       Error  = "Another workstation is already using the Warehouse Manager "
 | |
|       Error := "and has prevented other workstations from warehousing."
 | |
|       Ret = FALSE$
 | |
|       return
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   Count = count(List, @fm) + (List # "")
 | |
|   Pos   = 1
 | |
|   loop
 | |
|   while Pos <= Count
 | |
|     Text = List<Pos>
 | |
|     if Type = 2 then
 | |
|      * type 2 puts an exclusive (obtrusive) lock on each warehouse procedure
 | |
|       lock f, Text, X else
 | |
|         Error  = "Another workstation is already using the ": Text: " Warehouse Procedure."
 | |
|         Ret = FALSE$
 | |
|       end
 | |
|     end else
 | |
|      * type 3 puts a shared (non-obtrusive) lock on each warehouse procedure,
 | |
|      * but detects if a workstation has an exclusive (obtrusive) lock already
 | |
|       lock f, Text, S else
 | |
|         Error  = "Another workstation is already using the Warehouse Manager "
 | |
|         Error := "and has prevented other workstations from executing the "
 | |
|         Error := Text: " Warehouse Procedure."
 | |
|         Ret = FALSE$
 | |
|       end
 | |
|     end
 | |
|   while Ret
 | |
|     Pos += 1
 | |
|   repeat
 | |
| 
 | |
|   if Ret else
 | |
|    * unlock each wp that was successfully locked
 | |
|     Count = Pos - 1
 | |
|     for i = 1 to Count
 | |
|       unlock f, List<i> else null
 | |
|     next i
 | |
| 
 | |
|     if Init then
 | |
|      * remove the lock from "all"
 | |
|       unlock f, WP_ALL$ else null
 | |
|     end
 | |
|   end
 | |
| return
 | |
| 
 | |
| 
 | |
| *****************************
 | |
| * unlock warehouse procedures
 | |
| *****************************
 | |
| * Type   [in ] - 1=all, 2=specific, 3=none
 | |
| * List   [in ] - @fm-delim'd list of procs
 | |
| * Final  [in ] - TRUE$ means this is unlocking all procs
 | |
| * Ret    [out] - TRUE$ on success, FALSE$ on failure
 | |
| * Error  [out] - description on failure
 | |
| UnlockProcs:
 | |
|   Ret = TRUE$
 | |
|   if Type else return
 | |
| 
 | |
|   open "SYSENV" to f else
 | |
|     Error = "Unable to open SYSENV."
 | |
|     Ret = FALSE$
 | |
|     return
 | |
|   end
 | |
| 
 | |
|  * type 1 only bothers to put an exclusive lock on "all";
 | |
|  * the other types use exclusive or shared record locks on the wp's
 | |
|   if Type > 1 and len(List) then
 | |
|     Count = count(List, @fm) + (List # "")
 | |
|     for i = 1 to Count
 | |
|       unlock f, List<i> else null
 | |
|     next i
 | |
|   end
 | |
| 
 | |
|   if Final then
 | |
|     unlock f, WP_ALL$ else null
 | |
|   end
 | |
| return
 | |
| 
 | |
| 
 | |
| ******************************
 | |
| * check if time interval is ok
 | |
| ******************************
 | |
| * Text   [in ] - time interval string
 | |
| * Value  [out] - time interval in seconds (only if ok)
 | |
| * Ret    [out] - TRUE$ if ok, FALSE$ otherwise
 | |
| CheckInterval:
 | |
|   Ret   = TRUE$
 | |
|   Value = 0
 | |
|   Count = count(Text, ":") + (Text # "")
 | |
| 
 | |
|   if Count < 1 or Count > 3 then
 | |
|     Ret = FALSE$
 | |
|     return
 | |
|   end
 | |
| 
 | |
|   for i = 1 to Count
 | |
|     Temp = field(Text, ":", Count - i + 1)
 | |
|     Test = Temp
 | |
|     convert "0123456789" to "" in Test
 | |
|     if num(Temp) and len(Temp) and not(len(Test)) then
 | |
|       if Temp >= 0 and Temp <= 59 then
 | |
|         Value += Temp * field("1,60,3600", ",", i)
 | |
|       end else
 | |
|         Ret = FALSE$
 | |
|         return
 | |
|       end
 | |
|     end else
 | |
|       Ret = FALSE$
 | |
|       return
 | |
|     end
 | |
|   next i
 | |
| 
 | |
|  * zero not allowed
 | |
|   if Value else
 | |
|     Ret = FALSE$
 | |
|   end
 | |
| return
 | |
| 
 | |
| 
 | |
| *************************************
 | |
| * format seconds into interval string
 | |
| *************************************
 | |
| * Value  [in ] - time interval in seconds
 | |
| * Text   [out] - time interval string
 | |
| FormatInterval:
 | |
|   Text   = fmt(int(Value / 3600), "R(0)#2"): ":": fmt(int(mod(Value, 3600) / 60), "R(0)#2"): ":": fmt(mod(Value, 60), "R(0)#2")
 | |
| return
 | |
| 
 | |
| 
 | |
| ******************************
 | |
| * build list of available WP's
 | |
| ******************************
 | |
| * Procs [out] - @fm-delim'd list of procs
 | |
| GetProcs:
 | |
|   More  = 1
 | |
|   Procs = ""
 | |
|   *loop
 | |
|     List  = Get_Repos_Entities(@appid<1>, "STPROCEXE", "", FALSE$, FALSE$, FALSE$, More)
 | |
|     Count = count(List, @fm) + (List # "")
 | |
|     *if List<1> [1,3] <= "WP_" and List<Count> [1,3] >= "WP_" then
 | |
|      * extract wp's
 | |
|       Pos = index(@fm: List, @fm: "WP_", 1)
 | |
|       if Pos then
 | |
|         Pos = count(List [1,Pos], @fm) + 1
 | |
|         loop
 | |
|           Text = List<Pos>
 | |
|         while Text [1,3] = "WP_"
 | |
|           Procs<-1> = Text [4,99999]
 | |
|           Pos += 1
 | |
|         repeat
 | |
|       end
 | |
|     *end
 | |
|   *while More and List<Count> [1,3] <= "WP_"
 | |
|   *repeat
 | |
| return
 | |
| 
 | |
| 
 | |
| SkipCode:
 |