Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements in order of columns in new tables, quotes in privileges,… #62

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ dumpAlterAggregate(FILE *output, PQLAggregate *a, PQLAggregate *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER AGGREGATE %s.%s(%s) OWNER TO %s;",
fprintf(output, "ALTER AGGREGATE %s.%s(%s) OWNER TO \"%s\";",
schema2,
aggname2,
b->arguments,
Expand Down
2 changes: 1 addition & 1 deletion src/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ getAccessMethods(PGconn *c, int *n)
return NULL;
}

res = PQexec(c, "SELECT a.oid, a.amname, a.amtype, a.amhandler AS handleroid, n.nspname AS handlernspname, p.proname AS handlername, obj_description(a.oid, 'pg_am') AS description FROM pg_am a INNER JOIN pg_proc p ON (a.amhandler = p.oid) INNER JON pg_namespace n ON (p.pronamespace = n.oid) ORDER BY a.amname");
res = PQexec(c, "SELECT a.oid, a.amname, a.amtype, a.amhandler AS handleroid, n.nspname AS handlernspname, p.proname AS handlername, obj_description(a.oid, 'pg_am') AS description FROM pg_am a INNER JOIN pg_proc p ON (a.amhandler = p.oid) INNER JOIN pg_namespace n ON (p.pronamespace = n.oid) ORDER BY a.amname");

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
Expand Down
4 changes: 2 additions & 2 deletions src/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ dumpCreateCollation(FILE *output, PQLCollation *c)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER COLLATION %s.%s OWNER TO %s;",
fprintf(output, "ALTER COLLATION %s.%s OWNER TO \"%s\";",
schema,
collname,
c->owner);
Expand Down Expand Up @@ -253,7 +253,7 @@ dumpAlterCollation(FILE *output, PQLCollation *a, PQLCollation *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER COLLATION %s.%s OWNER TO %s;",
fprintf(output, "ALTER COLLATION %s.%s OWNER TO \"%s\";",
schema2,
collname2,
b->owner);
Expand Down
4 changes: 2 additions & 2 deletions src/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ dumpCreateConversion(FILE *output, PQLConversion *c)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER CONVERSION %s.%s OWNER TO %s;",
fprintf(output, "ALTER CONVERSION %s.%s OWNER TO \"%s\";",
schema,
convname,
c->owner);
Expand Down Expand Up @@ -193,7 +193,7 @@ dumpAlterConversion(FILE *output, PQLConversion *a, PQLConversion *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER CONVERSION %s.%s OWNER TO %s;",
fprintf(output, "ALTER CONVERSION %s.%s OWNER TO \"%s\";",
schema2,
convname2,
b->owner);
Expand Down
4 changes: 2 additions & 2 deletions src/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ dumpCreateDomain(FILE *output, PQLDomain *d)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER DOMAIN %s.%s OWNER TO %s;",
fprintf(output, "ALTER DOMAIN %s.%s OWNER TO \"%s\";",
schema,
domname,
d->owner);
Expand Down Expand Up @@ -544,7 +544,7 @@ dumpAlterDomain(FILE *output, PQLDomain *a, PQLDomain *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER DOMAIN %s.%s OWNER TO %s;",
fprintf(output, "ALTER DOMAIN %s.%s OWNER TO \"%s\";",
schema2,
domname2,
b->owner);
Expand Down
4 changes: 2 additions & 2 deletions src/eventtrigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ dumpCreateEventTrigger(FILE *output, PQLEventTrigger *e)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER EVENT TRIGGER %s OWNER TO %s;",
fprintf(output, "ALTER EVENT TRIGGER %s OWNER TO \"%s\";",
evtname,
e->owner);
}
Expand Down Expand Up @@ -398,7 +398,7 @@ dumpAlterEventTrigger(FILE *output, PQLEventTrigger *a, PQLEventTrigger *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER EVENT TRIGGER %s OWNER TO %s;",
fprintf(output, "ALTER EVENT TRIGGER %s OWNER TO \"%s\";",
evtname2,
b->owner);
}
Expand Down
4 changes: 2 additions & 2 deletions src/fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ dumpCreateForeignDataWrapper(FILE *output, PQLForeignDataWrapper *f)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER FOREIGN DATA WRAPPER %s OWNER TO %s;", fdwname,
fprintf(output, "ALTER FOREIGN DATA WRAPPER %s OWNER TO \"%s\";", fdwname,
f->owner);
}

Expand Down Expand Up @@ -452,7 +452,7 @@ dumpAlterForeignDataWrapper(FILE *output, PQLForeignDataWrapper *a,
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER FOREIGN DATA WRAPPER %s OWNER TO %s;", fdwname2,
fprintf(output, "ALTER FOREIGN DATA WRAPPER %s OWNER TO \"%s\";", fdwname2,
b->owner);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ dumpCreateFunction(FILE *output, PQLFunction *f, bool orreplace)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER FUNCTION %s.%s(%s) OWNER TO %s;",
fprintf(output, "ALTER FUNCTION %s.%s(%s) OWNER TO \"%s\";",
schema,
funcname,
f->iarguments,
Expand Down Expand Up @@ -766,7 +766,7 @@ dumpAlterFunction(FILE *output, PQLFunction *a, PQLFunction *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER FUNCTION %s.%s(%s) OWNER TO %s;",
fprintf(output, "ALTER FUNCTION %s.%s(%s) OWNER TO \"%s\";",
schema2, funcname2, b->iarguments, b->owner);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/language.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ dumpCreateLanguage(FILE *output, PQLLanguage *l)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER LANGUAGE %s OWNER TO %s;",
fprintf(output, "ALTER LANGUAGE %s OWNER TO \"%s\";",
langname,
l->owner);
}
Expand Down Expand Up @@ -378,7 +378,7 @@ dumpAlterLanguage(FILE *output, PQLLanguage *a, PQLLanguage *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER LANGUAGE %s OWNER TO %s;",
fprintf(output, "ALTER LANGUAGE %s OWNER TO \"%s\";",
langname2,
b->owner);
}
Expand Down
23 changes: 21 additions & 2 deletions src/matview.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ static void dumpAlterColumnSetStorage(FILE *output, PQLMaterializedView *a,
static void dumpAlterColumnSetOptions(FILE *output, PQLMaterializedView *a,
PQLMaterializedView *b, int i);

int
compareMaterializedViews(PQLMaterializedView *a, PQLMaterializedView *b)
{
int c;

c = strcmp(a->obj.schemaname, b->obj.schemaname);

/* compare relation names iif schema names are equal */
if (c == 0) {
c = strcmp((a->obj.objectname != NULL)?a->obj.objectname:"", (b->obj.objectname != NULL)?b->obj.objectname:"");

if (c == 0) {
c = strcmp((a->viewdef != NULL)?a->viewdef:"", (b->viewdef != NULL)?b->viewdef:"");
}
}

return c;
}

PQLMaterializedView *
getMaterializedViews(PGconn *c, int *n)
{
Expand Down Expand Up @@ -402,7 +421,7 @@ dumpCreateMaterializedView(FILE *output, PQLMaterializedView *v)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER MATERIALIZED VIEW %s.%s OWNER TO %s;", schema, matvname,
fprintf(output, "ALTER MATERIALIZED VIEW %s.%s OWNER TO \"%s\";", schema, matvname,
v->owner);
}

Expand Down Expand Up @@ -809,7 +828,7 @@ dumpAlterMaterializedView(FILE *output, PQLMaterializedView *a,
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER MATERIALIZED VIEW %s.%s OWNER TO %s;",
fprintf(output, "ALTER MATERIALIZED VIEW %s.%s OWNER TO \"%s\";",
schema2,
matvname2,
b->owner);
Expand Down
1 change: 1 addition & 0 deletions src/matview.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct PQLMaterializedView
} PQLMaterializedView;

PQLMaterializedView *getMaterializedViews(PGconn *c, int *n);
int compareMaterializedViews(PQLMaterializedView *a, PQLMaterializedView *b);
void getMaterializedViewAttributes(PGconn *c, PQLMaterializedView *v);
void getMaterializedViewSecurityLabels(PGconn *c, PQLMaterializedView *v);

Expand Down
12 changes: 6 additions & 6 deletions src/operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ dumpCreateOperator(FILE *output, PQLOperator *o)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR %s.%s(%s,%s) OWNER TO %s;",
fprintf(output, "ALTER OPERATOR %s.%s(%s,%s) OWNER TO \"%s\";",
schema, oprname,
(o->lefttype) ? o->lefttype : "NONE",
(o->righttype) ? o->righttype : "NONE",
Expand Down Expand Up @@ -763,7 +763,7 @@ dumpCreateOperatorClass(FILE *output, PQLOperatorClass *c)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO %s;",
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO \"%s\";",
schema, opcname,
c->accessmethod,
c->owner);
Expand Down Expand Up @@ -804,7 +804,7 @@ dumpCreateOperatorFamily(FILE *output, PQLOperatorFamily *f)
if (options.owner)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR FAMILY %s.%s USING %s OWNER TO %s;",
fprintf(output, "ALTER OPERATOR FAMILY %s.%s USING %s OWNER TO \"%s\";",
schema, opfname,
f->accessmethod,
f->owner);
Expand Down Expand Up @@ -892,7 +892,7 @@ dumpAlterOperator(FILE *output, PQLOperator *a, PQLOperator *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR %s.%s(%s,%s) OWNER TO %s;",
fprintf(output, "ALTER OPERATOR %s.%s(%s,%s) OWNER TO \"%s\";",
schema2,
oprname2,
(b->lefttype) ? b->lefttype : "NONE",
Expand Down Expand Up @@ -1018,7 +1018,7 @@ dumpAlterOperatorClass(FILE *output, PQLOperatorClass *a, PQLOperatorClass *b)
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO %s;",
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO \"%s\";",
schema2,
opcname2,
b->accessmethod,
Expand Down Expand Up @@ -1172,7 +1172,7 @@ dumpAlterOperatorFamily(FILE *output, PQLOperatorFamily *a,
if (strcmp(a->owner, b->owner) != 0)
{
fprintf(output, "\n\n");
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO %s;",
fprintf(output, "ALTER OPERATOR CLASS %s.%s USING %s OWNER TO \"%s\";",
schema2,
opfname2,
b->accessmethod,
Expand Down
67 changes: 58 additions & 9 deletions src/privileges.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ dumpGrant(FILE *output, int objecttype, PQLObject *a, char *privs,
case PGQ_TYPE:
fprintf(output, "TYPE");
break;
case PGQ_VIEW:
fprintf(output, "TABLE");
break;
}

/* function arguments? */
Expand All @@ -490,29 +493,51 @@ dumpGrant(FILE *output, int objecttype, PQLObject *a, char *privs,
/* there are some objects that are not schema-qualified */
schema = formatObjectIdentifier(a->schemaname);

fprintf(output, " %s.%s(%s) TO %s;",
if (strcmp(grantee, "PUBLIC") == 0 || strcmp(grantee, "public") == 0)
{
fprintf(output, " %s.%s(%s) TO %s;",
schema,
objname,
args,
grantee);
} else {
fprintf(output, " %s.%s(%s) TO \"%s\";",
schema,
objname,
args,
grantee);
}
}
else if (objecttype == PGQ_DATABASE || objecttype == PGQ_FOREIGN_DATA_WRAPPER ||
objecttype == PGQ_FOREIGN_SERVER || objecttype == PGQ_LANGUAGE ||
objecttype == PGQ_SCHEMA || objecttype == PGQ_TABLESPACE)
{
/* there are some objects that are not schema-qualified */
fprintf(output, " %s TO %s;",
/* there are some objects that are not schema-qualified */
if (strcmp(grantee, "PUBLIC") == 0 || strcmp(grantee, "public") == 0) {
fprintf(output, " %s TO %s;",
objname,
grantee);
} else {
fprintf(output, " %s TO \"%s\";",
objname,
grantee);
}
}
else
{
schema = formatObjectIdentifier(a->schemaname);

fprintf(output, " %s.%s TO %s;",
if (strcmp(grantee, "PUBLIC") == 0 || strcmp(grantee, "public") == 0) {
fprintf(output, " %s.%s TO %s;",
schema,
objname,
grantee);
} else {
fprintf(output, " %s.%s TO \"%s\";",
schema,
objname,
grantee);
}
}

free(p);
Expand Down Expand Up @@ -579,6 +604,9 @@ dumpRevoke(FILE *output, int objecttype, PQLObject *a, char *privs,
case PGQ_TYPE:
fprintf(output, "TYPE");
break;
case PGQ_VIEW:
fprintf(output, "TABLE");
break;
}

/* function arguments? */
Expand All @@ -587,29 +615,50 @@ dumpRevoke(FILE *output, int objecttype, PQLObject *a, char *privs,
/* there are some objects that are not schema-qualified */
schema = formatObjectIdentifier(a->schemaname);

fprintf(output, " %s.%s(%s) FROM %s;",
if (strcmp(grantee, "PUBLIC") == 0 || strcmp(grantee, "public") == 0) {
fprintf(output, " %s.%s(%s) FROM %s;",
schema,
objname,
args,
grantee);
} else {
fprintf(output, " %s.%s(%s) FROM \"%s\";",
schema,
objname,
args,
grantee);
}
}
else if (objecttype == PGQ_DATABASE || objecttype == PGQ_FOREIGN_DATA_WRAPPER ||
objecttype == PGQ_FOREIGN_SERVER || objecttype == PGQ_LANGUAGE ||
objecttype == PGQ_SCHEMA || objecttype == PGQ_TABLESPACE)
{
/* there are some objects that are not schema-qualified */
fprintf(output, " %s FROM %s;",
if (strcmp(grantee, "PUBLIC") == 0 || strcmp(grantee, "public") == 0) {
fprintf(output, " %s FROM %s;",
objname,
grantee);
} else {
fprintf(output, " %s FROM \"%s\";",
objname,
grantee);
}
}
else
{
schema = formatObjectIdentifier(a->schemaname);

fprintf(output, " %s.%s FROM %s;",
if (strcmp(grantee, "PUBLIC") == 0 || strcmp(grantee, "public") == 0) {
fprintf(output, " %s.%s FROM %s;",
schema,
objname,
grantee);
} else {
fprintf(output, " %s.%s FROM \"%s\";",
schema,
objname,
grantee);
}
}

free(p);
Expand Down Expand Up @@ -641,7 +690,7 @@ dumpGrantAndRevoke(FILE *output, int objecttype, PQLObject *a, PQLObject *b,
/* End of aclList ala. Print GRANT for aclList alb until its end. */
if (tmpa == NULL)
{
logDebug("grant to %s: server2 (end)", tmpb->grantee);
logDebug("grant to \"%s\": server2 (end)", tmpb->grantee);

dumpGrant(output, objecttype, b, tmpb->privileges, tmpb->grantee,
((objecttype == PGQ_FUNCTION) ? args : NULL), cols);
Expand Down Expand Up @@ -687,7 +736,7 @@ dumpGrantAndRevoke(FILE *output, int objecttype, PQLObject *a, PQLObject *b,
}
else if (strcmp(tmpa->grantee, tmpb->grantee) > 0)
{
logDebug("grant to %s: server2", tmpb->grantee);
logDebug("grant to \"%s\": server2", tmpb->grantee);

dumpGrant(output, objecttype, b, tmpb->privileges, tmpb->grantee,
((objecttype == PGQ_FUNCTION) ? args : NULL), cols);
Expand Down
Loading