Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5123139

Browse files
committed
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.
1 parent f6e0130 commit 5123139

File tree

11 files changed

+363
-367
lines changed

11 files changed

+363
-367
lines changed

doc/src/sgml/keywords.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/keywords.sgml,v 2.6 2002/06/20 16:00:43 momjian Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/keywords.sgml,v 2.7 2002/11/02 18:41:21 tgl Exp $ -->
22

33
<appendix id="sql-keywords-appendix">
44
<title><acronym>SQL</acronym> Key Words</title>
@@ -682,7 +682,7 @@
682682
</row>
683683
<row>
684684
<entry><token>CONVERT</token></entry>
685-
<entry></entry>
685+
<entry>non-reserved (cannot be function or type)</entry>
686686
<entry>non-reserved</entry>
687687
<entry>reserved</entry>
688688
</row>

src/backend/catalog/namespace.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.37 2002/11/02 02:33:03 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.38 2002/11/02 18:41:21 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1186,7 +1186,9 @@ makeRangeVarFromNameList(List *names)
11861186
/*
11871187
* NameListToString
11881188
* Utility routine to convert a qualified-name list into a string.
1189-
* Used primarily to form error messages.
1189+
*
1190+
* This is used primarily to form error messages, and so we do not quote
1191+
* the list elements, for the sake of legibility.
11901192
*/
11911193
char *
11921194
NameListToString(List *names)
@@ -1206,6 +1208,31 @@ NameListToString(List *names)
12061208
return string.data;
12071209
}
12081210

1211+
/*
1212+
* NameListToQuotedString
1213+
* Utility routine to convert a qualified-name list into a string.
1214+
*
1215+
* Same as above except that names will be double-quoted where necessary,
1216+
* so the string could be re-parsed (eg, by textToQualifiedNameList).
1217+
*/
1218+
char *
1219+
NameListToQuotedString(List *names)
1220+
{
1221+
StringInfoData string;
1222+
List *l;
1223+
1224+
initStringInfo(&string);
1225+
1226+
foreach(l, names)
1227+
{
1228+
if (l != names)
1229+
appendStringInfoChar(&string, '.');
1230+
appendStringInfo(&string, "%s", quote_identifier(strVal(lfirst(l))));
1231+
}
1232+
1233+
return string.data;
1234+
}
1235+
12091236
/*
12101237
* isTempNamespace - is the given namespace my temporary-table namespace?
12111238
*/

src/backend/catalog/pg_conversion.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.7 2002/11/02 02:33:03 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.8 2002/11/02 18:41:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -273,38 +273,44 @@ FindConversion(const char *conname, Oid connamespace)
273273
* CONVERT <left paren> <character value expression>
274274
* USING <form-of-use conversion name> <right paren>
275275
*
276-
* TEXT convert3(TEXT string, OID conversion_oid);
276+
* TEXT convert_using(TEXT string, TEXT conversion_name)
277277
*/
278278
Datum
279-
pg_convert3(PG_FUNCTION_ARGS)
279+
pg_convert_using(PG_FUNCTION_ARGS)
280280
{
281281
text *string = PG_GETARG_TEXT_P(0);
282-
Oid convoid = PG_GETARG_OID(1);
282+
text *conv_name = PG_GETARG_TEXT_P(1);
283+
text *retval;
284+
List *parsed_name;
285+
Oid convoid;
283286
HeapTuple tuple;
284287
Form_pg_conversion body;
285-
text *retval;
286288
unsigned char *str;
287289
unsigned char *result;
288290
int len;
289291

290-
if (!OidIsValid(convoid))
291-
elog(ERROR, "Conversion does not exist");
292-
293-
/* make sure that source string is null terminated */
292+
/* Convert input string to null-terminated form */
294293
len = VARSIZE(string) - VARHDRSZ;
295294
str = palloc(len + 1);
296295
memcpy(str, VARDATA(string), len);
297296
*(str + len) = '\0';
298297

298+
/* Look up the conversion name */
299+
parsed_name = textToQualifiedNameList(conv_name, "convert_using");
300+
convoid = FindConversionByName(parsed_name);
301+
if (!OidIsValid(convoid))
302+
elog(ERROR, "conversion %s not found", NameListToString(parsed_name));
303+
299304
tuple = SearchSysCache(CONOID,
300305
ObjectIdGetDatum(convoid),
301306
0, 0, 0);
302307
if (!HeapTupleIsValid(tuple))
303308
elog(ERROR, "Conversion %u search from syscache failed", convoid);
309+
body = (Form_pg_conversion) GETSTRUCT(tuple);
304310

311+
/* Temporary result area should be more than big enough */
305312
result = palloc(len * 4 + 1);
306313

307-
body = (Form_pg_conversion) GETSTRUCT(tuple);
308314
OidFunctionCall5(body->conproc,
309315
Int32GetDatum(body->conforencoding),
310316
Int32GetDatum(body->contoencoding),
@@ -315,7 +321,7 @@ pg_convert3(PG_FUNCTION_ARGS)
315321
ReleaseSysCache(tuple);
316322

317323
/*
318-
* build text data type structre. we cannot use textin() here, since
324+
* build text result structure. we cannot use textin() here, since
319325
* textin assumes that input string encoding is same as database
320326
* encoding.
321327
*/
@@ -327,8 +333,5 @@ pg_convert3(PG_FUNCTION_ARGS)
327333
pfree(result);
328334
pfree(str);
329335

330-
/* free memory if allocated by the toaster */
331-
PG_FREE_IF_COPY(string, 0);
332-
333336
PG_RETURN_TEXT_P(retval);
334337
}

src/backend/commands/dbcommands.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.106 2002/10/21 22:06:19 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.107 2002/11/02 18:41:21 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -122,14 +122,34 @@ createdb(const CreatedbStmt *stmt)
122122
defel->defname);
123123
}
124124

125-
if (downer)
125+
if (downer && downer->arg)
126126
dbowner = strVal(downer->arg);
127-
if (dpath)
127+
if (dpath && dpath->arg)
128128
dbpath = strVal(dpath->arg);
129-
if (dtemplate)
129+
if (dtemplate && dtemplate->arg)
130130
dbtemplate = strVal(dtemplate->arg);
131-
if (dencoding)
132-
encoding = intVal(dencoding->arg);
131+
if (dencoding && dencoding->arg)
132+
{
133+
const char *encoding_name;
134+
135+
if (IsA(dencoding->arg, Integer))
136+
{
137+
encoding = intVal(dencoding->arg);
138+
encoding_name = pg_encoding_to_char(encoding);
139+
if (strcmp(encoding_name, "") == 0 ||
140+
pg_valid_server_encoding(encoding_name) < 0)
141+
elog(ERROR, "%d is not a valid encoding code", encoding);
142+
}
143+
else if (IsA(dencoding->arg, String))
144+
{
145+
encoding_name = strVal(dencoding->arg);
146+
if (pg_valid_server_encoding(encoding_name) < 0)
147+
elog(ERROR, "%s is not a valid encoding name", encoding_name);
148+
encoding = pg_char_to_encoding(encoding_name);
149+
}
150+
else
151+
elog(ERROR, "CREATE DATABASE: bogus encoding parameter");
152+
}
133153

134154
/* obtain sysid of proposed owner */
135155
if (dbowner)

0 commit comments

Comments
 (0)