Remove encoding lookups from grammar stage, push them back to places

where it's safe to do database access.  Along the way, fix core dump
for 'DEFAULT' parameters to CREATE DATABASE.  initdb forced due to
change in pg_proc entry.
This commit is contained in:
Tom Lane 2002-11-02 18:41:22 +00:00
parent f6e0130b5b
commit 5123139210
11 changed files with 363 additions and 367 deletions

View File

@ -1,4 +1,4 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/keywords.sgml,v 2.6 2002/06/20 16:00:43 momjian Exp $ -->
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/keywords.sgml,v 2.7 2002/11/02 18:41:21 tgl Exp $ -->
<appendix id="sql-keywords-appendix">
<title><acronym>SQL</acronym> Key Words</title>
@ -682,7 +682,7 @@
</row>
<row>
<entry><token>CONVERT</token></entry>
<entry></entry>
<entry>non-reserved (cannot be function or type)</entry>
<entry>non-reserved</entry>
<entry>reserved</entry>
</row>

View File

@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.37 2002/11/02 02:33:03 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.38 2002/11/02 18:41:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1186,7 +1186,9 @@ makeRangeVarFromNameList(List *names)
/*
* NameListToString
* Utility routine to convert a qualified-name list into a string.
* Used primarily to form error messages.
*
* This is used primarily to form error messages, and so we do not quote
* the list elements, for the sake of legibility.
*/
char *
NameListToString(List *names)
@ -1206,6 +1208,31 @@ NameListToString(List *names)
return string.data;
}
/*
* NameListToQuotedString
* Utility routine to convert a qualified-name list into a string.
*
* Same as above except that names will be double-quoted where necessary,
* so the string could be re-parsed (eg, by textToQualifiedNameList).
*/
char *
NameListToQuotedString(List *names)
{
StringInfoData string;
List *l;
initStringInfo(&string);
foreach(l, names)
{
if (l != names)
appendStringInfoChar(&string, '.');
appendStringInfo(&string, "%s", quote_identifier(strVal(lfirst(l))));
}
return string.data;
}
/*
* isTempNamespace - is the given namespace my temporary-table namespace?
*/

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.7 2002/11/02 02:33:03 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.8 2002/11/02 18:41:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -273,38 +273,44 @@ FindConversion(const char *conname, Oid connamespace)
* CONVERT <left paren> <character value expression>
* USING <form-of-use conversion name> <right paren>
*
* TEXT convert3(TEXT string, OID conversion_oid);
* TEXT convert_using(TEXT string, TEXT conversion_name)
*/
Datum
pg_convert3(PG_FUNCTION_ARGS)
pg_convert_using(PG_FUNCTION_ARGS)
{
text *string = PG_GETARG_TEXT_P(0);
Oid convoid = PG_GETARG_OID(1);
text *conv_name = PG_GETARG_TEXT_P(1);
text *retval;
List *parsed_name;
Oid convoid;
HeapTuple tuple;
Form_pg_conversion body;
text *retval;
unsigned char *str;
unsigned char *result;
int len;
if (!OidIsValid(convoid))
elog(ERROR, "Conversion does not exist");
/* make sure that source string is null terminated */
/* Convert input string to null-terminated form */
len = VARSIZE(string) - VARHDRSZ;
str = palloc(len + 1);
memcpy(str, VARDATA(string), len);
*(str + len) = '\0';
/* Look up the conversion name */
parsed_name = textToQualifiedNameList(conv_name, "convert_using");
convoid = FindConversionByName(parsed_name);
if (!OidIsValid(convoid))
elog(ERROR, "conversion %s not found", NameListToString(parsed_name));
tuple = SearchSysCache(CONOID,
ObjectIdGetDatum(convoid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "Conversion %u search from syscache failed", convoid);
body = (Form_pg_conversion) GETSTRUCT(tuple);
/* Temporary result area should be more than big enough */
result = palloc(len * 4 + 1);
body = (Form_pg_conversion) GETSTRUCT(tuple);
OidFunctionCall5(body->conproc,
Int32GetDatum(body->conforencoding),
Int32GetDatum(body->contoencoding),
@ -315,7 +321,7 @@ pg_convert3(PG_FUNCTION_ARGS)
ReleaseSysCache(tuple);
/*
* build text data type structre. we cannot use textin() here, since
* build text result structure. we cannot use textin() here, since
* textin assumes that input string encoding is same as database
* encoding.
*/
@ -327,8 +333,5 @@ pg_convert3(PG_FUNCTION_ARGS)
pfree(result);
pfree(str);
/* free memory if allocated by the toaster */
PG_FREE_IF_COPY(string, 0);
PG_RETURN_TEXT_P(retval);
}

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.106 2002/10/21 22:06:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.107 2002/11/02 18:41:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -122,14 +122,34 @@ createdb(const CreatedbStmt *stmt)
defel->defname);
}
if (downer)
if (downer && downer->arg)
dbowner = strVal(downer->arg);
if (dpath)
if (dpath && dpath->arg)
dbpath = strVal(dpath->arg);
if (dtemplate)
if (dtemplate && dtemplate->arg)
dbtemplate = strVal(dtemplate->arg);
if (dencoding)
encoding = intVal(dencoding->arg);
if (dencoding && dencoding->arg)
{
const char *encoding_name;
if (IsA(dencoding->arg, Integer))
{
encoding = intVal(dencoding->arg);
encoding_name = pg_encoding_to_char(encoding);
if (strcmp(encoding_name, "") == 0 ||
pg_valid_server_encoding(encoding_name) < 0)
elog(ERROR, "%d is not a valid encoding code", encoding);
}
else if (IsA(dencoding->arg, String))
{
encoding_name = strVal(dencoding->arg);
if (pg_valid_server_encoding(encoding_name) < 0)
elog(ERROR, "%s is not a valid encoding name", encoding_name);
encoding = pg_char_to_encoding(encoding_name);
}
else
elog(ERROR, "CREATE DATABASE: bogus encoding parameter");
}
/* obtain sysid of proposed owner */
if (dbowner)

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.372 2002/11/01 22:52:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.373 2002/11/02 18:41:21 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -53,7 +53,6 @@
#include "access/htup.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
#include "nodes/params.h"
@ -63,7 +62,6 @@
#include "utils/numeric.h"
#include "utils/datetime.h"
#include "utils/date.h"
#include "mb/pg_wchar.h"
extern List *parsetree; /* final parse result is delivered here */
@ -217,8 +215,8 @@ static void doNegateFloat(Value *v);
group_clause TriggerFuncArgs select_limit
opt_select_limit opclass_item_list trans_options
TableFuncElementList
convert_args prep_type_clause prep_type_list
execute_param_clause execute_param_list
prep_type_clause prep_type_list
execute_param_clause
%type <range> into_clause OptTempTableName
@ -234,7 +232,7 @@ static void doNegateFloat(Value *v);
%type <jtype> join_type
%type <list> extract_list overlay_list position_list
%type <list> substr_list trim_list convert_list
%type <list> substr_list trim_list
%type <ival> opt_interval
%type <node> overlay_placing substr_from substr_for
@ -265,7 +263,7 @@ static void doNegateFloat(Value *v);
%type <node> def_arg columnElem where_clause insert_column_item
a_expr b_expr c_expr r_expr AexprConst
in_expr having_clause func_table
%type <list> row row_descriptor row_list in_expr_nodes type_list
%type <list> row row_descriptor type_list
%type <node> case_expr case_arg when_clause case_default
%type <list> when_clause_list
%type <ival> sub_type
@ -325,8 +323,8 @@ static void doNegateFloat(Value *v);
AGGREGATE ALL ALTER ANALYSE ANALYZE AND ANY AS ASC
ASSERTION ASSIGNMENT AT AUTHORIZATION
BACKWARD BEFORE BEGIN_TRANS BETWEEN BIGINT BINARY BIT BOTH
BOOLEAN BY
BACKWARD BEFORE BEGIN_TRANS BETWEEN BIGINT BINARY BIT
BOOLEAN BOTH BY
CACHE CALLED CASCADE CASE CAST CHAIN CHAR_P
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
@ -355,6 +353,7 @@ static void doNegateFloat(Value *v);
INTERVAL INTO INVOKER IS ISNULL ISOLATION
JOIN
KEY
LANCOMPILER LANGUAGE LEADING LEFT LEVEL LIKE LIMIT
@ -371,8 +370,7 @@ static void doNegateFloat(Value *v);
ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNER
PARTIAL PASSWORD PATH_P PENDANT PLACING POSITION
PRECISION PREPARE PRIMARY PRIOR PRIVILEGES PROCEDURE
PROCEDURAL
PRECISION PREPARE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE
READ REAL RECHECK REFERENCES REINDEX RELATIVE RENAME REPLACE
RESET RESTRICT RETURNS REVOKE RIGHT ROLLBACK ROW
@ -3618,27 +3616,15 @@ createdb_opt_item:
}
| ENCODING opt_equal Sconst
{
int encoding;
if (pg_valid_server_encoding($3) < 0)
elog(ERROR, "%s is not a valid encoding name", $3);
encoding = pg_char_to_encoding($3);
$$ = makeDefElem("encoding", (Node *)makeInteger(encoding));
$$ = makeDefElem("encoding", (Node *)makeString($3));
}
| ENCODING opt_equal Iconst
{
const char *encoding_name;
encoding_name = pg_encoding_to_char($3);
if (!strcmp(encoding_name,"") ||
pg_valid_server_encoding(encoding_name) < 0)
elog(ERROR, "%d is not a valid encoding code", $3);
$$ = makeDefElem("encoding", (Node *)makeInteger($3));
}
| ENCODING opt_equal DEFAULT
{
$$ = makeDefElem("encoding", (Node *)makeInteger(-1));
$$ = makeDefElem("encoding", NULL);
}
| OWNER opt_equal name
{
@ -3932,14 +3918,10 @@ ExecuteStmt: EXECUTE name execute_param_clause into_clause
}
;
execute_param_clause: '(' execute_param_list ')' { $$ = $2; }
execute_param_clause: '(' expr_list ')' { $$ = $2; }
| /* EMPTY */ { $$ = NIL; }
;
execute_param_list: a_expr { $$ = makeList1($1); }
| execute_param_list ',' a_expr { $$ = lappend($1, $3); }
;
/*****************************************************************************
*
* QUERY:
@ -5470,14 +5452,9 @@ row: ROW '(' row_descriptor ')' { $$ = $3; }
| ROW '(' a_expr ')' { $$ = makeList1($3); }
| ROW '(' ')' { $$ = NULL; }
| '(' row_descriptor ')' { $$ = $2; }
;
row_descriptor:
row_list ',' a_expr { $$ = lappend($1, $3); }
;
row_list: a_expr { $$ = makeList1($1); }
| row_list ',' a_expr { $$ = lappend($1, $3); }
row_descriptor: expr_list ',' a_expr { $$ = lappend($1, $3); }
;
sub_type: ANY { $$ = ANY_SUBLINK; }
@ -6366,7 +6343,21 @@ c_expr: columnref { $$ = (Node *) $1; }
n->agg_distinct = FALSE;
$$ = (Node *)n;
}
| CONVERT '(' convert_list ')'
| CONVERT '(' a_expr USING any_name ')'
{
FuncCall *n = makeNode(FuncCall);
A_Const *c = makeNode(A_Const);
c->val.type = T_String;
c->val.val.str = NameListToQuotedString($5);
n->funcname = SystemFuncName("convert_using");
n->args = makeList2($3, c);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
$$ = (Node *)n;
}
| CONVERT '(' expr_list ')'
{
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("convert");
@ -6422,7 +6413,6 @@ opt_indirection:
expr_list: a_expr { $$ = makeList1($1); }
| expr_list ',' a_expr { $$ = lappend($1, $3); }
| expr_list USING a_expr { $$ = lappend($1, $3); }
;
extract_list:
@ -6540,60 +6530,13 @@ trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
| expr_list { $$ = $1; }
;
/* CONVERT() arguments. We accept followings:
* SQL99 syntax
* o CONVERT(TEXT string USING conversion_name)
*
* Function calls
* o CONVERT(TEXT string, NAME src_encoding_name, NAME dest_encoding_name)
* o CONVERT(TEXT string, NAME encoding_name)
*/
convert_list:
a_expr USING any_name
{
Oid oid = FindConversionByName($3);
Const *convoid = makeNode(Const);
if (!OidIsValid(oid))
{
elog(ERROR, "Conversion \"%s\" does not exist",
NameListToString($3));
}
convoid->consttype = OIDOID;
convoid->constlen = sizeof(Oid);
convoid->constvalue = oid;
convoid->constisnull = FALSE;
convoid->constbyval = TRUE;
convoid->constisset = FALSE;
convoid->constiscast = FALSE;
$$ = makeList2($1, convoid);
}
| convert_args
{
$$ = $1;
}
| /*EMPTY*/
{ $$ = NIL; }
;
convert_args: a_expr { $$ = makeList1($1); }
| convert_args ',' a_expr { $$ = lappend($1, $3); }
;
in_expr: select_with_parens
{
SubLink *n = makeNode(SubLink);
n->subselect = $1;
$$ = (Node *)n;
}
| '(' in_expr_nodes ')' { $$ = (Node *)$2; }
;
in_expr_nodes:
a_expr { $$ = makeList1($1); }
| in_expr_nodes ',' a_expr { $$ = lappend($1, $3); }
| '(' expr_list ')' { $$ = (Node *)$2; }
;
/* Case clause
@ -7215,6 +7158,7 @@ col_name_keyword:
| CHAR_P
| CHARACTER
| COALESCE
| CONVERT
| DEC
| DECIMAL
| EXISTS

View File

@ -3,9 +3,11 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.35 2002/09/04 20:31:31 momjian Exp $
*
* $Header: /cvsroot/pgsql/src/backend/utils/mb/mbutils.c,v 1.36 2002/11/02 18:41:22 tgl Exp $
*/
#include "postgres.h"
#include "access/xact.h"
#include "miscadmin.h"
#include "mb/pg_wchar.h"
@ -23,19 +25,18 @@ static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
/*
* Caches for conversion function info. Note that Fcinfo.flinfo is
* allocated in TopMemoryContext so that it survives outside
* Caches for conversion function info. Note that these values are
* allocated in TopMemoryContext so that they survive across
* transactions. See SetClientEncoding() for more details.
*/
static FmgrInfo *ToServerConvPorc = NULL;
static FmgrInfo *ToClientConvPorc = NULL;
static FmgrInfo *ToServerConvProc = NULL;
static FmgrInfo *ToClientConvProc = NULL;
/* Internal functions */
static unsigned char *
perform_default_encoding_conversion(unsigned char *src, int len, bool is_client_to_server);
static unsigned char *perform_default_encoding_conversion(unsigned char *src,
int len, bool is_client_to_server);
static int cliplen(const unsigned char *str, int len, int limit);
static int
cliplen(const unsigned char *str, int len, int limit);
/*
* Set the client encoding and save fmgrinfo for the converion
@ -95,21 +96,21 @@ SetClientEncoding(int encoding, bool doit)
{
ClientEncoding = &pg_enc2name_tbl[encoding];
if (ToServerConvPorc != NULL)
if (ToServerConvProc != NULL)
{
if (ToServerConvPorc->fn_extra)
pfree(ToServerConvPorc->fn_extra);
pfree(ToServerConvPorc);
if (ToServerConvProc->fn_extra)
pfree(ToServerConvProc->fn_extra);
pfree(ToServerConvProc);
}
ToServerConvPorc = to_server;
ToServerConvProc = to_server;
if (ToClientConvPorc != NULL)
if (ToClientConvProc != NULL)
{
if (ToClientConvPorc->fn_extra)
pfree(ToClientConvPorc->fn_extra);
pfree(ToClientConvPorc);
if (ToClientConvProc->fn_extra)
pfree(ToClientConvProc->fn_extra);
pfree(ToClientConvProc);
}
ToClientConvPorc = to_client;
ToClientConvProc = to_client;
}
return 0;
}
@ -323,13 +324,13 @@ perform_default_encoding_conversion(unsigned char *src, int len, bool is_client_
{
src_encoding = ClientEncoding->encoding;
dest_encoding = DatabaseEncoding->encoding;
flinfo = ToServerConvPorc;
flinfo = ToServerConvProc;
}
else
{
src_encoding = DatabaseEncoding->encoding;
dest_encoding = ClientEncoding->encoding;
flinfo = ToClientConvPorc;
flinfo = ToClientConvProc;
}
if (flinfo == NULL)

View File

@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: catversion.h,v 1.162 2002/10/19 02:08:18 momjian Exp $
* $Id: catversion.h,v 1.163 2002/11/02 18:41:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200210181
#define CATALOG_VERSION_NO 200211021
#endif

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: namespace.h,v 1.21 2002/09/23 20:43:41 tgl Exp $
* $Id: namespace.h,v 1.22 2002/11/02 18:41:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -74,6 +74,7 @@ extern Oid LookupExplicitNamespace(const char *nspname);
extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p);
extern RangeVar *makeRangeVarFromNameList(List *names);
extern char *NameListToString(List *names);
extern char *NameListToQuotedString(List *names);
extern bool isTempNamespace(Oid namespaceId);
extern bool isOtherTempNamespace(Oid namespaceId);

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: pg_proc.h,v 1.274 2002/10/19 02:08:18 momjian Exp $
* $Id: pg_proc.h,v 1.275 2002/11/02 18:41:22 tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
@ -2166,8 +2166,8 @@ DESCR("convert string with specified destination encoding name");
DATA(insert OID = 1813 ( convert PGNSP PGUID 12 f f t f s 3 25 "25 19 19" pg_convert2 - _null_ ));
DESCR("convert string with specified encoding names");
DATA(insert OID = 90 ( convert PGNSP PGUID 12 f f t f s 2 25 "25 26" pg_convert3 - _null_ ));
DESCR("convert string with specified conversion oid");
DATA(insert OID = 1619 ( convert_using PGNSP PGUID 12 f f t f s 2 25 "25 25" pg_convert_using - _null_ ));
DESCR("convert string with specified conversion name");
DATA(insert OID = 1264 ( pg_char_to_encoding PGNSP PGUID 12 f f t f s 1 23 "19" PG_char_to_encoding - _null_ ));
DESCR("convert encoding name to encoding id");

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: builtins.h,v 1.203 2002/10/19 02:08:18 momjian Exp $
* $Id: builtins.h,v 1.204 2002/11/02 18:41:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -696,6 +696,6 @@ extern Datum show_all_settings(PG_FUNCTION_ARGS);
extern Datum pg_lock_status(PG_FUNCTION_ARGS);
/* catalog/pg_conversion.c */
extern Datum pg_convert3(PG_FUNCTION_ARGS);
extern Datum pg_convert_using(PG_FUNCTION_ARGS);
#endif /* BUILTINS_H */

File diff suppressed because it is too large Load Diff