mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Disable use of -o and -d pg_dump options together. Can't set oids in
inserts. Change some variables to bool to be clearer.
This commit is contained in:
		@@ -21,7 +21,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.109 1999/05/26 14:50:38 momjian Exp $
 | 
					 *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.110 1999/05/26 16:06:45 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
 | 
					 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -112,12 +112,12 @@ FILE	   *g_fout;				/* the script file */
 | 
				
			|||||||
PGconn	   *g_conn;				/* the database connection */
 | 
					PGconn	   *g_conn;				/* the database connection */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool		force_quotes;		/* User wants to suppress double-quotes */
 | 
					bool		force_quotes;		/* User wants to suppress double-quotes */
 | 
				
			||||||
int			dumpData;			/* dump data using proper insert strings */
 | 
					bool		dumpData;			/* dump data using proper insert strings */
 | 
				
			||||||
int			attrNames;			/* put attr names into insert strings */
 | 
					bool		attrNames;			/* put attr names into insert strings */
 | 
				
			||||||
int			schemaOnly;
 | 
					bool		schemaOnly;
 | 
				
			||||||
int			dataOnly;
 | 
					bool		dataOnly;
 | 
				
			||||||
int			aclsOption;
 | 
					bool		aclsOption;
 | 
				
			||||||
