Beispiel #1
0
void
dumpCreateSequence(FILE *output, PQLSequence s)
{
	fprintf(output, "\n\n");
	fprintf(output, "CREATE SEQUENCE %s.%s",
			formatObjectIdentifier(s.obj.schemaname),
			formatObjectIdentifier(s.obj.objectname));

	/*
	 * dump only if it is not default
	 */
	if (strcmp(s.incvalue, "1") != 0)
		fprintf(output, " INCREMENT BY %s", s.incvalue);

	if ((s.incvalue > 0 && strcmp(s.minvalue, "1") != 0) ||
			(s.incvalue < 0 && strcmp(s.minvalue, MINIMUM_SEQUENCE_VALUE) != 0))
		fprintf(output, " MINVALUE %s", s.minvalue);

	if ((s.incvalue > 0 && strcmp(s.maxvalue, MAXIMUM_SEQUENCE_VALUE) != 0) ||
			(s.incvalue < 0 && strcmp(s.maxvalue, "-1") != 0))
		fprintf(output, " MAXVALUE %s", s.maxvalue);

	if ((s.incvalue > 0 && strcmp(s.startvalue, s.minvalue) != 0) ||
			(s.incvalue < 0 && strcmp(s.startvalue, s.maxvalue) != 0))
		fprintf(output, " START WITH %s", s.startvalue);

	if (strcmp(s.cache, "1") != 0)
		fprintf(output, " CACHE %s", s.cache);

	if (s.cycle)
		fprintf(output, " CYCLE");

	fprintf(output, ";");

	/* comment */
	if (options.comment && s.comment != NULL)
	{
		fprintf(output, "\n\n");
		fprintf(output, "COMMENT ON SEQUENCE %s.%s IS '%s';",
				formatObjectIdentifier(s.obj.schemaname),
				formatObjectIdentifier(s.obj.objectname),
				s.comment);
	}

	/* owner */
	if (options.owner)
	{
		fprintf(output, "\n\n");
		fprintf(output, "ALTER SEQUENCE %s.%s OWNER TO %s;",
				formatObjectIdentifier(s.obj.schemaname),
				formatObjectIdentifier(s.obj.objectname),
				s.owner);
	}

	/* privileges */
	/* XXX second s.obj isn't used. Add an invalid PQLObject? */
	if (options.privileges)
		dumpGrantAndRevoke(output, PGQ_SEQUENCE, s.obj, s.obj, NULL, s.acl, NULL);
}
Beispiel #2
0
void
dumpAlterLanguage(FILE *output, PQLLanguage *a, PQLLanguage *b)
{
	char	*langname1 = formatObjectIdentifier(a->languagename);
	char	*langname2 = formatObjectIdentifier(b->languagename);

	if (strcmp(a->languagename, b->languagename) != 0)
	{
		fprintf(output, "\n\n");
		fprintf(output, "ALTER LANGUAGE %s RENAME TO %s;", langname1, langname2);
	}

	/* comment */
	if (options.comment)
	{
		if ((a->comment == NULL && b->comment != NULL) ||
				(a->comment != NULL && b->comment != NULL &&
				 strcmp(a->comment, b->comment) != 0))
		{
			fprintf(output, "\n\n");
			fprintf(output, "COMMENT ON LANGUAGE %s IS '%s';", langname2, b->comment);
		}
		else if (a->comment != NULL && b->comment == NULL)
		{
			fprintf(output, "\n\n");
			fprintf(output, "COMMENT ON LANGUAGE %s IS NULL;", langname2);
		}
	}

	/* security labels */
	if (options.securitylabels)
	{
		if (a->seclabels == NULL && b->seclabels != NULL)
		{
			int	i;

			for (i = 0; i < b->nseclabels; i++)
			{
				fprintf(output, "\n\n");
				fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS '%s';",
						b->seclabels[i].provider,
						langname2,
						b->seclabels[i].label);
			}
		}
		else if (a->seclabels != NULL && b->seclabels == NULL)
		{
			int	i;

			for (i = 0; i < a->nseclabels; i++)
			{
				fprintf(output, "\n\n");
				fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS NULL;",
						a->seclabels[i].provider,
						langname1);
			}
		}
		else if (a->seclabels != NULL && b->seclabels != NULL)
		{
			int	i, j;

			i = j = 0;
			while (i < a->nseclabels || j < b->nseclabels)
			{
				if (i == a->nseclabels)
				{
					fprintf(output, "\n\n");
					fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS '%s';",
							b->seclabels[j].provider,
							langname2,
							b->seclabels[j].label);
					j++;
				}
				else if (j == b->nseclabels)
				{
					fprintf(output, "\n\n");
					fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS NULL;",
							a->seclabels[i].provider,
							langname1);
					i++;
				}
				else if (strcmp(a->seclabels[i].provider, b->seclabels[j].provider) == 0)
				{
					if (strcmp(a->seclabels[i].label, b->seclabels[j].label) != 0)
					{
						fprintf(output, "\n\n");
						fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS '%s';",
								b->seclabels[j].provider,
								langname2,
								b->seclabels[j].label);
					}
					i++;
					j++;
				}
				else if (strcmp(a->seclabels[i].provider, b->seclabels[j].provider) < 0)
				{
					fprintf(output, "\n\n");
					fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS NULL;",
							a->seclabels[i].provider,
							langname1);
					i++;
				}
				else if (strcmp(a->seclabels[i].provider, b->seclabels[j].provider) > 0)
				{
					fprintf(output, "\n\n");
					fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS '%s';",
							b->seclabels[j].provider,
							langname2,
							b->seclabels[j].label);
					j++;
				}
			}
		}
	}

	/* owner */
	if (options.owner)
	{
		if (strcmp(a->owner, b->owner) != 0)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER LANGUAGE %s OWNER TO %s;",
					langname2,
					b->owner);
		}
	}

	/* privileges */
	if (options.privileges)
	{
		PQLObject tmpa, tmpb;

		tmpa.schemaname = NULL;
		tmpa.objectname = a->languagename;
		tmpb.schemaname = NULL;
		tmpb.objectname = b->languagename;

		if (a->acl != NULL || b->acl != NULL)
			dumpGrantAndRevoke(output, PGQ_LANGUAGE, &tmpa, &tmpb, a->acl, b->acl, NULL, NULL);
	}

	free(langname1);
	free(langname2);
}
Beispiel #3
0
void
dumpCreateLanguage(FILE *output, PQLLanguage *l)
{
	char	*langname = formatObjectIdentifier(l->languagename);

	fprintf(output, "\n\n");
	fprintf(output, "CREATE LANGUAGE %s", langname);

	if (!l->pltemplate)
	{
		if (l->trusted)
			fprintf(output, " TRUSTED");

		fprintf(output, " HANDLER %s", l->callhandler);
		fprintf(output, " INLINE %s", l->inlinehandler);
		fprintf(output, " VALIDATOR %s", l->validator);
	}

	fprintf(output, ";");

	/* comment */
	if (options.comment && l->comment != NULL)
	{
		fprintf(output, "\n\n");
		fprintf(output, "COMMENT ON LANGUAGE %s IS '%s';", langname, l->comment);
	}

	/* security labels */
	if (options.securitylabels && l->nseclabels > 0)
	{
		int	i;

		for (i = 0; i < l->nseclabels; i++)
		{
			fprintf(output, "\n\n");
			fprintf(output, "SECURITY LABEL FOR %s ON LANGUAGE %s IS '%s';",
					l->seclabels[i].provider,
					langname,
					l->seclabels[i].label);
		}
	}

	/* owner */
	if (options.owner)
	{
		fprintf(output, "\n\n");
		fprintf(output, "ALTER LANGUAGE %s OWNER TO %s;",
				langname,
				l->owner);
	}

	/* privileges */
	/* XXX second s.obj isn't used. Add an invalid PQLObject? */
	if (options.privileges)
	{
		PQLObject tmp;

		tmp.schemaname = NULL;
		tmp.objectname = l->languagename;

		dumpGrantAndRevoke(output, PGQ_LANGUAGE, &tmp, &tmp, NULL, l->acl, NULL, NULL);
	}

	free(langname);
}
Beispiel #4
0
void
dumpAlterSequence(FILE *output, PQLSequence a, PQLSequence b)
{
	bool	printalter = true;

	if (strcmp(a.incvalue, b.incvalue) != 0)
	{
		if (printalter)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
		printalter = false;

		fprintf(output, " INCREMENT BY %s", b.incvalue);
	}

	if (strcmp(a.minvalue, b.minvalue) != 0)
	{
		if (printalter)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
		printalter = false;

		fprintf(output, " MINVALUE %s", b.minvalue);
	}

	if (strcmp(a.maxvalue, b.maxvalue) != 0)
	{
		if (printalter)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
		printalter = false;

		fprintf(output, " MAXVALUE %s", b.maxvalue);
	}

	if (strcmp(a.startvalue, b.startvalue) != 0)
	{
		if (printalter)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
		printalter = false;

		fprintf(output, " START WITH %s RESTART WITH %s", b.startvalue, b.startvalue);
	}

	if (strcmp(a.cache, b.cache) != 0)
	{
		if (printalter)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
		printalter = false;

		fprintf(output, " CACHE %s", b.cache);
	}

	if (a.cycle != b.cycle)
	{
		if (printalter)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
		printalter = false;

		if (b.cycle)
			fprintf(output, " CYCLE");
		else
			fprintf(output, " NO CYCLE");
	}

	if (!printalter)
		fprintf(output, ";");

	/* comment */
	if (options.comment)
	{
		if ((a.comment == NULL && b.comment != NULL) ||
				(a.comment != NULL && b.comment != NULL &&
				 strcmp(a.comment, b.comment) != 0))
		{
			fprintf(output, "\n\n");
			fprintf(output, "COMMENT ON SEQUENCE %s.%s IS '%s';",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname),
					b.comment);
		}
		else if (a.comment != NULL && b.comment == NULL)
		{
			fprintf(output, "\n\n");
			fprintf(output, "COMMENT ON SEQUENCE %s.%s IS NULL;",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname));
		}
	}

	/* owner */
	if (options.owner)
	{
		if (strcmp(a.owner, b.owner) != 0)
		{
			fprintf(output, "\n\n");
			fprintf(output, "ALTER SEQUENCE %s.%s OWNER TO %s;",
					formatObjectIdentifier(b.obj.schemaname),
					formatObjectIdentifier(b.obj.objectname),
					b.owner);
		}
	}

	/* privileges */
	if (options.privileges)
	{
		if (a.acl != NULL || b.acl != NULL)
			dumpGrantAndRevoke(output, PGQ_SEQUENCE, a.obj, b.obj, a.acl, b.acl, NULL);
	}
}