mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-08 21:51:33 +08:00
🐛 fix(sql-editor): 修复存储过程与返回结果写语句的结果识别
- 补齐 SQL 分类逻辑,识别 SQL Server 裸存储过程调用、RETURNING/OUTPUT、SELECT INTO 及消息块场景 - 调整多语句执行与批量写入分支,避免返回行或服务端消息被 Exec 路径吞掉 - 为 PostgreSQL、OpenGauss、Kingbase、HighGo 补充 notice 回传能力并增加回归测试
This commit is contained in:
@@ -86,6 +86,13 @@ func TestIsReadOnlySQLQuery_ClassifiesWithByTopLevelOperation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsReadOnlySQLQuery_TreatsSelectIntoAsWrite(t *testing.T) {
|
||||
query := "SELECT * INTO archived_users FROM users"
|
||||
if isReadOnlySQLQuery("postgres", query) {
|
||||
t.Fatal("SELECT INTO should not be treated as read-only")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsReadOnlySQLQuery_TreatsKafkaConsumeAsReadOnly(t *testing.T) {
|
||||
if !isReadOnlySQLQuery("kafka", `CONSUME GROUP "analytics" FROM "orders.events" LIMIT 20`) {
|
||||
t.Fatal("Kafka CONSUME should be treated as read-only")
|
||||
@@ -102,6 +109,9 @@ func TestIsBatchableWriteSQLStatement_OnlyMatchesRealWriteStatements(t *testing.
|
||||
if !isBatchableWriteSQLStatement("postgres", "WITH moved AS (DELETE FROM audit_logs WHERE created_at < NOW() RETURNING id) SELECT * FROM moved") {
|
||||
t.Fatal("expected data-changing CTE to be treated as batchable write")
|
||||
}
|
||||
if !isBatchableWriteSQLStatement("postgres", "SELECT * INTO archived_users FROM users") {
|
||||
t.Fatal("expected SELECT INTO to be treated as batchable write")
|
||||
}
|
||||
if isBatchableWriteSQLStatement("sqlserver", "EXEC sp_who2") {
|
||||
t.Fatal("EXEC should not be treated as batchable write")
|
||||
}
|
||||
@@ -131,6 +141,45 @@ func TestShouldTryQueryResultFirst_TreatsSQLServerSystemCommandsAsQueryFirst(t *
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldTryQueryResultFirst_TreatsSQLServerBareProcedureCallsAsQueryFirst(t *testing.T) {
|
||||
if !shouldTryQueryResultFirst("sqlserver", `p_get_select c_dyscript,'projectid = 1',1`) {
|
||||
t.Fatal("expected bare SQL Server procedure call to try query-first")
|
||||
}
|
||||
if !shouldTryQueryResultFirst("sqlserver", `dbo.p_get_select c_dyscript,'projectid = 1',1`) {
|
||||
t.Fatal("expected schema-qualified SQL Server procedure call to try query-first")
|
||||
}
|
||||
if !shouldTryQueryResultFirst("sqlserver", `[dbo].[p_get_select] c_dyscript,'projectid = 1',1`) {
|
||||
t.Fatal("expected bracket-qualified SQL Server procedure call to try query-first")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldTryQueryResultFirst_TreatsReturningAndOutputWritesAsQueryFirst(t *testing.T) {
|
||||
if !shouldTryQueryResultFirst("postgres", "INSERT INTO audit_logs(id) VALUES (1) RETURNING id") {
|
||||
t.Fatal("expected INSERT ... RETURNING to try query-first")
|
||||
}
|
||||
if !shouldTryQueryResultFirst("sqlserver", "UPDATE users SET name = 'next' OUTPUT inserted.id WHERE id = 1") {
|
||||
t.Fatal("expected SQL Server OUTPUT DML to try query-first")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldTryQueryResultFirst_TreatsWrappedMessageBlocksAsQueryFirst(t *testing.T) {
|
||||
if !shouldTryQueryResultFirst("sqlserver", "IF 1 = 1 EXEC dbo.p_get_select @name = 'demo'") {
|
||||
t.Fatal("expected control-flow wrapped SQL Server procedure call to try query-first")
|
||||
}
|
||||
if !shouldTryQueryResultFirst("sqlserver", "BEGIN PRINT 'done'; END") {
|
||||
t.Fatal("expected SQL Server BEGIN/PRINT block to try query-first")
|
||||
}
|
||||
if !shouldTryQueryResultFirst("postgres", "DO $$ BEGIN RAISE NOTICE 'done'; END $$") {
|
||||
t.Fatal("expected PostgreSQL DO/RAISE NOTICE block to try query-first")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldTryQueryResultFirst_DoesNotMisclassifyPlainSQLServerDML(t *testing.T) {
|
||||
if shouldTryQueryResultFirst("sqlserver", "UPDATE users SET name = 'next' WHERE id = 1") {
|
||||
t.Fatal("plain SQL Server UPDATE should not try query-first")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldTryQueryResultFirst_TreatsDataChangingCTESelectAsQueryFirst(t *testing.T) {
|
||||
query := "WITH moved AS (DELETE FROM audit_logs WHERE created_at < NOW() RETURNING id) SELECT * FROM moved"
|
||||
if !shouldTryQueryResultFirst("postgres", query) {
|
||||
|
||||
Reference in New Issue
Block a user