Skip to main content

uqa_sql/
sql_batch_error.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use crate::SQLError;
8
9/// An atomic batch failure with its original SQL error and, when known, zero-based member.
10/// Transaction begin, commit and rollback failures are not attributed to a member.
11#[derive(Debug, thiserror::Error)]
12#[error("{error}")]
13pub struct SQLBatchError {
14    #[source]
15    pub error: SQLError,
16    pub statement_index: Option<usize>,
17}
18
19impl SQLBatchError {
20    pub const fn statement(error: SQLError, statement_index: usize) -> Self {
21        Self {
22            error,
23            statement_index: Some(statement_index),
24        }
25    }
26
27    pub const fn transaction(error: SQLError) -> Self {
28        Self {
29            error,
30            statement_index: None,
31        }
32    }
33
34    pub fn into_error(self) -> SQLError {
35        self.error
36    }
37}