mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Variable renaming in dbcommands.c
There were several sets of very similar local variable names, such as "downer" and "dbowner", which was very confusing and error-prone. Rename the former to "ownerEl" and so on, similar to collationcmds.c and typecmds.c. Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://www.postgresql.org/message-id/flat/e5bce225-ee04-40c7-a280-ea7214318048%40eisentraut.org
This commit is contained in:
parent
a3c6aa42ee
commit
fce7cb6da0
@ -704,22 +704,22 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
Oid dboid = InvalidOid;
|
Oid dboid = InvalidOid;
|
||||||
Oid datdba;
|
Oid datdba;
|
||||||
ListCell *option;
|
ListCell *option;
|
||||||
DefElem *dtablespacename = NULL;
|
DefElem *tablespacenameEl = NULL;
|
||||||
DefElem *downer = NULL;
|
DefElem *ownerEl = NULL;
|
||||||
DefElem *dtemplate = NULL;
|
DefElem *templateEl = NULL;
|
||||||
DefElem *dencoding = NULL;
|
DefElem *encodingEl = NULL;
|
||||||
DefElem *dlocale = NULL;
|
DefElem *localeEl = NULL;
|
||||||
DefElem *dbuiltinlocale = NULL;
|
DefElem *builtinlocaleEl = NULL;
|
||||||
DefElem *dcollate = NULL;
|
DefElem *collateEl = NULL;
|
||||||
DefElem *dctype = NULL;
|
DefElem *ctypeEl = NULL;
|
||||||
DefElem *diculocale = NULL;
|
DefElem *iculocaleEl = NULL;
|
||||||
DefElem *dicurules = NULL;
|
DefElem *icurulesEl = NULL;
|
||||||
DefElem *dlocprovider = NULL;
|
DefElem *locproviderEl = NULL;
|
||||||
DefElem *distemplate = NULL;
|
DefElem *istemplateEl = NULL;
|
||||||
DefElem *dallowconnections = NULL;
|
DefElem *allowconnectionsEl = NULL;
|
||||||
DefElem *dconnlimit = NULL;
|
DefElem *connlimitEl = NULL;
|
||||||
DefElem *dcollversion = NULL;
|
DefElem *collversionEl = NULL;
|
||||||
DefElem *dstrategy = NULL;
|
DefElem *strategyEl = NULL;
|
||||||
char *dbname = stmt->dbname;
|
char *dbname = stmt->dbname;
|
||||||
char *dbowner = NULL;
|
char *dbowner = NULL;
|
||||||
const char *dbtemplate = NULL;
|
const char *dbtemplate = NULL;
|
||||||
@ -746,93 +746,93 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
|
|
||||||
if (strcmp(defel->defname, "tablespace") == 0)
|
if (strcmp(defel->defname, "tablespace") == 0)
|
||||||
{
|
{
|
||||||
if (dtablespacename)
|
if (tablespacenameEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dtablespacename = defel;
|
tablespacenameEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "owner") == 0)
|
else if (strcmp(defel->defname, "owner") == 0)
|
||||||
{
|
{
|
||||||
if (downer)
|
if (ownerEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
downer = defel;
|
ownerEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "template") == 0)
|
else if (strcmp(defel->defname, "template") == 0)
|
||||||
{
|
{
|
||||||
if (dtemplate)
|
if (templateEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dtemplate = defel;
|
templateEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "encoding") == 0)
|
else if (strcmp(defel->defname, "encoding") == 0)
|
||||||
{
|
{
|
||||||
if (dencoding)
|
if (encodingEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dencoding = defel;
|
encodingEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "locale") == 0)
|
else if (strcmp(defel->defname, "locale") == 0)
|
||||||
{
|
{
|
||||||
if (dlocale)
|
if (localeEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dlocale = defel;
|
localeEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "builtin_locale") == 0)
|
else if (strcmp(defel->defname, "builtin_locale") == 0)
|
||||||
{
|
{
|
||||||
if (dbuiltinlocale)
|
if (builtinlocaleEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dbuiltinlocale = defel;
|
builtinlocaleEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "lc_collate") == 0)
|
else if (strcmp(defel->defname, "lc_collate") == 0)
|
||||||
{
|
{
|
||||||
if (dcollate)
|
if (collateEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dcollate = defel;
|
collateEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "lc_ctype") == 0)
|
else if (strcmp(defel->defname, "lc_ctype") == 0)
|
||||||
{
|
{
|
||||||
if (dctype)
|
if (ctypeEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dctype = defel;
|
ctypeEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "icu_locale") == 0)
|
else if (strcmp(defel->defname, "icu_locale") == 0)
|
||||||
{
|
{
|
||||||
if (diculocale)
|
if (iculocaleEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
diculocale = defel;
|
iculocaleEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "icu_rules") == 0)
|
else if (strcmp(defel->defname, "icu_rules") == 0)
|
||||||
{
|
{
|
||||||
if (dicurules)
|
if (icurulesEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dicurules = defel;
|
icurulesEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "locale_provider") == 0)
|
else if (strcmp(defel->defname, "locale_provider") == 0)
|
||||||
{
|
{
|
||||||
if (dlocprovider)
|
if (locproviderEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dlocprovider = defel;
|
locproviderEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "is_template") == 0)
|
else if (strcmp(defel->defname, "is_template") == 0)
|
||||||
{
|
{
|
||||||
if (distemplate)
|
if (istemplateEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
distemplate = defel;
|
istemplateEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "allow_connections") == 0)
|
else if (strcmp(defel->defname, "allow_connections") == 0)
|
||||||
{
|
{
|
||||||
if (dallowconnections)
|
if (allowconnectionsEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dallowconnections = defel;
|
allowconnectionsEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "connection_limit") == 0)
|
else if (strcmp(defel->defname, "connection_limit") == 0)
|
||||||
{
|
{
|
||||||
if (dconnlimit)
|
if (connlimitEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dconnlimit = defel;
|
connlimitEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "collation_version") == 0)
|
else if (strcmp(defel->defname, "collation_version") == 0)
|
||||||
{
|
{
|
||||||
if (dcollversion)
|
if (collversionEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dcollversion = defel;
|
collversionEl = defel;
|
||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "location") == 0)
|
else if (strcmp(defel->defname, "location") == 0)
|
||||||
{
|
{
|
||||||
@ -868,9 +868,9 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
}
|
}
|
||||||
else if (strcmp(defel->defname, "strategy") == 0)
|
else if (strcmp(defel->defname, "strategy") == 0)
|
||||||
{
|
{
|
||||||
if (dstrategy)
|
if (strategyEl)
|
||||||
errorConflictingDefElem(defel, pstate);
|
errorConflictingDefElem(defel, pstate);
|
||||||
dstrategy = defel;
|
strategyEl = defel;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -879,17 +879,17 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
parser_errposition(pstate, defel->location)));
|
parser_errposition(pstate, defel->location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downer && downer->arg)
|
if (ownerEl && ownerEl->arg)
|
||||||
dbowner = defGetString(downer);
|
dbowner = defGetString(ownerEl);
|
||||||
if (dtemplate && dtemplate->arg)
|
if (templateEl && templateEl->arg)
|
||||||
dbtemplate = defGetString(dtemplate);
|
dbtemplate = defGetString(templateEl);
|
||||||
if (dencoding && dencoding->arg)
|
if (encodingEl && encodingEl->arg)
|
||||||
{
|
{
|
||||||
const char *encoding_name;
|
const char *encoding_name;
|
||||||
|
|
||||||
if (IsA(dencoding->arg, Integer))
|
if (IsA(encodingEl->arg, Integer))
|
||||||
{
|
{
|
||||||
encoding = defGetInt32(dencoding);
|
encoding = defGetInt32(encodingEl);
|
||||||
encoding_name = pg_encoding_to_char(encoding);
|
encoding_name = pg_encoding_to_char(encoding);
|
||||||
if (strcmp(encoding_name, "") == 0 ||
|
if (strcmp(encoding_name, "") == 0 ||
|
||||||
pg_valid_server_encoding(encoding_name) < 0)
|
pg_valid_server_encoding(encoding_name) < 0)
|
||||||
@ -897,39 +897,39 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("%d is not a valid encoding code",
|
errmsg("%d is not a valid encoding code",
|
||||||
encoding),
|
encoding),
|
||||||
parser_errposition(pstate, dencoding->location)));
|
parser_errposition(pstate, encodingEl->location)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
encoding_name = defGetString(dencoding);
|
encoding_name = defGetString(encodingEl);
|
||||||
encoding = pg_valid_server_encoding(encoding_name);
|
encoding = pg_valid_server_encoding(encoding_name);
|
||||||
if (encoding < 0)
|
if (encoding < 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("%s is not a valid encoding name",
|
errmsg("%s is not a valid encoding name",
|
||||||
encoding_name),
|
encoding_name),
|
||||||
parser_errposition(pstate, dencoding->location)));
|
parser_errposition(pstate, encodingEl->location)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dlocale && dlocale->arg)
|
if (localeEl && localeEl->arg)
|
||||||
{
|
{
|
||||||
dbcollate = defGetString(dlocale);
|
dbcollate = defGetString(localeEl);
|
||||||
dbctype = defGetString(dlocale);
|
dbctype = defGetString(localeEl);
|
||||||
dblocale = defGetString(dlocale);
|
dblocale = defGetString(localeEl);
|
||||||
}
|
}
|
||||||
if (dbuiltinlocale && dbuiltinlocale->arg)
|
if (builtinlocaleEl && builtinlocaleEl->arg)
|
||||||
dblocale = defGetString(dbuiltinlocale);
|
dblocale = defGetString(builtinlocaleEl);
|
||||||
if (dcollate && dcollate->arg)
|
if (collateEl && collateEl->arg)
|
||||||
dbcollate = defGetString(dcollate);
|
dbcollate = defGetString(collateEl);
|
||||||
if (dctype && dctype->arg)
|
if (ctypeEl && ctypeEl->arg)
|
||||||
dbctype = defGetString(dctype);
|
dbctype = defGetString(ctypeEl);
|
||||||
if (diculocale && diculocale->arg)
|
if (iculocaleEl && iculocaleEl->arg)
|
||||||
dblocale = defGetString(diculocale);
|
dblocale = defGetString(iculocaleEl);
|
||||||
if (dicurules && dicurules->arg)
|
if (icurulesEl && icurulesEl->arg)
|
||||||
dbicurules = defGetString(dicurules);
|
dbicurules = defGetString(icurulesEl);
|
||||||
if (dlocprovider && dlocprovider->arg)
|
if (locproviderEl && locproviderEl->arg)
|
||||||
{
|
{
|
||||||
char *locproviderstr = defGetString(dlocprovider);
|
char *locproviderstr = defGetString(locproviderEl);
|
||||||
|
|
||||||
if (pg_strcasecmp(locproviderstr, "builtin") == 0)
|
if (pg_strcasecmp(locproviderstr, "builtin") == 0)
|
||||||
dblocprovider = COLLPROVIDER_BUILTIN;
|
dblocprovider = COLLPROVIDER_BUILTIN;
|
||||||
@ -943,20 +943,20 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
errmsg("unrecognized locale provider: %s",
|
errmsg("unrecognized locale provider: %s",
|
||||||
locproviderstr)));
|
locproviderstr)));
|
||||||
}
|
}
|
||||||
if (distemplate && distemplate->arg)
|
if (istemplateEl && istemplateEl->arg)
|
||||||
dbistemplate = defGetBoolean(distemplate);
|
dbistemplate = defGetBoolean(istemplateEl);
|
||||||
if (dallowconnections && dallowconnections->arg)
|
if (allowconnectionsEl && allowconnectionsEl->arg)
|
||||||
dballowconnections = defGetBoolean(dallowconnections);
|
dballowconnections = defGetBoolean(allowconnectionsEl);
|
||||||
if (dconnlimit && dconnlimit->arg)
|
if (connlimitEl && connlimitEl->arg)
|
||||||
{
|
{
|
||||||
dbconnlimit = defGetInt32(dconnlimit);
|
dbconnlimit = defGetInt32(connlimitEl);
|
||||||
if (dbconnlimit < DATCONNLIMIT_UNLIMITED)
|
if (dbconnlimit < DATCONNLIMIT_UNLIMITED)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("invalid connection limit: %d", dbconnlimit)));
|
errmsg("invalid connection limit: %d", dbconnlimit)));
|
||||||
}
|
}
|
||||||
if (dcollversion)
|
if (collversionEl)
|
||||||
dbcollversion = defGetString(dcollversion);
|
dbcollversion = defGetString(collversionEl);
|
||||||
|
|
||||||
/* obtain OID of proposed owner */
|
/* obtain OID of proposed owner */
|
||||||
if (dbowner)
|
if (dbowner)
|
||||||
@ -1025,11 +1025,11 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Validate the database creation strategy. */
|
/* Validate the database creation strategy. */
|
||||||
if (dstrategy && dstrategy->arg)
|
if (strategyEl && strategyEl->arg)
|
||||||
{
|
{
|
||||||
char *strategy;
|
char *strategy;
|
||||||
|
|
||||||
strategy = defGetString(dstrategy);
|
strategy = defGetString(strategyEl);
|
||||||
if (pg_strcasecmp(strategy, "wal_log") == 0)
|
if (pg_strcasecmp(strategy, "wal_log") == 0)
|
||||||
dbstrategy = CREATEDB_WAL_LOG;
|
dbstrategy = CREATEDB_WAL_LOG;
|
||||||
else if (pg_strcasecmp(strategy, "file_copy") == 0)
|
else if (pg_strcasecmp(strategy, "file_copy") == 0)
|
||||||
@ -1080,7 +1080,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
/* validate provider-specific parameters */
|
/* validate provider-specific parameters */
|
||||||
if (dblocprovider != COLLPROVIDER_BUILTIN)
|
if (dblocprovider != COLLPROVIDER_BUILTIN)
|
||||||
{
|
{
|
||||||
if (dbuiltinlocale)
|
if (builtinlocaleEl)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||||
errmsg("BUILTIN_LOCALE cannot be specified unless locale provider is builtin")));
|
errmsg("BUILTIN_LOCALE cannot be specified unless locale provider is builtin")));
|
||||||
@ -1088,7 +1088,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
|
|
||||||
if (dblocprovider != COLLPROVIDER_ICU)
|
if (dblocprovider != COLLPROVIDER_ICU)
|
||||||
{
|
{
|
||||||
if (diculocale)
|
if (iculocaleEl)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||||
errmsg("ICU locale cannot be specified unless locale provider is ICU")));
|
errmsg("ICU locale cannot be specified unless locale provider is ICU")));
|
||||||
@ -1239,7 +1239,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
* template0, for which we stipulate that it does not contain
|
* template0, for which we stipulate that it does not contain
|
||||||
* collation-using objects.)
|
* collation-using objects.)
|
||||||
*/
|
*/
|
||||||
if (src_collversion && !dcollversion)
|
if (src_collversion && !collversionEl)
|
||||||
{
|
{
|
||||||
char *actual_versionstr;
|
char *actual_versionstr;
|
||||||
const char *locale;
|
const char *locale;
|
||||||
@ -1289,12 +1289,12 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Resolve default tablespace for new database */
|
/* Resolve default tablespace for new database */
|
||||||
if (dtablespacename && dtablespacename->arg)
|
if (tablespacenameEl && tablespacenameEl->arg)
|
||||||
{
|
{
|
||||||
char *tablespacename;
|
char *tablespacename;
|
||||||
AclResult aclresult;
|
AclResult aclresult;
|
||||||
|
|
||||||
tablespacename = defGetString(dtablespacename);
|
tablespacename = defGetString(tablespacenameEl);
|
||||||
dst_deftablespace = get_tablespace_oid(tablespacename, false);
|
dst_deftablespace = get_tablespace_oid(tablespacename, false);
|
||||||
/* check permissions */
|
/* check permissions */
|
||||||
aclresult = object_aclcheck(TableSpaceRelationId, dst_deftablespace, GetUserId(),
|
aclresult = object_aclcheck(TableSpaceRelationId, dst_deftablespace, GetUserId(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user