mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-13 00:13:33 +08:00
- 区分 BEGIN 事务控制语句与 Oracle 匿名块起始 - 让包含 DML 的 Oracle like 匿名块进入 SQL 编辑器托管事务 - 补充匿名块进入事务与回滚收口的后端回归测试
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestShouldUseManagedSQLTransaction_UnsupportedTypesUsePlainExecution(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
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)"},
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestShouldUseManagedSQLTransaction_OracleAnonymousBlockWithDMLUsesManagedTransaction(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
query := `BEGIN
|
|
UPDATE users SET name = 'new' WHERE id = 1;
|
|
DELETE FROM audit_logs WHERE user_id = 1;
|
|
END;`
|
|
if !shouldUseManagedSQLTransaction("oracle", query) {
|
|
t.Fatal("expected Oracle anonymous block with DML to use SQL editor managed transaction")
|
|
}
|
|
}
|
|
|
|
func TestShouldUseManagedSQLTransaction_OracleReadOnlyAnonymousBlockStaysUnmanaged(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
query := `BEGIN
|
|
NULL;
|
|
END;`
|
|
if shouldUseManagedSQLTransaction("oracle", query) {
|
|
t.Fatal("expected Oracle read-only anonymous block to stay unmanaged")
|
|
}
|
|
}
|