Compare commits

..

5 Commits

4 changed files with 22 additions and 1 deletions

View File

@@ -37,6 +37,13 @@ describe('formatSqlExecutionError', () => {
expect(formatted).toContain('Raw error: driver returned unexpected status 123'); expect(formatted).toContain('Raw error: driver returned unexpected status 123');
}); });
it('recognizes driver bad connection during SQL execution as timeout semantics', () => {
const formatted = formatSqlExecutionError('第 1 条语句执行失败driver: bad connection');
expect(formatted).toContain('Semantic meaning: Query timed out or was canceled');
expect(formatted).toContain('Raw error: 第 1 条语句执行失败driver: bad connection');
});
it('recognizes localized connection-timeout wrappers as timeout semantics', () => { it('recognizes localized connection-timeout wrappers as timeout semantics', () => {
const translate = (key: string, params?: Record<string, unknown>) => { const translate = (key: string, params?: Record<string, unknown>) => {
if (key === 'query_editor.sql_error.wrapper.semantic_line') { if (key === 'query_editor.sql_error.wrapper.semantic_line') {

View File

@@ -135,6 +135,7 @@ const SQL_ERROR_RULES: SqlErrorSemanticRule[] = [
/context cancelled/i, /context cancelled/i,
/timeout/i, /timeout/i,
/timed out/i, /timed out/i,
/driver:\s*bad connection/i,
], ],
}, },
{ {

View File

@@ -9,6 +9,8 @@ import (
"GoNavi-Wails/internal/db" "GoNavi-Wails/internal/db"
) )
const defaultOceanBaseOracleQueryTimeoutSeconds = 120
func normalizeRunConfig(config connection.ConnectionConfig, dbName string) connection.ConnectionConfig { func normalizeRunConfig(config connection.ConnectionConfig, dbName string) connection.ConnectionConfig {
runConfig := config runConfig := config
name := strings.TrimSpace(dbName) name := strings.TrimSpace(dbName)
@@ -54,6 +56,10 @@ func applyOceanBaseOracleCurrentSchemaInit(config connection.ConnectionConfig, s
if normalizedSchema == "" { if normalizedSchema == "" {
return config return config
} }
if config.Timeout <= 0 {
// OceanBase Oracle 查询经常需要经过 OBProxy/Oracle driver 的读等待;默认 30s 容易把慢查询误报成 driver: bad connection。
config.Timeout = defaultOceanBaseOracleQueryTimeoutSeconds
}
values, err := url.ParseQuery(strings.TrimSpace(config.ConnectionParams)) values, err := url.ParseQuery(strings.TrimSpace(config.ConnectionParams))
if err != nil { if err != nil {
return config return config

View File

@@ -20,6 +20,9 @@ func TestNormalizeRunConfig_OceanBaseOracleAddsCurrentSchemaInit(t *testing.T) {
if runConfig.Database != "OBORCL" { if runConfig.Database != "OBORCL" {
t.Fatalf("expected OceanBase Oracle service name to stay OBORCL, got %q", runConfig.Database) t.Fatalf("expected OceanBase Oracle service name to stay OBORCL, got %q", runConfig.Database)
} }
if runConfig.Timeout != defaultOceanBaseOracleQueryTimeoutSeconds {
t.Fatalf("expected OceanBase Oracle default query timeout %d, got %d", defaultOceanBaseOracleQueryTimeoutSeconds, runConfig.Timeout)
}
values, err := url.ParseQuery(runConfig.ConnectionParams) values, err := url.ParseQuery(runConfig.ConnectionParams)
if err != nil { if err != nil {
t.Fatalf("unexpected connection params parse error: %v", err) t.Fatalf("unexpected connection params parse error: %v", err)
@@ -30,17 +33,21 @@ func TestNormalizeRunConfig_OceanBaseOracleAddsCurrentSchemaInit(t *testing.T) {
} }
} }
func TestNormalizeRunConfig_OceanBaseOraclePreservesExistingInit(t *testing.T) { func TestNormalizeRunConfig_OceanBaseOraclePreservesExplicitTimeoutAndExistingInit(t *testing.T) {
t.Parallel() t.Parallel()
config := connection.ConnectionConfig{ config := connection.ConnectionConfig{
Type: "oceanbase", Type: "oceanbase",
Database: "OBORCL", Database: "OBORCL",
OceanBaseProtocol: "oracle", OceanBaseProtocol: "oracle",
Timeout: 45,
ConnectionParams: "init=ALTER+SESSION+SET+NLS_DATE_FORMAT%3D%27YYYY-MM-DD%27&timeout=10s", ConnectionParams: "init=ALTER+SESSION+SET+NLS_DATE_FORMAT%3D%27YYYY-MM-DD%27&timeout=10s",
} }
runConfig := normalizeRunConfig(config, "sbdev") runConfig := normalizeRunConfig(config, "sbdev")
if runConfig.Timeout != 45 {
t.Fatalf("expected explicit timeout to be preserved, got %d", runConfig.Timeout)
}
values, err := url.ParseQuery(runConfig.ConnectionParams) values, err := url.ParseQuery(runConfig.ConnectionParams)
if err != nil { if err != nil {
t.Fatalf("unexpected connection params parse error: %v", err) t.Fatalf("unexpected connection params parse error: %v", err)