]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1091 Fix SQL for CPD over different projects
authorEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 26 Sep 2011 15:17:24 +0000 (19:17 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 26 Sep 2011 15:55:30 +0000 (19:55 +0400)
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java
plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml

index 6f11397f0bd46ba43a720446ab05e5f9b2bbc648..c63271e4807f94fb9683368ef226eae59d6fa09a 100644 (file)
@@ -76,7 +76,7 @@ public class DbDuplicationsIndex {
     int resourceSnapshotId = getSnapshotIdFor(resource);
 
     // Order of columns is important - see code below!
-    String sql = "SELECT to_blocks.hash, res.kee, to_blocks.index_in_file, to_blocks.start_line, to_blocks.end_line" +
+    String sql = "SELECT DISTINCT to_blocks.hash, res.kee, to_blocks.index_in_file, to_blocks.start_line, to_blocks.end_line" +
         " FROM duplications_index to_blocks, duplications_index from_blocks, snapshots snapshot, projects res" +
         " WHERE from_blocks.snapshot_id = :resource_snapshot_id" +
         " AND to_blocks.hash = from_blocks.hash" +
index ecef7dd2739aab92eacf1bf732834e3cbf9cf312..9581b0be96c4af3657224d588d3fb469578596e5 100644 (file)
@@ -40,4 +40,8 @@
   <!-- foo -->
   <duplications_index id="5" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="0" start_line="0" end_line="0" />
 
+  <!-- Note that there is two blocks with same hash for current analysis to verify that we use "SELECT DISTINCT", -->
+  <!-- without "DISTINCT" we will select block from "bar-last" two times. -->
+  <duplications_index id="6" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="1" start_line="1" end_line="1" />
+
 </dataset>