DatabaseProcApplicationCreatedLinks
sybsystemprocssp_jdbc_escapeliteralforlike  31 Aug 14Defects Dependencies

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


exec sp_procxmode 'sp_jdbc_escapeliteralforlike', 'AnyMode'
go

Grant Execute on sp_jdbc_escapeliteralforlike to public
go
DEFECTS
 MEST 4 Empty String will be replaced by Single Space 42
 MGTP 3 Grant to public sybsystemprocs..sp_jdbc_escapeliteralforlike  
 MUCO 3 Useless Code Useless Brackets 44
 MUCO 3 Useless Code Useless Brackets 57
 MUCO 3 Useless Code Useless Brackets 60
 MUCO 3 Useless Code Useless Brackets 71
 MTR1 2 Metrics: Comments Ratio Comments: 27% 10
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 6 = 6dec - 2exi + 2 10
 MTR3 2 Metrics: Query Complexity Complexity: 39 10

DEPENDENCIES
CALLERS
called by proc sybsystemprocs..sp_jdbc_primarykey  
called by proc sybsystemprocs..sp_jdbc_getcolumnprivileges  
called by proc sybsystemprocs..sp_jdbc_getversioncolumns  
called by proc sybsystemprocs..sp_jdbc_getbestrowidentifier