DatabaseProcApplicationCreatedLinks
sybsystemprocssp_gen_login_id  14 déc. 14Defects Propagation Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/gen_login_id */
4     
5     /*
6     ** The suid generation logic should match the suid generation logic used by
7     ** the "create login" command. This is because rep agent uses the 
8     ** "create login" command to create a login on a replicated master. The suids
9     ** generated should be consistent.
10    ** Modify the suid generation logic in "create login" whenever the suid
11    ** logic in this procedure is changed.
12    */
13    create or replace procedure sp_gen_login_id
14        @loginame varchar(30), /* login name of the new user */
15        @insertsuid int output /* suid corresponding to
16    					** insert slot in Syslogins
17    					*/
18    as
19    
20        declare @msg varchar(250),
21            @suid int, /* temp variable */
22            @retstat int
23    
24        /* suid 2 is reserved for 'probe' */
25        if (@loginame = "probe")
26            select @insertsuid = @@probesuid
27        else
28        begin
29    
30            /* Generate an appropriate suid */
31            select @suid = max(suid)
32            from master.dbo.syslogins(index syslogins) where suid > @@probesuid
33    
34            if @suid is NULL
35            begin
36                select @insertsuid = @@probesuid + 1
37            end
38            else if @suid != @@maxsuid
39                select @insertsuid = @suid + 1
40    
41            else
42            begin
43                select @suid = min(suid)
44                from master.dbo.syslogins(index syslogins) where suid < - 2
45    
46                if @suid is NULL
47                begin
48                    select @insertsuid = - 3
49                end
50                else if @suid != @@minsuid
51                    select @insertsuid = @suid - 1
52    
53                /* check for holes if we already used up all suids */
54                else
55                begin
56                    /* Start looking for holes between @@minsuid and
57                    ** @@maxsuid. */
58                    select @insertsuid = @@minsuid
59                    while exists (select * from master.dbo.syslogins
60                                (index syslogins)
61                            where suid = @insertsuid)
62                    begin
63                        select @insertsuid = @insertsuid + 1
64    
65                        if (@insertsuid = @@invalidsuid)
66                        begin
67                            /*
68                            ** Uids -2, -1, 0 and 2 are all invalid
69                            */
70                            select @insertsuid = @insertsuid + 5
71                        end
72    
73                        if @insertsuid = @@maxsuid
74                        begin
75                            /*
76                            ** 17266, "All logins have been
77                            ** assigned. No more logins can be
78                            ** added at this time."
79                            */
80                            raiserror 17266
81                            return (1)
82                        end
83                    end
84    
85                end
86            end
87        end
88    
89        return (0)
90    


exec sp_procxmode 'sp_gen_login_id', 'AnyMode'
go

Grant Execute on sp_gen_login_id to public
go
DEFECTS
 MGTP 3 Grant to public master..syslogins  
 MGTP 3 Grant to public sybsystemprocs..sp_gen_login_id  
 MUCO 3 Useless Code Useless Brackets 25
 MUCO 3 Useless Code Useless Brackets 65
 MUCO 3 Useless Code Useless Brackets 81
 MUCO 3 Useless Code Useless Brackets 89
 QFID 3 Force index master..syslogins 32
 QFID 3 Force index master..syslogins 44
 QFID 3 Force index master..syslogins 60
 QSWV 3 Sarg with variable @@probesuid, Candidate Index: syslogins.csyslogins unique clustered(suid) F 32
 VUNU 3 Variable is not used @msg 20
 VUNU 3 Variable is not used @retstat 22
 MSUB 2 Subquery Marker 59
 MTR1 2 Metrics: Comments Ratio Comments: 40% 13
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 9 = 9dec - 2exi + 2 13
 MTR3 2 Metrics: Query Complexity Complexity: 37 13

DEPENDENCIES
PROCS AND TABLES USED
reads table master..syslogins (1)  

CALLERS
called by proc sybsystemprocs..sp_addlogin