DatabaseProcApplicationCreatedLinks
sybsystemprocssp_ijdbc_escapeliteralforlike  31 Aug 14Defects Dependencies

1     
2     /*
3     **  sp_ijdbc_escapeliteralforlike
4     */
5     
6     
7     /*
8     ** This is a utility procedure which takes an input string
9     ** and places the escape character '\' before any symbol
10    ** which needs to be a literal when used in a LIKE clause.
11    **
12    */
13    
14    
15    create procedure sp_ijdbc_escapeliteralforlike
16        @pString varchar(255) output
17    as
18        declare @newString varchar(255)
19        declare @validEscapes varchar(255)
20        declare @escapeChar varchar(10)
21        declare @pIndex int
22        declare @pLength int
23        declare @curChar char(1)
24        declare @escapeIndex int
25        declare @escapeLength int
26        declare @boolEscapeIt int
27    
28        select @pLength = char_length(@pString)
29        if (@pString is null) or (@pLength = 0)
30        begin
31            return
32        end
33    
34        /*
35        ** we will use the backslash as our escape 
36        ** character
37        */
38        select @escapeChar = '\'
39    
40        /* 
41        ** valid escape characters
42        */
43        select @validEscapes = '%_\[]'
44        select @escapeLength = char_length(@validEscapes)
45    
46        /* start at the beginning of the string */
47        select @pIndex = 1
48        select @newString = ''
49    
50        while (@pIndex <= @pLength)
51        begin
52            /*
53            ** get the next character of the string
54            */
55            select @curChar = substring(@pString, @pIndex, 1)
56    
57            /*
58            ** loop through all of the escape characters and
59            ** see if the character needs to be escaped
60            */
61            select @escapeIndex = 1
62            select @boolEscapeIt = 0
63            while (@escapeIndex <= @escapeLength)
64            begin
65                /* see if this is a match */
66                if (substring(@validEscapes, @escapeIndex, 1) =
67                        @curChar)
68                begin
69                    select @boolEscapeIt = 1
70                    break
71                end
72                /* move on to the next escape character */
73                select @escapeIndex = @escapeIndex + 1
74            end
75    
76            /* build the string */
77            if (@boolEscapeIt = 1)
78            begin
79                select @newString = @newString + @escapeChar + @curChar
80            end
81            else
82            begin
83                select @newString = @newString + @curChar
84            end
85    
86            /* go on to the next character in our source string */
87            select @pIndex = @pIndex + 1
88        end
89    
90        /* return to new string to the caller */
91        select @pString = ltrim(rtrim(@newString))
92        return 0
93    


exec sp_procxmode 'sp_ijdbc_escapeliteralforlike', 'AnyMode'
go

Grant Execute on sp_ijdbc_escapeliteralforlike to public
go
DEFECTS
 MEST 4 Empty String will be replaced by Single Space 48
 MGTP 3 Grant to public sybsystemprocs..sp_ijdbc_escapeliteralforlike  
 MUCO 3 Useless Code Useless Brackets 50
 MUCO 3 Useless Code Useless Brackets 63
 MUCO 3 Useless Code Useless Brackets 66
 MUCO 3 Useless Code Useless Brackets 77
 MTR1 2 Metrics: Comments Ratio Comments: 28% 15
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 6 = 6dec - 2exi + 2 15
 MTR3 2 Metrics: Query Complexity Complexity: 39 15

DEPENDENCIES
CALLERS
called by proc sybsystemprocs..sp_ijdbc_getversioncolumns  
called by proc sybsystemprocs..sp_ijdbc_primarykey  
called by proc sybsystemprocs..sp_ijdbc_getcolumnprivileges  
called by proc sybsystemprocs..sp_ijdbc_getbestrowidentifier