Error message editing in contrib (mostly by Joe Conway --- thanks Joe!)

This commit is contained in:
Tom Lane 2003-07-24 17:52:50 +00:00
parent f0c5384d4a
commit 8fd5b3ed67
75 changed files with 1459 additions and 658 deletions

View File

@ -247,14 +247,20 @@ __BTREE_GIST_TYPE2__key_cmp(const void *a, const void *b)
Datum
__BTREE_GIST_TYPE2__key_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("<datatype>key_in() not implemented")));
PG_RETURN_POINTER(NULL);
}
Datum
__BTREE_GIST_TYPE2__key_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("<datatype>key_out() not implemented")));
PG_RETURN_POINTER(NULL);
}

View File

@ -270,13 +270,19 @@ tskey_cmp(const void *a, const void *b)
Datum
tskey_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("feature not implemented")));
PG_RETURN_POINTER(NULL);
}
Datum
tskey_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("feature not implemented")));
PG_RETURN_POINTER(NULL);
}

View File

@ -3,18 +3,24 @@
-- does not depend on contents of btree_gist.sql.
--
\set ECHO none
psql:btree_gist.sql:8: NOTICE: ProcedureCreate: type int2key is not yet defined
psql:btree_gist.sql:13: NOTICE: Argument type "int2key" is only a shell
psql:btree_gist.sql:25: NOTICE: ProcedureCreate: type int4key is not yet defined
psql:btree_gist.sql:30: NOTICE: Argument type "int4key" is only a shell
psql:btree_gist.sql:42: NOTICE: ProcedureCreate: type int8key is not yet defined
psql:btree_gist.sql:47: NOTICE: Argument type "int8key" is only a shell
psql:btree_gist.sql:59: NOTICE: ProcedureCreate: type float4key is not yet defined
psql:btree_gist.sql:64: NOTICE: Argument type "float4key" is only a shell
psql:btree_gist.sql:77: NOTICE: ProcedureCreate: type float8key is not yet defined
psql:btree_gist.sql:82: NOTICE: Argument type "float8key" is only a shell
psql:btree_gist.sql:392: NOTICE: ProcedureCreate: type tskey is not yet defined
psql:btree_gist.sql:397: NOTICE: Argument type "tskey" is only a shell
psql:btree_gist.sql:8: NOTICE: type int2key is not yet defined
DETAIL: Creating a shell type definition.
psql:btree_gist.sql:13: NOTICE: argument type int2key is only a shell
psql:btree_gist.sql:25: NOTICE: type int4key is not yet defined
DETAIL: Creating a shell type definition.
psql:btree_gist.sql:30: NOTICE: argument type int4key is only a shell
psql:btree_gist.sql:42: NOTICE: type int8key is not yet defined
DETAIL: Creating a shell type definition.
psql:btree_gist.sql:47: NOTICE: argument type int8key is only a shell
psql:btree_gist.sql:59: NOTICE: type float4key is not yet defined
DETAIL: Creating a shell type definition.
psql:btree_gist.sql:64: NOTICE: argument type float4key is only a shell
psql:btree_gist.sql:77: NOTICE: type float8key is not yet defined
DETAIL: Creating a shell type definition.
psql:btree_gist.sql:82: NOTICE: argument type float8key is only a shell
psql:btree_gist.sql:392: NOTICE: type tskey is not yet defined
DETAIL: Creating a shell type definition.
psql:btree_gist.sql:397: NOTICE: argument type tskey is only a shell
CREATE TABLE int4tmp (b int4);
\copy int4tmp from 'data/test_btree.data'
CREATE TABLE int8tmp (b int8);

View File

@ -4,7 +4,7 @@
* darcy@druid.net
* http://www.druid.net/darcy/
*
* $Id: chkpass.c,v 1.9 2002/10/26 15:00:59 tgl Exp $
* $Id: chkpass.c,v 1.10 2003/07/24 17:52:12 tgl Exp $
* best viewed with tabs set to 4
*/
@ -84,8 +84,10 @@ chkpass_in(PG_FUNCTION_ARGS)
if (verify_pass(str) != 0)
{
elog(ERROR, "chkpass_in: purported CHKPASS \"%s\" is a weak password",
str);
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("password \"%s\" is weak", str)));
PG_RETURN_POINTER(NULL);
}

View File

@ -2,8 +2,6 @@
#include "postgres.h"
#include "utils/elog.h"
static char *PARSE_BUFFER;
static char *PARSE_BUFFER_PTR;
static unsigned int PARSE_BUFFER_SIZE;
@ -26,7 +24,10 @@ set_parse_buffer(char *s)
PARSE_BUFFER = s;
PARSE_BUFFER_SIZE = strlen(s);
if (PARSE_BUFFER_SIZE == 0)
elog(ERROR, "cube_in: can't parse an empty string");
ereport(ERROR,
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
errmsg("can't parse an empty string")));
PARSE_BUFFER_PTR = PARSE_BUFFER;
SCANNER_POS = 0;
}

View File

@ -11,9 +11,6 @@
#include "cubedata.h"
#include "buffer.h"
#include "utils/palloc.h"
#include "utils/elog.h"
#undef yylex /* falure to redefine yylex will result in a call to the */
#define yylex cube_yylex /* wrong scanner when running inside the postgres backend */
@ -48,19 +45,31 @@ box:
if ( c != '\0' ) {
/* Not at EOF */
reset_parse_buffer();
elog(ERROR, "(0) bad cube representation; garbage at or before char %d, ('%c', \\%03o)\n", pos, c, c );
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("garbage at or before char %d, ('%c', \\%03o)",
pos, c, c)));
YYERROR;
}
dim = delim_count($2, ',') + 1;
if ( (delim_count($4, ',') + 1) != dim ) {
reset_parse_buffer();
elog(ERROR, "(1) bad cube representation; different point dimensions in (%s) and (%s)\n", $2, $4);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("different point dimensions in (%s) and (%s)",
$2, $4)));
YYABORT;
}
if (dim > CUBE_MAX_DIM) {
reset_parse_buffer();
elog(ERROR, "(8) bad cube representation; more than %d dimensions\n", CUBE_MAX_DIM);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("more than %d dimensions",
CUBE_MAX_DIM)));
YYABORT;
}
@ -75,7 +84,11 @@ box:
if ( c != '\0' ) { /* Not at EOF */
reset_parse_buffer();
elog(ERROR, "(2) bad cube representation; garbage at or before char %d, ('%c', \\%03o)\n", pos, c, c );
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("garbage at or before char %d, ('%c', \\%03o)",
pos, c, c)));
YYABORT;
}
@ -83,12 +96,20 @@ box:
if ( (delim_count($3, ',') + 1) != dim ) {
reset_parse_buffer();
elog(ERROR, "(3) bad cube representation; different point dimensions in (%s) and (%s)\n", $1, $3);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("different point dimensions in (%s) and (%s)",
$1, $3)));
YYABORT;
}
if (dim > CUBE_MAX_DIM) {
reset_parse_buffer();
elog(ERROR, "(8) bad cube representation; more than %d dimensions\n", CUBE_MAX_DIM);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("more than %d dimensions",
CUBE_MAX_DIM)));
YYABORT;
}
@ -103,21 +124,33 @@ box:
if ( c != '\0') { /* Not at EOF */
reset_parse_buffer();
elog(ERROR, "(4) bad cube representation; garbage at or before char %d, ('%c', \\%03o)\n", pos, c, c );
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("garbage at or before char %d, ('%c', \\%03o)",
pos, c, c)));
YYABORT;
}
if ( yychar != YYEOF) {
/* There's still a lookahead token to be parsed */
reset_parse_buffer();
elog(ERROR, "(5) bad cube representation; garbage at or before char %d, ('end of input', \\%03o)\n", pos, c);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("garbage at or before char %d, ('end of input', \\%03o)",
pos, c)));
YYABORT;
}
dim = delim_count($1, ',') + 1;
if (dim > CUBE_MAX_DIM) {
reset_parse_buffer();
elog(ERROR, "(8) bad cube representation; more than %d dimensions\n", CUBE_MAX_DIM);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("more than %d dimensions",
CUBE_MAX_DIM)));
YYABORT;
}
@ -133,21 +166,33 @@ box:
if ( c != '\0') { /* Not at EOF */
reset_parse_buffer();
elog(ERROR, "(6) bad cube representation; garbage at or before char %d, ('%c', \\%03o)\n", pos, c, c);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("garbage at or before char %d, ('%c', \\%03o)",
pos, c, c)));
YYABORT;
}
if ( yychar != YYEOF) {
/* There's still a lookahead token to be parsed */
reset_parse_buffer();
elog(ERROR, "(7) bad cube representation; garbage at or before char %d, ('end of input', \\%03o)\n", pos, c);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("garbage at or before char %d, ('end of input', \\%03o)",
pos, c)));
YYABORT;
}
dim = delim_count($1, ',') + 1;
if (dim > CUBE_MAX_DIM) {
reset_parse_buffer();
elog(ERROR, "(8) bad cube representation; more than %d dimensions\n", CUBE_MAX_DIM);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("more than %d dimensions",
CUBE_MAX_DIM)));
YYABORT;
}
*((void **)result) = write_point_as_box($1, dim);
@ -191,7 +236,7 @@ int cube_yyerror ( char *msg ) {
snprintf(
buf,
256,
"%s at or before position %d, character ('%c', \\%03o), input: '%s'\n",
"%s at or before position %d, character ('%c', \\%03o), input: '%s'",
msg,
position,
parse_buffer()[position - 1],
@ -200,7 +245,11 @@ int cube_yyerror ( char *msg ) {
);
reset_parse_buffer();
elog(ERROR, "%s", buf);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad cube representation"),
errdetail("%s", buf)));
return 0;
}

View File

@ -6,8 +6,9 @@
-- does not depend on contents of cube.sql.
--
\set ECHO none
psql:cube.sql:10: NOTICE: ProcedureCreate: type cube is not yet defined
psql:cube.sql:15: NOTICE: Argument type "cube" is only a shell
psql:cube.sql:10: NOTICE: type cube is not yet defined
DETAIL: Creating a shell type definition.
psql:cube.sql:15: NOTICE: argument type cube is only a shell
--
-- testing the input and output functions
--
@ -256,89 +257,89 @@ SELECT '[(0,0,0,0),(1,0,0,0)]'::cube AS cube;
-- invalid input: parse errors
SELECT ''::cube AS cube;
ERROR: cube_in: can't parse an empty string
ERROR: can't parse an empty string
SELECT 'ABC'::cube AS cube;
ERROR: syntax error at or before position 1, character ('A', \101), input: 'ABC'
ERROR: bad cube representation
DETAIL: syntax error at or before position 1, character ('A', \101), input: 'ABC'
SELECT '()'::cube AS cube;
ERROR: syntax error at or before position 2, character (')', \051), input: '()'
ERROR: bad cube representation
DETAIL: syntax error at or before position 2, character (')', \051), input: '()'
SELECT '[]'::cube AS cube;
ERROR: syntax error at or before position 2, character (']', \135), input: '[]'
ERROR: bad cube representation
DETAIL: syntax error at or before position 2, character (']', \135), input: '[]'
SELECT '[()]'::cube AS cube;
ERROR: syntax error at or before position 3, character (')', \051), input: '[()]'
ERROR: bad cube representation
DETAIL: syntax error at or before position 3, character (')', \051), input: '[()]'
SELECT '[(1)]'::cube AS cube;
ERROR: syntax error at or before position 5, character (']', \135), input: '[(1)]'
ERROR: bad cube representation
DETAIL: syntax error at or before position 5, character (']', \135), input: '[(1)]'
SELECT '[(1),]'::cube AS cube;
ERROR: syntax error at or before position 6, character (']', \135), input: '[(1),]'
ERROR: bad cube representation
DETAIL: syntax error at or before position 6, character (']', \135), input: '[(1),]'
SELECT '[(1),2]'::cube AS cube;
ERROR: syntax error at or before position 7, character (']', \135), input: '[(1),2]'
ERROR: bad cube representation
DETAIL: syntax error at or before position 7, character (']', \135), input: '[(1),2]'
SELECT '[(1),(2),(3)]'::cube AS cube;
ERROR: syntax error at or before position 9, character (',', \054), input: '[(1),(2),(3)]'
ERROR: bad cube representation
DETAIL: syntax error at or before position 9, character (',', \054), input: '[(1),(2),(3)]'
SELECT '1,'::cube AS cube;
ERROR: syntax error at or before position 2, character (',', \054), input: '1,'
ERROR: bad cube representation
DETAIL: syntax error at or before position 2, character (',', \054), input: '1,'
SELECT '1,2,'::cube AS cube;
ERROR: syntax error at or before position 4, character (',', \054), input: '1,2,'
ERROR: bad cube representation
DETAIL: syntax error at or before position 4, character (',', \054), input: '1,2,'
SELECT '1,,2'::cube AS cube;
ERROR: syntax error at or before position 3, character (',', \054), input: '1,,2'
ERROR: bad cube representation
DETAIL: syntax error at or before position 3, character (',', \054), input: '1,,2'
SELECT '(1,)'::cube AS cube;
ERROR: syntax error at or before position 4, character (')', \051), input: '(1,)'
ERROR: bad cube representation
DETAIL: syntax error at or before position 4, character (')', \051), input: '(1,)'
SELECT '(1,2,)'::cube AS cube;
ERROR: syntax error at or before position 6, character (')', \051), input: '(1,2,)'
ERROR: bad cube representation
DETAIL: syntax error at or before position 6, character (')', \051), input: '(1,2,)'
SELECT '(1,,2)'::cube AS cube;
ERROR: syntax error at or before position 4, character (',', \054), input: '(1,,2)'
ERROR: bad cube representation
DETAIL: syntax error at or before position 4, character (',', \054), input: '(1,,2)'
-- invalid input: semantic errors and trailing garbage
SELECT '[(1),(2)],'::cube AS cube; -- 0
ERROR: (0) bad cube representation; garbage at or before char 9, (',', \054)
ERROR: bad cube representation
DETAIL: garbage at or before char 9, (',', \054)
SELECT '[(1,2,3),(2,3)]'::cube AS cube; -- 1
ERROR: (1) bad cube representation; different point dimensions in (1,2,3) and (2,3)
ERROR: bad cube representation
DETAIL: different point dimensions in (1,2,3) and (2,3)
SELECT '[(1,2),(1,2,3)]'::cube AS cube; -- 1
ERROR: (1) bad cube representation; different point dimensions in (1,2) and (1,2,3)
ERROR: bad cube representation
DETAIL: different point dimensions in (1,2) and (1,2,3)
SELECT '(1),(2),'::cube AS cube; -- 2
ERROR: (2) bad cube representation; garbage at or before char 7, (',', \054)
ERROR: bad cube representation
DETAIL: garbage at or before char 7, (',', \054)
SELECT '(1,2,3),(2,3)'::cube AS cube; -- 3
ERROR: (3) bad cube representation; different point dimensions in (1,2,3) and (2,3)
ERROR: bad cube representation
DETAIL: different point dimensions in (1,2,3) and (2,3)
SELECT '(1,2),(1,2,3)'::cube AS cube; -- 3
ERROR: (3) bad cube representation; different point dimensions in (1,2) and (1,2,3)
ERROR: bad cube representation
DETAIL: different point dimensions in (1,2) and (1,2,3)
SELECT '(1,2,3)ab'::cube AS cube; -- 4
ERROR: (4) bad cube representation; garbage at or before char 8, ('b', \142)
ERROR: bad cube representation
DETAIL: garbage at or before char 8, ('b', \142)
SELECT '(1,2,3)a'::cube AS cube; -- 5
ERROR: (5) bad cube representation; garbage at or before char 8, ('end of input', \000)
ERROR: bad cube representation
DETAIL: garbage at or before char 8, ('end of input', \000)
SELECT '(1,2)('::cube AS cube; -- 5
ERROR: (5) bad cube representation; garbage at or before char 6, ('end of input', \000)
ERROR: bad cube representation
DETAIL: garbage at or before char 6, ('end of input', \000)
SELECT '1,2ab'::cube AS cube; -- 6
ERROR: (6) bad cube representation; garbage at or before char 4, ('b', \142)
ERROR: bad cube representation
DETAIL: garbage at or before char 4, ('b', \142)
SELECT '1 e7'::cube AS cube; -- 6
ERROR: (6) bad cube representation; garbage at or before char 3, ('7', \067)
ERROR: bad cube representation
DETAIL: garbage at or before char 3, ('7', \067)
SELECT '1,2a'::cube AS cube; -- 7
ERROR: (7) bad cube representation; garbage at or before char 4, ('end of input', \000)
ERROR: bad cube representation
DETAIL: garbage at or before char 4, ('end of input', \000)
SELECT '1..2'::cube AS cube; -- 7
ERROR: (7) bad cube representation; garbage at or before char 4, ('end of input', \000)
ERROR: bad cube representation
DETAIL: garbage at or before char 4, ('end of input', \000)
--
-- Testing building cubes from float8 values
--
@ -397,11 +398,11 @@ SELECT '(0)'::text::cube;
-- Testing limit of CUBE_MAX_DIM dimensions check in cube_in.
--
select '(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)'::cube;
ERROR: (8) bad cube representation; more than 100 dimensions
ERROR: bad cube representation
DETAIL: more than 100 dimensions
select '(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)'::cube;
ERROR: (8) bad cube representation; more than 100 dimensions
ERROR: bad cube representation
DETAIL: more than 100 dimensions
--
-- testing the operators
--

View File

