1#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2pub enum Status {
3 BadResponse,
5 CommandOk,
7 CopyBoth,
12 CopyIn,
14 CopyOut,
16 EmptyQuery,
18 FatalError,
20 NonFatalError,
22 SingleTuple,
27 TuplesOk,
29 #[deprecated(since = "4.1.0", note = "Uses TuplesOk variant instead")]
30 TupplesOk,
31
32 #[cfg(feature = "v14")]
34 PipelineSync,
35
36 #[cfg(feature = "v14")]
38 PipelineAborted,
39}
40
41#[doc(hidden)]
42impl From<pq_sys::ExecStatusType> for Status {
43 fn from(status: pq_sys::ExecStatusType) -> Self {
44 match status {
45 pq_sys::ExecStatusType::PGRES_BAD_RESPONSE => Self::BadResponse,
46 pq_sys::ExecStatusType::PGRES_COMMAND_OK => Self::CommandOk,
47 pq_sys::ExecStatusType::PGRES_COPY_BOTH => Self::CopyBoth,
48 pq_sys::ExecStatusType::PGRES_COPY_IN => Self::CopyIn,
49 pq_sys::ExecStatusType::PGRES_COPY_OUT => Self::CopyOut,
50 pq_sys::ExecStatusType::PGRES_EMPTY_QUERY => Self::EmptyQuery,
51 pq_sys::ExecStatusType::PGRES_FATAL_ERROR => Self::FatalError,
52 pq_sys::ExecStatusType::PGRES_NONFATAL_ERROR => Self::NonFatalError,
53 pq_sys::ExecStatusType::PGRES_SINGLE_TUPLE => Self::SingleTuple,
54 pq_sys::ExecStatusType::PGRES_TUPLES_OK => Self::TuplesOk,
55 #[cfg(feature = "v14")]
56 pq_sys::ExecStatusType::PGRES_PIPELINE_SYNC => Self::PipelineSync,
57 #[cfg(feature = "v14")]
58 pq_sys::ExecStatusType::PGRES_PIPELINE_ABORTED => Self::PipelineAborted,
59 #[allow(unreachable_patterns)]
60 _ => unreachable!(),
61 }
62 }
63}
64
65#[doc(hidden)]
66impl From<Status> for pq_sys::ExecStatusType {
67 fn from(status: Status) -> pq_sys::ExecStatusType {
68 (&status).into()
69 }
70}
71
72#[doc(hidden)]
73impl From<&Status> for pq_sys::ExecStatusType {
74 fn from(status: &Status) -> Self {
75 match *status {
76 Status::BadResponse => pq_sys::ExecStatusType::PGRES_BAD_RESPONSE,
77 Status::CommandOk => pq_sys::ExecStatusType::PGRES_COMMAND_OK,
78 Status::CopyBoth => pq_sys::ExecStatusType::PGRES_COPY_BOTH,
79 Status::CopyIn => pq_sys::ExecStatusType::PGRES_COPY_IN,
80 Status::CopyOut => pq_sys::ExecStatusType::PGRES_COPY_OUT,
81 Status::EmptyQuery => pq_sys::ExecStatusType::PGRES_EMPTY_QUERY,
82 Status::FatalError => pq_sys::ExecStatusType::PGRES_FATAL_ERROR,
83 Status::NonFatalError => pq_sys::ExecStatusType::PGRES_NONFATAL_ERROR,
84 Status::SingleTuple => pq_sys::ExecStatusType::PGRES_SINGLE_TUPLE,
85 Status::TuplesOk => pq_sys::ExecStatusType::PGRES_TUPLES_OK,
86 #[allow(deprecated)]
87 Status::TupplesOk => pq_sys::ExecStatusType::PGRES_TUPLES_OK,
88 #[cfg(feature = "v14")]
89 Status::PipelineSync => pq_sys::ExecStatusType::PGRES_PIPELINE_SYNC,
90 #[cfg(feature = "v14")]
91 Status::PipelineAborted => pq_sys::ExecStatusType::PGRES_PIPELINE_ABORTED,
92 #[allow(unreachable_patterns)]
93 _ => unreachable!(),
94 }
95 }
96}
97
98impl std::fmt::Display for Status {
99 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100 let status = unsafe { pq_sys::PQresStatus(self.into()) };
101
102 let s = crate::connection::PqString::from_raw(status)
103 .to_string_lossy()
104 .to_string();
105
106 f.write_str(&s)
107 }
108}