Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17841dd

Browse files
committed
Improve error reporting in parseTypeString(), motivated by confusing
behavior reported by Martin Marques.
1 parent3b72087 commit17841dd

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

‎src/backend/parser/parse_type.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.62 2003/09/25 06:58:01 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.63 2003/10/20 17:25:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -430,14 +430,21 @@ typeidTypeRelid(Oid type_id)
430430
returnresult;
431431
}
432432

433+
/*
434+
* error context callback for parse failure during parseTypeString()
435+
*/
436+
staticvoid
437+
pts_error_callback(void*arg)
438+
{
439+
constchar*str= (constchar*)arg;
440+
441+
errcontext("invalid type name \"%s\"",str);
442+
}
443+
433444
/*
434445
* Given a string that is supposed to be a SQL-compatible type declaration,
435446
* such as "int4" or "integer" or "character varying(32)", parse
436447
* the string and convert it to a type OID and type modifier.
437-
*
438-
* This routine is not currently used by the main backend, but it is
439-
* exported for use by add-on modules such as plpgsql, in hopes of
440-
* centralizing parsing knowledge about SQL type declarations.
441448
*/
442449
void
443450
parseTypeString(constchar*str,Oid*type_id,int32*typmod)
@@ -448,12 +455,27 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
448455
ResTarget*restarget;
449456
TypeCast*typecast;
450457
TypeName*typename;
458+
ErrorContextCallbackptserrcontext;
459+
460+
/* make sure we give useful error for empty input */
461+
if (strspn(str," \t\n\r\f")==strlen(str))
462+
gotofail;
451463

452464
initStringInfo(&buf);
453-
appendStringInfo(&buf,"SELECT (NULL::%s)",str);
465+
appendStringInfo(&buf,"SELECT NULL::%s",str);
466+
467+
/*
468+
* Setup error traceback support in case of ereport() during parse
469+
*/
470+
ptserrcontext.callback=pts_error_callback;
471+
ptserrcontext.arg= (void*)str;
472+
ptserrcontext.previous=error_context_stack;
473+
error_context_stack=&ptserrcontext;
454474

455475
raw_parsetree_list=raw_parser(buf.data);
456476

477+
error_context_stack=ptserrcontext.previous;
478+
457479
/*
458480
* Make sure we got back exactly what we expected and no more;
459481
* paranoia is justified since the string might contain anything.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp