Skip to content

Commit a008437

Browse files
committed
Parse Notice/Error SQLSTATE codes
The enum is stuck inside of an extra module due to rust-lang/rust#4375.
1 parent f392d6c commit a008437

File tree

4 files changed

+356
-14
lines changed

4 files changed

+356
-14
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUSTFLAGS += -L. --cfg debug -Z debug-info
44
.PHONY: all
55
all: postgres.dummy
66

7-
postgres.dummy: src/lib.rs src/message.rs src/types.rs
7+
postgres.dummy: src/lib.rs src/message.rs src/types.rs src/error.rs
88
$(RUSTC) $(RUSTFLAGS) --lib src/lib.rs --out-dir .
99
touch $@
1010

src/error.rs

Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
macro_rules! make_errors(
2+
($($code:pat => $error:ident),+) => (
3+
// TODO: Get rid of this module when mozilla/rust#4375 is fixed
4+
mod hack {
5+
#[deriving(ToStr, Eq)]
6+
pub enum PostgresSqlState {
7+
$($error),+ ,
8+
UnknownSqlState(~str)
9+
}
10+
11+
impl FromStr for PostgresSqlState {
12+
fn from_str(s: &str) -> Option<PostgresSqlState> {
13+
Some(match s {
14+
$($code => $error),+ ,
15+
state => UnknownSqlState(state.to_owned())
16+
})
17+
}
18+
}
19+
}
20+
)
21+
)
22+
23+
// From http://www.postgresql.org/docs/9.2/static/errcodes-appendix.html
24+
make_errors!(
25+
// Class 00 — Successful Completion
26+
"00000" => SuccessfulCompletion,
27+
28+
// Class 01 — Warning
29+
"01000" => Warning,
30+
"0100C" => DynamicResultSetsReturned,
31+
"01008" => ImplicitZeroBitPadding,
32+
"01003" => NullValueEliminatedInSetFunction,
33+
"01007" => PrivilegeNotGranted,
34+
"01006" => PrivilegeNotRevoked,
35+
"01004" => StringDataRightTruncationWarning,
36+
"01P01" => DeprecatedFeature,
37+
38+
// Class 02 — No Data
39+
"02000" => NoData,
40+
"02001" => NoAdditionalDynamicResultSetsReturned,
41+
42+
// Class 03 — SQL Statement Not Yet Complete
43+
"03000" => SqlStatementNotYetComplete,
44+
45+
// Class 08 — Connection Exception
46+
"08000" => ConnectionException,
47+
"08003" => ConnectionDoesNotExist,
48+
"08006" => ConnectionFailure,
49+
"08001" => SqlclientUnableToEstablishSqlconnection,
50+
"08004" => SqlserverRejectedEstablishmentOfSqlconnection,
51+
"08007" => TransactionResolutionUnknown,
52+
"08P01" => ProtocolViolation,
53+
54+
// Class 09 — Triggered Action Exception
55+
"09000" => TriggeredActionException,
56+
57+
// Class 0A — Feature Not Supported
58+
"0A000" => FeatureNotSupported,
59+
60+
// Class 0B — Invalid Transaction Initiation
61+
"0B000" => InvalidTransactionInitiation,
62+
63+
// Class 0F — Locator Exception
64+
"0F000" => LocatorException,
65+
"0F001" => InvalidLocatorException,
66+
67+
// Class 0L — Invalid Grantor
68+
"0L000" => InvalidGrantor,
69+
"0LP01" => InvalidGrantOperation,
70+
71+
// Class 0P — Invalid Role Specification
72+
"0P000" => InvalidRoleSpecification,
73+
74+
// Class 0Z — Diagnostics Exception
75+
"0Z000" => DiagnosticsException,
76+
"0Z002" => StackedDiagnosticsAccessedWithoutActiveHandler,
77+
78+
// Class 20 — Case Not Found
79+
"20000" => CaseNotFound,
80+
81+
// Class 21 — Cardinality Violation
82+
"21000" => CardinalityViolation,
83+
84+
// Class 22 — Data Exception
85+
"22000" => DataException,
86+
"2202E" => ArraySubscriptError,
87+
"22021" => CharacterNotInRepertoire,
88+
"22008" => DatetimeFieldOverflow,
89+
"22012" => DivisionByZero,
90+
"22005" => ErrorInAssignment,
91+
"2200B" => EscapeCharacterConflict,
92+
"22022" => IndicatorOverflow,
93+
"22015" => IntervalFieldOverflow,
94+
"2201E" => InvalidArgumentForLogarithm,
95+
"22014" => InvalidArgumentForNtileFunction,
96+
"22016" => InvalidArgumentForNthValueFunction,
97+
"2201F" => InvalidArgumentForPowerFunction,
98+
"2201G" => InvalidArgumentForWidthBucketFunction,
99+
"22018" => InvalidCharacterValueForCast,
100+
"22007" => InvalidDatetimeFormat,
101+
"22019" => InvalidEscapeCharacter,
102+
"2200D" => InvalidEscapeOctet,
103+
"22025" => InvalidEscapeSequence,
104+
"22P06" => NonstandardUseOfEscapeCharacter,
105+
"22010" => InvalidIndicatorParameterValue,
106+
"22023" => InvalidParameterValue,
107+
"2201B" => InvalidRegularExpression,
108+
"2201W" => InvalidRowCountInLimitClause,
109+
"2201X" => InvalidRowCountInResultOffsetClause,
110+
"22009" => InvalidTimeZoneDisplacementValue,
111+
"2200C" => InvalidUseOfEscapeCharacter,
112+
"2200G" => MostSpecificTypeMismatch,
113+
"22004" => NullValueNotAllowedData,
114+
"22002" => NullValueNoIndicatorParameter,
115+
"22003" => NumericValueOutOfRange,
116+
"22026" => StringDataLengthMismatch,
117+
"22001" => StringDataRightTruncationException,
118+
"22011" => SubstringError,
119+
"22027" => TrimError,
120+
"22024" => UnterminatedCString,
121+
"2200F" => ZeroLengthCharacterString,
122+
"22P01" => FloatingPointException,
123+
"22P02" => InvalidTextRepresentation,
124+
"22P03" => InvalidBinaryRepresentation,
125+
"22P04" => BadCopyFileFormat,
126+
"22P05" => UntranslatableCharacter,
127+
"2200L" => NotAnXmlDocument,
128+
"2200M" => InvalidXmlDocument,
129+
"2200N" => InvalidXmlContent,
130+
"2200S" => InvalidXmlComment,
131+
"2200T" => InvalidXmlProcessingInstruction,
132+
133+
// Class 23 — Integrity Constraint Violation
134+
"23000" => IntegrityConstraintViolation,
135+
"23001" => RestrictViolation,
136+
"23502" => NotNullViolation,
137+
"23503" => ForeignKeyViolation,
138+
"23505" => UniqueViolation,
139+
"23514" => CheckViolation,
140+
"32P01" => ExclusionViolation,
141+
142+
// Class 24 — Invalid Cursor State
143+
"24000" => InvalidCursorState,
144+
145+
// Class 25 — Invalid Transaction State
146+
"25000" => InvalidTransactionState,
147+
"25001" => ActiveSqlTransaction,
148+
"25002" => BranchTransactionAlreadyActive,
149+
"25008" => HeldCursorRequiresSameIsolationLevel,
150+
"25003" => InappropriateAccessModeForBranchTransaction,
151+
"25004" => InappropriateIsolationLevelForBranchTransaction,
152+
"25005" => NoActiveSqlTransactionForBranchTransaction,
153+
"25006" => ReadOnlySqlTransaction,
154+
"25007" => SchemaAndDataStatementMixingNotSupported,
155+
"25P01" => NoActiveSqlTransaction,
156+
"25P02" => InFailedSqlTransaction,
157+
158+
// Class 26 — Invalid SQL Statement Name
159+
"26000" => InvalidSqlStatementName,
160+
161+
// Class 27 — Triggered Data Change Violation
162+
"27000" => TriggeredDataChangeViolation,
163+
164+
// Class 28 — Invalid Authorization Specification
165+
"28000" => InvalidAuthorizationSpecification,
166+
"28P01" => InvalidPassword,
167+
168+
// Class 2B — Dependent Privilege Descriptors Still Exist
169+
"2B000" => DependentPrivilegeDescriptorsStillExist,
170+
"2BP01" => DependentObjectsStillExist,
171+
172+
// Class 2D — Invalid Transaction Termination
173+
"2D000" => InvalidTransactionTermination,
174+
175+
// Class 2F — SQL Routine Exception
176+
"2F000" => SqlRoutineException,
177+
"2F005" => FunctionExecutedNoReturnStatement,
178+
"2F002" => ModifyingSqlDataNotPermittedSqlRoutine,
179+
"2F003" => ProhibitedSqlStatementAttemptedSqlRoutine,
180+
"2F004" => ReadingSqlDataNotPermittedSqlRoutine,
181+
182+
// Class 34 — Invalid Cursor Name
183+
"34000" => InvalidCursorName,
184+
185+
// Class 38 — External Routine Exception
186+
"38000" => ExternalRoutineException,
187+
"38001" => ContainingSqlNotPermitted,
188+
"38002" => ModifyingSqlDataNotPermittedExternalRoutine,
189+
"38003" => ProhibitedSqlStatementAttemptedExternalRoutine,
190+
"38004" => ReadingSqlDataNotPermittedExternalRoutine,
191+
192+
193+
// Class 39 — External Routine Invocation Exception
194+
"39000" => ExternalRoutineInvocationException,
195+
"39001" => InvalidSqlstateReturned,
196+
"39004" => NullValueNotAllowedExternalRoutine,
197+
"39P01" => TriggerProtocolViolated,
198+
"39P02" => SrfProtocolViolated,
199+
200+
// Class 3B — Savepoint Exception
201+
"3B000" => SavepointException,
202+
"3B001" => InvalidSavepointException,
203+
204+
// Class 3D — Invalid Catalog Name
205+
"3D000" => InvalidCatalogName,
206+
207+
// Class 3F — Invalid Schema Name
208+
"3F000" => InvalidSchemaName,
209+
210+
// Class 40 — Transaction Rollback
211+
"40000" => TransactionRollback,
212+
"40002" => TransactionIntegrityConstraintViolation,
213+
"40001" => SerializationFailure,
214+
"40003" => StatementCompletionUnknown,
215+
"40P01" => DeadlockDetected,
216+
217+
// Class 42 — Syntax Error or Access Rule Violation
218+
"42000" => SyntaxErrorOrAccessRuleViolation,
219+
"42601" => SyntaxError,
220+
"42501" => InsufficientPrivilege,
221+
"42846" => CannotCoerce,
222+
"42803" => GroupingError,
223+
"42P20" => WindowingError,
224+
"42P19" => InvalidRecursion,
225+
"42830" => InvalidForeignKey,
226+
"42602" => InvalidName,
227+
"42622" => NameTooLong,
228+
"42939" => ReservedName,
229+
"42804" => DatatypeMismatch,
230+
"42P18" => IndeterminateDatatype,
231+
"42P21" => CollationMismatch,
232+
"42P22" => IndeterminateCollation,
233+
"42809" => WrongObjectType,
234+
"42703" => UndefinedColumn,
235+
"42883" => UndefinedFunction,
236+
"42P01" => UndefinedTable,
237+
"42P02" => UndefinedParameter,
238+
"42704" => UndefinedObject,
239+
"42701" => DuplicateColumn,
240+
"42P03" => DuplicateCursor,
241+
"42P04" => DuplicateDatabase,
242+
"42723" => DuplicateFunction,
243+
"42P05" => DuplicatePreparedStatement,
244+
"42P06" => DuplicateSchema,
245+
"42P07" => DuplicateTable,
246+
"42712" => DuplicateAliaas,
247+
"42710" => DuplicateObject,
248+
"42702" => AmbiguousColumn,
249+
"42725" => AmbiguousFunction,
250+
"42P08" => AmbiguousParameter,
251+
"42P09" => AmbiguousAlias,
252+
"42P10" => InvalidColumnReference,
253+
"42611" => InvalidColumnDefinition,
254+
"42P11" => InvalidCursorDefinition,
255+
"42P12" => InvalidDatabaseDefinition,
256+
"42P13" => InvalidFunctionDefinition,
257+
"42P14" => InvalidPreparedStatementDefinition,
258+
"42P15" => InvalidSchemaDefinition,
259+
"42P16" => InvalidTableDefinition,
260+
"42P17" => InvalidObjectDefinition,
261+
262+
// Class 44 — WITH CHECK OPTION Violation
263+
"44000" => WithCheckOptionViolation,
264+
265+
// Class 53 — Insufficient Resources
266+
"53000" => InsufficientResources,
267+
"53100" => DiskFull,
268+
"53200" => OutOfMemory,
269+
"53300" => TooManyConnections,
270+
"53400" => ConfigurationLimitExceeded,
271+
272+
// Class 54 — Program Limit Exceeded
273+
"54000" => ProgramLimitExceeded,
274+
"54001" => StatementTooComplex,
275+
"54011" => TooManyColumns,
276+
"54023" => TooManyArguments,
277+
278+
// Class 55 — Object Not In Prerequisite State
279+
"55000" => ObjectNotInPrerequisiteState,
280+
"55006" => ObjectInUse,
281+
"55P02" => CantChangeRuntimeParam,
282+
"55P03" => LockNotAvailable,
283+
284+
// Class 57 — Operator Intervention
285+
"57000" => OperatorIntervention,
286+
"57014" => QueryCanceled,
287+
"57P01" => AdminShutdown,
288+
"57P02" => CrashShutdown,
289+
"57P03" => CannotConnectNow,
290+
"57P04" => DatabaseDropped,
291+
292+
// Class 58 — System Error
293+
"58000" => SystemError,
294+
"58030" => IoError,
295+
"58P01" => UndefinedFile,
296+
"58P02" => DuplicateFile,
297+
298+
// Class F0 — Configuration File Error
299+
"F0000" => ConfigFileError,
300+
"F0001" => LockFileExists,
301+
302+
// Class HV — Foreign Data Wrapper Error (SQL/MED)
303+
"HV000" => FdwError,
304+
"HV005" => FdwColumnNameNotFound,
305+
"HV002" => FdwDynamicParameterValueNeeded,
306+
"HV010" => FdwFunctionSequenceError,
307+
"HV021" => FdwInconsistentDescriptorInformation,
308+
"HV024" => FdwInvalidAttributeValue,
309+
"HV007" => FdwInvalidColumnName,
310+
"HV008" => FdwInvalidColumnNumber,
311+
"HV004" => FdwInvalidDataType,
312+
"HV006" => FdwInvalidDataTypeDescriptors,
313+
"HV091" => FdwInvalidDescriptorFieldIdentifier,
314+
"HV00B" => FdwInvalidHandle,
315+
"HV00C" => FdwInvalidOptionIndex,
316+
"HV00D" => FdwInvalidOptionName,
317+
"HV090" => FdwInvalidStringLengthOrBufferLength,
318+
"HV00A" => FdwInvalidStringFormat,
319+
"HV009" => FdwInvalidUseOfNullPointer,
320+
"HV014" => FdwTooManyHandles,
321+
"HV001" => FdwOutOfMemory,
322+
"HV00P" => FdwNoSchemas,
323+
"HV00J" => FdwOptionNameNotFound,
324+
"HV00K" => FdwReplyHandle,
325+
"HV00Q" => FdwSchemaNotFound,
326+
"HV00R" => FdwTableNotFound,
327+
"HV00L" => FdwUnableToCreateExcecution,
328+
"HV00M" => FdwUnableToCreateReply,
329+
"HV00N" => FdwUnableToEstablishConnection,
330+
331+
// Class P0 — PL/pgSQL Error
332+
"P0000" => PlpgsqlError,
333+
"P0001" => RaiseException,
334+
"P0002" => NoDataFound,
335+
"P0003" => TooManyRows,
336+
337+
// Class XX — Internal Error
338+
"XX000" => InternalError,
339+
"XX001" => DataCorrupted,
340+
"XX002" => IndexCorrupted
341+
)
342+

0 commit comments

Comments
 (0)