from collections import ChainMap

from py4jdbc.exceptions import dbapi2


exc_classes = ChainMap(sqlstate.exc_classes).new_child()


class _VCodeAgg(dbapi2.CodeAggregatorMeta):
    exc_classes = exc_classes


class VerticaMultinodeError(dbapi2.DatabaseError, metaclass=_VCodeAgg):
    code = 'V1'

class VerticaMiscellaneousError(dbapi2.DatabaseError, metaclass=_VCodeAgg):
    code = 'V2'

class ConfigurationFileError(dbapi2.DatabaseError, metaclass=_VCodeAgg):
    code = 'VC'

class DbDesignerError(dbapi2.DatabaseError, metaclass=_VCodeAgg):
    code = 'VD'

class UserProcedureError(dbapi2.DatabaseError, metaclass=_VCodeAgg):
    code = 'VP'

class InternalError(dbapi2.DatabaseError, metaclass=_VCodeAgg):
    code = 'VX'


messages = (
    ('00000', 'ERRCODE_SUCCESSFUL_COMPLETION'),
    ('01000', 'ERRCODE_WARNING'),
    ('01003', 'ERRCODE_WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION'),
    ('01004', 'ERRCODE_WARNING_STRING_DATA_RIGHT_TRUNCATION'),
    ('01006', 'ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED'),
    ('01007', 'ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED'),
    ('01008', 'ERRCODE_WARNING_PRIVILEGE_ALREADY_GRANTED'),
    ('01009', 'ERRCODE_WARNING_PRIVILEGE_ALREADY_REVOKED'),
    ('0100C', 'ERRCODE_WARNING_DYNAMIC_RESULT_SETS_RETURNED'),
    ('01V01', 'ERRCODE_WARNING_DEPRECATED_FEATURE'),
    ('01V02', 'ERRCODE_WARNING_QUERY_RETRIED'),
    ('02000', 'ERRCODE_NO_DATA'),
    ('02001', 'ERRCODE_NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED'),
    ('03000', 'ERRCODE_SQL_STATEMENT_NOT_YET_COMPLETE'),
    ('08000', 'ERRCODE_CONNECTION_EXCEPTION'),
    ('08001', 'ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION'),
    ('08003', 'ERRCODE_CONNECTION_DOES_NOT_EXIST'),
    ('08004', 'ERRCODE_SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION'),
    ('08006', 'ERRCODE_CONNECTION_FAILURE'),
    ('08007', 'ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN'),
    ('08V01', 'ERRCODE_PROTOCOL_VIOLATION'),
    ('09000', 'ERRCODE_TRIGGERED_ACTION_EXCEPTION'),
    ('0A000', 'ERRCODE_FEATURE_NOT_SUPPORTED'),
    ('0A005', 'ERRCODE_PLAN_TO_SQL_NOT_SUPPORTED'),
    ('0B000', 'ERRCODE_INVALID_TRANSACTION_INITIATION'),
    ('0F000', 'ERRCODE_LOCATOR_EXCEPTION'),
    ('0F001', 'ERRCODE_L_E_INVALID_SPECIFICATION'),
    ('0L000', 'ERRCODE_INVALID_GRANTOR'),
    ('0LV01', 'ERRCODE_INVALID_GRANT_OPERATION'),
    ('0P000', 'ERRCODE_INVALID_ROLE_SPECIFICATION'),
    ('21000', 'ERRCODE_CARDINALITY_VIOLATION'),
    ('22000', 'ERRCODE_DATA_EXCEPTION'),
    ('22001', 'ERRCODE_STRING_DATA_RIGHT_TRUNCATION'),
    ('22002', 'ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER'),
    ('22003', 'ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE'),
    ('22004', 'ERRCODE_NULL_VALUE_NOT_ALLOWED'),
    ('22005', 'ERRCODE_ERROR_IN_ASSIGNMENT'),
    ('22007', 'ERRCODE_INVALID_DATETIME_FORMAT'),
    ('22008', 'ERRCODE_DATETIME_FIELD_OVERFLOW'),
    ('22009', 'ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE'),
    ('2200B', 'ERRCODE_ESCAPE_CHARACTER_CONFLICT'),
    ('2200C', 'ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER'),
    ('2200D', 'ERRCODE_INVALID_ESCAPE_OCTET'),
    ('2200F', 'ERRCODE_ZERO_LENGTH_CHARACTER_STRING'),
    ('2200G', 'ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH'),
    ('22010', 'ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE'),
    ('22011', 'ERRCODE_SUBSTRING_ERROR'),
    ('22012', 'ERRCODE_DIVISION_BY_ZERO'),
    ('22015', 'ERRCODE_INTERVAL_FIELD_OVERFLOW'),
    ('22018', 'ERRCODE_INVALID_CHARACTER_VALUE_FOR_CAST'),
    ('22019', 'ERRCODE_INVALID_ESCAPE_CHARACTER'),
    ('2201B', 'ERRCODE_INVALID_REGULAR_EXPRESSION'),
    ('2201E', 'ERRCODE_INVALID_ARGUMENT_FOR_LOG'),
    ('2201F', 'ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION'),
    ('2201G', 'ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION'),
    ('22020', 'ERRCODE_INVALID_LIMIT_VALUE'),
    ('22021', 'ERRCODE_CHARACTER_NOT_IN_REPERTOIRE'),
    ('22022', 'ERRCODE_INDICATOR_OVERFLOW'),
    ('22023', 'ERRCODE_INVALID_PARAMETER_VALUE'),
    ('22024', 'ERRCODE_UNTERMINATED_C_STRING'),
    ('22025', 'ERRCODE_INVALID_ESCAPE_SEQUENCE'),
    ('22026', 'ERRCODE_STRING_DATA_LENGTH_MISMATCH'),
    ('22027', 'ERRCODE_TRIM_ERROR'),
    ('2202E', 'ERRCODE_ARRAY_ELEMENT_ERROR'),
    ('22906', 'ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER'),
    ('22V01', 'ERRCODE_FLOATING_POINT_EXCEPTION'),
    ('22V02', 'ERRCODE_INVALID_TEXT_REPRESENTATION'),
    ('22V03', 'ERRCODE_INVALID_BINARY_REPRESENTATION'),
    ('22V04', 'ERRCODE_BAD_COPY_FILE_FORMAT'),
    ('22V05', 'ERRCODE_UNTRANSLATABLE_CHARACTER'),
    ('22V0B', 'ERRCODE_ESCAPE_CHARACTER_ON_NOESCAPE'),
    ('22V21', 'ERRCODE_INVALID_EPOCH'),
    ('22V22', 'ERRCODE_PLPGSQL_ERROR'),
    ('22V23', 'ERRCODE_RAISE_EXCEPTION'),
    ('22V24', 'ERRCODE_COPY_PARSE_ERROR'),
    ('23000', 'ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION'),
    ('23001', 'ERRCODE_RESTRICT_VIOLATION'),
    ('23502', 'ERRCODE_NOT_NULL_VIOLATION'),
    ('23503', 'ERRCODE_FOREIGN_KEY_VIOLATION'),
    ('23505', 'ERRCODE_UNIQUE_VIOLATION'),
    ('23514', 'ERRCODE_CHECK_VIOLATION'),
    ('24000', 'ERRCODE_INVALID_CURSOR_STATE'),
    ('25000', 'ERRCODE_INVALID_TRANSACTION_STATE'),
    ('25001', 'ERRCODE_ACTIVE_SQL_TRANSACTION'),
    ('25002', 'ERRCODE_BRANCH_TRANSACTION_ALREADY_ACTIVE'),
    ('25003', 'ERRCODE_INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION'),
    ('25004', 'ERRCODE_INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION'),
    ('25005', 'ERRCODE_NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION'),
    ('25006', 'ERRCODE_READ_ONLY_SQL_TRANSACTION'),
    ('25007', 'ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED'),
    ('25008', 'ERRCODE_HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL'),
    ('25V01', 'ERRCODE_NO_ACTIVE_SQL_TRANSACTION'),
    ('25V02', 'ERRCODE_IN_FAILED_SQL_TRANSACTION'),
    ('26000', 'ERRCODE_INVALID_SQL_STATEMENT_NAME'),
    ('27000', 'ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION'),
    ('28000', 'ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION'),
    ('28001', 'ERRCODE_ACCOUNT_LOCKED'),
    ('28002', 'ERRCODE_PASSWORD_EXPIRED'),
    ('28003', 'ERRCODE_PASSWORD_IN_GRACE_PERIOD'),
    ('2B000', 'ERRCODE_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST'),
    ('2BV01', 'ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST'),
    ('2D000', 'ERRCODE_INVALID_TRANSACTION_TERMINATION'),
    ('2F000', 'ERRCODE_SQL_ROUTINE_EXCEPTION'),
    ('2F002', 'ERRCODE_S_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED'),
    ('2F003', 'ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED'),
    ('2F004', 'ERRCODE_S_R_E_READING_SQL_DATA_NOT_PERMITTED'),
    ('2F005', 'ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT'),
    ('34000', 'ERRCODE_INVALID_CURSOR_NAME'),
    ('38000', 'ERRCODE_EXTERNAL_ROUTINE_EXCEPTION'),
    ('38001', 'ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED'),
    ('38002', 'ERRCODE_E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED'),
    ('38003', 'ERRCODE_E_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED'),
    ('38004', 'ERRCODE_E_R_E_READING_SQL_DATA_NOT_PERMITTED'),
    ('39000', 'ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION'),
    ('39001', 'ERRCODE_E_R_I_E_INVALID_SQLSTATE_RETURNED'),
    ('39004', 'ERRCODE_E_R_I_E_NULL_VALUE_NOT_ALLOWED'),
    ('39V01', 'ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED'),
    ('39V02', 'ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED'),
    ('3B000', 'ERRCODE_SAVEPOINT_EXCEPTION'),
    ('3B001', 'ERRCODE_S_E_INVALID_SPECIFICATION'),
    ('3D000', 'ERRCODE_INVALID_CATALOG_NAME'),
    ('3F000', 'ERRCODE_INVALID_SCHEMA_NAME'),
    ('40000', 'ERRCODE_TRANSACTION_ROLLBACK'),
    ('40001', 'ERRCODE_T_R_SERIALIZATION_FAILURE'),
    ('40002', 'ERRCODE_T_R_INTEGRITY_CONSTRAINT_VIOLATION'),
    ('40003', 'ERRCODE_T_R_STATEMENT_COMPLETION_UNKNOWN'),
    ('40V01', 'ERRCODE_T_R_DEADLOCK_DETECTED'),
    ('42000', 'ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION'),
    ('42501', 'ERRCODE_INSUFFICIENT_PRIVILEGE'),
    ('42601', 'ERRCODE_SYNTAX_ERROR'),
    ('42602', 'ERRCODE_INVALID_NAME'),
    ('42611', 'ERRCODE_INVALID_COLUMN_DEFINITION'),
    ('42622', 'ERRCODE_NAME_TOO_LONG'),
    ('42701', 'ERRCODE_DUPLICATE_COLUMN'),
    ('42702', 'ERRCODE_AMBIGUOUS_COLUMN'),
    ('42703', 'ERRCODE_UNDEFINED_COLUMN'),
    ('42704', 'ERRCODE_UNDEFINED_OBJECT'),
    ('42710', 'ERRCODE_DUPLICATE_OBJECT'),
    ('42712', 'ERRCODE_DUPLICATE_ALIAS'),
    ('42723', 'ERRCODE_DUPLICATE_FUNCTION'),
    ('42725', 'ERRCODE_AMBIGUOUS_FUNCTION'),
    ('42803', 'ERRCODE_GROUPING_ERROR'),
    ('42804', 'ERRCODE_DATATYPE_MISMATCH'),
    ('42809', 'ERRCODE_WRONG_OBJECT_TYPE'),
    ('42830', 'ERRCODE_INVALID_FOREIGN_KEY'),
    ('42846', 'ERRCODE_CANNOT_COERCE'),
    ('42883', 'ERRCODE_UNDEFINED_FUNCTION'),
    ('42939', 'ERRCODE_RESERVED_NAME'),
    ('42P20', 'ERRCODE_WINDOWING_ERROR'),
    ('42V01', 'ERRCODE_UNDEFINED_TABLE'),
    ('42V02', 'ERRCODE_UNDEFINED_PARAMETER'),
    ('42V03', 'ERRCODE_DUPLICATE_CURSOR'),
    ('42V04', 'ERRCODE_DUPLICATE_DATABASE'),
    ('42V05', 'ERRCODE_DUPLICATE_PSTATEMENT'),
    ('42V06', 'ERRCODE_DUPLICATE_SCHEMA'),
    ('42V07', 'ERRCODE_DUPLICATE_TABLE'),
    ('42V08', 'ERRCODE_AMBIGUOUS_PARAMETER'),
    ('42V09', 'ERRCODE_AMBIGUOUS_ALIAS'),
    ('42V10', 'ERRCODE_INVALID_COLUMN_REFERENCE'),
    ('42V11', 'ERRCODE_INVALID_CURSOR_DEFINITION'),
    ('42V12', 'ERRCODE_INVALID_DATABASE_DEFINITION'),
    ('42V13', 'ERRCODE_INVALID_FUNCTION_DEFINITION'),
    ('42V14', 'ERRCODE_INVALID_PSTATEMENT_DEFINITION'),
    ('42V15', 'ERRCODE_INVALID_SCHEMA_DEFINITION'),
    ('42V16', 'ERRCODE_INVALID_TABLE_DEFINITION'),
    ('42V17', 'ERRCODE_INVALID_OBJECT_DEFINITION'),
    ('42V18', 'ERRCODE_INDETERMINATE_DATATYPE'),
    ('42V21', 'ERRCODE_UNDEFINED_PROJECTION'),
    ('42V22', 'ERRCODE_UNDEFINED_NODE'),
    ('42V23', 'ERRCODE_UNDEFINED_PERMUTATION'),
    ('42V24', 'ERRCODE_UNDEFINED_USER'),
    ('42V25', 'ERRCODE_PATTERN_MATCH_ERROR'),
    ('42V26', 'ERRCODE_DUPLICATE_NODE'),
    ('44000', 'ERRCODE_WITH_CHECK_OPTION_VIOLATION'),
    ('53000', 'ERRCODE_INSUFFICIENT_RESOURCES'),
    ('53100', 'ERRCODE_DISK_FULL'),
    ('53200', 'ERRCODE_OUT_OF_MEMORY'),
    ('53300', 'ERRCODE_TOO_MANY_CONNECTIONS'),
    ('54000', 'ERRCODE_PROGRAM_LIMIT_EXCEEDED'),
    ('54001', 'ERRCODE_STATEMENT_TOO_COMPLEX'),
    ('54011', 'ERRCODE_TOO_MANY_COLUMNS'),
    ('54023', 'ERRCODE_TOO_MANY_ARGUMENTS'),
    ('55000', 'ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE'),
    ('55006', 'ERRCODE_OBJECT_IN_USE'),
    ('55V02', 'ERRCODE_CANT_CHANGE_RUNTIME_PARAM'),
    ('55V03', 'ERRCODE_LOCK_NOT_AVAILABLE'),
    ('55V04', 'ERRCODE_TM_MARKER_NOT_AVAILABLE'),
    ('57000', 'ERRCODE_OPERATOR_INTERVENTION'),
    ('57014', 'ERRCODE_QUERY_CANCELED'),
    ('57015', 'ERRCODE_SLOW_DELETE'),
    ('57V01', 'ERRCODE_ADMIN_SHUTDOWN'),
    ('57V02', 'ERRCODE_CRASH_SHUTDOWN'),
    ('57V03', 'ERRCODE_CANNOT_CONNECT_NOW'),
    ('58030', 'ERRCODE_IO_ERROR'),
    ('58V01', 'ERRCODE_UNDEFINED_FILE'),
    ('58V02', 'ERRCODE_DUPLICATE_FILE'),
    ('V1001', 'ERRCODE_LOST_CONNECTIVITY'),
    ('V1002', 'ERRCODE_K_SAFETY_VIOLATION'),
    ('V1003', 'ERRCODE_CLUSTER_CHANGE'),
    ('V2000', 'ERRCODE_AUTH_FAILED'),
    ('V2001', 'ERRCODE_LICENSE_ISSUE'),
    ('V2002', 'ERRCODE_MOVEOUT_ABORTED'),
    ('VC001', 'ERRCODE_CONFIG_FILE_ERROR'),
    ('VC002', 'ERRCODE_LOCK_FILE_EXISTS'),
    ('VD001', 'ERRCODE_DESIGNER_FUNCTION_ERROR'),
    ('VP000', 'ERRCODE_USER_PROC_ERROR'),
    ('VP001', 'ERRCODE_USER_PROC_EXEC_ERROR'),
    ('VX001', 'ERRCODE_INTERNAL_ERROR'),
    ('VX002', 'ERRCODE_DATA_CORRUPTED'),
    ('VX003', 'ERRCODE_INDEX_CORRUPTED'),
    ('VX004', 'ERRCODE_PLAN_TO_SQL_INTERNAL_EROR'),
)