8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -430,14 +430,21 @@ typeidTypeRelid(Oid type_id)
430
430
return result ;
431
431
}
432
432
433
+ /*
434
+ * error context callback for parse failure during parseTypeString()
435
+ */
436
+ static void
437
+ pts_error_callback (void * arg )
438
+ {
439
+ const char * str = (const char * ) arg ;
440
+
441
+ errcontext ("invalid type name \"%s\"" , str );
442
+ }
443
+
433
444
/*
434
445
* Given a string that is supposed to be a SQL-compatible type declaration,
435
446
* such as "int4" or "integer" or "character varying(32)", parse
436
447
* 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.
441
448
*/
442
449
void
443
450
parseTypeString (const char * str , Oid * type_id , int32 * typmod )
@@ -448,12 +455,27 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
448
455
ResTarget * restarget ;
449
456
TypeCast * typecast ;
450
457
TypeName * typename ;
458
+ ErrorContextCallback ptserrcontext ;
459
+
460
+ /* make sure we give useful error for empty input */
461
+ if (strspn (str , " \t\n\r\f" ) == strlen (str ))
462
+ goto fail ;
451
463
452
464
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 ;
454
474
455
475
raw_parsetree_list = raw_parser (buf .data );
456
476
477
+ error_context_stack = ptserrcontext .previous ;
478
+
457
479
/*
458
480
* Make sure we got back exactly what we expected and no more;
459
481
* paranoia is justified since the string might contain anything.
0 commit comments