hdbconnect_impl/protocol/parts/
transactionflags.rs

1use crate::protocol::parts::option_part::{OptionId, OptionPart};
2
3// The part is sent from the server to signal
4//
5// * changes of the current transaction status
6//   (committed, rolled back, start of a write transaction), and
7// * changes of the general session state
8// (transaction isolation level has changed, DDL statements are
9// automatically committed or not, it has become impossible to continue
10// processing the session)
11pub(crate) type TransactionFlags = OptionPart<TaFlagId>;
12
13#[derive(Clone, Debug, Eq, PartialEq, Hash)]
14pub(crate) enum TaFlagId {
15    RolledBack,            // 0 // BOOL    // The transaction is rolled back
16    Committed,             // 1 // BOOL    // The transaction is committed
17    NewIsolationlevel,     // 2 // INT     // The transaction isolation level has changed
18    DdlCommitmodeChanged,  // 3 // BOOL    // The DDL auto-commit mode has been changed
19    WriteTaStarted,        // 4 // BOOL    // A write transaction has been started
20    NoWriteTaStarted,      // 5 // BOOL    // No write transaction has been started
21    SessionclosingTaError, // 6 // BOOL    // The session must be terminated
22    ReadOnlyMode,          // 7 // BOOL    //
23    __Unexpected__(u8),
24}
25impl OptionId<TaFlagId> for TaFlagId {
26    fn to_u8(&self) -> u8 {
27        match *self {
28            Self::RolledBack => 0,
29            Self::Committed => 1,
30            Self::NewIsolationlevel => 2,
31            Self::DdlCommitmodeChanged => 3,
32            Self::WriteTaStarted => 4,
33            Self::NoWriteTaStarted => 5,
34            Self::SessionclosingTaError => 6,
35            Self::ReadOnlyMode => 7,
36            Self::__Unexpected__(val) => val,
37        }
38    }
39
40    fn from_u8(val: u8) -> Self {
41        match val {
42            0 => Self::RolledBack,
43            1 => Self::Committed,
44            2 => Self::NewIsolationlevel,
45            3 => Self::DdlCommitmodeChanged,
46            4 => Self::WriteTaStarted,
47            5 => Self::NoWriteTaStarted,
48            6 => Self::SessionclosingTaError,
49            7 => Self::ReadOnlyMode,
50            val => {
51                warn!("Unsupported value for TaFlagId received: {val}");
52                Self::__Unexpected__(val)
53            }
54        }
55    }
56
57    fn part_type(&self) -> &'static str {
58        "TransactionFlags"
59    }
60}
61
62impl TransactionFlags {
63    pub fn is_committed(&self) -> bool {
64        self.get(&TaFlagId::Committed)
65            .map(|bv| bv.get_bool().unwrap_or(false))
66            .unwrap_or(false)
67    }
68}