@ -30,6 +30,7 @@
*
*/
#include "postgres.h"
#include "libpq-fe.h"
#include "fmgr.h"
#include "funcapi.h"
@ -52,7 +53,6 @@
#include "utils/array.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/palloc.h"
#include "utils/dynahash.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
@ -71,7 +71,7 @@ typedef struct remoteConn
*/
static remoteConn *getConnectionByName(const char *name);
static HTAB *createConnHash(void);
static bool createNewConnection(const char *name,remoteConn *con);
static void createNewConnection(const char *name,remoteConn *con);
static void deleteConnection(const char *name);
static char **get_pkey_attnames(Oid relid, int16 *numatts);
static char *get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals);
@ -118,21 +118,35 @@ typedef struct remoteConnHashEnt
var_ = NULL; \
} \
} while (0)
#define DBLINK_RES_ERROR(p1, p2) \
#define DBLINK_RES_INTERNALERROR(p2) \
do { \
msg = pstrdup(PQerrorMessage(conn)); \
if (res) \
PQclear(res); \
elog(ERROR, "%s: %s: %s", p1, p2, msg); \
elog(ERROR, "%s: %s", p2, msg); \
} while (0)
#define DBLINK_CONN_NOT_AVAIL(p1) \
#define DBLINK_RES_ERROR(p2) \
do { \
msg = pstrdup(PQerrorMessage(conn)); \
if (res) \
PQclear(res); \
ereport(ERROR, \
(errcode(ERRCODE_SYNTAX_ERROR), \
errmsg("%s", p2), \
errdetail("%s", msg))); \
} while (0)
#define DBLINK_CONN_NOT_AVAIL \
do { \
if(conname) \
elog(ERROR, "%s: connection %s not available", p1, conname); \
ereport(ERROR, \
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST), \
errmsg("connection \"%s\" not available", conname))); \
else \
elog(ERROR, "%s: connection not available", p1); \
ereport(ERROR, \
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST), \
errmsg("connection not available"))); \
} while (0)
#define DBLINK_GET_CONN(p1) \
#define DBLINK_GET_CONN \
do { \
char *conname_or_str = GET_STR(PG_GETARG_TEXT_P(0)); \
rcon = getConnectionByName(conname_or_str); \
@ -149,7 +163,10 @@ typedef struct remoteConnHashEnt
{ \
msg = pstrdup(PQerrorMessage(conn)); \
PQfinish(conn); \
elog(ERROR, "%s: connection error: %s", p1, msg); \
ereport(ERROR, \
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), \
errmsg("could not establish connection"), \
errdetail("%s", msg))); \
} \
} \
} while (0)
@ -191,18 +208,17 @@ dblink_connect(PG_FUNCTION_ARGS)
PQfinish(conn);
if(rcon)
pfree(rcon);
elog(ERROR, "dblink_connect: connection error: %s", msg);
ereport(ERROR,
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
errmsg("could not establish connection"),
errdetail("%s", msg)));
}
if(connname)
{
rcon->con = conn;
if(createNewConnection(connname, rcon) == false)
{
PQfinish(conn);
pfree(rcon);
elog(ERROR, "dblink_connect: cannot save named connection");
}
createNewConnection(connname, rcon);
}
else
persistent_conn = conn;
@ -217,14 +233,14 @@ PG_FUNCTION_INFO_V1(dblink_disconnect);
Datum
dblink_disconnect(PG_FUNCTION_ARGS)
{
char *str = NULL;
char *conname = NULL;
remoteConn *rcon = NULL;
PGconn *conn = NULL;
if (PG_NARGS() ==1 )
{
str = GET_STR(PG_GETARG_TEXT_P(0));
rcon = getConnectionByName(str);
conname = GET_STR(PG_GETARG_TEXT_P(0));
rcon = getConnectionByName(conname);
if (rcon)
conn = rcon->con;
}
@ -232,18 +248,12 @@ dblink_disconnect(PG_FUNCTION_ARGS)
conn = persistent_conn;
if (!conn)
{
if (str)
elog(ERROR,"dblink_disconnect: connection named \"%s\" not found",
str);
else
elog(ERROR,"dblink_disconnect: connection not found");
}
DBLINK_CONN_NOT_AVAIL;
PQfinish(conn);
if (rcon)
{
deleteConnection(str);
deleteConnection(conname);
pfree(rcon);
}
@ -283,11 +293,11 @@ dblink_open(PG_FUNCTION_ARGS)
}
if (!conn)
DBLINK_CONN_NOT_AVAIL("dblink_open");
DBLINK_CONN_NOT_AVAIL;
res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
DBLINK_RES_ERROR("dblink_open", "begin error");
DBLINK_RES_INTERNALERROR("begin error");
PQclear(res);
@ -296,7 +306,7 @@ dblink_open(PG_FUNCTION_ARGS)
if (!res ||
(PQresultStatus(res) != PGRES_COMMAND_OK &&
PQresultStatus(res) != PGRES_TUPLES_OK))
DBLINK_RES_ERROR("dblink_open", "sql error");
DBLINK_RES_ERROR("sql error");
PQclear(res);
@ -333,21 +343,21 @@ dblink_close(PG_FUNCTION_ARGS)
}
if (!conn)
DBLINK_CONN_NOT_AVAIL("dblink_close");
DBLINK_CONN_NOT_AVAIL;
appendStringInfo(str, "CLOSE %s", curname);
/* close the cursor */
res = PQexec(conn, str->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
DBLINK_RES_ERROR("dblink_close", "sql error");
DBLINK_RES_ERROR("sql error");
PQclear(res);
/* commit the transaction */
res = PQexec(conn, "COMMIT");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
DBLINK_RES_ERROR("dblink_close", "commit error");
DBLINK_RES_INTERNALERROR("commit error");
PQclear(res);
@ -402,7 +412,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
}
if(!conn)
DBLINK_CONN_NOT_AVAIL("dblink_fetch");
DBLINK_CONN_NOT_AVAIL;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@ -420,13 +430,15 @@ dblink_fetch(PG_FUNCTION_ARGS)
(PQresultStatus(res) != PGRES_COMMAND_OK &&
PQresultStatus(res) != PGRES_TUPLES_OK))
{
DBLINK_RES_ERROR("dblink_fetch", "sql error");
DBLINK_RES_ERROR("sql error");
}
else if (PQresultStatus(res) == PGRES_COMMAND_OK)
{
/* cursor does not exist - closed already or bad name */
PQclear(res);
elog(ERROR, "dblink_fetch: cursor not found: %s", curname);
ereport(ERROR,
(errcode(ERRCODE_INVALID_CURSOR_NAME),
errmsg("cursor \"%s\" does not exist", curname)));
}
funcctx->max_calls = PQntuples(res);
@ -447,7 +459,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
else if (functyptype == 'p' && functypeid == RECORDOID)
tupdesc = pgresultGetTupleDesc(res);
else
elog(ERROR, "dblink_fetch: return type must be a row type");
/* shouldn't happen */
elog(ERROR, "return type must be a row type");
/* store needed metadata for subsequent calls */
slot = TupleDescGetSlot(tupdesc);
@ -549,7 +562,7 @@ dblink_record(PG_FUNCTION_ARGS)
if (PG_NARGS() == 2)
{
DBLINK_GET_CONN("dblink");
DBLINK_GET_CONN;
sql = GET_STR(PG_GETARG_TEXT_P(1));
}
else if (PG_NARGS() == 1)
@ -558,14 +571,15 @@ dblink_record(PG_FUNCTION_ARGS)
sql = GET_STR(PG_GETARG_TEXT_P(0));
}
else
elog(ERROR, "dblink: wrong number of arguments");
/* shouldn't happen */
elog(ERROR, "wrong number of arguments");
if(!conn)
DBLINK_CONN_NOT_AVAIL("dblink_record");
DBLINK_CONN_NOT_AVAIL;
res = PQexec(conn, sql);
if (!res || (PQresultStatus(res) != PGRES_COMMAND_OK && PQresultStatus(res) != PGRES_TUPLES_OK))
DBLINK_RES_ERROR("dblink", "sql error");
DBLINK_RES_ERROR("sql error");
if (PQresultStatus(res) == PGRES_COMMAND_OK)
{
@ -608,7 +622,8 @@ dblink_record(PG_FUNCTION_ARGS)
else if (functyptype == 'p' && functypeid == RECORDOID)
tupdesc = pgresultGetTupleDesc(res);
else
elog(ERROR, "dblink: return type must be a row type");
/* shouldn't happen */
elog(ERROR, "return type must be a row type");
}
/* store needed metadata for subsequent calls */
@ -697,7 +712,7 @@ dblink_exec(PG_FUNCTION_ARGS)
if (PG_NARGS() == 2)
{
DBLINK_GET_CONN("dblink_exec");
DBLINK_GET_CONN;
sql = GET_STR(PG_GETARG_TEXT_P(1));
}
else if (PG_NARGS() == 1)
@ -706,16 +721,17 @@ dblink_exec(PG_FUNCTION_ARGS)
sql = GET_STR(PG_GETARG_TEXT_P(0));
}
else
elog(ERROR, "dblink_exec: wrong number of arguments");
/* shouldn't happen */
elog(ERROR, "wrong number of arguments");
if(!conn)
DBLINK_CONN_NOT_AVAIL("dblink_exec");
DBLINK_CONN_NOT_AVAIL;
res = PQexec(conn, sql);
if (!res ||
(PQresultStatus(res) != PGRES_COMMAND_OK &&
PQresultStatus(res) != PGRES_TUPLES_OK))
DBLINK_RES_ERROR("dblink_exec", "sql error");
DBLINK_RES_ERROR("sql error");
if (PQresultStatus(res) == PGRES_COMMAND_OK)
{
@ -731,7 +747,9 @@ dblink_exec(PG_FUNCTION_ARGS)
sql_cmd_status = GET_TEXT(PQcmdStatus(res));
}
else
elog(ERROR, "dblink_exec: queries returning results not allowed");
ereport(ERROR,
(errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
errmsg("statement returning results not allowed")));
PQclear(res);
@ -780,8 +798,10 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
/* convert relname to rel Oid */
relid = get_relid_from_relname(PG_GETARG_TEXT_P(0));
if (!OidIsValid(relid))
elog(ERROR, "dblink_get_pkey: relation does not exist");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
GET_STR(PG_GETARG_TEXT_P(0)))));
/*
* need a tuple descriptor representing one INT and one TEXT
* column
@ -920,20 +940,28 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
*/
relid = get_relid_from_relname(relname_text);
if (!OidIsValid(relid))
elog(ERROR, "dblink_build_sql_insert: relation does not exist");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
GET_STR(relname_text))));
pkattnums = (int16 *) PG_GETARG_POINTER(1);
pknumatts_tmp = PG_GETARG_INT32(2);
if (pknumatts_tmp <= SHRT_MAX)
pknumatts = pknumatts_tmp;
else
elog(ERROR, "Bad input value for pknumatts; too large");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input for number of primary key " \
"attributes too large")));
/*
* There should be at least one key attribute
*/
if (pknumatts == 0)
elog(ERROR, "dblink_build_sql_insert: number of key attributes must be > 0.");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of key attributes must be > 0")));
src_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3);
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4);
@ -950,7 +978,10 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
* There should be one source array key value for each key attnum
*/
if (src_nitems != pknumatts)
elog(ERROR, "dblink_build_sql_insert: source key array length does not match number of key attributes.");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("source key array length must match number of key " \
"attributes")));
/*
* get array of pointers to c-strings from the input source array
@ -980,7 +1011,10 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
* There should be one target array key value for each key attnum
*/
if (tgt_nitems != pknumatts)
elog(ERROR, "dblink_build_sql_insert: target key array length does not match number of key attributes.");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("target key array length must match number of key " \
"attributes")));
/*
* get array of pointers to c-strings from the input target array
@ -1053,20 +1087,28 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
*/
relid = get_relid_from_relname(relname_text);
if (!OidIsValid(relid))
elog(ERROR, "dblink_build_sql_delete: relation does not exist");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
GET_STR(relname_text))));
pkattnums = (int16 *) PG_GETARG_POINTER(1);
pknumatts_tmp = PG_GETARG_INT32(2);
if (pknumatts_tmp <= SHRT_MAX)
pknumatts = pknumatts_tmp;
else
elog(ERROR, "Bad input value for pknumatts; too large");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input for number of primary key " \
"attributes too large")));
/*
* There should be at least one key attribute
*/
if (pknumatts == 0)
elog(ERROR, "dblink_build_sql_insert: number of key attributes must be > 0.");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of key attributes must be > 0")));
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3);
@ -1082,7 +1124,10 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
* There should be one target array key value for each key attnum
*/
if (tgt_nitems != pknumatts)
elog(ERROR, "dblink_build_sql_insert: target key array length does not match number of key attributes.");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("target key array length must match number of key " \
"attributes")));
/*
* get array of pointers to c-strings from the input target array
@ -1164,20 +1209,28 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
*/
relid = get_relid_from_relname(relname_text);
if (!OidIsValid(relid))
elog(ERROR, "dblink_build_sql_update: relation does not exist");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
GET_STR(relname_text))));
pkattnums = (int16 *) PG_GETARG_POINTER(1);
pknumatts_tmp = PG_GETARG_INT32(2);
if (pknumatts_tmp <= SHRT_MAX)
pknumatts = pknumatts_tmp;
else
elog(ERROR, "Bad input value for pknumatts; too large");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input for number of primary key " \
"attributes too large")));
/*
* There should be one source array key values for each key attnum
*/
if (pknumatts == 0)
elog(ERROR, "dblink_build_sql_insert: number of key attributes must be > 0.");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of key attributes must be > 0")));
src_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3);
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4);
@ -1194,7 +1247,10 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
* There should be one source array key value for each key attnum
*/
if (src_nitems != pknumatts)
elog(ERROR, "dblink_build_sql_insert: source key array length does not match number of key attributes.");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("source key array length must match number of key " \
"attributes")));
/*
* get array of pointers to c-strings from the input source array
@ -1224,7 +1280,10 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
* There should be one target array key value for each key attnum
*/
if (tgt_nitems != pknumatts)
elog(ERROR, "dblink_build_sql_insert: target key array length does not match number of key attributes.");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("target key array length must match number of key " \
"attributes")));
/*
* get array of pointers to c-strings from the input target array
@ -1358,7 +1417,9 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
tuple = get_tuple_of_interest(relid, pkattnums, pknumatts, src_pkattvals);
if (!tuple)
elog(ERROR, "dblink_build_sql_insert: row not found");
ereport(ERROR,
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source row not found")));
appendStringInfo(str, "INSERT INTO %s(", relname);
@ -1428,7 +1489,7 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval
int natts;
StringInfo str = makeStringInfo();
char *sql;
char *val;
char *val = NULL;
int i;
/* get relation name including any needed schema prefix and quoting */
@ -1455,10 +1516,8 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval
if (tgt_pkattvals != NULL)
val = pstrdup(tgt_pkattvals[i]);
else
{
elog(ERROR, "Target key array must not be NULL");
val = NULL; /* keep compiler quiet */
}
/* internal error */
elog(ERROR, "target key array must not be NULL");
if (val != NULL)
{
@ -1504,7 +1563,9 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
tuple = get_tuple_of_interest(relid, pkattnums, pknumatts, src_pkattvals);
if (!tuple)
elog(ERROR, "dblink_build_sql_update: row not found");
ereport(ERROR,
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source row not found")));
appendStringInfo(str, "UPDATE %s SET ", relname);
@ -1652,7 +1713,8 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p
* Connect to SPI manager
*/
if ((ret = SPI_connect()) < 0)
elog(ERROR, "get_tuple_of_interest: SPI_connect returned %d", ret);
/* internal error */
elog(ERROR, "SPI connect failure - returned %d", ret);
/*
* Build sql statement to look up tuple of interest Use src_pkattvals
@ -1694,7 +1756,10 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p
* Only allow one qualifying tuple
*/
if ((ret == SPI_OK_SELECT) && (SPI_processed > 1))
elog(ERROR, "get_tuple_of_interest: Source criteria may not match more than one record.");
ereport(ERROR,
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source criteria matched more than one record")));
else if (ret == SPI_OK_SELECT && SPI_processed == 1)
{
SPITupleTable *tuptable = SPI_tuptable;
@ -1750,6 +1815,7 @@ pgresultGetTupleDesc(PGresult *res)
*/
natts = PQnfields(res);
if (natts < 1)
/* shouldn't happen */
elog(ERROR, "cannot create a description for empty results");
desc = CreateTemplateTupleDesc(natts, false);
@ -1770,10 +1836,13 @@ pgresultGetTupleDesc(PGresult *res)
atttypmod = PQfmod(res, i);
if (PQfsize(res, i) != get_typlen(atttypid))
elog(ERROR, "Size of remote field \"%s\" does not match size "
"of local type \"%s\"",
attname,
format_type_with_typemod(atttypid, atttypmod));
ereport(ERROR,
(errcode(ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH),
errmsg("field size mismatch"),
errdetail("Size of remote field \"%s\" does not match " \
"size of local type \"%s\".", attname,
format_type_with_typemod(atttypid,
atttypmod))));
attdim = 0;
attisset = false;
@ -1803,7 +1872,8 @@ generate_relation_name(Oid relid)
ObjectIdGetDatum(relid),
0, 0, 0);
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup of relation %u failed", relid);
elog(ERROR, "cache lookup failed for relation %u", relid);
reltup = (Form_pg_class) GETSTRUCT(tp);
/* Qualify the name if not visible in search path */
@ -1852,12 +1922,14 @@ createConnHash(void)
ptr=hash_create("Remote Con hash", NUMCONN, &ctl, HASH_ELEM);
if(!ptr)
elog(ERROR,"Can not create connections hash table. Out of memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
return(ptr);
}
static bool
static void
createNewConnection(const char *name, remoteConn *con)
{
remoteConnHashEnt *hentry;
@ -1865,7 +1937,7 @@ createNewConnection(const char *name, remoteConn *con)
char key[NAMEDATALEN];
if(!remoteConnHash)
remoteConnHash=createConnHash();
remoteConnHash = createConnHash();
MemSet(key, 0, NAMEDATALEN);
snprintf(key, NAMEDATALEN - 1, "%s", name);
@ -1873,18 +1945,17 @@ createNewConnection(const char *name, remoteConn *con)
HASH_ENTER, &found);
if(!hentry)
elog(ERROR, "failed to create connection");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if(found)
{
elog(NOTICE, "cannot use a connection name more than once");
return false;
}
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("duplicate connection name")));
hentry->rcon = con;
strncpy(hentry->name, name, NAMEDATALEN - 1);
return true;
}
static void
@ -1904,5 +1975,8 @@ deleteConnection(const char *name)
key, HASH_REMOVE, &found);
if(!hentry)
elog(WARNING,"Trying to delete a connection that does not exist");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("undefined connection name")));
}

View File

@ -8,7 +8,7 @@ SET search_path = public;
-- contents of dblink.sql.
\set ECHO none
CREATE TABLE foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo'
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
INSERT INTO foo VALUES (0,'a','{"a0","b0","c0"}');
INSERT INTO foo VALUES (1,'b','{"a1","b1","c1"}');
INSERT INTO foo VALUES (2,'c','{"a2","b2","c2"}');
@ -62,7 +62,7 @@ SELECT dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}');
-- retest using a quoted and schema qualified table
CREATE SCHEMA "MySchema";
CREATE TABLE "MySchema"."Foo"(f1 int, f2 text, f3 text[], primary key (f1,f2));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'Foo_pkey' for table 'Foo'
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "Foo_pkey" for table "Foo"
INSERT INTO "MySchema"."Foo" VALUES (0,'a','{"a0","b0","c0"}');
-- list the primary key fields
SELECT *
@ -110,7 +110,7 @@ WHERE t.a > 7;
SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
ERROR: dblink_record: connection not available
ERROR: connection not available
-- create a persistent connection
SELECT dblink_connect('dbname=regression');
dblink_connect
@ -172,10 +172,10 @@ SELECT dblink_close('rmt_foo_cursor');
OK
(1 row)
-- should generate "cursor not found: rmt_foo_cursor" error
-- should generate 'cursor "rmt_foo_cursor" not found' error
SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
ERROR: dblink_fetch: cursor not found: rmt_foo_cursor
ERROR: cursor "rmt_foo_cursor" does not exist
-- close the persistent connection
SELECT dblink_disconnect();
dblink_disconnect
@ -187,7 +187,8 @@ SELECT dblink_disconnect();
SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
ERROR: dblink: sql error: no connection to the server
ERROR: sql error
DETAIL: no connection to the server
-- put more data into our slave table, first using arbitrary connection syntax
-- but truncate the actual return value so we can use diff to check for success
@ -276,7 +277,8 @@ SELECT dblink_disconnect();
SELECT *
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
ERROR: dblink: connection error: missing "=" after "myconn" in connection info string
ERROR: could not establish connection
DETAIL: missing "=" after "myconn" in connection info string
-- create a named persistent connection
SELECT dblink_connect('myconn','dbname=regression');
@ -297,10 +299,9 @@ WHERE t.a > 7;
(3 rows)
-- create a second named persistent connection
-- should error with "cannot save named connection"
-- should error with "duplicate connection name"
SELECT dblink_connect('myconn','dbname=regression');
NOTICE: cannot use a connection name more than once
ERROR: dblink_connect: cannot save named connection
ERROR: duplicate connection name
-- create a second named persistent connection with a new name
SELECT dblink_connect('myconn2','dbname=regression');
dblink_connect
@ -371,10 +372,10 @@ SELECT dblink_close('myconn','rmt_foo_cursor');
OK
(1 row)
-- should generate "cursor not found: rmt_foo_cursor" error
-- should generate 'cursor "rmt_foo_cursor" not found' error
SELECT *
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
ERROR: dblink_fetch: cursor not found: rmt_foo_cursor
ERROR: cursor "rmt_foo_cursor" does not exist
-- close the named persistent connection
SELECT dblink_disconnect('myconn');
dblink_disconnect
@ -386,7 +387,8 @@ SELECT dblink_disconnect('myconn');
SELECT *
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
ERROR: dblink: connection error: missing "=" after "myconn" in connection info string
ERROR: could not establish connection
DETAIL: missing "=" after "myconn" in connection info string
-- create a named persistent connection
SELECT dblink_connect('myconn','dbname=regression');
@ -461,6 +463,6 @@ SELECT dblink_disconnect('myconn');
(1 row)
-- close the named persistent connection again
-- should get "connection named "myconn" not found" error
-- should get 'connection "myconn" not available' error
SELECT dblink_disconnect('myconn');
ERROR: dblink_disconnect: connection named "myconn" not found
ERROR: connection "myconn" not available

View File

@ -98,7 +98,7 @@ FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
-- close the cursor
SELECT dblink_close('rmt_foo_cursor');
-- should generate "cursor not found: rmt_foo_cursor" error
-- should generate 'cursor "rmt_foo_cursor" not found' error
SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
@ -162,7 +162,7 @@ FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
-- create a second named persistent connection
-- should error with "cannot save named connection"
-- should error with "duplicate connection name"
SELECT dblink_connect('myconn','dbname=regression');
-- create a second named persistent connection with a new name
@ -193,7 +193,7 @@ FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
-- close the cursor
SELECT dblink_close('myconn','rmt_foo_cursor');
-- should generate "cursor not found: rmt_foo_cursor" error
-- should generate 'cursor "rmt_foo_cursor" not found' error
SELECT *
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
@ -236,5 +236,5 @@ WHERE a = 11;
SELECT dblink_disconnect('myconn');
-- close the named persistent connection again
-- should get "connection named "myconn" not found" error
-- should get 'connection "myconn" not available' error
SELECT dblink_disconnect('myconn');

View File

@ -1,6 +1,6 @@
/****************************************************************************
* pending.c
* $Id: pending.c,v 1.11 2003/03/20 03:58:13 momjian Exp $
* $Id: pending.c,v 1.12 2003/07/24 17:52:20 tgl Exp $
*
* This file contains a trigger for Postgresql-7.x to record changes to tables
* to a pending table for mirroring.
@ -127,12 +127,15 @@ recordchange(PG_FUNCTION_ARGS)
if (storePending(fullyqualtblname, beforeTuple, afterTuple, tupdesc, trigdata, op))
{
/* An error occoured. Skip the operation. */
elog(ERROR, "Operation could not be mirrored");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("operation could not be mirrored")));
return PointerGetDatum(NULL);
}
#if defined DEBUG_OUTPUT
elog(NOTICE, "Returning on success");
elog(NOTICE, "returning on success");
#endif
SPI_pfree(fullyqualtblname);
SPI_finish();
@ -175,7 +178,7 @@ storePending(char *cpTableName, HeapTuple tBeforeTuple,
vpPlan = SPI_prepare(cpQueryBase, 3, taPlanArgTypes);
if (vpPlan == NULL)
elog(NOTICE, "Error creating plan");
elog(NOTICE, "error creating plan");
/* SPI_saveplan(vpPlan); */
saPlanData[0] = PointerGetDatum(cpTableName);
@ -218,7 +221,7 @@ storePending(char *cpTableName, HeapTuple tBeforeTuple,
}
#if defined DEBUG_OUTPUT
elog(NOTICE, "Done storing keyinfo");
elog(NOTICE, "done storing keyinfo");
#endif
return iResult;
@ -241,19 +244,21 @@ storeKeyInfo(char *cpTableName, HeapTuple tTupleData,
pplan = SPI_prepare(insQuery, 1, saPlanArgTypes);
if (pplan == NULL)
{
elog(NOTICE, "Could not prepare INSERT plan");
elog(NOTICE, "could not prepare INSERT plan");
return -1;
}
/* pplan = SPI_saveplan(pplan); */
cpKeyData = packageData(tTupleData, tTupleDesc, tpTrigData, PRIMARY);
if (cpKeyData == NULL)
{
elog(ERROR,"Could not determine primary key data");
return -1;
}
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
/* cpTableName already contains quotes... */
errmsg("there is no PRIMARY KEY for table %s",
cpTableName)));
#if defined DEBUG_OUTPUT
elog(NOTICE, "KeyData: %s", cpKeyData);
elog(NOTICE, "key data: %s", cpKeyData);
#endif
saPlanData[0] = PointerGetDatum(cpKeyData);
@ -264,11 +269,11 @@ storeKeyInfo(char *cpTableName, HeapTuple tTupleData,
if (iRetCode != SPI_OK_INSERT)
{
elog(NOTICE, "Error inserting row in pendingDelete");
elog(NOTICE, "error inserting row in pendingDelete");
return -1;
}
#if defined DEBUG_OUTPUT
elog(NOTICE, "Insert successful");
elog(NOTICE, "insert successful");
#endif
return 0;
@ -294,11 +299,9 @@ getPrimaryKey(Oid tblOid)
query = SPI_palloc(strlen(queryBase) + MAX_OID_LEN + 1);
sprintf(query, "%s%d", queryBase, tblOid);
ret = SPI_exec(query, 1);
SPI_pfree(query);
if (ret != SPI_OK_SELECT || SPI_processed != 1)
{
elog(NOTICE, "Could not select primary index key");
return NULL;
}
resTuple = SPI_tuptable->vals[0];
resDatum = SPI_getbinval(resTuple, SPI_tuptable->tupdesc, 1, &isNull);
@ -307,7 +310,6 @@ getPrimaryKey(Oid tblOid)
resultKey = SPI_palloc(sizeof(int2vector));
memcpy(resultKey, tpResultKey, sizeof(int2vector));
SPI_pfree(query);
return resultKey;
}
@ -329,7 +331,7 @@ storeData(char *cpTableName, HeapTuple tTupleData, TupleDesc tTupleDesc,
pplan = SPI_prepare(insQuery, 1, planArgTypes);
if (pplan == NULL)
{
elog(NOTICE, "Could not prepare INSERT plan");
elog(NOTICE, "could not prepare INSERT plan");
return -1;
}
@ -347,11 +349,11 @@ storeData(char *cpTableName, HeapTuple tTupleData, TupleDesc tTupleDesc,
if (iRetValue != SPI_OK_INSERT)
{
elog(NOTICE, "Error inserting row in pendingDelete");
elog(NOTICE, "error inserting row in pendingDelete");
return -1;
}
#if defined DEBUG_OUTPUT
elog(NOTICE, "Insert successful");
elog(NOTICE, "insert successful");
#endif
return 0;
@ -394,7 +396,7 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc,
}
#if defined DEBUG_OUTPUT
if (tpPKeys != NULL)
elog(NOTICE, "Have primary keys");
elog(NOTICE, "have primary keys");
#endif
cpDataBlock = SPI_palloc(BUFFER_SIZE);
iDataBlockSize = BUFFER_SIZE;
@ -429,7 +431,7 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc,
* Don't use.
*/
#if defined DEBUG_OUTPUT
elog(NOTICE, "Skipping column");
elog(NOTICE, "skipping column");
#endif
continue;
}
@ -437,7 +439,7 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc,
cpFieldName = DatumGetPointer(NameGetDatum(&tTupleDesc->attrs
[iColumnCounter - 1]->attname));
#if defined DEBUG_OUTPUT
elog(NOTICE, "FieldName: %s", cpFieldName);
elog(NOTICE, "field name: %s", cpFieldName);
#endif
while (iDataBlockSize - iUsedDataBlock < strlen(cpFieldName) + 6)
{
@ -465,8 +467,8 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc,
}
#if defined DEBUG_OUTPUT
elog(NOTICE, "FieldData: %s", cpFieldData);
elog(NOTICE, "Starting format loop");
elog(NOTICE, "field data: \"%s\"", cpFieldData);
elog(NOTICE, "starting format loop");
#endif
while (*cpUnFormatedPtr != 0)
{
@ -499,14 +501,14 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc,
sprintf(cpFormatedPtr, "' ");
iUsedDataBlock = iUsedDataBlock + 2;
#if defined DEBUG_OUTPUT
elog(NOTICE, "DataBlock: %s", cpDataBlock);
elog(NOTICE, "data block: \"%s\"", cpDataBlock);
#endif
} /* for iColumnCounter */
if (tpPKeys != NULL)
SPI_pfree(tpPKeys);
#if defined DEBUG_OUTPUT
elog(NOTICE, "Returning: DataBlockSize:%d iUsedDataBlock:%d",iDataBlockSize,
elog(NOTICE, "returning DataBlockSize:%d iUsedDataBlock:%d",iDataBlockSize,
iUsedDataBlock);
#endif
memset(cpDataBlock + iUsedDataBlock, 0, iDataBlockSize - iUsedDataBlock);

View File

@ -52,13 +52,17 @@ database_size(PG_FUNCTION_ARGS)
dbid = get_database_oid(NameStr(*dbname));
if (!OidIsValid(dbid))
elog(ERROR, "database %s does not exist", NameStr(*dbname));
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", NameStr(*dbname))));
dbpath = GetDatabasePath(dbid);
dirdesc = opendir(dbpath);
if (!dirdesc)
elog(ERROR, "could not open directory %s: %s", dbpath, strerror(errno));
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m", dbpath)));
totalsize = 0;
for (;;)
@ -71,7 +75,9 @@ database_size(PG_FUNCTION_ARGS)
if (!direntry)
{
if (errno)
elog(ERROR, "error reading directory: %s", strerror(errno));
ereport(ERROR,
(errcode_for_file_access(),
errmsg("error reading directory: %m")));
else
break;
}
@ -79,7 +85,10 @@ database_size(PG_FUNCTION_ARGS)
fullname = psnprintf(strlen(dbpath) + 1 + strlen(direntry->d_name) + 1,
"%s/%s", dbpath, direntry->d_name);
if (stat(fullname, &statbuf) == -1)
elog(ERROR, "could not stat %s: %s", fullname, strerror(errno));
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not stat \"%s\": %m", fullname)));
totalsize += statbuf.st_size;
pfree(fullname);
}
@ -133,7 +142,9 @@ relation_size(PG_FUNCTION_ARGS)
if (errno == ENOENT)
break;
else
elog(ERROR, "could not stat %s: %m", fullname);
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not stat \"%s\": %m", fullname)));
}
totalsize += statbuf.st_size;
pfree(fullname);

View File

@ -49,7 +49,7 @@ CREATE OR REPLACE FUNCTION ll_to_earth(float8, float8)
RETURNS earth
LANGUAGE 'sql'
IMMUTABLE STRICT
AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))';
AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth';
CREATE OR REPLACE FUNCTION latitude(earth)
RETURNS float8

View File

@ -6,8 +6,9 @@
-- does not depend on contents of earthdistance.sql or cube.sql.
--
\set ECHO none
psql:../cube/cube.sql:10: NOTICE: ProcedureCreate: type cube is not yet defined
psql:../cube/cube.sql:15: NOTICE: Argument type "cube" is only a shell
psql:../cube/cube.sql:10: NOTICE: type cube is not yet defined
DETAIL: Creating a shell type definition.
psql:../cube/cube.sql:15: NOTICE: argument type cube is only a shell
--
-- The radius of the Earth we are using.
--
@ -879,9 +880,8 @@ SELECT earth_box(ll_to_earth(90,180),
-- Test the recommended constraints.
--
SELECT is_point(ll_to_earth(0,0));
ERROR: Function is_point(earth) does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
ERROR: function is_point(earth) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
SELECT cube_dim(ll_to_earth(0,0)) <= 3;
?column?
----------
@ -896,9 +896,8 @@ SELECT abs(cube_distance(ll_to_earth(0,0), '(0)'::cube) / earth() - 1) <
(1 row)
SELECT is_point(ll_to_earth(30,60));
ERROR: Function is_point(earth) does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
ERROR: function is_point(earth) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
SELECT cube_dim(ll_to_earth(30,60)) <= 3;
?column?
----------
@ -913,9 +912,8 @@ SELECT abs(cube_distance(ll_to_earth(30,60), '(0)'::cube) / earth() - 1) <
(1 row)
SELECT is_point(ll_to_earth(60,90));
ERROR: Function is_point(earth) does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
ERROR: function is_point(earth) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
SELECT cube_dim(ll_to_earth(60,90)) <= 3;
?column?
----------
@ -930,9 +928,8 @@ SELECT abs(cube_distance(ll_to_earth(60,90), '(0)'::cube) / earth() - 1) <
(1 row)
SELECT is_point(ll_to_earth(-30,-90));
ERROR: Function is_point(earth) does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
ERROR: function is_point(earth) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
SELECT cube_dim(ll_to_earth(-30,-90)) <= 3;
?column?
----------

View File

@ -151,15 +151,21 @@ fti(PG_FUNCTION_ARGS)
*/
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "Full Text Indexing: Not fired by trigger manager");
/* internal error */
elog(ERROR, "not fired by trigger manager");
/* It's safe to cast now that we've checked */
trigdata = (TriggerData *) fcinfo->context;
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
elog(ERROR, "Full Text Indexing: Can't process STATEMENT events");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("can't process STATEMENT events")));
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
elog(ERROR, "Full Text Indexing: Must be fired AFTER event");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("must be fired AFTER event")));
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
isinsert = true;
@ -179,11 +185,14 @@ fti(PG_FUNCTION_ARGS)
rettuple = trigdata->tg_newtuple;
if ((ret = SPI_connect()) < 0)
elog(ERROR, "Full Text Indexing: SPI_connect: Failed, returned %d\n", ret);
/* internal error */
elog(ERROR, "SPI_connect failed, returned %d", ret);
nargs = trigger->tgnargs;
if (nargs < 2)
elog(ERROR, "Full Text Indexing: Trigger must have at least 2 arguments\n");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("fti trigger must have at least 2 arguments")));
args = trigger->tgargs;
indexname = args[0];
@ -192,7 +201,10 @@ fti(PG_FUNCTION_ARGS)
/* get oid of current tuple, needed by all, so place here */
oid = HeapTupleGetOid(rettuple);
if (!OidIsValid(oid))
elog(ERROR, "Full Text Indexing: Oid of current tuple is invalid");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("OID is not present"),
errhint("Full Text Index requires indexed tables be created WITH OIDS.")));
if (isdelete)
{
@ -216,10 +228,12 @@ fti(PG_FUNCTION_ARGS)
snprintf(query, MAX_FTI_QUERY_LENGTH, "DELETE FROM %s WHERE id = $1", indexname);
pplan = SPI_prepare(query, 1, argtypes);
if (!pplan)
elog(ERROR, "Full Text Indexing: SPI_prepare: Returned NULL in delete");
/* internal error */
elog(ERROR, "SPI_prepare returned NULL in delete");
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
elog(ERROR, "Full Text Indexing: SPI_saveplan: Returned NULL in delete");
/* internal error */
elog(ERROR, "SPI_saveplan returned NULL in delete");
plan->splan = (void **) malloc(sizeof(void *));
*(plan->splan) = pplan;
@ -230,7 +244,9 @@ fti(PG_FUNCTION_ARGS)
ret = SPI_execp(*(plan->splan), values, NULL, 0);
if (ret != SPI_OK_DELETE)
elog(ERROR, "Full Text Indexing: SPI_execp: Error executing plan in delete");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("error executing delete")));
}
if (isinsert)
@ -267,11 +283,13 @@ fti(PG_FUNCTION_ARGS)
indexname);
pplan = SPI_prepare(query, 2, argtypes);
if (!pplan)
elog(ERROR, "Full Text Indexing: SPI_prepare: Returned NULL in insert");
/* internal error */
elog(ERROR, "SPI_prepare returned NULL in insert");
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
elog(ERROR, "Full Text Indexing: SPI_saveplan: Returned NULL in insert");
/* internal error */
elog(ERROR, "SPI_saveplan returned NULL in insert");
plan->splan = (void **) malloc(sizeof(void *));
*(plan->splan) = pplan;
@ -283,7 +301,10 @@ fti(PG_FUNCTION_ARGS)
{
colnum = SPI_fnumber(tupdesc, args[i + 1]);
if (colnum == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "Full Text Indexing: SPI_fnumber: Column '%s' of '%s' not found", args[i + 1], indexname);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" of \"%s\" does not exist",
args[i + 1], indexname)));
/* Get the char* representation of the column */
column = SPI_getvalue(rettuple, tupdesc, colnum);
@ -317,7 +338,9 @@ fti(PG_FUNCTION_ARGS)
ret = SPI_execp(*(plan->splan), values, NULL, 0);
if (ret != SPI_OK_INSERT)
elog(ERROR, "Full Text Indexing: SPI_execp: Error executing plan in insert");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("error executing insert")));
}
pfree(buff);
pfree(data);

View File

@ -84,7 +84,10 @@ levenshtein(PG_FUNCTION_ARGS)
* and memory usage).
*/
if ((cols > MAX_LEVENSHTEIN_STRLEN + 1) || (rows > MAX_LEVENSHTEIN_STRLEN + 1))
elog(ERROR, "levenshtein: Arguments may not exceed %d characters in length", MAX_LEVENSHTEIN_STRLEN);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument exceeds max length: %d",
MAX_LEVENSHTEIN_STRLEN)));
/*
* If either rows or cols is 0, the answer is the other value. This
@ -214,15 +217,28 @@ metaphone(PG_FUNCTION_ARGS)
str_i_len = strlen(str_i);
if (str_i_len > MAX_METAPHONE_STRLEN)
elog(ERROR, "metaphone: Input string must not exceed %d characters", MAX_METAPHONE_STRLEN);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument exceeds max length: %d",
MAX_METAPHONE_STRLEN)));
if (!(str_i_len > 0))
elog(ERROR, "metaphone: Input string length must be > 0");
ereport(ERROR,
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
errmsg("argument is empty string")));
reqlen = PG_GETARG_INT32(1);
if (reqlen > MAX_METAPHONE_STRLEN)
elog(ERROR, "metaphone: Requested Metaphone output length must not exceed %d characters", MAX_METAPHONE_STRLEN);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("output length exceeds max length: %d",
MAX_METAPHONE_STRLEN)));
if (!(reqlen > 0))
elog(ERROR, "metaphone: Requested Metaphone output length must be > 0");
ereport(ERROR,
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
errmsg("output cannot be empty string")));
retval = _metaphone(str_i, reqlen, &metaph);
if (retval == META_SUCCESS)
@ -232,6 +248,7 @@ metaphone(PG_FUNCTION_ARGS)
}
else
{
/* internal error */
elog(ERROR, "metaphone: failure");
/*
@ -315,10 +332,12 @@ _metaphone(
/* Negative phoneme length is meaningless */
if (!(max_phonemes > 0))
/* internal error */
elog(ERROR, "metaphone: Requested output length must be > 0");
/* Empty/null string is meaningless */
if ((word == NULL) || !(strlen(word) > 0))
/* internal error */
elog(ERROR, "metaphone: Input string length must be > 0");
/*-- Allocate memory for our phoned_phrase --*/

View File

@ -160,8 +160,10 @@ int_agg_state(PG_FUNCTION_ARGS)
PGARRAY *p = GetPGArray(state, 1);
if (!p)
elog(ERROR, "No aggregate storage");
/* internal error */
elog(ERROR, "no aggregate storage");
else if (p->items >= p->lower)
/* internal error */
elog(ERROR, "aggregate storage too small");
else
p->array[p->items++] = value;
@ -190,11 +192,13 @@ int_enum(PG_FUNCTION_ARGS)
ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
if (!rsi || !IsA(rsi, ReturnSetInfo))
elog(ERROR, "No ReturnSetInfo sent! function must be declared returning a 'setof' integer");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("int_enum called in context that cannot accept a set")));
if (!p)
{
elog(WARNING, "No data sent");
elog(WARNING, "no data sent");
PG_RETURN_NULL();
}
@ -211,7 +215,8 @@ int_enum(PG_FUNCTION_ARGS)
pc->flags = TOASTED;
if (!pc->p)
{
elog(ERROR, "Error in toaster!!! no detoasting");
/* internal error */
elog(ERROR, "error in toaster; not detoasting");
PG_RETURN_NULL();
}
}

View File

@ -6,8 +6,6 @@
#include "access/itup.h"
#include "access/rtree.h"
#include "catalog/pg_type.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
@ -34,7 +32,11 @@
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : ( ( ARR_NDIM(x) ) ? (elog(ERROR,"Array is not one-dimensional: %d dimensions",ARRNELEMS( x )),1) : 0 ) ) : 0 )
#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : ( ( ARR_NDIM(x) ) ? ( \
ereport(ERROR, \
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), \
errmsg("array must be one-dimensional, not %d dimensions", ARRNELEMS( x )))) \
,1) : 0 ) ) : 0 )
#define SORT(x) \
do { \

View File

@ -177,7 +177,9 @@ makepol(WORKSTATE * state)
else
{
if (lenstack == STACKDEPTH)
elog(ERROR, "Stack too short");
ereport(ERROR,
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
errmsg("statement too complex")));
stack[lenstack] = val;
lenstack++;
}
@ -202,7 +204,9 @@ makepol(WORKSTATE * state)
break;
case ERR:
default:
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
return ERR;
}
@ -359,7 +363,7 @@ findoprnd(ITEM * ptr, int4 *pos)
{
#ifdef BS_DEBUG
elog(DEBUG3, (ptr[*pos].type == OPR) ?
"%d %c" : "%d %d ", *pos, ptr[*pos].val);
"%d %c" : "%d %d", *pos, ptr[*pos].val);
#endif
if (ptr[*pos].type == VAL)
{
@ -413,7 +417,9 @@ bqarr_in(PG_FUNCTION_ARGS)
/* make polish notation (postfix, but in reverse order) */
makepol(&state);
if (!state.num)
elog(ERROR, "Empty query");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("empty query")));
commonlen = COMPUTESIZE(state.num);
query = (QUERYTYPE *) palloc(commonlen);
@ -548,7 +554,10 @@ bqarr_out(PG_FUNCTION_ARGS)
INFIX nrm;
if (query->size == 0)
elog(ERROR, "Empty");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("empty query")));
nrm.curpol = GETQUERY(query) + query->size - 1;
nrm.buflen = 32;
nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
@ -703,7 +712,9 @@ querytree(PG_FUNCTION_ARGS)
int4 len;
if (query->size == 0)
elog(ERROR, "Empty");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("empty query")));
q = (ITEM *) palloc(sizeof(ITEM) * query->size);
memcpy((void *) q, GETQUERY(query), sizeof(ITEM) * query->size);

