mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 02:43:43 +03:00
Added all supported properties to the Diagnostic object
This commit is contained in:
parent
9e79112e25
commit
42b063b562
|
@ -82,6 +82,24 @@ exit:
|
|||
|
||||
/* object calculated member list */
|
||||
static struct PyGetSetDef diagnosticsObject_getsets[] = {
|
||||
{ "severity", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_SEVERITY },
|
||||
{ "sqlstate", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_SQLSTATE },
|
||||
{ "message_primary", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_MESSAGE_PRIMARY },
|
||||
{ "message_detail", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_MESSAGE_DETAIL },
|
||||
{ "message_hint", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_MESSAGE_HINT },
|
||||
{ "statement_position", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_STATEMENT_POSITION },
|
||||
{ "internal_position", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_INTERNAL_POSITION },
|
||||
{ "internal_query", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_INTERNAL_QUERY },
|
||||
{ "context", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_CONTEXT },
|
||||
{ "schema_name", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_SCHEMA_NAME },
|
||||
{ "table_name", (getter)psyco_diagnostics_get_field, NULL,
|
||||
|
@ -92,6 +110,12 @@ static struct PyGetSetDef diagnosticsObject_getsets[] = {
|
|||
NULL, (void*) PG_DIAG_DATATYPE_NAME },
|
||||
{ "constraint_name", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_CONSTRAINT_NAME },
|
||||
{ "source_file", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_SOURCE_FILE },
|
||||
{ "source_line", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_SOURCE_LINE },
|
||||
{ "source_function", (getter)psyco_diagnostics_get_field, NULL,
|
||||
NULL, (void*) PG_DIAG_SOURCE_FUNCTION },
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -155,8 +155,38 @@ class ExceptionsTestCase(unittest.TestCase):
|
|||
self.assert_(e.pgerror)
|
||||
self.assert_(e.cursor is cur)
|
||||
|
||||
def test_diagnostics_attributes(self):
|
||||
cur = self.conn.cursor()
|
||||
try:
|
||||
cur.execute("select * from nonexist")
|
||||
except psycopg2.Error, exc:
|
||||
e = exc
|
||||
|
||||
diag = e.diag
|
||||
self.assert_(isinstance(diag, psycopg2.extensions.Diagnostics))
|
||||
for attr in [
|
||||
'column_name', 'constraint_name', 'context', 'datatype_name',
|
||||
'internal_position', 'internal_query', 'message_detail',
|
||||
'message_hint', 'message_primary', 'schema_name', 'severity',
|
||||
'source_file', 'source_function', 'source_line', 'sqlstate',
|
||||
'statement_position', 'table_name', ]:
|
||||
v = getattr(diag, attr)
|
||||
if v is not None:
|
||||
self.assert_(isinstance(v, str))
|
||||
|
||||
def test_diagnostics_values(self):
|
||||
cur = self.conn.cursor()
|
||||
try:
|
||||
cur.execute("select * from nonexist")
|
||||
except psycopg2.Error, exc:
|
||||
e = exc
|
||||
|
||||
self.assertEqual(e.diag.sqlstate, '42P01')
|
||||
self.assertEqual(e.diag.severity, 'ERROR')
|
||||
self.assertEqual(e.diag.statement_position, '15')
|
||||
|
||||
@skip_before_postgres(9, 3)
|
||||
def test_diagnostics(self):
|
||||
def test_9_3_diagnostics(self):
|
||||
cur = self.conn.cursor()
|
||||
cur.execute("""
|
||||
create temp table test_exc (
|
||||
|
|
Loading…
Reference in New Issue
Block a user