| |
(144 rows)
+-- test non error throwing API
+SELECT str as seg,
+ pg_input_is_valid(str,'seg') as ok,
+ pg_input_error_message(str,'seg') as errmsg
+FROM unnest(ARRAY['-1 .. 1'::text,
+ '100(+-)1',
+ '',
+ 'ABC',
+ '1 e7',
+ '1e700']) str;
+ seg | ok | errmsg
+----------+----+---------------------------------------
+ -1 .. 1 | t |
+ 100(+-)1 | t |
+ | f | bad seg representation
+ ABC | f | bad seg representation
+ 1 e7 | f | bad seg representation
+ 1e700 | f | "1e700" is out of range for type real
+(6 rows)
+
seg_scanner_init(str);
- if (seg_yyparse(result) != 0)
- seg_yyerror(result, "bogus input");
+ if (seg_yyparse(result, fcinfo->context) != 0)
+ seg_yyerror(result, fcinfo->context, "bogus input");
seg_scanner_finish();
/* in segscan.l */
extern int seg_yylex(void);
-extern void seg_yyerror(SEG *result, const char *message) pg_attribute_noreturn();
+extern void seg_yyerror(SEG *result, struct Node *escontext,
+ const char *message);
extern void seg_scanner_init(const char *str);
extern void seg_scanner_finish(void);
/* in segparse.y */
-extern int seg_yyparse(SEG *result);
+extern int seg_yyparse(SEG *result, struct Node *escontext);
#include <math.h>
#include "fmgr.h"
+#include "nodes/miscnodes.h"
#include "utils/builtins.h"
+#include "utils/float.h"
#include "segdata.h"
#define YYMALLOC palloc
#define YYFREE pfree
-static float seg_atof(const char *value);
+static bool seg_atof(char *value, float *result, struct Node *escontext);
static int sig_digits(const char *value);
/* BISON Declarations */
%parse-param {SEG *result}
+%parse-param {struct Node *escontext}
%expect 0
%name-prefix="seg_yy"
result->lower = $1.val;
result->upper = $3.val;
if ( result->lower > result->upper ) {
- ereport(ERROR,
+ errsave(escontext,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("swapped boundaries: %g is greater than %g",
result->lower, result->upper)));
boundary: SEGFLOAT
{
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */
- float val = seg_atof($1);
+ float val;
+
+ if (!seg_atof($1, &val, escontext))
+ YYABORT;
$$.ext = '\0';
$$.sigd = sig_digits($1);
| EXTENSION SEGFLOAT
{
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */
- float val = seg_atof($2);
+ float val;
+
+ if (!seg_atof($2, &val, escontext))
+ YYABORT;
$$.ext = $1[0];
$$.sigd = sig_digits($2);
deviation: SEGFLOAT
{
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */
- float val = seg_atof($1);
+ float val;
+
+ if (!seg_atof($1, &val, escontext))
+ YYABORT;
$$.ext = '\0';
$$.sigd = sig_digits($1);
%%
-static float
-seg_atof(const char *value)
+static bool
+seg_atof(char *value, float *result, struct Node *escontext)
{
- Datum datum;
-
- datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
- return DatumGetFloat4(datum);
+ *result = float4in_internal(value, NULL, "seg", value, escontext);
+ if (SOFT_ERROR_OCCURRED(escontext))
+ return false;
+ return true;
}
static int
*/
#include "postgres.h"
+#include "nodes/miscnodes.h"
+
/*
* NB: include segparse.h only AFTER including segdata.h, because segdata.h
* contains the definition for SEG.
/* LCOV_EXCL_STOP */
void
-seg_yyerror(SEG *result, const char *message)
+seg_yyerror(SEG *result, struct Node *escontext, const char *message)
{
+ /* if we already reported an error, don't overwrite it */
+ if (SOFT_ERROR_OCCURRED(escontext))
+ return;
+
if (*yytext == YY_END_OF_BUFFER_CHAR)
{
- ereport(ERROR,
+ errsave(escontext,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad seg representation"),
/* translator: %s is typically "syntax error" */
}
else
{
- ereport(ERROR,
+ errsave(escontext,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad seg representation"),
/* translator: first %s is typically "syntax error" */
-- Test functions
SELECT seg_lower(s), seg_center(s), seg_upper(s)
FROM test_seg WHERE s @> '11.2..11.3' OR s IS NULL ORDER BY s;
+
+
+-- test non error throwing API
+
+SELECT str as seg,
+ pg_input_is_valid(str,'seg') as ok,
+ pg_input_error_message(str,'seg') as errmsg
+FROM unnest(ARRAY['-1 .. 1'::text,
+ '100(+-)1',
+ '',
+ 'ABC',
+ '1 e7',
+ '1e700']) str;