From f645ee2ea95bc40e593dd786c374c156dcd14b7c Mon Sep 17 00:00:00 2001 From: Eric Giffon Date: Tue, 21 Mar 2023 10:01:56 +0100 Subject: [PATCH] SONAR-18583 Condition on schema when dropping constraints --- .../db/migration/sql/DropMsSQLDefaultConstraintsBuilder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropMsSQLDefaultConstraintsBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropMsSQLDefaultConstraintsBuilder.java index 95b082ac35e..2cfbd2886e5 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropMsSQLDefaultConstraintsBuilder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropMsSQLDefaultConstraintsBuilder.java @@ -80,8 +80,9 @@ public class DropMsSQLDefaultConstraintsBuilder { PreparedStatement pstmt = connection .prepareStatement(format("SELECT d.name FROM sys.tables t " + "JOIN sys.default_constraints d ON d.parent_object_id = t.object_id " - + "JOIN sys.columns c ON c.object_id = t.object_id AND c.column_id = d.parent_column_id " - + "WHERE t.name = '%s' AND c.name in (%s)", tableName, commaSeparatedListOfColumns)); + + "JOIN sys.columns c ON c.object_id = t.object_id AND c.column_id = d.parent_column_id " + + "JOIN sys.schemas s ON s.schema_id = t.schema_id " + + "WHERE t.name = '%s' AND c.name in (%s) AND s.name = '%s'", tableName, commaSeparatedListOfColumns, connection.getSchema())); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { defaultConstrainNames.add(rs.getString(1)); -- 2.39.5