Skip to content

Commit

Permalink
#13309 - MSSQL Upsert SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
acurionedotcms committed Jan 5, 2018
1 parent 13c33af commit 96ba442
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ private void deleteInsertPermission(Permissionable permissionable, String type,
String query = SQLUtil.generateUpsertSQL("permission_reference", "asset_id", "?",
new String[]{"asset_id", "reference_id", "permission_type"},
new String[]{"?", "?", "?"});
dc1.executeUpdate(query, permissionId, permissionId,
dc1.executeUpdate(query, permissionId,
permissionId, newReference.getPermissionId(), type,
permissionId, newReference.getPermissionId(), type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ private static boolean isValidSQLCharacter (final char c) {
+ "VALUES (%s) ON DUPLICATE KEY "
+ "UPDATE %s";
private final static String MSSQL_UPSERT_QUERY =
"MERGE INTO %s USING "
+ "(SELECT %s [conditional]) AS dummy([conditional]) ON %s = %s "
"MERGE %s AS [Target] USING "
+ "(SELECT %s AS %s) AS [Source] ON [Target].%s = [Source].%s "
+ "WHEN MATCHED THEN "
+ " UPDATE SET %s "
+ "WHEN NOT MATCHED THEN "
Expand Down Expand Up @@ -358,7 +358,8 @@ public static String generateUpsertSQL (String table, String conditionalColumn,
query = String.format(MSSQL_UPSERT_QUERY, table,
conditionalValue,
conditionalColumn,
conditionalValue,
conditionalColumn,
conditionalColumn,
buffer.toString(),
StringUtil.merge(columns),
StringUtil.merge(values));
Expand Down

0 comments on commit 96ba442

Please sign in to comment.