mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-25 02:00:09 +08:00
🐛 fix(sql-editor): 修复存储过程与返回结果写语句的结果识别
- 补齐 SQL 分类逻辑,识别 SQL Server 裸存储过程调用、RETURNING/OUTPUT、SELECT INTO 及消息块场景 - 调整多语句执行与批量写入分支,避免返回行或服务端消息被 Exec 路径吞掉 - 为 PostgreSQL、OpenGauss、Kingbase、HighGo 补充 notice 回传能力并增加回归测试
This commit is contained in:
60
internal/db/notice_query.go
Normal file
60
internal/db/notice_query.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type sqlTextNoticeHandlerSetter func(driver.Conn, func(string))
|
||||
|
||||
func querySQLConnWithTextNotices(ctx context.Context, conn *sql.Conn, query string, setHandler sqlTextNoticeHandlerSetter) ([]map[string]interface{}, []string, []string, error) {
|
||||
if conn == nil {
|
||||
return nil, nil, nil, fmt.Errorf("连接未打开")
|
||||
}
|
||||
if setHandler == nil {
|
||||
return nil, nil, nil, fmt.Errorf("未配置消息捕获处理器")
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
notices := make([]string, 0, 2)
|
||||
addNotice := func(text string) {
|
||||
text = strings.TrimSpace(text)
|
||||
if text != "" {
|
||||
notices = append(notices, text)
|
||||
}
|
||||
}
|
||||
|
||||
if err := conn.Raw(func(rawConn interface{}) error {
|
||||
driverConn, ok := rawConn.(driver.Conn)
|
||||
if !ok {
|
||||
return fmt.Errorf("底层连接类型不支持消息捕获")
|
||||
}
|
||||
setHandler(driverConn, addNotice)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Raw(func(rawConn interface{}) error {
|
||||
driverConn, ok := rawConn.(driver.Conn)
|
||||
if ok {
|
||||
setHandler(driverConn, nil)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
|
||||
rows, err := conn.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, nil, append([]string(nil), notices...), err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
data, columns, err := scanRows(rows)
|
||||
return data, columns, append([]string(nil), notices...), err
|
||||
}
|
||||
Reference in New Issue
Block a user