Skip to content

DefaultSqlErrorExtractor class

namespace: Serenity.Services.SqlErrors   assembly: Serenity.Net.Services

Default ISqlErrorExtractor that recognizes primary key, unique, foreign key and not null constraint violations for common database providers without referencing any provider specific package.

public class DefaultSqlErrorExtractor : ISqlErrorExtractor

Public Members

name description
DefaultSqlErrorExtractor() The default constructor.
Extract(…)

Protected Members

name description
virtual ClassifyFromMessage(…) Tries to classify the constraint violation type from the exception message. This is a fallback for exceptions that do not expose an error number or SQL state, and only knows the English message formats. Override to support other languages.
virtual Extract(…) Extracts constraint violation information from a database exception.
virtual GetErrorNumber(…) Tries to get the provider error number from the exception using reflection.
virtual GetErrorType(…) Determines the constraint violation type from the SQL state and error number, falling back to the exception message only when neither is available.
virtual GetServerType(…) Tries to determine the ServerType from the exception type without referencing provider specific assemblies.
virtual ParseErrorInfo(…) Tries to parse table, column, constraint and key value names from the exception message. Only stable/known culture formats are matched; other languages may leave the names empty, in which case a generic message should be used.
static readonly SqlServerMessageRegexes Regexes generated from SQL Server sys.messages for the handled constraint violation message ids (515, 547, 2601, 2627), one per language. Named groups: table, column, constraint, value.
static DoubleQuotedConstraintRegex()
static FirebirdConstraintRegex()
static FirebirdTableRegex()
static MatchAny(…) Returns the first successful match from the passed regex array, or null.
static MySqlColumnsRegex()
static MySqlKeyRegex()
static MySqlReferencedTableRegex()
static OracleConstraintRegex()
static ParseServerType(…) Parses a server type name, e.g. from ServerType, returning null if it is not a known ServerType.
static PostgresColumnsRegex()
static PostgresForeignKeyOnTableRegex()
static PostgresReferencedTableRegex()
static PostgresTableRegex()
static SingleQuotedConstraintRegex()
static SqliteColumnsRegex()
static SqlServerForeignKeyRegex()
static SqlServerKeyValueRegex()
static SqlServerObjectRegex()

Remarks

Error types are determined primarily from language independent error numbers and SQL state codes. Table, column and constraint names are only extracted from the exception message where the message format is stable (e.g. SQLite) or matches one of the culture specific patterns. Override ParseErrorInfo to support additional languages. When names cannot be determined, SqlErrorInfo falls back to a generic message.

See Also