sqlstate 0.1.0

Representations and parsing logic for SQLSTATE return codes.
Documentation
  • Coverage
  • 1.34%
    9 out of 672 items documented1 out of 173 items with examples
  • Size
  • Source code size: 51.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 33.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • 0xSiO/sqlstate-rs
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 0xSiO

Representations and parsing logic for SQLSTATE return codes.

Examples

Parsing return codes according to the SQL standard:

use sqlstate::standard::{
    class::{DataException::DivisionByZero, Warning::PrivilegeNotGranted},
    SqlState,
};

assert_eq!("00000".parse::<SqlState>()?, SqlState::Success(None));
assert_eq!("01007".parse::<SqlState>()?, SqlState::Warning(Some(PrivilegeNotGranted)));

// Unknown codes are represented as `Other`
assert_eq!("XX001".parse::<SqlState>()?, SqlState::Other(String::from("XX001")));

Examining the pieces of a return code:

use sqlstate::standard::{class::Warning::PrivilegeNotGranted, SqlState};

let success = SqlState::Success(None);
let warning = SqlState::Warning(Some(PrivilegeNotGranted));
assert_eq!((success.class(), success.subclass()), ("00", None));
assert_eq!((warning.class(), warning.subclass()), ("01", Some("007")));

Parsing return codes specific to PostgreSQL:

use sqlstate::{
    postgres::{
        class::{
            DataException::InvalidJsonText, InternalError::DataCorrupted,
            OperatorIntervention::CrashShutdown,
        },
        SqlState::*,
    },
    standard,
    PostgresSqlState,
};

assert_eq!("22032".parse::<PostgresSqlState>()?,
           PostgresSqlState::Custom(DataException(Some(InvalidJsonText))));
assert_eq!("XX001".parse::<PostgresSqlState>()?,
           PostgresSqlState::Custom(InternalError(Some(DataCorrupted))));

// Can also fall back to standard codes
assert_eq!("00000".parse::<PostgresSqlState>()?,
           PostgresSqlState::Standard(standard::SqlState::Success(None)));

Features

  • postgres: Enables PostgreSQL-specific types.