fix(connection): preserve Oracle SID fallback
This commit is contained in:
1 parent
9622080e59
commit
b4e9e798f1
5 files changed
+119
-25
No files matched your search
@@ -3,8 +3,8 @@ use tauri::State;
|
||||
|
||||
pub use dbx_core::connection::{
|
||||
agent_connect_params, connection_url_for_endpoint, expand_tilde, metadata_connection_config,
|
||||
mongo_legacy_error_with_auth_hint, probe_connection_endpoint, redacted_connection_url_for_endpoint, AppState,
|
||||
MysqlMode, PoolKind,
|
||||
mongo_legacy_error_with_auth_hint, probe_connection_endpoint, redacted_connection_url_for_endpoint,
|
||||
should_retry_oracle_with_10g_driver, AppState, MysqlMode, PoolKind,
|
||||
};
|
||||
use dbx_core::database_capabilities;
|
||||
use dbx_core::db;
|
||||
@@ -17,6 +17,69 @@ fn mongo_legacy_connect_params(config: &ConnectionConfig, host: &str, port: u16)
|
||||
})
|
||||
}
|
||||
|
||||
async fn test_agent_connection(
|
||||
state: &Arc<AppState>,
|
||||
config: &ConnectionConfig,
|
||||
host: &str,
|
||||
port: u16,
|
||||
) -> Result<String, String> {
|
||||
let connect_params = agent_connect_params(config, host, port, config.database.as_deref().unwrap_or(""));
|
||||
let result = state
|
||||
.agent_manager
|
||||
.call_daemon_method::<serde_json::Value>(
|
||||
&config.db_type,
|
||||
config.driver_profile.as_deref(),
|
||||
AgentMethod::TestConnection,
|
||||
connect_params.clone(),
|
||||
)
|
||||
.await;
|
||||
|
||||
if let Err(err) = result {
|
||||
if should_retry_oracle_with_10g_driver(config, &err) {
|
||||
state
|
||||
.agent_manager
|
||||
.call_daemon_method::<serde_json::Value>(
|
||||
&config.db_type,
|
||||
Some("oracle-10g"),
|
||||
AgentMethod::TestConnection,
|
||||
connect_params,
|
||||
)
|
||||
.await
|
||||
.map_err(|fallback_err| format!("{err}\n\nFallback with oracle-10g driver failed: {fallback_err}"))?;
|
||||
} else {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
Ok("Connection successful".to_string())
|
||||
}
|
||||
|
||||
async fn connect_agent_pool(
|
||||
state: &Arc<AppState>,
|
||||
config: &ConnectionConfig,
|
||||
host: &str,
|
||||
port: u16,
|
||||
) -> Result<PoolKind, String> {
|
||||
let connect_params = agent_connect_params(config, host, port, config.effective_database().unwrap_or(""));
|
||||
let mut client = state.agent_manager.spawn(&config.db_type, config.driver_profile.as_deref()).await?;
|
||||
let connect_result = client.call_method::<serde_json::Value>(AgentMethod::Connect, connect_params.clone()).await;
|
||||
|
||||
if let Err(err) = connect_result {
|
||||
if should_retry_oracle_with_10g_driver(config, &err) {
|
||||
let mut fallback_client = state.agent_manager.spawn(&config.db_type, Some("oracle-10g")).await?;
|
||||
fallback_client
|
||||
.call_method::<serde_json::Value>(AgentMethod::Connect, connect_params)
|
||||
.await
|
||||
.map_err(|fallback_err| format!("{err}\n\nFallback with oracle-10g driver failed: {fallback_err}"))?;
|
||||
client = fallback_client;
|
||||
} else {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(PoolKind::Agent(Arc::new(tokio::sync::Mutex::new(client))))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::mongo_legacy_connect_params;
|
||||
@@ -205,16 +268,7 @@ pub async fn test_connection(state: State<'_, Arc<AppState>>, config: Connection
|
||||
db::elasticsearch_driver::test_connection(&client).await.map(|_| "Connection successful".to_string())
|
||||
}
|
||||
db_type if database_capabilities::is_agent_type(&db_type) => {
|
||||
state
|
||||
.agent_manager
|
||||
.call_daemon_method::<serde_json::Value>(
|
||||
&config.db_type,
|
||||
config.driver_profile.as_deref(),
|
||||
AgentMethod::TestConnection,
|
||||
agent_connect_params(&config, &host, port, config.database.as_deref().unwrap_or("")),
|
||||
)
|
||||
.await?;
|
||||
Ok("Connection successful".to_string())
|
||||
test_agent_connection(state.inner(), &config, &host, port).await
|
||||
}
|
||||
DatabaseType::Jdbc => {
|
||||
let mut jdbc_config = config.clone();
|
||||
@@ -328,14 +382,7 @@ pub async fn connect_db(state: State<'_, Arc<AppState>>, config: ConnectionConfi
|
||||
PoolKind::Elasticsearch(client)
|
||||
}
|
||||
db_type if database_capabilities::is_agent_type(&db_type) => {
|
||||
let mut client = state.agent_manager.spawn(&db_config.db_type, db_config.driver_profile.as_deref()).await?;
|
||||
client
|
||||
.call_method::<serde_json::Value>(
|
||||
AgentMethod::Connect,
|
||||
agent_connect_params(&db_config, &host, port, db_config.effective_database().unwrap_or("")),
|
||||
)
|
||||
.await?;
|
||||
PoolKind::Agent(std::sync::Arc::new(tokio::sync::Mutex::new(client)))
|
||||
connect_agent_pool(state.inner(), &db_config, &host, port).await?
|
||||
}
|
||||
DatabaseType::Jdbc => state.external_driver_pool("jdbc", &db_config).await?,
|
||||
db_type => return Err(format!("Unsupported database type: {db_type:?}")),
|
||||
|
||||
Reference in new issue
Block a user