fix(editor): preserve current SQL execution boundaries

This commit is contained in:
zipg authored and GitHub committed 2026-08-04 00:37:42 +08:00
1 parent c9764be9a0
commit a6f1a9a871
13 files changed
+232 -44

No files matched your search

+35 -3
View File
@@ -1613,15 +1613,22 @@ fn classify_query_error(db_type: Option<DatabaseType>, error: QueryExecutionErro
QueryExecutionError::Legacy(message) if is_dbx_query_timeout_error(&message.to_ascii_lowercase()) => {
QueryExecutionError::Timeout(message)
}
QueryExecutionError::Legacy(message)
if db_type == Some(DatabaseType::Postgres) && message.trim_start().starts_with("ERROR:") =>
{
QueryExecutionError::Legacy(message) if is_native_sql_server_error(db_type, &message) => {
QueryExecutionError::Sql(message)
}
other => other,
}
}
fn is_native_sql_server_error(db_type: Option<DatabaseType>, message: &str) -> bool {
let message = message.trim_start();
match db_type {
Some(DatabaseType::Postgres) => message.starts_with("ERROR:"),
Some(DatabaseType::Mysql) => message.starts_with("Server error: `ERROR "),
_ => false,
}
}
pub async fn do_execute(
state: &AppState,
pool_key: &str,
@@ -5043,6 +5050,31 @@ for line in sys.stdin:
);
}
#[test]
fn mysql_server_error_preserves_sql_catalog_identity_and_detail() {
let error = classify_query_error(
Some(DatabaseType::Mysql),
QueryExecutionError::Legacy(
"Server error: `ERROR 1064 (42000): You have an error in your SQL syntax`".to_string(),
),
)
.with_omitted_sql_context("SELECT 111 AS first_value FROM DUAL");
let backend_error = error.into_backend_error();
assert_eq!(backend_error.code(), "DBX-JDBC-4001");
assert_eq!(backend_error.message_key(), "backendErrors.jdbc.sqlFailed");
assert_eq!(
backend_error.message_params().get("stage"),
Some(&crate::backend_error::BackendMessageParam::String("execute".to_string()))
);
assert_eq!(
backend_error.detail(),
Some(
"Server error: `ERROR 1064 (42000): You have an error in your SQL syntax` SQL text omitted from user-facing error; enable debug SQL diagnostics for a redacted statement."
)
);
}
#[test]
fn single_statement_multi_result_preserves_sql_error_type() {
let error = classify_query_error(