1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
# Copyright (c) 2019-2024 Open Text.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function, division, absolute_import, annotations
from collections import OrderedDict
FIELD_DEFINITIONS = [
{'type': b'q', 'name': "Internal Query", 'attribute': 'internal_query'},
{'type': b'S', 'name': "Severity", 'attribute': 'severity'},
{'type': b'M', 'name': "Message", 'attribute': 'message'},
{'type': b'C', 'name': "Sqlstate", 'attribute': 'sqlstate'},
{'type': b'D', 'name': "Detail", 'attribute': 'detail'},
{'type': b'H', 'name': "Hint", 'attribute': 'hint'},
{'type': b'P', 'name': "Position", 'attribute': 'position'},
{'type': b'W', 'name': "Where", 'attribute': 'where'},
{'type': b'p', 'name': "Internal Position", 'attribute': 'internal_position'},
{'type': b'R', 'name': "Routine", 'attribute': 'routine'},
{'type': b'F', 'name': "File", 'attribute': 'file'},
{'type': b'L', 'name': "Line", 'attribute': 'line'},
{'type': b'V', 'name': "Error Code", 'attribute': 'error_code'}
]
FIELD_ATTR_TO_TYPE = {field['attribute']: field['type'] for field in FIELD_DEFINITIONS}
class _NoticeResponseAttrMixin:
# class must have `self._notice_attrs` property that provides a mapping from
# the type indicator (see `FIELD_DEFINITIONS`) to value.
@property
def internal_query(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['internal_query'])
@property
def severity(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['severity'])
@property
def message(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['message'])
@property
def sqlstate(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['sqlstate'])
@property
def detail(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['detail'])
@property
def hint(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['hint'])
@property
def position(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['position'])
@property
def where(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['where'])
@property
def internal_position(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['internal_position'])
@property
def routine(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['routine'])
@property
def file(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['file'])
@property
def line(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['line'])
@property
def error_code(self):
return self._notice_attrs.get(FIELD_ATTR_TO_TYPE['error_code'])
def _get_labeled_values(self):
values_mapping = OrderedDict()
for field_def in FIELD_DEFINITIONS:
if field_def['type'] in self._notice_attrs:
values_mapping[field_def['name']] = self._notice_attrs[field_def['type']]
return values_mapping
|