mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Remove ancient downcasing code from procedural language operations.
A very long time ago, language names were specified as literals rather than identifiers, so this code was added to do case-folding. But that style has ben deprecated for many years so this isn't needed any more. Language names will still be downcased when specified as unquoted identifiers, but quoted identifiers or the old style using string literals will be left as-is.
This commit is contained in:
parent
ee3ef8f30c
commit
67dc4eed42
@ -143,9 +143,8 @@ CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="pa
|
|||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The name of the new procedural language. The language name is
|
The name of the new procedural language.
|
||||||
case insensitive. The name must be unique among the languages
|
The name must be unique among the languages in the database.
|
||||||
in the database.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -42,19 +42,6 @@
|
|||||||
#include "parser/scansup.h"
|
#include "parser/scansup.h"
|
||||||
#include "utils/int8.h"
|
#include "utils/int8.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Translate the input language name to lower case, and truncate if needed.
|
|
||||||
*
|
|
||||||
* Returns a palloc'd string
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
case_translate_language_name(const char *input)
|
|
||||||
{
|
|
||||||
return downcase_truncate_identifier(input, strlen(input), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extract a string value (otherwise uninterpreted) from a DefElem.
|
* Extract a string value (otherwise uninterpreted) from a DefElem.
|
||||||
*/
|
*/
|
||||||
|
@ -779,7 +779,6 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString)
|
|||||||
Oid prorettype;
|
Oid prorettype;
|
||||||
bool returnsSet;
|
bool returnsSet;
|
||||||
char *language;
|
char *language;
|
||||||
char *languageName;
|
|
||||||
Oid languageOid;
|
Oid languageOid;
|
||||||
Oid languageValidator;
|
Oid languageValidator;
|
||||||
char *funcname;
|
char *funcname;
|
||||||
@ -828,16 +827,13 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString)
|
|||||||
&isStrict, &security,
|
&isStrict, &security,
|
||||||
&proconfig, &procost, &prorows);
|
&proconfig, &procost, &prorows);
|
||||||
|
|
||||||
/* Convert language name to canonical case */
|
|
||||||
languageName = case_translate_language_name(language);
|
|
||||||
|
|
||||||
/* Look up the language and validate permissions */
|
/* Look up the language and validate permissions */
|
||||||
languageTuple = SearchSysCache1(LANGNAME, PointerGetDatum(languageName));
|
languageTuple = SearchSysCache1(LANGNAME, PointerGetDatum(language));
|
||||||
if (!HeapTupleIsValid(languageTuple))
|
if (!HeapTupleIsValid(languageTuple))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("language \"%s\" does not exist", languageName),
|
errmsg("language \"%s\" does not exist", language),
|
||||||
(PLTemplateExists(languageName) ?
|
(PLTemplateExists(language) ?
|
||||||
errhint("Use CREATE LANGUAGE to load the language into the database.") : 0)));
|
errhint("Use CREATE LANGUAGE to load the language into the database.") : 0)));
|
||||||
|
|
||||||
languageOid = HeapTupleGetOid(languageTuple);
|
languageOid = HeapTupleGetOid(languageTuple);
|
||||||
@ -906,7 +902,7 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString)
|
|||||||
|
|
||||||
compute_attributes_with_style(stmt->withClause, &isStrict, &volatility);
|
compute_attributes_with_style(stmt->withClause, &isStrict, &volatility);
|
||||||
|
|
||||||
interpret_AS_clause(languageOid, languageName, funcname, as_clause,
|
interpret_AS_clause(languageOid, language, funcname, as_clause,
|
||||||
&prosrc_str, &probin_str);
|
&prosrc_str, &probin_str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1964,7 +1960,6 @@ ExecuteDoStmt(DoStmt *stmt)
|
|||||||
DefElem *as_item = NULL;
|
DefElem *as_item = NULL;
|
||||||
DefElem *language_item = NULL;
|
DefElem *language_item = NULL;
|
||||||
char *language;
|
char *language;
|
||||||
char *languageName;
|
|
||||||
Oid laninline;
|
Oid laninline;
|
||||||
HeapTuple languageTuple;
|
HeapTuple languageTuple;
|
||||||
Form_pg_language languageStruct;
|
Form_pg_language languageStruct;
|
||||||
@ -2008,16 +2003,13 @@ ExecuteDoStmt(DoStmt *stmt)
|
|||||||
else
|
else
|
||||||
language = "plpgsql";
|
language = "plpgsql";
|
||||||
|
|
||||||
/* Convert language name to canonical case */
|
|
||||||
languageName = case_translate_language_name(language);
|
|
||||||
|
|
||||||
/* Look up the language and validate permissions */
|
/* Look up the language and validate permissions */
|
||||||
languageTuple = SearchSysCache1(LANGNAME, PointerGetDatum(languageName));
|
languageTuple = SearchSysCache1(LANGNAME, PointerGetDatum(language));
|
||||||
if (!HeapTupleIsValid(languageTuple))
|
if (!HeapTupleIsValid(languageTuple))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("language \"%s\" does not exist", languageName),
|
errmsg("language \"%s\" does not exist", language),
|
||||||
(PLTemplateExists(languageName) ?
|
(PLTemplateExists(language) ?
|
||||||
errhint("Use CREATE LANGUAGE to load the language into the database.") : 0)));
|
errhint("Use CREATE LANGUAGE to load the language into the database.") : 0)));
|
||||||
|
|
||||||
codeblock->langOid = HeapTupleGetOid(languageTuple);
|
codeblock->langOid = HeapTupleGetOid(languageTuple);
|
||||||
|
@ -64,7 +64,6 @@ static void AlterLanguageOwner_internal(HeapTuple tup, Relation rel,
|
|||||||
void
|
void
|
||||||
CreateProceduralLanguage(CreatePLangStmt *stmt)
|
CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||||
{
|
{
|
||||||
char *languageName;
|
|
||||||
PLTemplate *pltemplate;
|
PLTemplate *pltemplate;
|
||||||
Oid handlerOid,
|
Oid handlerOid,
|
||||||
inlineOid,
|
inlineOid,
|
||||||
@ -72,16 +71,11 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
|||||||
Oid funcrettype;
|
Oid funcrettype;
|
||||||
Oid funcargtypes[1];
|
Oid funcargtypes[1];
|
||||||
|
|
||||||
/*
|
|
||||||
* Translate the language name to lower case
|
|
||||||
*/
|
|
||||||
languageName = case_translate_language_name(stmt->plname);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have template information for the language, ignore the supplied
|
* If we have template information for the language, ignore the supplied
|
||||||
* parameters (if any) and use the template information.
|
* parameters (if any) and use the template information.
|
||||||
*/
|
*/
|
||||||
if ((pltemplate = find_language_template(languageName)) != NULL)
|
if ((pltemplate = find_language_template(stmt->plname)) != NULL)
|
||||||
{
|
{
|
||||||
List *funcname;
|
List *funcname;
|
||||||
|
|
||||||
@ -101,7 +95,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
|||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||||
errmsg("must be superuser to create procedural language \"%s\"",
|
errmsg("must be superuser to create procedural language \"%s\"",
|
||||||
languageName)));
|
stmt->plname)));
|
||||||
if (!pg_database_ownercheck(MyDatabaseId, GetUserId()))
|
if (!pg_database_ownercheck(MyDatabaseId, GetUserId()))
|
||||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
||||||
get_database_name(MyDatabaseId));
|
get_database_name(MyDatabaseId));
|
||||||
@ -226,7 +220,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
|||||||
valOid = InvalidOid;
|
valOid = InvalidOid;
|
||||||
|
|
||||||
/* ok, create it */
|
/* ok, create it */
|
||||||
create_proc_lang(languageName, stmt->replace, GetUserId(),
|
create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
||||||
handlerOid, inlineOid,
|
handlerOid, inlineOid,
|
||||||
valOid, pltemplate->tmpltrusted);
|
valOid, pltemplate->tmpltrusted);
|
||||||
}
|
}
|
||||||
@ -241,7 +235,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
|||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("unsupported language \"%s\"",
|
errmsg("unsupported language \"%s\"",
|
||||||
languageName),
|
stmt->plname),
|
||||||
errhint("The supported languages are listed in the pg_pltemplate system catalog.")));
|
errhint("The supported languages are listed in the pg_pltemplate system catalog.")));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -301,7 +295,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
|||||||
valOid = InvalidOid;
|
valOid = InvalidOid;
|
||||||
|
|
||||||
/* ok, create it */
|
/* ok, create it */
|
||||||
create_proc_lang(languageName, stmt->replace, GetUserId(),
|
create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
||||||
handlerOid, inlineOid,
|
handlerOid, inlineOid,
|
||||||
valOid, stmt->pltrusted);
|
valOid, stmt->pltrusted);
|
||||||
}
|
}
|
||||||
@ -521,21 +515,15 @@ PLTemplateExists(const char *languageName)
|
|||||||
void
|
void
|
||||||
DropProceduralLanguage(DropPLangStmt *stmt)
|
DropProceduralLanguage(DropPLangStmt *stmt)
|
||||||
{
|
{
|
||||||
char *languageName;
|
|
||||||
Oid oid;
|
Oid oid;
|
||||||
ObjectAddress object;
|
ObjectAddress object;
|
||||||
|
|
||||||
/*
|
oid = get_language_oid(stmt->plname, stmt->missing_ok);
|
||||||
* Translate the language name, check that the language exists
|
|
||||||
*/
|
|
||||||
languageName = case_translate_language_name(stmt->plname);
|
|
||||||
|
|
||||||
oid = get_language_oid(languageName, stmt->missing_ok);
|
|
||||||
if (!OidIsValid(oid))
|
if (!OidIsValid(oid))
|
||||||
{
|
{
|
||||||
ereport(NOTICE,
|
ereport(NOTICE,
|
||||||
(errmsg("language \"%s\" does not exist, skipping",
|
(errmsg("language \"%s\" does not exist, skipping",
|
||||||
languageName)));
|
stmt->plname)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,7 +532,7 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
|||||||
*/
|
*/
|
||||||
if (!pg_language_ownercheck(oid, GetUserId()))
|
if (!pg_language_ownercheck(oid, GetUserId()))
|
||||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
|
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
|
||||||
languageName);
|
stmt->plname);
|
||||||
|
|
||||||
object.classId = LanguageRelationId;
|
object.classId = LanguageRelationId;
|
||||||
object.objectId = oid;
|
object.objectId = oid;
|
||||||
@ -587,10 +575,6 @@ RenameLanguage(const char *oldname, const char *newname)
|
|||||||
HeapTuple tup;
|
HeapTuple tup;
|
||||||
Relation rel;
|
Relation rel;
|
||||||
|
|
||||||
/* Translate both names for consistency with CREATE */
|
|
||||||
oldname = case_translate_language_name(oldname);
|
|
||||||
newname = case_translate_language_name(newname);
|
|
||||||
|
|
||||||
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
||||||
|
|
||||||
tup = SearchSysCacheCopy1(LANGNAME, CStringGetDatum(oldname));
|
tup = SearchSysCacheCopy1(LANGNAME, CStringGetDatum(oldname));
|
||||||
@ -628,9 +612,6 @@ AlterLanguageOwner(const char *name, Oid newOwnerId)
|
|||||||
HeapTuple tup;
|
HeapTuple tup;
|
||||||
Relation rel;
|
Relation rel;
|
||||||
|
|
||||||
/* Translate name for consistency with CREATE */
|
|
||||||
name = case_translate_language_name(name);
|
|
||||||
|
|
||||||
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
||||||
|
|
||||||
tup = SearchSysCache1(LANGNAME, CStringGetDatum(name));
|
tup = SearchSysCache1(LANGNAME, CStringGetDatum(name));
|
||||||
|
@ -174,8 +174,6 @@ extern Datum transformGenericOptions(Oid catalogId,
|
|||||||
|
|
||||||
/* support routines in commands/define.c */
|
/* support routines in commands/define.c */
|
||||||
|
|
||||||
extern char *case_translate_language_name(const char *input);
|
|
||||||
|
|
||||||
extern char *defGetString(DefElem *def);
|
extern char *defGetString(DefElem *def);
|
||||||
extern double defGetNumeric(DefElem *def);
|
extern double defGetNumeric(DefElem *def);
|
||||||
extern bool defGetBoolean(DefElem *def);
|
extern bool defGetBoolean(DefElem *def);
|
||||||
|
Loading…
Reference in New Issue
Block a user