🐛 fix(query-editor): 跳过TDengine托管事务

Fixes #592
This commit is contained in:
Syngnat
2026-06-27 10:41:28 +08:00
parent a24f4a2bc1
commit 2d73bcc6de
5 changed files with 86 additions and 11 deletions

View File

@@ -369,7 +369,7 @@ func executeManagedSQLTransactionStatements(ctx context.Context, session db.Stat
}
func shouldUseManagedSQLTransaction(dbType string, query string) bool {
if strings.EqualFold(strings.TrimSpace(dbType), "trino") {
if isManagedSQLTransactionUnsupportedType(dbType) {
return false
}
statements := splitSQLStatements(query)
@@ -394,6 +394,15 @@ func shouldUseManagedSQLTransaction(dbType string, query string) bool {
return hasManagedWrite
}
func isManagedSQLTransactionUnsupportedType(dbType string) bool {
switch strings.ToLower(strings.TrimSpace(dbType)) {
case "trino", "tdengine", "clickhouse", "iotdb", "rocketmq", "mqtt", "kafka", "rabbitmq":
return true
default:
return false
}
}
func sqlEditorImplicitTransactionSQL(dbType string) (commitSQL string, rollbackSQL string, ok bool) {
switch strings.ToLower(strings.TrimSpace(dbType)) {
case "oracle":

View File

@@ -2,13 +2,28 @@ package app
import "testing"
func TestShouldUseManagedSQLTransaction_TrinoAlwaysUsesPlainExecution(t *testing.T) {
func TestShouldUseManagedSQLTransaction_UnsupportedTypesUsePlainExecution(t *testing.T) {
t.Parallel()
if shouldUseManagedSQLTransaction("trino", "UPDATE hive.default.orders SET status = 'done'") {
t.Fatal("expected trino DML to skip SQL editor managed transactions")
cases := []struct {
dbType string
query string
}{
{dbType: "trino", query: "UPDATE hive.default.orders SET status = 'done'"},
{dbType: "tdengine", query: "INSERT INTO meters(ts, current) VALUES (NOW, 10.2)"},
{dbType: "clickhouse", query: `INSERT INTO events FORMAT JSONEachRow {"id":1}`},
{dbType: "iotdb", query: "INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(1,true)"},
}
if shouldUseManagedSQLTransaction("trino", "BEGIN; UPDATE hive.default.orders SET status = 'done'; COMMIT;") {
t.Fatal("expected trino explicit transactions to stay unmanaged")
for _, tc := range cases {
tc := tc
t.Run(tc.dbType, func(t *testing.T) {
t.Parallel()
if shouldUseManagedSQLTransaction(tc.dbType, tc.query) {
t.Fatalf("expected %s DML to skip SQL editor managed transactions", tc.dbType)
}
if shouldUseManagedSQLTransaction(tc.dbType, "BEGIN; "+tc.query+"; COMMIT;") {
t.Fatalf("expected %s explicit transactions to stay unmanaged", tc.dbType)
}
})
}
}