From 396c7ddce6ab881fe738fcaf1e84117d93aaa6cf Mon Sep 17 00:00:00 2001 From: b0r1ssh <295612221+b0r1ssh@users.noreply.github.com> Date: Sat, 22 Aug 2026 16:19:32 +0200 Subject: [PATCH] First release --- .github/workflows/go-test.yml | 38 + .github/workflows/publish-on-main.yml | 71 ++ .gitignore | 2 + LICENSE | 21 + code.go | 1331 +++++++++++++++++++++++++ code_test.go | 832 ++++++++++++++++ go.mod | 3 + 7 files changed, 2298 insertions(+) create mode 100644 .github/workflows/go-test.yml create mode 100644 .github/workflows/publish-on-main.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 code.go create mode 100644 code_test.go create mode 100644 go.mod diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000..1ee2cdd --- /dev/null +++ b/.github/workflows/go-test.yml @@ -0,0 +1,38 @@ +name: Go CI + +on: + push: + branches: + - '**' + pull_request: + +permissions: + contents: read + +jobs: + test: + name: Go ${{ matrix.go-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: ['1.22', '1.23', '1.24', '1.25', '1.26', '1.27'] + + steps: + - name: Check out code + uses: actions/checkout@v7 + + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version: ${{ matrix.go-version }} + cache: true + + - name: Show Go version + run: go version + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: go test ./... diff --git a/.github/workflows/publish-on-main.yml b/.github/workflows/publish-on-main.yml new file mode 100644 index 0000000..3bdd73d --- /dev/null +++ b/.github/workflows/publish-on-main.yml @@ -0,0 +1,71 @@ +name: Publish Go module + +on: + pull_request: + types: [closed] + branches: + - main + workflow_dispatch: + +permissions: + contents: write + +jobs: + publish: + if: > + github.event_name == 'workflow_dispatch' || + (github.event_name == 'pull_request' && + github.event.pull_request.merged == true) + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version: '1.27' + cache: true + + - name: Run tests + run: go test ./... + + - name: Determine next version + id: version + shell: bash + run: | + set -euo pipefail + git fetch --tags --force + + latest=$(git tag --sort=-v:refname | head -n 1 || true) + + if [ -z "$latest" ]; then + next="v0.0.1" + else + version="${latest#v}" + IFS='.' read -r major minor patch <<< "$version" + patch=$((patch + 1)) + next="v${major}.${minor}.${patch}" + fi + + echo "next_version=$next" >> "$GITHUB_OUTPUT" + + - name: Create Git tag and GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NEXT_VERSION: ${{ steps.version.outputs.next_version }} + shell: bash + run: | + set -euo pipefail + + if git rev-parse "$NEXT_VERSION" >/dev/null 2>&1; then + echo "Tag $NEXT_VERSION already exists. Skipping release." + exit 0 + fi + + git tag "$NEXT_VERSION" + git push origin "$NEXT_VERSION" + gh release create "$NEXT_VERSION" --generate-notes --verify-tag diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00741cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +.idea/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..77ba414 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 b0r1ssh + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/code.go b/code.go new file mode 100644 index 0000000..883b7da --- /dev/null +++ b/code.go @@ -0,0 +1,1331 @@ +package pgcode + +// Constants for every PostgreSQL SQLSTATE code. +// When multiple codes share a condition name, the primary code keeps the clean name +// and aliases are suffixed with their class: e.g. ModifyingSQLDataNotPermittedClass38. +const ( + // Class 00 — Successful Completion + SuccessfulCompletion = "00000" + + // Class 01 — Warning + Warning = "01000" + NullValueEliminatedInSetFunction = "01003" + StringDataRightTruncation = "01004" + PrivilegeNotRevoked = "01006" + PrivilegeNotGranted = "01007" + ImplicitZeroBitPadding = "01008" + DynamicResultSetsReturned = "0100C" + DeprecatedFeature = "01P01" + + // Class 02 — No Data (this is also a warning class per the SQL standard) + NoData = "02000" + NoAdditionalDynamicResultSetsReturned = "02001" + + // Class 03 — SQL Statement Not Yet Complete + SQLStatementNotYetComplete = "03000" + + // Class 08 — Connection Exception + ConnectionException = "08000" + SqlclientUnableToEstablishSqlconnection = "08001" + ConnectionDoesNotExist = "08003" + SqlserverRejectedEstablishmentOfSqlconnection = "08004" + ConnectionFailure = "08006" + TransactionResolutionUnknown = "08007" + ProtocolViolation = "08P01" + + // Class 09 — Triggered Action Exception + TriggeredActionException = "09000" + + // Class 0A — Feature Not Supported + FeatureNotSupported = "0A000" + + // Class 0B — Invalid Transaction Initiation + InvalidTransactionInitiation = "0B000" + + // Class 0F — Locator Exception + LocatorException = "0F000" + InvalidLocatorSpecification = "0F001" + + // Class 0L — Invalid Grantor + InvalidGrantor = "0L000" + InvalidGrantOperation = "0LP01" + + // Class 0P — Invalid Role Specification + InvalidRoleSpecification = "0P000" + + // Class 0Z — Diagnostics Exception + DiagnosticsException = "0Z000" + StackedDiagnosticsAccessedWithoutActiveHandler = "0Z002" + + // Class 20 — Case Not Found + CaseNotFound = "20000" + + // Class 21 — Cardinality Violation + CardinalityViolation = "21000" + + // Class 22 — Data Exception + DataException = "22000" + StringDataRightTruncationClass22 = "22001" + NullValueNoIndicatorParameter = "22002" + NumericValueOutOfRange = "22003" + NullValueNotAllowed = "22004" + ErrorInAssignment = "22005" + InvalidDatetimeFormat = "22007" + DatetimeFieldOverflow = "22008" + InvalidTimeZoneDisplacementValue = "22009" + EscapeCharacterConflict = "2200B" + InvalidUseOfEscapeCharacter = "2200C" + InvalidEscapeOctet = "2200D" + ZeroLengthCharacterString = "2200F" + MostSpecificTypeMismatch = "2200G" + SequenceGeneratorLimitExceeded = "2200H" + NotAnXMLDocument = "2200L" + InvalidXMLDocument = "2200M" + InvalidXMLContent = "2200N" + InvalidXMLComment = "2200S" + InvalidXMLProcessingInstruction = "2200T" + InvalidIndicatorParameterValue = "22010" + SubstringError = "22011" + DivisionByZero = "22012" + InvalidPrecedingOrFollowingSize = "22013" + InvalidArgumentForNtileFunction = "22014" + IntervalFieldOverflow = "22015" + InvalidArgumentForNthValueFunction = "22016" + InvalidCharacterValueForCast = "22018" + InvalidEscapeCharacter = "22019" + InvalidRegularExpression = "2201B" + InvalidArgumentForLogarithm = "2201E" + InvalidArgumentForPowerFunction = "2201F" + InvalidArgumentForWidthBucketFunction = "2201G" + InvalidRowCountInLimitClause = "2201W" + InvalidRowCountInResultOffsetClause = "2201X" + CharacterNotInRepertoire = "22021" + IndicatorOverflow = "22022" + InvalidParameterValue = "22023" + UnterminatedCString = "22024" + InvalidEscapeSequence = "22025" + StringDataLengthMismatch = "22026" + TrimError = "22027" + ArraySubscriptError = "2202E" + InvalidTablesampleRepeat = "2202G" + InvalidTablesampleArgument = "2202H" + DuplicateJSONObjectKeyValue = "22030" + InvalidArgumentForSQLJSONDatetimeFunction = "22031" + InvalidJSONText = "22032" + InvalidSQLJSONSubscript = "22033" + MoreThanOneSQLJSONItem = "22034" + NoSQLJSONItem = "22035" + NonNumericSQLJSONItem = "22036" + NonUniqueKeysInAJSONObject = "22037" + SingletonSQLJSONItemRequired = "22038" + SQLJSONArrayNotFound = "22039" + SQLJSONMemberNotFound = "2203A" + SQLJSONNumberNotFound = "2203B" + SQLJSONObjectNotFound = "2203C" + TooManyJSONArrayElements = "2203D" + TooManyJSONObjectMembers = "2203E" + SQLJSONScalarRequired = "2203F" + SQLJSONItemCannotBeCastToTargetType = "2203G" // since PG15 + FloatingPointException = "22P01" + InvalidTextRepresentation = "22P02" + InvalidBinaryRepresentation = "22P03" + BadCopyFileFormat = "22P04" + UntranslatableCharacter = "22P05" + NonstandardUseOfEscapeCharacter = "22P06" + + // Class 23 — Integrity Constraint Violation + IntegrityConstraintViolation = "23000" + RestrictViolation = "23001" + NotNullViolation = "23502" + ForeignKeyViolation = "23503" + UniqueViolation = "23505" + CheckViolation = "23514" + ExclusionViolation = "23P01" + + // Class 24 — Invalid Cursor State + InvalidCursorState = "24000" + + // Class 25 — Invalid Transaction State + InvalidTransactionState = "25000" + ActiveSQLTransaction = "25001" + BranchTransactionAlreadyActive = "25002" + InappropriateAccessModeForBranchTransaction = "25003" + InappropriateIsolationLevelForBranchTransaction = "25004" + NoActiveSQLTransactionForBranchTransaction = "25005" + ReadOnlySQLTransaction = "25006" + SchemaAndDataStatementMixingNotSupported = "25007" + HeldCursorRequiresSameIsolationLevel = "25008" + NoActiveSQLTransaction = "25P01" + InFailedSQLTransaction = "25P02" + IdleInTransactionSessionTimeout = "25P03" + TransactionTimeout = "25P04" // since PG17 + + // Class 26 — Invalid SQL Statement Name + InvalidSQLStatementName = "26000" + + // Class 27 — Triggered Data Change Violation + TriggeredDataChangeViolation = "27000" + + // Class 28 — Invalid Authorization Specification + InvalidAuthorizationSpecification = "28000" + InvalidPassword = "28P01" + + // Class 2B — Dependent Privilege Descriptors Still Exist + DependentPrivilegeDescriptorsStillExist = "2B000" + DependentObjectsStillExist = "2BP01" + + // Class 2D — Invalid Transaction Termination + InvalidTransactionTermination = "2D000" + + // Class 2F — SQL Routine Exception + SQLRoutineException = "2F000" + ModifyingSQLDataNotPermitted = "2F002" + ProhibitedSQLStatementAttempted = "2F003" + ReadingSQLDataNotPermitted = "2F004" + FunctionExecutedNoReturnStatement = "2F005" + + // Class 34 — Invalid Cursor Name + InvalidCursorName = "34000" + + // Class 38 — External Routine Exception + ExternalRoutineException = "38000" + ContainingSQLNotPermitted = "38001" + ModifyingSQLDataNotPermittedClass38 = "38002" + ProhibitedSQLStatementAttemptedClass38 = "38003" + ReadingSQLDataNotPermittedClass38 = "38004" + + // Class 39 — External Routine Invocation Exception + ExternalRoutineInvocationException = "39000" + InvalidSQLStateReturned = "39001" + NullValueNotAllowedClass39 = "39004" + TriggerProtocolViolated = "39P01" + SRFProtocolViolated = "39P02" + EventTriggerProtocolViolated = "39P03" + + // Class 3B — Savepoint Exception + SavepointException = "3B000" + InvalidSavepointSpecification = "3B001" + + // Class 3D — Invalid Catalog Name + InvalidCatalogName = "3D000" + + // Class 3F — Invalid Schema Name + InvalidSchemaName = "3F000" + + // Class 40 — Transaction Rollback + TransactionRollback = "40000" + SerializationFailure = "40001" + TransactionIntegrityConstraintViolation = "40002" + StatementCompletionUnknown = "40003" + DeadlockDetected = "40P01" + + // Class 42 — Syntax Error or Access Rule Violation + SyntaxErrorOrAccessRuleViolation = "42000" + InsufficientPrivilege = "42501" + SyntaxError = "42601" + InvalidName = "42602" + InvalidColumnDefinition = "42611" + NameTooLong = "42622" + DuplicateColumn = "42701" + AmbiguousColumn = "42702" + UndefinedColumn = "42703" + UndefinedObject = "42704" + DuplicateObject = "42710" + DuplicateAlias = "42712" + DuplicateFunction = "42723" + AmbiguousFunction = "42725" + GroupingError = "42803" + DatatypeMismatch = "42804" + WrongObjectType = "42809" + InvalidForeignKey = "42830" + CannotCoerce = "42846" + UndefinedFunction = "42883" + GeneratedAlways = "428C9" + ReservedName = "42939" + UndefinedTable = "42P01" + UndefinedParameter = "42P02" + DuplicateCursor = "42P03" + DuplicateDatabase = "42P04" + DuplicatePreparedStatement = "42P05" + DuplicateSchema = "42P06" + DuplicateTable = "42P07" + AmbiguousParameter = "42P08" + AmbiguousAlias = "42P09" + InvalidColumnReference = "42P10" + InvalidCursorDefinition = "42P11" + InvalidDatabaseDefinition = "42P12" + InvalidFunctionDefinition = "42P13" + InvalidPreparedStatementDefinition = "42P14" + InvalidSchemaDefinition = "42P15" + InvalidTableDefinition = "42P16" + InvalidObjectDefinition = "42P17" + IndeterminateDatatype = "42P18" + InvalidRecursion = "42P19" + WindowingError = "42P20" + CollationMismatch = "42P21" + IndeterminateCollation = "42P22" + + // Class 44 — WITH CHECK OPTION Violation + WithCheckOptionViolation = "44000" + + // Class 53 — Insufficient Resources + InsufficientResources = "53000" + DiskFull = "53100" + OutOfMemory = "53200" + TooManyConnections = "53300" + ConfigurationLimitExceeded = "53400" + + // Class 54 — Program Limit Exceeded + ProgramLimitExceeded = "54000" + StatementTooComplex = "54001" + TooManyColumns = "54011" + TooManyArguments = "54023" + + // Class 55 — Object Not In Prerequisite State + ObjectNotInPrerequisiteState = "55000" + ObjectInUse = "55006" + CantChangeRuntimeParam = "55P02" + LockNotAvailable = "55P03" + UnsafeNewEnumValueUsage = "55P04" + + // Class 57 — Operator Intervention + OperatorIntervention = "57000" + QueryCanceled = "57014" + AdminShutdown = "57P01" + CrashShutdown = "57P02" + CannotConnectNow = "57P03" + DatabaseDropped = "57P04" + IdleSessionTimeout = "57P05" + + // Class 58 — System Error (errors external to PostgreSQL itself) + SystemError = "58000" + IOError = "58030" + UndefinedFile = "58P01" + DuplicateFile = "58P02" + FileNameTooLong = "58P03" // since PG18 + + // Class 72 — Snapshot Failure + SnapshotTooOld = "72000" + + // Class F0 — Configuration File Error + ConfigFileError = "F0000" + LockFileExists = "F0001" + + // Class HV — Foreign Data Wrapper Error (SQL/MED) + FDWError = "HV000" + FDWOutOfMemory = "HV001" + FDWDynamicParameterValueNeeded = "HV002" + FDWInvalidDataType = "HV004" + FDWColumnNameNotFound = "HV005" + FDWInvalidDataTypeDescriptors = "HV006" + FDWInvalidColumnName = "HV007" + FDWInvalidColumnNumber = "HV008" + FDWInvalidUseOfNullPointer = "HV009" + FDWInvalidStringFormat = "HV00A" + FDWInvalidHandle = "HV00B" + FDWInvalidOptionIndex = "HV00C" + FDWInvalidOptionName = "HV00D" + FDWOptionNameNotFound = "HV00J" + FDWReplyHandle = "HV00K" + FDWUnableToCreateExecution = "HV00L" + FDWUnableToCreateReply = "HV00M" + FDWUnableToEstablishConnection = "HV00N" + FDWNoSchemas = "HV00P" + FDWSchemaNotFound = "HV00Q" + FDWTableNotFound = "HV00R" + FDWFunctionSequenceError = "HV010" + FDWTooManyHandles = "HV014" + FDWInconsistentDescriptorInformation = "HV021" + FDWInvalidAttributeValue = "HV024" + FDWInvalidStringLengthOrBufferLength = "HV090" + FDWInvalidDescriptorFieldIdentifier = "HV091" + + // Class P0 — PL/pgSQL Error + PLpgSQLError = "P0000" + RaiseException = "P0001" + NoDataFound = "P0002" + TooManyRows = "P0003" + AssertFailure = "P0004" + + // Class XX — Internal Error + InternalError = "XX000" + DataCorrupted = "XX001" + IndexCorrupted = "XX002" + + // Class 10 — XQuery Error + InvalidArgumentForXquery = "10608" // since PG18 +) + +// IsSuccessfulCompletion returns true if code belongs to +// Class 00 — Successful Completion. +func IsSuccessfulCompletion(code string) bool { + switch code { + case SuccessfulCompletion: + return true + } + return false +} + +// IsWarning returns true if code belongs to +// Class 01 — Warning. +func IsWarning(code string) bool { + switch code { + case Warning, NullValueEliminatedInSetFunction, StringDataRightTruncation, PrivilegeNotRevoked, PrivilegeNotGranted, ImplicitZeroBitPadding, DynamicResultSetsReturned, DeprecatedFeature: + return true + } + return false +} + +// IsNoData returns true if code belongs to +// Class 02 — No Data (this is also a warning class per the SQL standard). +func IsNoData(code string) bool { + switch code { + case NoData, NoAdditionalDynamicResultSetsReturned: + return true + } + return false +} + +// IsSqlStatementNotYetComplete returns true if code belongs to +// Class 03 — SQL Statement Not Yet Complete. +func IsSqlStatementNotYetComplete(code string) bool { + switch code { + case SQLStatementNotYetComplete: + return true + } + return false +} + +// IsConnectionException returns true if code belongs to +// Class 08 — Connection Exception. +func IsConnectionException(code string) bool { + switch code { + case ConnectionException, SqlclientUnableToEstablishSqlconnection, ConnectionDoesNotExist, SqlserverRejectedEstablishmentOfSqlconnection, ConnectionFailure, TransactionResolutionUnknown, ProtocolViolation: + return true + } + return false +} + +// IsTriggeredActionException returns true if code belongs to +// Class 09 — Triggered Action Exception. +func IsTriggeredActionException(code string) bool { + switch code { + case TriggeredActionException: + return true + } + return false +} + +// IsFeatureNotSupported returns true if code belongs to +// Class 0A — Feature Not Supported. +func IsFeatureNotSupported(code string) bool { + switch code { + case FeatureNotSupported: + return true + } + return false +} + +// IsInvalidTransactionInitiation returns true if code belongs to +// Class 0B — Invalid Transaction Initiation. +func IsInvalidTransactionInitiation(code string) bool { + switch code { + case InvalidTransactionInitiation: + return true + } + return false +} + +// IsLocatorException returns true if code belongs to +// Class 0F — Locator Exception. +func IsLocatorException(code string) bool { + switch code { + case LocatorException, InvalidLocatorSpecification: + return true + } + return false +} + +// IsInvalidGrantor returns true if code belongs to +// Class 0L — Invalid Grantor. +func IsInvalidGrantor(code string) bool { + switch code { + case InvalidGrantor, InvalidGrantOperation: + return true + } + return false +} + +// IsInvalidRoleSpecification returns true if code belongs to +// Class 0P — Invalid Role Specification. +func IsInvalidRoleSpecification(code string) bool { + switch code { + case InvalidRoleSpecification: + return true + } + return false +} + +// IsDiagnosticsException returns true if code belongs to +// Class 0Z — Diagnostics Exception. +func IsDiagnosticsException(code string) bool { + switch code { + case DiagnosticsException, StackedDiagnosticsAccessedWithoutActiveHandler: + return true + } + return false +} + +// IsCaseNotFound returns true if code belongs to +// Class 20 — Case Not Found. +func IsCaseNotFound(code string) bool { + switch code { + case CaseNotFound: + return true + } + return false +} + +// IsCardinalityViolation returns true if code belongs to +// Class 21 — Cardinality Violation. +func IsCardinalityViolation(code string) bool { + switch code { + case CardinalityViolation: + return true + } + return false +} + +// IsDataException returns true if code belongs to +// Class 22 — Data Exception. +func IsDataException(code string) bool { + switch code { + case DataException, StringDataRightTruncationClass22, NullValueNoIndicatorParameter, NumericValueOutOfRange, NullValueNotAllowed, ErrorInAssignment, InvalidDatetimeFormat, DatetimeFieldOverflow, InvalidTimeZoneDisplacementValue, EscapeCharacterConflict, InvalidUseOfEscapeCharacter, InvalidEscapeOctet, ZeroLengthCharacterString, MostSpecificTypeMismatch, SequenceGeneratorLimitExceeded, NotAnXMLDocument, InvalidXMLDocument, InvalidXMLContent, InvalidXMLComment, InvalidXMLProcessingInstruction, InvalidIndicatorParameterValue, SubstringError, DivisionByZero, InvalidPrecedingOrFollowingSize, InvalidArgumentForNtileFunction, IntervalFieldOverflow, InvalidArgumentForNthValueFunction, InvalidCharacterValueForCast, InvalidEscapeCharacter, InvalidRegularExpression, InvalidArgumentForLogarithm, InvalidArgumentForPowerFunction, InvalidArgumentForWidthBucketFunction, InvalidRowCountInLimitClause, InvalidRowCountInResultOffsetClause, CharacterNotInRepertoire, IndicatorOverflow, InvalidParameterValue, UnterminatedCString, InvalidEscapeSequence, StringDataLengthMismatch, TrimError, ArraySubscriptError, InvalidTablesampleRepeat, InvalidTablesampleArgument, DuplicateJSONObjectKeyValue, InvalidArgumentForSQLJSONDatetimeFunction, InvalidJSONText, InvalidSQLJSONSubscript, MoreThanOneSQLJSONItem, NoSQLJSONItem, NonNumericSQLJSONItem, NonUniqueKeysInAJSONObject, SingletonSQLJSONItemRequired, SQLJSONArrayNotFound, SQLJSONMemberNotFound, SQLJSONNumberNotFound, SQLJSONObjectNotFound, TooManyJSONArrayElements, TooManyJSONObjectMembers, SQLJSONScalarRequired, SQLJSONItemCannotBeCastToTargetType, FloatingPointException, InvalidTextRepresentation, InvalidBinaryRepresentation, BadCopyFileFormat, UntranslatableCharacter, NonstandardUseOfEscapeCharacter: + return true + } + return false +} + +// IsIntegrityConstraintViolation returns true if code belongs to +// Class 23 — Integrity Constraint Violation. +func IsIntegrityConstraintViolation(code string) bool { + switch code { + case IntegrityConstraintViolation, RestrictViolation, NotNullViolation, ForeignKeyViolation, UniqueViolation, CheckViolation, ExclusionViolation: + return true + } + return false +} + +// IsInvalidCursorState returns true if code belongs to +// Class 24 — Invalid Cursor State. +func IsInvalidCursorState(code string) bool { + switch code { + case InvalidCursorState: + return true + } + return false +} + +// IsInvalidTransactionState returns true if code belongs to +// Class 25 — Invalid Transaction State. +func IsInvalidTransactionState(code string) bool { + switch code { + case InvalidTransactionState, ActiveSQLTransaction, BranchTransactionAlreadyActive, InappropriateAccessModeForBranchTransaction, InappropriateIsolationLevelForBranchTransaction, NoActiveSQLTransactionForBranchTransaction, ReadOnlySQLTransaction, SchemaAndDataStatementMixingNotSupported, HeldCursorRequiresSameIsolationLevel, NoActiveSQLTransaction, InFailedSQLTransaction, IdleInTransactionSessionTimeout, TransactionTimeout: + return true + } + return false +} + +// IsInvalidSqlStatementName returns true if code belongs to +// Class 26 — Invalid SQL Statement Name. +func IsInvalidSqlStatementName(code string) bool { + switch code { + case InvalidSQLStatementName: + return true + } + return false +} + +// IsTriggeredDataChangeViolation returns true if code belongs to +// Class 27 — Triggered Data Change Violation. +func IsTriggeredDataChangeViolation(code string) bool { + switch code { + case TriggeredDataChangeViolation: + return true + } + return false +} + +// IsInvalidAuthorizationSpecification returns true if code belongs to +// Class 28 — Invalid Authorization Specification. +func IsInvalidAuthorizationSpecification(code string) bool { + switch code { + case InvalidAuthorizationSpecification, InvalidPassword: + return true + } + return false +} + +// IsDependentPrivilegeDescriptorsStillExist returns true if code belongs to +// Class 2B — Dependent Privilege Descriptors Still Exist. +func IsDependentPrivilegeDescriptorsStillExist(code string) bool { + switch code { + case DependentPrivilegeDescriptorsStillExist, DependentObjectsStillExist: + return true + } + return false +} + +// IsInvalidTransactionTermination returns true if code belongs to +// Class 2D — Invalid Transaction Termination. +func IsInvalidTransactionTermination(code string) bool { + switch code { + case InvalidTransactionTermination: + return true + } + return false +} + +// IsSqlRoutineException returns true if code belongs to +// Class 2F — SQL Routine Exception. +func IsSqlRoutineException(code string) bool { + switch code { + case SQLRoutineException, ModifyingSQLDataNotPermitted, ProhibitedSQLStatementAttempted, ReadingSQLDataNotPermitted, FunctionExecutedNoReturnStatement: + return true + } + return false +} + +// IsInvalidCursorName returns true if code belongs to +// Class 34 — Invalid Cursor Name. +func IsInvalidCursorName(code string) bool { + switch code { + case InvalidCursorName: + return true + } + return false +} + +// IsExternalRoutineException returns true if code belongs to +// Class 38 — External Routine Exception. +func IsExternalRoutineException(code string) bool { + switch code { + case ExternalRoutineException, ContainingSQLNotPermitted, ModifyingSQLDataNotPermittedClass38, ProhibitedSQLStatementAttemptedClass38, ReadingSQLDataNotPermittedClass38: + return true + } + return false +} + +// IsExternalRoutineInvocationException returns true if code belongs to +// Class 39 — External Routine Invocation Exception. +func IsExternalRoutineInvocationException(code string) bool { + switch code { + case ExternalRoutineInvocationException, InvalidSQLStateReturned, NullValueNotAllowedClass39, TriggerProtocolViolated, SRFProtocolViolated, EventTriggerProtocolViolated: + return true + } + return false +} + +// IsSavepointException returns true if code belongs to +// Class 3B — Savepoint Exception. +func IsSavepointException(code string) bool { + switch code { + case SavepointException, InvalidSavepointSpecification: + return true + } + return false +} + +// IsInvalidCatalogName returns true if code belongs to +// Class 3D — Invalid Catalog Name. +func IsInvalidCatalogName(code string) bool { + switch code { + case InvalidCatalogName: + return true + } + return false +} + +// IsInvalidSchemaName returns true if code belongs to +// Class 3F — Invalid Schema Name. +func IsInvalidSchemaName(code string) bool { + switch code { + case InvalidSchemaName: + return true + } + return false +} + +// IsTransactionRollback returns true if code belongs to +// Class 40 — Transaction Rollback. +func IsTransactionRollback(code string) bool { + switch code { + case TransactionRollback, SerializationFailure, TransactionIntegrityConstraintViolation, StatementCompletionUnknown, DeadlockDetected: + return true + } + return false +} + +// IsSyntaxErrorOrAccessRuleViolation returns true if code belongs to +// Class 42 — Syntax Error or Access Rule Violation. +func IsSyntaxErrorOrAccessRuleViolation(code string) bool { + switch code { + case SyntaxErrorOrAccessRuleViolation, InsufficientPrivilege, SyntaxError, InvalidName, InvalidColumnDefinition, NameTooLong, DuplicateColumn, AmbiguousColumn, UndefinedColumn, UndefinedObject, DuplicateObject, DuplicateAlias, DuplicateFunction, AmbiguousFunction, GroupingError, DatatypeMismatch, WrongObjectType, InvalidForeignKey, CannotCoerce, UndefinedFunction, GeneratedAlways, ReservedName, UndefinedTable, UndefinedParameter, DuplicateCursor, DuplicateDatabase, DuplicatePreparedStatement, DuplicateSchema, DuplicateTable, AmbiguousParameter, AmbiguousAlias, InvalidColumnReference, InvalidCursorDefinition, InvalidDatabaseDefinition, InvalidFunctionDefinition, InvalidPreparedStatementDefinition, InvalidSchemaDefinition, InvalidTableDefinition, InvalidObjectDefinition, IndeterminateDatatype, InvalidRecursion, WindowingError, CollationMismatch, IndeterminateCollation: + return true + } + return false +} + +// IsWithCheckOptionViolation returns true if code belongs to +// Class 44 — WITH CHECK OPTION Violation. +func IsWithCheckOptionViolation(code string) bool { + switch code { + case WithCheckOptionViolation: + return true + } + return false +} + +// IsInsufficientResources returns true if code belongs to +// Class 53 — Insufficient Resources. +func IsInsufficientResources(code string) bool { + switch code { + case InsufficientResources, DiskFull, OutOfMemory, TooManyConnections, ConfigurationLimitExceeded: + return true + } + return false +} + +// IsProgramLimitExceeded returns true if code belongs to +// Class 54 — Program Limit Exceeded. +func IsProgramLimitExceeded(code string) bool { + switch code { + case ProgramLimitExceeded, StatementTooComplex, TooManyColumns, TooManyArguments: + return true + } + return false +} + +// IsObjectNotInPrerequisiteState returns true if code belongs to +// Class 55 — Object Not In Prerequisite State. +func IsObjectNotInPrerequisiteState(code string) bool { + switch code { + case ObjectNotInPrerequisiteState, ObjectInUse, CantChangeRuntimeParam, LockNotAvailable, UnsafeNewEnumValueUsage: + return true + } + return false +} + +// IsOperatorIntervention returns true if code belongs to +// Class 57 — Operator Intervention. +func IsOperatorIntervention(code string) bool { + switch code { + case OperatorIntervention, QueryCanceled, AdminShutdown, CrashShutdown, CannotConnectNow, DatabaseDropped, IdleSessionTimeout: + return true + } + return false +} + +// IsSystemError returns true if code belongs to +// Class 58 — System Error (errors external to PostgreSQL itself). +func IsSystemError(code string) bool { + switch code { + case SystemError, IOError, UndefinedFile, DuplicateFile, FileNameTooLong: + return true + } + return false +} + +// IsSnapshotFailure returns true if code belongs to +// Class 72 — Snapshot Failure. +func IsSnapshotFailure(code string) bool { + switch code { + case SnapshotTooOld: + return true + } + return false +} + +// IsConfigurationFileError returns true if code belongs to +// Class F0 — Configuration File Error. +func IsConfigurationFileError(code string) bool { + switch code { + case ConfigFileError, LockFileExists: + return true + } + return false +} + +// IsForeignDataWrapperError returns true if code belongs to +// Class HV — Foreign Data Wrapper Error (SQL/MED). +func IsForeignDataWrapperError(code string) bool { + switch code { + case FDWError, FDWOutOfMemory, FDWDynamicParameterValueNeeded, FDWInvalidDataType, FDWColumnNameNotFound, FDWInvalidDataTypeDescriptors, FDWInvalidColumnName, FDWInvalidColumnNumber, FDWInvalidUseOfNullPointer, FDWInvalidStringFormat, FDWInvalidHandle, FDWInvalidOptionIndex, FDWInvalidOptionName, FDWOptionNameNotFound, FDWReplyHandle, FDWUnableToCreateExecution, FDWUnableToCreateReply, FDWUnableToEstablishConnection, FDWNoSchemas, FDWSchemaNotFound, FDWTableNotFound, FDWFunctionSequenceError, FDWTooManyHandles, FDWInconsistentDescriptorInformation, FDWInvalidAttributeValue, FDWInvalidStringLengthOrBufferLength, FDWInvalidDescriptorFieldIdentifier: + return true + } + return false +} + +// IsPl returns true if code belongs to +// Class P0 — PL/pgSQL Error. +func IsPl(code string) bool { + switch code { + case PLpgSQLError, RaiseException, NoDataFound, TooManyRows, AssertFailure: + return true + } + return false +} + +// IsInternalError returns true if code belongs to +// Class XX — Internal Error. +func IsInternalError(code string) bool { + switch code { + case InternalError, DataCorrupted, IndexCorrupted: + return true + } + return false +} + +// IsXqueryError returns true if code belongs to +// Class 10 — XQuery Error. +func IsXqueryError(code string) bool { + switch code { + case InvalidArgumentForXquery: + return true + } + return false +} + +// Name returns the constant name for a PostgreSQL error code, +// or an empty string if the code is not recognised. +func Name(code string) string { + switch code { + case SuccessfulCompletion: + return "SuccessfulCompletion" + case Warning: + return "Warning" + case NullValueEliminatedInSetFunction: + return "NullValueEliminatedInSetFunction" + case StringDataRightTruncation: + return "StringDataRightTruncation" + case PrivilegeNotRevoked: + return "PrivilegeNotRevoked" + case PrivilegeNotGranted: + return "PrivilegeNotGranted" + case ImplicitZeroBitPadding: + return "ImplicitZeroBitPadding" + case DynamicResultSetsReturned: + return "DynamicResultSetsReturned" + case DeprecatedFeature: + return "DeprecatedFeature" + case NoData: + return "NoData" + case NoAdditionalDynamicResultSetsReturned: + return "NoAdditionalDynamicResultSetsReturned" + case SQLStatementNotYetComplete: + return "SQLStatementNotYetComplete" + case ConnectionException: + return "ConnectionException" + case SqlclientUnableToEstablishSqlconnection: + return "SqlclientUnableToEstablishSqlconnection" + case ConnectionDoesNotExist: + return "ConnectionDoesNotExist" + case SqlserverRejectedEstablishmentOfSqlconnection: + return "SqlserverRejectedEstablishmentOfSqlconnection" + case ConnectionFailure: + return "ConnectionFailure" + case TransactionResolutionUnknown: + return "TransactionResolutionUnknown" + case ProtocolViolation: + return "ProtocolViolation" + case TriggeredActionException: + return "TriggeredActionException" + case FeatureNotSupported: + return "FeatureNotSupported" + case InvalidTransactionInitiation: + return "InvalidTransactionInitiation" + case LocatorException: + return "LocatorException" + case InvalidLocatorSpecification: + return "InvalidLocatorSpecification" + case InvalidGrantor: + return "InvalidGrantor" + case InvalidGrantOperation: + return "InvalidGrantOperation" + case InvalidRoleSpecification: + return "InvalidRoleSpecification" + case DiagnosticsException: + return "DiagnosticsException" + case StackedDiagnosticsAccessedWithoutActiveHandler: + return "StackedDiagnosticsAccessedWithoutActiveHandler" + case CaseNotFound: + return "CaseNotFound" + case CardinalityViolation: + return "CardinalityViolation" + case DataException: + return "DataException" + case StringDataRightTruncationClass22: + return "StringDataRightTruncation" + case NullValueNoIndicatorParameter: + return "NullValueNoIndicatorParameter" + case NumericValueOutOfRange: + return "NumericValueOutOfRange" + case NullValueNotAllowed: + return "NullValueNotAllowed" + case ErrorInAssignment: + return "ErrorInAssignment" + case InvalidDatetimeFormat: + return "InvalidDatetimeFormat" + case DatetimeFieldOverflow: + return "DatetimeFieldOverflow" + case InvalidTimeZoneDisplacementValue: + return "InvalidTimeZoneDisplacementValue" + case EscapeCharacterConflict: + return "EscapeCharacterConflict" + case InvalidUseOfEscapeCharacter: + return "InvalidUseOfEscapeCharacter" + case InvalidEscapeOctet: + return "InvalidEscapeOctet" + case ZeroLengthCharacterString: + return "ZeroLengthCharacterString" + case MostSpecificTypeMismatch: + return "MostSpecificTypeMismatch" + case SequenceGeneratorLimitExceeded: + return "SequenceGeneratorLimitExceeded" + case NotAnXMLDocument: + return "NotAnXMLDocument" + case InvalidXMLDocument: + return "InvalidXMLDocument" + case InvalidXMLContent: + return "InvalidXMLContent" + case InvalidXMLComment: + return "InvalidXMLComment" + case InvalidXMLProcessingInstruction: + return "InvalidXMLProcessingInstruction" + case InvalidIndicatorParameterValue: + return "InvalidIndicatorParameterValue" + case SubstringError: + return "SubstringError" + case DivisionByZero: + return "DivisionByZero" + case InvalidPrecedingOrFollowingSize: + return "InvalidPrecedingOrFollowingSize" + case InvalidArgumentForNtileFunction: + return "InvalidArgumentForNtileFunction" + case IntervalFieldOverflow: + return "IntervalFieldOverflow" + case InvalidArgumentForNthValueFunction: + return "InvalidArgumentForNthValueFunction" + case InvalidCharacterValueForCast: + return "InvalidCharacterValueForCast" + case InvalidEscapeCharacter: + return "InvalidEscapeCharacter" + case InvalidRegularExpression: + return "InvalidRegularExpression" + case InvalidArgumentForLogarithm: + return "InvalidArgumentForLogarithm" + case InvalidArgumentForPowerFunction: + return "InvalidArgumentForPowerFunction" + case InvalidArgumentForWidthBucketFunction: + return "InvalidArgumentForWidthBucketFunction" + case InvalidRowCountInLimitClause: + return "InvalidRowCountInLimitClause" + case InvalidRowCountInResultOffsetClause: + return "InvalidRowCountInResultOffsetClause" + case CharacterNotInRepertoire: + return "CharacterNotInRepertoire" + case IndicatorOverflow: + return "IndicatorOverflow" + case InvalidParameterValue: + return "InvalidParameterValue" + case UnterminatedCString: + return "UnterminatedCString" + case InvalidEscapeSequence: + return "InvalidEscapeSequence" + case StringDataLengthMismatch: + return "StringDataLengthMismatch" + case TrimError: + return "TrimError" + case ArraySubscriptError: + return "ArraySubscriptError" + case InvalidTablesampleRepeat: + return "InvalidTablesampleRepeat" + case InvalidTablesampleArgument: + return "InvalidTablesampleArgument" + case DuplicateJSONObjectKeyValue: + return "DuplicateJSONObjectKeyValue" + case InvalidArgumentForSQLJSONDatetimeFunction: + return "InvalidArgumentForSQLJSONDatetimeFunction" + case InvalidJSONText: + return "InvalidJSONText" + case InvalidSQLJSONSubscript: + return "InvalidSQLJSONSubscript" + case MoreThanOneSQLJSONItem: + return "MoreThanOneSQLJSONItem" + case NoSQLJSONItem: + return "NoSQLJSONItem" + case NonNumericSQLJSONItem: + return "NonNumericSQLJSONItem" + case NonUniqueKeysInAJSONObject: + return "NonUniqueKeysInAJSONObject" + case SingletonSQLJSONItemRequired: + return "SingletonSQLJSONItemRequired" + case SQLJSONArrayNotFound: + return "SQLJSONArrayNotFound" + case SQLJSONMemberNotFound: + return "SQLJSONMemberNotFound" + case SQLJSONNumberNotFound: + return "SQLJSONNumberNotFound" + case SQLJSONObjectNotFound: + return "SQLJSONObjectNotFound" + case TooManyJSONArrayElements: + return "TooManyJSONArrayElements" + case TooManyJSONObjectMembers: + return "TooManyJSONObjectMembers" + case SQLJSONScalarRequired: + return "SQLJSONScalarRequired" + case SQLJSONItemCannotBeCastToTargetType: + return "SQLJSONItemCannotBeCastToTargetType" + case FloatingPointException: + return "FloatingPointException" + case InvalidTextRepresentation: + return "InvalidTextRepresentation" + case InvalidBinaryRepresentation: + return "InvalidBinaryRepresentation" + case BadCopyFileFormat: + return "BadCopyFileFormat" + case UntranslatableCharacter: + return "UntranslatableCharacter" + case NonstandardUseOfEscapeCharacter: + return "NonstandardUseOfEscapeCharacter" + case IntegrityConstraintViolation: + return "IntegrityConstraintViolation" + case RestrictViolation: + return "RestrictViolation" + case NotNullViolation: + return "NotNullViolation" + case ForeignKeyViolation: + return "ForeignKeyViolation" + case UniqueViolation: + return "UniqueViolation" + case CheckViolation: + return "CheckViolation" + case ExclusionViolation: + return "ExclusionViolation" + case InvalidCursorState: + return "InvalidCursorState" + case InvalidTransactionState: + return "InvalidTransactionState" + case ActiveSQLTransaction: + return "ActiveSQLTransaction" + case BranchTransactionAlreadyActive: + return "BranchTransactionAlreadyActive" + case InappropriateAccessModeForBranchTransaction: + return "InappropriateAccessModeForBranchTransaction" + case InappropriateIsolationLevelForBranchTransaction: + return "InappropriateIsolationLevelForBranchTransaction" + case NoActiveSQLTransactionForBranchTransaction: + return "NoActiveSQLTransactionForBranchTransaction" + case ReadOnlySQLTransaction: + return "ReadOnlySQLTransaction" + case SchemaAndDataStatementMixingNotSupported: + return "SchemaAndDataStatementMixingNotSupported" + case HeldCursorRequiresSameIsolationLevel: + return "HeldCursorRequiresSameIsolationLevel" + case NoActiveSQLTransaction: + return "NoActiveSQLTransaction" + case InFailedSQLTransaction: + return "InFailedSQLTransaction" + case IdleInTransactionSessionTimeout: + return "IdleInTransactionSessionTimeout" + case TransactionTimeout: + return "TransactionTimeout" + case InvalidSQLStatementName: + return "InvalidSQLStatementName" + case TriggeredDataChangeViolation: + return "TriggeredDataChangeViolation" + case InvalidAuthorizationSpecification: + return "InvalidAuthorizationSpecification" + case InvalidPassword: + return "InvalidPassword" + case DependentPrivilegeDescriptorsStillExist: + return "DependentPrivilegeDescriptorsStillExist" + case DependentObjectsStillExist: + return "DependentObjectsStillExist" + case InvalidTransactionTermination: + return "InvalidTransactionTermination" + case SQLRoutineException: + return "SQLRoutineException" + case ModifyingSQLDataNotPermitted: + return "ModifyingSQLDataNotPermitted" + case ProhibitedSQLStatementAttempted: + return "ProhibitedSQLStatementAttempted" + case ReadingSQLDataNotPermitted: + return "ReadingSQLDataNotPermitted" + case FunctionExecutedNoReturnStatement: + return "FunctionExecutedNoReturnStatement" + case InvalidCursorName: + return "InvalidCursorName" + case ExternalRoutineException: + return "ExternalRoutineException" + case ContainingSQLNotPermitted: + return "ContainingSQLNotPermitted" + case ModifyingSQLDataNotPermittedClass38: + return "ModifyingSQLDataNotPermitted" + case ProhibitedSQLStatementAttemptedClass38: + return "ProhibitedSQLStatementAttempted" + case ReadingSQLDataNotPermittedClass38: + return "ReadingSQLDataNotPermitted" + case ExternalRoutineInvocationException: + return "ExternalRoutineInvocationException" + case InvalidSQLStateReturned: + return "InvalidSQLStateReturned" + case NullValueNotAllowedClass39: + return "NullValueNotAllowed" + case TriggerProtocolViolated: + return "TriggerProtocolViolated" + case SRFProtocolViolated: + return "SRFProtocolViolated" + case EventTriggerProtocolViolated: + return "EventTriggerProtocolViolated" + case SavepointException: + return "SavepointException" + case InvalidSavepointSpecification: + return "InvalidSavepointSpecification" + case InvalidCatalogName: + return "InvalidCatalogName" + case InvalidSchemaName: + return "InvalidSchemaName" + case TransactionRollback: + return "TransactionRollback" + case SerializationFailure: + return "SerializationFailure" + case TransactionIntegrityConstraintViolation: + return "TransactionIntegrityConstraintViolation" + case StatementCompletionUnknown: + return "StatementCompletionUnknown" + case DeadlockDetected: + return "DeadlockDetected" + case SyntaxErrorOrAccessRuleViolation: + return "SyntaxErrorOrAccessRuleViolation" + case InsufficientPrivilege: + return "InsufficientPrivilege" + case SyntaxError: + return "SyntaxError" + case InvalidName: + return "InvalidName" + case InvalidColumnDefinition: + return "InvalidColumnDefinition" + case NameTooLong: + return "NameTooLong" + case DuplicateColumn: + return "DuplicateColumn" + case AmbiguousColumn: + return "AmbiguousColumn" + case UndefinedColumn: + return "UndefinedColumn" + case UndefinedObject: + return "UndefinedObject" + case DuplicateObject: + return "DuplicateObject" + case DuplicateAlias: + return "DuplicateAlias" + case DuplicateFunction: + return "DuplicateFunction" + case AmbiguousFunction: + return "AmbiguousFunction" + case GroupingError: + return "GroupingError" + case DatatypeMismatch: + return "DatatypeMismatch" + case WrongObjectType: + return "WrongObjectType" + case InvalidForeignKey: + return "InvalidForeignKey" + case CannotCoerce: + return "CannotCoerce" + case UndefinedFunction: + return "UndefinedFunction" + case GeneratedAlways: + return "GeneratedAlways" + case ReservedName: + return "ReservedName" + case UndefinedTable: + return "UndefinedTable" + case UndefinedParameter: + return "UndefinedParameter" + case DuplicateCursor: + return "DuplicateCursor" + case DuplicateDatabase: + return "DuplicateDatabase" + case DuplicatePreparedStatement: + return "DuplicatePreparedStatement" + case DuplicateSchema: + return "DuplicateSchema" + case DuplicateTable: + return "DuplicateTable" + case AmbiguousParameter: + return "AmbiguousParameter" + case AmbiguousAlias: + return "AmbiguousAlias" + case InvalidColumnReference: + return "InvalidColumnReference" + case InvalidCursorDefinition: + return "InvalidCursorDefinition" + case InvalidDatabaseDefinition: + return "InvalidDatabaseDefinition" + case InvalidFunctionDefinition: + return "InvalidFunctionDefinition" + case InvalidPreparedStatementDefinition: + return "InvalidPreparedStatementDefinition" + case InvalidSchemaDefinition: + return "InvalidSchemaDefinition" + case InvalidTableDefinition: + return "InvalidTableDefinition" + case InvalidObjectDefinition: + return "InvalidObjectDefinition" + case IndeterminateDatatype: + return "IndeterminateDatatype" + case InvalidRecursion: + return "InvalidRecursion" + case WindowingError: + return "WindowingError" + case CollationMismatch: + return "CollationMismatch" + case IndeterminateCollation: + return "IndeterminateCollation" + case WithCheckOptionViolation: + return "WithCheckOptionViolation" + case InsufficientResources: + return "InsufficientResources" + case DiskFull: + return "DiskFull" + case OutOfMemory: + return "OutOfMemory" + case TooManyConnections: + return "TooManyConnections" + case ConfigurationLimitExceeded: + return "ConfigurationLimitExceeded" + case ProgramLimitExceeded: + return "ProgramLimitExceeded" + case StatementTooComplex: + return "StatementTooComplex" + case TooManyColumns: + return "TooManyColumns" + case TooManyArguments: + return "TooManyArguments" + case ObjectNotInPrerequisiteState: + return "ObjectNotInPrerequisiteState" + case ObjectInUse: + return "ObjectInUse" + case CantChangeRuntimeParam: + return "CantChangeRuntimeParam" + case LockNotAvailable: + return "LockNotAvailable" + case UnsafeNewEnumValueUsage: + return "UnsafeNewEnumValueUsage" + case OperatorIntervention: + return "OperatorIntervention" + case QueryCanceled: + return "QueryCanceled" + case AdminShutdown: + return "AdminShutdown" + case CrashShutdown: + return "CrashShutdown" + case CannotConnectNow: + return "CannotConnectNow" + case DatabaseDropped: + return "DatabaseDropped" + case IdleSessionTimeout: + return "IdleSessionTimeout" + case SystemError: + return "SystemError" + case IOError: + return "IOError" + case UndefinedFile: + return "UndefinedFile" + case DuplicateFile: + return "DuplicateFile" + case FileNameTooLong: + return "FileNameTooLong" + case SnapshotTooOld: + return "SnapshotTooOld" + case ConfigFileError: + return "ConfigFileError" + case LockFileExists: + return "LockFileExists" + case FDWError: + return "FDWError" + case FDWOutOfMemory: + return "FDWOutOfMemory" + case FDWDynamicParameterValueNeeded: + return "FDWDynamicParameterValueNeeded" + case FDWInvalidDataType: + return "FDWInvalidDataType" + case FDWColumnNameNotFound: + return "FDWColumnNameNotFound" + case FDWInvalidDataTypeDescriptors: + return "FDWInvalidDataTypeDescriptors" + case FDWInvalidColumnName: + return "FDWInvalidColumnName" + case FDWInvalidColumnNumber: + return "FDWInvalidColumnNumber" + case FDWInvalidUseOfNullPointer: + return "FDWInvalidUseOfNullPointer" + case FDWInvalidStringFormat: + return "FDWInvalidStringFormat" + case FDWInvalidHandle: + return "FDWInvalidHandle" + case FDWInvalidOptionIndex: + return "FDWInvalidOptionIndex" + case FDWInvalidOptionName: + return "FDWInvalidOptionName" + case FDWOptionNameNotFound: + return "FDWOptionNameNotFound" + case FDWReplyHandle: + return "FDWReplyHandle" + case FDWUnableToCreateExecution: + return "FDWUnableToCreateExecution" + case FDWUnableToCreateReply: + return "FDWUnableToCreateReply" + case FDWUnableToEstablishConnection: + return "FDWUnableToEstablishConnection" + case FDWNoSchemas: + return "FDWNoSchemas" + case FDWSchemaNotFound: + return "FDWSchemaNotFound" + case FDWTableNotFound: + return "FDWTableNotFound" + case FDWFunctionSequenceError: + return "FDWFunctionSequenceError" + case FDWTooManyHandles: + return "FDWTooManyHandles" + case FDWInconsistentDescriptorInformation: + return "FDWInconsistentDescriptorInformation" + case FDWInvalidAttributeValue: + return "FDWInvalidAttributeValue" + case FDWInvalidStringLengthOrBufferLength: + return "FDWInvalidStringLengthOrBufferLength" + case FDWInvalidDescriptorFieldIdentifier: + return "FDWInvalidDescriptorFieldIdentifier" + case PLpgSQLError: + return "PLpgSQLError" + case RaiseException: + return "RaiseException" + case NoDataFound: + return "NoDataFound" + case TooManyRows: + return "TooManyRows" + case AssertFailure: + return "AssertFailure" + case InternalError: + return "InternalError" + case DataCorrupted: + return "DataCorrupted" + case IndexCorrupted: + return "IndexCorrupted" + case InvalidArgumentForXquery: + return "InvalidArgumentForXquery" + } + return "" +} diff --git a/code_test.go b/code_test.go new file mode 100644 index 0000000..aedc49c --- /dev/null +++ b/code_test.go @@ -0,0 +1,832 @@ +package pgcode_test + +import ( + "testing" + + "github.com/b0r1ssh/pgcode" +) + +// TestConstantsMatchCodes verifies every constant has the correct string value. +func TestConstantsMatchCodes(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + got string + want string + }{ + {"SuccessfulCompletion", pgcode.SuccessfulCompletion, "00000"}, + {"Warning", pgcode.Warning, "01000"}, + {"NullValueEliminatedInSetFunction", pgcode.NullValueEliminatedInSetFunction, "01003"}, + {"StringDataRightTruncation", pgcode.StringDataRightTruncation, "01004"}, + {"PrivilegeNotRevoked", pgcode.PrivilegeNotRevoked, "01006"}, + {"PrivilegeNotGranted", pgcode.PrivilegeNotGranted, "01007"}, + {"ImplicitZeroBitPadding", pgcode.ImplicitZeroBitPadding, "01008"}, + {"DynamicResultSetsReturned", pgcode.DynamicResultSetsReturned, "0100C"}, + {"DeprecatedFeature", pgcode.DeprecatedFeature, "01P01"}, + {"NoData", pgcode.NoData, "02000"}, + {"NoAdditionalDynamicResultSetsReturned", pgcode.NoAdditionalDynamicResultSetsReturned, "02001"}, + {"SQLStatementNotYetComplete", pgcode.SQLStatementNotYetComplete, "03000"}, + {"ConnectionException", pgcode.ConnectionException, "08000"}, + {"SqlclientUnableToEstablishSqlconnection", pgcode.SqlclientUnableToEstablishSqlconnection, "08001"}, + {"ConnectionDoesNotExist", pgcode.ConnectionDoesNotExist, "08003"}, + {"SqlserverRejectedEstablishmentOfSqlconnection", pgcode.SqlserverRejectedEstablishmentOfSqlconnection, "08004"}, + {"ConnectionFailure", pgcode.ConnectionFailure, "08006"}, + {"TransactionResolutionUnknown", pgcode.TransactionResolutionUnknown, "08007"}, + {"ProtocolViolation", pgcode.ProtocolViolation, "08P01"}, + {"TriggeredActionException", pgcode.TriggeredActionException, "09000"}, + {"FeatureNotSupported", pgcode.FeatureNotSupported, "0A000"}, + {"InvalidTransactionInitiation", pgcode.InvalidTransactionInitiation, "0B000"}, + {"LocatorException", pgcode.LocatorException, "0F000"}, + {"InvalidLocatorSpecification", pgcode.InvalidLocatorSpecification, "0F001"}, + {"InvalidGrantor", pgcode.InvalidGrantor, "0L000"}, + {"InvalidGrantOperation", pgcode.InvalidGrantOperation, "0LP01"}, + {"InvalidRoleSpecification", pgcode.InvalidRoleSpecification, "0P000"}, + {"DiagnosticsException", pgcode.DiagnosticsException, "0Z000"}, + {"StackedDiagnosticsAccessedWithoutActiveHandler", pgcode.StackedDiagnosticsAccessedWithoutActiveHandler, "0Z002"}, + {"CaseNotFound", pgcode.CaseNotFound, "20000"}, + {"CardinalityViolation", pgcode.CardinalityViolation, "21000"}, + {"DataException", pgcode.DataException, "22000"}, + {"StringDataRightTruncation", pgcode.StringDataRightTruncationClass22, "22001"}, + {"NullValueNoIndicatorParameter", pgcode.NullValueNoIndicatorParameter, "22002"}, + {"NumericValueOutOfRange", pgcode.NumericValueOutOfRange, "22003"}, + {"NullValueNotAllowed", pgcode.NullValueNotAllowed, "22004"}, + {"ErrorInAssignment", pgcode.ErrorInAssignment, "22005"}, + {"InvalidDatetimeFormat", pgcode.InvalidDatetimeFormat, "22007"}, + {"DatetimeFieldOverflow", pgcode.DatetimeFieldOverflow, "22008"}, + {"InvalidTimeZoneDisplacementValue", pgcode.InvalidTimeZoneDisplacementValue, "22009"}, + {"EscapeCharacterConflict", pgcode.EscapeCharacterConflict, "2200B"}, + {"InvalidUseOfEscapeCharacter", pgcode.InvalidUseOfEscapeCharacter, "2200C"}, + {"InvalidEscapeOctet", pgcode.InvalidEscapeOctet, "2200D"}, + {"ZeroLengthCharacterString", pgcode.ZeroLengthCharacterString, "2200F"}, + {"MostSpecificTypeMismatch", pgcode.MostSpecificTypeMismatch, "2200G"}, + {"SequenceGeneratorLimitExceeded", pgcode.SequenceGeneratorLimitExceeded, "2200H"}, + {"NotAnXMLDocument", pgcode.NotAnXMLDocument, "2200L"}, + {"InvalidXMLDocument", pgcode.InvalidXMLDocument, "2200M"}, + {"InvalidXMLContent", pgcode.InvalidXMLContent, "2200N"}, + {"InvalidXMLComment", pgcode.InvalidXMLComment, "2200S"}, + {"InvalidXMLProcessingInstruction", pgcode.InvalidXMLProcessingInstruction, "2200T"}, + {"InvalidIndicatorParameterValue", pgcode.InvalidIndicatorParameterValue, "22010"}, + {"SubstringError", pgcode.SubstringError, "22011"}, + {"DivisionByZero", pgcode.DivisionByZero, "22012"}, + {"InvalidPrecedingOrFollowingSize", pgcode.InvalidPrecedingOrFollowingSize, "22013"}, + {"InvalidArgumentForNtileFunction", pgcode.InvalidArgumentForNtileFunction, "22014"}, + {"IntervalFieldOverflow", pgcode.IntervalFieldOverflow, "22015"}, + {"InvalidArgumentForNthValueFunction", pgcode.InvalidArgumentForNthValueFunction, "22016"}, + {"InvalidCharacterValueForCast", pgcode.InvalidCharacterValueForCast, "22018"}, + {"InvalidEscapeCharacter", pgcode.InvalidEscapeCharacter, "22019"}, + {"InvalidRegularExpression", pgcode.InvalidRegularExpression, "2201B"}, + {"InvalidArgumentForLogarithm", pgcode.InvalidArgumentForLogarithm, "2201E"}, + {"InvalidArgumentForPowerFunction", pgcode.InvalidArgumentForPowerFunction, "2201F"}, + {"InvalidArgumentForWidthBucketFunction", pgcode.InvalidArgumentForWidthBucketFunction, "2201G"}, + {"InvalidRowCountInLimitClause", pgcode.InvalidRowCountInLimitClause, "2201W"}, + {"InvalidRowCountInResultOffsetClause", pgcode.InvalidRowCountInResultOffsetClause, "2201X"}, + {"CharacterNotInRepertoire", pgcode.CharacterNotInRepertoire, "22021"}, + {"IndicatorOverflow", pgcode.IndicatorOverflow, "22022"}, + {"InvalidParameterValue", pgcode.InvalidParameterValue, "22023"}, + {"UnterminatedCString", pgcode.UnterminatedCString, "22024"}, + {"InvalidEscapeSequence", pgcode.InvalidEscapeSequence, "22025"}, + {"StringDataLengthMismatch", pgcode.StringDataLengthMismatch, "22026"}, + {"TrimError", pgcode.TrimError, "22027"}, + {"ArraySubscriptError", pgcode.ArraySubscriptError, "2202E"}, + {"InvalidTablesampleRepeat", pgcode.InvalidTablesampleRepeat, "2202G"}, + {"InvalidTablesampleArgument", pgcode.InvalidTablesampleArgument, "2202H"}, + {"DuplicateJSONObjectKeyValue", pgcode.DuplicateJSONObjectKeyValue, "22030"}, + {"InvalidArgumentForSQLJSONDatetimeFunction", pgcode.InvalidArgumentForSQLJSONDatetimeFunction, "22031"}, + {"InvalidJSONText", pgcode.InvalidJSONText, "22032"}, + {"InvalidSQLJSONSubscript", pgcode.InvalidSQLJSONSubscript, "22033"}, + {"MoreThanOneSQLJSONItem", pgcode.MoreThanOneSQLJSONItem, "22034"}, + {"NoSQLJSONItem", pgcode.NoSQLJSONItem, "22035"}, + {"NonNumericSQLJSONItem", pgcode.NonNumericSQLJSONItem, "22036"}, + {"NonUniqueKeysInAJSONObject", pgcode.NonUniqueKeysInAJSONObject, "22037"}, + {"SingletonSQLJSONItemRequired", pgcode.SingletonSQLJSONItemRequired, "22038"}, + {"SQLJSONArrayNotFound", pgcode.SQLJSONArrayNotFound, "22039"}, + {"SQLJSONMemberNotFound", pgcode.SQLJSONMemberNotFound, "2203A"}, + {"SQLJSONNumberNotFound", pgcode.SQLJSONNumberNotFound, "2203B"}, + {"SQLJSONObjectNotFound", pgcode.SQLJSONObjectNotFound, "2203C"}, + {"TooManyJSONArrayElements", pgcode.TooManyJSONArrayElements, "2203D"}, + {"TooManyJSONObjectMembers", pgcode.TooManyJSONObjectMembers, "2203E"}, + {"SQLJSONScalarRequired", pgcode.SQLJSONScalarRequired, "2203F"}, + {"SQLJSONItemCannotBeCastToTargetType", pgcode.SQLJSONItemCannotBeCastToTargetType, "2203G"}, + {"FloatingPointException", pgcode.FloatingPointException, "22P01"}, + {"InvalidTextRepresentation", pgcode.InvalidTextRepresentation, "22P02"}, + {"InvalidBinaryRepresentation", pgcode.InvalidBinaryRepresentation, "22P03"}, + {"BadCopyFileFormat", pgcode.BadCopyFileFormat, "22P04"}, + {"UntranslatableCharacter", pgcode.UntranslatableCharacter, "22P05"}, + {"NonstandardUseOfEscapeCharacter", pgcode.NonstandardUseOfEscapeCharacter, "22P06"}, + {"IntegrityConstraintViolation", pgcode.IntegrityConstraintViolation, "23000"}, + {"RestrictViolation", pgcode.RestrictViolation, "23001"}, + {"NotNullViolation", pgcode.NotNullViolation, "23502"}, + {"ForeignKeyViolation", pgcode.ForeignKeyViolation, "23503"}, + {"UniqueViolation", pgcode.UniqueViolation, "23505"}, + {"CheckViolation", pgcode.CheckViolation, "23514"}, + {"ExclusionViolation", pgcode.ExclusionViolation, "23P01"}, + {"InvalidCursorState", pgcode.InvalidCursorState, "24000"}, + {"InvalidTransactionState", pgcode.InvalidTransactionState, "25000"}, + {"ActiveSQLTransaction", pgcode.ActiveSQLTransaction, "25001"}, + {"BranchTransactionAlreadyActive", pgcode.BranchTransactionAlreadyActive, "25002"}, + {"InappropriateAccessModeForBranchTransaction", pgcode.InappropriateAccessModeForBranchTransaction, "25003"}, + {"InappropriateIsolationLevelForBranchTransaction", pgcode.InappropriateIsolationLevelForBranchTransaction, "25004"}, + {"NoActiveSQLTransactionForBranchTransaction", pgcode.NoActiveSQLTransactionForBranchTransaction, "25005"}, + {"ReadOnlySQLTransaction", pgcode.ReadOnlySQLTransaction, "25006"}, + {"SchemaAndDataStatementMixingNotSupported", pgcode.SchemaAndDataStatementMixingNotSupported, "25007"}, + {"HeldCursorRequiresSameIsolationLevel", pgcode.HeldCursorRequiresSameIsolationLevel, "25008"}, + {"NoActiveSQLTransaction", pgcode.NoActiveSQLTransaction, "25P01"}, + {"InFailedSQLTransaction", pgcode.InFailedSQLTransaction, "25P02"}, + {"IdleInTransactionSessionTimeout", pgcode.IdleInTransactionSessionTimeout, "25P03"}, + {"TransactionTimeout", pgcode.TransactionTimeout, "25P04"}, + {"InvalidSQLStatementName", pgcode.InvalidSQLStatementName, "26000"}, + {"TriggeredDataChangeViolation", pgcode.TriggeredDataChangeViolation, "27000"}, + {"InvalidAuthorizationSpecification", pgcode.InvalidAuthorizationSpecification, "28000"}, + {"InvalidPassword", pgcode.InvalidPassword, "28P01"}, + {"DependentPrivilegeDescriptorsStillExist", pgcode.DependentPrivilegeDescriptorsStillExist, "2B000"}, + {"DependentObjectsStillExist", pgcode.DependentObjectsStillExist, "2BP01"}, + {"InvalidTransactionTermination", pgcode.InvalidTransactionTermination, "2D000"}, + {"SQLRoutineException", pgcode.SQLRoutineException, "2F000"}, + {"ModifyingSQLDataNotPermitted", pgcode.ModifyingSQLDataNotPermitted, "2F002"}, + {"ProhibitedSQLStatementAttempted", pgcode.ProhibitedSQLStatementAttempted, "2F003"}, + {"ReadingSQLDataNotPermitted", pgcode.ReadingSQLDataNotPermitted, "2F004"}, + {"FunctionExecutedNoReturnStatement", pgcode.FunctionExecutedNoReturnStatement, "2F005"}, + {"InvalidCursorName", pgcode.InvalidCursorName, "34000"}, + {"ExternalRoutineException", pgcode.ExternalRoutineException, "38000"}, + {"ContainingSQLNotPermitted", pgcode.ContainingSQLNotPermitted, "38001"}, + {"ModifyingSQLDataNotPermitted", pgcode.ModifyingSQLDataNotPermittedClass38, "38002"}, + {"ProhibitedSQLStatementAttempted", pgcode.ProhibitedSQLStatementAttemptedClass38, "38003"}, + {"ReadingSQLDataNotPermitted", pgcode.ReadingSQLDataNotPermittedClass38, "38004"}, + {"ExternalRoutineInvocationException", pgcode.ExternalRoutineInvocationException, "39000"}, + {"InvalidSQLStateReturned", pgcode.InvalidSQLStateReturned, "39001"}, + {"NullValueNotAllowed", pgcode.NullValueNotAllowedClass39, "39004"}, + {"TriggerProtocolViolated", pgcode.TriggerProtocolViolated, "39P01"}, + {"SRFProtocolViolated", pgcode.SRFProtocolViolated, "39P02"}, + {"EventTriggerProtocolViolated", pgcode.EventTriggerProtocolViolated, "39P03"}, + {"SavepointException", pgcode.SavepointException, "3B000"}, + {"InvalidSavepointSpecification", pgcode.InvalidSavepointSpecification, "3B001"}, + {"InvalidCatalogName", pgcode.InvalidCatalogName, "3D000"}, + {"InvalidSchemaName", pgcode.InvalidSchemaName, "3F000"}, + {"TransactionRollback", pgcode.TransactionRollback, "40000"}, + {"SerializationFailure", pgcode.SerializationFailure, "40001"}, + {"TransactionIntegrityConstraintViolation", pgcode.TransactionIntegrityConstraintViolation, "40002"}, + {"StatementCompletionUnknown", pgcode.StatementCompletionUnknown, "40003"}, + {"DeadlockDetected", pgcode.DeadlockDetected, "40P01"}, + {"SyntaxErrorOrAccessRuleViolation", pgcode.SyntaxErrorOrAccessRuleViolation, "42000"}, + {"InsufficientPrivilege", pgcode.InsufficientPrivilege, "42501"}, + {"SyntaxError", pgcode.SyntaxError, "42601"}, + {"InvalidName", pgcode.InvalidName, "42602"}, + {"InvalidColumnDefinition", pgcode.InvalidColumnDefinition, "42611"}, + {"NameTooLong", pgcode.NameTooLong, "42622"}, + {"DuplicateColumn", pgcode.DuplicateColumn, "42701"}, + {"AmbiguousColumn", pgcode.AmbiguousColumn, "42702"}, + {"UndefinedColumn", pgcode.UndefinedColumn, "42703"}, + {"UndefinedObject", pgcode.UndefinedObject, "42704"}, + {"DuplicateObject", pgcode.DuplicateObject, "42710"}, + {"DuplicateAlias", pgcode.DuplicateAlias, "42712"}, + {"DuplicateFunction", pgcode.DuplicateFunction, "42723"}, + {"AmbiguousFunction", pgcode.AmbiguousFunction, "42725"}, + {"GroupingError", pgcode.GroupingError, "42803"}, + {"DatatypeMismatch", pgcode.DatatypeMismatch, "42804"}, + {"WrongObjectType", pgcode.WrongObjectType, "42809"}, + {"InvalidForeignKey", pgcode.InvalidForeignKey, "42830"}, + {"CannotCoerce", pgcode.CannotCoerce, "42846"}, + {"UndefinedFunction", pgcode.UndefinedFunction, "42883"}, + {"GeneratedAlways", pgcode.GeneratedAlways, "428C9"}, + {"ReservedName", pgcode.ReservedName, "42939"}, + {"UndefinedTable", pgcode.UndefinedTable, "42P01"}, + {"UndefinedParameter", pgcode.UndefinedParameter, "42P02"}, + {"DuplicateCursor", pgcode.DuplicateCursor, "42P03"}, + {"DuplicateDatabase", pgcode.DuplicateDatabase, "42P04"}, + {"DuplicatePreparedStatement", pgcode.DuplicatePreparedStatement, "42P05"}, + {"DuplicateSchema", pgcode.DuplicateSchema, "42P06"}, + {"DuplicateTable", pgcode.DuplicateTable, "42P07"}, + {"AmbiguousParameter", pgcode.AmbiguousParameter, "42P08"}, + {"AmbiguousAlias", pgcode.AmbiguousAlias, "42P09"}, + {"InvalidColumnReference", pgcode.InvalidColumnReference, "42P10"}, + {"InvalidCursorDefinition", pgcode.InvalidCursorDefinition, "42P11"}, + {"InvalidDatabaseDefinition", pgcode.InvalidDatabaseDefinition, "42P12"}, + {"InvalidFunctionDefinition", pgcode.InvalidFunctionDefinition, "42P13"}, + {"InvalidPreparedStatementDefinition", pgcode.InvalidPreparedStatementDefinition, "42P14"}, + {"InvalidSchemaDefinition", pgcode.InvalidSchemaDefinition, "42P15"}, + {"InvalidTableDefinition", pgcode.InvalidTableDefinition, "42P16"}, + {"InvalidObjectDefinition", pgcode.InvalidObjectDefinition, "42P17"}, + {"IndeterminateDatatype", pgcode.IndeterminateDatatype, "42P18"}, + {"InvalidRecursion", pgcode.InvalidRecursion, "42P19"}, + {"WindowingError", pgcode.WindowingError, "42P20"}, + {"CollationMismatch", pgcode.CollationMismatch, "42P21"}, + {"IndeterminateCollation", pgcode.IndeterminateCollation, "42P22"}, + {"WithCheckOptionViolation", pgcode.WithCheckOptionViolation, "44000"}, + {"InsufficientResources", pgcode.InsufficientResources, "53000"}, + {"DiskFull", pgcode.DiskFull, "53100"}, + {"OutOfMemory", pgcode.OutOfMemory, "53200"}, + {"TooManyConnections", pgcode.TooManyConnections, "53300"}, + {"ConfigurationLimitExceeded", pgcode.ConfigurationLimitExceeded, "53400"}, + {"ProgramLimitExceeded", pgcode.ProgramLimitExceeded, "54000"}, + {"StatementTooComplex", pgcode.StatementTooComplex, "54001"}, + {"TooManyColumns", pgcode.TooManyColumns, "54011"}, + {"TooManyArguments", pgcode.TooManyArguments, "54023"}, + {"ObjectNotInPrerequisiteState", pgcode.ObjectNotInPrerequisiteState, "55000"}, + {"ObjectInUse", pgcode.ObjectInUse, "55006"}, + {"CantChangeRuntimeParam", pgcode.CantChangeRuntimeParam, "55P02"}, + {"LockNotAvailable", pgcode.LockNotAvailable, "55P03"}, + {"UnsafeNewEnumValueUsage", pgcode.UnsafeNewEnumValueUsage, "55P04"}, + {"OperatorIntervention", pgcode.OperatorIntervention, "57000"}, + {"QueryCanceled", pgcode.QueryCanceled, "57014"}, + {"AdminShutdown", pgcode.AdminShutdown, "57P01"}, + {"CrashShutdown", pgcode.CrashShutdown, "57P02"}, + {"CannotConnectNow", pgcode.CannotConnectNow, "57P03"}, + {"DatabaseDropped", pgcode.DatabaseDropped, "57P04"}, + {"IdleSessionTimeout", pgcode.IdleSessionTimeout, "57P05"}, + {"SystemError", pgcode.SystemError, "58000"}, + {"IOError", pgcode.IOError, "58030"}, + {"UndefinedFile", pgcode.UndefinedFile, "58P01"}, + {"DuplicateFile", pgcode.DuplicateFile, "58P02"}, + {"FileNameTooLong", pgcode.FileNameTooLong, "58P03"}, + {"SnapshotTooOld", pgcode.SnapshotTooOld, "72000"}, + {"ConfigFileError", pgcode.ConfigFileError, "F0000"}, + {"LockFileExists", pgcode.LockFileExists, "F0001"}, + {"FDWError", pgcode.FDWError, "HV000"}, + {"FDWOutOfMemory", pgcode.FDWOutOfMemory, "HV001"}, + {"FDWDynamicParameterValueNeeded", pgcode.FDWDynamicParameterValueNeeded, "HV002"}, + {"FDWInvalidDataType", pgcode.FDWInvalidDataType, "HV004"}, + {"FDWColumnNameNotFound", pgcode.FDWColumnNameNotFound, "HV005"}, + {"FDWInvalidDataTypeDescriptors", pgcode.FDWInvalidDataTypeDescriptors, "HV006"}, + {"FDWInvalidColumnName", pgcode.FDWInvalidColumnName, "HV007"}, + {"FDWInvalidColumnNumber", pgcode.FDWInvalidColumnNumber, "HV008"}, + {"FDWInvalidUseOfNullPointer", pgcode.FDWInvalidUseOfNullPointer, "HV009"}, + {"FDWInvalidStringFormat", pgcode.FDWInvalidStringFormat, "HV00A"}, + {"FDWInvalidHandle", pgcode.FDWInvalidHandle, "HV00B"}, + {"FDWInvalidOptionIndex", pgcode.FDWInvalidOptionIndex, "HV00C"}, + {"FDWInvalidOptionName", pgcode.FDWInvalidOptionName, "HV00D"}, + {"FDWOptionNameNotFound", pgcode.FDWOptionNameNotFound, "HV00J"}, + {"FDWReplyHandle", pgcode.FDWReplyHandle, "HV00K"}, + {"FDWUnableToCreateExecution", pgcode.FDWUnableToCreateExecution, "HV00L"}, + {"FDWUnableToCreateReply", pgcode.FDWUnableToCreateReply, "HV00M"}, + {"FDWUnableToEstablishConnection", pgcode.FDWUnableToEstablishConnection, "HV00N"}, + {"FDWNoSchemas", pgcode.FDWNoSchemas, "HV00P"}, + {"FDWSchemaNotFound", pgcode.FDWSchemaNotFound, "HV00Q"}, + {"FDWTableNotFound", pgcode.FDWTableNotFound, "HV00R"}, + {"FDWFunctionSequenceError", pgcode.FDWFunctionSequenceError, "HV010"}, + {"FDWTooManyHandles", pgcode.FDWTooManyHandles, "HV014"}, + {"FDWInconsistentDescriptorInformation", pgcode.FDWInconsistentDescriptorInformation, "HV021"}, + {"FDWInvalidAttributeValue", pgcode.FDWInvalidAttributeValue, "HV024"}, + {"FDWInvalidStringLengthOrBufferLength", pgcode.FDWInvalidStringLengthOrBufferLength, "HV090"}, + {"FDWInvalidDescriptorFieldIdentifier", pgcode.FDWInvalidDescriptorFieldIdentifier, "HV091"}, + {"PLpgSQLError", pgcode.PLpgSQLError, "P0000"}, + {"RaiseException", pgcode.RaiseException, "P0001"}, + {"NoDataFound", pgcode.NoDataFound, "P0002"}, + {"TooManyRows", pgcode.TooManyRows, "P0003"}, + {"AssertFailure", pgcode.AssertFailure, "P0004"}, + {"InternalError", pgcode.InternalError, "XX000"}, + {"DataCorrupted", pgcode.DataCorrupted, "XX001"}, + {"IndexCorrupted", pgcode.IndexCorrupted, "XX002"}, + {"InvalidArgumentForXquery", pgcode.InvalidArgumentForXquery, "10608"}, + } + for _, tt := range tests { + if tt.got != tt.want { + t.Errorf("pgcode.%s = %q, want %q", tt.name, tt.got, tt.want) + } + } +} + +// TestIsXxxFunctions verifies each IsXxx function accepts all codes in its class +// and rejects codes from other classes. +func TestIsXxxFunctions(t *testing.T) { + t.Parallel() + + tests := []struct { + fn string + is func(string) bool + members []string + }{ + { + fn: "IsSuccessfulCompletion", + is: pgcode.IsSuccessfulCompletion, + members: []string{"00000"}, + }, + { + fn: "IsWarning", + is: pgcode.IsWarning, + members: []string{"01000", "01003", "01004", "01006", "01007", "01008", "0100C", "01P01"}, + }, + { + fn: "IsNoData", + is: pgcode.IsNoData, + members: []string{"02000", "02001"}, + }, + { + fn: "IsSqlStatementNotYetComplete", + is: pgcode.IsSqlStatementNotYetComplete, + members: []string{"03000"}, + }, + { + fn: "IsConnectionException", + is: pgcode.IsConnectionException, + members: []string{"08000", "08001", "08003", "08004", "08006", "08007", "08P01"}, + }, + { + fn: "IsTriggeredActionException", + is: pgcode.IsTriggeredActionException, + members: []string{"09000"}, + }, + { + fn: "IsFeatureNotSupported", + is: pgcode.IsFeatureNotSupported, + members: []string{"0A000"}, + }, + { + fn: "IsInvalidTransactionInitiation", + is: pgcode.IsInvalidTransactionInitiation, + members: []string{"0B000"}, + }, + { + fn: "IsLocatorException", + is: pgcode.IsLocatorException, + members: []string{"0F000", "0F001"}, + }, + { + fn: "IsInvalidGrantor", + is: pgcode.IsInvalidGrantor, + members: []string{"0L000", "0LP01"}, + }, + { + fn: "IsInvalidRoleSpecification", + is: pgcode.IsInvalidRoleSpecification, + members: []string{"0P000"}, + }, + { + fn: "IsDiagnosticsException", + is: pgcode.IsDiagnosticsException, + members: []string{"0Z000", "0Z002"}, + }, + { + fn: "IsCaseNotFound", + is: pgcode.IsCaseNotFound, + members: []string{"20000"}, + }, + { + fn: "IsCardinalityViolation", + is: pgcode.IsCardinalityViolation, + members: []string{"21000"}, + }, + { + fn: "IsDataException", + is: pgcode.IsDataException, + members: []string{"22000", "22001", "22002", "22003", "22004", "22005", "22007", "22008", "22009", "2200B", "2200C", "2200D", "2200F", "2200G", "2200H", "2200L", "2200M", "2200N", "2200S", "2200T", "22010", "22011", "22012", "22013", "22014", "22015", "22016", "22018", "22019", "2201B", "2201E", "2201F", "2201G", "2201W", "2201X", "22021", "22022", "22023", "22024", "22025", "22026", "22027", "2202E", "2202G", "2202H", "22030", "22031", "22032", "22033", "22034", "22035", "22036", "22037", "22038", "22039", "2203A", "2203B", "2203C", "2203D", "2203E", "2203F", "2203G", "22P01", "22P02", "22P03", "22P04", "22P05", "22P06"}, + }, + { + fn: "IsIntegrityConstraintViolation", + is: pgcode.IsIntegrityConstraintViolation, + members: []string{"23000", "23001", "23502", "23503", "23505", "23514", "23P01"}, + }, + { + fn: "IsInvalidCursorState", + is: pgcode.IsInvalidCursorState, + members: []string{"24000"}, + }, + { + fn: "IsInvalidTransactionState", + is: pgcode.IsInvalidTransactionState, + members: []string{"25000", "25001", "25002", "25003", "25004", "25005", "25006", "25007", "25008", "25P01", "25P02", "25P03", "25P04"}, + }, + { + fn: "IsInvalidSqlStatementName", + is: pgcode.IsInvalidSqlStatementName, + members: []string{"26000"}, + }, + { + fn: "IsTriggeredDataChangeViolation", + is: pgcode.IsTriggeredDataChangeViolation, + members: []string{"27000"}, + }, + { + fn: "IsInvalidAuthorizationSpecification", + is: pgcode.IsInvalidAuthorizationSpecification, + members: []string{"28000", "28P01"}, + }, + { + fn: "IsDependentPrivilegeDescriptorsStillExist", + is: pgcode.IsDependentPrivilegeDescriptorsStillExist, + members: []string{"2B000", "2BP01"}, + }, + { + fn: "IsInvalidTransactionTermination", + is: pgcode.IsInvalidTransactionTermination, + members: []string{"2D000"}, + }, + { + fn: "IsSqlRoutineException", + is: pgcode.IsSqlRoutineException, + members: []string{"2F000", "2F002", "2F003", "2F004", "2F005"}, + }, + { + fn: "IsInvalidCursorName", + is: pgcode.IsInvalidCursorName, + members: []string{"34000"}, + }, + { + fn: "IsExternalRoutineException", + is: pgcode.IsExternalRoutineException, + members: []string{"38000", "38001", "38002", "38003", "38004"}, + }, + { + fn: "IsExternalRoutineInvocationException", + is: pgcode.IsExternalRoutineInvocationException, + members: []string{"39000", "39001", "39004", "39P01", "39P02", "39P03"}, + }, + { + fn: "IsSavepointException", + is: pgcode.IsSavepointException, + members: []string{"3B000", "3B001"}, + }, + { + fn: "IsInvalidCatalogName", + is: pgcode.IsInvalidCatalogName, + members: []string{"3D000"}, + }, + { + fn: "IsInvalidSchemaName", + is: pgcode.IsInvalidSchemaName, + members: []string{"3F000"}, + }, + { + fn: "IsTransactionRollback", + is: pgcode.IsTransactionRollback, + members: []string{"40000", "40001", "40002", "40003", "40P01"}, + }, + { + fn: "IsSyntaxErrorOrAccessRuleViolation", + is: pgcode.IsSyntaxErrorOrAccessRuleViolation, + members: []string{"42000", "42501", "42601", "42602", "42611", "42622", "42701", "42702", "42703", "42704", "42710", "42712", "42723", "42725", "42803", "42804", "42809", "42830", "42846", "42883", "428C9", "42939", "42P01", "42P02", "42P03", "42P04", "42P05", "42P06", "42P07", "42P08", "42P09", "42P10", "42P11", "42P12", "42P13", "42P14", "42P15", "42P16", "42P17", "42P18", "42P19", "42P20", "42P21", "42P22"}, + }, + { + fn: "IsWithCheckOptionViolation", + is: pgcode.IsWithCheckOptionViolation, + members: []string{"44000"}, + }, + { + fn: "IsInsufficientResources", + is: pgcode.IsInsufficientResources, + members: []string{"53000", "53100", "53200", "53300", "53400"}, + }, + { + fn: "IsProgramLimitExceeded", + is: pgcode.IsProgramLimitExceeded, + members: []string{"54000", "54001", "54011", "54023"}, + }, + { + fn: "IsObjectNotInPrerequisiteState", + is: pgcode.IsObjectNotInPrerequisiteState, + members: []string{"55000", "55006", "55P02", "55P03", "55P04"}, + }, + { + fn: "IsOperatorIntervention", + is: pgcode.IsOperatorIntervention, + members: []string{"57000", "57014", "57P01", "57P02", "57P03", "57P04", "57P05"}, + }, + { + fn: "IsSystemError", + is: pgcode.IsSystemError, + members: []string{"58000", "58030", "58P01", "58P02", "58P03"}, + }, + { + fn: "IsSnapshotFailure", + is: pgcode.IsSnapshotFailure, + members: []string{"72000"}, + }, + { + fn: "IsConfigurationFileError", + is: pgcode.IsConfigurationFileError, + members: []string{"F0000", "F0001"}, + }, + { + fn: "IsForeignDataWrapperError", + is: pgcode.IsForeignDataWrapperError, + members: []string{"HV000", "HV001", "HV002", "HV004", "HV005", "HV006", "HV007", "HV008", "HV009", "HV00A", "HV00B", "HV00C", "HV00D", "HV00J", "HV00K", "HV00L", "HV00M", "HV00N", "HV00P", "HV00Q", "HV00R", "HV010", "HV014", "HV021", "HV024", "HV090", "HV091"}, + }, + { + fn: "IsPl", + is: pgcode.IsPl, + members: []string{"P0000", "P0001", "P0002", "P0003", "P0004"}, + }, + { + fn: "IsInternalError", + is: pgcode.IsInternalError, + members: []string{"XX000", "XX001", "XX002"}, + }, + { + fn: "IsXqueryError", + is: pgcode.IsXqueryError, + members: []string{"10608"}, + }, + } + + // Build a set of all codes per function for cross-rejection testing. + for _, tt := range tests { + for _, code := range tt.members { + if !tt.is(code) { + t.Errorf("%s(%q) = false, want true", tt.fn, code) + } + } + } + + // Each function must reject codes that belong to other classes. + for i, tt := range tests { + for j, other := range tests { + if i == j { + continue + } + for _, code := range other.members { + if tt.is(code) { + t.Errorf("%s(%q) = true, want false (code belongs to %s)", tt.fn, code, other.fn) + } + } + } + } +} + +// TestNameRoundtrip verifies Name() returns the constant name for every code. +func TestNameRoundtrip(t *testing.T) { + t.Parallel() + + tests := []struct { + code string + want string + }{ + {"00000", "SuccessfulCompletion"}, + {"01000", "Warning"}, + {"01003", "NullValueEliminatedInSetFunction"}, + {"01004", "StringDataRightTruncation"}, + {"01006", "PrivilegeNotRevoked"}, + {"01007", "PrivilegeNotGranted"}, + {"01008", "ImplicitZeroBitPadding"}, + {"0100C", "DynamicResultSetsReturned"}, + {"01P01", "DeprecatedFeature"}, + {"02000", "NoData"}, + {"02001", "NoAdditionalDynamicResultSetsReturned"}, + {"03000", "SQLStatementNotYetComplete"}, + {"08000", "ConnectionException"}, + {"08001", "SqlclientUnableToEstablishSqlconnection"}, + {"08003", "ConnectionDoesNotExist"}, + {"08004", "SqlserverRejectedEstablishmentOfSqlconnection"}, + {"08006", "ConnectionFailure"}, + {"08007", "TransactionResolutionUnknown"}, + {"08P01", "ProtocolViolation"}, + {"09000", "TriggeredActionException"}, + {"0A000", "FeatureNotSupported"}, + {"0B000", "InvalidTransactionInitiation"}, + {"0F000", "LocatorException"}, + {"0F001", "InvalidLocatorSpecification"}, + {"0L000", "InvalidGrantor"}, + {"0LP01", "InvalidGrantOperation"}, + {"0P000", "InvalidRoleSpecification"}, + {"0Z000", "DiagnosticsException"}, + {"0Z002", "StackedDiagnosticsAccessedWithoutActiveHandler"}, + {"20000", "CaseNotFound"}, + {"21000", "CardinalityViolation"}, + {"22000", "DataException"}, + {"22001", "StringDataRightTruncation"}, + {"22002", "NullValueNoIndicatorParameter"}, + {"22003", "NumericValueOutOfRange"}, + {"22004", "NullValueNotAllowed"}, + {"22005", "ErrorInAssignment"}, + {"22007", "InvalidDatetimeFormat"}, + {"22008", "DatetimeFieldOverflow"}, + {"22009", "InvalidTimeZoneDisplacementValue"}, + {"2200B", "EscapeCharacterConflict"}, + {"2200C", "InvalidUseOfEscapeCharacter"}, + {"2200D", "InvalidEscapeOctet"}, + {"2200F", "ZeroLengthCharacterString"}, + {"2200G", "MostSpecificTypeMismatch"}, + {"2200H", "SequenceGeneratorLimitExceeded"}, + {"2200L", "NotAnXMLDocument"}, + {"2200M", "InvalidXMLDocument"}, + {"2200N", "InvalidXMLContent"}, + {"2200S", "InvalidXMLComment"}, + {"2200T", "InvalidXMLProcessingInstruction"}, + {"22010", "InvalidIndicatorParameterValue"}, + {"22011", "SubstringError"}, + {"22012", "DivisionByZero"}, + {"22013", "InvalidPrecedingOrFollowingSize"}, + {"22014", "InvalidArgumentForNtileFunction"}, + {"22015", "IntervalFieldOverflow"}, + {"22016", "InvalidArgumentForNthValueFunction"}, + {"22018", "InvalidCharacterValueForCast"}, + {"22019", "InvalidEscapeCharacter"}, + {"2201B", "InvalidRegularExpression"}, + {"2201E", "InvalidArgumentForLogarithm"}, + {"2201F", "InvalidArgumentForPowerFunction"}, + {"2201G", "InvalidArgumentForWidthBucketFunction"}, + {"2201W", "InvalidRowCountInLimitClause"}, + {"2201X", "InvalidRowCountInResultOffsetClause"}, + {"22021", "CharacterNotInRepertoire"}, + {"22022", "IndicatorOverflow"}, + {"22023", "InvalidParameterValue"}, + {"22024", "UnterminatedCString"}, + {"22025", "InvalidEscapeSequence"}, + {"22026", "StringDataLengthMismatch"}, + {"22027", "TrimError"}, + {"2202E", "ArraySubscriptError"}, + {"2202G", "InvalidTablesampleRepeat"}, + {"2202H", "InvalidTablesampleArgument"}, + {"22030", "DuplicateJSONObjectKeyValue"}, + {"22031", "InvalidArgumentForSQLJSONDatetimeFunction"}, + {"22032", "InvalidJSONText"}, + {"22033", "InvalidSQLJSONSubscript"}, + {"22034", "MoreThanOneSQLJSONItem"}, + {"22035", "NoSQLJSONItem"}, + {"22036", "NonNumericSQLJSONItem"}, + {"22037", "NonUniqueKeysInAJSONObject"}, + {"22038", "SingletonSQLJSONItemRequired"}, + {"22039", "SQLJSONArrayNotFound"}, + {"2203A", "SQLJSONMemberNotFound"}, + {"2203B", "SQLJSONNumberNotFound"}, + {"2203C", "SQLJSONObjectNotFound"}, + {"2203D", "TooManyJSONArrayElements"}, + {"2203E", "TooManyJSONObjectMembers"}, + {"2203F", "SQLJSONScalarRequired"}, + {"2203G", "SQLJSONItemCannotBeCastToTargetType"}, + {"22P01", "FloatingPointException"}, + {"22P02", "InvalidTextRepresentation"}, + {"22P03", "InvalidBinaryRepresentation"}, + {"22P04", "BadCopyFileFormat"}, + {"22P05", "UntranslatableCharacter"}, + {"22P06", "NonstandardUseOfEscapeCharacter"}, + {"23000", "IntegrityConstraintViolation"}, + {"23001", "RestrictViolation"}, + {"23502", "NotNullViolation"}, + {"23503", "ForeignKeyViolation"}, + {"23505", "UniqueViolation"}, + {"23514", "CheckViolation"}, + {"23P01", "ExclusionViolation"}, + {"24000", "InvalidCursorState"}, + {"25000", "InvalidTransactionState"}, + {"25001", "ActiveSQLTransaction"}, + {"25002", "BranchTransactionAlreadyActive"}, + {"25003", "InappropriateAccessModeForBranchTransaction"}, + {"25004", "InappropriateIsolationLevelForBranchTransaction"}, + {"25005", "NoActiveSQLTransactionForBranchTransaction"}, + {"25006", "ReadOnlySQLTransaction"}, + {"25007", "SchemaAndDataStatementMixingNotSupported"}, + {"25008", "HeldCursorRequiresSameIsolationLevel"}, + {"25P01", "NoActiveSQLTransaction"}, + {"25P02", "InFailedSQLTransaction"}, + {"25P03", "IdleInTransactionSessionTimeout"}, + {"25P04", "TransactionTimeout"}, + {"26000", "InvalidSQLStatementName"}, + {"27000", "TriggeredDataChangeViolation"}, + {"28000", "InvalidAuthorizationSpecification"}, + {"28P01", "InvalidPassword"}, + {"2B000", "DependentPrivilegeDescriptorsStillExist"}, + {"2BP01", "DependentObjectsStillExist"}, + {"2D000", "InvalidTransactionTermination"}, + {"2F000", "SQLRoutineException"}, + {"2F002", "ModifyingSQLDataNotPermitted"}, + {"2F003", "ProhibitedSQLStatementAttempted"}, + {"2F004", "ReadingSQLDataNotPermitted"}, + {"2F005", "FunctionExecutedNoReturnStatement"}, + {"34000", "InvalidCursorName"}, + {"38000", "ExternalRoutineException"}, + {"38001", "ContainingSQLNotPermitted"}, + {"38002", "ModifyingSQLDataNotPermitted"}, + {"38003", "ProhibitedSQLStatementAttempted"}, + {"38004", "ReadingSQLDataNotPermitted"}, + {"39000", "ExternalRoutineInvocationException"}, + {"39001", "InvalidSQLStateReturned"}, + {"39004", "NullValueNotAllowed"}, + {"39P01", "TriggerProtocolViolated"}, + {"39P02", "SRFProtocolViolated"}, + {"39P03", "EventTriggerProtocolViolated"}, + {"3B000", "SavepointException"}, + {"3B001", "InvalidSavepointSpecification"}, + {"3D000", "InvalidCatalogName"}, + {"3F000", "InvalidSchemaName"}, + {"40000", "TransactionRollback"}, + {"40001", "SerializationFailure"}, + {"40002", "TransactionIntegrityConstraintViolation"}, + {"40003", "StatementCompletionUnknown"}, + {"40P01", "DeadlockDetected"}, + {"42000", "SyntaxErrorOrAccessRuleViolation"}, + {"42501", "InsufficientPrivilege"}, + {"42601", "SyntaxError"}, + {"42602", "InvalidName"}, + {"42611", "InvalidColumnDefinition"}, + {"42622", "NameTooLong"}, + {"42701", "DuplicateColumn"}, + {"42702", "AmbiguousColumn"}, + {"42703", "UndefinedColumn"}, + {"42704", "UndefinedObject"}, + {"42710", "DuplicateObject"}, + {"42712", "DuplicateAlias"}, + {"42723", "DuplicateFunction"}, + {"42725", "AmbiguousFunction"}, + {"42803", "GroupingError"}, + {"42804", "DatatypeMismatch"}, + {"42809", "WrongObjectType"}, + {"42830", "InvalidForeignKey"}, + {"42846", "CannotCoerce"}, + {"42883", "UndefinedFunction"}, + {"428C9", "GeneratedAlways"}, + {"42939", "ReservedName"}, + {"42P01", "UndefinedTable"}, + {"42P02", "UndefinedParameter"}, + {"42P03", "DuplicateCursor"}, + {"42P04", "DuplicateDatabase"}, + {"42P05", "DuplicatePreparedStatement"}, + {"42P06", "DuplicateSchema"}, + {"42P07", "DuplicateTable"}, + {"42P08", "AmbiguousParameter"}, + {"42P09", "AmbiguousAlias"}, + {"42P10", "InvalidColumnReference"}, + {"42P11", "InvalidCursorDefinition"}, + {"42P12", "InvalidDatabaseDefinition"}, + {"42P13", "InvalidFunctionDefinition"}, + {"42P14", "InvalidPreparedStatementDefinition"}, + {"42P15", "InvalidSchemaDefinition"}, + {"42P16", "InvalidTableDefinition"}, + {"42P17", "InvalidObjectDefinition"}, + {"42P18", "IndeterminateDatatype"}, + {"42P19", "InvalidRecursion"}, + {"42P20", "WindowingError"}, + {"42P21", "CollationMismatch"}, + {"42P22", "IndeterminateCollation"}, + {"44000", "WithCheckOptionViolation"}, + {"53000", "InsufficientResources"}, + {"53100", "DiskFull"}, + {"53200", "OutOfMemory"}, + {"53300", "TooManyConnections"}, + {"53400", "ConfigurationLimitExceeded"}, + {"54000", "ProgramLimitExceeded"}, + {"54001", "StatementTooComplex"}, + {"54011", "TooManyColumns"}, + {"54023", "TooManyArguments"}, + {"55000", "ObjectNotInPrerequisiteState"}, + {"55006", "ObjectInUse"}, + {"55P02", "CantChangeRuntimeParam"}, + {"55P03", "LockNotAvailable"}, + {"55P04", "UnsafeNewEnumValueUsage"}, + {"57000", "OperatorIntervention"}, + {"57014", "QueryCanceled"}, + {"57P01", "AdminShutdown"}, + {"57P02", "CrashShutdown"}, + {"57P03", "CannotConnectNow"}, + {"57P04", "DatabaseDropped"}, + {"57P05", "IdleSessionTimeout"}, + {"58000", "SystemError"}, + {"58030", "IOError"}, + {"58P01", "UndefinedFile"}, + {"58P02", "DuplicateFile"}, + {"58P03", "FileNameTooLong"}, + {"72000", "SnapshotTooOld"}, + {"F0000", "ConfigFileError"}, + {"F0001", "LockFileExists"}, + {"HV000", "FDWError"}, + {"HV001", "FDWOutOfMemory"}, + {"HV002", "FDWDynamicParameterValueNeeded"}, + {"HV004", "FDWInvalidDataType"}, + {"HV005", "FDWColumnNameNotFound"}, + {"HV006", "FDWInvalidDataTypeDescriptors"}, + {"HV007", "FDWInvalidColumnName"}, + {"HV008", "FDWInvalidColumnNumber"}, + {"HV009", "FDWInvalidUseOfNullPointer"}, + {"HV00A", "FDWInvalidStringFormat"}, + {"HV00B", "FDWInvalidHandle"}, + {"HV00C", "FDWInvalidOptionIndex"}, + {"HV00D", "FDWInvalidOptionName"}, + {"HV00J", "FDWOptionNameNotFound"}, + {"HV00K", "FDWReplyHandle"}, + {"HV00L", "FDWUnableToCreateExecution"}, + {"HV00M", "FDWUnableToCreateReply"}, + {"HV00N", "FDWUnableToEstablishConnection"}, + {"HV00P", "FDWNoSchemas"}, + {"HV00Q", "FDWSchemaNotFound"}, + {"HV00R", "FDWTableNotFound"}, + {"HV010", "FDWFunctionSequenceError"}, + {"HV014", "FDWTooManyHandles"}, + {"HV021", "FDWInconsistentDescriptorInformation"}, + {"HV024", "FDWInvalidAttributeValue"}, + {"HV090", "FDWInvalidStringLengthOrBufferLength"}, + {"HV091", "FDWInvalidDescriptorFieldIdentifier"}, + {"P0000", "PLpgSQLError"}, + {"P0001", "RaiseException"}, + {"P0002", "NoDataFound"}, + {"P0003", "TooManyRows"}, + {"P0004", "AssertFailure"}, + {"XX000", "InternalError"}, + {"XX001", "DataCorrupted"}, + {"XX002", "IndexCorrupted"}, + {"10608", "InvalidArgumentForXquery"}, + } + for _, tt := range tests { + if got := pgcode.Name(tt.code); got != tt.want { + t.Errorf("Name(%q) = %q, want %q", tt.code, got, tt.want) + } + } +} + +// TestNameUnknown verifies Name() returns empty string for unknown codes. +func TestNameUnknown(t *testing.T) { + unknown := []string{"", "99999", "ZZZZZ", "00001"} + for _, code := range unknown { + if got := pgcode.Name(code); got != "" { + t.Errorf("Name(%q) = %q, want empty string", code, got) + } + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..98f2908 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/b0r1ssh/pgcode + +go 1.22