Skip to main content

odbc_sys/
connection_attribute.rs

1/// Connection attributes for `SQLSetConnectAttr`
2///
3/// See: <https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function>
4#[repr(transparent)]
5#[derive(Debug, PartialEq, Eq, Clone, Copy)]
6pub struct ConnectionAttribute(pub i32);
7
8impl ConnectionAttribute {
9    pub const ASYNC_ENABLE: Self = Self(4);
10
11    /// Equivalent to `SQL_ATTR_ACCESS_MODE` in the C-API
12    pub const ACCESS_MODE: Self = Self(101);
13    /// Equivalent to `SQL_ATTR_AUTOCOMMIT` in the C-API
14    pub const AUTOCOMMIT: Self = Self(102);
15    /// Equivalent to `SQL_ATTR_LOGIN_TIMEOUT` in the C-API
16    pub const LOGIN_TIMEOUT: Self = Self(103);
17    /// Equivalent to `SQL_ATTR_TRACE` in the C-API
18    pub const TRACE: Self = Self(104);
19    /// Equivalent to `SQL_ATTR_TRACEFILE` in the C-API
20    pub const TRACEFILE: Self = Self(105);
21    /// Equivalent to `SQL_ATTR_TRANSLATE_LIB` in the C-API
22    pub const TRANSLATE_LIB: Self = Self(106);
23    /// Equivalent to `SQL_ATTR_TRANSLATE_OPTION` in the C-API
24    pub const TRANSLATE_OPTION: Self = Self(107);
25    /// Equivalent to `SQL_ATTR_TXN_ISOLATION` in the C-API
26    pub const TXN_ISOLATION: Self = Self(108);
27    /// Equivalent to `SQL_ATTR_CURRENT_CATALOG` in the C-API
28    pub const CURRENT_CATALOG: Self = Self(109);
29    /// Equivalent to `SQL_ATTR_ODBC_CURSORS` in the C-API
30    pub const ODBC_CURSORS: Self = Self(110);
31    /// Equivalent to `SQL_ATTR_QUIET_MODE` in the C-API
32    pub const QUIET_MODE: Self = Self(111);
33    /// Equivalent to `SQL_ATTR_PACKET_SIZE` in the C-API
34    pub const PACKET_SIZE: Self = Self(112);
35    /// Equivalent to `SQL_ATTR_CONNECTION_TIMEOUT` in the C-API
36    pub const CONNECTION_TIMEOUT: Self = Self(113);
37    /// Equivalent to `SQL_ATTR_DISCONNECT_BEHAVIOUR` in the C-API
38    pub const DISCONNECT_BEHAVIOUR: Self = Self(114);
39
40    // Attribute 115 is `SQL_ATTR_ANSI_APP`. This attribute is not set by an odbc applictation, but
41    // by the driver manager itself. Therfore it is not included here.
42
43    /// Equivalent to `SQL_ATTR_DBC_INFO_TOKEN`
44    ///
45    /// Reset the pooled connection in case it is not a perfect match
46    pub const DBC_INFO_TOKEN: Self = Self(118);
47
48    /// Equivalent to `SQL_ATTR_RESET_CONNECTION` in the C-API
49    pub const RESET_CONNECTION: Self = Self(116);
50    /// Equivalent to `SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE` in the C-API
51    pub const ASYNC_DBC_FUNCTIONS_ENABLE: Self = Self(117);
52    /// Equivalent to `SQL_ATTR_ASYNC_DBC_EVENT` in the C-API
53    pub const ASYNC_DBC_EVENT: Self = Self(119);
54    /// Equivalent to `SQL_ATTR_ENLIST_IN_DTC` in the C-API
55    pub const ENLIST_IN_DTC: Self = Self(1207);
56    /// Equivalent to `SQL_ATTR_ENLIST_IN_XA` in the C-API
57    pub const ENLIST_IN_XA: Self = Self(1208);
58    pub const CONNECTION_DEAD: Self = Self(1209);
59    pub const AUTO_IPD: Self = Self(10001);
60    pub const METADATA_ID: Self = Self(10014);
61
62    /// Equivalent to `SQL_COPT_SS_ACCESS_TOKEN` in `msodbcsql.h`.
63    ///
64    /// Pre-connect attribute to authenticate with a Microsoft Entra ID access token. Specific to
65    /// the Microsoft ODBC Driver for SQL Server. Setting this for other drivers could cause
66    /// undefined behavior. The value is a pointer to an [`SsAccessToken`]. It must stay allocated
67    /// for as long as the connection handle is allocated.
68    ///
69    /// See:
70    /// <https://learn.microsoft.com/sql/connect/odbc/using-azure-active-directory#authenticating-with-an-access-token>
71    pub const SS_ACCESS_TOKEN: Self = Self(1256);
72}
73
74/// Equivalent to `ACCESSTOKEN` in `msodbcsql.h`. Value of [`ConnectionAttribute::SS_ACCESS_TOKEN`].
75///
76/// Specific to the Microsoft ODBC Driver for SQL Server. A dynamically sized type: pointers to it
77/// are fat and carry the length of `data`, which must equal `data_size`. Cast to a thin pointer
78/// before passing it to the driver.
79///
80/// See:
81/// <https://learn.microsoft.com/sql/connect/odbc/using-azure-active-directory#authenticating-with-an-access-token>
82#[repr(C)]
83pub struct SsAccessToken {
84    /// Length of `data` in bytes. Does not include a terminating zero.
85    pub data_size: u32,
86    /// Flexible array member (`BYTE data[]` in C). Directly follows `data_size`.
87    ///
88    /// According to Microsoft, a token obtained from an OAuth 2.0 JSON response must be expanded,
89    /// so each byte is followed by a zero byte. For the ASCII characters of an access token, this
90    /// equals UTF-16 with little endian byte order. This holds whether the narrow or wide ODBC
91    /// functions are used, since the driver manager passes the pointer through unchanged.
92    pub data: [u8],
93}