pub struct PostgresErrorCodes;
impl PostgresErrorCodes {
pub fn get_sqlstate(error_type: &PostgresErrorType) -> &'static str {
match error_type {
PostgresErrorType::Success => "00000",
PostgresErrorType::Warning => "01000",
PostgresErrorType::DynamicResultSetsReturned => "0100C",
PostgresErrorType::ImplicitZeroBitPadding => "01008",
PostgresErrorType::NullValueEliminatedInSetFunction => "01003",
PostgresErrorType::PrivilegeNotGranted => "01007",
PostgresErrorType::PrivilegeNotRevoked => "01006",
PostgresErrorType::StringDataRightTruncationWarning => "01004",
PostgresErrorType::DeprecatedFeature => "01P01",
PostgresErrorType::NoData => "02000",
PostgresErrorType::NoAdditionalDynamicResultSetsReturned => "02001",
PostgresErrorType::SqlStatementNotYetComplete => "03000",
PostgresErrorType::ConnectionException => "08000",
PostgresErrorType::ConnectionDoesNotExist => "08003",
PostgresErrorType::ConnectionFailure => "08006",
PostgresErrorType::SqlclientUnableToEstablishSqlconnection => "08001",
PostgresErrorType::SqlserverRejectedEstablishmentOfSqlconnection => "08004",
PostgresErrorType::TransactionResolutionUnknown => "08007",
PostgresErrorType::ProtocolViolation => "08P01",
PostgresErrorType::TriggeredActionException => "09000",
PostgresErrorType::FeatureNotSupported => "0A000",
PostgresErrorType::InvalidTransactionInitiation => "0B000",
PostgresErrorType::LocatorException => "0F000",
PostgresErrorType::InvalidLocatorSpecification => "0F001",
PostgresErrorType::InvalidGrantor => "0L000",
PostgresErrorType::InvalidGrantOperation => "0LP01",
PostgresErrorType::InvalidRoleSpecification => "0P000",
PostgresErrorType::DiagnosticsException => "0Z000",
PostgresErrorType::StackedDiagnosticsAccessedWithoutActiveHandler => "0Z002",
PostgresErrorType::CaseNotFound => "20000",
PostgresErrorType::CardinalityViolation => "21000",
PostgresErrorType::DataException => "22000",
PostgresErrorType::ArraySubscriptError => "2202E",
PostgresErrorType::CharacterNotInRepertoire => "22021",
PostgresErrorType::DatetimeFieldOverflow => "22008",
PostgresErrorType::DivisionByZero => "22012",
PostgresErrorType::ErrorInAssignment => "22005",
PostgresErrorType::EscapeCharacterConflict => "2200B",
PostgresErrorType::IndicatorOverflow => "22022",
PostgresErrorType::IntervalFieldOverflow => "22015",
PostgresErrorType::InvalidArgumentForLogarithm => "2201E",
PostgresErrorType::InvalidArgumentForNtileFunction => "22014",
PostgresErrorType::InvalidArgumentForNthValueFunction => "22016",
PostgresErrorType::InvalidArgumentForPowerFunction => "2201F",
PostgresErrorType::InvalidArgumentForWidthBucketFunction => "2201G",
PostgresErrorType::InvalidCharacterValueForCast => "22018",
PostgresErrorType::InvalidDatetimeFormat => "22007",
PostgresErrorType::InvalidEscapeCharacter => "22019",
PostgresErrorType::InvalidEscapeOctet => "2200D",
PostgresErrorType::InvalidEscapeSequence => "22025",
PostgresErrorType::NonstandardUseOfEscapeCharacter => "22P06",
PostgresErrorType::InvalidIndicatorParameterValue => "22010",
PostgresErrorType::InvalidParameterValue => "22023",
PostgresErrorType::InvalidRegularExpression => "2201B",
PostgresErrorType::InvalidRowCountInLimitClause => "2201W",
PostgresErrorType::InvalidRowCountInResultOffsetClause => "2201X",
PostgresErrorType::InvalidTablesampleArgument => "2202H",
PostgresErrorType::InvalidTablesampleRepeat => "2202G",
PostgresErrorType::InvalidTimeZoneDisplacementValue => "22009",
PostgresErrorType::InvalidUseOfEscapeCharacter => "2200C",
PostgresErrorType::MostSpecificTypeMismatch => "2200G",
PostgresErrorType::NullValueNotAllowed => "22004",
PostgresErrorType::NullValueNoIndicatorParameter => "22002",
PostgresErrorType::NumericValueOutOfRange => "22003",
PostgresErrorType::SequenceGeneratorLimitExceeded => "2200H",
PostgresErrorType::StringDataLengthMismatch => "22026",
PostgresErrorType::StringDataRightTruncation => "22001",
PostgresErrorType::SubstringError => "22011",
PostgresErrorType::TrimError => "22027",
PostgresErrorType::UnterminatedCString => "22024",
PostgresErrorType::ZeroLengthCharacterString => "2200F",
PostgresErrorType::FloatingPointException => "22P01",
PostgresErrorType::InvalidTextRepresentation => "22P02",
PostgresErrorType::InvalidBinaryRepresentation => "22P03",
PostgresErrorType::BadCopyFileFormat => "22P04",
PostgresErrorType::UntranslatableCharacter => "22P05",
PostgresErrorType::IntegrityConstraintViolation => "23000",
PostgresErrorType::RestrictViolation => "23001",
PostgresErrorType::NotNullViolation => "23502",
PostgresErrorType::ForeignKeyViolation => "23503",
PostgresErrorType::UniqueViolation => "23505",
PostgresErrorType::CheckViolation => "23514",
PostgresErrorType::ExclusionViolation => "23P01",
PostgresErrorType::InvalidCursorState => "24000",
PostgresErrorType::InvalidTransactionState => "25000",
PostgresErrorType::ActiveSqlTransaction => "25001",
PostgresErrorType::BranchTransactionAlreadyActive => "25002",
PostgresErrorType::HeldCursorRequiresSameIsolationLevel => "25008",
PostgresErrorType::InappropriateAccessModeForBranchTransaction => "25003",
PostgresErrorType::InappropriateIsolationLevelForBranchTransaction => "25004",
PostgresErrorType::NoActiveSqlTransactionForBranchTransaction => "25005",
PostgresErrorType::ReadOnlySqlTransaction => "25006",
PostgresErrorType::SchemaAndDataStatementMixingNotSupported => "25007",
PostgresErrorType::NoActiveSqlTransaction => "25P01",
PostgresErrorType::InFailedSqlTransaction => "25P02",
PostgresErrorType::IdleInTransactionSessionTimeout => "25P03",
PostgresErrorType::InvalidSqlStatementName => "26000",
PostgresErrorType::TriggeredDataChangeViolation => "27000",
PostgresErrorType::InvalidAuthorizationSpecification => "28000",
PostgresErrorType::InvalidPassword => "28P01",
PostgresErrorType::DependentPrivilegeDescriptorsStillExist => "2B000",
PostgresErrorType::DependentObjectsStillExist => "2BP01",
PostgresErrorType::InvalidTransactionTermination => "2D000",
PostgresErrorType::SqlRoutineException => "2F000",
PostgresErrorType::FunctionExecutedNoReturnStatement => "2F005",
PostgresErrorType::ModifyingSqlDataNotPermitted => "2F002",
PostgresErrorType::ProhibitedSqlStatementAttempted => "2F003",
PostgresErrorType::ReadingSqlDataNotPermitted => "2F004",
PostgresErrorType::InvalidCursorName => "34000",
PostgresErrorType::ExternalRoutineException => "38000",
PostgresErrorType::ContainingSqlNotPermitted => "38001",
PostgresErrorType::ModifyingSqlDataNotPermittedExternal => "38002",
PostgresErrorType::ProhibitedSqlStatementAttemptedExternal => "38003",
PostgresErrorType::ReadingSqlDataNotPermittedExternal => "38004",
PostgresErrorType::ExternalRoutineInvocationException => "39000",
PostgresErrorType::InvalidSqlstateReturned => "39001",
PostgresErrorType::NullValueNotAllowedExternal => "39004",
PostgresErrorType::TriggerProtocolViolated => "39P01",
PostgresErrorType::SrfProtocolViolated => "39P02",
PostgresErrorType::EventTriggerProtocolViolated => "39P03",
PostgresErrorType::SavepointException => "3B000",
PostgresErrorType::InvalidSavepointSpecification => "3B001",
PostgresErrorType::InvalidCatalogName => "3D000",
PostgresErrorType::InvalidSchemaName => "3F000",
PostgresErrorType::TransactionRollback => "40000",
PostgresErrorType::TransactionIntegrityConstraintViolation => "40002",
PostgresErrorType::SerializationFailure => "40001",
PostgresErrorType::StatementCompletionUnknown => "40003",
PostgresErrorType::DeadlockDetected => "40P01",
PostgresErrorType::SyntaxErrorOrAccessRuleViolation => "42000",
PostgresErrorType::SyntaxError => "42601",
PostgresErrorType::InsufficientPrivilege => "42501",
PostgresErrorType::CannotCoerce => "42846",
PostgresErrorType::GroupingError => "42803",
PostgresErrorType::WindowingError => "42P20",
PostgresErrorType::InvalidRecursion => "42P19",
PostgresErrorType::InvalidForeignKey => "42830",
PostgresErrorType::InvalidName => "42602",
PostgresErrorType::NameTooLong => "42622",
PostgresErrorType::ReservedName => "42939",
PostgresErrorType::DatatypeMismatch => "42804",
PostgresErrorType::IndeterminateDatatype => "42P18",
PostgresErrorType::CollationMismatch => "42P21",
PostgresErrorType::IndeterminateCollation => "42P22",
PostgresErrorType::WrongObjectType => "42809",
PostgresErrorType::GeneratedAlways => "428C9",
PostgresErrorType::UndefinedColumn => "42703",
PostgresErrorType::UndefinedFunction => "42883",
PostgresErrorType::UndefinedTable => "42P01",
PostgresErrorType::UndefinedParameter => "42P02",
PostgresErrorType::UndefinedObject => "42704",
PostgresErrorType::DuplicateColumn => "42701",
PostgresErrorType::DuplicateCursor => "42P03",
PostgresErrorType::DuplicateDatabase => "42P04",
PostgresErrorType::DuplicateFunction => "42723",
PostgresErrorType::DuplicatePreparedStatement => "42P05",
PostgresErrorType::DuplicateSchema => "42P06",
PostgresErrorType::DuplicateTable => "42P07",
PostgresErrorType::DuplicateAlias => "42712",
PostgresErrorType::DuplicateObject => "42710",
PostgresErrorType::AmbiguousColumn => "42702",
PostgresErrorType::AmbiguousFunction => "42725",
PostgresErrorType::AmbiguousParameter => "42P08",
PostgresErrorType::AmbiguousAlias => "42P09",
PostgresErrorType::InvalidColumnReference => "42P10",
PostgresErrorType::InvalidColumnDefinition => "42611",
PostgresErrorType::InvalidCursorDefinition => "42P11",
PostgresErrorType::InvalidDatabaseDefinition => "42P12",
PostgresErrorType::InvalidFunctionDefinition => "42P13",
PostgresErrorType::InvalidPreparedStatementDefinition => "42P14",
PostgresErrorType::InvalidSchemaDefinition => "42P15",
PostgresErrorType::InvalidTableDefinition => "42P16",
PostgresErrorType::InvalidObjectDefinition => "42P17",
PostgresErrorType::WithCheckOptionViolation => "44000",
PostgresErrorType::InsufficientResources => "53000",
PostgresErrorType::DiskFull => "53100",
PostgresErrorType::OutOfMemory => "53200",
PostgresErrorType::TooManyConnections => "53300",
PostgresErrorType::ConfigurationLimitExceeded => "53400",
PostgresErrorType::ProgramLimitExceeded => "54000",
PostgresErrorType::StatementTooComplex => "54001",
PostgresErrorType::TooManyColumns => "54011",
PostgresErrorType::TooManyArguments => "54023",
PostgresErrorType::ObjectNotInPrerequisiteState => "55000",
PostgresErrorType::ObjectInUse => "55006",
PostgresErrorType::CantChangeRuntimeParam => "55P02",
PostgresErrorType::LockNotAvailable => "55P03",
PostgresErrorType::UnsafeNewEnumValueUsage => "55P04",
PostgresErrorType::OperatorIntervention => "57000",
PostgresErrorType::QueryCanceled => "57014",
PostgresErrorType::AdminShutdown => "57P01",
PostgresErrorType::CrashShutdown => "57P02",
PostgresErrorType::CannotConnectNow => "57P03",
PostgresErrorType::DatabaseDropped => "57P04",
PostgresErrorType::SystemError => "58000",
PostgresErrorType::IoError => "58030",
PostgresErrorType::UndefinedFile => "58P01",
PostgresErrorType::DuplicateFile => "58P02",
PostgresErrorType::SnapshotTooOld => "72000",
PostgresErrorType::ConfigFileError => "F0000",
PostgresErrorType::LockFileExists => "F0001",
PostgresErrorType::FdwError => "HV000",
PostgresErrorType::FdwColumnNameNotFound => "HV005",
PostgresErrorType::FdwDynamicParameterValueNeeded => "HV002",
PostgresErrorType::FdwFunctionSequenceError => "HV010",
PostgresErrorType::FdwInconsistentDescriptorInformation => "HV021",
PostgresErrorType::FdwInvalidAttributeValue => "HV024",
PostgresErrorType::FdwInvalidColumnName => "HV007",
PostgresErrorType::FdwInvalidColumnNumber => "HV008",
PostgresErrorType::FdwInvalidDataType => "HV004",
PostgresErrorType::FdwInvalidDataTypeDescriptors => "HV006",
PostgresErrorType::FdwInvalidDescriptorFieldIdentifier => "HV091",
PostgresErrorType::FdwInvalidHandle => "HV00B",
PostgresErrorType::FdwInvalidOptionIndex => "HV00C",
PostgresErrorType::FdwInvalidOptionName => "HV00D",
PostgresErrorType::FdwInvalidStringLengthOrBufferLength => "HV090",
PostgresErrorType::FdwInvalidStringFormat => "HV00A",
PostgresErrorType::FdwInvalidUseOfNullPointer => "HV009",
PostgresErrorType::FdwTooManyHandles => "HV014",
PostgresErrorType::FdwOutOfMemory => "HV001",
PostgresErrorType::FdwNoSchemas => "HV00P",
PostgresErrorType::FdwOptionNameNotFound => "HV00J",
PostgresErrorType::FdwReplyHandle => "HV00K",
PostgresErrorType::FdwSchemaNotFound => "HV00Q",
PostgresErrorType::FdwTableNotFound => "HV00R",
PostgresErrorType::FdwUnableToCreateExecution => "HV00L",
PostgresErrorType::FdwUnableToCreateReply => "HV00M",
PostgresErrorType::FdwUnableToEstablishConnection => "HV00N",
PostgresErrorType::PlpgsqlError => "P0000",
PostgresErrorType::RaiseException => "P0001",
PostgresErrorType::NoDataFound => "P0002",
PostgresErrorType::TooManyRows => "P0003",
PostgresErrorType::AssertFailure => "P0004",
PostgresErrorType::InternalError => "XX000",
PostgresErrorType::DataCorrupted => "XX001",
PostgresErrorType::IndexCorrupted => "XX002",
}
}
pub fn get_error_message(error_type: &PostgresErrorType) -> &'static str {
match error_type {
PostgresErrorType::Success => "successful completion",
PostgresErrorType::SyntaxError => "syntax error",
PostgresErrorType::UndefinedTable => "relation does not exist",
PostgresErrorType::UndefinedColumn => "column does not exist",
PostgresErrorType::UndefinedFunction => "function does not exist",
PostgresErrorType::InsufficientPrivilege => "permission denied",
PostgresErrorType::FeatureNotSupported => "feature not supported",
PostgresErrorType::InvalidPassword => "password authentication failed",
PostgresErrorType::ConnectionFailure => "connection failure",
PostgresErrorType::ProtocolViolation => "protocol violation",
PostgresErrorType::InternalError => "internal error",
_ => "unknown error",
}
}
}
#[derive(Debug, Clone)]
pub enum PostgresErrorType {
Success,
Warning,
DynamicResultSetsReturned,
ImplicitZeroBitPadding,
NullValueEliminatedInSetFunction,
PrivilegeNotGranted,
PrivilegeNotRevoked,
StringDataRightTruncationWarning,
DeprecatedFeature,
NoData,
NoAdditionalDynamicResultSetsReturned,
SqlStatementNotYetComplete,
ConnectionException,
ConnectionDoesNotExist,
ConnectionFailure,
SqlclientUnableToEstablishSqlconnection,
SqlserverRejectedEstablishmentOfSqlconnection,
TransactionResolutionUnknown,
ProtocolViolation,
TriggeredActionException,
FeatureNotSupported,
InvalidTransactionInitiation,
LocatorException,
InvalidLocatorSpecification,
InvalidGrantor,
InvalidGrantOperation,
InvalidRoleSpecification,
DiagnosticsException,
StackedDiagnosticsAccessedWithoutActiveHandler,
CaseNotFound,
CardinalityViolation,
DataException,
ArraySubscriptError,
CharacterNotInRepertoire,
DatetimeFieldOverflow,
DivisionByZero,
ErrorInAssignment,
EscapeCharacterConflict,
IndicatorOverflow,
IntervalFieldOverflow,
InvalidArgumentForLogarithm,
InvalidArgumentForNtileFunction,
InvalidArgumentForNthValueFunction,
InvalidArgumentForPowerFunction,
InvalidArgumentForWidthBucketFunction,
InvalidCharacterValueForCast,
InvalidDatetimeFormat,
InvalidEscapeCharacter,
InvalidEscapeOctet,
InvalidEscapeSequence,
NonstandardUseOfEscapeCharacter,
InvalidIndicatorParameterValue,
InvalidParameterValue,
InvalidRegularExpression,
InvalidRowCountInLimitClause,
InvalidRowCountInResultOffsetClause,
InvalidTablesampleArgument,
InvalidTablesampleRepeat,
InvalidTimeZoneDisplacementValue,
InvalidUseOfEscapeCharacter,
MostSpecificTypeMismatch,
NullValueNotAllowed,
NullValueNoIndicatorParameter,
NumericValueOutOfRange,
SequenceGeneratorLimitExceeded,
StringDataLengthMismatch,
StringDataRightTruncation,
SubstringError,
TrimError,
UnterminatedCString,
ZeroLengthCharacterString,
FloatingPointException,
InvalidTextRepresentation,
InvalidBinaryRepresentation,
BadCopyFileFormat,
UntranslatableCharacter,
IntegrityConstraintViolation,
RestrictViolation,
NotNullViolation,
ForeignKeyViolation,
UniqueViolation,
CheckViolation,
ExclusionViolation,
InvalidCursorState,
InvalidTransactionState,
ActiveSqlTransaction,
BranchTransactionAlreadyActive,
HeldCursorRequiresSameIsolationLevel,
InappropriateAccessModeForBranchTransaction,
InappropriateIsolationLevelForBranchTransaction,
NoActiveSqlTransactionForBranchTransaction,
ReadOnlySqlTransaction,
SchemaAndDataStatementMixingNotSupported,
NoActiveSqlTransaction,
InFailedSqlTransaction,
IdleInTransactionSessionTimeout,
InvalidSqlStatementName,
TriggeredDataChangeViolation,
InvalidAuthorizationSpecification,
InvalidPassword,
DependentPrivilegeDescriptorsStillExist,
DependentObjectsStillExist,
InvalidTransactionTermination,
SqlRoutineException,
FunctionExecutedNoReturnStatement,
ModifyingSqlDataNotPermitted,
ProhibitedSqlStatementAttempted,
ReadingSqlDataNotPermitted,
InvalidCursorName,
ExternalRoutineException,
ContainingSqlNotPermitted,
ModifyingSqlDataNotPermittedExternal,
ProhibitedSqlStatementAttemptedExternal,
ReadingSqlDataNotPermittedExternal,
ExternalRoutineInvocationException,
InvalidSqlstateReturned,
NullValueNotAllowedExternal,
TriggerProtocolViolated,
SrfProtocolViolated,
EventTriggerProtocolViolated,
SavepointException,
InvalidSavepointSpecification,
InvalidCatalogName,
InvalidSchemaName,
TransactionRollback,
TransactionIntegrityConstraintViolation,
SerializationFailure,
StatementCompletionUnknown,
DeadlockDetected,
SyntaxErrorOrAccessRuleViolation,
SyntaxError,
InsufficientPrivilege,
CannotCoerce,
GroupingError,
WindowingError,
InvalidRecursion,
InvalidForeignKey,
InvalidName,
NameTooLong,
ReservedName,
DatatypeMismatch,
IndeterminateDatatype,
CollationMismatch,
IndeterminateCollation,
WrongObjectType,
GeneratedAlways,
UndefinedColumn,
UndefinedFunction,
UndefinedTable,
UndefinedParameter,
UndefinedObject,
DuplicateColumn,
DuplicateCursor,
DuplicateDatabase,
DuplicateFunction,
DuplicatePreparedStatement,
DuplicateSchema,
DuplicateTable,
DuplicateAlias,
DuplicateObject,
AmbiguousColumn,
AmbiguousFunction,
AmbiguousParameter,
AmbiguousAlias,
InvalidColumnReference,
InvalidColumnDefinition,
InvalidCursorDefinition,
InvalidDatabaseDefinition,
InvalidFunctionDefinition,
InvalidPreparedStatementDefinition,
InvalidSchemaDefinition,
InvalidTableDefinition,
InvalidObjectDefinition,
WithCheckOptionViolation,
InsufficientResources,
DiskFull,
OutOfMemory,
TooManyConnections,
ConfigurationLimitExceeded,
ProgramLimitExceeded,
StatementTooComplex,
TooManyColumns,
TooManyArguments,
ObjectNotInPrerequisiteState,
ObjectInUse,
CantChangeRuntimeParam,
LockNotAvailable,
UnsafeNewEnumValueUsage,
OperatorIntervention,
QueryCanceled,
AdminShutdown,
CrashShutdown,
CannotConnectNow,
DatabaseDropped,
SystemError,
IoError,
UndefinedFile,
DuplicateFile,
SnapshotTooOld,
ConfigFileError,
LockFileExists,
FdwError,
FdwColumnNameNotFound,
FdwDynamicParameterValueNeeded,
FdwFunctionSequenceError,
FdwInconsistentDescriptorInformation,
FdwInvalidAttributeValue,
FdwInvalidColumnName,
FdwInvalidColumnNumber,
FdwInvalidDataType,
FdwInvalidDataTypeDescriptors,
FdwInvalidDescriptorFieldIdentifier,
FdwInvalidHandle,
FdwInvalidOptionIndex,
FdwInvalidOptionName,
FdwInvalidStringLengthOrBufferLength,
FdwInvalidStringFormat,
FdwInvalidUseOfNullPointer,
FdwTooManyHandles,
FdwOutOfMemory,
FdwNoSchemas,
FdwOptionNameNotFound,
FdwReplyHandle,
FdwSchemaNotFound,
FdwTableNotFound,
FdwUnableToCreateExecution,
FdwUnableToCreateReply,
FdwUnableToEstablishConnection,
PlpgsqlError,
RaiseException,
NoDataFound,
TooManyRows,
AssertFailure,
InternalError,
DataCorrupted,
IndexCorrupted,
}