DatabaseProcApplicationCreatedLinks
sybsystemprocssp_rebuild_text  14 déc. 14Defects Propagation Dependencies

1     
2     
3     /* 
4     ** Messages for "sp_rebuild_text"	18925
5     **
6     ** 17260, "Can't run %1! from within a transaction." 
7     ** 17590, "The specified database does not exist."
8     ** 18301, "Database name '%1!' is not the current database."
9     ** 18925  "sp_rebuild_text failed. Check the SQL Server error log file."
10    */
11    
12    create or replace procedure sp_rebuild_text
13        @dbname varchar(255) /* database name */
14    as
15        declare @nullarg char(1)
16        declare @dummy int
17        declare @status int
18        declare @gp_enabled int
19    
20    
21        /*
22        **  If we're in a transaction, disallow this since it might make recovery
23        **  impossible.
24        */
25        if @@trancount > 0
26        begin
27            /*
28            ** 17260, "Can't run %1! from within a transaction." 
29            */
30            raiserror 17260, "sp_rebuild_text"
31            return (1)
32        end
33    
34        set chained off
35    
36        set transaction isolation level 1
37    
38        /*
39        **  Make sure the database exists.
40        */
41        if not exists (select * from master.dbo.sysdatabases
42                where name = @dbname)
43        begin
44            /* 17590, "The specified database does not exist." */
45            raiserror 17590
46            return (1)
47        end
48    
49        /*
50        **  Make sure that we are in the database specified
51        **  by @dbname.
52        */
53        if @dbname != db_name()
54        begin
55            /*
56            ** 18301, "Database name '%1!' is not the current database."
57            */
58            raiserror 18301, @dbname
59            return (1)
60        end
61    
62        /* 
63        ** If granular permissions is not enabled then sa_role is required.
64        ** If granular permissions is enabled then the permission 'manage database' is
65        ** required.  proc_role and proc_auditperm will also do auditing
66        ** if required. Both will also print error message if required.
67        */
68    
69        select @nullarg = NULL
70        execute @status = sp_aux_checkroleperm "sa_role", "manage database",
71            @dbname, @gp_enabled output
72    
73        /* For Auditing */
74        if (@gp_enabled = 0)
75        begin
76            if (proc_role("sa_role") = 0)
77                return (1)
78        end
79        else
80        begin
81            select @dummy = proc_auditperm("manage database", @status, @dbname)
82        end
83    
84        if (@status != 0)
85            return (1)
86    
87        /* Uses internal sql to rebuild_text */
88    
89        dbcc rebuild_text("all")
90    
91        if (@@error != 0)
92        begin
93            /*
94            ** 18925, "sp_rebuild_text failed. Check the SQL Server error log file."
95            */
96            raiserror 18925
97            return (1)
98        end
99    
100       return (0)
101   
102   


exec sp_procxmode 'sp_rebuild_text', 'AnyMode'
go

Grant Execute on sp_rebuild_text to public
go
DEFECTS
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public sybsystemprocs..sp_rebuild_text  
 MUCO 3 Useless Code Useless Brackets 31
 MUCO 3 Useless Code Useless Brackets 46
 MUCO 3 Useless Code Useless Brackets 59
 MUCO 3 Useless Code Useless Brackets 74
 MUCO 3 Useless Code Useless Brackets 76
 MUCO 3 Useless Code Useless Brackets 77
 MUCO 3 Useless Code Useless Brackets 84
 MUCO 3 Useless Code Useless Brackets 85
 MUCO 3 Useless Code Useless Brackets 91
 MUCO 3 Useless Code Useless Brackets 97
 MUCO 3 Useless Code Useless Brackets 100
 QISO 3 Set isolation level 36
 VNRD 3 Variable is not read @nullarg 69
 VNRD 3 Variable is not read @dummy 81
 MSUB 2 Subquery Marker 41
 MTR1 2 Metrics: Comments Ratio Comments: 48% 12
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 4 = 8dec - 6exi + 2 12
 MTR3 2 Metrics: Query Complexity Complexity: 38 12

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