1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Representations and parsing logic for [`SQLSTATE`](https://en.wikipedia.org/wiki/SQLSTATE)
//! return codes.
//!
//! # Examples
//!
//! Parsing return codes according to the SQL standard:
//! ```
//! use sqlstate::standard::{
//! class::{DataException::DivisionByZero, Warning::PrivilegeNotGranted},
//! SqlState,
//! };
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! assert_eq!("00000".parse::<SqlState>()?, SqlState::Success(None));
//! assert_eq!("01007".parse::<SqlState>()?, SqlState::Warning(Some(PrivilegeNotGranted)));
//!
//! // Unknown codes are represented as `Other`
//! assert_eq!("XX001".parse::<SqlState>()?, SqlState::Other(String::from("XX001")));
//! # Ok(())
//! # }
//! ```
//!
//! Examining the pieces of a return code:
//! ```
//! use sqlstate::standard::{class::Warning::PrivilegeNotGranted, SqlState};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let success = SqlState::Success(None);
//! let warning = SqlState::Warning(Some(PrivilegeNotGranted));
//! assert_eq!((success.class(), success.subclass()), ("00", None));
//! assert_eq!((warning.class(), warning.subclass()), ("01", Some("007")));
//! # Ok(())
//! # }
//! ```
//!
//! Parsing return codes specific to PostgreSQL:
//! ```
//! use sqlstate::{
//! postgres::{
//! class::{DataException::InvalidJsonText, InternalError::DataCorrupted},
//! SqlState::*,
//! },
//! standard, PostgresSqlState,
//! };
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! assert_eq!("22032".parse::<PostgresSqlState>()?,
//! PostgresSqlState::Custom(DataException(Some(InvalidJsonText))));
//! assert_eq!("XX001".parse::<PostgresSqlState>()?,
//! PostgresSqlState::Custom(InternalError(Some(DataCorrupted))));
//!
//! // Can also fall back to standard codes
//! assert_eq!("00000".parse::<PostgresSqlState>()?,
//! PostgresSqlState::Standard(standard::SqlState::Success(None)));
//! # Ok(())
//! # }
//! ```
//!
//! # Features
//!
//! - `postgres`: Enables PostgreSQL-specific types.
pub use PostgresSqlState;
pub use SqlState;
/// A category for a given `SQLSTATE` code.