#[non_exhaustive]pub struct SqlErrorInfo { /* private fields */ }Expand description
结构化数据库错误信息(SQLSTATE + 常用诊断字段)。
Implementations§
Source§impl SqlErrorInfo
impl SqlErrorInfo
Sourcepub fn new(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self
创建仅含 SQLSTATE 与报文的错误信息。
Sourcepub fn with_constraint(self, constraint: Option<String>) -> Self
pub fn with_constraint(self, constraint: Option<String>) -> Self
设置约束名。
Sourcepub fn with_schema(self, schema: Option<String>) -> Self
pub fn with_schema(self, schema: Option<String>) -> Self
设置 schema 名。
Sourcepub fn with_table(self, table: Option<String>) -> Self
pub fn with_table(self, table: Option<String>) -> Self
设置表名。
Sourcepub fn with_column(self, column: Option<String>) -> Self
pub fn with_column(self, column: Option<String>) -> Self
设置列名。
Sourcepub fn with_detail(self, detail: Option<String>) -> Self
pub fn with_detail(self, detail: Option<String>) -> Self
设置 DETAIL 诊断信息。
Sourcepub fn with_kind_hint(self, kind: SqlErrorKind) -> Self
pub fn with_kind_hint(self, kind: SqlErrorKind) -> Self
在 SQLSTATE 不足以区分时补充错误类别(如 MySQL 23000)。
Sourcepub fn constraint(&self) -> Option<&str>
pub fn constraint(&self) -> Option<&str>
触发错误的约束名(如唯一索引名)。
Sourcepub fn kind(&self) -> SqlErrorKind
pub fn kind(&self) -> SqlErrorKind
归一后的错误类别。
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
是否为可安全重试的瞬时错误。
仅 PostgreSQL 的 40001(序列化失败)、40P01(死锁)、08 类
(连接失败/断开)与 53 类(资源不足,如连接数超限)返回 true。
其余 SQLSTATE 一律不可重试,尤其是:
55P03锁不可用(锁等待超时):属于DbErrorCategory::Timeout, 是否重试由调用方决定;57014语句被取消:同样归DbErrorCategory::Timeout,不是瞬时故障;25P02事务已中止:必须先ROLLBACK,重试只会在中止事务上继续失败。
Trait Implementations§
Source§impl Clone for SqlErrorInfo
impl Clone for SqlErrorInfo
Source§impl Debug for SqlErrorInfo
impl Debug for SqlErrorInfo
impl Eq for SqlErrorInfo
Source§impl PartialEq for SqlErrorInfo
impl PartialEq for SqlErrorInfo
impl StructuralPartialEq for SqlErrorInfo
Auto Trait Implementations§
impl Forget for SqlErrorInfo
impl Freeze for SqlErrorInfo
impl Move for SqlErrorInfo
impl RefUnwindSafe for SqlErrorInfo
impl Send for SqlErrorInfo
impl Sync for SqlErrorInfo
impl Unpin for SqlErrorInfo
impl UnsafeUnpin for SqlErrorInfo
impl UnwindSafe for SqlErrorInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more