Files
MyGoNavi/internal/app/oceanbase_protocol.go
Syngnat d2dad75167 ♻️ refactor(oceanbase): 完善双协议连接链路
- 抽象 OceanBase 协议解析与运行态参数注入
- 复用 OracleDB 实现 OceanBase Oracle 租户连接能力
- 调整 DDL、schema、SQL 方言和数据源能力判断
- 补充协议优先级、缓存隔离和 RPC 参数测试
- 支持按指定 driver 自动生成 agent revision
2026-04-30 15:05:05 +08:00

76 lines
1.9 KiB
Go

package app
import (
"net/url"
"strings"
"GoNavi-Wails/internal/connection"
)
func normalizeOceanBaseProtocolForApp(raw string) string {
switch strings.ToLower(strings.TrimSpace(raw)) {
case "oracle", "oracle-mode", "oracle_mode", "oboracle":
return "oracle"
default:
return "mysql"
}
}
func resolveOceanBaseProtocolParam(raw string) string {
text := strings.TrimSpace(raw)
if text == "" {
return ""
}
if queryIndex := strings.Index(text, "?"); queryIndex >= 0 {
text = text[queryIndex+1:]
}
if hashIndex := strings.Index(text, "#"); hashIndex >= 0 {
text = text[:hashIndex]
}
values, err := url.ParseQuery(strings.TrimLeft(strings.TrimSpace(text), "?&"))
if err != nil {
return ""
}
for _, key := range []string{"protocol", "oceanBaseProtocol", "oceanbaseProtocol", "tenantMode", "compatMode", "mode"} {
if value := strings.TrimSpace(values.Get(key)); value != "" {
return normalizeOceanBaseProtocolForApp(value)
}
}
return ""
}
func normalizeOceanBaseConnectionParamsForCache(raw string) string {
text := strings.TrimSpace(raw)
if text == "" {
return ""
}
values, err := url.ParseQuery(strings.TrimLeft(text, "?&"))
if err != nil {
return text
}
if len(values) == 0 {
return ""
}
protocol := resolveOceanBaseProtocolParam(raw)
for _, key := range []string{"protocol", "oceanBaseProtocol", "oceanbaseProtocol", "tenantMode", "compatMode", "mode"} {
values.Del(key)
}
if strings.EqualFold(protocol, "oracle") {
values.Set("protocol", "oracle")
}
return values.Encode()
}
func isOceanBaseOracleProtocol(config connection.ConnectionConfig) bool {
if !strings.EqualFold(strings.TrimSpace(config.Type), "oceanbase") {
return false
}
if protocol := resolveOceanBaseProtocolParam(config.ConnectionParams); protocol != "" {
return protocol == "oracle"
}
if protocol := resolveOceanBaseProtocolParam(config.URI); protocol != "" {
return protocol == "oracle"
}
return false
}