DatabaseProcApplicationCreatedLinks
sybsystemprocssp_dbremap  14 déc. 14Defects Propagation Dependencies

1     
2     /* Sccsid = "@(#) generic/sproc/src/%M% %I% %G%" */
3     
4     /*
5     ** Messages for "sp_dbremap"      17550
6     **
7     ** 17260, "Can't run %1! from within a transaction."
8     ** 17284, "'%1!' is not a valid identifier."
9     ** 17590, "The specified database does not exist."
10    ** 18336, "Permission denied. Your curwrite label must be
11    **	   set at the hurdle of the affected database."
12    */
13    
14    create or replace procedure sp_dbremap
15        @dbname varchar(30) /* name of database whose diskmap is to be remapped */
16    as
17    
18        declare @procval int
19    
20    
21        declare @dummy int
22        declare @nullarg char(1)
23        declare @gp_enabled int
24        declare @status1 int
25        declare @status2 int
26    
27        select @status1 = 1
28        select @status2 = 1
29    
30        if @@trancount = 0
31        begin
32            set chained off
33        end
34    
35        set transaction isolation level 1
36    
37        /*
38        ** Check for valid identifier.
39        */
40        if valid_name(@dbname) = 0
41        begin
42            /*
43            ** 17284, "'%1!' is not a valid identifier."
44            */
45            raiserror 17284, @dbname
46            return (1)
47        end
48    
49    
50        /*
51        **  Only the Database Owner (DBO) or Accounts with SA role can execute it.
52        **  If the user has SA role, it's uid will be DBO uid (1). If granular 
53        **  permissions is enabled then users with 'own database' permission can 
54        **  execute it.
55        */
56        select @nullarg = NULL
57    
58        execute @status1 = sp_aux_checkroleperm "dbo",
59            "own database", @dbname, @gp_enabled output
60        if (@status1 != 0)
61        begin
62            if (@gp_enabled = 0)
63            begin
64                execute @status2 = sp_aux_checkroleperm "sa_role",
65                    @nullarg, @nullarg, @gp_enabled output
66    
67                if (@status2 != 0)
68                begin
69                    /* 
70                    ** proc_role() will raise permission errors
71                    ** and send audit records to the audit trail
72                    */
73                    select @dummy = proc_role("sa_role")
74                    return (1)
75                end
76            end
77            else
78            begin
79                /* Call proc_perm here to do auditing and error message. */
80                select @dummy = proc_auditperm("own database",
81                        @status1, @dbname)
82                return (1)
83            end
84        end
85    
86        /* 
87        ** Send apropriate audit records, already determined user has one
88        ** of the roles or the permission. 
89        */
90        if (@gp_enabled = 0)
91        begin
92            if (@status2 = 0)
93                select @dummy = proc_role("sa_role")
94        end
95        else
96        begin
97            select @dummy = proc_auditperm("own database", @status1, @dbname)
98        end
99    
100       /*
101       **  If we're in a transaction, disallow this since it might make recovery
102       **  impossible.
103       */
104       if @@trancount > 0
105       begin
106           /*
107           ** 17260, "Can't run %1! from within a transaction."
108           */
109           raiserror 17260, "sp_dbremap"
110           return (1)
111       end
112       else
113       begin
114           set chained off
115       end
116   
117       set transaction isolation level 1
118   
119       /*
120       **  Check to see if the database exists.
121       */
122       if not exists (select *
123               from master.dbo.sysdatabases
124               where name = @dbname)
125       begin
126           /*
127           ** 17590, "The specified database does not exist."
128           */
129           raiserror 17590
130           return (1)
131       end
132   
133   
134   
135       /*
136       **  Now go ahead and update the in-core image of the database usage map table.
137       */
138       dbcc dbrepair(@dbname, remap)
139   
140   
141       return (0)
142   


exec sp_procxmode 'sp_dbremap', 'AnyMode'
go

Grant Execute on sp_dbremap to public
go
DEFECTS
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public sybsystemprocs..sp_dbremap  
 MUCO 3 Useless Code Useless Brackets 46
 MUCO 3 Useless Code Useless Brackets 60
 MUCO 3 Useless Code Useless Brackets 62
 MUCO 3 Useless Code Useless Brackets 67
 MUCO 3 Useless Code Useless Brackets 74
 MUCO 3 Useless Code Useless Brackets 82
 MUCO 3 Useless Code Useless Brackets 90
 MUCO 3 Useless Code Useless Brackets 92
 MUCO 3 Useless Code Useless Brackets 110
 MUCO 3 Useless Code Useless Brackets 130
 MUCO 3 Useless Code Useless Brackets 141
 QISO 3 Set isolation level 35
 QISO 3 Set isolation level 117
 VNRD 3 Variable is not read @dummy 97
 VUNU 3 Variable is not used @procval 18
 MSUB 2 Subquery Marker 122
 MTR1 2 Metrics: Comments Ratio Comments: 47% 14
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 6 = 10dec - 6exi + 2 14
 MTR3 2 Metrics: Query Complexity Complexity: 50 14

DEPENDENCIES
PROCS AND TABLES USED
reads table master..sysdatabases (1)  
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)