diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-26 19:17:24 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-26 19:55:30 +0400 |
commit | e01749f160a9bead858e17b37c2b1dc0be93b7bc (patch) | |
tree | 814b18bf5f4ee68929028baa83dc366fe85a6395 /plugins/sonar-cpd-plugin | |
parent | 00126a9dca35e1b62509ea8f044753d8ad05f2b0 (diff) | |
download | sonarqube-e01749f160a9bead858e17b37c2b1dc0be93b7bc.tar.gz sonarqube-e01749f160a9bead858e17b37c2b1dc0be93b7bc.zip |
SONAR-1091 Fix SQL for CPD over different projects
Diffstat (limited to 'plugins/sonar-cpd-plugin')
2 files changed, 5 insertions, 1 deletions
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java index 6f11397f0bd..c63271e4807 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java @@ -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" + diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml index ecef7dd2739..9581b0be96c 100644 --- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml +++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml @@ -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> |