Skip to content

Commit

Permalink
Quote role names when needed
Browse files Browse the repository at this point in the history
ALTER commands have to deal with role names that have uppercase letters.
Those identifiers should be quoted if there is a upppercase letter. It
was pointed out by @rafaelsagastume at PR #61 although I don't use his
patch. I add a small test to exercise this code (indeed, I have to
overhaul tests to exercise more cases than it does nowadays; let's say
it is just a reminder to not forgot uppercase identifier case).
  • Loading branch information
Euler Taveira committed Sep 6, 2019
1 parent ad1c3e4 commit cff4f0b
Show file tree
Hide file tree
Showing 23 changed files with 252 additions and 50 deletions.
6 changes: 5 additions & 1 deletion src/aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,16 @@ dumpAlterAggregate(FILE *output, PQLAggregate *a, PQLAggregate *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER AGGREGATE %s.%s(%s) OWNER TO %s;",
schema2,
aggname2,
b->arguments,
b->owner);
owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,15 @@ dumpCreateCollation(FILE *output, PQLCollation *c)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(c->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER COLLATION %s.%s OWNER TO %s;",
schema,
collname,
c->owner);
owner);

free(owner);
}

free(schema);
Expand Down Expand Up @@ -265,11 +269,15 @@ dumpAlterCollation(FILE *output, PQLCollation *a, PQLCollation *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER COLLATION %s.%s OWNER TO %s;",
schema2,
collname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ dumpCreateConversion(FILE *output, PQLConversion *c)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(c->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER CONVERSION %s.%s OWNER TO %s;",
schema,
convname,
c->owner);
owner);

free(owner);
}

free(schema);
Expand Down Expand Up @@ -205,11 +209,15 @@ dumpAlterConversion(FILE *output, PQLConversion *a, PQLConversion *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER CONVERSION %s.%s OWNER TO %s;",
schema2,
convname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,15 @@ dumpCreateDomain(FILE *output, PQLDomain *d)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(d->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER DOMAIN %s.%s OWNER TO %s;",
schema,
domname,
d->owner);
owner);

free(owner);
}

/* privileges */
Expand Down Expand Up @@ -567,11 +571,15 @@ dumpAlterDomain(FILE *output, PQLDomain *a, PQLDomain *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER DOMAIN %s.%s OWNER TO %s;",
schema2,
domname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/eventtrigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ dumpCreateEventTrigger(FILE *output, PQLEventTrigger *e)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(e->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER EVENT TRIGGER %s OWNER TO %s;",
evtname,
e->owner);

free(owner);
}

free(evtname);
Expand Down Expand Up @@ -421,10 +425,14 @@ dumpAlterEventTrigger(FILE *output, PQLEventTrigger *a, PQLEventTrigger *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER EVENT TRIGGER %s OWNER TO %s;",
evtname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,13 @@ dumpCreateForeignDataWrapper(FILE *output, PQLForeignDataWrapper *f)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(f->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER FOREIGN DATA WRAPPER %s OWNER TO %s;", fdwname,
f->owner);
owner);

free(owner);
}

/* privileges */
Expand Down Expand Up @@ -464,9 +468,13 @@ dumpAlterForeignDataWrapper(FILE *output, PQLForeignDataWrapper *a,
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER FOREIGN DATA WRAPPER %s OWNER TO %s;", fdwname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,16 @@ dumpCreateFunction(FILE *output, PQLFunction *f, bool orreplace)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(f->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER FUNCTION %s.%s(%s) OWNER TO %s;",
schema,
funcname,
f->iarguments,
f->owner);
owner);

free(owner);
}

/* privileges */
Expand Down Expand Up @@ -789,9 +793,13 @@ dumpAlterFunction(FILE *output, PQLFunction *a, PQLFunction *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER FUNCTION %s.%s(%s) OWNER TO %s;",
schema2, funcname2, b->iarguments, b->owner);
schema2, funcname2, b->iarguments, owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/language.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,14 @@ dumpCreateLanguage(FILE *output, PQLLanguage *l)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(l->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER LANGUAGE %s OWNER TO %s;",
langname,
l->owner);
owner);

free(owner);
}

/* privileges */
Expand Down Expand Up @@ -401,10 +405,14 @@ dumpAlterLanguage(FILE *output, PQLLanguage *a, PQLLanguage *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER LANGUAGE %s OWNER TO %s;",
langname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/matview.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,13 @@ dumpCreateMaterializedView(FILE *output, PQLMaterializedView *v)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(v->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER MATERIALIZED VIEW %s.%s OWNER TO %s;", schema, matvname,
v->owner);
owner);

free(owner);
}

free(schema);
Expand Down Expand Up @@ -831,11 +835,15 @@ dumpAlterMaterializedView(FILE *output, PQLMaterializedView *a,
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER MATERIALIZED VIEW %s.%s OWNER TO %s;",
schema2,
matvname2,
b->owner);
owner);

free(owner);
}
}

Expand Down
36 changes: 30 additions & 6 deletions src/operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,16 @@ dumpCreateOperator(FILE *output, PQLOperator *o)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(o->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR %s.%s(%s,%s) OWNER TO %s;",
schema, oprname,
(o->lefttype) ? o->lefttype : "NONE",
(o->righttype) ? o->righttype : "NONE",
o->owner);
owner);

free(owner);
}

free(schema);
Expand Down Expand Up @@ -801,11 +805,15 @@ dumpCreateOperatorClass(FILE *output, PQLOperatorClass *c)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(c->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO %s;",
schema, opcname,
c->accessmethod,
c->owner);
owner);

free(owner);
}

free(schema);
Expand Down Expand Up @@ -842,11 +850,15 @@ dumpCreateOperatorFamily(FILE *output, PQLOperatorFamily *f)
/* owner */
if (options.owner)
{
char *owner = formatObjectIdentifier(f->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR FAMILY %s.%s USING %s OWNER TO %s;",
schema, opfname,
f->accessmethod,
f->owner);
owner);

free(owner);
}

free(schema);
Expand Down Expand Up @@ -930,13 +942,17 @@ dumpAlterOperator(FILE *output, PQLOperator *a, PQLOperator *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR %s.%s(%s,%s) OWNER TO %s;",
schema2,
oprname2,
(b->lefttype) ? b->lefttype : "NONE",
(b->righttype) ? b->righttype : "NONE",
b->owner);
owner);

free(owner);
}
}

Expand Down Expand Up @@ -1056,12 +1072,16 @@ dumpAlterOperatorClass(FILE *output, PQLOperatorClass *a, PQLOperatorClass *b)
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO %s;",
schema2,
opcname2,
b->accessmethod,
b->owner);
owner);

free(owner);
}
}

Expand Down Expand Up @@ -1210,12 +1230,16 @@ dumpAlterOperatorFamily(FILE *output, PQLOperatorFamily *a,
{
if (strcmp(a->owner, b->owner) != 0)
{
char *owner = formatObjectIdentifier(b->owner);

fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO %s;",
schema2,
opfname2,
b->accessmethod,
b->owner);
owner);

free(owner);
}
}

Expand Down
Loading

0 comments on commit cff4f0b

Please sign in to comment.