View File

@ -243,7 +243,9 @@ sort(PG_FUNCTION_ARGS)
&& (d[3] == 'C' || d[3] == 'c'))
dir = 0;
if (dir == -1)
elog(ERROR, "Invalid second parameter in function sort. It must be 'ASC' or 'DESC'.");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("second parameter must be \"ASC\" or \"DESC\"")));
QSORT(a, dir);
PG_RETURN_POINTER(a);
}

View File

@ -40,13 +40,17 @@ Datum _intbig_out(PG_FUNCTION_ARGS);
Datum
_intbig_in(PG_FUNCTION_ARGS) {
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("_intbig_in() not implemented")));
PG_RETURN_DATUM(0);
}
Datum
_intbig_out(PG_FUNCTION_ARGS) {
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("_intbig_out() not implemented")));
PG_RETURN_DATUM(0);
}

View File

@ -1,12 +1,14 @@
--
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of seg.sql.
-- does not depend on contents of _int.sql.
--
\set ECHO none
psql:_int.sql:13: NOTICE: ProcedureCreate: type query_int is not yet defined
psql:_int.sql:18: NOTICE: Argument type "query_int" is only a shell
psql:_int.sql:367: NOTICE: ProcedureCreate: type intbig_gkey is not yet defined
psql:_int.sql:372: NOTICE: Argument type "intbig_gkey" is only a shell
psql:_int.sql:13: NOTICE: type query_int is not yet defined
DETAIL: Creating a shell type definition.
psql:_int.sql:18: NOTICE: argument type query_int is only a shell
psql:_int.sql:367: NOTICE: type intbig_gkey is not yet defined
DETAIL: Creating a shell type definition.
psql:_int.sql:372: NOTICE: argument type intbig_gkey is only a shell
SELECT intset(1234);
intset
--------

View File

@ -1,6 +1,6 @@
--
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of seg.sql.
-- does not depend on contents of _int.sql.
--
\set ECHO none
\i _int.sql

View File

@ -1,7 +1,7 @@
/*
* PostgreSQL type definitions for ISBNs.
*
* $Id: isbn_issn.c,v 1.5 2002/11/04 17:14:29 tgl Exp $
* $Id: isbn_issn.c,v 1.6 2003/07/24 17:52:29 tgl Exp $
*/
#include "postgres.h"
@ -48,13 +48,19 @@ isbn_in(char *str)
if (strlen(str) != 13)
{
elog(ERROR, "isbn_in: invalid ISBN \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid ISBN: \"%s\"", str),
errdetail("incorrect length")));
return (NULL);
}
if (isbn_sum(str) != 0)
{
elog(ERROR, "isbn_in: purported ISBN \"%s\" failed checksum",
str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid ISBN: \"%s\"", str),
errdetail("failed checksum")));
return (NULL);
}
@ -236,13 +242,19 @@ issn_in(char *str)
if (strlen(str) != 9)
{
elog(ERROR, "issn_in: invalid ISSN \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid ISSN: \"%s\"", str),
errdetail("incorrect length")));
return (NULL);
}
if (issn_sum(str) != 0)
{
elog(ERROR, "issn_in: purported ISSN \"%s\" failed checksum",
str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid ISSN: \"%s\"", str),
errdetail("failed checksum")));
return (NULL);
}

View File

@ -1,7 +1,7 @@
/*
* PostgreSQL type definitions for managed LargeObjects.
*
* $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.12 2002/08/15 02:58:29 momjian Exp $
* $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.13 2003/07/24 17:52:30 tgl Exp $
*
*/
@ -57,10 +57,14 @@ lo_in(char *str)
count = sscanf(str, "%u", &oid);
if (count < 1)
elog(ERROR, "lo_in: error in parsing \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("error in parsing \"%s\"", str)));
if (oid == InvalidOid)
elog(ERROR, "lo_in: illegal oid \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("illegal oid: \"%s\"", str)));
}
else
{
@ -70,7 +74,8 @@ lo_in(char *str)
oid = DatumGetObjectId(DirectFunctionCall1(lo_creat,
Int32GetDatum(INV_READ | INV_WRITE)));
if (oid == InvalidOid)
elog(ERROR, "lo_in: InvalidOid returned from lo_creat");
/* internal error */
elog(ERROR, "InvalidOid returned from lo_creat");
}
result = (Blob *) palloc(sizeof(Blob));
@ -143,7 +148,8 @@ lo_manage(PG_FUNCTION_ARGS)
HeapTuple trigtuple; /* The original value of tuple */
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "lo: not fired by trigger manager");
/* internal error */
elog(ERROR, "not fired by trigger manager");
/*
* Fetch some values from trigdata

View File

@ -74,7 +74,9 @@ _ltree_compress(PG_FUNCTION_ARGS)
ltree *item = (ltree *) ARR_DATA_PTR(val);
if (ARR_NDIM(val) != 1)
elog(ERROR, "Dimension of array != 1");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
key = (ltree_gist *) palloc(len);
key->len = len;
@ -502,7 +504,9 @@ _arrq_cons(ltree_gist *key, ArrayType *_query) {
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
if (ARR_NDIM(_query) != 1)
elog(ERROR, "Dimension of array != 1");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
while (num > 0) {
if ( gist_qe(key, query) )
@ -545,7 +549,8 @@ _ltree_consistent(PG_FUNCTION_ARGS)
res = _arrq_cons(key, (ArrayType *) query);
break;
default:
elog(ERROR, "Unknown StrategyNumber: %d", strategy);
/* internal error */
elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
}
PG_RETURN_BOOL(res);
}

View File

@ -44,7 +44,9 @@ array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree ** found)
ltree *item = (ltree *) ARR_DATA_PTR(la);
if (ARR_NDIM(la) != 1)
elog(ERROR, "Dimension of array != 1");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
if (found)
*found = NULL;
@ -138,7 +140,9 @@ _lt_q_regex(PG_FUNCTION_ARGS)
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
if (ARR_NDIM(_query) != 1)
elog(ERROR, "Dimension of array != 1");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
while (num > 0) {
if ( array_iterator(_tree, ltq_regex, (void*)query, NULL) ) {

View File

@ -1,12 +1,16 @@
\set ECHO none
psql:ltree.sql:7: NOTICE: ProcedureCreate: type ltree is not yet defined
psql:ltree.sql:12: NOTICE: Argument type "ltree" is only a shell
psql:ltree.sql:299: NOTICE: ProcedureCreate: type lquery is not yet defined
psql:ltree.sql:304: NOTICE: Argument type "lquery" is only a shell
psql:ltree.sql:410: NOTICE: ProcedureCreate: type ltxtquery is not yet defined
psql:ltree.sql:415: NOTICE: Argument type "ltxtquery" is only a shell
psql:ltree.sql:477: NOTICE: ProcedureCreate: type ltree_gist is not yet defined
psql:ltree.sql:482: NOTICE: Argument type "ltree_gist" is only a shell
psql:ltree.sql:7: NOTICE: type ltree is not yet defined
DETAIL: Creating a shell type definition.
psql:ltree.sql:12: NOTICE: argument type ltree is only a shell
psql:ltree.sql:299: NOTICE: type lquery is not yet defined
DETAIL: Creating a shell type definition.
psql:ltree.sql:304: NOTICE: argument type lquery is only a shell
psql:ltree.sql:410: NOTICE: type ltxtquery is not yet defined
DETAIL: Creating a shell type definition.
psql:ltree.sql:415: NOTICE: argument type ltxtquery is only a shell
psql:ltree.sql:477: NOTICE: type ltree_gist is not yet defined
DETAIL: Creating a shell type definition.
psql:ltree.sql:482: NOTICE: argument type ltree_gist is only a shell
SELECT ''::ltree;
ltree
-------

View File

@ -317,7 +317,9 @@ lt_q_regex(PG_FUNCTION_ARGS)
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
if (ARR_NDIM(_query) != 1)
elog(ERROR, "Dimension of array != 1");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
while (num > 0) {
if (DatumGetBool(DirectFunctionCall2(ltq_regex,

View File

@ -21,14 +21,18 @@ Datum ltree_gist_out(PG_FUNCTION_ARGS);
Datum
ltree_gist_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Unimplemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("ltree_gist_in() not implemented")));
PG_RETURN_DATUM(0);
}
Datum
ltree_gist_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Unimplemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("ltree_gist_out() not implemented")));
PG_RETURN_DATUM(0);
}
@ -604,7 +608,9 @@ arrq_cons(ltree_gist *key, ArrayType *_query) {
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
if (ARR_NDIM(_query) != 1)
elog(ERROR, "Dimension of array != 1");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
while (num > 0) {
if ( gist_qe(key, query) && gist_between(key, query) )
@ -701,7 +707,8 @@ ltree_consistent(PG_FUNCTION_ARGS)
res = arrq_cons(key, (ArrayType *) query);
break;
default:
elog(ERROR, "Unknown StrategyNumber: %d", strategy);
/* internal error */
elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
}
PG_RETURN_BOOL(res);
}

View File

@ -20,7 +20,11 @@ PG_FUNCTION_INFO_V1(lquery_out);
Datum lquery_out(PG_FUNCTION_ARGS);
#define UNCHAR elog(ERROR,"Syntax error in position %d near '%c'", (int)(ptr-buf), *ptr)
#define UNCHAR ereport(ERROR, \
(errcode(ERRCODE_SYNTAX_ERROR), \
errmsg("syntax error at position %d near \"%c\"", \
(int)(ptr-buf), *ptr)));
typedef struct
{
@ -73,8 +77,13 @@ ltree_in(PG_FUNCTION_ARGS)
{
lptr->len = ptr - lptr->start;
if (lptr->len > 255)
elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d",
lptr->len, (int) (lptr->start - buf));
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
lptr->len, (int) (lptr->start - buf))));
totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
lptr++;
state = LTPRS_WAITNAME;
@ -83,7 +92,8 @@ ltree_in(PG_FUNCTION_ARGS)
UNCHAR;
}
else
elog(ERROR, "Inner error in parser");
/* internal error */
elog(ERROR, "internal error in parser");
ptr++;
}
@ -91,13 +101,21 @@ ltree_in(PG_FUNCTION_ARGS)
{
lptr->len = ptr - lptr->start;
if (lptr->len > 255)
elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d",
lptr->len, (int) (lptr->start - buf));
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
lptr->len, (int) (lptr->start - buf))));
totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
lptr++;
}
else if (!(state == LTPRS_WAITNAME && lptr == list))
elog(ERROR, "Unexpected end of line");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Unexpected end of line.")));
result = (ltree *) palloc(LTREE_HDRSIZE + totallen);
result->len = LTREE_HDRSIZE + totallen;
@ -261,8 +279,13 @@ lquery_in(PG_FUNCTION_ARGS)
((lptr->flag & LVAR_INCASE) ? 1 : 0) -
((lptr->flag & LVAR_ANYEND) ? 1 : 0);
if (lptr->len > 255)
elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d",
lptr->len, (int) (lptr->start - buf));
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
lptr->len, (int) (lptr->start - buf))));
state = LQPRS_WAITVAR;
}
else if (*ptr == '.')
@ -272,8 +295,13 @@ lquery_in(PG_FUNCTION_ARGS)
((lptr->flag & LVAR_INCASE) ? 1 : 0) -
((lptr->flag & LVAR_ANYEND) ? 1 : 0);
if (lptr->len > 255)
elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d",
lptr->len, (int) (lptr->start - buf));
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
lptr->len, (int) (lptr->start - buf))));
state = LQPRS_WAITLEVEL;
curqlevel = NEXTLEV(curqlevel);
}
@ -356,28 +384,44 @@ lquery_in(PG_FUNCTION_ARGS)
UNCHAR;
}
else
elog(ERROR, "Inner error in parser");
/* internal error */
elog(ERROR, "internal error in parser");
ptr++;
}
if (state == LQPRS_WAITDELIM)
{
if (lptr->start == ptr)
elog(ERROR, "Unexpected end of line");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Unexpected end of line.")));
lptr->len = ptr - lptr->start -
((lptr->flag & LVAR_SUBLEXEM) ? 1 : 0) -
((lptr->flag & LVAR_INCASE) ? 1 : 0) -
((lptr->flag & LVAR_ANYEND) ? 1 : 0);
if (lptr->len == 0)
elog(ERROR, "Unexpected end of line");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Unexpected end of line.")));
if (lptr->len > 255)
elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d",
lptr->len, (int) (lptr->start - buf));
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
lptr->len, (int) (lptr->start - buf))));
}
else if (state == LQPRS_WAITOPEN)
curqlevel->high = 0xffff;
else if (state != LQPRS_WAITEND)
elog(ERROR, "Unexpected end of line");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Unexpected end of line.")));
curqlevel = tmpql;
totallen = LQUERY_HDRSIZE;
@ -394,7 +438,12 @@ lquery_in(PG_FUNCTION_ARGS)
}
}
else if (curqlevel->low > curqlevel->high)
elog(ERROR, "Low limit(%d) is greater than upper(%d)", curqlevel->low, curqlevel->high);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Low limit(%d) is greater than upper(%d).",
curqlevel->low, curqlevel->high)));
curqlevel = NEXTLEV(curqlevel);
}

View File

@ -197,7 +197,9 @@ inner_subltree(ltree * t, int4 startpos, int4 endpos)
int i;
if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos > endpos)
elog(ERROR, "Wrong positions");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid positions")));
if (endpos > t->numlevel)
endpos = t->numlevel;

View File

@ -81,13 +81,17 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint1
*flag = 0;
}
else if (!isspace((unsigned int) *(state->buf)))
elog(ERROR, "Operand syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("operand syntax error")));
break;
case INOPERAND:
if (ISALNUM(*(state->buf)))
{
if (*flag)
elog(ERROR, "Modificators syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("modificators syntax error")));
(*lenval)++;
}
else if (*(state->buf) == '%')
@ -142,9 +146,13 @@ pushquery(QPRS_STATE * state, int4 type, int4 val, int4 distance, int4 lenval, u
tmp->val = val;
tmp->flag = flag;
if (distance > 0xffff)
elog(ERROR, "Value is too big");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("value is too big")));
if (lenval > 0xff)
elog(ERROR, "Operand is too long");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("operand is too long")));
tmp->distance = distance;
tmp->length = lenval;
tmp->next = state->str;
@ -159,7 +167,9 @@ static void
pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval, uint16 flag)
{
if (lenval > 0xffff)
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("word is too long")));
pushquery(state, type, ltree_crc32_sz((uint8 *) strval, lenval),
state->curop - state->op, lenval, flag);
@ -214,7 +224,8 @@ makepol(QPRS_STATE * state)
else
{
if (lenstack == STACKDEPTH)
elog(ERROR, "Stack too short");
/* internal error */
elog(ERROR, "stack too short");
stack[lenstack] = val;
lenstack++;
}
@ -239,7 +250,10 @@ makepol(QPRS_STATE * state)
break;
case ERR:
default:
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
return ERR;
}
@ -314,7 +328,11 @@ queryin(char *buf)
/* parse query & make polish notation (postfix, but in reverse order) */
makepol(&state);
if (!state.num)
elog(ERROR, "Empty query");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Empty query.")));
/* make finish struct */
commonlen = COMPUTESIZE(state.num, state.sumlen);
query = (ltxtquery *) palloc(commonlen);
@ -483,7 +501,11 @@ ltxtq_out(PG_FUNCTION_ARGS)
INFIX nrm;
if (query->size == 0)
elog(ERROR, "Empty");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Empty query.")));
nrm.curpol = GETQUERY(query);
nrm.buflen = 32;
nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);

View File

@ -40,18 +40,22 @@ noup(PG_FUNCTION_ARGS)
/* Called by trigger manager ? */
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "noup: not fired by trigger manager");
/* Should be called for ROW trigger */
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "noup: can't process STATEMENT events");
/* Not should be called for INSERT */
/* Should not be called for INSERT */
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
/* internal error */
elog(ERROR, "noup: can't process INSERT events");
/* Not should be called for DELETE */
/* Should not be called for DELETE */
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
/* internal error */
elog(ERROR, "noup: can't process DELETE events");
/* check new Tuple */
@ -67,6 +71,7 @@ noup(PG_FUNCTION_ARGS)
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "noup: SPI_connect returned %d", ret);
/*
@ -83,6 +88,7 @@ noup(PG_FUNCTION_ARGS)
/* Bad guys may give us un-existing column in CREATE TRIGGER */
if (fnumber < 0)
/* internal error */
elog(ERROR, "noup: there is no attribute %s in relation %s",
args[i], SPI_getrelname(rel));
@ -94,7 +100,6 @@ noup(PG_FUNCTION_ARGS)
*/
if (!isnull)
{
elog(WARNING, "%s: update not allowed", args[i]);
SPI_finish();
return PointerGetDatum(NULL);

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mhash.c,v 1.7 2001/11/20 18:54:07 momjian Exp $
* $Id: mhash.c,v 1.8 2003/07/24 17:52:33 tgl Exp $
*/
#include <postgres.h>
@ -143,7 +143,10 @@ cipher_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
err = mcrypt_generic_init(ctx, (char *) key, klen, (char *) iv);
if (err < 0)
elog(ERROR, "mcrypt_generic_init error: %s", mcrypt_strerror(err));
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("mcrypt_generic_init error"),
errdetail("%s", mcrypt_strerror(err))));
c->pstat = 1;
return 0;
@ -159,7 +162,10 @@ cipher_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
err = mcrypt_generic(ctx, res, dlen);
if (err < 0)
elog(ERROR, "mcrypt_generic error: %s", mcrypt_strerror(err));
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("mcrypt_generic error"),
errdetail("%s", mcrypt_strerror(err))));
return 0;
}
@ -173,7 +179,10 @@ cipher_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
err = mdecrypt_generic(ctx, res, dlen);
if (err < 0)
elog(ERROR, "mdecrypt_generic error: %s", mcrypt_strerror(err));
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("mdecrypt_generic error"),
errdetail("%s", mcrypt_strerror(err))));
return 0;
}

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: pgcrypto.c,v 1.12 2001/12/30 23:09:41 tgl Exp $
* $Id: pgcrypto.c,v 1.13 2003/07/24 17:52:33 tgl Exp $
*/
#include <postgres.h>
@ -202,7 +202,9 @@ pg_gen_salt(PG_FUNCTION_ARGS)
buf[len] = 0;
len = px_gen_salt(buf, buf, 0);
if (len == 0)
elog(ERROR, "No such crypt algorithm");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("no such crypt algorithm")));
res = (text *) palloc(len + VARHDRSZ);
VARATT_SIZEP(res) = len + VARHDRSZ;
@ -237,7 +239,9 @@ pg_gen_salt_rounds(PG_FUNCTION_ARGS)
buf[len] = 0;
len = px_gen_salt(buf, buf, rounds);
if (len == 0)
elog(ERROR, "No such crypt algorithm or bad number of rounds");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("no such crypt algorithm or bad number of rounds")));
res = (text *) palloc(len + VARHDRSZ);
VARATT_SIZEP(res) = len + VARHDRSZ;
@ -292,7 +296,9 @@ pg_crypt(PG_FUNCTION_ARGS)
pfree(buf1);
if (cres == NULL)
elog(ERROR, "crypt(3) returned NULL");
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("crypt(3) returned NULL")));
clen = strlen(cres);
@ -349,7 +355,9 @@ pg_encrypt(PG_FUNCTION_ARGS)
if (err)
{
pfree(res);
elog(ERROR, "encrypt error: %d", err);
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("encrypt error: %d", err)));
}
VARATT_SIZEP(res) = VARHDRSZ + rlen;
@ -393,7 +401,9 @@ pg_decrypt(PG_FUNCTION_ARGS)
px_combo_free(c);
if (err)
elog(ERROR, "decrypt error: %d", err);
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("decrypt error: %d", err)));
VARATT_SIZEP(res) = VARHDRSZ + rlen;
@ -446,7 +456,9 @@ pg_encrypt_iv(PG_FUNCTION_ARGS)
px_combo_free(c);
if (err)
elog(ERROR, "encrypt_iv error: %d", err);
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("encrypt_iv error: %d", err)));
VARATT_SIZEP(res) = VARHDRSZ + rlen;
@ -500,7 +512,9 @@ pg_decrypt_iv(PG_FUNCTION_ARGS)
px_combo_free(c);
if (err)
elog(ERROR, "decrypt_iv error: %d", err);
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("decrypt_iv error: %d", err)));
VARATT_SIZEP(res) = VARHDRSZ + rlen;
@ -551,7 +565,9 @@ find_provider(text *name,
{
if (silent)
return NULL;
elog(ERROR, "%s type does not exist (name too long)", desc);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("%s type does not exist (name too long)", desc)));
}
p = VARDATA(name);
@ -562,7 +578,9 @@ find_provider(text *name,
err = provider_lookup(buf, &res);
if (err && !silent)
elog(ERROR, "%s type does not exist: '%s'", desc, buf);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("%s type does not exist: \"%s\"", desc, buf)));
return err ? NULL : res;
}

