1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// PORT NOTE: Zig source is a *non-exhaustive* `enum(u8)` (trailing `_`), meaning
// any `u8` value is a valid `FieldType` and unknown bytes from the wire must
// round-trip. A `#[repr(u8)] enum` in Rust is exhaustive — transmuting an
// unlisted byte into it is UB. So this is ported as a transparent `u8` newtype
// with associated consts for the known field codes.
#[repr(transparent)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct FieldType(pub u8);
impl FieldType {
/// Severity: the field contents are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a localized translation of one of these. Always present.
pub const SEVERITY: Self = Self(b'S');
/// Severity: the field contents are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message). This is identical to the S field except that the contents are never localized. This is present only in messages generated by PostgreSQL versions 9.6 and later.
pub const LOCALIZED_SEVERITY: Self = Self(b'V');
/// Code: the SQLSTATE code for the error (see Appendix A). Not localizable. Always present.
pub const CODE: Self = Self(b'C');
/// Message: the primary human-readable error message. This should be accurate but terse (typically one line). Always present.
pub const MESSAGE: Self = Self(b'M');
/// Detail: an optional secondary error message carrying more detail about the problem. Might run to multiple lines.
pub const DETAIL: Self = Self(b'D');
/// Hint: an optional suggestion what to do about the problem. This is intended to differ from Detail in that it offers advice (potentially inappropriate) rather than hard facts. Might run to multiple lines.
pub const HINT: Self = Self(b'H');
/// Position: the field value is a decimal ASCII integer, indicating an error cursor position as an index into the original query string. The first character has index 1, and positions are measured in characters not bytes.
pub const POSITION: Self = Self(b'P');
/// Internal position: this is defined the same as the P field, but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client. The q field will always appear when this field appears.
pub const INTERNAL_POSITION: Self = Self(b'p');
/// Internal query: the text of a failed internally-generated command. This could be, for example, an SQL query issued by a PL/pgSQL function.
pub const INTERNAL: Self = Self(b'q');
/// Where: an indication of the context in which the error occurred. Presently this includes a call stack traceback of active procedural language functions and internally-generated queries. The trace is one entry per line, most recent first.
pub const WHERE: Self = Self(b'W');
/// Schema name: if the error was associated with a specific database object, the name of the schema containing that object, if any.
pub const SCHEMA: Self = Self(b's');
/// Table name: if the error was associated with a specific table, the name of the table. (Refer to the schema name field for the name of the table's schema.)
pub const TABLE: Self = Self(b't');
/// Column name: if the error was associated with a specific table column, the name of the column. (Refer to the schema and table name fields to identify the table.)
pub const COLUMN: Self = Self(b'c');
/// Data type name: if the error was associated with a specific data type, the name of the data type. (Refer to the schema name field for the name of the data type's schema.)
pub const DATATYPE: Self = Self(b'd');
/// Constraint name: if the error was associated with a specific constraint, the name of the constraint. Refer to fields listed above for the associated table or domain. (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.)
pub const CONSTRAINT: Self = Self(b'n');
/// File: the file name of the source-code location where the error was reported.
pub const FILE: Self = Self(b'F');
/// Line: the line number of the source-code location where the error was reported.
pub const LINE: Self = Self(b'L');
/// Routine: the name of the source-code routine reporting the error.
pub const ROUTINE: Self = Self(b'R');
}
impl From<u8> for FieldType {
#[inline]
fn from(n: u8) -> Self {
Self(n)
}
}
impl From<FieldType> for u8 {
#[inline]
fn from(t: FieldType) -> Self {
t.0
}
}
// ported from: src/sql/postgres/protocol/FieldType.zig