TakeActionNow2019 commented on code in PR #6511:
URL: https://github.com/apache/incubator-seata/pull/6511#discussion_r1676713159


##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/undo/sqlserver/SqlServerUndoDeleteExecutor.java:
##########
@@ -59,17 +71,75 @@ protected String buildUndoSQL() {
         String insertValues = fields.stream().map(field -> "?")
                 .collect(Collectors.joining(", "));
 
-        return "SET IDENTITY_INSERT " +
-                sqlUndoLog.getTableName() +
-                " ON; INSERT INTO " +
-                sqlUndoLog.getTableName() +
-                " (" +
-                insertColumns +
-                ") VALUES (" +
-                insertValues +
-                "); SET IDENTITY_INSERT " +
-                sqlUndoLog.getTableName() +
-                " OFF;";
+        if (tableIdentifyExistence) {
+            return "begin " +
+                    "SET IDENTITY_INSERT " + sqlUndoLog.getTableName() + " 
ON;" +
+                    "INSERT INTO " + sqlUndoLog.getTableName() + "(" + 
insertColumns + ") VALUES (" + insertValues + ");" +
+                    "SET IDENTITY_INSERT " + sqlUndoLog.getTableName() + " 
OFF; " +
+                    "end";
+        }
+        return "INSERT INTO " + sqlUndoLog.getTableName() + "(" + 
insertColumns + ") VALUES (" + insertValues + ");";
+    }
+
+    /**
+     * Judge whether there is a column of a SQLServer table is with a 
"IDENTITY"
+     *
+     * @param connectionProxy
+     */
+    private void judgeTableIdentifyExistence(ConnectionProxy connectionProxy) {
+        TableMeta tableMeta = 
TableMetaCacheFactory.getTableMetaCache(connectionProxy.getDbType())
+                .getTableMeta(
+                        connectionProxy.getTargetConnection(),
+                        sqlUndoLog.getTableName(),
+                        connectionProxy.getDataSourceProxy().getResourceId()
+                );
+        tableIdentifyExistence = ((SqlServerTableMeta) 
tableMeta).isTableIdentifyExistence();
+    }
+
+    /**
+     * Execute on.
+     *
+     * @param connectionProxy the connection proxy
+     * @throws SQLException the sql exception
+     */
+    @Override
+    public void executeOn(ConnectionProxy connectionProxy) throws SQLException 
{
+        Connection conn = connectionProxy.getTargetConnection();
+        if (IS_UNDO_DATA_VALIDATION_ENABLE && 
!dataValidationAndGoOn(connectionProxy)) {
+            return;
+        }
+
+        judgeTableIdentifyExistence(connectionProxy);

Review Comment:
   
![image](https://github.com/user-attachments/assets/33360342-ea8e-461a-8f69-e045d74b5a74)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to