View File

@ -57,10 +57,12 @@ _rserv_log_()
/* Called by trigger manager ? */
if (!CurrentTriggerData)
/* internal error */
elog(ERROR, "_rserv_log_: triggers are not initialized");
/* Should be called for ROW trigger */
if (TRIGGER_FIRED_FOR_STATEMENT(CurrentTriggerData->tg_event))
/* internal error */
elog(ERROR, "_rserv_log_: can't process STATEMENT events");
tuple = CurrentTriggerData->tg_trigtuple;
@ -70,11 +72,13 @@ _rserv_log_()
args = trigger->tgargs;
if (nargs != 1) /* odd number of arguments! */
/* internal error */
elog(ERROR, "_rserv_log_: need in *one* argument");
keynum = atoi(args[0]);
if (keynum < 0 && keynum != ObjectIdAttributeNumber)
/* internal error */
elog(ERROR, "_rserv_log_: invalid keynum %d", keynum);
rel = CurrentTriggerData->tg_relation;
@ -98,6 +102,7 @@ _rserv_log_()
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "_rserv_log_: SPI_connect returned %d", ret);
if (keynum == ObjectIdAttributeNumber)
@ -109,13 +114,17 @@ _rserv_log_()
key = SPI_getvalue(tuple, tupdesc, keynum);
if (key == NULL)
elog(ERROR, "_rserv_log_: key must be not null");
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("key must be not null")));
if (newtuple && keynum != ObjectIdAttributeNumber)
{
newkey = SPI_getvalue(newtuple, tupdesc, keynum);
if (newkey == NULL)
elog(ERROR, "_rserv_log_: key must be not null");
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("key must be not null")));
if (strcmp(newkey, key) == 0)
newkey = NULL;
else
@ -137,13 +146,18 @@ _rserv_log_()
ret = SPI_exec(sql, 0);
if (ret < 0)
elog(ERROR, "_rserv_log_: SPI_exec(update) returned %d", ret);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("SPI_exec(update) returned %d", ret)));
/*
* If no tuple was UPDATEd then do INSERT...
*/
if (SPI_processed > 1)
elog(ERROR, "_rserv_log_: duplicate tuples");
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("duplicate tuples")));
else if (SPI_processed == 0)
{
snprintf(sql, 8192, "insert into _RSERV_LOG_ "
@ -158,7 +172,9 @@ _rserv_log_()
ret = SPI_exec(sql, 0);
if (ret < 0)
elog(ERROR, "_rserv_log_: SPI_exec(insert) returned %d", ret);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("SPI_exec(insert) returned %d", ret)));
}
if (okey != key && okey != outbuf)
@ -182,7 +198,9 @@ _rserv_log_()
ret = SPI_exec(sql, 0);
if (ret < 0)
elog(ERROR, "_rserv_log_: SPI_exec returned %d", ret);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("SPI_exec returned %d", ret)));
if (okey != newkey && okey != outbuf)
pfree(okey);
@ -215,6 +233,7 @@ _rserv_sync_(int32 server)
int ret;
if (SerializableSnapshot == NULL)
/* internal error */
elog(ERROR, "_rserv_sync_: SerializableSnapshot is NULL");
buf[0] = 0;
@ -226,6 +245,7 @@ _rserv_sync_(int32 server)
}
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "_rserv_sync_: SPI_connect returned %d", ret);
snprintf(sql, 8192, "insert into _RSERV_SYNC_ "
@ -236,7 +256,9 @@ _rserv_sync_(int32 server)
ret = SPI_exec(sql, 0);
if (ret < 0)
elog(ERROR, "_rserv_sync_: SPI_exec returned %d", ret);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("SPI_exec returned %d", ret)));
SPI_finish();

View File

@ -2,8 +2,6 @@
#include "postgres.h"
#include "utils/elog.h"
static char *PARSE_BUFFER;
static char *PARSE_BUFFER_PTR;
static unsigned int PARSE_BUFFER_SIZE;
@ -26,7 +24,9 @@ set_parse_buffer(char *s)
PARSE_BUFFER = s;
PARSE_BUFFER_SIZE = strlen(s);
if (PARSE_BUFFER_SIZE == 0)
elog(ERROR, "seg_in: can't parse an empty string");
ereport(ERROR,
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
errmsg("can't parse an empty string")));
PARSE_BUFFER_PTR = PARSE_BUFFER;
SCANNER_POS = 0;
}

View File

@ -6,8 +6,9 @@
-- does not depend on contents of seg.sql.
--
\set ECHO none
psql:seg.sql:10: NOTICE: ProcedureCreate: type seg is not yet defined
psql:seg.sql:15: NOTICE: Argument type "seg" is only a shell
psql:seg.sql:10: NOTICE: type seg is not yet defined
DETAIL: Creating a shell type definition.
psql:seg.sql:15: NOTICE: argument type seg is only a shell
--
-- testing the input and output functions
--
@ -393,30 +394,38 @@ SELECT '100(+-)1'::seg AS seg;
-- invalid input
SELECT ''::seg AS seg;
ERROR: seg_in: can't parse an empty string
ERROR: can't parse an empty string
SELECT 'ABC'::seg AS seg;
ERROR: syntax error at or near position 1, character ('A', \101), input: 'ABC'
ERROR: syntax error
DETAIL: syntax error at or near position 1, character ('A', \101), input: 'ABC'
SELECT '1ABC'::seg AS seg;
ERROR: syntax error at or near position 2, character ('A', \101), input: '1ABC'
ERROR: syntax error
DETAIL: syntax error at or near position 2, character ('A', \101), input: '1ABC'
SELECT '1.'::seg AS seg;
ERROR: syntax error at or near position 2, character ('.', \056), input: '1.'
ERROR: syntax error
DETAIL: syntax error at or near position 2, character ('.', \056), input: '1.'
SELECT '1.....'::seg AS seg;
ERROR: syntax error at or near position 6, character ('.', \056), input: '1.....'
ERROR: syntax error
DETAIL: syntax error at or near position 6, character ('.', \056), input: '1.....'
SELECT '.1'::seg AS seg;
ERROR: syntax error at or near position 2, character ('1', \061), input: '.1'
ERROR: syntax error
DETAIL: syntax error at or near position 2, character ('1', \061), input: '.1'
SELECT '1..2.'::seg AS seg;
ERROR: syntax error at or near position 5, character ('.', \056), input: '1..2.'
ERROR: syntax error
DETAIL: syntax error at or near position 5, character ('.', \056), input: '1..2.'
SELECT '1 e7'::seg AS seg;
ERROR: syntax error at or near position 3, character ('e', \145), input: '1 e7'
ERROR: syntax error
DETAIL: syntax error at or near position 3, character ('e', \145), input: '1 e7'
SELECT '1e700'::seg AS seg;
ERROR: numeric value 1e700 unrepresentable
ERROR: syntax error
DETAIL: numeric value 1e700 unrepresentable
--
-- testing the operators
--

View File

@ -10,8 +10,6 @@
#include "access/gist.h"
#include "access/rtree.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/builtins.h"
#include "segdata.h"
@ -798,7 +796,7 @@ seg_cmp(SEG * a, SEG * b)
if (b->l_ext == '~')
return 1;
/* can't get here unless data is corrupt */
elog(ERROR, "seg_cmp: bogus lower boundary types %d %d",
elog(ERROR, "bogus lower boundary types %d %d",
(int) a->l_ext, (int) b->l_ext);
}
@ -857,7 +855,7 @@ seg_cmp(SEG * a, SEG * b)
if (b->u_ext == '~')
return -1;
/* can't get here unless data is corrupt */
elog(ERROR, "seg_cmp: bogus upper boundary types %d %d",
elog(ERROR, "bogus upper boundary types %d %d",
(int) a->u_ext, (int) b->u_ext);
}

View File

@ -4,8 +4,6 @@
#include "postgres.h"
#include <math.h>
#include "utils/elog.h"
#include "segdata.h"
#include "buffer.h"
@ -75,7 +73,11 @@ range:
((SEG *)result)->upper = $3.val;
if ( ((SEG *)result)->lower > ((SEG *)result)->upper ) {
reset_parse_buffer();
elog(ERROR, "swapped boundaries: %g is greater than %g", ((SEG *)result)->lower, ((SEG *)result)->upper );
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("swapped boundaries: %g is greater than %g",
((SEG *)result)->lower, ((SEG *)result)->upper)));
YYERROR;
}
((SEG *)result)->l_sigd = $1.sigd;
@ -144,7 +146,10 @@ float seg_atof ( char *value ) {
if ( errno ) {
snprintf(buf, 256, "numeric value %s unrepresentable", value);
reset_parse_buffer();
elog(ERROR, "%s", buf);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("%s", buf)));
}
return result;
@ -175,7 +180,10 @@ int seg_yyerror ( char *msg ) {
);
reset_parse_buffer();
elog(ERROR, "%s", buf);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("%s", buf)));
return 0;
}

View File

@ -25,18 +25,22 @@ autoinc(PG_FUNCTION_ARGS)
int i;
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "autoinc: not fired by trigger manager");
/* internal error */
elog(ERROR, "not fired by trigger manager");
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
elog(ERROR, "autoinc: can't process STATEMENT events");
/* internal error */
elog(ERROR, "can't process STATEMENT events");
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
elog(ERROR, "autoinc: must be fired before event");
/* internal error */
elog(ERROR, "must be fired before event");
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
rettuple = trigdata->tg_trigtuple;
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
elog(ERROR, "autoinc: can't process DELETE events");
/* internal error */
elog(ERROR, "can't process DELETE events");
rel = trigdata->tg_relation;
relname = SPI_getrelname(rel);
@ -45,6 +49,7 @@ autoinc(PG_FUNCTION_ARGS)
nargs = trigger->tgnargs;
if (nargs <= 0 || nargs % 2 != 0)
/* internal error */
elog(ERROR, "autoinc (%s): even number gt 0 of arguments was expected", relname);
args = trigger->tgargs;
@ -60,11 +65,16 @@ autoinc(PG_FUNCTION_ARGS)
Datum seqname;
if (attnum < 0)
elog(ERROR, "autoinc (%s): there is no attribute %s",
relname, args[i]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\" has no attribute \"%s\"",
relname, args[i])));
if (SPI_gettypeid(tupdesc, attnum) != INT4OID)
elog(ERROR, "autoinc (%s): attribute %s must be of INT4 type",
relname, args[i]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("attribute \"%s\" of \"%s\" must be type INT4",
args[i], relname)));
val = DatumGetInt32(SPI_getbinval(rettuple, tupdesc, attnum, &isnull));
@ -95,6 +105,7 @@ autoinc(PG_FUNCTION_ARGS)
{
rettuple = SPI_modifytuple(rel, rettuple, chnattrs, chattrs, newvals, NULL);
if (rettuple == NULL)
/* internal error */
elog(ERROR, "autoinc (%s): %d returned by SPI_modifytuple",
relname, SPI_result);
}

View File

@ -30,10 +30,13 @@ insert_username(PG_FUNCTION_ARGS)
/* sanity checks from autoinc.c */
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "insert_username: not fired by trigger manager");
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "insert_username: can't process STATEMENT events");
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
/* internal error */
elog(ERROR, "insert_username: must be fired before event");
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
@ -41,6 +44,7 @@ insert_username(PG_FUNCTION_ARGS)
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
/* internal error */
elog(ERROR, "insert_username: can't process DELETE events");
rel = trigdata->tg_relation;
@ -50,6 +54,7 @@ insert_username(PG_FUNCTION_ARGS)
nargs = trigger->tgnargs;
if (nargs != 1)
/* internal error */
elog(ERROR, "insert_username (%s): one argument was expected", relname);
args = trigger->tgargs;
@ -58,10 +63,15 @@ insert_username(PG_FUNCTION_ARGS)
attnum = SPI_fnumber(tupdesc, args[0]);
if (attnum < 0)
elog(ERROR, "insert_username (%s): there is no attribute %s", relname, args[0]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\" has no attribute \"%s\"", relname, args[0])));
if (SPI_gettypeid(tupdesc, attnum) != TEXTOID)
elog(ERROR, "insert_username (%s): attribute %s must be of TEXT type",
relname, args[0]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("attribute \"%s\" of \"%s\" must be type TEXT",
args[0], relname)));
/* create fields containing name */
newval = DirectFunctionCall1(textin,
@ -70,7 +80,8 @@ insert_username(PG_FUNCTION_ARGS)
/* construct new tuple */
rettuple = SPI_modifytuple(rel, rettuple, 1, &attnum, &newval, NULL);
if (rettuple == NULL)
elog(ERROR, "insert_username (%s): %d returned by SPI_modifytuple",
/* internal error */
elog(ERROR, "insert_username (\"%s\"): %d returned by SPI_modifytuple",
relname, SPI_result);
pfree(relname);

View File

@ -34,20 +34,25 @@ moddatetime(PG_FUNCTION_ARGS)
TupleDesc tupdesc; /* tuple description */
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "moddatetime: not fired by trigger manager.");
/* internal error */
elog(ERROR, "moddatetime: not fired by trigger manager");
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
elog(ERROR, "moddatetime: can't process STATEMENT events.");
/* internal error */
elog(ERROR, "moddatetime: can't process STATEMENT events");
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
elog(ERROR, "moddatetime: must be fired before event.");
/* internal error */
elog(ERROR, "moddatetime: must be fired before event");
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
elog(ERROR, "moddatetime: must be fired before event.");
/* internal error */
elog(ERROR, "moddatetime: must be fired before event");
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
elog(ERROR, "moddatetime: can't process DELETE events.");
/* internal error */
elog(ERROR, "moddatetime: can't process DELETE events");
rel = trigdata->tg_relation;
relname = SPI_getrelname(rel);
@ -57,7 +62,8 @@ moddatetime(PG_FUNCTION_ARGS)
nargs = trigger->tgnargs;
if (nargs != 1)
elog(ERROR, "moddatetime (%s): A single argument was expected.", relname);
/* internal error */
elog(ERROR, "moddatetime (%s): A single argument was expected", relname);
args = trigger->tgargs;
/* must be the field layout? */
@ -81,8 +87,10 @@ moddatetime(PG_FUNCTION_ARGS)
* even exits. The above function must return -1 if name not found?
*/
if (attnum < 0)
elog(ERROR, "moddatetime (%s): there is no attribute %s", relname,
args[0]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\" has no attribute \"%s\"",
relname, args[0])));
/*
* OK, this is where we make sure the timestamp field that we are
@ -90,8 +98,10 @@ moddatetime(PG_FUNCTION_ARGS)
* novel idea !-)
*/
if (SPI_gettypeid(tupdesc, attnum) != TIMESTAMPOID)
elog(ERROR, "moddatetime (%s): attribute %s must be of TIMESTAMP type",
relname, args[0]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("attribute \"%s\" of \"%s\" must be type TIMESTAMP",
args[0], relname)));
/* 1 is the number of items in the arrays attnum and newdt.
attnum is the positional number of the field to be updated.
@ -103,6 +113,7 @@ moddatetime(PG_FUNCTION_ARGS)
rettuple = SPI_modifytuple(rel, rettuple, 1, &attnum, &newdt, NULL);
if (rettuple == NULL)
/* internal error */
elog(ERROR, "moddatetime (%s): %d returned by SPI_modifytuple",
relname, SPI_result);

View File

@ -59,7 +59,7 @@ check_primary_key(PG_FUNCTION_ARGS)
int i;
#ifdef DEBUG_QUERY
elog(DEBUG4, "Check_primary_key Enter Function");
elog(DEBUG4, "check_primary_key: Enter Function");
#endif
/*
@ -68,10 +68,12 @@ check_primary_key(PG_FUNCTION_ARGS)
/* Called by trigger manager ? */
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "check_primary_key: not fired by trigger manager");
/* Should be called for ROW trigger */
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "check_primary_key: can't process STATEMENT events");
/* If INSERTion then must check Tuple to being inserted */
@ -80,6 +82,7 @@ check_primary_key(PG_FUNCTION_ARGS)
/* Not should be called for DELETE */
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
/* internal error */
elog(ERROR, "check_primary_key: can't process DELETE events");
/* If UPDATion the must check new Tuple, not old one */
@ -91,6 +94,7 @@ check_primary_key(PG_FUNCTION_ARGS)
args = trigger->tgargs;
if (nargs % 2 != 1) /* odd number of arguments! */
/* internal error */
elog(ERROR, "check_primary_key: odd number of arguments should be specified");
nkeys = nargs / 2;
@ -100,6 +104,7 @@ check_primary_key(PG_FUNCTION_ARGS)
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "check_primary_key: SPI_connect returned %d", ret);
/*
@ -127,8 +132,10 @@ check_primary_key(PG_FUNCTION_ARGS)
/* Bad guys may give us un-existing column in CREATE TRIGGER */
if (fnumber < 0)
elog(ERROR, "check_primary_key: there is no attribute %s in relation %s",
args[i], SPI_getrelname(rel));
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("there is no attribute \"%s\" in relation \"%s\"",
args[i], SPI_getrelname(rel))));
/* Well, get binary (in internal format) value of column */
kvals[i] = SPI_getbinval(tuple, tupdesc, fnumber, &isnull);
@ -170,6 +177,7 @@ check_primary_key(PG_FUNCTION_ARGS)
/* Prepare plan for query */
pplan = SPI_prepare(sql, nkeys, argtypes);
if (pplan == NULL)
/* internal error */
elog(ERROR, "check_primary_key: SPI_prepare returned %d", SPI_result);
/*
@ -179,6 +187,7 @@ check_primary_key(PG_FUNCTION_ARGS)
*/
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
/* internal error */
elog(ERROR, "check_primary_key: SPI_saveplan returned %d", SPI_result);
plan->splan = (void **) malloc(sizeof(void *));
*(plan->splan) = pplan;
@ -192,14 +201,17 @@ check_primary_key(PG_FUNCTION_ARGS)
/* we have no NULLs - so we pass ^^^^ here */
if (ret < 0)
/* internal error */
elog(ERROR, "check_primary_key: SPI_execp returned %d", ret);
/*
* If there are no tuples returned by SELECT then ...
*/
if (SPI_processed == 0)
elog(ERROR, "%s: tuple references non-existing key in %s",
trigger->tgname, relname);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("tuple references non-existent key"),
errdetail("Trigger \"%s\" found tuple referencing non-existent key in \"%s\".", trigger->tgname, relname)));
SPI_finish();
@ -249,7 +261,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
r;
#ifdef DEBUG_QUERY
elog(DEBUG4, "Check_foreign_key Enter Function");
elog(DEBUG4, "check_foreign_key: Enter Function");
#endif
/*
@ -258,14 +270,17 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* Called by trigger manager ? */
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "check_foreign_key: not fired by trigger manager");
/* Should be called for ROW trigger */
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "check_foreign_key: can't process STATEMENT events");
/* Not should be called for INSERT */
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
/* internal error */
elog(ERROR, "check_foreign_key: can't process INSERT events");
/* Have to check tg_trigtuple - tuple being deleted */
@ -288,18 +303,22 @@ check_foreign_key(PG_FUNCTION_ARGS)
if (nargs < 5) /* nrefs, action, key, Relation, key - at
* least */
/* internal error */
elog(ERROR, "check_foreign_key: too short %d (< 5) list of arguments", nargs);
nrefs = pg_atoi(args[0], sizeof(int), 0);
if (nrefs < 1)
/* internal error */
elog(ERROR, "check_foreign_key: %d (< 1) number of references specified", nrefs);
action = tolower((unsigned char) *(args[1]));
if (action != 'r' && action != 'c' && action != 's')
/* internal error */
elog(ERROR, "check_foreign_key: invalid action %s", args[1]);
nargs -= 2;
args += 2;
nkeys = (nargs - nrefs) / (nrefs + 1);
if (nkeys <= 0 || nargs != (nrefs + nkeys * (nrefs + 1)))
/* internal error */
elog(ERROR, "check_foreign_key: invalid number of arguments %d for %d references",
nargs + 2, nrefs);
@ -308,6 +327,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "check_foreign_key: SPI_connect returned %d", ret);
/*
@ -331,6 +351,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
* else - check that we have exactly nrefs plan(s) ready
*/
else if (plan->nplans != nrefs)
/* internal error */
elog(ERROR, "%s: check_foreign_key: # of plans changed in meantime",
trigger->tgname);
@ -342,8 +363,10 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* Bad guys may give us un-existing column in CREATE TRIGGER */
if (fnumber < 0)
elog(ERROR, "check_foreign_key: there is no attribute %s in relation %s",
args[i], SPI_getrelname(rel));
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("there is no attribute \"%s\" in relation \"%s\"",
args[i], SPI_getrelname(rel))));
/* Well, get binary (in internal format) value of column */
kvals[i] = SPI_getbinval(trigtuple, tupdesc, fnumber, &isnull);
@ -371,6 +394,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* this shouldn't happen! SPI_ERROR_NOOUTFUNC ? */
if (oldval == NULL)
/* internal error */
elog(ERROR, "check_foreign_key: SPI_getvalue returned %d", SPI_result);
newval = SPI_getvalue(newtuple, tupdesc, fnumber);
if (newval == NULL || strcmp(oldval, newval) != 0)
@ -453,7 +477,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
strcmp(type, "date") && strcmp(type, "timestamp")) == 0)
is_char_type = 1;
#ifdef DEBUG_QUERY
elog(DEBUG4, "Check_foreign_key Debug value %s type %s %d",
elog(DEBUG4, "check_foreign_key Debug value %s type %s %d",
nv, type, is_char_type);
#endif
@ -504,6 +528,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* Prepare plan for query */
pplan = SPI_prepare(sql, nkeys, argtypes);
if (pplan == NULL)
/* internal error */
elog(ERROR, "check_foreign_key: SPI_prepare returned %d", SPI_result);
/*
@ -513,6 +538,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
*/
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
/* internal error */
elog(ERROR, "check_foreign_key: SPI_saveplan returned %d", SPI_result);
plan->splan[r] = pplan;
@ -521,7 +547,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
}
plan->nplans = nrefs;
#ifdef DEBUG_QUERY
elog(DEBUG4, "Check_foreign_key Debug Query is : %s ", sql);
elog(DEBUG4, "check_foreign_key Debug Query is : %s ", sql);
#endif
}
@ -553,22 +579,26 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* we have no NULLs - so we pass ^^^^ here */
if (ret < 0)
elog(ERROR, "check_foreign_key: SPI_execp returned %d", ret);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("SPI_execp returned %d", ret)));
/* If action is 'R'estrict ... */
if (action == 'r')
{
/* If there is tuple returned by SELECT then ... */
if (SPI_processed > 0)
elog(ERROR, "%s: tuple referenced in %s",
trigger->tgname, relname);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\": tuple is referenced in \"%s\"",
trigger->tgname, relname)));
}
else
{
#ifdef REFINT_VERBOSE
elog(NOTICE, "%s: %d tuple(s) of %s are %s",
trigger->tgname, SPI_processed, relname,
(action == 'c') ? "deleted" : "setted to null");
(action == 'c') ? "deleted" : "set to null");
#endif
}
args += nkeys + 1; /* to the next relation */

