mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Completed documentation for errorcodes module.
This commit is contained in:
parent
96b7912bcf
commit
a320f25a2a
|
@ -1,5 +1,9 @@
|
||||||
@import url("default.css");
|
@import url("default.css");
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
div.admonition-todo {
|
div.admonition-todo {
|
||||||
background-color: #ffa;
|
background-color: #ffa;
|
||||||
border: 1px solid #ee2;
|
border: 1px solid #ee2;
|
||||||
|
|
|
@ -3,13 +3,20 @@
|
||||||
|
|
||||||
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||||
|
|
||||||
|
.. index::
|
||||||
|
single: Error; Codes
|
||||||
|
|
||||||
.. module:: psycopg2.errorcodes
|
.. module:: psycopg2.errorcodes
|
||||||
|
|
||||||
|
.. testsetup:: *
|
||||||
|
|
||||||
|
from psycopg2 import errorcodes
|
||||||
|
|
||||||
.. versionadded:: 2.0.6
|
.. versionadded:: 2.0.6
|
||||||
|
|
||||||
This module contains symbolic names for all PostgreSQL error codes.
|
This module contains symbolic names for all PostgreSQL error codes and error
|
||||||
Subclasses of :exc:`~psycopg2.Error` make the PostgreSQL error code available
|
classes codes. Subclasses of :exc:`~psycopg2.Error` make the PostgreSQL error
|
||||||
in the :attr:`~psycopg2.Error.pgcode` attribute.
|
code available in the :attr:`~psycopg2.Error.pgcode` attribute.
|
||||||
|
|
||||||
From PostgreSQL documentation:
|
From PostgreSQL documentation:
|
||||||
|
|
||||||
|
@ -30,12 +37,36 @@ From PostgreSQL documentation:
|
||||||
recognize the specific error code can still be able to infer what to do
|
recognize the specific error code can still be able to infer what to do
|
||||||
from the error class.
|
from the error class.
|
||||||
|
|
||||||
|
|
||||||
.. seealso:: `PostgreSQL Error Codes table`__
|
.. seealso:: `PostgreSQL Error Codes table`__
|
||||||
|
|
||||||
.. __: http://www.postgresql.org/docs/8.4/static/errcodes-appendix.html#ERRCODES-TABLE
|
.. __: http://www.postgresql.org/docs/8.4/static/errcodes-appendix.html#ERRCODES-TABLE
|
||||||
|
|
||||||
|
|
||||||
.. todo:: errors table
|
An example of the available constants defined in the module:
|
||||||
|
|
||||||
|
>>> errorcodes.CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION
|
||||||
|
'42'
|
||||||
|
>>> errorcodes.UNDEFINED_TABLE
|
||||||
|
'42P01'
|
||||||
|
|
||||||
|
Constants representing all the error values documented by PostgreSQL versions
|
||||||
|
between 8.1 and 8.4 are included in the module.
|
||||||
|
|
||||||
|
|
||||||
|
.. autofunction:: lookup(code)
|
||||||
|
|
||||||
|
.. doctest::
|
||||||
|
|
||||||
|
>>> try:
|
||||||
|
... cur.execute("SELECT ouch FROM aargh;")
|
||||||
|
... except Exception, e:
|
||||||
|
... pass
|
||||||
|
...
|
||||||
|
>>> errorcodes.lookup(e.pgcode[:2])
|
||||||
|
'CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION'
|
||||||
|
>>> errorcodes.lookup(e.pgcode)
|
||||||
|
'UNDEFINED_TABLE'
|
||||||
|
|
||||||
|
.. versionadded:: 2.0.14
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ This module contains symbolic names for all PostgreSQL error codes.
|
||||||
#
|
#
|
||||||
|
|
||||||
def lookup(code, _cache={}):
|
def lookup(code, _cache={}):
|
||||||
"""Lookup a code error and return its symbolic name.
|
"""Lookup an error code or class code and return its symbolic name.
|
||||||
|
|
||||||
Raise KeyError if the code is not found.
|
Raise :exc:`KeyError` if the code is not found.
|
||||||
"""
|
"""
|
||||||
if _cache:
|
if _cache:
|
||||||
return _cache[code]
|
return _cache[code]
|
||||||
|
|
|
@ -71,6 +71,11 @@ def parse_errors(url):
|
||||||
errcode = tr.tt.string.encode("ascii")
|
errcode = tr.tt.string.encode("ascii")
|
||||||
assert len(errcode) == 5
|
assert len(errcode) == 5
|
||||||
errlabel = tr('td')[1].string.replace(" ", "_").encode("ascii")
|
errlabel = tr('td')[1].string.replace(" ", "_").encode("ascii")
|
||||||
|
|
||||||
|
# double check the columns are equal
|
||||||
|
cond_name = tr('td')[2].string.upper().encode("ascii")
|
||||||
|
assert errlabel == cond_name, tr
|
||||||
|
|
||||||
errors[class_][errcode] = errlabel
|
errors[class_][errcode] = errlabel
|
||||||
|
|
||||||
return classes, errors
|
return classes, errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user