rs_odbc/sqlreturn.rs
1use rs_odbc_derive::odbc_type;
2
3/// Each function in ODBC returns a code, known as its return code, which indicates the
4/// overall success or failure of the function. Program logic is generally based on return
5/// codes.
6///
7/// # Documentation
8/// https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/return-codes-odbc
9/// https://github.com/microsoft/ODBC-Specification/blob/ODBC%204.0.md
10#[must_use]
11#[odbc_type(SQLSMALLINT)]
12pub struct SQLRETURN;
13
14/// Function completed successfully. The application calls SQLGetDiagField to retrieve
15/// additional information from the header record.
16pub const SQL_SUCCESS: SQLRETURN = SQLRETURN(0);
17
18/// Function completed successfully, possibly with a nonfatal error (warning). The
19/// application calls SQLGetDiagRec or SQLGetDiagField to retrieve additional
20/// information.
21pub const SQL_SUCCESS_WITH_INFO: SQLRETURN = SQLRETURN(1);
22
23/// Function failed. The application calls SQLGetDiagRec or SQLGetDiagField to
24/// retrieve additional information. The contents of any output arguments to the
25/// function are undefined.
26pub const SQL_ERROR: SQLRETURN = SQLRETURN(-1);
27
28// TODO: Can this error occur?
29/// Function failed due to an invalid environment, connection, statement, or
30/// descriptor handle. This indicates a programming error. No additional information
31/// is available from SQLGetDiagRec or SQLGetDiagField. This code is returned only
32/// when the handle is a null pointer or is the wrong type, such as when a statement
33/// handle is passed for an argument that requires a connection handle.
34pub const SQL_INVALID_HANDLE: SQLRETURN = SQLRETURN(-2);
35
36/// No more data was available. The application calls SQLGetDiagRec or SQLGetDiagField
37/// to retrieve additional information. One or more driver-defined status records in
38/// class 02xxx may be returned. Note: In ODBC 2.x, this return code was named
39/// SQL_NO_DATA_FOUND.
40pub const SQL_NO_DATA: SQLRETURN = SQLRETURN(100);
41
42/// More data is needed, such as when parameter data is sent at execution time or
43/// additional connection information is required. The application calls SQLGetDiagRec
44/// or SQLGetDiagField to retrieve additional information, if any.
45pub const SQL_NEED_DATA: SQLRETURN = SQLRETURN(99);
46
47/// A function that was started asynchronously is still executing. The application
48/// calls SQLGetDiagRec or SQLGetDiagField to retrieve additional information, if any.
49pub const SQL_STILL_EXECUTING: SQLRETURN = SQLRETURN(2);
50
51/// Indicates that there are streamed output parameters available for the next set of
52/// parameters to retrieve.
53#[cfg(feature = "v3_8")]
54pub const SQL_PARAM_DATA_AVAILABLE: SQLRETURN = SQLRETURN(101);
55
56/// Signals data-at-fetch columns are available.
57#[cfg(feature = "v4")]
58pub const SQL_DATA_AVAILABLE: SQLRETURN = SQLRETURN(102);
59
60/// The descriptor is changed by the driver when reading a column.
61#[cfg(feature = "v4")]
62pub const SQL_METADATA_CHANGED: SQLRETURN = SQLRETURN(103);
63
64/// The driver does not know how much additional data is to be written.
65#[cfg(feature = "v4")]
66pub const SQL_MORE_DATA: SQLRETURN = SQLRETURN(104);
67
68#[allow(non_snake_case)]
69pub fn SQL_SUCCEEDED<T: Into<SQLRETURN>>(ret: T) -> bool {
70 match ret.into() {
71 SQL_SUCCESS | SQL_SUCCESS_WITH_INFO => true,
72 _ => false,
73 }
74}