diff options
| author | Tom Lane | 2013-01-29 22:06:26 +0000 |
|---|---|---|
| committer | Tom Lane | 2013-01-29 22:08:26 +0000 |
| commit | 991f3e5ab3f8196d18d5b313c81a5f744f3baaea (patch) | |
| tree | 376f7a4bc5541156a3c270304dc22333f2ba6955 /src/include | |
| parent | 89d00cbe01447fd36edbc3bed659f869b18172d1 (diff) | |
Provide database object names as separate fields in error messages.
This patch addresses the problem that applications currently have to
extract object names from possibly-localized textual error messages,
if they want to know for example which index caused a UNIQUE_VIOLATION
failure. It adds new error message fields to the wire protocol, which
can carry the name of a table, table column, data type, or constraint
associated with the error. (Since the protocol spec has always instructed
clients to ignore unrecognized field types, this should not create any
compatibility problem.)
Support for providing these new fields has been added to just a limited set
of error reports (mainly, those in the "integrity constraint violation"
SQLSTATE class), but we will doubtless add them to more calls in future.
Pavel Stehule, reviewed and extensively revised by Peter Geoghegan, with
additional hacking by Tom Lane.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/access/hash.h | 2 | ||||
| -rw-r--r-- | src/include/access/nbtree.h | 3 | ||||
| -rw-r--r-- | src/include/postgres_ext.h | 5 | ||||
| -rw-r--r-- | src/include/utils/builtins.h | 5 | ||||
| -rw-r--r-- | src/include/utils/elog.h | 7 | ||||
| -rw-r--r-- | src/include/utils/relcache.h | 8 | ||||
| -rw-r--r-- | src/include/utils/tuplesort.h | 6 |
7 files changed, 31 insertions, 5 deletions
diff --git a/src/include/access/hash.h b/src/include/access/hash.h index c50bbd0d005..f66111f0c22 100644 --- a/src/include/access/hash.h +++ b/src/include/access/hash.h @@ -334,7 +334,7 @@ extern bool _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir); /* hashsort.c */ typedef struct HSpool HSpool; /* opaque struct in hashsort.c */ -extern HSpool *_h_spoolinit(Relation index, uint32 num_buckets); +extern HSpool *_h_spoolinit(Relation heap, Relation index, uint32 num_buckets); extern void _h_spooldestroy(HSpool *hspool); extern void _h_spool(IndexTuple itup, HSpool *hspool); extern void _h_indexbuild(HSpool *hspool); diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 0e35d7ad25b..3997f94f46e 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -686,7 +686,8 @@ extern void BTreeShmemInit(void); */ typedef struct BTSpool BTSpool; /* opaque type known only within nbtsort.c */ -extern BTSpool *_bt_spoolinit(Relation index, bool isunique, bool isdead); +extern BTSpool *_bt_spoolinit(Relation heap, Relation index, + bool isunique, bool isdead); extern void _bt_spooldestroy(BTSpool *btspool); extern void _bt_spool(IndexTuple itup, BTSpool *btspool); extern void _bt_leafbuild(BTSpool *btspool, BTSpool *spool2); diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h index 5ba379f869b..48d5dd31e53 100644 --- a/src/include/postgres_ext.h +++ b/src/include/postgres_ext.h @@ -57,6 +57,11 @@ typedef PG_INT64_TYPE pg_int64; #define PG_DIAG_INTERNAL_POSITION 'p' #define PG_DIAG_INTERNAL_QUERY 'q' #define PG_DIAG_CONTEXT 'W' +#define PG_DIAG_SCHEMA_NAME 's' +#define PG_DIAG_TABLE_NAME 't' +#define PG_DIAG_COLUMN_NAME 'c' +#define PG_DIAG_DATATYPE_NAME 'd' +#define PG_DIAG_CONSTRAINT_NAME 'n' #define PG_DIAG_SOURCE_FILE 'F' #define PG_DIAG_SOURCE_LINE 'L' #define PG_DIAG_SOURCE_FUNCTION 'R' diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index ad4d68cd50a..533539ca293 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -143,7 +143,10 @@ extern Datum char_text(PG_FUNCTION_ARGS); /* domains.c */ extern Datum domain_in(PG_FUNCTION_ARGS); extern Datum domain_recv(PG_FUNCTION_ARGS); -extern void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt); +extern void domain_check(Datum value, bool isnull, Oid domainType, + void **extra, MemoryContext mcxt); +extern int errdatatype(Oid datatypeOid); +extern int errdomainconstraint(Oid datatypeOid, const char *conname); /* encode.c */ extern Datum binary_encode(PG_FUNCTION_ARGS); diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 5e937fb10c3..d5fec89a480 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -220,6 +220,8 @@ extern int errposition(int cursorpos); extern int internalerrposition(int cursorpos); extern int internalerrquery(const char *query); +extern int err_generic_string(int field, const char *str); + extern int geterrcode(void); extern int geterrposition(void); extern int getinternalerrposition(void); @@ -386,6 +388,11 @@ typedef struct ErrorData char *detail_log; /* detail error message for server log only */ char *hint; /* hint message */ char *context; /* context message */ + char *schema_name; /* name of schema */ + char *table_name; /* name of table */ + char *column_name; /* name of column */ + char *datatype_name; /* name of datatype */ + char *constraint_name; /* name of constraint */ int cursorpos; /* cursor index into query string */ int internalpos; /* cursor index into internalquery */ char *internalquery; /* text of internally-generated query */ diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index 1ec2683eacb..8ac2549cb3a 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -53,6 +53,14 @@ extern void RelationSetIndexList(Relation relation, extern void RelationInitIndexAccessInfo(Relation relation); /* + * Routines to support ereport() reports of relation-related errors + */ +extern int errtable(Relation rel); +extern int errtablecol(Relation rel, int attnum); +extern int errtablecolname(Relation rel, const char *colname); +extern int errtableconstraint(Relation rel, const char *conname); + +/* * Routines for backend startup */ extern void RelationCacheInitialize(void); diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h index 8fdc6a1bf43..e69aafcd903 100644 --- a/src/include/utils/tuplesort.h +++ b/src/include/utils/tuplesort.h @@ -66,10 +66,12 @@ extern Tuplesortstate *tuplesort_begin_heap(TupleDesc tupDesc, extern Tuplesortstate *tuplesort_begin_cluster(TupleDesc tupDesc, Relation indexRel, int workMem, bool randomAccess); -extern Tuplesortstate *tuplesort_begin_index_btree(Relation indexRel, +extern Tuplesortstate *tuplesort_begin_index_btree(Relation heapRel, + Relation indexRel, bool enforceUnique, int workMem, bool randomAccess); -extern Tuplesortstate *tuplesort_begin_index_hash(Relation indexRel, +extern Tuplesortstate *tuplesort_begin_index_hash(Relation heapRel, + Relation indexRel, uint32 hash_mask, int workMem, bool randomAccess); extern Tuplesortstate *tuplesort_begin_datum(Oid datumType, |
