DatabaseProcApplicationCreatedLinks
sybsystemprocssp_start_xact  31 Aug 14Defects Dependencies

1     
2     create procedure sp_start_xact
3         @applname varchar(30),
4         @xactname varchar(30),
5         @count smallint,
6         @password varchar(30) = NULL
7     AS
8     
9         declare @xid binary(140)
10        declare @randid int
11    
12        if @@trancount = 0
13        begin
14            set transaction isolation level 1
15            set chained off
16        end
17    
18        set nocount on
19    
20        BEGIN
21            BEGIN TRANSACTION
22            select @xid = convert(binary(140), 0x0)
23    
24            /*	
25            ** Get a random commid to reduce the page lock contention
26            ** during insert.  Note that there is a possibility of 
27            ** inserting a duplicate row.  If we do, then repeat the
28            ** insert with another commid until we are successful.
29            ** The probability is extremely low since we can have 
30            ** atleast 2 billion combinations (2147483647 to be precise)
31            ** for the commid.
32            */
33            while (1 = 1)
34            begin
35                /* Select a random commid between 1 and 2147483647 */
36                select @randid = rand() * 2147483647
37                INSERT sybsystemdb.dbo.spt_committab VALUES
38                (
39                    @randid,
40                    - 1, /* this tells us that this is a non-XA 2pc */
41                    getdate(),
42                    getdate(),
43                    @count,
44                    @count,
45                    'n',
46                    'b',
47                    @xid,
48                    @applname,
49                    @xactname,
50                    @password
51                )
52    
53                /* 
54                ** If we attempted to insert a duplicate row into the 
55                ** table we would have got a 2601 error.  But we have
56                ** some special checks in dupcheck() routine which will
57                ** avoid printing the error message if the object is 
58                ** spt_committab.  So, the user will not see an error
59                ** message in this situation.  If we get a 2601 error,
60                ** should try a different random commid.
61                */
62                if (@@error = 2601)
63                    continue
64                else
65                    /* Insert was successful. */
66                    break
67            end
68    
69            if @@trancount = 0
70            begin
71                return 1
72            end
73    
74            SELECT @randid
75            COMMIT TRANSACTION
76        END
77    


exec sp_procxmode 'sp_start_xact', 'AnyMode'
go

Grant Execute on sp_start_xact to public
go
RESULT SETS
sp_start_xact_rset_001

DEFECTS
 MRIT 5 Return in Transaction trancount is 1 71
 MBLI 3 Integer Value of Binary Literal is Platform Dependant 22
 MGTP 3 Grant to public sybsystemprocs..sp_start_xact  
 MUCO 3 Useless Code Useless Begin-End Pair 20
 MUCO 3 Useless Code Useless Brackets 33
 MUCO 3 Useless Code Useless Brackets 62
 QISO 3 Set isolation level 14
 QNAM 3 Select expression has no name @randid 74
 MRST 2 Result Set Marker 74
 MTR1 2 Metrics: Comments Ratio Comments: 44% 2
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 4 = 4dec - 2exi + 2 2
 MTR3 2 Metrics: Query Complexity Complexity: 24 2

DEPENDENCIES
PROCS AND TABLES USED
writes table sybsystemdb..spt_committab (1)