DatabaseProcApplicationCreatedLinks
sybsystemprocssp_jdbc_escapeliteralforlike  14 déc. 14Defects Propagation Dependencies

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


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 40
 MGTP 3 Grant to public sybsystemprocs..sp_jdbc_escapeliteralforlike  
 MUCO 3 Useless Code Useless Brackets 42
 MUCO 3 Useless Code Useless Brackets 55
 MUCO 3 Useless Code Useless Brackets 58
 MUCO 3 Useless Code Useless Brackets 69
 MTR1 2 Metrics: Comments Ratio Comments: 26% 8
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 7dec - 2exi + 2 8
 MTR3 2 Metrics: Query Complexity Complexity: 39 8

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