mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Add location field to DefElem
Add a location field to the DefElem struct, used to parse many utility commands. Update various error messages to supply error position information. To propogate the error position information in a more systematic way, create a ParseState in standard_ProcessUtility() and pass that to interested functions implementing the utility commands. This seems better than passing the query string and then reassembling a parse state ad hoc, which violates the encapsulation of the ParseState type. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
This commit is contained in:
@ -96,7 +96,7 @@ static int errdetail_busy_db(int notherbackends, int npreparedxacts);
|
||||
* CREATE DATABASE
|
||||
*/
|
||||
Oid
|
||||
createdb(const CreatedbStmt *stmt)
|
||||
createdb(ParseState *pstate, const CreatedbStmt *stmt)
|
||||
{
|
||||
HeapScanDesc scan;
|
||||
Relation rel;
|
||||
@ -152,7 +152,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dtablespacename)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dtablespacename = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "owner") == 0)
|
||||
@ -160,7 +161,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (downer)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
downer = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "template") == 0)
|
||||
@ -168,7 +170,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dtemplate)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dtemplate = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "encoding") == 0)
|
||||
@ -176,7 +179,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dencoding)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dencoding = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "lc_collate") == 0)
|
||||
@ -184,7 +188,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dcollate)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dcollate = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "lc_ctype") == 0)
|
||||
@ -192,7 +197,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dctype)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dctype = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "is_template") == 0)
|
||||
@ -200,7 +206,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (distemplate)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
distemplate = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "allow_connections") == 0)
|
||||
@ -208,7 +215,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dallowconnections)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dallowconnections = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "connection_limit") == 0)
|
||||
@ -216,7 +224,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
if (dconnlimit)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dconnlimit = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "location") == 0)
|
||||
@ -224,12 +233,14 @@ createdb(const CreatedbStmt *stmt)
|
||||
ereport(WARNING,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("LOCATION is not supported anymore"),
|
||||
errhint("Consider using tablespaces instead.")));
|
||||
errhint("Consider using tablespaces instead."),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
}
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("option \"%s\" not recognized", defel->defname)));
|
||||
errmsg("option \"%s\" not recognized", defel->defname),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
}
|
||||
|
||||
if (downer && downer->arg)
|
||||
@ -249,7 +260,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("%d is not a valid encoding code",
|
||||
encoding)));
|
||||
encoding),
|
||||
parser_errposition(pstate, dencoding->location)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -259,7 +271,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("%s is not a valid encoding name",
|
||||
encoding_name)));
|
||||
encoding_name),
|
||||
parser_errposition(pstate, dencoding->location)));
|
||||
}
|
||||
}
|
||||
if (dcollate && dcollate->arg)
|
||||
@ -1364,7 +1377,7 @@ movedb_failure_callback(int code, Datum arg)
|
||||
* ALTER DATABASE name ...
|
||||
*/
|
||||
Oid
|
||||
AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
{
|
||||
Relation rel;
|
||||
Oid dboid;
|
||||
@ -1394,7 +1407,8 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
if (distemplate)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
distemplate = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "allow_connections") == 0)
|
||||
@ -1402,7 +1416,8 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
if (dallowconnections)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dallowconnections = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "connection_limit") == 0)
|
||||
@ -1410,7 +1425,8 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
if (dconnlimit)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dconnlimit = defel;
|
||||
}
|
||||
else if (strcmp(defel->defname, "tablespace") == 0)
|
||||
@ -1418,13 +1434,15 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
if (dtablespace)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
errmsg("conflicting or redundant options"),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
dtablespace = defel;
|
||||
}
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("option \"%s\" not recognized", defel->defname)));
|
||||
errmsg("option \"%s\" not recognized", defel->defname),
|
||||
parser_errposition(pstate, defel->location)));
|
||||
}
|
||||
|
||||
if (dtablespace)
|
||||
@ -1438,7 +1456,8 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("option \"%s\" cannot be specified with other options",
|
||||
dtablespace->defname)));
|
||||
dtablespace->defname),
|
||||
parser_errposition(pstate, dtablespace->location)));
|
||||
/* this case isn't allowed within a transaction block */
|
||||
PreventTransactionChain(isTopLevel, "ALTER DATABASE SET TABLESPACE");
|
||||
movedb(stmt->dbname, defGetString(dtablespace));
|
||||
|
Reference in New Issue
Block a user