View File

@ -82,14 +82,17 @@ timetravel(PG_FUNCTION_ARGS)
/* Called by trigger manager ? */
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "timetravel: not fired by trigger manager");
/* Should be called for ROW trigger */
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "timetravel: can't process STATEMENT events");
/* Should be called BEFORE */
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
/* internal error */
elog(ERROR, "timetravel: must be fired before event");
/* INSERT ? */
@ -117,6 +120,7 @@ timetravel(PG_FUNCTION_ARGS)
trigger = trigdata->tg_trigger;
if (trigger->tgnargs != 2)
/* internal error */
elog(ERROR, "timetravel (%s): invalid (!= 2) number of arguments %d",
relname, trigger->tgnargs);
@ -128,10 +132,15 @@ timetravel(PG_FUNCTION_ARGS)
{
attnum[i] = SPI_fnumber(tupdesc, args[i]);
if (attnum[i] < 0)
elog(ERROR, "timetravel (%s): there is no attribute %s", relname, args[i]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\" has no attribute \"%s\"",
relname, args[i])));
if (SPI_gettypeid(tupdesc, attnum[i]) != ABSTIMEOID)
elog(ERROR, "timetravel (%s): attributes %s and %s must be of abstime type",
relname, args[0], args[1]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("attribute \"%s\" of \"%s\" must be type ABSTIME",
args[i], relname)));
}
if (isinsert) /* INSERT */
@ -153,8 +162,10 @@ timetravel(PG_FUNCTION_ARGS)
{
if ((chnattrs == 0 && DatumGetInt32(oldon) >= NOEND_ABSTIME) ||
(chnattrs > 0 && DatumGetInt32(newvals[0]) >= NOEND_ABSTIME))
elog(ERROR, "timetravel (%s): %s ge %s",
relname, args[0], args[1]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("timetravel (%s): %s ge %s",
relname, args[0], args[1])));
newvals[chnattrs] = NOEND_ABSTIME;
chattrs[chnattrs] = attnum[1];
chnattrs++;
@ -165,8 +176,10 @@ timetravel(PG_FUNCTION_ARGS)
DatumGetInt32(oldoff)) ||
(chnattrs > 0 && DatumGetInt32(newvals[0]) >=
DatumGetInt32(oldoff)))
elog(ERROR, "timetravel (%s): %s ge %s",
relname, args[0], args[1]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("timetravel (%s): %s ge %s",
relname, args[0], args[1])));
}
pfree(relname);
@ -180,11 +193,16 @@ timetravel(PG_FUNCTION_ARGS)
oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
if (isnull)
elog(ERROR, "timetravel (%s): %s must be NOT NULL", relname, args[0]);
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("\"%s\" must be NOT NULL in \"%s\"",
args[0],relname)));
oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
if (isnull)
elog(ERROR, "timetravel (%s): %s must be NOT NULL", relname, args[1]);
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("\"%s\" must be NOT NULL in \"%s\"",
args[1],relname)));
/*
* If DELETE/UPDATE of tuple with stop_date neq INFINITY then say
@ -194,14 +212,23 @@ timetravel(PG_FUNCTION_ARGS)
{
newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
if (isnull)
elog(ERROR, "timetravel (%s): %s must be NOT NULL", relname, args[0]);
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("\"%s\" must be NOT NULL in \"%s\"",
args[0],relname)));
newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
if (isnull)
elog(ERROR, "timetravel (%s): %s must be NOT NULL", relname, args[1]);
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("\"%s\" must be NOT NULL in \"%s\"",
args[1],relname)));
if (oldon != newon || oldoff != newoff)
elog(ERROR, "timetravel (%s): you can't change %s and/or %s columns (use set_timetravel)",
relname, args[0], args[1]);
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("cannot change columns \"%s\" or \"%s\" in \"%s\"",
args[0], args[1], relname),
errhint("Use set_timetravel() instead.")));
if (newoff != NOEND_ABSTIME)
{
@ -219,6 +246,7 @@ timetravel(PG_FUNCTION_ARGS)
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "timetravel (%s): SPI_connect returned %d", relname, ret);
/* Fetch tuple values and nulls */
@ -277,6 +305,7 @@ timetravel(PG_FUNCTION_ARGS)
/* Prepare plan for query */
pplan = SPI_prepare(sql, natts, ctypes);
if (pplan == NULL)
/* internal error */
elog(ERROR, "timetravel (%s): SPI_prepare returned %d", relname, SPI_result);
/*
@ -286,6 +315,7 @@ timetravel(PG_FUNCTION_ARGS)
*/
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
/* internal error */
elog(ERROR, "timetravel (%s): SPI_saveplan returned %d", relname, SPI_result);
plan->splan = pplan;
@ -297,6 +327,7 @@ timetravel(PG_FUNCTION_ARGS)
ret = SPI_execp(plan->splan, cvals, cnulls, 0);
if (ret < 0)
/* internal error */
elog(ERROR, "timetravel (%s): SPI_execp returned %d", relname, ret);
/* Tuple to return to upper Executor ... */

View File

@ -127,7 +127,7 @@ SELECT * FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''
-- hash based crosstab
--
create table cth(id serial, rowid text, rowdt timestamp, attribute text, val text);
NOTICE: CREATE TABLE will create implicit sequence 'cth_id_seq' for SERIAL column 'cth.id'
NOTICE: CREATE TABLE will create implicit sequence "cth_id_seq" for SERIAL column "cth.id"
insert into cth values(DEFAULT,'test1','01 March 2003','temperature','42');
insert into cth values(DEFAULT,'test1','01 March 2003','test_result','PASS');
-- the next line is intentionally left commented and is therefore a "missing" attribute
@ -186,13 +186,13 @@ SELECT * FROM crosstab(
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
'SELECT DISTINCT attribute FROM cth WHERE attribute = ''a'' ORDER BY 1')
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
ERROR: load_categories_hash: provided categories SQL must return 1 column of at least one row
ERROR: provided "categories" SQL must return 1 column of at least one row
-- if category query generates more than one column, get expected error
SELECT * FROM crosstab(
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
ERROR: load_categories_hash: provided categories SQL must return 1 column of at least one row
ERROR: provided "categories" SQL must return 1 column of at least one row
--
-- connectby
--

View File

@ -137,24 +137,16 @@ do { \
hentry = (crosstab_HashEnt*) hash_search(crosstab_HashTable, \
key, HASH_ENTER, &found); \
if (hentry == NULL) \
elog(ERROR, "out of memory in crosstab_HashTable"); \
ereport(ERROR, \
(errcode(ERRCODE_OUT_OF_MEMORY), \
errmsg("out of memory"))); \
if (found) \
elog(ERROR, "trying to use a category name more than once"); \
ereport(ERROR, \
(errcode(ERRCODE_DUPLICATE_OBJECT), \
errmsg("duplicate category name"))); \
hentry->catdesc = CATDESC; \
} while(0)
#define crosstab_HashTableDelete(CATNAME) \
do { \
crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN]; \
\
MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATNAME); \
hentry = (crosstab_HashEnt*) hash_search(crosstab_HashTable, \
key, HASH_REMOVE, NULL); \
if (hentry == NULL) \
elog(WARNING, "trying to delete function name that does not exist."); \
} while(0)
/* hash table */
typedef struct crosstab_hashent
{
@ -389,6 +381,7 @@ crosstab(PG_FUNCTION_ARGS)
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "crosstab: SPI_connect returned %d", ret);
/* Retrieve the desired rows */
@ -410,8 +403,11 @@ crosstab(PG_FUNCTION_ARGS)
* in the final result
*/
if (spi_tupdesc->natts != 3)
elog(ERROR, "crosstab: provided SQL must return 3 columns;"
" a rowid, a category, and a values column");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid source data SQL statement"),
errdetail("The provided SQL must return 3 " \
" columns; rowid, category, and values.")));
}
else
{
@ -437,7 +433,9 @@ crosstab(PG_FUNCTION_ARGS)
else if (functyptype == 'p' && functypeid == RECORDOID)
{
if (fcinfo->nargs != 2)
elog(ERROR, "Wrong number of arguments specified for function");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("wrong number of arguments")));
else
{
int num_categories = PG_GETARG_INT32(1);
@ -446,7 +444,9 @@ crosstab(PG_FUNCTION_ARGS)
}
}
else
elog(ERROR, "crosstab: return type must be a row type");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("return type must be a row type")));
/*
* Check that return tupdesc is compatible with the one we got
@ -454,8 +454,10 @@ crosstab(PG_FUNCTION_ARGS)
* attributes
*/
if (!compatCrosstabTupleDescs(tupdesc, spi_tupdesc))
elog(ERROR, "crosstab: return and sql tuple descriptions are"
" incompatible");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("return and sql tuple descriptions are " \
"incompatible")));
/* allocate a slot for a tuple with this tupdesc */
slot = TupleDescGetSlot(tupdesc);
@ -706,8 +708,10 @@ crosstab_hash(PG_FUNCTION_ARGS)
/* check to see if caller supports us returning a tuplestore */
if (!rsinfo || !(rsinfo->allowedModes & SFRM_Materialize))
elog(ERROR, "crosstab: materialize mode required, but it is not "
"allowed in this context");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("materialize mode required, but it is not " \
"allowed in this context")));
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
oldcontext = MemoryContextSwitchTo(per_query_ctx);
@ -723,8 +727,10 @@ crosstab_hash(PG_FUNCTION_ARGS)
* function to complain if needed.
*/
if (tupdesc->natts < 2)
elog(ERROR, "crosstab: query-specified return tuple and " \
"crosstab function are not compatible");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("query-specified return tuple and " \
"crosstab function are not compatible")));
/* load up the categories hash table */
num_categories = load_categories_hash(cats_sql, per_query_ctx);
@ -775,6 +781,7 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "load_categories_hash: SPI_connect returned %d", ret);
/* Retrieve the category name rows */
@ -793,8 +800,10 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
* category - the label or identifier for each column
*/
if (spi_tupdesc->natts != 1)
elog(ERROR, "load_categories_hash: provided categories SQL must " \
"return 1 column of at least one row");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("provided \"categories\" SQL must " \
"return 1 column of at least one row")));
for (i = 0; i < proc; i++)
{
@ -824,11 +833,14 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
{
/* no qualifying tuples */
SPI_finish();
elog(ERROR, "load_categories_hash: provided categories SQL must " \
"return 1 column of at least one row");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("provided \"categories\" SQL must " \
"return 1 column of at least one row")));
}
if (SPI_finish() != SPI_OK_FINISH)
/* internal error */
elog(ERROR, "load_categories_hash: SPI_finish() failed");
return num_categories;
@ -856,6 +868,7 @@ get_crosstab_tuplestore(char *sql,
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "get_crosstab_tuplestore: SPI_connect returned %d", ret);
/* Now retrieve the crosstab source rows */
@ -887,17 +900,22 @@ get_crosstab_tuplestore(char *sql,
* time we encounter a particular rowname.
*/
if (ncols < 3)
elog(ERROR, "get_crosstab_tuplestore: provided source SQL must " \
"return at least 3 columns; a rowid, a category, " \
"and a values column");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid source data SQL statement"),
errdetail("The provided SQL must return 3 " \
" columns; rowid, category, and values.")));
result_ncols = (ncols - 2) + num_categories;
/* Recheck to make sure we tuple descriptor still looks reasonable */
if (tupdesc->natts != result_ncols)
elog(ERROR, "get_crosstab_tuplestore: query-specified return " \
"tuple has %d columns but crosstab returns %d",
tupdesc->natts, result_ncols);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("query-specified return " \
"tuple has %d columns but crosstab " \
"returns %d", tupdesc->natts, result_ncols)));
/* allocate space */
values = (char **) palloc(result_ncols * sizeof(char *));
@ -985,6 +1003,7 @@ get_crosstab_tuplestore(char *sql,
}
if (SPI_finish() != SPI_OK_FINISH)
/* internal error */
elog(ERROR, "get_crosstab_tuplestore: SPI_finish() failed");
tuplestore_donestoring(tupstore);
@ -1048,8 +1067,10 @@ connectby_text(PG_FUNCTION_ARGS)
/* check to see if caller supports us returning a tuplestore */
if (!rsinfo || !(rsinfo->allowedModes & SFRM_Materialize))
elog(ERROR, "connectby: materialize mode required, but it is not "
"allowed in this context");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("materialize mode required, but it is not " \
"allowed in this context")));
if (fcinfo->nargs == 6)
{
@ -1074,8 +1095,10 @@ connectby_text(PG_FUNCTION_ARGS)
/* check to see if caller supports us returning a tuplestore */
if (!rsinfo || !(rsinfo->allowedModes & SFRM_Materialize))
elog(ERROR, "connectby requires Materialize mode, but it is not "
"allowed in this context");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("materialize mode required, but it is not " \
"allowed in this context")));
/* OK, go to work */
rsinfo->returnMode = SFRM_Materialize;
@ -1122,6 +1145,7 @@ connectby(char *relname,
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
elog(ERROR, "connectby: SPI_connect returned %d", ret);
/* switch to longer term context to create the tuple store */
@ -1226,8 +1250,11 @@ build_tuplestore_recursively(char *key_fld,
*/
if (!compatConnectbyTupleDescs(tupdesc, spi_tupdesc))
elog(ERROR, "connectby: return and sql tuple descriptions are "
"incompatible");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("Return and SQL tuple descriptions are " \
"incompatible.")));
/* root value is the one we initially start with */
values[0] = start_with;
@ -1346,30 +1373,44 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch)
if (show_branch)
{
if (tupdesc->natts != CONNECTBY_NCOLS)
elog(ERROR, "Query-specified return tuple not valid for Connectby: "
"wrong number of columns");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("Query-specified return tuple has " \
"wrong number of columns.")));
}
else
{
if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH)
elog(ERROR, "Query-specified return tuple not valid for Connectby: "
"wrong number of columns");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("Query-specified return tuple has " \
"wrong number of columns.")));
}
/* check that the types of the first two columns match */
if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid)
elog(ERROR, "Query-specified return tuple not valid for Connectby: "
"first two columns must be the same type");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("First two columns must be the same type.")));
/* check that the type of the third column is INT4 */
if (tupdesc->attrs[2]->atttypid != INT4OID)
elog(ERROR, "Query-specified return tuple not valid for Connectby: "
"third column must be type %s", format_type_be(INT4OID));
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("Third column must be type %s.",
format_type_be(INT4OID))));
/* check that the type of the fourth column is TEXT if applicable */
if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID)
elog(ERROR, "Query-specified return tuple not valid for Connectby: "
"fourth column must be type %s", format_type_be(TEXTOID));
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("Fourth column must be type %s.",
format_type_be(TEXTOID))));
/* OK, the tupdesc is valid for our purposes */
}
@ -1387,15 +1428,21 @@ compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
ret_atttypid = ret_tupdesc->attrs[0]->atttypid;
sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
if (ret_atttypid != sql_atttypid)
elog(ERROR, "compatConnectbyTupleDescs: SQL key field datatype does "
"not match return key field datatype");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("SQL key field datatype does " \
"not match return key field datatype.")));
/* check the parent_key_fld types match */
ret_atttypid = ret_tupdesc->attrs[1]->atttypid;
sql_atttypid = sql_tupdesc->attrs[1]->atttypid;
if (ret_atttypid != sql_atttypid)
elog(ERROR, "compatConnectbyTupleDescs: SQL parent key field datatype "
"does not match return parent key field datatype");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("SQL parent key field datatype does " \
"not match return parent key field datatype.")));
/* OK, the two tupdescs are compatible for our purposes */
return true;
@ -1417,8 +1464,11 @@ compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
ret_atttypid = ret_tupdesc->attrs[0]->atttypid;
sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
if (ret_atttypid != sql_atttypid)
elog(ERROR, "compatCrosstabTupleDescs: SQL rowid datatype does not match"
" return rowid datatype");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid return type"),
errdetail("SQL rowid datatype does not match " \
"return rowid datatype.")));
/*
* - attribute [1] of the sql tuple is the category; no need to check

View File

@ -3,14 +3,18 @@
-- does not depend on contents of seg.sql.
--
\set ECHO none
psql:tsearch.sql:9: NOTICE: ProcedureCreate: type txtidx is not yet defined
psql:tsearch.sql:14: NOTICE: Argument type "txtidx" is only a shell
psql:tsearch.sql:38: NOTICE: ProcedureCreate: type query_txt is not yet defined
psql:tsearch.sql:43: NOTICE: Argument type "query_txt" is only a shell
psql:tsearch.sql:55: NOTICE: ProcedureCreate: type mquery_txt is not yet defined
psql:tsearch.sql:61: NOTICE: Argument type "mquery_txt" is only a shell
psql:tsearch.sql:156: NOTICE: ProcedureCreate: type gtxtidx is not yet defined
psql:tsearch.sql:161: NOTICE: Argument type "gtxtidx" is only a shell
psql:tsearch.sql:9: NOTICE: type txtidx is not yet defined
DETAIL: Creating a shell type definition.
psql:tsearch.sql:14: NOTICE: argument type txtidx is only a shell
psql:tsearch.sql:38: NOTICE: type query_txt is not yet defined
DETAIL: Creating a shell type definition.
psql:tsearch.sql:43: NOTICE: argument type query_txt is only a shell
psql:tsearch.sql:55: NOTICE: type mquery_txt is not yet defined
DETAIL: Creating a shell type definition.
psql:tsearch.sql:61: NOTICE: argument type mquery_txt is only a shell
psql:tsearch.sql:156: NOTICE: type gtxtidx is not yet defined
DETAIL: Creating a shell type definition.
psql:tsearch.sql:161: NOTICE: argument type gtxtidx is only a shell
--txtidx
SELECT '1'::txtidx;
txtidx

View File

@ -5,8 +5,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "access/rtree.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
@ -60,14 +58,18 @@ Datum gtxtidx_picksplit(PG_FUNCTION_ARGS);
Datum
gtxtidx_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("gtxtidx_in not implemented")));
PG_RETURN_DATUM(0);
}
Datum
gtxtidx_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("gtxtidx_out not implemented")));
PG_RETURN_DATUM(0);
}

View File

@ -15,8 +15,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "access/rtree.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
@ -129,7 +127,9 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval)
return VAL;
}
else
elog(ERROR, "No operand");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("no operand")));
}
break;
case WAITOPERATOR:
@ -171,9 +171,13 @@ pushquery(QPRS_STATE * state, int4 type, int4 val, int4 distance, int4 lenval)
tmp->type = type;
tmp->val = val;
if (distance > 0xffff)
elog(ERROR, "Value is too big");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("value is too big")));
if (lenval > 0xffff)
elog(ERROR, "Operand is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("operand is too long")));
tmp->distance = distance;
tmp->length = lenval;
tmp->next = state->str;
@ -188,7 +192,9 @@ static void
pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval)
{
if (lenval > 0xffff)
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
pushquery(state, type, crc32_sz((uint8 *) strval, lenval),
state->curop - state->op, lenval);
@ -226,7 +232,9 @@ pushval_morph(QPRS_STATE * state, int typeval, char *strval, int lenval)
if (tokenlen > 0xffff)
{
end_parse();
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
}
lenlemm = tokenlen;
lemm = lemmatize(token, &lenlemm, type);
@ -278,7 +286,8 @@ makepol(QPRS_STATE * state, void (*pushval) (QPRS_STATE *, int, char *, int))
else
{
if (lenstack == STACKDEPTH)
elog(ERROR, "Stack too short");
/* internal error */
elog(ERROR, "stack too short");
stack[lenstack] = val;
lenstack++;
}
@ -303,7 +312,10 @@ makepol(QPRS_STATE * state, void (*pushval) (QPRS_STATE *, int, char *, int))
break;
case ERR:
default:
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
return ERR;
}
@ -450,7 +462,7 @@ findoprnd(ITEM * ptr, int4 *pos)
{
#ifdef BS_DEBUG
elog(DEBUG4, (ptr[*pos].type == OPR) ?
"%d %c" : "%d %d ", *pos, ptr[*pos].val);
"%d %c" : "%d %d", *pos, ptr[*pos].val);
#endif
if (ptr[*pos].type == VAL || ptr[*pos].type == VALTRUE)
{
@ -517,7 +529,9 @@ queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int))
makepol(&state, pushval);
pfree(state.valstate.word);
if (!state.num)
elog(ERROR, "Empty query");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("empty query")));
/* make finish struct */
commonlen = COMPUTESIZE(state.num, state.sumlen);