bool		drop_schema;
 | 
					bool		dropSchema;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char		g_opaque_type[10];	/* name for the opaque type */
 | 
					char		g_opaque_type[10];	/* name for the opaque type */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -233,7 +233,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
 | 
				
			|||||||
	bool		copydone;
 | 
						bool		copydone;
 | 
				
			||||||
	char		copybuf[COPYBUFSIZ];
 | 
						char		copybuf[COPYBUFSIZ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (oids)
 | 
						if (oids == true)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		fprintf(fout, "COPY %s WITH OIDS FROM stdin;\n",
 | 
							fprintf(fout, "COPY %s WITH OIDS FROM stdin;\n",
 | 
				
			||||||
				fmtId(classname, force_quotes));
 | 
									fmtId(classname, force_quotes));
 | 
				
			||||||
@@ -336,7 +336,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
 | 
				
			|||||||
	for (tuple = 0; tuple < PQntuples(res); tuple++)
 | 
						for (tuple = 0; tuple < PQntuples(res); tuple++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		fprintf(fout, "INSERT INTO %s ", fmtId(classname, force_quotes));
 | 
							fprintf(fout, "INSERT INTO %s ", fmtId(classname, force_quotes));
 | 
				
			||||||
		if (attrNames)
 | 
							if (attrNames == true)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			sprintf(q, "(");
 | 
								sprintf(q, "(");
 | 
				
			||||||
			for (field = 0; field < PQnfields(res); field++)
 | 
								for (field = 0; field < PQnfields(res); field++)
 | 
				
			||||||
@@ -545,7 +545,7 @@ main(int argc, char **argv)
 | 
				
			|||||||
	const char *pghost = NULL;
 | 
						const char *pghost = NULL;
 | 
				
			||||||
	const char *pgport = NULL;
 | 
						const char *pgport = NULL;
 | 
				
			||||||
	char	   *tablename = NULL;
 | 
						char	   *tablename = NULL;
 | 
				
			||||||
	int			oids = 0;
 | 
						bool		oids = false;
 | 
				
			||||||
	TableInfo  *tblinfo;
 | 
						TableInfo  *tblinfo;
 | 
				
			||||||
	int			numTables;
 | 
						int			numTables;
 | 
				
			||||||
	char		connect_string[512] = "";
 | 
						char		connect_string[512] = "";
 | 
				
			||||||
@@ -556,13 +556,13 @@ main(int argc, char **argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	g_verbose = false;
 | 
						g_verbose = false;
 | 
				
			||||||
	force_quotes = true;
 | 
						force_quotes = true;
 | 
				
			||||||
	drop_schema = false;
 | 
						dropSchema = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	strcpy(g_comment_start, "-- ");
 | 
						strcpy(g_comment_start, "-- ");
 | 
				
			||||||
	g_comment_end[0] = '\0';
 | 
						g_comment_end[0] = '\0';
 | 
				
			||||||
	strcpy(g_opaque_type, "opaque");
 | 
						strcpy(g_opaque_type, "opaque");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dataOnly = schemaOnly = dumpData = attrNames = 0;
 | 
						dataOnly = schemaOnly = dumpData = attrNames = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	progname = *argv;
 | 
						progname = *argv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -571,19 +571,19 @@ main(int argc, char **argv)
 | 
				
			|||||||
		switch (c)
 | 
							switch (c)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			case 'a':			/* Dump data only */
 | 
								case 'a':			/* Dump data only */
 | 
				
			||||||
				dataOnly = 1;
 | 
									dataOnly = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'c':			/* clean (i.e., drop) schema prior to
 | 
								case 'c':			/* clean (i.e., drop) schema prior to
 | 
				
			||||||
								 * create */
 | 
													 * create */
 | 
				
			||||||
				drop_schema = true;
 | 
									dropSchema = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'd':			/* dump data as proper insert strings */
 | 
								case 'd':			/* dump data as proper insert strings */
 | 
				
			||||||
				dumpData = 1;
 | 
									dumpData = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'D':			/* dump data as proper insert strings with
 | 
								case 'D':			/* dump data as proper insert strings with
 | 
				
			||||||
								 * attr names */
 | 
													 * attr names */
 | 
				
			||||||
				dumpData = 1;
 | 
									dumpData = true;
 | 
				
			||||||
				attrNames = 1;
 | 
									attrNames = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'f':			/* output file name */
 | 
								case 'f':			/* output file name */
 | 
				
			||||||
				filename = optarg;
 | 
									filename = optarg;
 | 
				
			||||||
@@ -599,13 +599,13 @@ main(int argc, char **argv)
 | 
				
			|||||||
				force_quotes = true;
 | 
									force_quotes = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'o':			/* Dump oids */
 | 
								case 'o':			/* Dump oids */
 | 
				
			||||||
				oids = 1;
 | 
									oids = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'p':			/* server port */
 | 
								case 'p':			/* server port */
 | 
				
			||||||
				pgport = optarg;
 | 
									pgport = optarg;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 's':			/* dump schema only */
 | 
								case 's':			/* dump schema only */
 | 
				
			||||||
				schemaOnly = 1;
 | 
									schemaOnly = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 't':			/* Dump data for this table only */
 | 
								case 't':			/* Dump data for this table only */
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
@@ -637,7 +637,7 @@ main(int argc, char **argv)
 | 
				
			|||||||
				g_verbose = true;
 | 
									g_verbose = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'z':			/* Dump ACLs and table ownership info */
 | 
								case 'z':			/* Dump ACLs and table ownership info */
 | 
				
			||||||
				aclsOption = 1;
 | 
									aclsOption = true;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'u':
 | 
								case 'u':
 | 
				
			||||||
				use_password = 1;
 | 
									use_password = 1;
 | 
				
			||||||
@@ -648,6 +648,14 @@ main(int argc, char **argv)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (dumpData == true && oids == true)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							fprintf(stderr,
 | 
				
			||||||
 | 
								 "%s: INSERT's can not set oids, so INSERT and OID options can not be used together.\n",
 | 
				
			||||||
 | 
									progname);
 | 
				
			||||||
 | 
							exit(2);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
	/* open the output file */
 | 
						/* open the output file */
 | 
				
			||||||
	if (filename == NULL)
 | 
						if (filename == NULL)
 | 
				
			||||||
		g_fout = stdout;
 | 
							g_fout = stdout;
 | 
				
			||||||
@@ -714,7 +722,7 @@ main(int argc, char **argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	g_last_builtin_oid = findLastBuiltinOid();
 | 
						g_last_builtin_oid = findLastBuiltinOid();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (oids)
 | 
						if (oids == true)
 | 
				
			||||||
		setMaxOid(g_fout);
 | 
							setMaxOid(g_fout);
 | 
				
			||||||
	if (!dataOnly)
 | 
						if (!dataOnly)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -1663,7 +1671,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if 0
 | 
					#if 0
 | 
				
			||||||
				/* XXX - how to emit this DROP TRIGGER? */
 | 
									/* XXX - how to emit this DROP TRIGGER? */
 | 
				
			||||||
				if (drop_schema)
 | 
									if (dropSchema)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					sprintf(query, "DROP TRIGGER %s ON %s;\n",
 | 
										sprintf(query, "DROP TRIGGER %s ON %s;\n",
 | 
				
			||||||
					 fmtId(PQgetvalue(res2, i2, i_tgname), force_quotes),
 | 
										 fmtId(PQgetvalue(res2, i2, i_tgname), force_quotes),
 | 
				
			||||||
@@ -2067,7 +2075,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		becomeUser(fout, tinfo[i].usename);
 | 
							becomeUser(fout, tinfo[i].usename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (drop_schema)
 | 
							if (dropSchema)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			sprintf(q, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes));
 | 
								sprintf(q, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes));
 | 
				
			||||||
			fputs(q, fout);
 | 
								fputs(q, fout);
 | 
				
			||||||
@@ -2170,7 +2178,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
 | 
				
			|||||||
		lanname = checkForQuote(PQgetvalue(res, i, i_lanname));
 | 
							lanname = checkForQuote(PQgetvalue(res, i, i_lanname));
 | 
				
			||||||
		lancompiler = checkForQuote(PQgetvalue(res, i, i_lancompiler));
 | 
							lancompiler = checkForQuote(PQgetvalue(res, i, i_lancompiler));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (drop_schema)
 | 
							if (dropSchema)
 | 
				
			||||||
			fprintf(fout, "DROP PROCEDURAL LANGUAGE '%s';\n", lanname);
 | 
								fprintf(fout, "DROP PROCEDURAL LANGUAGE '%s';\n", lanname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fprintf(fout, "CREATE %sPROCEDURAL LANGUAGE '%s' "
 | 
							fprintf(fout, "CREATE %sPROCEDURAL LANGUAGE '%s' "
 | 
				
			||||||
@@ -2288,7 +2296,7 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
 | 
				
			|||||||
		PQclear(res);
 | 
							PQclear(res);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (drop_schema)
 | 
						if (dropSchema)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		sprintf(q, "DROP FUNCTION %s (", fmtId(finfo[i].proname, force_quotes));
 | 
							sprintf(q, "DROP FUNCTION %s (", fmtId(finfo[i].proname, force_quotes));
 | 
				
			||||||
		for (j = 0; j < finfo[i].nargs; j++)
 | 
							for (j = 0; j < finfo[i].nargs; j++)
 | 
				
			||||||
@@ -2415,7 +2423,7 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		becomeUser(fout, oprinfo[i].usename);
 | 
							becomeUser(fout, oprinfo[i].usename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (drop_schema)
 | 
							if (dropSchema)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			sprintf(q, "DROP OPERATOR %s (%s, %s);\n", oprinfo[i].oprname,
 | 
								sprintf(q, "DROP OPERATOR %s (%s, %s);\n", oprinfo[i].oprname,
 | 
				
			||||||
					fmtId(findTypeByOid(tinfo, numTypes, oprinfo[i].oprleft), false),
 | 
										fmtId(findTypeByOid(tinfo, numTypes, oprinfo[i].oprleft), false),
 | 
				
			||||||
@@ -2519,7 +2527,7 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		becomeUser(fout, agginfo[i].usename);
 | 
							becomeUser(fout, agginfo[i].usename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (drop_schema)
 | 
							if (dropSchema)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			sprintf(q, "DROP AGGREGATE %s %s;\n", agginfo[i].aggname,
 | 
								sprintf(q, "DROP AGGREGATE %s %s;\n", agginfo[i].aggname,
 | 
				
			||||||
					fmtId(findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype), false));
 | 
										fmtId(findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype), false));
 | 
				
			||||||
@@ -2739,7 +2747,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			becomeUser(fout, tblinfo[i].usename);
 | 
								becomeUser(fout, tblinfo[i].usename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (drop_schema)
 | 
								if (dropSchema)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				sprintf(q, "DROP TABLE %s;\n", fmtId(tblinfo[i].relname, force_quotes));
 | 
									sprintf(q, "DROP TABLE %s;\n", fmtId(tblinfo[i].relname, force_quotes));
 | 
				
			||||||
				fputs(q, fout);
 | 
									fputs(q, fout);
 | 
				
			||||||
@@ -2979,7 +2987,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
 | 
				
			|||||||
			strcpy(id1, fmtId(indinfo[i].indexrelname, force_quotes));
 | 
								strcpy(id1, fmtId(indinfo[i].indexrelname, force_quotes));
 | 
				
			||||||
			strcpy(id2, fmtId(indinfo[i].indrelname, force_quotes));
 | 
								strcpy(id2, fmtId(indinfo[i].indrelname, force_quotes));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (drop_schema)
 | 
								if (dropSchema)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				sprintf(q, "DROP INDEX %s;\n", id1);
 | 
									sprintf(q, "DROP INDEX %s;\n", id1);
 | 
				
			||||||
				fputs(q, fout);
 | 
									fputs(q, fout);
 | 
				
			||||||
@@ -3245,7 +3253,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	PQclear(res);
 | 
						PQclear(res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (drop_schema)
 | 
						if (dropSchema)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		sprintf(query, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes));
 | 
							sprintf(query, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes));
 | 
				
			||||||
		fputs(query, fout);
 | 
							fputs(query, fout);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user