DatabaseProcApplicationCreatedLinks
sybsystemprocssyb_aux_privsand  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
3     
4     
5     create procedure syb_aux_privsand
6         @left_binary varbinary(32), /* left operand of AND */
7         @right_binary varbinary(32), /* right operand of AND */
8         @col_count smallint, /* number of columns in the table */
9         @result_binary varbinary(32) output /* result of ANDing */
10    as
11    
12        declare @loop_count tinyint /* loop counter for the 32 bytes in varbinary operand */
13        declare @left_opr tinyint /* integer represenation of a byte in left opr */
14        declare @right_opr tinyint /* integer represenation of a byte in right opr */
15        declare @result_opr tinyint /* result byte */
16        declare @left_bin varbinary(32) /* expanded bit map of left operand */
17        declare @right_bin varbinary(32) /* expanded bit map of right operand */
18        declare @loop_bound tinyint /* stores the loop upper bound */
19    
20        /*
21        ** initialize the loop count
22        */
23        select @loop_count = 1
24    
25        /* 
26        ** initialize loop_bound
27        */
28        select @loop_bound = @col_count / 8 + 1
29    
30        /*
31        ** boundary condition. If any of the operand is 0, the result will be zero 
32        */
33        if ((@right_binary = 0x00) or (@left_binary = 0x00))
34        begin
35            select @result_binary = 0x00
36            return
37        end
38    
39        /*
40        ** boundary condition. If both operands are all 1's, return all 1's
41        */
42    
43        if ((@left_binary = 0x01) and (@right_binary = 0x01))
44        begin
45            select @result_binary = 0x01
46            return
47        end
48    
49        /* 
50        ** if left operand was all 1's, expand it into appropriate number of columns 
51        */
52        if (@left_binary = 0x01)
53            exec sybsystemprocs.dbo.syb_aux_expandbitmap @col_count, @left_bin output
54        else
55            select @left_bin = @left_binary
56    
57        /*
58        ** if right operand was all 1's, expand it into appropriate number of columns 
59        */
60    
61        if (@right_binary = 0x01)
62            exec sybsystemprocs.dbo.syb_aux_expandbitmap @col_count, @right_bin output
63        else
64            select @right_bin = @right_binary
65    
66    
67        /*
68        ** loop for each byte in the varbinary operand
69        */
70        while (@loop_count <= @loop_bound)
71        begin
72            select @left_opr = convert(tinyint, substring(@left_bin, @loop_count, 1))
73            select @right_opr = convert(tinyint, substring(@right_bin, @loop_count, 1))
74    
75            /* bit wise ANDing. Note atmost only one of the operands might have been
76            expanded to full 32 bytes. The extra 1s will ge zeroed out in the operation*/
77    
78            select @result_opr = @left_opr & @right_opr
79    
80            /*
81            ** first byte is treated differently as there is nothing to be appended 
82            */
83            if (@loop_count = 1)
84            begin
85                select @result_binary = convert(binary(1), @result_opr)
86            end
87            else
88            begin
89                select @result_binary = @result_binary + convert(binary(1), @result_opr)
90            end
91    
92            select @loop_count = @loop_count + 1
93        end
94    


exec sp_procxmode 'syb_aux_privsand', 'AnyMode'
go

Grant Execute on syb_aux_privsand to public
go
DEFECTS
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 33
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 35
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 43
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 45
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 52
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 61
 MGTP 3 Grant to public sybsystemprocs..syb_aux_privsand  
 MNER 3 No Error Check should check return value of exec 53
 MNER 3 No Error Check should check return value of exec 62
 MUCO 3 Useless Code Useless Brackets 33
 MUCO 3 Useless Code Useless Brackets 43
 MUCO 3 Useless Code Useless Brackets 52
 MUCO 3 Useless Code Useless Brackets 61
 MUCO 3 Useless Code Useless Brackets 70
 MUCO 3 Useless Code Useless Brackets 83
 MTR1 2 Metrics: Comments Ratio Comments: 38% 5
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 8dec - 3exi + 2 5
 MTR3 2 Metrics: Query Complexity Complexity: 38 5

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..syb_aux_expandbitmap  

CALLERS
called by proc sybsystemprocs..sp_changegroup