DatabaseProcApplicationCreatedLinks
sybsystemprocssp_getopts  31 Aug 14Defects Dependencies

1     
2     /*
3     ** sp_getopts
4     **
5     **	Utility procedure to parse a string arguments with options.
6     **	Each call to this procedure will extract the 1st (if any) option
7     **	in @options, move @options past the option just read, and return
8     ** 	the newly found option via @option_item.
9     **
10    ** Parameters:
11    **	@options	- Input string containing 0 or more options
12    **			  separated by a user-specified separator.
13    **	@opt_sep	- User-specified option separator character.
14    **	@option_item	- (Out) Option item found, if any.
15    **	@options_out	- (Out) @options after moving past '@option_item'.
16    **
17    ** Returns:
18    **	1	- If a new option was found.
19    **	0	- Otherwise. (terminates iteration in caller.)
20    {
21    */
22    create procedure sp_getopts(@options varchar(512)
23        , @opt_sep char(1) = ','
24        , @option_item varchar(30) output
25        , @options_out varchar(512) output
26    ) as
27        begin
28            declare @sep_index int
29    
30            -- Signal end of options to process.
31            if (@options IS NULL) or (datalength(@options) = 0)
32                return 0
33    
34            -- Extract each comma-separated print option.
35            if ((charindex(@opt_sep, @options) != 0)
36                    or (datalength(@options) > 0))
37            begin
38                -- Locate index of option separator, if any.
39                select @sep_index = charindex(@opt_sep, @options)
40    
41                -- Pull out the 1st option, if there is a separator.
42                if (@sep_index > 0)
43                begin
44                    select @option_item = substring(@options,
45                            1,
46                            (@sep_index - 1))
47                    select @option_item = ltrim(rtrim(@option_item))
48    
49                    -- Move past this print option for next itern.
50                    select @options_out =
51                        substring(@options, (@sep_index + 1),
52                            (datalength(@options)
53                            - @sep_index))
54                end
55                else -- no commas; single print option
56                begin
57                    select @option_item = ltrim(rtrim(@options))
58                    select @options_out = NULL
59                end
60            end
61            return 1
62        end
63    


exec sp_procxmode 'sp_getopts', 'AnyMode'
go

Grant Execute on sp_getopts to public
go
DEFECTS
 MGTP 3 Grant to public sybsystemprocs..sp_getopts  
 MUCO 3 Useless Code Useless Brackets in create proc 22
 MUCO 3 Useless Code Useless Begin-End Pair 27
 MUCO 3 Useless Code Useless Brackets 35
 MUCO 3 Useless Code Useless Brackets 42
 MTR1 2 Metrics: Comments Ratio Comments: 51% 22
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 6 = 5dec - 1exi + 2 22
 MTR3 2 Metrics: Query Complexity Complexity: 18 22

DEPENDENCIES
CALLERS
called by proc sybsystemprocs..sp_monitor_deadlock_getopts  
   called by proc sybsystemprocs..sp_monitor_deadlock  
      called by proc sybsystemprocs..sp_monitor  
called by proc sybsystemprocs..sp_showtext_output  
   called by proc sybsystemprocs..sp_showtext  
      called by proc sybsystemprocs..sp_helptext_usage  
         called by proc sybsystemprocs..sp_helptext  
      called by proc sybsystemprocs..sp_helptext