View File

@ -8,8 +8,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
#include "executor/spi.h"
@ -128,7 +126,9 @@ gettoken_txtidx(TI_IN_STATE * state)
oldstate = WAITENDWORD;
}
else if (state->oprisdelim && ISOPERATOR(*(state->prsbuf)))
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
else if (*(state->prsbuf) != ' ')
{
*(state->curpos) = *(state->prsbuf);
@ -139,7 +139,9 @@ gettoken_txtidx(TI_IN_STATE * state)
else if (state->state == WAITNEXTCHAR)
{
if (*(state->prsbuf) == '\0')
elog(ERROR, "There is no escaped character");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("there is no escaped character")));
else
{
RESIZEPRSBUF;
@ -160,7 +162,9 @@ gettoken_txtidx(TI_IN_STATE * state)
{
RESIZEPRSBUF;
if (state->curpos == state->word)
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
*(state->curpos) = '\0';
return 1;
}
@ -178,7 +182,9 @@ gettoken_txtidx(TI_IN_STATE * state)
RESIZEPRSBUF;
*(state->curpos) = '\0';
if (state->curpos == state->word)
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
state->prsbuf++;
return 1;
}
@ -188,7 +194,9 @@ gettoken_txtidx(TI_IN_STATE * state)
oldstate = WAITENDCMPLX;
}
else if (*(state->prsbuf) == '\0')
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
else
{
RESIZEPRSBUF;
@ -197,7 +205,8 @@ gettoken_txtidx(TI_IN_STATE * state)
}
}
else
elog(ERROR, "Inner bug :(");
/* internal error */
elog(ERROR, "internal error");
state->prsbuf++;
}
@ -241,10 +250,14 @@ txtidx_in(PG_FUNCTION_ARGS)
cur = tmpbuf + dist;
}
if (state.curpos - state.word > 0xffff)
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
arr[len].len = state.curpos - state.word;
if (cur - tmpbuf > 0xffff)
elog(ERROR, "Too long value");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("too long value")));
arr[len].pos = cur - tmpbuf;
memcpy((void *) cur, (void *) state.word, arr[len].len);
cur += arr[len].len;
@ -253,7 +266,9 @@ txtidx_in(PG_FUNCTION_ARGS)
pfree(state.word);
if (!len)
elog(ERROR, "Void value");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("void value")));
len = uniqueentry(arr, len, tmpbuf, &buflen);
totallen = CALCDATASIZE(len, buflen);
@ -359,7 +374,9 @@ parsetext(PRSTEXT * prs, char *buf, int4 buflen)
if (tokenlen > 0xffff)
{
end_parse();
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
}
lenlemm = tokenlen;
@ -461,7 +478,9 @@ makevalue(PRSTEXT * prs)
{
ptr->len = prs->words[i].len;
if (cur - str > 0xffff)
elog(ERROR, "Value is too big");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("value is too big")));
ptr->pos = cur - str;
ptr++;
memcpy((void *) cur, (void *) prs->words[i].word, prs->words[i].len);
@ -512,12 +531,15 @@ tsearch(PG_FUNCTION_ARGS)
Datum datum = (Datum) 0;
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "TSearch: Not fired by trigger manager");
trigdata = (TriggerData *) fcinfo->context;
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "TSearch: Can't process STATEMENT events");
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
/* internal error */
elog(ERROR, "TSearch: Must be fired BEFORE event");
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
@ -525,18 +547,21 @@ tsearch(PG_FUNCTION_ARGS)
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
/* internal error */
elog(ERROR, "TSearch: Unknown event");
trigger = trigdata->tg_trigger;
rel = trigdata->tg_relation;
if (trigger->tgnargs < 2)
/* internal error */
elog(ERROR, "TSearch: format tsearch(txtidx_field, text_field1,...)");
numidxattr = SPI_fnumber(rel->rd_att, trigger->tgargs[0]);
if (numidxattr == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "TSearch: Can not find txtidx_field");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("could not find txtidx_field")));
prs.lenwords = 32;
prs.curwords = 0;
prs.words = (WORD *) palloc(sizeof(WORD) * prs.lenwords);
@ -594,6 +619,7 @@ tsearch(PG_FUNCTION_ARGS)
}
if (rettuple == NULL)
/* internal error */
elog(ERROR, "TSearch: %d returned by SPI_modifytuple", SPI_result);
return PointerGetDatum(rettuple);

View File

@ -68,7 +68,8 @@ ts_error(int state, const char *format, ...) {
}
va_end(args);
elog(state,buf);
/* ?? internal error ?? */
elog(state, "%s", buf);
pfree(buf);
}

View File

@ -258,7 +258,10 @@ Datum
lexize_bycurrent(PG_FUNCTION_ARGS) {
Datum res;
if ( currect_dictionary_id == 0 )
elog(ERROR, "No currect dictionary. Execute select set_curdict().");
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("no currect dictionary"),
errhint("Execute select set_curdict().")));
res = DirectFunctionCall3(
lexize,

View File

@ -26,7 +26,9 @@ dex_init(PG_FUNCTION_ARGS) {
DictExample *d = (DictExample*)malloc( sizeof(DictExample) );
if ( !d )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
memset(d,0,sizeof(DictExample));
d->stoplist.wordop=lowerstr;

View File

@ -37,11 +37,15 @@ spell_init(PG_FUNCTION_ARGS) {
bool affloaded=false, dictloaded=false, stoploaded=false;
if ( PG_ARGISNULL(0) || PG_GETARG_POINTER(0)==NULL )
elog(ERROR,"ISpell confguration error");
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("ISpell confguration error")));
d = (DictISpell*)malloc( sizeof(DictISpell) );
if ( !d )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
memset(d,0,sizeof(DictISpell));
d->stoplist.wordop=lowerstr;
@ -53,28 +57,40 @@ spell_init(PG_FUNCTION_ARGS) {
if ( strcasecmp("DictFile", pcfg->key) == 0 ) {
if ( dictloaded ) {
freeDictISpell(d);
elog(ERROR,"Dictionary already loaded");
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("dictionary already loaded")));
}
if ( ImportDictionary(&(d->obj), pcfg->value) ) {
freeDictISpell(d);
elog(ERROR,"Can't load dictionary file (%s)", pcfg->value);
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("could not load dictionary file \"%s\"",
pcfg->value)));
}
dictloaded=true;
} else if ( strcasecmp("AffFile", pcfg->key) == 0 ) {
if ( affloaded ) {
freeDictISpell(d);
elog(ERROR,"Affixes already loaded");
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("affixes already loaded")));
}
if ( ImportAffixes(&(d->obj), pcfg->value) ) {
freeDictISpell(d);
elog(ERROR,"Can't load affix file (%s)", pcfg->value);
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("could not load affix file \"%s\"",
pcfg->value)));
}
affloaded=true;
} else if ( strcasecmp("StopFile", pcfg->key) == 0 ) {
text *tmp=char2text(pcfg->value);
if ( stoploaded ) {
freeDictISpell(d);
elog(ERROR,"Stop words already loaded");
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("stop words already loaded")));
}
readstoplist(tmp, &(d->stoplist));
sortstoplist(&(d->stoplist));
@ -82,7 +98,10 @@ spell_init(PG_FUNCTION_ARGS) {
stoploaded=true;
} else {
freeDictISpell(d);
elog(ERROR,"Unknown option: %s => %s", pcfg->key, pcfg->value);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unrecognized option: %s => %s",
pcfg->key, pcfg->value)));
}
pfree(pcfg->key);
pfree(pcfg->value);
@ -95,10 +114,14 @@ spell_init(PG_FUNCTION_ARGS) {
SortAffixes(&(d->obj));
} else if ( !affloaded ) {
freeDictISpell(d);
elog(ERROR,"No affixes");
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("no affixes")));
} else {
freeDictISpell(d);
elog(ERROR,"No dictionary");
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("no dictionary")));
}
PG_RETURN_POINTER(d);

View File

@ -33,7 +33,9 @@ snb_en_init(PG_FUNCTION_ARGS) {
DictSnowball *d = (DictSnowball*)malloc( sizeof(DictSnowball) );
if ( !d )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
memset(d,0,sizeof(DictSnowball));
d->stoplist.wordop=lowerstr;
@ -47,7 +49,9 @@ snb_en_init(PG_FUNCTION_ARGS) {
d->z = english_create_env();
if (!d->z) {
freestoplist(&(d->stoplist));
elog(ERROR,"No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
d->stem=english_stem;
@ -59,7 +63,9 @@ snb_ru_init(PG_FUNCTION_ARGS) {
DictSnowball *d = (DictSnowball*)malloc( sizeof(DictSnowball) );
if ( !d )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
memset(d,0,sizeof(DictSnowball));
d->stoplist.wordop=lowerstr;
@ -73,7 +79,9 @@ snb_ru_init(PG_FUNCTION_ARGS) {
d->z = russian_create_env();
if (!d->z) {
freestoplist(&(d->stoplist));
elog(ERROR,"No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
d->stem=russian_stem;

View File

@ -65,21 +65,30 @@ syn_init(PG_FUNCTION_ARGS) {
int slen;
if ( PG_ARGISNULL(0) || PG_GETARG_POINTER(0)==NULL )
elog(ERROR,"NULL config");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("NULL config")));
in = PG_GETARG_TEXT_P(0);
if ( VARSIZE(in) - VARHDRSZ == 0 )
elog(ERROR,"VOID config");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("VOID config")));
filename=text2char(in);
PG_FREE_IF_COPY(in, 0);
if ( (fin=fopen(filename,"r")) == NULL )
elog(ERROR,"Can't open file '%s': %s", filename, strerror(errno));
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m",
filename)));
d = (DictSyn*)malloc( sizeof(DictSyn) );
if ( !d ) {
fclose(fin);
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
memset(d,0,sizeof(DictSyn));
@ -92,7 +101,9 @@ syn_init(PG_FUNCTION_ARGS) {
d->syn=(Syn*)realloc( d->syn, sizeof(Syn)*d->len );
if ( !d->syn ) {
fclose(fin);
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
}
@ -112,7 +123,9 @@ syn_init(PG_FUNCTION_ARGS) {
d->syn[cur].out=strdup(lowerstr(starto));
if ( !(d->syn[cur].in && d->syn[cur].out) ) {
fclose(fin);
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
cur++;

View File

@ -28,7 +28,9 @@ dinit_CFG_MODNAME(PG_FUNCTION_ARGS) {
DictSnowball *d = (DictSnowball*)malloc( sizeof(DictSnowball) );
if ( !d )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
memset(d,0,sizeof(DictSnowball));
d->stoplist.wordop=lowerstr;
@ -42,7 +44,9 @@ dinit_CFG_MODNAME(PG_FUNCTION_ARGS) {
d->z = CFG_PREFIX_create_env();
if (!d->z) {
freestoplist(&(d->stoplist));
elog(ERROR,"No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
d->stem=CFG_PREFIX_stem;

View File

@ -26,7 +26,9 @@ HASINIT dinit_CFG_MODNAME(PG_FUNCTION_ARGS) {
HASINIT DictExample *d = (DictExample*)malloc( sizeof(DictExample) );
HASINIT
HASINIT if ( !d )
HASINIT elog(ERROR, "No memory");
HASINIT ereport(ERROR,
HASINIT (errcode(ERRCODE_OUT_OF_MEMORY),
HASINIT errmsg("out of memory")));
HASINIT memset(d,0,sizeof(DictExample));
HASINIT
HASINIT d->stoplist.wordop=lowerstr;

View File

@ -5,8 +5,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "access/rtree.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
@ -60,14 +58,18 @@ Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
Datum
gtsvector_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("gtsvector_in not implemented")));
PG_RETURN_DATUM(0);
}
Datum
gtsvector_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Not implemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("gtsvector_out not implemented")));
PG_RETURN_DATUM(0);
}

View File

@ -75,11 +75,15 @@ AddSpell(IspellDict * Conf,const char * word,const char *flag){
Conf->Spell=(SPELL *)malloc(Conf->mspell*sizeof(SPELL));
}
if ( Conf->Spell == NULL )
elog(ERROR,"No memory for AddSpell");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
Conf->Spell[Conf->nspell].word=strdup(word);
if ( !Conf->Spell[Conf->nspell].word )
elog(ERROR,"No memory for AddSpell");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
strncpy(Conf->Spell[Conf->nspell].flag,flag,10);
Conf->nspell++;
return(0);
@ -177,7 +181,9 @@ AddAffix(IspellDict * Conf,int flag,const char *mask,const char *find,const char
Conf->Affix = (AFFIX*)malloc(Conf->maffixes * sizeof(AFFIX));
}
if ( Conf->Affix == NULL )
elog(ERROR,"No memory for AddAffix");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
if (type=='s') {
sprintf(Conf->Affix[Conf->naffixes].mask,"%s$",mask);

View File

@ -58,7 +58,11 @@ parse_cfgdict(text *in, Map **m) {
begin=ptr;
state=CS_INKEY;
} else if ( !isspace(*ptr) )
elog(ERROR,"Syntax error in position %d near '%c'", ptr-VARDATA(in), *ptr);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Syntax error in position %d near \"%c\"",
ptr-VARDATA(in), *ptr)));
} else if (state==CS_INKEY) {
if ( isspace(*ptr) ) {
mptr->key=nstrdup(begin, ptr-begin);
@ -67,12 +71,20 @@ parse_cfgdict(text *in, Map **m) {
mptr->key=nstrdup(begin, ptr-begin);
state=CS_WAITVALUE;
} else if ( !isalpha(*ptr) )
elog(ERROR,"Syntax error in position %d near '%c'", ptr-VARDATA(in), *ptr);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Syntax error in position %d near \"%c\"",
ptr-VARDATA(in), *ptr)));
} else if ( state==CS_WAITEQ ) {
if ( *ptr=='=' )
state=CS_WAITVALUE;
else if ( !isspace(*ptr) )
elog(ERROR,"Syntax error in position %d near '%c'", ptr-VARDATA(in), *ptr);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Syntax error in position %d near \"%c\"",
ptr-VARDATA(in), *ptr)));
} else if ( state==CS_WAITVALUE ) {
if ( *ptr=='"' ) {
begin=ptr+1;
@ -99,13 +111,21 @@ parse_cfgdict(text *in, Map **m) {
if ( *ptr==',' )
state=CS_WAITKEY;
else if ( !isspace(*ptr) )
elog(ERROR,"Syntax error in position %d near '%c'", ptr-VARDATA(in), *ptr);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Syntax error in position %d near \"%c\"",
ptr-VARDATA(in), *ptr)));
} else if ( state == CS_INESC ) {
state=CS_INVALUE;
} else if ( state == CS_IN2ESC ) {
state=CS_IN2VALUE;
} else
elog(ERROR,"Bad parser state: %d at position %d near '%c'", state, ptr-VARDATA(in), *ptr);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad parser state"),
errdetail("%d at position %d near \"%c\"",
state, ptr-VARDATA(in), *ptr)));
ptr++;
}
@ -113,7 +133,9 @@ parse_cfgdict(text *in, Map **m) {
mptr->value = nstrdup(begin, ptr-begin);
mptr++;
} else if ( !(state==CS_WAITDELIM || state==CS_WAITKEY) )
elog(ERROR,"Unexpected end of line");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unexpected end of line")));
}

View File

