提交 08edcaa4 编写于 作者: H Heikki Linnakangas

Fix quoting issues in dispatching ALTER and DROP DATABASE, and gpcheckcat.

Unfortunately, pg_upgrade still barfs on this. That was fixed in the
upstream in commit a2385cac13, in PostgreSQL 9.1, so we'll revisit this
once we merge up to that.
上级 5222828b
......@@ -3415,12 +3415,12 @@ def duplicatePersistentEntryQuery(catname, pkey, excol, state):
where {excol} != {state}
) all_segments
LEFT OUTER JOIN pg_database d ON (all_segments.database_oid = d.oid)
WHERE d.datname = '{dbname}'
WHERE d.datname = {dbname}
GROUP BY segid, {pkey}
HAVING count(*) > 1
) rowresult
GROUP BY {pkey}, total
""".format(catalog=catname, pkey=','.join(pkey), excol=excol, state=state, dbname=GV.dbname)
""".format(catalog=catname, pkey=','.join(pkey), excol=excol, state=state, dbname=quote_value(GV.dbname))
return qry
# -------------------------------------------------------------------------------
......
......@@ -1452,8 +1452,7 @@ dropdb(const char *dbname, bool missing_ok)
initStringInfo(&buffer);
appendStringInfo(&buffer, "DROP DATABASE IF EXISTS \"%s\"", dbname);
appendStringInfo(&buffer, "DROP DATABASE IF EXISTS %s", quote_identifier(dbname));
/*
* Do the DROP DATABASE as part of a distributed transaction.
......@@ -2008,41 +2007,40 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
MetaTrackUpdObject(DatabaseRelationId,
dboid,
GetUserId(),
"ALTER", alter_subtype
);
"ALTER", alter_subtype);
/* Close pg_database, but keep lock till commit */
heap_close(rel, NoLock);
if (Gp_role == GP_ROLE_DISPATCH)
{
StringInfoData buffer;
initStringInfo(&buffer);
appendStringInfo(&buffer, "ALTER DATABASE \"%s\" ", stmt->dbname);
appendStringInfo(&buffer, "ALTER DATABASE %s ", quote_identifier(stmt->dbname));
if (stmt->setstmt->kind == VAR_RESET_ALL)
{
appendStringInfo(&buffer, "RESET ALL");
}
else if (valuestr == NULL)
{
appendStringInfo(&buffer, "RESET \"%s\"", stmt->setstmt->name);
appendStringInfo(&buffer, "RESET %s", quote_identifier(stmt->setstmt->name));
}
else
{
ListCell *l;
bool first;
appendStringInfo(&buffer, "SET \"%s\" TO ",stmt->setstmt->name);
appendStringInfo(&buffer, "SET %s TO ", quote_identifier(stmt->setstmt->name));
/* Parse string into list of identifiers */
first = true;
foreach(l, stmt->setstmt->args)
{
A_Const *arg = (A_Const *) lfirst(l);
if (!first)
appendStringInfo(&buffer, ",");
first = false;
......@@ -2057,13 +2055,12 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
appendStringInfoString(&buffer, strVal(&arg->val));
break;
case T_String:
appendStringInfo(&buffer,"'%s'", strVal(&arg->val));
appendStringInfoString(&buffer, quote_literal_internal(strVal(&arg->val)));
break;
default:
appendStringInfo(&buffer, "%s", quote_identifier(strVal(&arg->val)));
elog(ERROR, "unexpected constant type: %d", nodeTag(&arg->val));
}
}
}
CdbDispatchCommand(buffer.data,
......
......@@ -11,6 +11,19 @@ CREATE EXTENSION IF NOT EXISTS gp_inject_fault;
-- end_matchsubs
-- Test quoting of GUC values and database names when they're sent to segments
set client_min_messages='warning';
DROP DATABASE IF EXISTS "funny""db'with\\quotes";
reset client_min_messages;
CREATE DATABASE "funny""db'with\\quotes";
ALTER DATABASE "funny""db'with\\quotes" SET search_path="funny""schema'with\\quotes";
-- GPDB_91_MERGE_FIXME: It would be good to leave the database in place, to
-- also test gpcheckcat and pg_upgrade after all the regression tests have
-- completed. As of this writing pg_upgrade does not in fact handle that well.
-- Remove this DROP DATABASE once it's fixed. That should happen when we
-- reach commit a2385cac13, which was backported to PostgreSQL 9.1.
DROP DATABASE "funny""db'with\\quotes";
-- There used to be a bug in the quoting when the search_path setting was sent
-- to the segment. It was not easily visible when search_path was set with a
......
......@@ -8,6 +8,18 @@ CREATE EXTENSION IF NOT EXISTS gp_inject_fault;
-- s/^DETAIL: Internal error: No motion listener port \(seg\d.*:.*\)/DETAIL: Internal error: No motion listener port/
-- end_matchsubs
-- Test quoting of GUC values and database names when they're sent to segments
set client_min_messages='warning';
DROP DATABASE IF EXISTS "funny""db'with\\quotes";
reset client_min_messages;
CREATE DATABASE "funny""db'with\\quotes";
ALTER DATABASE "funny""db'with\\quotes" SET search_path="funny""schema'with\\quotes";
NOTICE: schema "funny"schema'with\\quotes" does not exist
-- GPDB_91_MERGE_FIXME: It would be good to leave the database in place, to
-- also test gpcheckcat and pg_upgrade after all the regression tests have
-- completed. As of this writing pg_upgrade does not in fact handle that well.
-- Remove this DROP DATABASE once it's fixed. That should happen when we
-- reach commit a2385cac13, which was backported to PostgreSQL 9.1.
DROP DATABASE "funny""db'with\\quotes";
-- There used to be a bug in the quoting when the search_path setting was sent
-- to the segment. It was not easily visible when search_path was set with a
-- SET command, only when the setting was sent as part of the startup packet.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册