mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-05 01:51:43 +08:00
@@ -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":
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user