Maps a parse/cast [`ParseError`] to the appropriate `DATA_EXCEPTION` (class 22) SQLSTATE. Out-of-range values map to overflow codes and malformed input maps to invalid-representation codes, in both cases distinguishing datetime types from everything else, matching PostgreSQL.
(err: &ParseError)
| 312 | /// maps to invalid-representation codes, in both cases distinguishing datetime |
| 313 | /// types from everything else, matching PostgreSQL. |
| 314 | fn parse_error_code(err: &ParseError) -> SqlState { |
| 315 | let is_datetime = matches!( |
| 316 | &*err.type_name, |
| 317 | "date" | "time" | "timestamp" | "timestamp with time zone" | "interval" |
| 318 | ); |
| 319 | match (err.kind, is_datetime) { |
| 320 | (ParseErrorKind::OutOfRange, true) => SqlState::DATETIME_FIELD_OVERFLOW, |
| 321 | (ParseErrorKind::OutOfRange, false) => SqlState::NUMERIC_VALUE_OUT_OF_RANGE, |
| 322 | (ParseErrorKind::InvalidInputSyntax, true) => SqlState::INVALID_DATETIME_FORMAT, |
| 323 | (ParseErrorKind::InvalidInputSyntax, false) => SqlState::INVALID_TEXT_REPRESENTATION, |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /// Maps an [`EvalError`] to the appropriate SQLSTATE. |
| 328 | /// |