sqlx_core/mssql/protocol/
done.rs

1use bitflags::bitflags;
2use bytes::{Buf, Bytes};
3
4use crate::error::Error;
5
6#[derive(Debug)]
7pub(crate) struct Done {
8    pub(crate) status: Status,
9
10    // The token of the current SQL statement. The token value is provided and controlled by the
11    // application layer, which utilizes TDS. The TDS layer does not evaluate the value.
12    #[allow(dead_code)]
13    cursor_command: u16,
14
15    // The count of rows that were affected by the SQL statement. The value of DoneRowCount is
16    // valid if the value of Status includes DONE_COUNT.
17    pub(crate) affected_rows: u64, // NOTE: u32 before TDS 7.2
18}
19
20impl Done {
21    pub(crate) fn get(buf: &mut Bytes) -> Result<Self, Error> {
22        let status = Status::from_bits_truncate(buf.get_u16_le());
23        let cursor_command = buf.get_u16_le();
24        let affected_rows = buf.get_u64_le();
25
26        Ok(Self {
27            affected_rows,
28            status,
29            cursor_command,
30        })
31    }
32}
33
34bitflags! {
35    pub struct Status: u16 {
36        // This DONEINPROC message is not the final DONE/DONEPROC/DONEINPROC message in
37        // the response; more data streams are to follow.
38        const DONE_MORE = 0x0001;
39
40        // An error occurred on the current SQL statement or execution of a stored procedure was
41        // interrupted. A preceding ERROR token SHOULD be sent when this bit is set.
42        const DONE_ERROR = 0x0002;
43
44        // A transaction is in progress.
45        const DONE_INXACT = 0x0004;
46
47        // The DoneRowCount value is valid. This is used to distinguish between a valid value of 0
48        // for DoneRowCount or just an initialized variable.
49        const DONE_COUNT = 0x0010;
50
51        // Used in place of DONE_ERROR when an error occurred on the current SQL statement that is
52        // severe enough to require the result set, if any, to be discarded.
53        const DONE_SRVERROR = 0x0100;
54    }
55}