Click or drag to resize

SEM007 : Statement metrics for detecting duplicated code

The topic describes the SEM007 analysis rule.

Message

Statement metrics for detecting duplicated code

Description

Metrics rule - hash,tokens and lines count of each statement. For use by copy-paste detection.

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Metrics

Additional Information

There is no additional info for this rule.

Example Test Script
SQL
 1begin
 2-- non-ANSI inner join syntax: 
 3SELECT     a.au_id ,
 4           t.titlr e
 5FROM       titles AS t ,
 6           authors AS a ,
 7           titleauthor AS ta
 8WHERE      a.au_id = ta.au_id
 9       AND ta.title_id = t.title_id
10       AND t.title LIKE 'Example%'
11
12-- ANSI inner join syntax: 
13
14/*
15SELECT     a.au_id ,
16           t.title
17FROM       authors AS a
18INNER JOIN titleauthor AS ta
19ON         a.au_id = ta.au_id
20INNER JOIN titles AS t
21ON         ta.title_id = t.title_id
22WHERE      t.title LIKE 'Example%'*/
23
24
25SELECT     a.au_id ,
26           t.title
27FROM       authors AS a
28INNER JOIN titleauthor AS ta
29ON         a.au_id = ta.au_id
30INNER JOIN titles AS t
31ON         ta.title_id = t.title_id
32WHERE      t.title LIKE 'Example%' -- Ignore
33
34SELECT     a.au_id ,
35           t.title
36FROM       authors AS a
37INNER JOIN titleauthor AS ta
38ON         a.au_id = ta.au_id
39INNER JOIN titles AS t
40ON         ta.title_id = t.title_id
41WHERE      t.title LIKE 'Example%' -- Ignore
42
43
44end

Analysis Results

 MessageLineColumn
1SEM007 : Hash=BCC52F87,Statements=4,Tokens=138,Lines=44,Position=110
2SEM007 : Hash=F01E538,Statements=1,Tokens=43,Lines=21,Position=230
3SEM007 : Hash=F01E538+EA388B09,Statements=2,Tokens=88,Lines=29,Position=2+330
4SEM007 : Hash=F01E538+EA388B09+EA388B09,Statements=3,Tokens=133,Lines=37,Position=2+3+430
5SEM007 : Hash=EA388B09,Statements=1,Tokens=45,Lines=8,Position=3250
6SEM007 : Hash=EA388B09+EA388B09,Statements=2,Tokens=90,Lines=16,Position=3+4250
7SEM007 : Hash=EA388B09,Statements=1,Tokens=45,Lines=8,Position=4340
See Also

Other Resources