sqlx_core/mssql/protocol/
error.rs

1use crate::mssql::io::MssqlBufExt;
2use bytes::{Buf, Bytes};
3
4#[derive(Debug)]
5pub(crate) struct Error {
6    // The error number
7    pub(crate) number: i32,
8
9    // The error state, used as a modifier to the error number.
10    pub(crate) state: u8,
11
12    // The class (severity) of the error. A class of less than 10 indicates
13    // an informational message.
14    pub(crate) class: u8,
15
16    // The message text length and message text using US_VARCHAR format.
17    pub(crate) message: String,
18
19    // The server name length and server name using B_VARCHAR format
20    pub(crate) server: String,
21
22    // The stored procedure name length and the stored procedure name using B_VARCHAR format
23    pub(crate) procedure: String,
24
25    // The line number in the SQL batch or stored procedure that caused the error. Line numbers
26    // begin at 1. If the line number is not applicable to the message, the
27    // value of LineNumber is 0.
28    pub(crate) line: i32,
29}
30
31impl Error {
32    pub(crate) fn get(buf: &mut Bytes) -> Result<Self, crate::error::Error> {
33        let len = buf.get_u16_le();
34        let mut data = buf.split_to(len as usize);
35
36        let number = data.get_i32_le();
37        let state = data.get_u8();
38        let class = data.get_u8();
39        let message = data.get_us_varchar()?;
40        let server = data.get_b_varchar()?;
41        let procedure = data.get_b_varchar()?;
42        let line = data.get_i32_le();
43
44        Ok(Self {
45            number,
46            state,
47            class,
48            message,
49            server,
50            procedure,
51            line,
52        })
53    }
54}