Skip to main content

Module sqlstate

Module sqlstate 

Source
Expand description

SQLSTATE error codes — Post-MVP credibility item.

Mirrors PostgreSQL’s errcodes.h 5-character SQLSTATE codes so reddb errors carry the same standardized identifiers drivers / client libs / monitoring tools already understand. A SQLSTATE is a fixed 5-character ASCII string where the first 2 characters identify a class and the next 3 identify a specific condition within that class.

Examples:

  • 08006 connection_failure
  • 22012 division_by_zero
  • 23505 unique_violation
  • 42601 syntax_error
  • 42P01 undefined_table
  • XX000 internal_error

§Why this matters

ODBC / JDBC / psycopg / pgx all switch on SQLSTATE for retry logic, error categorization, and i18n. A reddb client that sees 42P01 knows the table doesn’t exist regardless of the human-readable message language. Without SQLSTATE, drivers have to string-match error text — fragile across versions.

§Mapping to RedDBError

RedDBError -> SqlState is a one-line lookup. The reverse direction (parse a 5-char code into a category) is also available via SqlState::class() for filter UIs.

§Wiring

Phase post-MVP wiring adds a sqlstate() method on RedDBError and threads the code through the wire protocol ErrorResponse frame so HTTP / gRPC / stdio clients all receive it.

Structs§

SqlState
5-character SQLSTATE code wrapper. Stored as a fixed [u8; 5] so it’s Copy, fits in a register, and can be compared with a single ==.

Constants§

ACTIVE_SQL_TRANSACTION
AMBIGUOUS_COLUMN
CHECK_VIOLATION
CONNECTION_DOES_NOT_EXIST
CONNECTION_EXCEPTION
CONNECTION_FAILURE
DATATYPE_MISMATCH
DATA_CORRUPTED
DATA_EXCEPTION
DEADLOCK_DETECTED
DISK_FULL
DIVISION_BY_ZERO
DUPLICATE_COLUMN
DUPLICATE_TABLE
FOREIGN_KEY_VIOLATION
INSUFFICIENT_RESOURCES
INTEGRITY_CONSTRAINT_VIOLATION
INTERNAL_ERROR
INVALID_DATETIME_FORMAT
INVALID_PASSWORD
INVALID_TEXT_REPRESENTATION
INVALID_TRANSACTION_STATE
IO_ERROR
NOT_NULL_VIOLATION
NO_ACTIVE_SQL_TRANSACTION
NULL_VALUE_NOT_ALLOWED_DATA
NUMERIC_VALUE_OUT_OF_RANGE
OPERATOR_INTERVENTION
OUT_OF_MEMORY
QUERY_CANCELED
READ_ONLY_SQL_TRANSACTION
SERIALIZATION_FAILURE
SQLSERVER_REJECTED_ESTABLISHMENT
STRING_DATA_RIGHT_TRUNCATION
SUCCESSFUL_COMPLETION
SYNTAX_ERROR
SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION
SYSTEM_ERROR
TOO_MANY_CONNECTIONS
TRANSACTION_ROLLBACK
UNDEFINED_COLUMN
UNDEFINED_FUNCTION
UNDEFINED_PARAMETER
UNDEFINED_TABLE
UNIQUE_VIOLATION
WRONG_OBJECT_TYPE

Functions§

sqlstate_for_reddb_error
Map a RedDBError variant to its SQLSTATE code. Used by the wire protocol’s error response frame so clients get the standardized identifier alongside the human message.