use uqa_sql::{SQLError, SQLNotice};
pub(super) fn sql_error_text(error: &SQLError) -> String {
let mut text = format!("{}: {error}", error.sqlstate().unwrap_or("XX000"));
if let SQLError::Diagnostic { detail, hint, .. } = error {
append_fields(&mut text, detail.as_deref(), hint.as_deref());
}
text
}
pub(super) fn sql_notice_text(notice: &SQLNotice) -> String {
let mut text = format!("{}: {}", notice.level.as_str(), notice.message);
append_fields(&mut text, notice.detail.as_deref(), notice.hint.as_deref());
text
}
fn append_fields(text: &mut String, detail: Option<&str>, hint: Option<&str>) {
if let Some(detail) = detail {
text.push_str("\nDETAIL: ");
text.push_str(detail);
}
if let Some(hint) = hint {
text.push_str("\nHINT: ");
text.push_str(hint);
}
}