DatabaseProcApplicationCreatedLinks
sybsystemprocssp_setup_table_transfer  14 déc. 14Defects Propagation Dependencies

1     
2     /*
3     ** Messages for "sp_setup_table_transfer"         17280
4     **
5     ** 17260, "Can't run %1! from within a transaction." 
6     ** 18305, "Table '%1!' has already been created."
7     */
8     create or replace procedure sp_setup_table_transfer
9     as
10    
11        declare @cmd varchar(100),
12            @procname varchar(30),
13            @procval int,
14            @dummy int,
15            @nullarg char(1),
16            @retstat int,
17            @status1 int,
18            @gp_enabled int,
19            @dbname varchar(255),
20            @tabname varchar(30)
21    
22        /* Initialize */
23        select @procname = 'sp_setup_table_transfer',
24            @tabname = 'spt_TableTransfer',
25            @status1 = 1
26    
27        /*
28        **  Create-table does not happen within a transaction.
29        */
30        if @@trancount > 0
31        begin
32            -- 17260, "Can't run %1! from within a transaction." 
33            raiserror 17260, @procname
34            return 1
35        end
36    
37        set chained off
38        set transaction isolation level 1
39    
40        /*
41        **  If granular permissions is not enabled only the Database Owner (DBO) or
42        **  accounts with SA role can execute it.
43        **  If granular permissions is enabled then users with 'manage database' 
44        **  permission can execute it.
45        */
46        select @dbname = db_name()
47        select @nullarg = NULL
48    
49        execute @retstat = sp_aux_checkroleperm "dbo",
50            "manage database", @dbname, @gp_enabled output
51        if (@retstat != 0)
52        begin
53            if (@gp_enabled = 0)
54            begin
55                /* 
56                ** proc_role() will raise permission errors
57                ** and send audit records to the audit trail
58                */
59                select @dummy = proc_role("sa_role")
60                return (1)
61            end
62            else
63            begin
64                /* Call proc_perm here to do auditing and error message. */
65                select @dummy = proc_auditperm("manage database",
66                        @retstat, @dbname)
67                return (1)
68            end
69        end
70    
71        /* 
72        ** Send apropriate audit records, already determined user has one
73        ** of the roles or the permission. 
74        */
75        if (@gp_enabled = 0)
76        begin
77            /* For Auditing if user really has sa_role */
78            execute @status1 = sp_aux_checkroleperm "sa_role",
79                @nullarg, @nullarg, @gp_enabled output
80            if (@status1 = 0)
81                select @dummy = proc_role("sa_role")
82        end
83        else
84        begin
85            select @dummy = proc_auditperm("manage database",
86                    @retstat, @dbname)
87        end
88    
89        -- If spt_TableTransfer already exists, don't try to create it again.
90        if exists (select id from sysobjects where name = @tabname)
91        begin
92            -- 18305, "Table '%1!' has already been created."
93            raiserror 18305, @tabname
94            return 0
95        end
96    
97        -- Create the table.
98        create table spt_TableTransfer(
99            end_code unsigned smallint not null,
100           id int not null,
101           ts_floor bigint not null,
102           ts_ceiling bigint not null,
103           time_begin datetime not null,
104           time_end datetime not null,
105           row_count bigint not null,
106           byte_count bigint not null,
107           sequence_id int not null,
108           col_order tinyint not null,
109           output_to tinyint not null,
110           tracking_id int null,
111           pathname varchar(512) null,
112           row_sep varchar(64) null,
113           col_sep varchar(64) null,
114           primary key (id, sequence_id))
115       lock allpages
116           on 'default'
117   
118       if (@@error != 0)
119           return 1
120   
121       /*
122       ** Let everyone see its contents.  This unfortunately does not compile
123       ** if we create the table within this procedure, so we need to perform
124       ** it via 'exec immediate'.
125       */
126       select @cmd = 'grant select on ' + @tabname + ' to public'
127       exec (@cmd)
128   
129       if (@@error != 0)
130           return 1
131   
132       -- Done successfully
133       return 0
134   


exec sp_procxmode 'sp_setup_table_transfer', 'AnyMode'
go

Grant Execute on sp_setup_table_transfer to public
go
DEFECTS
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 90
 MDYN 3 Proc uses Dynamic SQL but is not flagged with Dynamic Ownership Chain 8
 MGTP 3 Grant to public sybsystemprocs..sp_setup_table_transfer  
 MGTP 3 Grant to public sybsystemprocs..sysobjects  
 MUCO 3 Useless Code Useless Brackets 51
 MUCO 3 Useless Code Useless Brackets 53
 MUCO 3 Useless Code Useless Brackets 60
 MUCO 3 Useless Code Useless Brackets 67
 MUCO 3 Useless Code Useless Brackets 75
 MUCO 3 Useless Code Useless Brackets 80
 MUCO 3 Useless Code Useless Brackets 118
 MUCO 3 Useless Code Useless Brackets 129
 MZMB 3 Zombie: use of non-existent object sybsystemprocs..spt_TableTransfer 98
 QISO 3 Set isolation level 38
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysobjects.ncsysobjects unique
(name, uid)
Intersection: {name}
90
 VNRD 3 Variable is not read @gp_enabled 79
 VNRD 3 Variable is not read @dummy 85
 VUNU 3 Variable is not used @procval 13
 MDYS 2 Dynamic SQL Marker 127
 MSUB 2 Subquery Marker 90
 MTR1 2 Metrics: Comments Ratio Comments: 34% 8
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 6 = 9dec - 5exi + 2 8
 MTR3 2 Metrics: Query Complexity Complexity: 44 8

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