You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/07/15 10:33:14 UTC
(shardingsphere) branch master updated: Support SqlServer update statement for Updating data in a remote table by using a linked server when use encrypt feature (#39122)
This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 74d4b46474f Support SqlServer update statement for Updating data in a remote table by using a linked server when use encrypt feature (#39122)
74d4b46474f is described below
commit 74d4b46474f591d0882e001d606e61b36905df51
Author: Claire <cl...@163.com>
AuthorDate: Wed Jul 15 18:33:08 2026 +0800
Support SqlServer update statement for Updating data in a remote table by using a linked server when use encrypt feature (#39122)
* support Updating data in a remote table by using a linked server
* support Updating data in a remote table by using a linked server
---
RELEASE-NOTES.md | 1 +
.../token/common/generator/generic/RemoveTokenGenerator.java | 3 ++-
.../encrypt/case/query-with-cipher/dml/update/update.xml | 10 ++++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index d9ab902c04a..a5af0bc22b3 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -75,6 +75,7 @@
1. JDBC: Bump the ClickHouse JDBC Driver used by optional modules to version `0.9.8` - [#38878](https://github.com/apache/shardingsphere/pull/38878)
1. Proxy: Support basic Firebird batch operations: create, send, execute, cancel, and release - [#38605](https://github.com/apache/shardingsphere/pull/38605)
1. JDBC & Proxy: Add a check to verify database name naming conventions. - [#38883](https://github.com/apache/shardingsphere/pull/38883)
+1. Encrypt: Support SqlServer update statement for Updating data in a remote table by using a linked server when use encrypt feature - [#39122](https://github.com/apache/shardingsphere/pull/39122)
1. Encrypt: Support SqlServer update statement for Specifying a table alias as the target object when use encrypt feature - [#38733](https://github.com/apache/shardingsphere/pull/38733)
1. Encrypt: Support SqlServer update statement for Specifying a view as the target object when use encrypt feature - [#38896](https://github.com/apache/shardingsphere/pull/38896)
1. Encrypt: Support SqlServer for Using the UPDATE statement with information from another table when use encrypt feature - [#38926](https://github.com/apache/shardingsphere/pull/38926)
diff --git a/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java b/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
index 7555387fb3a..4e8ca7626ba 100644
--- a/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
+++ b/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
@@ -82,7 +82,8 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(sqlStatementContext.getSqlStatement().getDatabaseType()).getDialectDatabaseMetaData();
OwnerSegment ownerSegment = each.getOwner().get();
if (dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().isPresent()) {
- ownerSegment.getOwner().ifPresent(optional -> result.add(new RemoveToken(optional.getStartIndex(), ownerSegment.getStartIndex() - 1)));
+ ownerSegment.getOwner().filter(databaseName -> !databaseName.getOwner().isPresent())
+ .ifPresent(databaseName -> result.add(new RemoveToken(databaseName.getStartIndex(), ownerSegment.getStartIndex() - 1)));
} else {
result.add(new RemoveToken(ownerSegment.getStartIndex(), each.getTableName().getStartIndex() - 1));
}
diff --git a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/update/update.xml b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/update/update.xml
index 7c8df50c3be..3093abf3c96 100644
--- a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/update/update.xml
+++ b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/update/update.xml
@@ -115,6 +115,16 @@
<output sql="UPDATE dbo.SalesPerson SET SalesYTD = SalesYTD + SubTotal, [bonus_cipher] = 'encrypt_3000.00' FROM dbo.SalesPerson AS sp JOIN dbo.SalesOrderHeader AS so ON sp.BusinessEntityID = so.SalesPersonID AND so.OrderDate = (SELECT MAX(OrderDate) FROM dbo.SalesOrderHeader WHERE SalesPersonID = sp.BusinessEntityID)" />
</rewrite-assertion>
+ <rewrite-assertion id="update_sales_person_with_linked_server_for_literals" db-types="SQLServer">
+ <input sql="UPDATE MyLinkedServer.encrypt.dbo.SalesPerson SET Bonus = 3000.00 WHERE BusinessEntityID = 1" />
+ <output sql="UPDATE MyLinkedServer.encrypt.dbo.SalesPerson SET [bonus_cipher] = 'encrypt_3000.00' WHERE BusinessEntityID = 1" />
+ </rewrite-assertion>
+
+ <rewrite-assertion id="update_account_with_database_and_schema_for_literals" db-types="PostgreSQL,openGauss">
+ <input sql="UPDATE encrypt.public.t_account SET amount = 1000 WHERE account_id = 1" />
+ <output sql="UPDATE public.t_account SET "cipher_amount" = 'encrypt_1000' WHERE account_id = 1" />
+ </rewrite-assertion>
+
<rewrite-assertion id="update_sales_person_from_cross_schema_join_for_literals" db-types="SQLServer">
<input sql="UPDATE dbo.SalesPerson SET SalesYTD = SalesYTD + SubTotal, Bonus = 3000.00 FROM Sales.SalesPerson AS sp JOIN dbo.SalesOrderHeader AS so ON sp.EmpID = so.SalesPersonID WHERE dbo.SalesPerson.BusinessEntityID = sp.EmpID" />
<output sql="UPDATE dbo.SalesPerson SET SalesYTD = SalesYTD + SubTotal, [bonus_cipher] = 'encrypt_3000.00' FROM Sales.SalesPerson AS sp JOIN dbo.SalesOrderHeader AS so ON sp.EmpID = so.SalesPersonID WHERE dbo.SalesPerson.BusinessEntityID = sp.EmpID" />