@ -16,8 +16,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "access/rtree.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
@ -149,7 +147,9 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2
(state->buf)++;
return OPEN;
} else if ( *(state->buf) == ':' ) {
elog(ERROR,"Error at start of operand");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("error at start of operand")));
} else if (*(state->buf) != ' ') {
state->valstate.prsbuf = state->buf;
state->state = WAITOPERATOR;
@ -161,7 +161,9 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2
return VAL;
}
else
elog(ERROR, "No operand");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("no operand")));
}
break;
case WAITOPERATOR:
@ -204,9 +206,13 @@ pushquery(QPRS_STATE * state, int4 type, int4 val, int4 distance, int4 lenval, i
tmp->type = type;
tmp->val = val;
if (distance >= MAXSTRPOS)
elog(ERROR, "Value is too big");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("value is too big")));
if (lenval >= MAXSTRLEN)
elog(ERROR, "Operand is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("operand is too long")));
tmp->distance = distance;
tmp->length = lenval;
tmp->next = state->str;
@ -221,7 +227,9 @@ static void
pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval, int2 weight)
{
if (lenval >= MAXSTRLEN)
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
pushquery(state, type, crc32_sz((uint8 *) strval, lenval),
state->curop - state->op, lenval, weight);
@ -305,7 +313,8 @@ makepol(QPRS_STATE * state, void (*pushval) (QPRS_STATE *, int, char *, int, int
else
{
if (lenstack == STACKDEPTH)
elog(ERROR, "Stack too short");
/* internal error */
elog(ERROR, "stack too short");
stack[lenstack] = val;
lenstack++;
}
@ -330,7 +339,9 @@ makepol(QPRS_STATE * state, void (*pushval) (QPRS_STATE *, int, char *, int, int
break;
case ERR:
default:
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
return ERR;
}
@ -493,7 +504,7 @@ findoprnd(ITEM * ptr, int4 *pos)
{
#ifdef BS_DEBUG
elog(DEBUG3, (ptr[*pos].type == OPR) ?
"%d %c" : "%d %d ", *pos, ptr[*pos].val);
"%d %c" : "%d %d", *pos, ptr[*pos].val);
#endif
if (ptr[*pos].type == VAL || ptr[*pos].type == VALTRUE)
{
@ -561,7 +572,9 @@ queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int c
makepol(&state, pushval);
pfree(state.valstate.word);
if (!state.num)
elog(ERROR, "Empty query");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("empty query")));
/* make finish struct */
commonlen = COMPUTESIZE(state.num, state.sumlen);

View File

@ -7,8 +7,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/builtins.h"
#include "fmgr.h"
#include "funcapi.h"
@ -217,7 +215,8 @@ calc_rank(float *w, tsvector *t, QUERYTYPE *q, int4 method) {
case 1: res /= log((float)cnt_length(t)); break;
case 2: res /= (float)cnt_length(t); break;
default:
elog(ERROR,"Unknown normalization method: %d",method);
/* internal error */
elog(ERROR,"unrecognized normalization method: %d", method);
}
return res;
@ -234,14 +233,21 @@ rank(PG_FUNCTION_ARGS) {
int i;
if ( ARR_NDIM(win) != 1 )
elog(ERROR,"Array of weight is not one dimentional");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array of weight must be one-dimensional")));
if ( ARRNELEMS(win) < lengthof(weights) )
elog(ERROR,"Array of weight is too short");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array of weight is too short")));
for(i=0;i<lengthof(weights);i++) {
ws[ i ] = ( ((float4*)ARR_DATA_PTR(win))[i] >= 0 ) ? ((float4*)ARR_DATA_PTR(win))[i] : weights[i];
if ( ws[ i ] > 1.0 )
elog(ERROR,"Weight out of range");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("weight out of range")));
}
if ( PG_NARGS() == 4 )
@ -462,7 +468,8 @@ rank_cd(PG_FUNCTION_ARGS) {
case 1: res /= log((float)cnt_length(txt)); break;
case 2: res /= (float)cnt_length(txt); break;
default:
elog(ERROR,"Unknown normalization method: %d",method);
/* internal error */
elog(ERROR,"unrecognized normalization method: %d", method);
}
pfree(doc);
@ -527,7 +534,9 @@ get_covers(PG_FUNCTION_ARGS) {
for(i=0;i<txt->size;i++) {
if (!pptr[i].haspos)
elog(ERROR,"No pos info");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("no pos info")));
dlen += POSDATALEN(txt,&(pptr[i]));
}

View File

@ -22,13 +22,17 @@ addSNMap( SNMap *map, char *key, Oid value ) {
int len = (map->reallen) ? 2*map->reallen : 16;
tmp=(SNMapEntry*)realloc(map->list, sizeof(SNMapEntry) * len);
if ( !tmp )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
map->reallen=len;
map->list=tmp;
}
map->list[ map->len ].key = strdup(key);
if ( ! map->list[ map->len ].key )
elog(ERROR, "No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
map->list[ map->len ].value=value;
map->len++;
if ( map->len>1 ) qsort(map->list, map->len, sizeof(SNMapEntry), compareSNMapEntry);

View File

@ -46,7 +46,11 @@ readstoplist(text *in, StopList *s) {
int reallen=0;
if ( (hin=fopen(filename,"r")) == NULL )
elog(ERROR,"Can't open file '%s': %s", filename, strerror(errno));
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("could not open file \"%s\": %m",
filename)));
while( fgets(buf,STOPBUFLEN,hin) ) {
buf[strlen(buf)-1] = '\0';
if ( *buf=='\0' ) continue;
@ -58,7 +62,9 @@ readstoplist(text *in, StopList *s) {
if (!tmp) {
freestoplist(s);
fclose(hin);
elog(ERROR,"Not enough memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
stop=tmp;
}
@ -67,7 +73,9 @@ readstoplist(text *in, StopList *s) {
if ( !stop[s->len] ) {
freestoplist(s);
fclose(hin);
elog(ERROR,"Not enough memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
if ( s->wordop )
stop[s->len]=(s->wordop)(stop[s->len]);

View File

@ -85,7 +85,9 @@ init_cfg(Oid id, TSCfgInfo *cfg) {
cfg->len=lexid+1;
cfg->map = (ListDictionary*)malloc( sizeof(ListDictionary)*cfg->len );
if ( !cfg->map )
ts_error(ERROR,"No memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
memset( cfg->map, 0, sizeof(ListDictionary)*cfg->len );
}
@ -206,18 +208,25 @@ name2id_cfg(text *name) {
if ( !plan_name2id ) {
plan_name2id = SPI_saveplan( SPI_prepare( "select oid from pg_ts_cfg where ts_name = $1" , 1, arg ) );
if ( !plan_name2id )
/* internal error */
elog(ERROR, "SPI_prepare() failed");
}
stat = SPI_execp(plan_name2id, pars, " ", 1);
if ( stat < 0 )
/* internal error */
elog (ERROR, "SPI_execp return %d", stat);
if ( SPI_processed > 0 ) {
id=DatumGetObjectId( SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull) );
if ( isnull )
elog(ERROR, "Null id for tsearch config");
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("null id for tsearch config")));
} else
elog(ERROR, "No tsearch config");
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("no tsearch config")));
SPI_finish();
addSNMap_t( &(CList.name2id_map), name, id );
return id;
@ -245,8 +254,9 @@ parsetext_v2(TSCfgInfo *cfg, PRSTEXT * prs, char *buf, int4 buflen) {
PointerGetDatum(&lenlemm))) ) != 0 ) {
if ( lenlemm >= MAXSTRLEN )
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
if ( type >= cfg->len ) /* skip this type of lexem */
continue;
@ -352,7 +362,9 @@ hlparsetext(TSCfgInfo *cfg, HLPRSTEXT * prs, QUERYTYPE *query, char *buf, int4 b
PointerGetDatum(&lenlemm))) ) != 0 ) {
if ( lenlemm >= MAXSTRLEN )
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
hladdword(prs,lemm,lenlemm,type);
@ -451,6 +463,7 @@ get_currcfg(void) {
if ( !plan_getcfg_bylocale ) {
plan_getcfg_bylocale=SPI_saveplan( SPI_prepare( "select oid from pg_ts_cfg where locale = $1 ", 1, arg ) );
if ( !plan_getcfg_bylocale )
/* internal error */
elog(ERROR, "SPI_prepare() failed");
}
@ -459,11 +472,14 @@ get_currcfg(void) {
stat = SPI_execp(plan_getcfg_bylocale, pars, " ", 1);
if ( stat < 0 )
/* internal error */
elog (ERROR, "SPI_execp return %d", stat);
if ( SPI_processed > 0 )
current_cfg_id = DatumGetObjectId( SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull) );
else
elog(ERROR,"Can't find tsearch config by locale");
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("could not find tsearch config by locale")));
pfree(DatumGetPointer(pars[0]));
SPI_finish();

View File

@ -23,7 +23,9 @@ PG_FUNCTION_INFO_V1(tsstat_out);
Datum tsstat_out(PG_FUNCTION_ARGS);
Datum
tsstat_out(PG_FUNCTION_ARGS) {
elog(ERROR,"Unimplemented");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("tsstat_out not implemented")));
PG_RETURN_NULL();
}
@ -316,13 +318,16 @@ get_ti_Oid(void) {
int ret;
bool isnull;
if ( (ret = SPI_exec("select oid from pg_type where typname='tsvector'",1)) < 0 )
if ( (ret = SPI_exec("select oid from pg_type where typname='tsvector'",1)) < 0 )
/* internal error */
elog(ERROR, "SPI_exec to get tsvector oid returns %d", ret);
if ( SPI_processed<0 )
/* internal error */
elog(ERROR, "There is no tsvector type");
tiOid = DatumGetObjectId( SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull) );
if ( tiOid==InvalidOid )
/* internal error */
elog(ERROR, "tsvector type has InvalidOid");
}
@ -339,18 +344,22 @@ ts_stat_sql(text *txt) {
get_ti_Oid();
if ( (plan = SPI_prepare(query,0,NULL))==NULL )
/* internal error */
elog(ERROR, "SPI_prepare('%s') returns NULL",query);
if ( (portal = SPI_cursor_open(NULL, plan, NULL, NULL)) == NULL )
/* internal error */
elog(ERROR, "SPI_cursor_open('%s') returns NULL",query);
SPI_cursor_fetch(portal, true, 100);
if ( SPI_tuptable->tupdesc->natts != 1 )
elog(ERROR, "Number of fields doesn't equal to 1");
/* internal error */
elog(ERROR, "number of fields doesn't equal to 1");
if ( SPI_gettypeid(SPI_tuptable->tupdesc, 1) != tiOid )
elog(ERROR, "Column isn't of tsvector type");
/* internal error */
elog(ERROR, "column isn't of tsvector type");
stat=palloc(STATHDRSIZE);
stat->len=STATHDRSIZE;

View File

@ -8,8 +8,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
#include "executor/spi.h"
@ -190,7 +188,9 @@ gettoken_tsvector(TI_IN_STATE * state)
oldstate = WAITENDWORD;
}
else if (state->oprisdelim && ISOPERATOR(*(state->prsbuf)))
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
else if (*(state->prsbuf) != ' ')
{
*(state->curpos) = *(state->prsbuf);
@ -201,7 +201,9 @@ gettoken_tsvector(TI_IN_STATE * state)
else if (state->state == WAITNEXTCHAR)
{
if (*(state->prsbuf) == '\0')
elog(ERROR, "There is no escaped character");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("there is no escaped character")));
else
{
RESIZEPRSBUF;
@ -222,12 +224,16 @@ gettoken_tsvector(TI_IN_STATE * state)
{
RESIZEPRSBUF;
if (state->curpos == state->word)
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
*(state->curpos) = '\0';
return 1;
} else if ( *(state->prsbuf) == ':' ) {
if (state->curpos == state->word)
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
*(state->curpos) = '\0';
if ( state->oprisdelim )
return 1;
@ -248,7 +254,9 @@ gettoken_tsvector(TI_IN_STATE * state)
RESIZEPRSBUF;
*(state->curpos) = '\0';
if (state->curpos == state->word)
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
if ( state->oprisdelim ) {
state->prsbuf++;
return 1;
@ -261,7 +269,9 @@ gettoken_tsvector(TI_IN_STATE * state)
oldstate = WAITENDCMPLX;
}
else if (*(state->prsbuf) == '\0')
elog(ERROR, "Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
else
{
RESIZEPRSBUF;
@ -286,36 +296,51 @@ gettoken_tsvector(TI_IN_STATE * state)
( *(uint16*)(state->pos) )++;
state->pos[ *(uint16*)(state->pos) ].pos = LIMITPOS(atoi(state->prsbuf));
if ( state->pos[ *(uint16*)(state->pos) ].pos == 0 )
elog(ERROR,"Wrong position info");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("wrong position info")));
state->pos[ *(uint16*)(state->pos) ].weight = 0;
state->state = WAITPOSDELIM;
} else
elog(ERROR,"Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
} else if (state->state == WAITPOSDELIM) {
if ( *(state->prsbuf) == ',' ) {
state->state = INPOSINFO;
} else if ( tolower(*(state->prsbuf)) == 'a' || *(state->prsbuf)=='*' ) {
if ( state->pos[ *(uint16*)(state->pos) ].weight )
elog(ERROR,"Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
state->pos[ *(uint16*)(state->pos) ].weight = 3;
} else if ( tolower(*(state->prsbuf)) == 'b' ) {
if ( state->pos[ *(uint16*)(state->pos) ].weight )
elog(ERROR,"Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
state->pos[ *(uint16*)(state->pos) ].weight = 2;
} else if ( tolower(*(state->prsbuf)) == 'c' ) {
if ( state->pos[ *(uint16*)(state->pos) ].weight )
elog(ERROR,"Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
state->pos[ *(uint16*)(state->pos) ].weight = 1;
} else if ( tolower(*(state->prsbuf)) == 'd' ) {
if ( state->pos[ *(uint16*)(state->pos) ].weight )
elog(ERROR,"Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
state->pos[ *(uint16*)(state->pos) ].weight = 0;
} else if ( isspace(*(state->prsbuf)) || *(state->prsbuf) == '\0' ) {
return 1;
} else if ( !isdigit(*(state->prsbuf)) )
elog(ERROR,"Syntax error");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
} else
elog(ERROR, "Inner bug :(");
/* internal error */
elog(ERROR, "internal error");
state->prsbuf++;
}
@ -360,10 +385,14 @@ tsvector_in(PG_FUNCTION_ARGS)
cur = tmpbuf + dist;
}
if (state.curpos - state.word >= MAXSTRLEN)
elog(ERROR, "Word is too long");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("word is too long")));
arr[len].entry.len= state.curpos - state.word;
if (cur - tmpbuf > MAXSTRPOS)
elog(ERROR, "Too long value");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("too long value")));
arr[len].entry.pos=cur - tmpbuf;
memcpy((void *) cur, (void *) state.word, arr[len].entry.len);
cur += arr[len].entry.len;
@ -583,7 +612,9 @@ makevalue(PRSTEXT * prs)
{
ptr->len = prs->words[i].len;
if (cur - str > MAXSTRPOS)
elog(ERROR, "Value is too big");
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("value is too big")));
ptr->pos= cur - str;
memcpy((void *) cur, (void *) prs->words[i].word, prs->words[i].len);
pfree(prs->words[i].word);
@ -701,12 +732,15 @@ tsearch2(PG_FUNCTION_ARGS)
Oid funcoid = InvalidOid;
if (!CALLED_AS_TRIGGER(fcinfo))
/* internal error */
elog(ERROR, "TSearch: Not fired by trigger manager");
trigdata = (TriggerData *) fcinfo->context;
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
/* internal error */
elog(ERROR, "TSearch: Can't process STATEMENT events");
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
/* internal error */
elog(ERROR, "TSearch: Must be fired BEFORE event");
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
@ -714,17 +748,21 @@ tsearch2(PG_FUNCTION_ARGS)
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
/* internal error */
elog(ERROR, "TSearch: Unknown event");
trigger = trigdata->tg_trigger;
rel = trigdata->tg_relation;
if (trigger->tgnargs < 2)
/* internal error */
elog(ERROR, "TSearch: format tsearch2(tsvector_field, text_field1,...)");
numidxattr = SPI_fnumber(rel->rd_att, trigger->tgargs[0]);
if (numidxattr == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "TSearch: Can not find tsvector_field");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("cannot find tsvector_field")));
prs.lenwords = 32;
prs.curwords = 0;
@ -745,7 +783,11 @@ tsearch2(PG_FUNCTION_ARGS)
{
funcoid=findFunc(trigger->tgargs[i]);
if ( funcoid==InvalidOid )
elog(ERROR,"TSearch: can't find function or field '%s'",trigger->tgargs[i]);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("cannot find function or field \"%s\"",
trigger->tgargs[i])));
continue;
}
oidtype = SPI_gettypeid(rel->rd_att, numattr);
@ -798,6 +840,7 @@ tsearch2(PG_FUNCTION_ARGS)
}
if (rettuple == NULL)
/* internal error */
elog(ERROR, "TSearch: %d returned by SPI_modifytuple", SPI_result);
return PointerGetDatum(rettuple);

View File

@ -6,8 +6,6 @@
#include "access/gist.h"
#include "access/itup.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
#include "executor/spi.h"
@ -79,7 +77,8 @@ setweight(PG_FUNCTION_ARGS)
case 'b': w=2; break;
case 'c': w=1; break;
case 'd': w=0; break;
default: elog(ERROR,"Unknown weight");
/* internal error */
default: elog(ERROR,"unrecognized weight");
}
out=(tsvector*)palloc(in->len);

View File

@ -195,11 +195,17 @@ prsd_headline(PG_FUNCTION_ARGS) {
pfree(map);
if ( min_words >= max_words )
elog(ERROR,"Must be MinWords < MaxWords");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("must be MinWords < MaxWords")));
if ( min_words<=0 )
elog(ERROR,"Must be MinWords > 0");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("must be MinWords > 0")));
if ( shortword<0 )
elog(ERROR,"Must be ShortWord >= 0");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("must be ShortWord >= 0")));
}
while( hlCover(prs,query,&p,&q) ) {

View File

@ -68,7 +68,9 @@ pgxml_parse(PG_FUNCTION_ARGS)
p = XML_ParserCreate_MM(NULL, &mhs, NULL);
if (!p)
{
elog(ERROR, "pgxml: Could not create expat parser");
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
errmsg("could not create expat parser")));
PG_RETURN_NULL(); /* seems appropriate if we couldn't parse */
}
@ -141,7 +143,9 @@ build_xpath_results(text *doc, text *pathstr)
p = XML_ParserCreate_MM(NULL, &mhs, NULL);
if (!p)
{
elog(ERROR, "pgxml: Could not create expat parser");
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
errmsg("could not create expat parser")));
pfree(xpr);
pfree(udata->path);
pfree(udata);
@ -267,7 +271,7 @@ pgxml_starthandler(void *userData, const XML_Char * name,
char sepstr[] = "/";
if ((strlen(name) + strlen(UD->currentpath)) > MAXPATHLENGTH - 2)
elog(WARNING, "Path too long");
elog(WARNING, "path too long");
else
{
strncat(UD->currentpath, sepstr, 1);
@ -297,12 +301,13 @@ pgxml_endhandler(void *userData, const XML_Char * name)
sepptr = strrchr(UD->currentpath, '/');
if (sepptr == NULL)
{
elog(ERROR, "There's a problem...");
/* internal error */
elog(ERROR, "did not find '/'");
sepptr = UD->currentpath;
}
if (strcmp(name, sepptr + 1) != 0)
{
elog(WARNING, "Wanted [%s], got [%s]", sepptr, name);
elog(WARNING, "wanted [%s], got [%s]", sepptr, name);
/* unmatched entry, so do nothing */
}
else

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: elog.h,v 1.55 2003/07/22 22:14:57 tgl Exp $
* $Id: elog.h,v 1.56 2003/07/24 17:52:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -100,6 +100,9 @@
#define ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN MAKE_SQLSTATE('0','8', '0','0','7')
#define ERRCODE_PROTOCOL_VIOLATION MAKE_SQLSTATE('0','8', 'P','0','1')
/* Class 09 - Triggered Action Exception */
#define ERRCODE_TRIGGERED_ACTION_EXCEPTION MAKE_SQLSTATE('0','9', '0','0','0')
/* Class 0A - Feature Not Supported */
#define ERRCODE_FEATURE_NOT_SUPPORTED MAKE_SQLSTATE('0','A', '0','0','0')

View File

@ -63,26 +63,29 @@ insert into fkeys2 values (40, '4', 5);
insert into fkeys2 values (50, '5', 3);
-- no key in pkeys
insert into fkeys2 values (70, '5', 3);
ERROR: check_fkeys2_pkey_exist: tuple references non-existing key in pkeys
ERROR: tuple references non-existent key
DETAIL: Trigger "check_fkeys2_pkey_exist" found tuple referencing non-existent key in "pkeys".
insert into fkeys values (10, '1', 2);
insert into fkeys values (30, '3', 3);
insert into fkeys values (40, '4', 2);
insert into fkeys values (50, '5', 2);
-- no key in pkeys
insert into fkeys values (70, '5', 1);
ERROR: check_fkeys_pkey_exist: tuple references non-existing key in pkeys
ERROR: tuple references non-existent key
DETAIL: Trigger "check_fkeys_pkey_exist" found tuple referencing non-existent key in "pkeys".
-- no key in fkeys2
insert into fkeys values (60, '6', 4);
ERROR: check_fkeys_pkey2_exist: tuple references non-existing key in fkeys2
ERROR: tuple references non-existent key
DETAIL: Trigger "check_fkeys_pkey2_exist" found tuple referencing non-existent key in "fkeys2".
delete from pkeys where pkey1 = 30 and pkey2 = '3';
NOTICE: check_pkeys_fkey_cascade: 1 tuple(s) of fkeys are deleted
ERROR: check_fkeys2_fkey_restrict: tuple referenced in fkeys
ERROR: "check_fkeys2_fkey_restrict": tuple is referenced in "fkeys"
delete from pkeys where pkey1 = 40 and pkey2 = '4';
NOTICE: check_pkeys_fkey_cascade: 1 tuple(s) of fkeys are deleted
NOTICE: check_pkeys_fkey_cascade: 1 tuple(s) of fkeys2 are deleted
update pkeys set pkey1 = 7, pkey2 = '70' where pkey1 = 50 and pkey2 = '5';
NOTICE: check_pkeys_fkey_cascade: 1 tuple(s) of fkeys are deleted
ERROR: check_fkeys2_fkey_restrict: tuple referenced in fkeys
ERROR: "check_fkeys2_fkey_restrict": tuple is referenced in "fkeys"
update pkeys set pkey1 = 7, pkey2 = '70' where pkey1 = 10 and pkey2 = '1';
NOTICE: check_pkeys_fkey_cascade: 1 tuple(s) of fkeys are deleted
NOTICE: check_pkeys_fkey_cascade: 1 tuple(s) of fkeys2 are deleted