mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-09 08:13:29 +08:00
🐛 fix(tdengine): 修复查询结果仅显示执行日志
- TDengine 只读查询跳过不支持的多结果集探测 - 保证可选驱动代理通过普通查询返回完整行列数据 - 补充应用层与驱动层回归测试 Fixes #610
This commit is contained in:
@@ -1700,6 +1700,11 @@ func shouldPreferPlainReadQueryResult(dbType string) bool {
|
||||
"gaussdb", "gauss_db", "gauss-db",
|
||||
"dameng", "dm", "dm8":
|
||||
return true
|
||||
case "tdengine":
|
||||
// TDengine only implements the plain query API. The optional driver-agent
|
||||
// exposes a transport-level multi-result method, but reports it unsupported.
|
||||
// Skipping that probe prevents a successful SELECT from becoming an empty result.
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s *fakeUnsupportedMultiResultSession) QueryMultiContextWithMessages(contex
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func installFakeOptionalSQLiteDatabase(t *testing.T, fakeDB db.Database) {
|
||||
func installFakeOptionalDriverDatabase(t *testing.T, fakeDB db.Database) {
|
||||
t.Helper()
|
||||
originalNewDatabaseFunc := newDatabaseFunc
|
||||
originalDriverRuntimeSupportStatusFunc := driverRuntimeSupportStatusFunc
|
||||
@@ -126,7 +126,7 @@ func TestDBQueryMultiSQLiteAgentStyleQueryReturnsRowsAndAuditCount(t *testing.T)
|
||||
queryErr: map[string]error{},
|
||||
}
|
||||
fakeDB := &fakeUnsupportedMultiResultDB{fakeBatchWriteDB: baseDB}
|
||||
installFakeOptionalSQLiteDatabase(t, fakeDB)
|
||||
installFakeOptionalDriverDatabase(t, fakeDB)
|
||||
|
||||
app := newSQLAuditTestApp(t)
|
||||
config := connection.ConnectionConfig{Type: "sqlite", Host: "/tmp/orders.sqlite"}
|
||||
|
||||
64
internal/app/methods_db_tdengine_agent_regression_test.go
Normal file
64
internal/app/methods_db_tdengine_agent_regression_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"GoNavi-Wails/internal/connection"
|
||||
"GoNavi-Wails/internal/db"
|
||||
)
|
||||
|
||||
type fakeTDengineOptionalAgentDB struct {
|
||||
*fakeUnsupportedMultiResultDB
|
||||
}
|
||||
|
||||
func (*fakeTDengineOptionalAgentDB) OpenSessionExecer(context.Context) (db.StatementExecer, error) {
|
||||
return nil, errors.New("TDengine driver does not support pinned sessions")
|
||||
}
|
||||
|
||||
func TestDBQueryMultiTDengineAgentSelectUsesPlainQuery(t *testing.T) {
|
||||
query := "SELECT ts, current FROM meters ORDER BY ts DESC LIMIT 1"
|
||||
baseDB := &fakeBatchWriteDB{
|
||||
queryMap: map[string][]map[string]interface{}{
|
||||
query: {{"ts": "2026-07-19T00:00:00+08:00", "current": 10.2}},
|
||||
},
|
||||
fieldMap: map[string][]string{
|
||||
query: {"ts", "current"},
|
||||
},
|
||||
queryErr: map[string]error{},
|
||||
}
|
||||
fakeDB := &fakeTDengineOptionalAgentDB{
|
||||
fakeUnsupportedMultiResultDB: &fakeUnsupportedMultiResultDB{fakeBatchWriteDB: baseDB},
|
||||
}
|
||||
installFakeOptionalDriverDatabase(t, fakeDB)
|
||||
|
||||
app := NewApp()
|
||||
result := app.DBQueryMulti(
|
||||
connection.ConnectionConfig{Type: "tdengine", Host: "127.0.0.1", Port: 6041},
|
||||
"power",
|
||||
query,
|
||||
"tdengine-agent-select",
|
||||
)
|
||||
if !result.Success {
|
||||
t.Fatalf("TDengine agent SELECT returned failure: %s", result.Message)
|
||||
}
|
||||
|
||||
resultSets, ok := result.Data.([]connection.ResultSetData)
|
||||
if !ok || len(resultSets) != 1 {
|
||||
t.Fatalf("TDengine agent SELECT result sets = %#v, want one result set", result.Data)
|
||||
}
|
||||
if !reflect.DeepEqual(resultSets[0].Columns, []string{"ts", "current"}) {
|
||||
t.Fatalf("TDengine agent SELECT columns = %#v", resultSets[0].Columns)
|
||||
}
|
||||
if len(resultSets[0].Rows) != 1 || resultSets[0].Rows[0]["current"] != 10.2 {
|
||||
t.Fatalf("TDengine agent SELECT rows = %#v, want one data row", resultSets[0].Rows)
|
||||
}
|
||||
if fakeDB.multiCalls != 0 {
|
||||
t.Fatalf("TDengine SELECT must not probe unsupported multi-result API, calls=%d", fakeDB.multiCalls)
|
||||
}
|
||||
if baseDB.queryCalls != 1 {
|
||||
t.Fatalf("TDengine SELECT should execute exactly once through plain Query, calls=%d", baseDB.queryCalls)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user